proc: implement detach on windows (#615)

This commit is contained in:
Alex Brainman 2016-09-13 04:16:41 +10:00 committed by Derek Parker
parent 2fad5abe74
commit 4d8daeb1a8
4 changed files with 20 additions and 3 deletions

@ -544,6 +544,9 @@ func (dbp *Process) resume() error {
}
func killProcess(pid int) error {
fmt.Println("killProcess")
return fmt.Errorf("not implemented: killProcess")
p, err := os.FindProcess(pid)
if err != nil {
return err
}
return p.Kill()
}

@ -9,5 +9,5 @@ func PtraceAttach(pid int) error {
}
func PtraceDetach(tid, sig int) error {
return fmt.Errorf("not implemented: PtraceDetach")
return _DebugActiveProcessStop(uint32(tid))
}

@ -89,4 +89,5 @@ func _NT_SUCCESS(x _NTSTATUS) bool {
//sys _DebugBreakProcess(process syscall.Handle) (err error) = kernel32.DebugBreakProcess
//sys _WaitForDebugEvent(debugevent *_DEBUG_EVENT, milliseconds uint32) (err error) = kernel32.WaitForDebugEvent
//sys _DebugActiveProcess(processid uint32) (err error) = kernel32.DebugActiveProcess
//sys _DebugActiveProcessStop(processid uint32) (err error) = kernel32.DebugActiveProcessStop
//sys _QueryFullProcessImageName(process syscall.Handle, flags uint32, exename *uint16, size *uint32) (err error) = kernel32.QueryFullProcessImageNameW

@ -24,6 +24,7 @@ var (
procDebugBreakProcess = modkernel32.NewProc("DebugBreakProcess")
procWaitForDebugEvent = modkernel32.NewProc("WaitForDebugEvent")
procDebugActiveProcess = modkernel32.NewProc("DebugActiveProcess")
procDebugActiveProcessStop = modkernel32.NewProc("DebugActiveProcessStop")
procQueryFullProcessImageNameW = modkernel32.NewProc("QueryFullProcessImageNameW")
)
@ -155,6 +156,18 @@ func _DebugActiveProcess(processid uint32) (err error) {
return
}
func _DebugActiveProcessStop(processid uint32) (err error) {
r1, _, e1 := syscall.Syscall(procDebugActiveProcessStop.Addr(), 1, uintptr(processid), 0, 0)
if r1 == 0 {
if e1 != 0 {
err = error(e1)
} else {
err = syscall.EINVAL
}
}
return
}
func _QueryFullProcessImageName(process syscall.Handle, flags uint32, exename *uint16, size *uint32) (err error) {
r1, _, e1 := syscall.Syscall6(procQueryFullProcessImageNameW.Addr(), 4, uintptr(process), uintptr(flags), uintptr(unsafe.Pointer(exename)), uintptr(unsafe.Pointer(size)), 0, 0)
if r1 == 0 {