diff options
author | Russ Cox <rsc@golang.org> | 2019-06-05 12:31:42 -0400 |
---|---|---|
committer | Russ Cox <rsc@golang.org> | 2019-06-06 00:11:29 +0000 |
commit | c00ff65d016c07f7feb188ca0458ae3bae0f1532 (patch) | |
tree | 309125bbbc653cb3407df085c55a49e5b54964e0 /src/runtime/os_darwin.go | |
parent | e9073ef809895740b3e3876148af808c51c016d5 (diff) | |
download | go-c00ff65d016c07f7feb188ca0458ae3bae0f1532.tar.gz go-c00ff65d016c07f7feb188ca0458ae3bae0f1532.zip |
runtime: use default system stack size, not 64 kB, on non-cgo macOS
At least one libc call we make
(res_search, which calls _mdns_query and then mdns_item_call)
pushes a 64 kB stack frame onto the stack.
Then it faults on the guard page.
Use the default system stack size, under the assumption
that the C code being called is compatible with that stack size.
For #31705.
Change-Id: I1b0bfc2e54043c49f0709255988ef920ce30ee82
Reviewed-on: https://go-review.googlesource.com/c/go/+/180779
Run-TryBot: Russ Cox <rsc@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Diffstat (limited to 'src/runtime/os_darwin.go')
-rw-r--r-- | src/runtime/os_darwin.go | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/src/runtime/os_darwin.go b/src/runtime/os_darwin.go index 18c15ad89e..819aaaca70 100644 --- a/src/runtime/os_darwin.go +++ b/src/runtime/os_darwin.go @@ -145,14 +145,14 @@ func newosproc(mp *m) { exit(1) } - // Set the stack size we want to use. 64KB for now. - // TODO: just use OS default size? - const stackSize = 1 << 16 - if pthread_attr_setstacksize(&attr, stackSize) != 0 { + // Find out OS stack size for our own stack guard. + var stacksize uintptr + if pthread_attr_getstacksize(&attr, &stacksize) != 0 { write(2, unsafe.Pointer(&failthreadcreate[0]), int32(len(failthreadcreate))) exit(1) } - //mSysStatInc(&memstats.stacks_sys, stackSize) //TODO: do this? + mp.g0.stack.hi = stacksize // for mstart + //mSysStatInc(&memstats.stacks_sys, stacksize) //TODO: do this? // Tell the pthread library we won't join with this thread. if pthread_attr_setdetachstate(&attr, _PTHREAD_CREATE_DETACHED) != 0 { @@ -191,11 +191,16 @@ func newosproc0(stacksize uintptr, fn uintptr) { exit(1) } - // Set the stack we want to use. - if pthread_attr_setstacksize(&attr, stacksize) != 0 { + // The caller passes in a suggested stack size, + // from when we allocated the stack and thread ourselves, + // without libpthread. Now that we're using libpthread, + // we use the OS default stack size instead of the suggestion. + // Find out that stack size for our own stack guard. + if pthread_attr_getstacksize(&attr, &stacksize) != 0 { write(2, unsafe.Pointer(&failthreadcreate[0]), int32(len(failthreadcreate))) exit(1) } + g0.stack.hi = stacksize // for mstart mSysStatInc(&memstats.stacks_sys, stacksize) // Tell the pthread library we won't join with this thread. |