Commit fe057c14 authored by Ian Lance Taylor's avatar Ian Lance Taylor

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 <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: default avatarBrad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: default avatarBryan Mills <bcmills@google.com>
parent 8dc47e3b
......@@ -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);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment