syscall: only compile ptrace varargs shim on Linux
authorNikhil Benesch <nikhil.benesch@gmail.com>
Sun, 18 Oct 2020 19:28:54 +0000 (19:28 +0000)
committerIan Lance Taylor <iant@golang.org>
Thu, 22 Oct 2020 05:29:04 +0000 (22:29 -0700)
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

14 files changed:
gcc/go/gofrontend/MERGE
libgo/go/syscall/exec_bsd.go
libgo/go/syscall/exec_linux.go
libgo/go/syscall/exec_stubs.go
libgo/go/syscall/libcall_aix.go
libgo/go/syscall/libcall_glibc.go
libgo/go/syscall/libcall_hurd.go
libgo/go/syscall/libcall_irix.go
libgo/go/syscall/libcall_linux.go
libgo/go/syscall/libcall_solaris_386.go
libgo/go/syscall/libcall_solaris_amd64.go
libgo/go/syscall/libcall_solaris_sparc.go
libgo/go/syscall/libcall_solaris_sparc64.go
libgo/runtime/go-varargs.c

index aedaf4664d554972b372b202249a062be4a6cdd5..384ca6e88647faf62fafed81aec67d8677dbbeb6 100644 (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.
index 7e06943f13ec179902cdb5c3f105c7d0c7e500a0..ca7fdc0825e7a66e0bf222d96b61ce2ec9056f18 100644 (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
                }
index 2f0a34fef0b77e29d5e23767e8c306ba59b7250a..38975810432973dbbcedd65bea5779094d094d01 100644 (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
                }
index e95b4158e1a073a80370e0b0eebe56fed9f67b33..c837cf7a4e2ff0e60a06ec3d8aecc71aaa701795 100644 (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
 }
index 27b469e1e477efa6bdee9277e678c777ba671ddf..92c7f3cc23234080a7469cecfece2f385a264515 100644 (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)
index 823343d5075a8aaa0f339f657145dade50614045..a32d6968f24fcb5b057a25b3d37de9796c5778db 100644 (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
 
index f0e038ca616c6dbceff85f601380a673e65e32d4..44ff46d1016e4b9e50c8449382b659955576a0f1 100644 (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
 }
 
index 9b6cdcca2c81cfbcceb3b5a2941827a91522bd9b..98807668d52756496b5f9b646cd8cca79e59e102 100644 (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
index 78fda0ea7ef1c6c93a092928b84a71035e670342..96974bd3269aa9f7a2f85ba68bdd318a8b6d8578 100644 (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) {
index 20eba22a302d8362b8f2fa91747a57170f5a5636..ef86f09711d12a31837aa558a6e84491a4df2c12 100644 (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
index 69b11ba5ee64810c5785a64d20d40b8a37d571d3..f44025e1eec71fe176d18fcf36bb4a2d73a87bea 100644 (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
 }
index 50863fadf1809256b80a5c0d180c1ae2e530295d..3d50309983f1858b3eaa5585d1ccceb96f002465 100644 (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
index 69b11ba5ee64810c5785a64d20d40b8a37d571d3..f44025e1eec71fe176d18fcf36bb4a2d73a87bea 100644 (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
 }
index d8f7dc55ea4125fac8dda30715ce17fe7f072604..f84860891e6cfd4fef4f5421d4c1402329fc165e 100644 (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)