Commit 0ce57a73 authored by Jeff Hodges's avatar Jeff Hodges Committed by Russ Cox

syscall: add ptrace on darwin

The ptrace syscall remains gutted on darwin, but usable.  This
also makes the syscall addition process reproducible on darwin
instead of relying on a file path in rsc's home directory.
I've also removed an override of $PATH in env.bash that made
tooling harder.

R=rsc, dave, r
CC=golang-dev
https://golang.org/cl/4517147
parent 5f77bf8b
......@@ -120,14 +120,13 @@ freebsd_amd64)
darwin_386)
mkerrors="$mkerrors -f -m32"
mksyscall="./mksyscall.pl -l32"
mksysnum="./mksysnum_darwin.pl /home/rsc/pub/xnu-1228/bsd/kern/syscalls.master"
mksysnum="./mksysnum_darwin.pl /usr/include/sys/syscall.h"
mktypes="godefs -gsyscall -f-m32"
;;
darwin_amd64)
mkerrors="$mkerrors -f -m64"
mksysnum="./mksysnum_darwin.pl /home/rsc/pub/xnu-1228/bsd/kern/syscalls.master"
mksysnum="./mksysnum_darwin.pl /usr/include/sys/syscall.h"
mktypes="godefs -gsyscall -f-m64"
mkerrors="./mkerrors.sh"
;;
linux_386)
mkerrors="$mkerrors -f -m32"
......
......@@ -47,6 +47,7 @@ includes_Darwin='
#define _DARWIN_USE_64_BIT_INODE
#include <sys/types.h>
#include <sys/event.h>
#include <sys/ptrace.h>
#include <sys/socket.h>
#include <sys/sockio.h>
#include <sys/sysctl.h>
......@@ -136,7 +137,7 @@ done
$2 == "CTL_MAXNAME" ||
$2 ~ /^(MS|MNT)_/ ||
$2 ~ /^TUN(SET|GET|ATTACH|DETACH)/ ||
$2 ~ /^(O|F|FD|NAME|S|PTRACE)_/ ||
$2 ~ /^(O|F|FD|NAME|S|PTRACE|PT)_/ ||
$2 ~ /^LINUX_REBOOT_CMD_/ ||
$2 ~ /^LINUX_REBOOT_MAGIC[12]$/ ||
$2 !~ "NLA_TYPE_MASK" &&
......
......@@ -3,8 +3,7 @@
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.
#
# Generate system call table for Darwin from master list
# (for example, xnu-1228/bsd/kern/syscalls.master).
# Generate system call table for Darwin from sys/syscall.h
my $command = "mksysnum_darwin.pl " . join(' ', @ARGV);
......@@ -18,18 +17,11 @@ const (
EOF
while(<>){
if(/^([0-9]+)\s+ALL\s+({ \S+\s+(\w+).*})/){
my $num = $1;
my $proto = $2;
my $name = "SYS_$3";
if(/^#define\s+SYS_(\w+)\s+([0-9]+)/){
my $name = $1;
my $num = $2;
$name =~ y/a-z/A-Z/;
# There are multiple entries for enosys and nosys, so comment them out.
if($name =~ /^SYS_E?NOSYS$/){
$name = "// $name";
}
print " $name = $num; // $proto\n";
print " SYS_$name = $num;"
}
}
......
......@@ -56,6 +56,10 @@ func ParseDirent(buf []byte, max int, names []string) (consumed int, count int,
return origlen - len(buf), count, names
}
//sys ptrace(request int, pid int, addr uintptr, data uintptr) (errno int)
func PtraceAttach(pid int) (errno int) { return ptrace(PT_ATTACH, pid, 0, 0) }
func PtraceDetach(pid int) (errno int) { return ptrace(PT_DETACH, pid, 0, 0) }
// TODO
func Sendfile(outfd int, infd int, offset *int64, count int) (written int, errno int) {
return -1, ENOSYS
......
......@@ -709,6 +709,24 @@ const (
PROT_NONE = 0
PROT_READ = 0x1
PROT_WRITE = 0x2
PT_ATTACH = 0xa
PT_ATTACHEXC = 0xe
PT_CONTINUE = 0x7
PT_DENY_ATTACH = 0x1f
PT_DETACH = 0xb
PT_FIRSTMACH = 0x20
PT_FORCEQUOTA = 0x1e
PT_KILL = 0x8
PT_READ_D = 0x2
PT_READ_I = 0x1
PT_READ_U = 0x3
PT_SIGEXC = 0xc
PT_STEP = 0x9
PT_THUPDATE = 0xd
PT_TRACE_ME = 0
PT_WRITE_D = 0x5
PT_WRITE_I = 0x4
PT_WRITE_U = 0x6
RTAX_AUTHOR = 0x6
RTAX_BRD = 0x7
RTAX_DST = 0
......
// mkerrors.sh
// mkerrors.sh -f -m64
// MACHINE GENERATED BY THE COMMAND ABOVE; DO NOT EDIT
// godefs -c gcc -gsyscall _const.c
// godefs -c gcc -f -m64 -gsyscall -f -m64 _const.c
// MACHINE GENERATED - DO NOT EDIT.
......@@ -709,6 +709,24 @@ const (
PROT_NONE = 0
PROT_READ = 0x1
PROT_WRITE = 0x2
PT_ATTACH = 0xa
PT_ATTACHEXC = 0xe
PT_CONTINUE = 0x7
PT_DENY_ATTACH = 0x1f
PT_DETACH = 0xb
PT_FIRSTMACH = 0x20
PT_FORCEQUOTA = 0x1e
PT_KILL = 0x8
PT_READ_D = 0x2
PT_READ_I = 0x1
PT_READ_U = 0x3
PT_SIGEXC = 0xc
PT_STEP = 0x9
PT_THUPDATE = 0xd
PT_TRACE_ME = 0
PT_WRITE_D = 0x5
PT_WRITE_I = 0x4
PT_WRITE_U = 0x6
RTAX_AUTHOR = 0x6
RTAX_BRD = 0x7
RTAX_DST = 0
......
......@@ -219,6 +219,14 @@ func munmap(addr uintptr, length uintptr) (errno int) {
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
func ptrace(request int, pid int, addr uintptr, data uintptr) (errno int) {
_, _, e1 := Syscall6(SYS_PTRACE, uintptr(request), uintptr(pid), uintptr(addr), uintptr(data), 0, 0)
errno = int(e1)
return
}
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
func kill(pid int, signum int, posix int) (errno int) {
_, _, e1 := Syscall(SYS_KILL, uintptr(pid), uintptr(signum), uintptr(posix))
errno = int(e1)
......
......@@ -219,6 +219,14 @@ func munmap(addr uintptr, length uintptr) (errno int) {
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
func ptrace(request int, pid int, addr uintptr, data uintptr) (errno int) {
_, _, e1 := Syscall6(SYS_PTRACE, uintptr(request), uintptr(pid), uintptr(addr), uintptr(data), 0, 0)
errno = int(e1)
return
}
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
func kill(pid int, signum int, posix int) (errno int) {
_, _, e1 := Syscall(SYS_KILL, uintptr(pid), uintptr(signum), uintptr(posix))
errno = int(e1)
......
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment