Commit 77ea9f9f authored by Austin Clements's avatar Austin Clements

runtime: always use 1MB stacks on 32-bit Windows

Commit c2c07c79 (CL 49331) changed the linker and runtime to always
use 2MB stacks on 64-bit Windows. This is the corresponding change to
make 32-bit Windows always use large (1MB) stacks because it's
difficult to detect when Windows applications will call into arbitrary
C code that may expect a large stack.

This is done as a separate change because it's possible this will
cause too much address space pressure for a 32-bit address space. On
the other hand, cgo binaries on Windows already use 1MB stacks and
there haven't been complaints.

Updates #20975.

Change-Id: I8ce583f07cb52254fb4bd47250f1ef2b789bc490
Reviewed-on: https://go-review.googlesource.com/49610
Run-TryBot: Austin Clements <austin@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: default avatarAlex Brainman <alex.brainman@gmail.com>
parent 78583a12
...@@ -857,14 +857,10 @@ func (f *peFile) writeOptionalHeader(ctxt *Link) { ...@@ -857,14 +857,10 @@ func (f *peFile) writeOptionalHeader(ctxt *Link) {
oh64.SizeOfStackCommit = 0x00200000 - 0x2000 // account for 2 guard pages oh64.SizeOfStackCommit = 0x00200000 - 0x2000 // account for 2 guard pages
} }
// 32-bit is trickier since there much less address space to oh.SizeOfStackReserve = 0x00100000
// work with. Here we use large stacks only in cgo binaries as
// a compromise.
if !iscgo { if !iscgo {
oh.SizeOfStackReserve = 0x00020000
oh.SizeOfStackCommit = 0x00001000 oh.SizeOfStackCommit = 0x00001000
} else { } else {
oh.SizeOfStackReserve = 0x00100000
oh.SizeOfStackCommit = 0x00100000 - 0x2000 // account for 2 guard pages oh.SizeOfStackCommit = 0x00100000 - 0x2000 // account for 2 guard pages
} }
......
...@@ -623,7 +623,7 @@ func semacreate(mp *m) { ...@@ -623,7 +623,7 @@ func semacreate(mp *m) {
func newosproc(mp *m, stk unsafe.Pointer) { func newosproc(mp *m, stk unsafe.Pointer) {
const _STACK_SIZE_PARAM_IS_A_RESERVATION = 0x00010000 const _STACK_SIZE_PARAM_IS_A_RESERVATION = 0x00010000
// stackSize must match SizeOfStackReserve in cmd/link/internal/ld/pe.go. // stackSize must match SizeOfStackReserve in cmd/link/internal/ld/pe.go.
const stackSize = 0x00200000*_64bit + 0x00020000*(1-_64bit) const stackSize = 0x00200000*_64bit + 0x00100000*(1-_64bit)
thandle := stdcall6(_CreateThread, 0, stackSize, thandle := stdcall6(_CreateThread, 0, stackSize,
funcPC(tstart_stdcall), uintptr(unsafe.Pointer(mp)), funcPC(tstart_stdcall), uintptr(unsafe.Pointer(mp)),
_STACK_SIZE_PARAM_IS_A_RESERVATION, 0) _STACK_SIZE_PARAM_IS_A_RESERVATION, 0)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment