Skip to content

Commit 9eff0d2

Browse files
committed
replace raw syscall implementation with musl wrapper
Signed-off-by: leongross <[email protected]>
1 parent e6fface commit 9eff0d2

File tree

3 files changed

+19
-10
lines changed

3 files changed

+19
-10
lines changed

builder/musl.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,8 @@ var libMusl = Library{
136136
"thread/*.c",
137137
"time/*.c",
138138
"unistd/*.c",
139+
// "process/fork.c",
140+
"process/*.c",
139141
}
140142
if arch == "arm" {
141143
// These files need to be added to the start for some reason.

src/os/exec_linux.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,9 @@ func forkExec(argv0 string, argv []string, attr *ProcAttr) (pid int, err error)
5757
attr = new(ProcAttr)
5858
}
5959

60-
pid, err = fork()
60+
p, err := fork()
61+
pid = int(p)
62+
6163
if err != nil {
6264
return 0, err
6365
} else {

src/os/osexec.go

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//go:build linux && !baremetal && !darwin && !tinygo.wasm && !arm64
1+
//go:build linux && !baremetal && !tinygo.wasm && !arm64
22

33
// arm64 does not have a fork syscall, so ignore it for now
44
// TODO: add support for arm64 with clone or use musl implementation
@@ -10,15 +10,12 @@ import (
1010
"unsafe"
1111
)
1212

13-
func fork() (pid int, err error) {
14-
ret, _, err := syscall.Syscall(syscall.SYS_FORK, 0, 0, 0)
15-
if int(ret) != 0 {
16-
errno := err.(syscall.Errno)
17-
if int(errno) != 0 {
18-
return -1, errno
19-
}
13+
func fork() (pid int32, err error) {
14+
pid = libc_fork()
15+
if pid != 0 {
16+
err = syscall.Errno(*libc_errno())
2017
}
21-
return int(ret), nil
18+
return
2219
}
2320

2421
// the golang standard library does not expose interfaces for execve and fork, so we define them here the same way via the libc wrapper
@@ -52,3 +49,11 @@ func cstring(s string) []byte {
5249
// final byte should be zero from the initial allocation
5350
return data
5451
}
52+
53+
//export fork
54+
func libc_fork() int32
55+
56+
// Internal musl function to get the C errno pointer.
57+
//
58+
//export __errno_location
59+
func libc_errno() *int32

0 commit comments

Comments
 (0)