Skip to content

Commit 889e71c

Browse files
committed
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 golang#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 <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Michael Pratt <[email protected]>
1 parent cc8a678 commit 889e71c

19 files changed

+681
-658
lines changed
Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
// Copyright 2025 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
// Architecture-independent definitions.
6+
7+
package windows
8+
9+
// Pseudo handles.
10+
const (
11+
CurrentProcess = ^uintptr(0) // -1 = current process
12+
CurrentThread = ^uintptr(1) // -2 = current thread
13+
)
14+
15+
const INVALID_HANDLE_VALUE = ^uintptr(0)
16+
17+
const DWORD_MAX = 0xffffffff
18+
19+
const (
20+
PROT_NONE = 0
21+
PROT_READ = 1
22+
PROT_WRITE = 2
23+
PROT_EXEC = 4
24+
)
25+
26+
const (
27+
MAP_ANON = 1
28+
MAP_PRIVATE = 2
29+
)
30+
31+
const DUPLICATE_SAME_ACCESS = 0x2
32+
33+
const THREAD_PRIORITY_HIGHEST = 0x2
34+
35+
const (
36+
SIGINT = 0x2
37+
SIGTERM = 0xF
38+
)
39+
40+
const (
41+
CTRL_C_EVENT = 0x0
42+
CTRL_BREAK_EVENT = 0x1
43+
CTRL_CLOSE_EVENT = 0x2
44+
CTRL_LOGOFF_EVENT = 0x5
45+
CTRL_SHUTDOWN_EVENT = 0x6
46+
)
47+
48+
const (
49+
EXCEPTION_ACCESS_VIOLATION = 0xc0000005
50+
EXCEPTION_IN_PAGE_ERROR = 0xc0000006
51+
EXCEPTION_BREAKPOINT = 0x80000003
52+
EXCEPTION_ILLEGAL_INSTRUCTION = 0xc000001d
53+
EXCEPTION_FLT_DENORMAL_OPERAND = 0xc000008d
54+
EXCEPTION_FLT_DIVIDE_BY_ZERO = 0xc000008e
55+
EXCEPTION_FLT_INEXACT_RESULT = 0xc000008f
56+
EXCEPTION_FLT_OVERFLOW = 0xc0000091
57+
EXCEPTION_FLT_UNDERFLOW = 0xc0000093
58+
EXCEPTION_INT_DIVIDE_BY_ZERO = 0xc0000094
59+
EXCEPTION_INT_OVERFLOW = 0xc0000095
60+
)
61+
62+
const (
63+
SEM_FAILCRITICALERRORS = 0x0001
64+
SEM_NOGPFAULTERRORBOX = 0x0002
65+
SEM_NOOPENFILEERRORBOX = 0x8000
66+
)
67+
68+
const WER_FAULT_REPORTING_NO_UI = 0x0020
69+
70+
const INFINITE = 0xffffffff
71+
72+
const WAIT_TIMEOUT = 258
73+
74+
const FAIL_FAST_GENERATE_EXCEPTION_ADDRESS = 0x1
75+
76+
const (
77+
EXCEPTION_CONTINUE_EXECUTION = -0x1
78+
EXCEPTION_CONTINUE_SEARCH = 0x0
79+
EXCEPTION_CONTINUE_SEARCH_SEH = 0x1
80+
)
81+
82+
const CREATE_WAITABLE_TIMER_HIGH_RESOLUTION = 0x00000002
83+
84+
const (
85+
SYNCHRONIZE = 0x00100000
86+
TIMER_QUERY_STATE = 0x0001
87+
TIMER_MODIFY_STATE = 0x0002
88+
)
89+
90+
// https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-erref/596a1078-e883-4972-9bbc-49e60bebca55
91+
const (
92+
STATUS_SUCCESS = 0x00000000
93+
STATUS_PENDING = 0x00000103
94+
STATUS_CANCELLED = 0xC0000120
95+
)
96+
97+
// https://learn.microsoft.com/en-us/windows/win32/api/sysinfoapi/ns-sysinfoapi-system_info
98+
type SystemInfo struct {
99+
ProcessorArchitecture uint16
100+
Reserved uint16
101+
PageSize uint32
102+
MinimumApplicationAddress *byte
103+
MaximumApplicationAddress *byte
104+
ActiveProcessorMask uintptr
105+
NumberOfProcessors uint32
106+
ProcessorType uint32
107+
AllocationGranularity uint32
108+
ProcessorLevel uint16
109+
ProcessorRevision uint16
110+
}
111+
112+
// https://learn.microsoft.com/en-us/windows/win32/api/winnt/ns-winnt-exception_pointers
113+
type ExceptionPointers struct {
114+
Record *ExceptionRecord
115+
Context *Context
116+
}
117+
118+
// https://learn.microsoft.com/en-us/windows/win32/api/winnt/ns-winnt-exception_record
119+
type ExceptionRecord struct {
120+
ExceptionCode uint32
121+
ExceptionFlags uint32
122+
ExceptionRecord *ExceptionRecord
123+
ExceptionAddress uintptr
124+
NumberParameters uint32
125+
ExceptionInformation [15]uintptr
126+
}
127+
128+
type Handle uintptr
129+
130+
// https://learn.microsoft.com/en-us/windows/win32/api/minwinbase/ns-minwinbase-overlapped
131+
type Overlapped struct {
132+
Internal uintptr
133+
InternalHigh uintptr
134+
Offset uint32
135+
OffsetHigh uint32
136+
HEvent Handle
137+
}
138+
139+
// https://learn.microsoft.com/en-us/windows/win32/api/winnt/ns-winnt-memory_basic_information
140+
type MemoryBasicInformation struct {
141+
BaseAddress uintptr
142+
AllocationBase uintptr
143+
AllocationProtect uint32
144+
PartitionId uint16
145+
RegionSize uintptr
146+
State uint32
147+
Protect uint32
148+
Type uint32
149+
}
150+
151+
// https://learn.microsoft.com/en-us/windows-hardware/drivers/ddi/wdm/ns-wdm-_osversioninfow
152+
type OSVERSIONINFOW struct {
153+
OSVersionInfoSize uint32
154+
MajorVersion uint32
155+
MinorVersion uint32
156+
BuildNumber uint32
157+
PlatformID uint32
158+
CSDVersion [128]uint16
159+
}
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
// Copyright 2025 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
package windows
6+
7+
import (
8+
"internal/goarch"
9+
"unsafe"
10+
)
11+
12+
const CONTEXT_CONTROL = 0x10001
13+
14+
type FloatingSaveArea struct {
15+
ControlWord uint32
16+
StatusWord uint32
17+
TagWord uint32
18+
ErrorOffset uint32
19+
ErrorSelector uint32
20+
DataOffset uint32
21+
DataSelector uint32
22+
RegisterArea [80]uint8
23+
Cr0NpxState uint32
24+
}
25+
26+
type Context struct {
27+
ContextFlags uint32
28+
Dr0 uint32
29+
Dr1 uint32
30+
Dr2 uint32
31+
Dr3 uint32
32+
Dr6 uint32
33+
Dr7 uint32
34+
FloatingSaveArea FloatingSaveArea
35+
SegGs uint32
36+
SegFs uint32
37+
SegEs uint32
38+
SegDs uint32
39+
Edi uint32
40+
Esi uint32
41+
Ebx uint32
42+
Edx uint32
43+
Ecx uint32
44+
Eax uint32
45+
Ebp uint32
46+
Eip uint32
47+
SegCs uint32
48+
EFlags uint32
49+
Esp uint32
50+
SegSs uint32
51+
ExtendedRegisters [512]uint8
52+
}
53+
54+
func (c *Context) PC() uintptr { return uintptr(c.Eip) }
55+
func (c *Context) SP() uintptr { return uintptr(c.Esp) }
56+
57+
// 386 does not have link register, so this returns 0.
58+
func (c *Context) LR() uintptr { return 0 }
59+
func (c *Context) SetLR(x uintptr) {}
60+
61+
func (c *Context) SetPC(x uintptr) { c.Eip = uint32(x) }
62+
func (c *Context) SetSP(x uintptr) { c.Esp = uint32(x) }
63+
64+
// 386 does not have frame pointer register.
65+
func (c *Context) SetFP(x uintptr) {}
66+
67+
func (c *Context) PushCall(targetPC, resumePC uintptr) {
68+
sp := c.SP() - goarch.StackAlign
69+
*(*uintptr)(unsafe.Pointer(sp)) = resumePC
70+
c.SetSP(sp)
71+
c.SetPC(targetPC)
72+
}
73+
74+
// DISPATCHER_CONTEXT is not defined on 386.
75+
type DISPATCHER_CONTEXT struct{}
76+
77+
func (c *DISPATCHER_CONTEXT) Ctx() *Context {
78+
return nil
79+
}
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
// Copyright 2025 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
package windows
6+
7+
import (
8+
"internal/goarch"
9+
"unsafe"
10+
)
11+
12+
const CONTEXT_CONTROL = 0x100001
13+
14+
type M128 struct {
15+
Low uint64
16+
High int64
17+
}
18+
19+
type Context struct {
20+
P1Home uint64
21+
P2Home uint64
22+
P3Home uint64
23+
P4Home uint64
24+
P5Home uint64
25+
P6Home uint64
26+
ContextFlags uint32
27+
MxCsr uint32
28+
SegCs uint16
29+
SegDs uint16
30+
SegEs uint16
31+
SegFs uint16
32+
SegGs uint16
33+
SegSs uint16
34+
EFlags uint32
35+
DR0 uint64
36+
DR1 uint64
37+
DR2 uint64
38+
DR3 uint64
39+
DR6 uint64
40+
DR7 uint64
41+
Rax uint64
42+
Rcx uint64
43+
Rdx uint64
44+
Rbx uint64
45+
Rsp uint64
46+
Rbp uint64
47+
Rsi uint64
48+
Rdi uint64
49+
R8 uint64
50+
R9 uint64
51+
R10 uint64
52+
R11 uint64
53+
R12 uint64
54+
R13 uint64
55+
R14 uint64
56+
R15 uint64
57+
Rip uint64
58+
_ [512]byte
59+
VectorRegister [26]M128
60+
VectorControl uint64
61+
DebugControl uint64
62+
LastBranchToRip uint64
63+
LastBranchFromRip uint64
64+
LastExceptionToRip uint64
65+
LastExceptionFromRip uint64
66+
}
67+
68+
func (c *Context) PC() uintptr { return uintptr(c.Rip) }
69+
func (c *Context) SP() uintptr { return uintptr(c.Rsp) }
70+
71+
// AMD64 does not have link register, so this returns 0.
72+
func (c *Context) LR() uintptr { return 0 }
73+
func (c *Context) SetLR(x uintptr) {}
74+
75+
func (c *Context) SetPC(x uintptr) { c.Rip = uint64(x) }
76+
func (c *Context) SetSP(x uintptr) { c.Rsp = uint64(x) }
77+
func (c *Context) SetFP(x uintptr) { c.Rbp = uint64(x) }
78+
79+
func (c *Context) PushCall(targetPC, resumePC uintptr) {
80+
sp := c.SP() - goarch.StackAlign
81+
*(*uintptr)(unsafe.Pointer(sp)) = resumePC
82+
c.SetSP(sp)
83+
c.SetPC(targetPC)
84+
}
85+
86+
type DISPATCHER_CONTEXT struct {
87+
ControlPc uint64
88+
ImageBase uint64
89+
FunctionEntry uintptr
90+
EstablisherFrame uint64
91+
TargetIp uint64
92+
Context *Context
93+
LanguageHandler uintptr
94+
HandlerData uintptr
95+
}
96+
97+
func (c *DISPATCHER_CONTEXT) Ctx() *Context {
98+
return c.Context
99+
}

0 commit comments

Comments
 (0)