Commit a8dd20d3 authored by Bryan C. Mills's avatar Bryan C. Mills Committed by Bryan Mills

runtime/cgo: add TSAN annotations for C sigaction call

This avoids false-positive TSAN reports when using the C sigaction
function to read handlers registered by the Go runtime.

(Unfortunately, I can't seem to coax the runtime into reproducing the
failure in a small unit-test.)

Change-Id: I744279a163708e24b1fbe296ca691935c394b5f3
Reviewed-on: https://go-review.googlesource.com/44270
Run-TryBot: Bryan Mills <bcmills@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: default avatarIan Lance Taylor <iant@golang.org>
Reviewed-by: default avatarDmitry Vyukov <dvyukov@google.com>
parent c31231cc
...@@ -10,6 +10,8 @@ ...@@ -10,6 +10,8 @@
#include <string.h> #include <string.h>
#include <signal.h> #include <signal.h>
#include "libcgo.h"
// go_sigaction_t is a C version of the sigactiont struct from // go_sigaction_t is a C version of the sigactiont struct from
// defs_linux_amd64.go. This definition — and its conversion to and from struct // defs_linux_amd64.go. This definition — and its conversion to and from struct
// sigaction — are specific to linux/amd64. // sigaction — are specific to linux/amd64.
...@@ -33,6 +35,8 @@ x_cgo_sigaction(intptr_t signum, const go_sigaction_t *goact, go_sigaction_t *ol ...@@ -33,6 +35,8 @@ x_cgo_sigaction(intptr_t signum, const go_sigaction_t *goact, go_sigaction_t *ol
struct sigaction oldact; struct sigaction oldact;
int i; int i;
_cgo_tsan_acquire();
memset(&act, 0, sizeof act); memset(&act, 0, sizeof act);
memset(&oldact, 0, sizeof oldact); memset(&oldact, 0, sizeof oldact);
...@@ -53,7 +57,8 @@ x_cgo_sigaction(intptr_t signum, const go_sigaction_t *goact, go_sigaction_t *ol ...@@ -53,7 +57,8 @@ x_cgo_sigaction(intptr_t signum, const go_sigaction_t *goact, go_sigaction_t *ol
ret = sigaction(signum, goact ? &act : NULL, oldgoact ? &oldact : NULL); ret = sigaction(signum, goact ? &act : NULL, oldgoact ? &oldact : NULL);
if (ret == -1) { if (ret == -1) {
/* This is what the Go code expects on failure. */ // runtime.rt_sigaction expects _cgo_sigaction to return errno on error.
_cgo_tsan_release();
return errno; return errno;
} }
...@@ -72,5 +77,6 @@ x_cgo_sigaction(intptr_t signum, const go_sigaction_t *goact, go_sigaction_t *ol ...@@ -72,5 +77,6 @@ x_cgo_sigaction(intptr_t signum, const go_sigaction_t *goact, go_sigaction_t *ol
oldgoact->flags = oldact.sa_flags; oldgoact->flags = oldact.sa_flags;
} }
_cgo_tsan_release();
return ret; return ret;
} }
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