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

std.posix.errno fails when syscall fails and libc is linked #19849

Open
ProkopRandacek opened this issue May 3, 2024 · 0 comments
Open

std.posix.errno fails when syscall fails and libc is linked #19849

ProkopRandacek opened this issue May 3, 2024 · 0 comments
Labels
bug Observed behavior contradicts documented or intended behavior

Comments

@ProkopRandacek
Copy link
Contributor

Zig Version

0.13.0-dev.46+3648d7df1

Steps to Reproduce and Observed Behavior

The std.posix.errno function contains a check if libc is linked. if it is, then it assumes that a syscall will return -1 on failure and set the C's errno value. It seems like it assumes when libc is linked then all syscalls are made using the libc. The problem is that some syscalls dont have a libc wrap (such as perf_event_open) so it still calls the raw syscall

When the syscalls fails the errno wrongly returns SUCCESS and then the perf_event_open .SUCCESS intCast crashes.

I guess better solution could be two separate errno functions, one for syscalls and one for libc functions?

Expected Behavior

No crash, corrent error returned.

@ProkopRandacek ProkopRandacek added the bug Observed behavior contradicts documented or intended behavior label May 3, 2024
@ProkopRandacek ProkopRandacek changed the title std.posix.errno invalid usage std.posix.errno fails when syscall fails and libc is linked May 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Observed behavior contradicts documented or intended behavior
Projects
None yet
Development

No branches or pull requests

1 participant