syscall: only compile ptrace varargs shim on Linux

Only compile the __go_ptrace varargs shim on Linux to avoid compilation
failures on some other platforms. The C ptrace function is not entirely
portable (e.g., NetBSD has `int data` instead of `void* data`), and so
far Linux is the only platform that needs the varargs shim.

Additionally, make the types in the ptrace and raw_ptrace function
declarations match. This makes it more clear that the only difference
between the two is that calls via the former are allowed to block while
calls via the latter are not.

Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/263517
This commit is contained in:
Nikhil Benesch 2020-10-18 19:28:54 +00:00 committed by Ian Lance Taylor
parent d5d9706f95
commit 439407aa2c
14 changed files with 18 additions and 19 deletions

View File

@ -1,4 +1,4 @@
64c25b2365f7125a32b3146618b627f26a78c1fc
fa66bd11bbe58943e273cfa74356771c996f5b24
The first line of this file holds the git revision number of the last
merge done from the gofrontend repository.

View File

@ -93,7 +93,7 @@ func forkAndExecInChild(argv0 *byte, argv, envv []*byte, chroot, dir *byte, attr
// Enable tracing if requested.
if sys.Ptrace {
err1 = raw_ptrace(_PTRACE_TRACEME, 0, nil, nil)
err1 = raw_ptrace(_PTRACE_TRACEME, 0, 0, 0)
if err1 != 0 {
goto childerror
}

View File

@ -538,7 +538,7 @@ func forkAndExecInChild1(argv0 *byte, argv, envv []*byte, chroot, dir *byte, att
// Do this right before exec so that we don't unnecessarily trace the runtime
// setting up after the fork. See issue #21428.
if sys.Ptrace {
err1 = raw_ptrace(_PTRACE_TRACEME, 0, nil, nil)
err1 = raw_ptrace(_PTRACE_TRACEME, 0, 0, 0)
if err1 != 0 {
goto childerror
}

View File

@ -30,6 +30,6 @@ func (w WaitStatus) Signal() int { return 0 }
func (w WaitStatus) StopSignal() int { return 0 }
func (w WaitStatus) TrapCause() int { return 0 }
func raw_ptrace(request int, pid int, addr *byte, data *byte) Errno {
func raw_ptrace(request int, pid int, addr uintptr, data uintptr) Errno {
return ENOSYS
}

View File

@ -19,7 +19,7 @@ const SYS_EXECVE = 0
//sys ptrace64(request int, id int64, addr int64, data int, buff uintptr) (err error)
//ptrace64(request _C_int, id int64, addr int64, data _C_int, buff *byte) _C_int
func raw_ptrace(request int, pid int, addr *byte, data *byte) Errno {
func raw_ptrace(request int, pid int, addr uintptr, data uintptr) Errno {
if request == _PTRACE_TRACEME {
// Convert to AIX ptrace call.
err := ptrace64(_PT_TRACE_ME, 0, 0, 0, 0)

View File

@ -31,9 +31,6 @@ func Futimes(fd int, tv []Timeval) (err error) {
return Utimes("/proc/self/fd/"+itoa(fd), tv)
}
//sys ptrace(request int, pid int, addr uintptr, data uintptr) (err error)
//__go_ptrace(request _C_int, pid Pid_t, addr *byte, data *byte) _C_long
//sys accept4(fd int, sa *RawSockaddrAny, len *Socklen_t, flags int) (nfd int, err error)
//accept4(fd _C_int, sa *RawSockaddrAny, len *Socklen_t, flags _C_int) _C_int

View File

@ -7,7 +7,7 @@
package syscall
// Dummy function
func raw_ptrace(request int, pid int, addr *byte, data *byte) Errno {
func raw_ptrace(request int, pid int, addr uintptr, data uintptr) Errno {
return ENOSYS
}

View File

@ -6,5 +6,5 @@
package syscall
//sysnb raw_ptrace(request int, pid int, addr *byte, data *byte) (err Errno)
//sysnb raw_ptrace(request int, pid int, addr uintptr, data uintptr) (err Errno)
//ptrace(request _C_int, pid Pid_t, addr *byte, data *byte) _C_long

View File

@ -10,7 +10,10 @@ import (
"unsafe"
)
//sysnb raw_ptrace(request int, pid int, addr *byte, data *byte) (err Errno)
//sys ptrace(request int, pid int, addr uintptr, data uintptr) (err Errno)
//__go_ptrace(request _C_int, pid Pid_t, addr *byte, data *byte) _C_long
//sysnb raw_ptrace(request int, pid int, addr uintptr, data uintptr) (err Errno)
//__go_ptrace(request _C_int, pid Pid_t, addr *byte, data *byte) _C_long
func ptracePeek(req int, pid int, addr uintptr, out []byte) (count int, err error) {

View File

@ -8,5 +8,5 @@ package syscall
//sysnb Uname(buf *Utsname) (err error)
//_nuname(buf *Utsname) _C_int
//sysnb raw_ptrace(request int, pid int, addr *byte, data *byte) (err Errno)
//sysnb raw_ptrace(request int, pid int, addr uintptr, data uintptr) (err Errno)
//ptrace(request _C_int, pid Pid_t, addr *byte, data *byte) _C_long

View File

@ -5,6 +5,6 @@
package syscall
// 64-bit ptrace(3C) doesn't exist
func raw_ptrace(request int, pid int, addr *byte, data *byte) Errno {
func raw_ptrace(request int, pid int, addr uintptr, data uintptr) Errno {
return ENOSYS
}

View File

@ -4,5 +4,5 @@
package syscall
//sysnb raw_ptrace(request int, pid int, addr *byte, data *byte) (err Errno)
//sysnb raw_ptrace(request int, pid int, addr uintptr, data uintptr) (err Errno)
//ptrace(request _C_int, pid Pid_t, addr *byte, data *byte) _C_long

View File

@ -5,6 +5,6 @@
package syscall
// 64-bit ptrace(3C) doesn't exist
func raw_ptrace(request int, pid int, addr *byte, data *byte) Errno {
func raw_ptrace(request int, pid int, addr uintptr, data uintptr) Errno {
return ENOSYS
}

View File

@ -114,12 +114,11 @@ __go_syscall6(uintptr_t flag, uintptr_t a1, uintptr_t a2, uintptr_t a3,
#endif
// AIX ptrace is really different from Linux ptrace. Let syscall
// package handles it.
#if defined(HAVE_SYS_PTRACE_H) && !defined(_AIX)
#if defined(HAVE_SYS_PTRACE_H) && defined(__linux__)
// Despite documented appearances, this is actually implemented as
// a variadic function within glibc.
// a variadic function within glibc on Linux.
long
__go_ptrace(int request, pid_t pid, void *addr, void *data)