diff options
author | Michael Pratt <mpratt@google.com> | 2019-04-17 12:13:46 -0700 |
---|---|---|
committer | Shentubot <shentubot@google.com> | 2019-04-17 12:15:01 -0700 |
commit | 08d99c5fbea76ecc92038280387d24ecdf7ed814 (patch) | |
tree | 76df71b51b5515098e8c61978c441e8c530526ff /pkg/sentry/socket/rpcinet/notifier/notifier.go | |
parent | e091b4e7c07056e32120ab25cc9a78ed24f7c754 (diff) |
Convert poll/select to operate more directly on linux.PollFD
Current, doPoll copies the user struct pollfd array into a
[]syscalls.PollFD, which contains internal kdefs.FD and
waiter.EventMask types. While these are currently binary-compatible with
the Linux versions, we generally discourage copying directly to internal
types (someone may inadvertantly change kdefs.FD to uint64).
Instead, copy directly to a []linux.PollFD, which will certainly be
binary compatible. Most of syscalls/polling.go is included directly into
syscalls/linux/sys_poll.go, as it can then operate directly on
linux.PollFD. The additional syscalls.PollFD type is providing little
value.
I've also added explicit conversion functions for waiter.EventMask,
which creates the possibility of a different binary format.
PiperOrigin-RevId: 244042947
Change-Id: I24e5b642002a32b3afb95a9dcb80d4acd1288abf
Diffstat (limited to 'pkg/sentry/socket/rpcinet/notifier/notifier.go')
-rw-r--r-- | pkg/sentry/socket/rpcinet/notifier/notifier.go | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/pkg/sentry/socket/rpcinet/notifier/notifier.go b/pkg/sentry/socket/rpcinet/notifier/notifier.go index 73c255c33..d9bda78b0 100644 --- a/pkg/sentry/socket/rpcinet/notifier/notifier.go +++ b/pkg/sentry/socket/rpcinet/notifier/notifier.go @@ -76,7 +76,7 @@ func (n *Notifier) waitFD(fd uint32, fi *fdInfo, mask waiter.EventMask) error { } e := pb.EpollEvent{ - Events: uint32(mask) | -syscall.EPOLLET, + Events: mask.ToLinux() | -syscall.EPOLLET, Fd: fd, } @@ -178,7 +178,7 @@ func (n *Notifier) waitAndNotify() error { n.mu.Lock() for _, e := range res.(*pb.EpollWaitResponse_Events).Events.Events { if fi, ok := n.fdMap[e.Fd]; ok { - fi.queue.Notify(waiter.EventMask(e.Events)) + fi.queue.Notify(waiter.EventMaskFromLinux(e.Events)) } } n.mu.Unlock() @@ -214,7 +214,7 @@ func (n *Notifier) HasFD(fd uint32) bool { // although the syscall is non-blocking. func (n *Notifier) NonBlockingPoll(fd uint32, mask waiter.EventMask) waiter.EventMask { for { - id, c := n.rpcConn.NewRequest(pb.SyscallRequest{Args: &pb.SyscallRequest_Poll{&pb.PollRequest{Fd: fd, Events: uint32(mask)}}}, false /* ignoreResult */) + id, c := n.rpcConn.NewRequest(pb.SyscallRequest{Args: &pb.SyscallRequest_Poll{&pb.PollRequest{Fd: fd, Events: mask.ToLinux()}}}, false /* ignoreResult */) <-c res := n.rpcConn.Request(id).Result.(*pb.SyscallResponse_Poll).Poll.Result @@ -225,6 +225,6 @@ func (n *Notifier) NonBlockingPoll(fd uint32, mask waiter.EventMask) waiter.Even return mask } - return waiter.EventMask(res.(*pb.PollResponse_Events).Events) + return waiter.EventMaskFromLinux(res.(*pb.PollResponse_Events).Events) } } |