Debian Codegraph @

libgo/go/os/wait_wait6.go

raw
1 // Copyright 2016 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
4
5 //go:build dragonfly || freebsd
6
7 package os
8
9 import (
10 "runtime"
11 "syscall"
12 )
13
14 const _P_PID = 0
15
16 // blockUntilWaitable attempts to block until a call to p.Wait will
17 // succeed immediately, and reports whether it has done so.
18 // It does not actually call p.Wait.
19 func (p *Process) blockUntilWaitable() (bool, error) {
20 var errno syscall.Errno
21 for {
22 // The arguments on 32-bit FreeBSD look like the following:
23 // - freebsd32_wait6_args{ idtype, id1, id2, status, options, wrusage, info } or
24 // - freebsd32_wait6_args{ idtype, pad, id1, id2, status, options, wrusage, info } when PAD64_REQUIRED=1 on ARM, MIPS or PowerPC
25 if runtime.GOOS == "freebsd" && runtime.GOARCH == "386" {
26 _, _, errno = syscall.Syscall9(syscall.SYS_WAIT6, _P_PID, uintptr(p.Pid), 0, 0, syscall.WEXITED|syscall.WNOWAIT, 0, 0, 0, 0)
27 } else if runtime.GOOS == "freebsd" && runtime.GOARCH == "arm" {
28 _, _, errno = syscall.Syscall9(syscall.SYS_WAIT6, _P_PID, 0, uintptr(p.Pid), 0, 0, syscall.WEXITED|syscall.WNOWAIT, 0, 0, 0)
29 } else {
30 _, _, errno = syscall.Syscall6(syscall.SYS_WAIT6, _P_PID, uintptr(p.Pid), 0, syscall.WEXITED|syscall.WNOWAIT, 0, 0)
31 }
32 if errno != syscall.EINTR {
33 break
34 }
35 }
36 runtime.KeepAlive(p)
37 if errno == syscall.ENOSYS {
38 return false, nil
39 } else if errno != 0 {
40 return false, NewSyscallError("wait6", errno)
41 }
42 return true, nil
43 }