From fe057c1478c4309f715d689127125cabbb4efe08 Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Wed, 16 Nov 2016 13:51:32 -0800 Subject: [PATCH] runtime/cgo: fixes for calling sigaction in C 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 TryBot-Result: Gobot Gobot Reviewed-by: Brad Fitzpatrick Reviewed-by: Bryan Mills --- src/runtime/cgo/gcc_sigaction.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/runtime/cgo/gcc_sigaction.c b/src/runtime/cgo/gcc_sigaction.c index aab13373391..5aca2710bd4 100644 --- a/src/runtime/cgo/gcc_sigaction.c +++ b/src/runtime/cgo/gcc_sigaction.c @@ -7,6 +7,7 @@ #include #include #include +#include #include // 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);