Skip to content

Commit a8dd20d

Browse files
author
Bryan C. Mills
committed
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 <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]> Reviewed-by: Dmitry Vyukov <[email protected]>
1 parent c31231c commit a8dd20d

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/runtime/cgo/gcc_sigaction.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
#include <string.h>
1111
#include <signal.h>
1212

13+
#include "libcgo.h"
14+
1315
// go_sigaction_t is a C version of the sigactiont struct from
1416
// defs_linux_amd64.go. This definition — and its conversion to and from struct
1517
// 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
3335
struct sigaction oldact;
3436
int i;
3537

38+
_cgo_tsan_acquire();
39+
3640
memset(&act, 0, sizeof act);
3741
memset(&oldact, 0, sizeof oldact);
3842

@@ -53,7 +57,8 @@ x_cgo_sigaction(intptr_t signum, const go_sigaction_t *goact, go_sigaction_t *ol
5357

5458
ret = sigaction(signum, goact ? &act : NULL, oldgoact ? &oldact : NULL);
5559
if (ret == -1) {
56-
/* This is what the Go code expects on failure. */
60+
// runtime.rt_sigaction expects _cgo_sigaction to return errno on error.
61+
_cgo_tsan_release();
5762
return errno;
5863
}
5964

@@ -72,5 +77,6 @@ x_cgo_sigaction(intptr_t signum, const go_sigaction_t *goact, go_sigaction_t *ol
7277
oldgoact->flags = oldact.sa_flags;
7378
}
7479

80+
_cgo_tsan_release();
7581
return ret;
7682
}

0 commit comments

Comments
 (0)