mirror of
https://github.com/golang/go
synced 2024-09-29 09:24:28 -06:00
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 <mknyszek@google.com> Run-TryBot: Cherry Mui <cherryyz@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
This commit is contained in:
parent
7e5b7d7720
commit
4956c3437b
@ -85,6 +85,9 @@ if($ARGV[0] =~ /^-/) {
|
||||
if($libc) {
|
||||
$extraimports = 'import "internal/abi"';
|
||||
}
|
||||
if($darwin) {
|
||||
$extraimports .= "\nimport \"runtime\"";
|
||||
}
|
||||
|
||||
sub parseparamlist($) {
|
||||
my ($list) = @_;
|
||||
@ -137,7 +140,7 @@ while(<>) {
|
||||
# without reading the header.
|
||||
$text .= "// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT\n\n";
|
||||
|
||||
if (($darwin && $func =~ /^ptrace1(Ptr)?$/) || (($openbsd && $libc) && $func =~ /^ptrace(Ptr)?$/)) {
|
||||
if ((($darwin || ($openbsd && $libc)) && $func =~ /^ptrace(Ptr)?$/)) {
|
||||
# The ptrace function is called from forkAndExecInChild where stack
|
||||
# growth is forbidden.
|
||||
$text .= "//go:nosplit\n"
|
||||
@ -147,6 +150,13 @@ while(<>) {
|
||||
my $out_decl = @out ? sprintf(" (%s)", join(', ', @out)) : "";
|
||||
$text .= sprintf "func %s(%s)%s {\n", $func, join(', ', @in), $out_decl;
|
||||
|
||||
# Disable ptrace on iOS.
|
||||
if ($darwin && $func =~ /^ptrace(Ptr)?$/) {
|
||||
$text .= "\tif runtime.GOOS == \"ios\" {\n";
|
||||
$text .= "\t\tpanic(\"unimplemented\")\n";
|
||||
$text .= "\t}\n";
|
||||
}
|
||||
|
||||
# Check if err return available
|
||||
my $errvar = "";
|
||||
foreach my $p (@out) {
|
||||
|
@ -1,14 +0,0 @@
|
||||
// Copyright 2020 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
//go:build !ios
|
||||
|
||||
package syscall
|
||||
|
||||
// Nosplit because it is called from forkAndExecInChild.
|
||||
//
|
||||
//go:nosplit
|
||||
func ptrace(request int, pid int, addr uintptr, data uintptr) error {
|
||||
return ptrace1(request, pid, addr, data)
|
||||
}
|
@ -1,14 +0,0 @@
|
||||
// Copyright 2020 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
//go:build ios
|
||||
|
||||
package syscall
|
||||
|
||||
// Nosplit because it is called from forkAndExecInChild.
|
||||
//
|
||||
//go:nosplit
|
||||
func ptrace(request int, pid int, addr uintptr, data uintptr) (err error) {
|
||||
panic("unimplemented")
|
||||
}
|
@ -24,7 +24,7 @@ func setTimeval(sec, usec int64) Timeval {
|
||||
//sys Stat(path string, stat *Stat_t) (err error) = SYS_stat64
|
||||
//sys Statfs(path string, stat *Statfs_t) (err error) = SYS_statfs64
|
||||
//sys fstatat(fd int, path string, stat *Stat_t, flags int) (err error) = SYS_fstatat64
|
||||
//sys ptrace1(request int, pid int, addr uintptr, data uintptr) (err error) = SYS_ptrace
|
||||
//sys ptrace(request int, pid int, addr uintptr, data uintptr) (err error)
|
||||
|
||||
func SetKevent(k *Kevent_t, fd, mode, flags int) {
|
||||
k.Ident = uint64(fd)
|
||||
|
@ -24,7 +24,7 @@ func setTimeval(sec, usec int64) Timeval {
|
||||
//sys Stat(path string, stat *Stat_t) (err error)
|
||||
//sys Statfs(path string, stat *Statfs_t) (err error)
|
||||
//sys fstatat(fd int, path string, stat *Stat_t, flags int) (err error)
|
||||
//sys ptrace1(request int, pid int, addr uintptr, data uintptr) (err error) = SYS_ptrace
|
||||
//sys ptrace(request int, pid int, addr uintptr, data uintptr) (err error)
|
||||
|
||||
func SetKevent(k *Kevent_t, fd, mode, flags int) {
|
||||
k.Ident = uint64(fd)
|
||||
|
@ -7,6 +7,7 @@ package syscall
|
||||
|
||||
import "unsafe"
|
||||
import "internal/abi"
|
||||
import "runtime"
|
||||
|
||||
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
|
||||
|
||||
@ -2011,7 +2012,10 @@ func libc_fstatat64_trampoline()
|
||||
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
|
||||
|
||||
//go:nosplit
|
||||
func ptrace1(request int, pid int, addr uintptr, data uintptr) (err error) {
|
||||
func ptrace(request int, pid int, addr uintptr, data uintptr) (err error) {
|
||||
if runtime.GOOS == "ios" {
|
||||
panic("unimplemented")
|
||||
}
|
||||
_, _, e1 := syscall6(abi.FuncPCABI0(libc_ptrace_trampoline), uintptr(request), uintptr(pid), uintptr(addr), uintptr(data), 0, 0)
|
||||
if e1 != 0 {
|
||||
err = errnoErr(e1)
|
||||
|
@ -7,6 +7,7 @@ package syscall
|
||||
|
||||
import "unsafe"
|
||||
import "internal/abi"
|
||||
import "runtime"
|
||||
|
||||
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
|
||||
|
||||
@ -2011,7 +2012,10 @@ func libc_fstatat_trampoline()
|
||||
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
|
||||
|
||||
//go:nosplit
|
||||
func ptrace1(request int, pid int, addr uintptr, data uintptr) (err error) {
|
||||
func ptrace(request int, pid int, addr uintptr, data uintptr) (err error) {
|
||||
if runtime.GOOS == "ios" {
|
||||
panic("unimplemented")
|
||||
}
|
||||
_, _, e1 := syscall6(abi.FuncPCABI0(libc_ptrace_trampoline), uintptr(request), uintptr(pid), uintptr(addr), uintptr(data), 0, 0)
|
||||
if e1 != 0 {
|
||||
err = errnoErr(e1)
|
||||
|
Loading…
Reference in New Issue
Block a user