]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: fix signal stack bug
authorRuss Cox <rsc@golang.org>
Thu, 24 Feb 2011 21:46:44 +0000 (13:46 -0800)
committerRuss Cox <rsc@golang.org>
Thu, 24 Feb 2011 21:46:44 +0000 (13:46 -0800)
In CL 4188061 I changed malg to allocate the requested
number of bytes n, not n+StackGuard, so that the
allocations would use rounder numbers.

The allocation of the signal stack asks for 32k and
then used g->stackguard as the base, but g->stackguard
is StackGuard bytes above the base.  Previously, asking
for 32k meant getting 32k+StackGuard bytes, so using
g->stackguard as the base was safe.  Now, the actual base
must be computed, so that the signal handler does not
run StackGuard bytes past the top of the stack.

Was causing flakiness mainly in programs that use the
network, because they sometimes write to closed network
connections, causing SIGPIPEs.  Was also causing problems
in the doc/progs test.

Also fix Makefile so that changes to stack.h trigger rebuild.

R=bradfitzgo, r, r2
CC=golang-dev
https://golang.org/cl/4230044

src/Make.pkg
src/pkg/runtime/Makefile
src/pkg/runtime/darwin/thread.c
src/pkg/runtime/freebsd/thread.c
src/pkg/runtime/linux/thread.c

index 435c8943da8e7625abdeffd9f5d3abe4a165ba71..549936e53af768b9c01430a1e756c24b76a2d7cc 100644 (file)
@@ -176,11 +176,9 @@ _cgo_defun.$O: _cgo_defun.c
 # Generic build rules.
 # These come last so that the rules above can override them
 # for more specific file names.
-%.$O: %.c
+%.$O: %.c $(HFILES)
        $(CC) $(CFLAGS) $*.c
 
 %.$O: %.s
        $(AS) $*.s
 
-%.$O: $(HFILES)
-
index 38e1aa61e370445a95f52778f9436872114e5a7e..185397f5708aacf4702806761d6f19f28859dbb7 100644 (file)
@@ -94,6 +94,7 @@ HFILES=\
        runtime.h\
        hashmap.h\
        malloc.h\
+       stack.h\
        $(GOARCH)/asm.h\
        $(GOOS)/os.h\
        $(GOOS)/signals.h\
@@ -141,13 +142,13 @@ version_$(GOOS).go:
        ./goc2c "`pwd`/$<" > $@.tmp
        mv -f $@.tmp $@
 
-%.$O:  $(GOARCH)/%.c
+%.$O:  $(GOARCH)/%.c $(HFILES)
        $(CC) $(CFLAGS) $<
 
-%.$O:  $(GOOS)/%.c
+%.$O:  $(GOOS)/%.c $(HFILES)
        $(CC) $(CFLAGS) $<
 
-%.$O:  $(GOOS)/$(GOARCH)/%.c
+%.$O:  $(GOOS)/$(GOARCH)/%.c $(HFILES)
        $(CC) $(CFLAGS) $<
 
 %.$O:  $(GOARCH)/%.s $(GOARCH)/asm.h
index 57e813109cc5cd9a72ae31ba411af7ea48de88bc..235d69abfc319193839448b75c128a9d83c11188 100644 (file)
@@ -5,6 +5,7 @@
 #include "runtime.h"
 #include "defs.h"
 #include "os.h"
+#include "stack.h"
 
 extern SigTab runtime·sigtab[];
 
@@ -176,7 +177,7 @@ runtime·minit(void)
 {
        // Initialize signal handling.
        m->gsignal = runtime·malg(32*1024);    // OS X wants >=8K, Linux >=2K
-       runtime·signalstack(m->gsignal->stackguard, 32*1024);
+       runtime·signalstack(m->gsignal->stackguard - StackGuard, 32*1024);
 }
 
 // Mach IPC, to get at semaphores
index 9bd8838335c40e830e27d88ec649f7b9115cb96b..569098aa218653e7e83987cda9e6bd71b6c7d68c 100644 (file)
@@ -4,6 +4,7 @@
 #include "runtime.h"
 #include "defs.h"
 #include "os.h"
+#include "stack.h"
 
 extern SigTab runtime·sigtab[];
 extern int32 runtime·sys_umtx_op(uint32*, int32, uint32, void*, void*);
@@ -175,7 +176,7 @@ runtime·minit(void)
 {
        // Initialize signal handling
        m->gsignal = runtime·malg(32*1024);
-       runtime·signalstack(m->gsignal->stackguard, 32*1024);
+       runtime·signalstack(m->gsignal->stackguard - StackGuard, 32*1024);
 }
 
 void
index d5f9a8fb0e371c50ec0026427690ee8310db4c7b..7166b0ef27f6af45c2b038dd2f4a9c5e65ebf207 100644 (file)
@@ -5,6 +5,7 @@
 #include "runtime.h"
 #include "defs.h"
 #include "os.h"
+#include "stack.h"
 
 extern SigTab runtime·sigtab[];
 
@@ -274,7 +275,7 @@ runtime·minit(void)
 {
        // Initialize signal handling.
        m->gsignal = runtime·malg(32*1024);    // OS X wants >=8K, Linux >=2K
-       runtime·signalstack(m->gsignal->stackguard, 32*1024);
+       runtime·signalstack(m->gsignal->stackguard - StackGuard, 32*1024);
 }
 
 void