]> Cypherpunks repositories - gostls13.git/commit
runtime: query thread stack size from OS on Windows
authorAustin Clements <austin@google.com>
Thu, 21 Jun 2018 16:08:36 +0000 (12:08 -0400)
committerAustin Clements <austin@google.com>
Mon, 2 Jul 2018 15:18:26 +0000 (15:18 +0000)
commit99e9be804379d0607de4a322353b317aa087073d
tree8243a4b056bb7ef2674d2061dfed50054cd908f1
parent52e782a2d6e83065e394d127ea5df20e4aaaa8af
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>
18 files changed:
src/cmd/link/internal/ld/pe.go
src/cmd/vet/all/whitelist/386.txt
src/cmd/vet/all/whitelist/amd64.txt
src/cmd/vet/all/whitelist/nacl_amd64p32.txt
src/runtime/cgo/gcc_windows_386.c
src/runtime/cgo/gcc_windows_amd64.c
src/runtime/crash_cgo_test.go
src/runtime/defs_windows.go
src/runtime/defs_windows_386.go
src/runtime/defs_windows_amd64.go
src/runtime/os_windows.go
src/runtime/proc.go
src/runtime/stubs_x86.go [new file with mode: 0644]
src/runtime/sys_windows_386.s
src/runtime/sys_windows_amd64.s
src/runtime/syscall_windows_test.go
src/runtime/testdata/testprogcgo/bigstack_windows.c [new file with mode: 0644]
src/runtime/testdata/testprogcgo/bigstack_windows.go [new file with mode: 0644]