diff --git a/internal/lib/os/wait_waitid.go b/internal/lib/os/wait_waitid.go index 0c89c81b..301254b3 100644 --- a/internal/lib/os/wait_waitid.go +++ b/internal/lib/os/wait_waitid.go @@ -10,10 +10,10 @@ package os import ( + "syscall" _ "unsafe" "github.com/goplus/llgo/c" - "github.com/goplus/llgo/c/syscall" ) const _P_PID = 1 diff --git a/internal/lib/syscall/exec_libc.go b/internal/lib/syscall/exec_libc.go index 44557867..1c38a19a 100644 --- a/internal/lib/syscall/exec_libc.go +++ b/internal/lib/syscall/exec_libc.go @@ -11,6 +11,8 @@ package syscall import ( "runtime" "unsafe" + + "github.com/goplus/llgo/c" ) type SysProcAttr struct { @@ -77,8 +79,8 @@ func init() { // split the stack, or acquire mutexes). We can't call RawSyscall // because it's not safe even for BSD-subsystem calls. // -//go:norace -func forkAndExecInChild(argv0 *byte, argv, envv []*byte, chroot, dir *byte, attr *ProcAttr, sys *SysProcAttr, pipe int) (pid int, err Errno) { +// func forkAndExecInChild(argv0 *byte, argv, envv []*byte, chroot, dir *byte, attr *ProcAttr, sys *SysProcAttr, pipe int) (pid int, err Errno) { +func forkAndExecInChild(argv0 *c.Char, argv, envv **c.Char, chroot, dir *c.Char, attr *ProcAttr, sys *SysProcAttr, pipe int) (pid int, err Errno) { // Declare all variables at top in case any // declarations require heap allocation (e.g., err1). var ( diff --git a/internal/lib/syscall/exec_libc2.go b/internal/lib/syscall/exec_libc2.go index 61b2c3b3..4c45b80b 100644 --- a/internal/lib/syscall/exec_libc2.go +++ b/internal/lib/syscall/exec_libc2.go @@ -52,8 +52,6 @@ func runtime_AfterForkInChild() // For the same reason compiler does not race instrument it. // The calls to rawSyscall are okay because they are assembly // functions that do not grow the stack. -// -//go:norace func forkAndExecInChild(argv0 *c.Char, argv, envv **c.Char, chroot, dir *c.Char, attr *ProcAttr, sys *SysProcAttr, pipe int) (pid int, err1 Errno) { // Declare all variables at top in case any // declarations require heap allocation (e.g., err1). diff --git a/internal/lib/syscall/exec_linux.go b/internal/lib/syscall/exec_linux.go index c66e820f..fb93fce3 100644 --- a/internal/lib/syscall/exec_linux.go +++ b/internal/lib/syscall/exec_linux.go @@ -6,6 +6,8 @@ package syscall +import "github.com/goplus/llgo/c" + // Linux unshare/clone/clone2/clone3 flags, architecture-independent, // copied from linux/sched.h. const ( @@ -119,8 +121,8 @@ func runtime_AfterForkInChild() // The calls to RawSyscall are okay because they are assembly // functions that do not grow the stack. // -//go:norace -func forkAndExecInChild(argv0 *byte, argv, envv []*byte, chroot, dir *byte, attr *ProcAttr, sys *SysProcAttr, pipe int) (pid int, err Errno) { +// func forkAndExecInChild(argv0 *byte, argv, envv []*byte, chroot, dir *byte, attr *ProcAttr, sys *SysProcAttr, pipe int) (pid int, err Errno) { +func forkAndExecInChild(argv0 *c.Char, argv, envv **c.Char, chroot, dir *c.Char, attr *ProcAttr, sys *SysProcAttr, pipe int) (pid int, err Errno) { /* TODO(xsw): // Set up and fork. This returns immediately in the parent or // if there's an error. diff --git a/internal/lib/syscall/syscall_linux.go b/internal/lib/syscall/syscall_linux.go index 3b643db2..7c4c2a59 100644 --- a/internal/lib/syscall/syscall_linux.go +++ b/internal/lib/syscall/syscall_linux.go @@ -15,6 +15,7 @@ import ( _ "unsafe" "github.com/goplus/llgo/c" + "github.com/goplus/llgo/c/syscall" ) // ----------------------------------------------------------------------------- @@ -78,6 +79,15 @@ func (w WaitStatus) TrapCause() int { } */ +func Wait4(pid int, wstatus *WaitStatus, options int, rusage *Rusage) (wpid int, err error) { + var status c.Int + wpid, err = wait4(pid, &status, options, rusage) + if wstatus != nil { + *wstatus = WaitStatus(status) + } + return +} + // ----------------------------------------------------------------------------- // int pipe2(int pipefd[2], int flags); @@ -85,13 +95,9 @@ func (w WaitStatus) TrapCause() int { //go:linkname pipe2 C.pipe2 func pipe2(pipefd *[2]c.Int, flags c.Int) c.Int -func Pipe(p []int) error { - return Pipe2(p, 0) -} - func Pipe2(p []int, flags int) error { if len(p) != 2 { - return EINVAL + return Errno(syscall.EINVAL) } var pp [2]c.Int ret := pipe2(&pp, c.Int(flags))