Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace uses of syscall.EPOLLET with unix.EPOLLET #85

Closed
mundaym opened this issue Jul 4, 2018 · 3 comments
Closed

Replace uses of syscall.EPOLLET with unix.EPOLLET #85

mundaym opened this issue Jul 4, 2018 · 3 comments
Labels
type: cleanup Refactorings and cleanups to improve the code

Comments

@mundaym
Copy link

mundaym commented Jul 4, 2018

syscall.EPOLLET has incorrectly been generated as a negative number on 386/amd64/arm. Due to the Go 1 guarantee it is frozen and cannot be fixed (golang/go#5328). This leads to workarounds where EPOLLET is negated before it is used. Unfortunately on other platforms it has the correct, positive, value making the negation incorrect.

Can unix.EPOLLET be used instead (https://godoc.org/golang.org/x/sys/unix#pkg-constants)? It is correct on all platforms.

(@ydjainopensource ran into this while investigating #79)

@ghost
Copy link

ghost commented Jul 4, 2018

syscall.EPOLLET is used at 3 places. However, there is a comment which acknowledges this issue here which makes me question whether the unix pkg was not used on purpose.Can anybody confirm before I send a PR?

I am able to compile if I change it to use unix.

@prattmic
Copy link
Member

prattmic commented Jul 4, 2018

That comment was written before we used the unix package anywhere in gVisor, which is why it isn't used there. Switching to the unix package is fine.

That said, there is an opportunity for a bit more cleanup here.

TL;DR for below, use the unix package here and the linux package here and here. You'll need to add EPOLLET to the linux package.

We use syscall constants like EPOLLET in two different contexts.

  1. Sentry-host interactions.

These are cases where the sentry is making system calls to the host Linux kernel to perform some operation. That is the case here. The sentry is making epoll syscalls to the host, so we use the syscall (or unix) package.

If there were a port of gVisor to another host OS, e.g., FreeBSD, we want to use the appropriate syscall constants for FreeBSD1. The syscall and unix packages do this automatically.

  1. App-sentry interactions.

These are cases where the sandboxed app is making a syscall that the sentry is handling. That is the case here. If we port gVisor to another host OS, we're still running Linux applications inside the sandbox, so using the syscall or unix package is incorrect, as they provide values for the host OS.

For these cases, we use the linux package, which is very similar to syscall/unix, but always provides the values for Linux.

The final use of EPOLLET is an odd edge case inside gVisor, but I believe those protos always expect Linux flags, so IMO it should be using the linux package.

The existence of a gVisor port to a non-Linux host OS is theoretical at this point, so we have not gone through and replaced all instances of case 2 with the linux package, but we've been slowly converting them as we refactor or other issues like this arise.

1 Note that epoll isn't a great example here because it is Linux-specific. A better example would be open flags like syscall.O_RDWR, which are defined on multiple OSes, but may have different values.

@fvoznika fvoznika added the type: cleanup Refactorings and cleanups to improve the code label Jan 11, 2019
@nlacasse
Copy link
Collaborator

nlacasse commented Jun 8, 2021

We no longer use syscall.EPOLLET, but use linux and unix packages as appropriate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: cleanup Refactorings and cleanups to improve the code
Projects
None yet
Development

No branches or pull requests

4 participants