-
Notifications
You must be signed in to change notification settings - Fork 224
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
bpf() shim don't follow upstream error conventions #3749
Comments
I think I misunderstood how things work, at least partially: ebpf-for-windows/libs/api/libbpf_internal.h Lines 8 to 27 in 0b4142d
The libbpf wrappers use these functions to return integer errors in the correct way. What confused me is that they also set errno, and some tests inspect errno. The
It might make sense to reword this issue to only be about the |
The Linux ABI returns all syscall errors via the function return value, not via errno. Fixes microsoft#3749
The Linux ABI returns all syscall errors via the function return value, not via errno. Fixes microsoft#3749
The Linux ABI returns all syscall errors via the function return value, not via errno. Fixes microsoft#3749
The Linux ABI returns all syscall errors via the function return value, not via errno. Fixes microsoft#3749
* bpf(): do not return errors via errno The Linux ABI returns all syscall errors via the function return value, not via errno. Fixes #3749 * Allow detecting if bpf() command is not implemented Use SetLastError to indicate to callers that a bpf() command is not implemented. This avoids polluting the bpf() return value with platform specific error returns while still allowing detection of this important case. * Add forwards and backwards compatibility to bpf() emulation On Linux, bpf() accepts a bpf_attr which is larger than what the syscall expects, as long as the unknown fields are all 0. It also accepts a bpf_attr which is smaller than what it expects, by assuming that all missing fields are zero. This allows forwards and backwards compatilibity between old and new versions of both the Linux kernel and user space tooling. Implement a similar scheme for the bpf() emulation. * Return EPERM from bpf() if user is not privileged On Linux, bpf() returns EPERM if the user doesn't have CAP_BPF. Return the same error when the user isn't able to open the device handle.
Describe the bug
The efW libbpf shim uses the convention of returning
-1
and settingerrno
. Upstream libbpf returns errno directly from most functions, except when returning a pointer. See https://libbpf.readthedocs.io/en/latest/api.htmlThis problem extends to the
bpf()
syscall wrapper, which doesn't follow Linux ABI for this reason. See https://man7.org/linux/man-pages/man2/bpf.2.htmlOS information
No response
Steps taken to reproduce bug
Call a libbpf function and inspect the return code.
Expected behavior
errno
should not be modified, and errors returned according to upstream behaviour.Actual outcome
errno
is modified and-1
returned.Additional details
No response
The text was updated successfully, but these errors were encountered: