Commit 5ee06f54 authored by Clément Chigot's avatar Clément Chigot Committed by Ian Lance Taylor

internal/poll, os/exec, runtime: replace PollDescriptor by IsPollDescriptor

This commit changes poll.PollDescriptor by poll.IsPollDescriptor. This
is needed for OS like AIX which have more than one FD using inside their
netpoll implementation.

Change-Id: I49e12a8d74045c501e19fdd8527cf166a3c64850
Reviewed-on: https://go-review.googlesource.com/c/146938
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: default avatarIan Lance Taylor <iant@golang.org>
parent 56421f26
...@@ -193,10 +193,10 @@ func isInterrupted(err error) bool { ...@@ -193,10 +193,10 @@ func isInterrupted(err error) bool {
return err != nil && stringsHasSuffix(err.Error(), "interrupted") return err != nil && stringsHasSuffix(err.Error(), "interrupted")
} }
// PollDescriptor returns the descriptor being used by the poller, // IsPollDescriptor returns true if fd is the descriptor being used by the poller.
// or ^uintptr(0) if there isn't one. This is only used for testing. // This is only used for testing.
func PollDescriptor() uintptr { func IsPollDescriptor(fd uintptr) bool {
return ^uintptr(0) return false
} }
// RawControl invokes the user-defined function f for a non-IO // RawControl invokes the user-defined function f for a non-IO
......
...@@ -92,8 +92,8 @@ func setDeadlineImpl(fd *FD, t time.Time, mode int) error { ...@@ -92,8 +92,8 @@ func setDeadlineImpl(fd *FD, t time.Time, mode int) error {
return nil return nil
} }
// PollDescriptor returns the descriptor being used by the poller, // IsPollDescriptor returns true if fd is the descriptor being used by the poller.
// or ^uintptr(0) if there isn't one. This is only used for testing. // This is only used for testing.
func PollDescriptor() uintptr { func IsPollDescriptor(fd uintptr) bool {
return ^uintptr(0) return false
} }
...@@ -19,7 +19,6 @@ import ( ...@@ -19,7 +19,6 @@ import (
func runtimeNano() int64 func runtimeNano() int64
func runtime_pollServerInit() func runtime_pollServerInit()
func runtime_pollServerDescriptor() uintptr
func runtime_pollOpen(fd uintptr) (uintptr, int) func runtime_pollOpen(fd uintptr) (uintptr, int)
func runtime_pollClose(ctx uintptr) func runtime_pollClose(ctx uintptr)
func runtime_pollWait(ctx uintptr, mode int) int func runtime_pollWait(ctx uintptr, mode int) int
...@@ -27,6 +26,7 @@ func runtime_pollWaitCanceled(ctx uintptr, mode int) int ...@@ -27,6 +26,7 @@ func runtime_pollWaitCanceled(ctx uintptr, mode int) int
func runtime_pollReset(ctx uintptr, mode int) int func runtime_pollReset(ctx uintptr, mode int) int
func runtime_pollSetDeadline(ctx uintptr, d int64, mode int) func runtime_pollSetDeadline(ctx uintptr, d int64, mode int)
func runtime_pollUnblock(ctx uintptr) func runtime_pollUnblock(ctx uintptr)
func runtime_isPollServerDescriptor(fd uintptr) bool
type pollDesc struct { type pollDesc struct {
runtimeCtx uintptr runtimeCtx uintptr
...@@ -154,8 +154,8 @@ func setDeadlineImpl(fd *FD, t time.Time, mode int) error { ...@@ -154,8 +154,8 @@ func setDeadlineImpl(fd *FD, t time.Time, mode int) error {
return nil return nil
} }
// PollDescriptor returns the descriptor being used by the poller, // IsPollDescriptor returns true if fd is the descriptor being used by the poller.
// or ^uintptr(0) if there isn't one. This is only used for testing. // This is only used for testing.
func PollDescriptor() uintptr { func IsPollDescriptor(fd uintptr) bool {
return runtime_pollServerDescriptor() return runtime_isPollServerDescriptor(fd)
} }
...@@ -459,7 +459,7 @@ func basefds() uintptr { ...@@ -459,7 +459,7 @@ func basefds() uintptr {
// The poll (epoll/kqueue) descriptor can be numerically // The poll (epoll/kqueue) descriptor can be numerically
// either between stderr and the testlog-fd, or after // either between stderr and the testlog-fd, or after
// testlog-fd. // testlog-fd.
if poll.PollDescriptor() == n { if poll.IsPollDescriptor(n) {
n++ n++
} }
for _, arg := range os.Args { for _, arg := range os.Args {
...@@ -472,7 +472,7 @@ func basefds() uintptr { ...@@ -472,7 +472,7 @@ func basefds() uintptr {
func closeUnexpectedFds(t *testing.T, m string) { func closeUnexpectedFds(t *testing.T, m string) {
for fd := basefds(); fd <= 101; fd++ { for fd := basefds(); fd <= 101; fd++ {
if fd == poll.PollDescriptor() { if poll.IsPollDescriptor(fd) {
continue continue
} }
err := os.NewFile(fd, "").Close() err := os.NewFile(fd, "").Close()
...@@ -734,6 +734,8 @@ func TestHelperProcess(*testing.T) { ...@@ -734,6 +734,8 @@ func TestHelperProcess(*testing.T) {
ofcmd = "fstat" ofcmd = "fstat"
case "plan9": case "plan9":
ofcmd = "/bin/cat" ofcmd = "/bin/cat"
case "aix":
ofcmd = "procfiles"
} }
args := os.Args args := os.Args
...@@ -837,7 +839,7 @@ func TestHelperProcess(*testing.T) { ...@@ -837,7 +839,7 @@ func TestHelperProcess(*testing.T) {
// Now verify that there are no other open fds. // Now verify that there are no other open fds.
var files []*os.File var files []*os.File
for wantfd := basefds() + 1; wantfd <= 100; wantfd++ { for wantfd := basefds() + 1; wantfd <= 100; wantfd++ {
if wantfd == poll.PollDescriptor() { if poll.IsPollDescriptor(wantfd) {
continue continue
} }
f, err := os.Open(os.Args[0]) f, err := os.Open(os.Args[0])
...@@ -851,6 +853,8 @@ func TestHelperProcess(*testing.T) { ...@@ -851,6 +853,8 @@ func TestHelperProcess(*testing.T) {
switch runtime.GOOS { switch runtime.GOOS {
case "plan9": case "plan9":
args = []string{fmt.Sprintf("/proc/%d/fd", os.Getpid())} args = []string{fmt.Sprintf("/proc/%d/fd", os.Getpid())}
case "aix":
args = []string{fmt.Sprint(os.Getpid())}
default: default:
args = []string{"-p", fmt.Sprint(os.Getpid())} args = []string{"-p", fmt.Sprint(os.Getpid())}
} }
......
...@@ -93,12 +93,19 @@ func netpollinited() bool { ...@@ -93,12 +93,19 @@ func netpollinited() bool {
return atomic.Load(&netpollInited) != 0 return atomic.Load(&netpollInited) != 0
} }
//go:linkname poll_runtime_pollServerDescriptor internal/poll.runtime_pollServerDescriptor //go:linkname poll_runtime_isPollServerDescriptor internal/poll.runtime_isPollServerDescriptor
// poll_runtime_pollServerDescriptor returns the descriptor being used, // poll_runtime_isPollServerDescriptor returns true if fd is a
// or ^uintptr(0) if the system does not use a poll descriptor. // descriptor being used by netpoll.
func poll_runtime_pollServerDescriptor() uintptr { func poll_runtime_isPollServerDescriptor(fd uintptr) bool {
return netpolldescriptor() fds := netpolldescriptor()
if GOOS != "aix" {
return fd == fds
} else {
// AIX have a pipe in its netpoll implementation.
// Therefore, two fd are returned by netpolldescriptor using a mask.
return fd == fds&0xFFFF || fd == (fds>>16)&0xFFFF
}
} }
//go:linkname poll_runtime_pollOpen internal/poll.runtime_pollOpen //go:linkname poll_runtime_pollOpen internal/poll.runtime_pollOpen
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment