Skip to content

Commit

Permalink
bpf(): do not return errors via errno
Browse files Browse the repository at this point in the history
The Linux ABI returns all syscall errors via the function return value,
not via errno.

Fixes microsoft#3749
  • Loading branch information
lmb committed Aug 12, 2024
1 parent 54632eb commit bd64bca
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions libs/api/bpf_syscall.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,16 @@

#define CHECK_SIZE(last_field_name) \
if (size < offsetof(union bpf_attr, last_field_name) + sizeof(attr->last_field_name)) { \
errno = EINVAL; \
return -1; \
return -EINVAL; \
}

int
bpf(int cmd, union bpf_attr* attr, unsigned int size)
{
// bpf() is ABI compatible with the Linux bpf() syscall.
//
// * Do not return errors via errno.

switch (cmd) {
case BPF_LINK_DETACH:
CHECK_SIZE(link_detach.link_fd);
Expand Down Expand Up @@ -53,8 +56,7 @@ bpf(int cmd, union bpf_attr* attr, unsigned int size)
case BPF_OBJ_GET:
CHECK_SIZE(bpf_fd);
if (attr->bpf_fd != 0) {
errno = EINVAL;
return -1;
return -EINVAL;
}
return bpf_obj_get((const char*)attr->pathname);
case BPF_PROG_ATTACH: {
Expand Down Expand Up @@ -120,7 +122,6 @@ bpf(int cmd, union bpf_attr* attr, unsigned int size)
return retval;
}
default:
errno = EINVAL;
return -1;
return -EINVAL;
}
}

0 comments on commit bd64bca

Please sign in to comment.