proc: Refactor ptrace calls on Darwin

This commit is contained in:
Derek Parker
2015-10-06 10:45:36 -07:00
parent 769dd59b4d
commit c731a83424
2 changed files with 10 additions and 21 deletions

View File

@ -673,7 +673,7 @@ func (dbp *Process) run(fn func() error) error {
func (dbp *Process) handlePtraceFuncs() { func (dbp *Process) handlePtraceFuncs() {
// We must ensure here that we are running on the same thread during // We must ensure here that we are running on the same thread during
// the execution of dbg. This is due to the fact that ptrace(2) expects // while invoking the ptrace(2) syscall. This is due to the fact that ptrace(2) expects
// all commands after PTRACE_ATTACH to come from the same thread. // all commands after PTRACE_ATTACH to come from the same thread.
runtime.LockOSThread() runtime.LockOSThread()

View File

@ -1,31 +1,20 @@
package proc package proc
import ( import sys "golang.org/x/sys/unix"
"syscall"
sys "golang.org/x/sys/unix"
)
func PtraceDetach(tid, sig int) error { func PtraceDetach(tid, sig int) error {
_, _, err := sys.Syscall6(sys.SYS_PTRACE, sys.PT_DETACH, uintptr(tid), 1, uintptr(sig), 0, 0) return ptrace(sys.PT_DETACH, tid, 1, uintptr(sig))
if err != syscall.Errno(0) {
return err
}
return nil
} }
func PtraceCont(tid, sig int) error { func PtraceCont(tid, sig int) error {
_, _, err := sys.Syscall6(sys.SYS_PTRACE, sys.PTRACE_CONT, uintptr(tid), 1, uintptr(sig), 0, 0) return ptrace(sys.PTRACE_CONT, tid, 1, 0)
if err != syscall.Errno(0) {
return err
}
return nil
} }
func PtraceSingleStep(tid int) error { func PtraceSingleStep(tid int) error {
_, _, err := sys.Syscall6(sys.SYS_PTRACE, sys.PT_STEP, uintptr(tid), 1, 0, 0, 0) return ptrace(sys.PT_STEP, tid, 1, 0)
if err != syscall.Errno(0) { }
return err
} func ptrace(request, pid int, addr uintptr, data uintptr) (err error) {
return nil _, _, err = sys.Syscall6(sys.SYS_PTRACE, uintptr(request), uintptr(pid), uintptr(addr), uintptr(data), 0, 0)
return
} }