Skip to content

Commit 87105e5

Browse files
committed
[release-branch.go1.18] runtime: revert "call __fork instead of fork on darwin"
A recent comment on #57263 reports an unexplained crash in a cgo program that is fixed by reverting the __fork fix. We don't have any viable fix for the os/exec bug at this point, so give up on a fix for the January point releases. This reverts CL 459179 (commit 07b6ffb). Fixes #57689. Change-Id: I3b81de6bded399f47862325129e86a65c83d8e3b Reviewed-on: https://go-review.googlesource.com/c/go/+/461116 Reviewed-by: Ian Lance Taylor <[email protected]> Run-TryBot: Russ Cox <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Cherry Mui <[email protected]>
1 parent 476384e commit 87105e5

7 files changed

+15
-81
lines changed

src/syscall/exec_libc2.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ func forkAndExecInChild(argv0 *byte, argv, envv []*byte, chroot, dir *byte, attr
7676
// About to call fork.
7777
// No more allocation or calls of non-assembly functions.
7878
runtime_BeforeFork()
79-
r1, _, err1 = rawSyscall(forkTrampoline, 0, 0, 0)
79+
r1, _, err1 = rawSyscall(abi.FuncPCABI0(libc_fork_trampoline), 0, 0, 0)
8080
if err1 != 0 {
8181
runtime_AfterFork()
8282
return 0, err1
@@ -260,6 +260,6 @@ childerror:
260260
// send error code on pipe
261261
rawSyscall(abi.FuncPCABI0(libc_write_trampoline), uintptr(pipe), uintptr(unsafe.Pointer(&err1)), unsafe.Sizeof(err1))
262262
for {
263-
rawSyscall(exitTrampoline, 253, 0, 0)
263+
rawSyscall(abi.FuncPCABI0(libc_exit_trampoline), 253, 0, 0)
264264
}
265265
}

src/syscall/syscall_darwin.go

+1-30
Original file line numberDiff line numberDiff line change
@@ -17,34 +17,6 @@ import (
1717
"unsafe"
1818
)
1919

20-
// These are called from exec_libc2.go in the child of fork.
21-
// The names differ between macOS and OpenBSD, so we need
22-
// to declare the specific ones used here to keep the exec_libc2.go
23-
// code portable.
24-
//
25-
// We use __fork and __exit, not fork and exit, to avoid the libc atfork
26-
// and atexit handlers. The atfork handlers have caused fork child
27-
// hangs in the past (see #33565, #56784). The atexit handlers have
28-
// not, but the non-libc ports all invoke the system call, so doing
29-
// the same here makes sense. In general we wouldn't expect
30-
// atexit handlers to work terribly well in a fork child anyway.
31-
// (Also, perhaps the atfork handlers clear the atexit handlers,
32-
// in which case we definitely need to avoid calling the libc exit
33-
// if we bypass the libc fork.)
34-
//
35-
// Other calls that are made in the child after the fork are
36-
// ptrace, setsid, setpgid, getpid, ioctl, chroot, setgroups,
37-
// setgid, setuid, chdir, dup2, fcntl, close, execve, and write.
38-
// Those are all simple kernel wrappers that should be safe
39-
// to be called directly. The fcntl and ioctl functions do run
40-
// some code around the kernel call, but they don't call any
41-
// other functions, so for now we keep using them instead of
42-
// calling the lower-level __fcntl and __ioctl functions.
43-
var (
44-
exitTrampoline = abi.FuncPCABI0(libc___exit_trampoline)
45-
forkTrampoline = abi.FuncPCABI0(libc___fork_trampoline)
46-
)
47-
4820
type SockaddrDatalink struct {
4921
Len uint8
5022
Family uint8
@@ -230,12 +202,11 @@ func Kill(pid int, signum Signal) (err error) { return kill(pid, int(signum), 1)
230202
//sys writev(fd int, iovecs []Iovec) (cnt uintptr, err error)
231203
//sys mmap(addr uintptr, length uintptr, prot int, flag int, fd int, pos int64) (ret uintptr, err error)
232204
//sys munmap(addr uintptr, length uintptr) (err error)
233-
//sysnb __fork() (pid int, err error)
205+
//sysnb fork() (pid int, err error)
234206
//sysnb ioctl(fd int, req int, arg int) (err error)
235207
//sysnb ioctlPtr(fd int, req uint, arg unsafe.Pointer) (err error) = SYS_ioctl
236208
//sysnb execve(path *byte, argv **byte, envp **byte) (err error)
237209
//sysnb exit(res int) (err error)
238-
//sysnb __exit(res int) (err error)
239210
//sys sysctl(mib []_C_int, old *byte, oldlen *uintptr, new *byte, newlen uintptr) (err error)
240211
//sys fcntlPtr(fd int, cmd int, arg unsafe.Pointer) (val int, err error) = SYS_fcntl
241212
//sys unlinkat(fd int, path string, flags int) (err error)

src/syscall/syscall_openbsd_libc.go

-5
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,6 @@ import (
1010
"internal/abi"
1111
)
1212

13-
var (
14-
exitTrampoline = abi.FuncPCABI0(libc_exit_trampoline)
15-
forkTrampoline = abi.FuncPCABI0(libc_fork_trampoline)
16-
)
17-
1813
func init() {
1914
execveOpenBSD = execve
2015
}

src/syscall/zsyscall_darwin_amd64.go

+4-18
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/syscall/zsyscall_darwin_amd64.s

+2-4
Original file line numberDiff line numberDiff line change
@@ -219,16 +219,14 @@ TEXT ·libc_mmap_trampoline(SB),NOSPLIT,$0-0
219219
JMP libc_mmap(SB)
220220
TEXT ·libc_munmap_trampoline(SB),NOSPLIT,$0-0
221221
JMP libc_munmap(SB)
222-
TEXT ·libc___fork_trampoline(SB),NOSPLIT,$0-0
223-
JMP libc___fork(SB)
222+
TEXT ·libc_fork_trampoline(SB),NOSPLIT,$0-0
223+
JMP libc_fork(SB)
224224
TEXT ·libc_ioctl_trampoline(SB),NOSPLIT,$0-0
225225
JMP libc_ioctl(SB)
226226
TEXT ·libc_execve_trampoline(SB),NOSPLIT,$0-0
227227
JMP libc_execve(SB)
228228
TEXT ·libc_exit_trampoline(SB),NOSPLIT,$0-0
229229
JMP libc_exit(SB)
230-
TEXT ·libc___exit_trampoline(SB),NOSPLIT,$0-0
231-
JMP libc___exit(SB)
232230
TEXT ·libc_sysctl_trampoline(SB),NOSPLIT,$0-0
233231
JMP libc_sysctl(SB)
234232
TEXT ·libc_unlinkat_trampoline(SB),NOSPLIT,$0-0

src/syscall/zsyscall_darwin_arm64.go

+4-18
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/syscall/zsyscall_darwin_arm64.s

+2-4
Original file line numberDiff line numberDiff line change
@@ -219,16 +219,14 @@ TEXT ·libc_mmap_trampoline(SB),NOSPLIT,$0-0
219219
JMP libc_mmap(SB)
220220
TEXT ·libc_munmap_trampoline(SB),NOSPLIT,$0-0
221221
JMP libc_munmap(SB)
222-
TEXT ·libc___fork_trampoline(SB),NOSPLIT,$0-0
223-
JMP libc___fork(SB)
222+
TEXT ·libc_fork_trampoline(SB),NOSPLIT,$0-0
223+
JMP libc_fork(SB)
224224
TEXT ·libc_ioctl_trampoline(SB),NOSPLIT,$0-0
225225
JMP libc_ioctl(SB)
226226
TEXT ·libc_execve_trampoline(SB),NOSPLIT,$0-0
227227
JMP libc_execve(SB)
228228
TEXT ·libc_exit_trampoline(SB),NOSPLIT,$0-0
229229
JMP libc_exit(SB)
230-
TEXT ·libc___exit_trampoline(SB),NOSPLIT,$0-0
231-
JMP libc___exit(SB)
232230
TEXT ·libc_sysctl_trampoline(SB),NOSPLIT,$0-0
233231
JMP libc_sysctl(SB)
234232
TEXT ·libc_unlinkat_trampoline(SB),NOSPLIT,$0-0

0 commit comments

Comments
 (0)