]> Cypherpunks repositories - gostls13.git/commitdiff
runtime/cgo: fixes for calling sigaction in C
authorIan Lance Taylor <iant@golang.org>
Wed, 16 Nov 2016 21:51:32 +0000 (13:51 -0800)
committerIan Lance Taylor <iant@golang.org>
Wed, 16 Nov 2016 23:10:33 +0000 (23:10 +0000)
Zero out the sigaction structs, in case the sa_restorer field is set.

Clear the SA_RESTORER flag; it is part of the kernel interface, not the
libc interface.

Fixes #17947.

Change-Id: I610348ce3c196d3761cf2170f06c24ecc3507cf7
Reviewed-on: https://go-review.googlesource.com/33331
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Bryan Mills <bcmills@google.com>
src/runtime/cgo/gcc_sigaction.c

index aab13373391951c477b4587ec4fbdbb30c7a6546..5aca2710bd4883f05e16601ed9b3267ed91974fd 100644 (file)
@@ -7,6 +7,7 @@
 #include <errno.h>
 #include <stddef.h>
 #include <stdint.h>
+#include <string.h>
 #include <signal.h>
 
 // go_sigaction_t is a C version of the sigactiont struct from
@@ -19,6 +20,12 @@ typedef struct {
        uint64_t mask;
 } go_sigaction_t;
 
+// SA_RESTORER is part of the kernel interface.
+// This is GNU/Linux i386/amd64 specific.
+#ifndef SA_RESTORER
+#define SA_RESTORER 0x4000000
+#endif
+
 int32_t
 x_cgo_sigaction(intptr_t signum, const go_sigaction_t *goact, go_sigaction_t *oldgoact) {
        int32_t ret;
@@ -26,6 +33,9 @@ x_cgo_sigaction(intptr_t signum, const go_sigaction_t *goact, go_sigaction_t *ol
        struct sigaction oldact;
        int i;
 
+       memset(&act, 0, sizeof act);
+       memset(&oldact, 0, sizeof oldact);
+
        if (goact) {
                if (goact->flags & SA_SIGINFO) {
                        act.sa_sigaction = (void(*)(int, siginfo_t*, void*))(goact->handler);
@@ -38,7 +48,7 @@ x_cgo_sigaction(intptr_t signum, const go_sigaction_t *goact, go_sigaction_t *ol
                                sigaddset(&act.sa_mask, i+1);
                        }
                }
-               act.sa_flags = goact->flags;
+               act.sa_flags = goact->flags & ~SA_RESTORER;
        }
 
        ret = sigaction(signum, goact ? &act : NULL, oldgoact ? &oldact : NULL);