Skip to content

Commit 4956c34

Browse files
committed
syscall: remove ptrace1 on darwin
On Darwin, the ptrace syscall is called in ptrace1, which then be called in ptrace. This allows ptrace1 be disabled on iOS (by implementing ptrace differently). But we can also achieve this by adding a conditional directly in ptrace. This reduces stack usage with -N -l, while keeping ptrace disabled on iOS. For #64113. Change-Id: I89d8e317e77352fffdbb5a25ba21ee9cdf2e1e20 Reviewed-on: https://go-review.googlesource.com/c/go/+/545276 Reviewed-by: Michael Knyszek <[email protected]> Run-TryBot: Cherry Mui <[email protected]> TryBot-Result: Gopher Robot <[email protected]>
1 parent 7e5b7d7 commit 4956c34

File tree

7 files changed

+23
-33
lines changed

7 files changed

+23
-33
lines changed

src/syscall/mksyscall.pl

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,9 @@
8585
if($libc) {
8686
$extraimports = 'import "internal/abi"';
8787
}
88+
if($darwin) {
89+
$extraimports .= "\nimport \"runtime\"";
90+
}
8891

8992
sub parseparamlist($) {
9093
my ($list) = @_;
@@ -137,7 +140,7 @@ ($)
137140
# without reading the header.
138141
$text .= "// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT\n\n";
139142

140-
if (($darwin && $func =~ /^ptrace1(Ptr)?$/) || (($openbsd && $libc) && $func =~ /^ptrace(Ptr)?$/)) {
143+
if ((($darwin || ($openbsd && $libc)) && $func =~ /^ptrace(Ptr)?$/)) {
141144
# The ptrace function is called from forkAndExecInChild where stack
142145
# growth is forbidden.
143146
$text .= "//go:nosplit\n"
@@ -147,6 +150,13 @@ ($)
147150
my $out_decl = @out ? sprintf(" (%s)", join(', ', @out)) : "";
148151
$text .= sprintf "func %s(%s)%s {\n", $func, join(', ', @in), $out_decl;
149152

153+
# Disable ptrace on iOS.
154+
if ($darwin && $func =~ /^ptrace(Ptr)?$/) {
155+
$text .= "\tif runtime.GOOS == \"ios\" {\n";
156+
$text .= "\t\tpanic(\"unimplemented\")\n";
157+
$text .= "\t}\n";
158+
}
159+
150160
# Check if err return available
151161
my $errvar = "";
152162
foreach my $p (@out) {

src/syscall/ptrace_darwin.go

Lines changed: 0 additions & 14 deletions
This file was deleted.

src/syscall/ptrace_ios.go

Lines changed: 0 additions & 14 deletions
This file was deleted.

src/syscall/syscall_darwin_amd64.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ func setTimeval(sec, usec int64) Timeval {
2424
//sys Stat(path string, stat *Stat_t) (err error) = SYS_stat64
2525
//sys Statfs(path string, stat *Statfs_t) (err error) = SYS_statfs64
2626
//sys fstatat(fd int, path string, stat *Stat_t, flags int) (err error) = SYS_fstatat64
27-
//sys ptrace1(request int, pid int, addr uintptr, data uintptr) (err error) = SYS_ptrace
27+
//sys ptrace(request int, pid int, addr uintptr, data uintptr) (err error)
2828

2929
func SetKevent(k *Kevent_t, fd, mode, flags int) {
3030
k.Ident = uint64(fd)

src/syscall/syscall_darwin_arm64.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ func setTimeval(sec, usec int64) Timeval {
2424
//sys Stat(path string, stat *Stat_t) (err error)
2525
//sys Statfs(path string, stat *Statfs_t) (err error)
2626
//sys fstatat(fd int, path string, stat *Stat_t, flags int) (err error)
27-
//sys ptrace1(request int, pid int, addr uintptr, data uintptr) (err error) = SYS_ptrace
27+
//sys ptrace(request int, pid int, addr uintptr, data uintptr) (err error)
2828

2929
func SetKevent(k *Kevent_t, fd, mode, flags int) {
3030
k.Ident = uint64(fd)

src/syscall/zsyscall_darwin_amd64.go

Lines changed: 5 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: 5 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)