Skip to content

Commit 351555f

Browse files
committed
syscall: add //go:norace to rawSyscall on darwin
On darwin, rawSyscall, rawSyscall6, and rawSyscall9 are Go functions (not assembly as on Linux) that get race-detector instrumentation. When forkAndExecInChild calls rawSyscall in the forked child process, the TSan ThreadState pointer is invalid, causing SIGSEGV in TraceSwitchPartImpl. Add //go:norace to these functions so the race detector does not instrument them. Also update the stale comment in exec_libc2.go that referred to rawSyscall as assembly. Fixes #79804
1 parent 2ce1819 commit 351555f

2 files changed

Lines changed: 6 additions & 2 deletions

File tree

src/syscall/exec_libc2.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,9 @@ func runtime_AfterForkInChild()
4848
// they might have been locked at the time of the fork. This means
4949
// no rescheduling, no malloc calls, and no new stack segments.
5050
// For the same reason compiler does not race instrument it.
51-
// The calls to rawSyscall are okay because they are assembly
52-
// functions that do not grow the stack.
51+
// The calls to rawSyscall are okay because they are nosplit
52+
// functions that do not grow the stack and are not race
53+
// instrumented (go:norace).
5354
//
5455
//go:norace
5556
func forkAndExecInChild(argv0 *byte, argv, envv []*byte, chroot, dir *byte, attr *ProcAttr, sys *SysProcAttr, pipe int) (pid int, err1 Errno) {

src/syscall/syscall_darwin.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,7 @@ func syscall9(fn, a1, a2, a3, a4, a5, a6, a7, a8, a9 uintptr) (r1, r2 uintptr, e
409409

410410
//go:linkname rawSyscall
411411
//go:nosplit
412+
//go:norace
412413
//go:uintptrkeepalive
413414
func rawSyscall(fn, a1, a2, a3 uintptr) (r1, r2 uintptr, err Errno) {
414415
r1, r2, err = rawsyscalln(fn, a1, a2, a3)
@@ -417,6 +418,7 @@ func rawSyscall(fn, a1, a2, a3 uintptr) (r1, r2 uintptr, err Errno) {
417418

418419
//go:linkname rawSyscall6
419420
//go:nosplit
421+
//go:norace
420422
//go:uintptrkeepalive
421423
func rawSyscall6(fn, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2 uintptr, err Errno) {
422424
r1, r2, err = rawsyscalln(fn, a1, a2, a3, a4, a5, a6)
@@ -425,6 +427,7 @@ func rawSyscall6(fn, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2 uintptr, err Errno)
425427

426428
//go:linkname rawSyscall9
427429
//go:nosplit
430+
//go:norace
428431
//go:uintptrkeepalive
429432
func rawSyscall9(fn, a1, a2, a3, a4, a5, a6, a7, a8, a9 uintptr) (r1, r2 uintptr, err Errno) {
430433
r1, r2, err = rawsyscalln(fn, a1, a2, a3, a4, a5, a6, a7, a8, a9)

0 commit comments

Comments
 (0)