aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/cgo
diff options
context:
space:
mode:
authorAustin Clements <austin@google.com>2018-06-20 16:25:41 -0400
committerAustin Clements <austin@google.com>2018-07-02 15:18:24 +0000
commit52e782a2d6e83065e394d127ea5df20e4aaaa8af (patch)
treea3f7e1792e44421e855f208792b78831e0d5616e /src/runtime/cgo
parentb55fe6a3702922f35b8d440f32fd5a54ee92f5f8 (diff)
downloadgo-52e782a2d6e83065e394d127ea5df20e4aaaa8af.tar.xz
runtime: initialize g0 stack bounds on Windows to full stack
Currently, we allocate 1MB or 2MB thread stacks on Windows, but in non-cgo binaries still set the g0 stack bounds assuming only 64k is available. While this is fine in pure Go binaries, a non-cgo Go binary on Windows can use the syscall package to call arbitrary DLLs, which may call back into Go. If a DLL function uses more than 64k of stack and then calls back into Go, the Go runtime will believe that it's out of stack space and crash. Fix this by plumbing the correct stack size into the g0 stacks of non-cgo binaries. Cgo binaries already use the correct size because their g0 stack sizes are set by a different code path. Fixes #20975. Change-Id: Id6fb559cfe1e1ea0dfac56d4654865c20dccf68d Reviewed-on: https://go-review.googlesource.com/120195 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>
Diffstat (limited to 'src/runtime/cgo')
-rw-r--r--src/runtime/cgo/gcc_windows_386.c2
-rw-r--r--src/runtime/cgo/gcc_windows_amd64.c2
2 files changed, 2 insertions, 2 deletions
diff --git a/src/runtime/cgo/gcc_windows_386.c b/src/runtime/cgo/gcc_windows_386.c
index fa0c69bc13..e80a564943 100644
--- a/src/runtime/cgo/gcc_windows_386.c
+++ b/src/runtime/cgo/gcc_windows_386.c
@@ -13,7 +13,7 @@ static void threadentry(void*);
/* 1MB is default stack size for 32-bit Windows.
Allocation granularity on Windows is typically 64 KB.
- The constant is also hardcoded in cmd/ld/pe.c (keep synchronized). */
+ This constant must match SizeOfStackReserve in ../cmd/link/internal/ld/pe.go. */
#define STACKSIZE (1*1024*1024)
void
diff --git a/src/runtime/cgo/gcc_windows_amd64.c b/src/runtime/cgo/gcc_windows_amd64.c
index a3c3896edf..75a7dc8ec2 100644
--- a/src/runtime/cgo/gcc_windows_amd64.c
+++ b/src/runtime/cgo/gcc_windows_amd64.c
@@ -13,7 +13,7 @@ static void threadentry(void*);
/* 2MB is default stack size for 64-bit Windows.
Allocation granularity on Windows is typically 64 KB.
- The constant is also hardcoded in cmd/ld/pe.c (keep synchronized). */
+ This constant must match SizeOfStackReserve in ../cmd/link/internal/ld/pe.go. */
#define STACKSIZE (2*1024*1024)
void