Skip to content

Commit cd58f44

Browse files
committed
runtime/cgo: assume Solaris thread stack is at least 1 MB
When run with "ulimit -s unlimited", the misc/cgo/test test binary finds a stack size of 0x3000 returned by getcontext, causing the runtime to try to stay within those bounds and then fault when called back in the test after 64 kB has been used by C. I suspect that Solaris is doing something clever like reporting the current stack size and growing the stack as faults happen. On all the other systems, getcontext reports the maximum stack size. And when the ulimit is not unlimited, even Solaris reports the maximum stack size. Work around this by assuming that any stack on Solaris must be at least 1 MB. Fixes #12210. Change-Id: I0a6ed0afb8a8f50aa1b2486f32b4ae470ab47dbf Reviewed-on: https://go-review.googlesource.com/17452 Reviewed-by: Ian Lance Taylor <[email protected]>
1 parent 5c24832 commit cd58f44

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/runtime/cgo/gcc_solaris_amd64.c

+6
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ x_cgo_init(G *g, void (*setg)(void*))
2020
if (getcontext(&ctx) != 0)
2121
perror("runtime/cgo: getcontext failed");
2222
g->stacklo = (uintptr_t)ctx.uc_stack.ss_sp;
23+
24+
// Solaris processes report a tiny stack when run with "ulimit -s unlimited".
25+
// Correct that as best we can: assume it's at least 1 MB.
26+
// See golang.org/issue/12210.
27+
if(ctx.uc_stack.ss_size < 1024*1024)
28+
g->stacklo -= 1024*1024 - ctx.uc_stack.ss_size;
2329
}
2430

2531
void

0 commit comments

Comments
 (0)