sigsetsize argument to epoll_pwait is incorrect #12715
Labels
bug
Observed behavior contradicts documented or intended behavior
os-linux
standard library
This issue involves writing Zig code for the standard library.
Milestone
Zig Version
0.10.0-dev.3840+2b92c5a23
Steps to Reproduce
Call
std.os.linux.epoll_pwait
with a non-nullsigmask
argument.Complete working example:
Compile with
zig build-exe
and run.Expected Behavior
It should print
epoll_pwait succeeded
.Actual Behavior
It prints
EINVAL
.Zig's implementation of
epoll_pwait
is here:zig/lib/std/os/linux.zig
Lines 1436 to 1446 in 36f4f32
It passes
@sizeOf(sigset_t)
as the final argument of the syscall, which matches what the man page forepoll_pwait
says:Also according to the man page, the only occasion that
EINVAL
should be returned is whenepfd
is not an epoll file descriptor ormaxevents
is less than or equal to zero. But neither of those cases are true in this example. But if you check the Linux kernel sources, you find there is one more case whereEINVAL
can be returned, and that is if thesigsetsize
argument does not match the size of thesigset_t
data structure in the kernel:The
sigset_t
data structure defined in the kernel is 8 bytes (for x86-64):I also checked the glibc sources to see what they are actually doing. They use a macro
__NSIG_BYTES
defined as:which, when you resolve all of the macros, is also 8 bytes for x86-64.
The
sigset_t
that Zig is passing to@sizeOf
is 128 bytes. This size mismatch causes theEINVAL
error. It looks like Zig needs to define a separate constant for thissigsetsize
argument rather than using@sizeOf(sigset_t)
(as theepoll_pwait
man page would have you believe).The text was updated successfully, but these errors were encountered: