Skip to content

Commit fe057c1

Browse files
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 <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Brad Fitzpatrick <[email protected]> Reviewed-by: Bryan Mills <[email protected]>
1 parent 8dc47e3 commit fe057c1

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/runtime/cgo/gcc_sigaction.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <errno.h>
88
#include <stddef.h>
99
#include <stdint.h>
10+
#include <string.h>
1011
#include <signal.h>
1112

1213
// go_sigaction_t is a C version of the sigactiont struct from
@@ -19,13 +20,22 @@ typedef struct {
1920
uint64_t mask;
2021
} go_sigaction_t;
2122

23+
// SA_RESTORER is part of the kernel interface.
24+
// This is GNU/Linux i386/amd64 specific.
25+
#ifndef SA_RESTORER
26+
#define SA_RESTORER 0x4000000
27+
#endif
28+
2229
int32_t
2330
x_cgo_sigaction(intptr_t signum, const go_sigaction_t *goact, go_sigaction_t *oldgoact) {
2431
int32_t ret;
2532
struct sigaction act;
2633
struct sigaction oldact;
2734
int i;
2835

36+
memset(&act, 0, sizeof act);
37+
memset(&oldact, 0, sizeof oldact);
38+
2939
if (goact) {
3040
if (goact->flags & SA_SIGINFO) {
3141
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
3848
sigaddset(&act.sa_mask, i+1);
3949
}
4050
}
41-
act.sa_flags = goact->flags;
51+
act.sa_flags = goact->flags & ~SA_RESTORER;
4252
}
4353

4454
ret = sigaction(signum, goact ? &act : NULL, oldgoact ? &oldact : NULL);

0 commit comments

Comments
 (0)