library syscall (linux): Wait4

This commit is contained in:
xushiwei
2024-07-26 14:49:21 +08:00
parent 384e887fdb
commit a3b23e348a
5 changed files with 20 additions and 12 deletions

View File

@@ -10,10 +10,10 @@
package os package os
import ( import (
"syscall"
_ "unsafe" _ "unsafe"
"github.com/goplus/llgo/c" "github.com/goplus/llgo/c"
"github.com/goplus/llgo/c/syscall"
) )
const _P_PID = 1 const _P_PID = 1

View File

@@ -11,6 +11,8 @@ package syscall
import ( import (
"runtime" "runtime"
"unsafe" "unsafe"
"github.com/goplus/llgo/c"
) )
type SysProcAttr struct { type SysProcAttr struct {
@@ -77,8 +79,8 @@ func init() {
// split the stack, or acquire mutexes). We can't call RawSyscall // split the stack, or acquire mutexes). We can't call RawSyscall
// because it's not safe even for BSD-subsystem calls. // 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 // Declare all variables at top in case any
// declarations require heap allocation (e.g., err1). // declarations require heap allocation (e.g., err1).
var ( var (

View File

@@ -52,8 +52,6 @@ func runtime_AfterForkInChild()
// For the same reason compiler does not race instrument it. // For the same reason compiler does not race instrument it.
// The calls to rawSyscall are okay because they are assembly // The calls to rawSyscall are okay because they are assembly
// functions that do not grow the stack. // 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) { 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 // Declare all variables at top in case any
// declarations require heap allocation (e.g., err1). // declarations require heap allocation (e.g., err1).

View File

@@ -6,6 +6,8 @@
package syscall package syscall
import "github.com/goplus/llgo/c"
// Linux unshare/clone/clone2/clone3 flags, architecture-independent, // Linux unshare/clone/clone2/clone3 flags, architecture-independent,
// copied from linux/sched.h. // copied from linux/sched.h.
const ( const (
@@ -119,8 +121,8 @@ func runtime_AfterForkInChild()
// The calls to RawSyscall are okay because they are assembly // The calls to RawSyscall are okay because they are assembly
// functions that do not grow the stack. // 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): /* TODO(xsw):
// Set up and fork. This returns immediately in the parent or // Set up and fork. This returns immediately in the parent or
// if there's an error. // if there's an error.

View File

@@ -15,6 +15,7 @@ import (
_ "unsafe" _ "unsafe"
"github.com/goplus/llgo/c" "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); // int pipe2(int pipefd[2], int flags);
@@ -85,13 +95,9 @@ func (w WaitStatus) TrapCause() int {
//go:linkname pipe2 C.pipe2 //go:linkname pipe2 C.pipe2
func pipe2(pipefd *[2]c.Int, flags c.Int) c.Int 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 { func Pipe2(p []int, flags int) error {
if len(p) != 2 { if len(p) != 2 {
return EINVAL return Errno(syscall.EINVAL)
} }
var pp [2]c.Int var pp [2]c.Int
ret := pipe2(&pp, c.Int(flags)) ret := pipe2(&pp, c.Int(flags))