本文整理匯總了Golang中C.mach_port_wait函數的典型用法代碼示例。如果您正苦於以下問題:Golang mach_port_wait函數的具體用法?Golang mach_port_wait怎麽用?Golang mach_port_wait使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了mach_port_wait函數的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: trapWait
func (dbp *Process) trapWait(pid int) (*Thread, error) {
var (
th *Thread
err error
)
for {
port := C.mach_port_wait(dbp.os.portSet)
switch port {
case dbp.os.notificationPort:
_, status, err := wait(dbp.Pid, dbp.Pid, 0)
if err != nil {
return nil, err
}
dbp.exited = true
return nil, ProcessExitedError{Pid: dbp.Pid, Status: status.ExitStatus()}
case C.MACH_RCV_INTERRUPTED:
if !dbp.halt {
// Call trapWait again, it seems
// MACH_RCV_INTERRUPTED is emitted before
// process natural death _sometimes_.
continue
}
return nil, nil
case 0:
return nil, fmt.Errorf("error while waiting for task")
}
// Since we cannot be notified of new threads on OS X
// this is as good a time as any to check for them.
dbp.updateThreadList()
th, err = dbp.handleBreakpointOnThread(int(port))
if err != nil {
if _, ok := err.(NoBreakpointError); ok {
if dbp.halt {
dbp.halt = false
return dbp.Threads[int(port)], nil
}
th := dbp.Threads[int(port)]
if dbp.firstStart || th.singleStepping {
dbp.firstStart = false
return dbp.Threads[int(port)], nil
}
if err := th.Continue(); err != nil {
return nil, err
}
continue
}
return nil, err
}
return th, nil
}
return th, nil
}
示例2: singleStep
func (t *Thread) singleStep() error {
kret := C.single_step(t.os.threadAct)
if kret != C.KERN_SUCCESS {
return fmt.Errorf("could not single step")
}
for {
port := C.mach_port_wait(t.dbp.os.portSet, C.int(0))
if port == C.mach_port_t(t.ID) {
break
}
}
kret = C.clear_trap_flag(t.os.threadAct)
if kret != C.KERN_SUCCESS {
return fmt.Errorf("could not clear CPU trap flag")
}
return nil
}
示例3: Kill
func (dbp *Process) Kill() (err error) {
err = sys.Kill(dbp.Pid, sys.SIGKILL)
if err != nil {
return errors.New("could not deliver signal: " + err.Error())
}
for port := range dbp.Threads {
if C.thread_resume(C.thread_act_t(port)) != C.KERN_SUCCESS {
return errors.New("could not resume task")
}
}
for {
port := C.mach_port_wait(dbp.os.portSet)
if port == dbp.os.notificationPort {
break
}
}
dbp.exited = true
return
}
示例4: waitForStop
func (dbp *Process) waitForStop() ([]int, error) {
ports := make([]int, 0, len(dbp.Threads))
count := 0
for {
port := C.mach_port_wait(dbp.os.portSet, C.int(1))
if port != 0 {
count = 0
ports = append(ports, int(port))
} else {
n := C.num_running_threads(C.task_t(dbp.os.task))
if n == 0 {
return ports, nil
} else if n < 0 {
return nil, fmt.Errorf("error waiting for thread stop %d", n)
} else if count > 16 {
return nil, fmt.Errorf("could not stop process %d", n)
}
}
}
}