diff --git a/internal/lib/os/wait_waitid.go b/internal/lib/os/wait_waitid.go index c14aba38..0c89c81b 100644 --- a/internal/lib/os/wait_waitid.go +++ b/internal/lib/os/wait_waitid.go @@ -21,7 +21,7 @@ const _P_PID = 1 // int waitid(idtype_t idtype, id_t id, siginfo_t *infop, int options); // //go:linkname waitid C.waitid -func waitid(idtype, id uintptr, infop *[16]uint64, options c.Int) c.Int +func waitid(idtype, id uintptr, infop *uint64, options c.Int) c.Int // blockUntilWaitable attempts to block until a call to p.Wait will // succeed immediately, and reports whether it has done so. @@ -35,7 +35,7 @@ func (p *Process) blockUntilWaitable() (bool, error) { psig := &siginfo[0] var e syscall.Errno for { - e = syscall.Errno(waitid(_P_PID, uintptr(p.Pid), psig, syscall.WEXITED|syscall.WNOWAIT, 0, 0)) + e = syscall.Errno(waitid(_P_PID, uintptr(p.Pid), psig, syscall.WEXITED|syscall.WNOWAIT)) if e != syscall.EINTR { break } diff --git a/internal/lib/syscall/forkpipe2.go b/internal/lib/syscall/forkpipe2.go index 9a93b258..b5cd1d30 100644 --- a/internal/lib/syscall/forkpipe2.go +++ b/internal/lib/syscall/forkpipe2.go @@ -6,12 +6,16 @@ package syscall -import "sync" +import ( + "sync" + + "github.com/goplus/llgo/c/syscall" +) // forkExecPipe atomically opens a pipe with O_CLOEXEC set on both file // descriptors. func forkExecPipe(p []int) error { - return Pipe2(p, O_CLOEXEC) + return Pipe2(p, syscall.O_CLOEXEC) } var ( diff --git a/internal/lib/syscall/syscall_linux.go b/internal/lib/syscall/syscall_linux.go index cad706d3..3b643db2 100644 --- a/internal/lib/syscall/syscall_linux.go +++ b/internal/lib/syscall/syscall_linux.go @@ -11,6 +11,14 @@ package syscall +import ( + _ "unsafe" + + "github.com/goplus/llgo/c" +) + +// ----------------------------------------------------------------------------- + type WaitStatus uint32 // Wait status is 7 bits at bottom, either 0 (exited), @@ -70,6 +78,35 @@ func (w WaitStatus) TrapCause() int { } */ +// ----------------------------------------------------------------------------- + +// int pipe2(int pipefd[2], int flags); +// +//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 + } + var pp [2]c.Int + ret := pipe2(&pp, c.Int(flags)) + if ret == 0 { + p[0] = int(pp[0]) + p[1] = int(pp[1]) + return nil + } + return Errno(ret) +} + +// ----------------------------------------------------------------------------- + func Faccessat(dirfd int, path string, mode uint32, flags int) (err error) { panic("todo: syscall.Faccessat") } + +// -----------------------------------------------------------------------------