microsoft / ebpf-for-windows

eBPF implementation that runs on top of Windows
MIT License
2.85k stars 217 forks source link

bpf() shim don't follow upstream error conventions #3749

Open lmb opened 1 month ago

lmb commented 1 month ago

Describe the bug

The efW libbpf shim uses the convention of returning -1 and setting errno. Upstream libbpf returns errno directly from most functions, except when returning a pointer. See https://libbpf.readthedocs.io/en/latest/api.html

This 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.html

OS 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

lmb commented 1 month ago

I think I misunderstood how things work, at least partially: https://github.com/microsoft/ebpf-for-windows/blob/0b4142d9d674c0dc1af214aeac102e2696d8d302/libs/api/libbpf_internal.h#L8-L27

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 bpf() wrapper does indeed contain some error returns which aren't according to spec though:

It might make sense to reword this issue to only be about the bpf() wrapper.