]> Cypherpunks repositories - gostls13.git/commitdiff
runtime/cgo: assume Solaris thread stack is at least 1 MB
authorRuss Cox <rsc@golang.org>
Fri, 4 Dec 2015 21:10:15 +0000 (16:10 -0500)
committerRuss Cox <rsc@golang.org>
Sat, 5 Dec 2015 03:56:06 +0000 (03:56 +0000)
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 <iant@golang.org>
src/runtime/cgo/gcc_solaris_amd64.c

index 72ace56c07121f2372af6bd0caedcd1e87984ab9..98a1a8be532a3bf9cebee1f86adf14bdb64f9b72 100644 (file)
@@ -20,6 +20,12 @@ x_cgo_init(G *g, void (*setg)(void*))
        if (getcontext(&ctx) != 0)
                perror("runtime/cgo: getcontext failed");
        g->stacklo = (uintptr_t)ctx.uc_stack.ss_sp;
+
+       // Solaris processes report a tiny stack when run with "ulimit -s unlimited".
+       // Correct that as best we can: assume it's at least 1 MB.
+       // See golang.org/issue/12210.
+       if(ctx.uc_stack.ss_size < 1024*1024)
+               g->stacklo -= 1024*1024 - ctx.uc_stack.ss_size;
 }
 
 void