From 8a6c64f4fe726c956ea876cea0fed9494290130f Mon Sep 17 00:00:00 2001 From: qmuntal Date: Thu, 2 Oct 2025 15:12:30 +0200 Subject: syscall: use rawSyscall6 to call ptrace in forkAndExecInChild On darwin and openbsd, the autogenerated ptrace wrapper is nosplit because it is called from forkAndExecInChild. This makes it difficult to modify and improve the underlying syscall mechanism, as ptrace is almost over the nosplit limit. We better call ptrace directly using rawSyscall6 in forkAndExecInChild so that we can lift the ptrace nosplit restriction to. Doing so also fixes a long-standing inconsistency: forkAndExecInChild is documented to only allow rawSyscall, but the ptrace wrapper is using non-raw syscalls. Updates #64113 Change-Id: Ibbbb218511561c1a5cb5b6d288a691f9738b14a6 Reviewed-on: https://go-review.googlesource.com/c/go/+/708575 Reviewed-by: Michael Pratt Reviewed-by: David Chase LUCI-TryBot-Result: Go LUCI --- src/syscall/exec_libc2.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'src/syscall/exec_libc2.go') diff --git a/src/syscall/exec_libc2.go b/src/syscall/exec_libc2.go index a0579627a3..5de09dfe99 100644 --- a/src/syscall/exec_libc2.go +++ b/src/syscall/exec_libc2.go @@ -59,7 +59,6 @@ func forkAndExecInChild(argv0 *byte, argv, envv []*byte, chroot, dir *byte, attr r1 uintptr nextfd int i int - err error pgrp _C_int cred *Credential ngroups, groups uintptr @@ -99,8 +98,12 @@ func forkAndExecInChild(argv0 *byte, argv, envv []*byte, chroot, dir *byte, attr // Enable tracing if requested. if sys.Ptrace { - if err = ptrace(PTRACE_TRACEME, 0, 0, 0); err != nil { - err1 = err.(Errno) + if runtime.GOOS == "ios" { + err1 = ENOSYS + goto childerror + } + _, _, err1 = rawSyscall6(abi.FuncPCABI0(libc_ptrace_trampoline), PTRACE_TRACEME, 0, 0, 0, 0, 0) + if err1 != 0 { goto childerror } } -- cgit v1.3