Skip to content

Commit 8a6c64f

Browse files
committed
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 <mpratt@google.com> Reviewed-by: David Chase <drchase@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
1 parent 4620db7 commit 8a6c64f

10 files changed

+6
-17
lines changed

src/syscall/exec_libc2.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ func forkAndExecInChild(argv0 *byte, argv, envv []*byte, chroot, dir *byte, attr
5959
r1 uintptr
6060
nextfd int
6161
i int
62-
err error
6362
pgrp _C_int
6463
cred *Credential
6564
ngroups, groups uintptr
@@ -99,8 +98,12 @@ func forkAndExecInChild(argv0 *byte, argv, envv []*byte, chroot, dir *byte, attr
9998

10099
// Enable tracing if requested.
101100
if sys.Ptrace {
102-
if err = ptrace(PTRACE_TRACEME, 0, 0, 0); err != nil {
103-
err1 = err.(Errno)
101+
if runtime.GOOS == "ios" {
102+
err1 = ENOSYS
103+
goto childerror
104+
}
105+
_, _, err1 = rawSyscall6(abi.FuncPCABI0(libc_ptrace_trampoline), PTRACE_TRACEME, 0, 0, 0, 0, 0)
106+
if err1 != 0 {
104107
goto childerror
105108
}
106109
}

src/syscall/mksyscall.pl

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -141,12 +141,6 @@ ($)
141141
# without reading the header.
142142
$text .= "// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT\n\n";
143143

144-
if ((($darwin || ($openbsd && $libc)) && $func =~ /^ptrace(Ptr)?$/)) {
145-
# The ptrace function is called from forkAndExecInChild where stack
146-
# growth is forbidden.
147-
$text .= "//go:nosplit\n"
148-
}
149-
150144
# Go function header.
151145
my $out_decl = @out ? sprintf(" (%s)", join(', ', @out)) : "";
152146
$text .= sprintf "func %s(%s)%s {\n", $func, join(', ', @in), $out_decl;

src/syscall/zsyscall_darwin_amd64.go

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/syscall/zsyscall_darwin_arm64.go

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/syscall/zsyscall_openbsd_386.go

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/syscall/zsyscall_openbsd_amd64.go

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/syscall/zsyscall_openbsd_arm.go

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/syscall/zsyscall_openbsd_arm64.go

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/syscall/zsyscall_openbsd_ppc64.go

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/syscall/zsyscall_openbsd_riscv64.go

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)