2014-11-11 17:07:37 -05:00
|
|
|
// created by cgo -cdefs and then converted to Go
|
|
|
|
|
// cgo -cdefs defs_windows.go
|
|
|
|
|
|
|
|
|
|
package runtime
|
|
|
|
|
|
|
|
|
|
const (
|
|
|
|
|
_PROT_NONE = 0
|
|
|
|
|
_PROT_READ = 1
|
|
|
|
|
_PROT_WRITE = 2
|
|
|
|
|
_PROT_EXEC = 4
|
|
|
|
|
|
|
|
|
|
_MAP_ANON = 1
|
|
|
|
|
_MAP_PRIVATE = 2
|
|
|
|
|
|
|
|
|
|
_DUPLICATE_SAME_ACCESS = 0x2
|
|
|
|
|
_THREAD_PRIORITY_HIGHEST = 0x2
|
|
|
|
|
|
runtime: treat CTRL_CLOSE_EVENT, CTRL_LOGOFF_EVENT, CTRL_SHUTDOWN_EVENT as SIGTERM on Windows
This matches the existing behavior of treating CTRL_C_EVENT, CTRL_BREAK_EVENT as a synthesized SIGINT event.
See https://docs.microsoft.com/en-us/windows/console/handlerroutine for a good documentation source upstream to confirm these values.
As for the usage of these events, the "Timeouts" section of that upstream documentation is important to note, especially the limited window in which to do any cleanup before the program will be forcibly killed (defaults typically 5s, but as low as 500ms, and in many cases configurable system-wide).
These events are especially relevant for Windows containers, where these events (particularly `CTRL_SHUTDOWN_EVENT`) are one of the only ways containers can "gracefully" shut down (https://github.com/moby/moby/issues/25982#issuecomment-466804071).
This was verified by making a simple `main()` which implements the same code as in `ExampleNotify_allSignals` but in a `for` loop, building a `main.exe`, running that in a container, then doing `docker kill -sTERM` on said container. The program prints `Got signal: SIGTERM`, then exits after the aforementioned timeout, as expected. Behavior before this patch is that the program gets no notification (and thus no output) but still exits after the timeout.
Fixes #7479
Change-Id: I2af79421cd484a0fbb9467bb7ddb5f0e8bc3610e
GitHub-Last-Rev: 9e05d631b542393f5ebb0eb3747157c8bd0de635
GitHub-Pull-Request: golang/go#33311
Reviewed-on: https://go-review.googlesource.com/c/go/+/187739
Run-TryBot: Alex Brainman <alex.brainman@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Alex Brainman <alex.brainman@gmail.com>
2019-08-14 15:19:55 +00:00
|
|
|
_SIGINT = 0x2
|
|
|
|
|
_SIGTERM = 0xF
|
|
|
|
|
_CTRL_C_EVENT = 0x0
|
|
|
|
|
_CTRL_BREAK_EVENT = 0x1
|
|
|
|
|
_CTRL_CLOSE_EVENT = 0x2
|
|
|
|
|
_CTRL_LOGOFF_EVENT = 0x5
|
|
|
|
|
_CTRL_SHUTDOWN_EVENT = 0x6
|
2014-11-11 17:07:37 -05:00
|
|
|
|
|
|
|
|
_CONTEXT_CONTROL = 0x100001
|
|
|
|
|
_CONTEXT_FULL = 0x10000b
|
|
|
|
|
|
|
|
|
|
_EXCEPTION_ACCESS_VIOLATION = 0xc0000005
|
|
|
|
|
_EXCEPTION_BREAKPOINT = 0x80000003
|
|
|
|
|
_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
|
|
|
|
|
|
|
|
|
|
_INFINITE = 0xffffffff
|
|
|
|
|
_WAIT_TIMEOUT = 0x102
|
|
|
|
|
|
|
|
|
|
_EXCEPTION_CONTINUE_EXECUTION = -0x1
|
|
|
|
|
_EXCEPTION_CONTINUE_SEARCH = 0x0
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type systeminfo struct {
|
|
|
|
|
anon0 [4]byte
|
|
|
|
|
dwpagesize uint32
|
|
|
|
|
lpminimumapplicationaddress *byte
|
|
|
|
|
lpmaximumapplicationaddress *byte
|
|
|
|
|
dwactiveprocessormask uint64
|
|
|
|
|
dwnumberofprocessors uint32
|
|
|
|
|
dwprocessortype uint32
|
|
|
|
|
dwallocationgranularity uint32
|
|
|
|
|
wprocessorlevel uint16
|
|
|
|
|
wprocessorrevision uint16
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type exceptionrecord struct {
|
|
|
|
|
exceptioncode uint32
|
|
|
|
|
exceptionflags uint32
|
|
|
|
|
exceptionrecord *exceptionrecord
|
|
|
|
|
exceptionaddress *byte
|
|
|
|
|
numberparameters uint32
|
|
|
|
|
pad_cgo_0 [4]byte
|
|
|
|
|
exceptioninformation [15]uint64
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type m128a 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
|
|
|
|
|
anon0 [512]byte
|
|
|
|
|
vectorregister [26]m128a
|
|
|
|
|
vectorcontrol uint64
|
|
|
|
|
debugcontrol uint64
|
|
|
|
|
lastbranchtorip uint64
|
|
|
|
|
lastbranchfromrip uint64
|
|
|
|
|
lastexceptiontorip uint64
|
|
|
|
|
lastexceptionfromrip uint64
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-14 12:25:55 +11:00
|
|
|
func (c *context) ip() uintptr { return uintptr(c.rip) }
|
|
|
|
|
func (c *context) sp() uintptr { return uintptr(c.rsp) }
|
|
|
|
|
|
2018-08-08 14:44:42 -07:00
|
|
|
// Amd64 does not have link register, so this returns 0.
|
2018-11-21 14:04:29 -08:00
|
|
|
func (c *context) lr() uintptr { return 0 }
|
|
|
|
|
func (c *context) set_lr(x uintptr) {}
|
2018-08-08 14:44:42 -07:00
|
|
|
|
2018-11-21 14:04:29 -08:00
|
|
|
func (c *context) set_ip(x uintptr) { c.rip = uint64(x) }
|
|
|
|
|
func (c *context) set_sp(x uintptr) { c.rsp = uint64(x) }
|
2015-01-14 12:25:55 +11:00
|
|
|
|
2015-02-12 12:14:02 +11:00
|
|
|
func dumpregs(r *context) {
|
|
|
|
|
print("rax ", hex(r.rax), "\n")
|
|
|
|
|
print("rbx ", hex(r.rbx), "\n")
|
|
|
|
|
print("rcx ", hex(r.rcx), "\n")
|
|
|
|
|
print("rdi ", hex(r.rdi), "\n")
|
|
|
|
|
print("rsi ", hex(r.rsi), "\n")
|
|
|
|
|
print("rbp ", hex(r.rbp), "\n")
|
|
|
|
|
print("rsp ", hex(r.rsp), "\n")
|
|
|
|
|
print("r8 ", hex(r.r8), "\n")
|
|
|
|
|
print("r9 ", hex(r.r9), "\n")
|
|
|
|
|
print("r10 ", hex(r.r10), "\n")
|
|
|
|
|
print("r11 ", hex(r.r11), "\n")
|
|
|
|
|
print("r12 ", hex(r.r12), "\n")
|
|
|
|
|
print("r13 ", hex(r.r13), "\n")
|
|
|
|
|
print("r14 ", hex(r.r14), "\n")
|
|
|
|
|
print("r15 ", hex(r.r15), "\n")
|
|
|
|
|
print("rip ", hex(r.rip), "\n")
|
|
|
|
|
print("rflags ", hex(r.eflags), "\n")
|
|
|
|
|
print("cs ", hex(r.segcs), "\n")
|
|
|
|
|
print("fs ", hex(r.segfs), "\n")
|
|
|
|
|
print("gs ", hex(r.seggs), "\n")
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-11 17:07:37 -05:00
|
|
|
type overlapped struct {
|
|
|
|
|
internal uint64
|
|
|
|
|
internalhigh uint64
|
|
|
|
|
anon0 [8]byte
|
|
|
|
|
hevent *byte
|
|
|
|
|
}
|
runtime: query thread stack size from OS on Windows
Currently, on Windows, the thread stack size is set or assumed in many
different places. In non-cgo binaries, both the Go linker and the
runtime have a copy of the stack size, the Go linker sets the size of
the main thread stack, and the runtime sets the size of other thread
stacks. In cgo binaries, the external linker sets the main thread
stack size, the runtime assumes the size of the main thread stack will
be the same as used by the Go linker, and the cgo entry code assumes
the same.
Furthermore, users can change the main thread stack size using
editbin, so the runtime doesn't even really know what size it is, and
user C code can create threads with unknown thread stack sizes, which
we also assume have the same default stack size.
This is all a mess.
Fix the corner cases of this and the duplication of knowledge between
the linker and the runtime by querying the OS for the stack bounds
during thread setup. Furthermore, we unify all of this into just
runtime.minit for both cgo and non-cgo binaries and for the main
thread, other runtime-created threads, and C-created threads.
Updates #20975.
Change-Id: I45dbee2b5ea2ae721a85a27680737ff046f9d464
Reviewed-on: https://go-review.googlesource.com/120336
Run-TryBot: Austin Clements <austin@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Alex Brainman <alex.brainman@gmail.com>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2018-06-21 12:08:36 -04:00
|
|
|
|
|
|
|
|
type memoryBasicInformation struct {
|
|
|
|
|
baseAddress uintptr
|
|
|
|
|
allocationBase uintptr
|
|
|
|
|
allocationProtect uint32
|
|
|
|
|
regionSize uintptr
|
|
|
|
|
state uint32
|
|
|
|
|
protect uint32
|
|
|
|
|
type_ uint32
|
|
|
|
|
}
|