提交 98142c69 编写于 作者: A aarzilli 提交者: Alessandro Arzilli

proc/native: race between RequestManualStop and trapWait

RequestManualStop will run concurrently with trapWait, since one writes
dbp.halt and the other reads it dbp.halt should be protected by a
mutex.

Updates #830
上级 640dedb4
......@@ -37,6 +37,7 @@ type Process struct {
breakpointIDCounter int
internalBreakpointIDCounter int
firstStart bool
haltMu sync.Mutex
halt bool
exited bool
ptraceChan chan func()
......@@ -187,6 +188,8 @@ func (dbp *Process) RequestManualStop() error {
if dbp.exited {
return &proc.ProcessExitedError{}
}
dbp.haltMu.Lock()
defer dbp.haltMu.Unlock()
dbp.halt = true
return dbp.requestManualStop()
}
......
......@@ -291,7 +291,10 @@ func (dbp *Process) trapWait(pid int) (*Thread, error) {
return nil, proc.ProcessExitedError{Pid: dbp.pid, Status: status.ExitStatus()}
case C.MACH_RCV_INTERRUPTED:
if !dbp.halt {
dbp.haltMu.Lock()
halt := dbp.halt
dbp.haltMu.Unlock()
if !halt {
// Call trapWait again, it seems
// MACH_RCV_INTERRUPTED is emitted before
// process natural death _sometimes_.
......@@ -319,7 +322,10 @@ func (dbp *Process) trapWait(pid int) (*Thread, error) {
dbp.updateThreadList()
th, ok := dbp.threads[int(port)]
if !ok {
if dbp.halt {
dbp.haltMu.Lock()
halt := dbp.halt
dbp.haltMu.Unlock()
if halt {
dbp.halt = false
return th, nil
}
......
......@@ -236,7 +236,10 @@ func (dbp *Process) trapWait(pid int) (*Thread, error) {
// Sometimes we get an unknown thread, ignore it?
continue
}
if status.StopSignal() == sys.SIGTRAP && dbp.halt {
dbp.haltMu.Lock()
halt := dbp.halt
dbp.haltMu.Unlock()
if status.StopSignal() == sys.SIGTRAP && halt {
th.running = false
dbp.halt = false
return th, nil
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册