Black Lives Matter. Support the Equal Justice Initiative.

Source file src/os/wait_wait6.go

Documentation: os

     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 || netbsd
     6  // +build dragonfly freebsd netbsd
     7  
     8  package os
     9  
    10  import (
    11  	"runtime"
    12  	"syscall"
    13  )
    14  
    15  const _P_PID = 0
    16  
    17  // blockUntilWaitable attempts to block until a call to p.Wait will
    18  // succeed immediately, and reports whether it has done so.
    19  // It does not actually call p.Wait.
    20  func (p *Process) blockUntilWaitable() (bool, error) {
    21  	var errno syscall.Errno
    22  	for {
    23  		// The arguments on 32-bit FreeBSD look like the following:
    24  		// - freebsd32_wait6_args{ idtype, id1, id2, status, options, wrusage, info } or
    25  		// - freebsd32_wait6_args{ idtype, pad, id1, id2, status, options, wrusage, info } when PAD64_REQUIRED=1 on ARM, MIPS or PowerPC
    26  		if runtime.GOOS == "freebsd" && runtime.GOARCH == "386" {
    27  			_, _, errno = syscall.Syscall9(syscall.SYS_WAIT6, _P_PID, uintptr(p.Pid), 0, 0, syscall.WEXITED|syscall.WNOWAIT, 0, 0, 0, 0)
    28  		} else if runtime.GOOS == "freebsd" && runtime.GOARCH == "arm" {
    29  			_, _, errno = syscall.Syscall9(syscall.SYS_WAIT6, _P_PID, 0, uintptr(p.Pid), 0, 0, syscall.WEXITED|syscall.WNOWAIT, 0, 0, 0)
    30  		} else {
    31  			_, _, errno = syscall.Syscall6(syscall.SYS_WAIT6, _P_PID, uintptr(p.Pid), 0, syscall.WEXITED|syscall.WNOWAIT, 0, 0)
    32  		}
    33  		if errno != syscall.EINTR {
    34  			break
    35  		}
    36  	}
    37  	runtime.KeepAlive(p)
    38  	if errno == syscall.ENOSYS {
    39  		return false, nil
    40  	} else if errno != 0 {
    41  		return false, NewSyscallError("wait6", errno)
    42  	}
    43  	return true, nil
    44  }
    45  

View as plain text