Skip to content

Commit 7feb687

Browse files
Bryan C. Millsgopherbot
Bryan C. Mills
authored andcommitted
os: split wait6 syscall wrapper into per-platform files
There are getting to be enough special cases in this wrapper that the increase in clarity from having a single file is starting to be outweighed by the complexity from chained conditionals. Updates #50138. Updates #13987. Change-Id: If4f1be19c0344e249aa6092507c28363ca6c8438 Reviewed-on: https://go-review.googlesource.com/c/go/+/442575 Run-TryBot: Bryan Mills <bcmills@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Auto-Submit: Bryan Mills <bcmills@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com>
1 parent c79b200 commit 7feb687

6 files changed

+93
-17
lines changed

src/os/wait6_dragonfly.go

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright 2022 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+
package os
6+
7+
import (
8+
"syscall"
9+
"unsafe"
10+
)
11+
12+
const _P_PID = 0
13+
14+
func wait6(idtype, id, options int) (status int, errno syscall.Errno) {
15+
var status32 int32 // C.int
16+
_, _, errno = syscall.Syscall6(syscall.SYS_WAIT6, uintptr(idtype), uintptr(id), uintptr(unsafe.Pointer(&status32)), uintptr(options), 0, 0)
17+
return int(status32), errno
18+
}

src/os/wait6_freebsd64.go

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Copyright 2022 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 freebsd && (amd64 || arm64 || riscv64)
6+
7+
package os
8+
9+
import (
10+
"syscall"
11+
"unsafe"
12+
)
13+
14+
const _P_PID = 0
15+
16+
func wait6(idtype, id, options int) (status int, errno syscall.Errno) {
17+
var status32 int32 // C.int
18+
_, _, errno = syscall.Syscall6(syscall.SYS_WAIT6, uintptr(idtype), uintptr(id), uintptr(unsafe.Pointer(&status32)), uintptr(options), 0, 0)
19+
return int(status32), errno
20+
}

src/os/wait6_freebsd_386.go

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright 2022 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+
package os
6+
7+
import (
8+
"syscall"
9+
"unsafe"
10+
)
11+
12+
const _P_PID = 0
13+
14+
func wait6(idtype, id, options int) (status int, errno syscall.Errno) {
15+
// freebsd32_wait6_args{ idtype, id1, id2, status, options, wrusage, info }
16+
_, _, errno = syscall.Syscall9(syscall.SYS_WAIT6, uintptr(idtype), uintptr(id), 0, uintptr(unsafe.Pointer(&status)), uintptr(options), 0, 0, 0, 0)
17+
return status, errno
18+
}

src/os/wait6_freebsd_arm.go

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright 2022 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+
package os
6+
7+
import (
8+
"syscall"
9+
"unsafe"
10+
)
11+
12+
const _P_PID = 0
13+
14+
func wait6(idtype, id, options int) (status int, errno syscall.Errno) {
15+
// freebsd32_wait6_args{ idtype, pad, id1, id2, status, options, wrusage, info }
16+
_, _, errno = syscall.Syscall9(syscall.SYS_WAIT6, uintptr(idtype), 0, uintptr(id), 0, uintptr(unsafe.Pointer(&status)), uintptr(options), 0, 0, 0)
17+
return status, errno
18+
}

src/os/wait6_netbsd.go

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright 2022 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+
package os
6+
7+
import (
8+
"syscall"
9+
"unsafe"
10+
)
11+
12+
const _P_PID = 1 // not 0 as on FreeBSD and Dragonfly!
13+
14+
func wait6(idtype, id, options int) (status int, errno syscall.Errno) {
15+
var status32 int32 // C.int
16+
_, _, errno = syscall.Syscall6(syscall.SYS_WAIT6, uintptr(idtype), uintptr(id), uintptr(unsafe.Pointer(&status32)), uintptr(options), 0, 0)
17+
return int(status32), errno
18+
}

src/os/wait_wait6.go

+1-17
Original file line numberDiff line numberDiff line change
@@ -11,29 +11,13 @@ import (
1111
"syscall"
1212
)
1313

14-
const (
15-
_P_PID = 0 // everywhere except for NetBSD?
16-
_P_PID_NETBSD = 1 // on NetBSD, 0 is P_ALL
17-
)
18-
1914
// blockUntilWaitable attempts to block until a call to p.Wait will
2015
// succeed immediately, and reports whether it has done so.
2116
// It does not actually call p.Wait.
2217
func (p *Process) blockUntilWaitable() (bool, error) {
2318
var errno syscall.Errno
2419
for {
25-
// The arguments on 32-bit FreeBSD look like the following:
26-
// - freebsd32_wait6_args{ idtype, id1, id2, status, options, wrusage, info } or
27-
// - freebsd32_wait6_args{ idtype, pad, id1, id2, status, options, wrusage, info } when PAD64_REQUIRED=1 on ARM, MIPS or PowerPC
28-
if runtime.GOOS == "freebsd" && runtime.GOARCH == "386" {
29-
_, _, errno = syscall.Syscall9(syscall.SYS_WAIT6, _P_PID, uintptr(p.Pid), 0, 0, syscall.WEXITED|syscall.WNOWAIT, 0, 0, 0, 0)
30-
} else if runtime.GOOS == "freebsd" && runtime.GOARCH == "arm" {
31-
_, _, errno = syscall.Syscall9(syscall.SYS_WAIT6, _P_PID, 0, uintptr(p.Pid), 0, 0, syscall.WEXITED|syscall.WNOWAIT, 0, 0, 0)
32-
} else if runtime.GOOS == "netbsd" {
33-
_, _, errno = syscall.Syscall6(syscall.SYS_WAIT6, _P_PID_NETBSD, uintptr(p.Pid), 0, syscall.WEXITED|syscall.WNOWAIT, 0, 0)
34-
} else {
35-
_, _, errno = syscall.Syscall6(syscall.SYS_WAIT6, _P_PID, uintptr(p.Pid), 0, syscall.WEXITED|syscall.WNOWAIT, 0, 0)
36-
}
20+
_, errno = wait6(_P_PID, p.Pid, syscall.WEXITED|syscall.WNOWAIT)
3721
if errno != syscall.EINTR {
3822
break
3923
}

0 commit comments

Comments
 (0)