aboutsummaryrefslogtreecommitdiff
path: root/src/internal/runtime
diff options
context:
space:
mode:
authorqmuntal <quimmuntal@gmail.com>2025-08-21 21:23:03 +0200
committerQuim Muntal <quimmuntal@gmail.com>2025-09-12 12:00:33 -0700
commit889e71c2ac43f22dbd41c0b935acac2e778c8f87 (patch)
treee6fe466d35cfc41e3ade6fcfe7fb62988af05580 /src/internal/runtime
parentcc8a6780acf192b0df2ecfab65bd8c2b5ab1f809 (diff)
downloadgo-889e71c2ac43f22dbd41c0b935acac2e778c8f87.tar.xz
runtime: move Windows types and consts to internal/runtime/syscall/windows
This CL doesn't change any behavior, it just moves code around to reduce the size of the runtime package and remove some duplicated symbols. Updates #51087. Cq-Include-Trybots: luci.golang.try:gotip-windows-arm64 Change-Id: I3d3e5f214f045c24fb5d4050d56e7b0822a6e4b5 Reviewed-on: https://go-review.googlesource.com/c/go/+/698098 Reviewed-by: Cherry Mui <cherryyz@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Michael Pratt <mpratt@google.com>
Diffstat (limited to 'src/internal/runtime')
-rw-r--r--src/internal/runtime/syscall/windows/defs_windows.go159
-rw-r--r--src/internal/runtime/syscall/windows/defs_windows_386.go79
-rw-r--r--src/internal/runtime/syscall/windows/defs_windows_amd64.go99
-rw-r--r--src/internal/runtime/syscall/windows/defs_windows_arm64.go75
4 files changed, 412 insertions, 0 deletions
diff --git a/src/internal/runtime/syscall/windows/defs_windows.go b/src/internal/runtime/syscall/windows/defs_windows.go
new file mode 100644
index 0000000000..6b1098098c
--- /dev/null
+++ b/src/internal/runtime/syscall/windows/defs_windows.go
@@ -0,0 +1,159 @@
+// Copyright 2025 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// Architecture-independent definitions.
+
+package windows
+
+// Pseudo handles.
+const (
+ CurrentProcess = ^uintptr(0) // -1 = current process
+ CurrentThread = ^uintptr(1) // -2 = current thread
+)
+
+const INVALID_HANDLE_VALUE = ^uintptr(0)
+
+const DWORD_MAX = 0xffffffff
+
+const (
+ PROT_NONE = 0
+ PROT_READ = 1
+ PROT_WRITE = 2
+ PROT_EXEC = 4
+)
+
+const (
+ MAP_ANON = 1
+ MAP_PRIVATE = 2
+)
+
+const DUPLICATE_SAME_ACCESS = 0x2
+
+const THREAD_PRIORITY_HIGHEST = 0x2
+
+const (
+ SIGINT = 0x2
+ SIGTERM = 0xF
+)
+
+const (
+ CTRL_C_EVENT = 0x0
+ CTRL_BREAK_EVENT = 0x1
+ CTRL_CLOSE_EVENT = 0x2
+ CTRL_LOGOFF_EVENT = 0x5
+ CTRL_SHUTDOWN_EVENT = 0x6
+)
+
+const (
+ EXCEPTION_ACCESS_VIOLATION = 0xc0000005
+ EXCEPTION_IN_PAGE_ERROR = 0xc0000006
+ EXCEPTION_BREAKPOINT = 0x80000003
+ EXCEPTION_ILLEGAL_INSTRUCTION = 0xc000001d
+ EXCEPTION_FLT_DENORMAL_OPERAND = 0xc000008d
+ EXCEPTION_FLT_DIVIDE_BY_ZERO = 0xc000008e
+ EXCEPTION_FLT_INEXACT_RESULT = 0xc000008f
+ EXCEPTION_FLT_OVERFLOW = 0xc0000091
+ EXCEPTION_FLT_UNDERFLOW = 0xc0000093
+ EXCEPTION_INT_DIVIDE_BY_ZERO = 0xc0000094
+ EXCEPTION_INT_OVERFLOW = 0xc0000095
+)
+
+const (
+ SEM_FAILCRITICALERRORS = 0x0001
+ SEM_NOGPFAULTERRORBOX = 0x0002
+ SEM_NOOPENFILEERRORBOX = 0x8000
+)
+
+const WER_FAULT_REPORTING_NO_UI = 0x0020
+
+const INFINITE = 0xffffffff
+
+const WAIT_TIMEOUT = 258
+
+const FAIL_FAST_GENERATE_EXCEPTION_ADDRESS = 0x1
+
+const (
+ EXCEPTION_CONTINUE_EXECUTION = -0x1
+ EXCEPTION_CONTINUE_SEARCH = 0x0
+ EXCEPTION_CONTINUE_SEARCH_SEH = 0x1
+)
+
+const CREATE_WAITABLE_TIMER_HIGH_RESOLUTION = 0x00000002
+
+const (
+ SYNCHRONIZE = 0x00100000
+ TIMER_QUERY_STATE = 0x0001
+ TIMER_MODIFY_STATE = 0x0002
+)
+
+// https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-erref/596a1078-e883-4972-9bbc-49e60bebca55
+const (
+ STATUS_SUCCESS = 0x00000000
+ STATUS_PENDING = 0x00000103
+ STATUS_CANCELLED = 0xC0000120
+)
+
+// https://learn.microsoft.com/en-us/windows/win32/api/sysinfoapi/ns-sysinfoapi-system_info
+type SystemInfo struct {
+ ProcessorArchitecture uint16
+ Reserved uint16
+ PageSize uint32
+ MinimumApplicationAddress *byte
+ MaximumApplicationAddress *byte
+ ActiveProcessorMask uintptr
+ NumberOfProcessors uint32
+ ProcessorType uint32
+ AllocationGranularity uint32
+ ProcessorLevel uint16
+ ProcessorRevision uint16
+}
+
+// https://learn.microsoft.com/en-us/windows/win32/api/winnt/ns-winnt-exception_pointers
+type ExceptionPointers struct {
+ Record *ExceptionRecord
+ Context *Context
+}
+
+// https://learn.microsoft.com/en-us/windows/win32/api/winnt/ns-winnt-exception_record
+type ExceptionRecord struct {
+ ExceptionCode uint32
+ ExceptionFlags uint32
+ ExceptionRecord *ExceptionRecord
+ ExceptionAddress uintptr
+ NumberParameters uint32
+ ExceptionInformation [15]uintptr
+}
+
+type Handle uintptr
+
+// https://learn.microsoft.com/en-us/windows/win32/api/minwinbase/ns-minwinbase-overlapped
+type Overlapped struct {
+ Internal uintptr
+ InternalHigh uintptr
+ Offset uint32
+ OffsetHigh uint32
+ HEvent Handle
+}
+
+// https://learn.microsoft.com/en-us/windows/win32/api/winnt/ns-winnt-memory_basic_information
+type MemoryBasicInformation struct {
+ BaseAddress uintptr
+ AllocationBase uintptr
+ AllocationProtect uint32
+ PartitionId uint16
+ RegionSize uintptr
+ State uint32
+ Protect uint32
+ Type uint32
+}
+
+// https://learn.microsoft.com/en-us/windows-hardware/drivers/ddi/wdm/ns-wdm-_osversioninfow
+type OSVERSIONINFOW struct {
+ OSVersionInfoSize uint32
+ MajorVersion uint32
+ MinorVersion uint32
+ BuildNumber uint32
+ PlatformID uint32
+ CSDVersion [128]uint16
+}
diff --git a/src/internal/runtime/syscall/windows/defs_windows_386.go b/src/internal/runtime/syscall/windows/defs_windows_386.go
new file mode 100644
index 0000000000..6c2271efb0
--- /dev/null
+++ b/src/internal/runtime/syscall/windows/defs_windows_386.go
@@ -0,0 +1,79 @@
+// Copyright 2025 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package windows
+
+import (
+ "internal/goarch"
+ "unsafe"
+)
+
+const CONTEXT_CONTROL = 0x10001
+
+type FloatingSaveArea struct {
+ ControlWord uint32
+ StatusWord uint32
+ TagWord uint32
+ ErrorOffset uint32
+ ErrorSelector uint32
+ DataOffset uint32
+ DataSelector uint32
+ RegisterArea [80]uint8
+ Cr0NpxState uint32
+}
+
+type Context struct {
+ ContextFlags uint32
+ Dr0 uint32
+ Dr1 uint32
+ Dr2 uint32
+ Dr3 uint32
+ Dr6 uint32
+ Dr7 uint32
+ FloatingSaveArea FloatingSaveArea
+ SegGs uint32
+ SegFs uint32
+ SegEs uint32
+ SegDs uint32
+ Edi uint32
+ Esi uint32
+ Ebx uint32
+ Edx uint32
+ Ecx uint32
+ Eax uint32
+ Ebp uint32
+ Eip uint32
+ SegCs uint32
+ EFlags uint32
+ Esp uint32
+ SegSs uint32
+ ExtendedRegisters [512]uint8
+}
+
+func (c *Context) PC() uintptr { return uintptr(c.Eip) }
+func (c *Context) SP() uintptr { return uintptr(c.Esp) }
+
+// 386 does not have link register, so this returns 0.
+func (c *Context) LR() uintptr { return 0 }
+func (c *Context) SetLR(x uintptr) {}
+
+func (c *Context) SetPC(x uintptr) { c.Eip = uint32(x) }
+func (c *Context) SetSP(x uintptr) { c.Esp = uint32(x) }
+
+// 386 does not have frame pointer register.
+func (c *Context) SetFP(x uintptr) {}
+
+func (c *Context) PushCall(targetPC, resumePC uintptr) {
+ sp := c.SP() - goarch.StackAlign
+ *(*uintptr)(unsafe.Pointer(sp)) = resumePC
+ c.SetSP(sp)
+ c.SetPC(targetPC)
+}
+
+// DISPATCHER_CONTEXT is not defined on 386.
+type DISPATCHER_CONTEXT struct{}
+
+func (c *DISPATCHER_CONTEXT) Ctx() *Context {
+ return nil
+}
diff --git a/src/internal/runtime/syscall/windows/defs_windows_amd64.go b/src/internal/runtime/syscall/windows/defs_windows_amd64.go
new file mode 100644
index 0000000000..018124488b
--- /dev/null
+++ b/src/internal/runtime/syscall/windows/defs_windows_amd64.go
@@ -0,0 +1,99 @@
+// Copyright 2025 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package windows
+
+import (
+ "internal/goarch"
+ "unsafe"
+)
+
+const CONTEXT_CONTROL = 0x100001
+
+type M128 struct {
+ Low uint64
+ High int64
+}
+
+type Context struct {
+ P1Home uint64
+ P2Home uint64
+ P3Home uint64
+ P4Home uint64
+ P5Home uint64
+ P6Home uint64
+ ContextFlags uint32
+ MxCsr uint32
+ SegCs uint16
+ SegDs uint16
+ SegEs uint16
+ SegFs uint16
+ SegGs uint16
+ SegSs uint16
+ EFlags uint32
+ DR0 uint64
+ DR1 uint64
+ DR2 uint64
+ DR3 uint64
+ DR6 uint64
+ DR7 uint64
+ Rax uint64
+ Rcx uint64
+ Rdx uint64
+ Rbx uint64
+ Rsp uint64
+ Rbp uint64
+ Rsi uint64
+ Rdi uint64
+ R8 uint64
+ R9 uint64
+ R10 uint64
+ R11 uint64
+ R12 uint64
+ R13 uint64
+ R14 uint64
+ R15 uint64
+ Rip uint64
+ _ [512]byte
+ VectorRegister [26]M128
+ VectorControl uint64
+ DebugControl uint64
+ LastBranchToRip uint64
+ LastBranchFromRip uint64
+ LastExceptionToRip uint64
+ LastExceptionFromRip uint64
+}
+
+func (c *Context) PC() uintptr { return uintptr(c.Rip) }
+func (c *Context) SP() uintptr { return uintptr(c.Rsp) }
+
+// AMD64 does not have link register, so this returns 0.
+func (c *Context) LR() uintptr { return 0 }
+func (c *Context) SetLR(x uintptr) {}
+
+func (c *Context) SetPC(x uintptr) { c.Rip = uint64(x) }
+func (c *Context) SetSP(x uintptr) { c.Rsp = uint64(x) }
+func (c *Context) SetFP(x uintptr) { c.Rbp = uint64(x) }
+
+func (c *Context) PushCall(targetPC, resumePC uintptr) {
+ sp := c.SP() - goarch.StackAlign
+ *(*uintptr)(unsafe.Pointer(sp)) = resumePC
+ c.SetSP(sp)
+ c.SetPC(targetPC)
+}
+
+type DISPATCHER_CONTEXT struct {
+ ControlPc uint64
+ ImageBase uint64
+ FunctionEntry uintptr
+ EstablisherFrame uint64
+ TargetIp uint64
+ Context *Context
+ LanguageHandler uintptr
+ HandlerData uintptr
+}
+
+func (c *DISPATCHER_CONTEXT) Ctx() *Context {
+ return c.Context
+}
diff --git a/src/internal/runtime/syscall/windows/defs_windows_arm64.go b/src/internal/runtime/syscall/windows/defs_windows_arm64.go
new file mode 100644
index 0000000000..c05573a531
--- /dev/null
+++ b/src/internal/runtime/syscall/windows/defs_windows_arm64.go
@@ -0,0 +1,75 @@
+// Copyright 2025 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package windows
+
+import (
+ "internal/goarch"
+ "unsafe"
+)
+
+// NOTE(rsc): CONTEXT_CONTROL is actually 0x400001 and should include PC, SP, and LR.
+// However, empirically, LR doesn't come along on Windows 10
+// unless you also set CONTEXT_INTEGER (0x400002).
+// Without LR, we skip over the next-to-bottom function in profiles
+// when the bottom function is frameless.
+// So we set both here, to make a working CONTEXT_CONTROL.
+const CONTEXT_CONTROL = 0x400003
+
+type Neon128 struct {
+ Low uint64
+ High int64
+}
+
+// See https://docs.microsoft.com/en-us/windows/win32/api/winnt/ns-winnt-arm64_nt_context
+type Context struct {
+ ContextFlags uint32
+ Cpsr uint32
+ X [31]uint64 // fp is x[29], lr is x[30]
+ XSp uint64
+ Pc uint64
+ V [32]Neon128
+ Fpcr uint32
+ Fpsr uint32
+ Bcr [8]uint32
+ Bvr [8]uint64
+ Wcr [2]uint32
+ Wvr [2]uint64
+}
+
+func (c *Context) PC() uintptr { return uintptr(c.Pc) }
+func (c *Context) SP() uintptr { return uintptr(c.XSp) }
+func (c *Context) LR() uintptr { return uintptr(c.X[30]) }
+
+func (c *Context) SetPC(x uintptr) { c.Pc = uint64(x) }
+func (c *Context) SetSP(x uintptr) { c.XSp = uint64(x) }
+func (c *Context) SetLR(x uintptr) { c.X[30] = uint64(x) }
+func (c *Context) SetFP(x uintptr) { c.X[29] = uint64(x) }
+
+func (c *Context) PushCall(targetPC, resumePC uintptr) {
+ // Push LR. The injected call is responsible
+ // for restoring LR. gentraceback is aware of
+ // this extra slot. See sigctxt.pushCall in
+ // signal_arm64.go.
+ sp := c.SP() - goarch.StackAlign
+ c.SetSP(sp)
+ *(*uint64)(unsafe.Pointer(sp)) = uint64(c.LR())
+ c.SetLR(resumePC)
+ c.SetPC(targetPC)
+}
+
+type DISPATCHER_CONTEXT struct {
+ ControlPc uint64
+ ImageBase uint64
+ FunctionEntry uintptr
+ EstablisherFrame uint64
+ TargetIp uint64
+ Context *Context
+ LanguageHandler uintptr
+ HandlerData uintptr
+}
+
+func (c *DISPATCHER_CONTEXT) Ctx() *Context {
+ return c.Context
+}