LEFT | RIGHT |
1 // Copyright 2014 The Go Authors. All rights reserved. | 1 // Copyright 2014 The Go Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
4 | 4 |
5 package server | 5 package server |
6 | 6 |
7 // TODO: syscall.PTRACE_O_TRACECLONE shenanigans to trace multi-threaded | 7 // TODO: syscall.PTRACE_O_TRACECLONE shenanigans to trace multi-threaded |
8 // programs. | 8 // programs. |
9 | 9 |
10 import ( | 10 import ( |
11 "fmt" | 11 "fmt" |
12 "os" | 12 "os" |
13 "runtime" | 13 "runtime" |
14 "syscall" | 14 "syscall" |
15 ) | 15 ) |
16 | 16 |
17 // ptraceRun runs all the closures from fc on a dedicated OS thread. Errors | 17 // ptraceRun runs all the closures from fc on a dedicated OS thread. Errors |
18 // are returned on ec. Both channels must be unbuffered. | 18 // are returned on ec. Both channels must be unbuffered, to ensure that the |
| 19 // resultant error is sent back to the same goroutine that sent the closure. |
19 func ptraceRun(fc chan func() error, ec chan error) { | 20 func ptraceRun(fc chan func() error, ec chan error) { |
20 if cap(fc) != 0 || cap(ec) != 0 { | 21 if cap(fc) != 0 || cap(ec) != 0 { |
21 panic("ptraceRun was given unbuffered channels") | 22 panic("ptraceRun was given unbuffered channels") |
22 } | 23 } |
23 runtime.LockOSThread() | 24 runtime.LockOSThread() |
24 for f := range fc { | 25 for f := range fc { |
25 ec <- f() | 26 ec <- f() |
26 } | 27 } |
27 } | 28 } |
28 | 29 |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 | 87 |
87 func (s *Server) wait() (err error) { | 88 func (s *Server) wait() (err error) { |
88 var status syscall.WaitStatus | 89 var status syscall.WaitStatus |
89 s.fc <- func() error { | 90 s.fc <- func() error { |
90 _, err1 := syscall.Wait4(-1, &status, 0, nil) | 91 _, err1 := syscall.Wait4(-1, &status, 0, nil) |
91 return err1 | 92 return err1 |
92 } | 93 } |
93 // TODO: do something with status. | 94 // TODO: do something with status. |
94 return <-s.ec | 95 return <-s.ec |
95 } | 96 } |
LEFT | RIGHT |