LEFT | RIGHT |
1 // Copyright 2009 The Go Authors. All rights reserved. | 1 // Copyright 2009 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 // Fork, exec, wait, etc. | 5 // Fork, exec, wait, etc. |
6 | 6 |
7 package syscall | 7 package syscall |
8 | 8 |
9 import ( | 9 import ( |
10 "sync" | 10 "sync" |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 // no rescheduling, no malloc calls, and no new stack segments. | 96 // no rescheduling, no malloc calls, and no new stack segments. |
97 // The calls to RawSyscall are okay because they are assembly | 97 // The calls to RawSyscall are okay because they are assembly |
98 // functions that do not grow the stack. | 98 // functions that do not grow the stack. |
99 func forkAndExecInChild(argv0 *byte, argv, envv []*byte, dir *byte, attr *ProcAt
tr, pipe int) (pid int, err int) { | 99 func forkAndExecInChild(argv0 *byte, argv, envv []*byte, dir *byte, attr *ProcAt
tr, pipe int) (pid int, err int) { |
100 // Declare all variables at top in case any | 100 // Declare all variables at top in case any |
101 // declarations require heap allocation (e.g., err1). | 101 // declarations require heap allocation (e.g., err1). |
102 var r1, r2, err1 uintptr | 102 var r1, r2, err1 uintptr |
103 var nextfd int | 103 var nextfd int |
104 var i int | 104 var i int |
105 | 105 |
106 » // we could copy this if we cared about the side effects, but this is sy
scall. | 106 » // guard against side effects of shuffling fds below. |
107 » fd := attr.Files | 107 » fd := append([]int(nil), attr.Files...) |
108 | 108 |
109 darwin := OS == "darwin" | 109 darwin := OS == "darwin" |
110 | 110 |
111 // About to call fork. | 111 // About to call fork. |
112 // No more allocation or calls of non-assembly functions. | 112 // No more allocation or calls of non-assembly functions. |
113 r1, r2, err1 = RawSyscall(SYS_FORK, 0, 0, 0) | 113 r1, r2, err1 = RawSyscall(SYS_FORK, 0, 0, 0) |
114 if err1 != 0 { | 114 if err1 != 0 { |
115 return 0, int(err1) | 115 return 0, int(err1) |
116 } | 116 } |
117 | 117 |
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
335 } | 335 } |
336 | 336 |
337 // Ordinary exec. | 337 // Ordinary exec. |
338 func Exec(argv0 string, argv []string, envv []string) (err int) { | 338 func Exec(argv0 string, argv []string, envv []string) (err int) { |
339 _, _, err1 := RawSyscall(SYS_EXECVE, | 339 _, _, err1 := RawSyscall(SYS_EXECVE, |
340 uintptr(unsafe.Pointer(StringBytePtr(argv0))), | 340 uintptr(unsafe.Pointer(StringBytePtr(argv0))), |
341 uintptr(unsafe.Pointer(&StringArrayPtr(argv)[0])), | 341 uintptr(unsafe.Pointer(&StringArrayPtr(argv)[0])), |
342 uintptr(unsafe.Pointer(&StringArrayPtr(envv)[0]))) | 342 uintptr(unsafe.Pointer(&StringArrayPtr(envv)[0]))) |
343 return int(err1) | 343 return int(err1) |
344 } | 344 } |
LEFT | RIGHT |