std.posix.timerfd_create can reach unreachable
code
#20334
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.14.0-dev.58+254a3ba9d
Steps to Reproduce and Observed Behavior
This example program will reach unreachable code in
std.posix.timerfd_create
:Expected Behavior
On Linux, the
timerfd_create
syscall will returnEINVAL
ifclockid
is not one ofCLOCK_MONOTONIC
,CLOCK_REALTIME
,CLOCK_REALTIME_ALARM
,CLOCK_BOOTTIME
,CLOCK_BOOTTIME_ALARM
. This is a stricter list of allowed clock ids than for some other syscalls, for exampleCLOCK_TAI
, while otherwise a valid clock id, is not valid here.Kernel source: https://github.com/torvalds/linux/blob/14d7c92f8df9c0964ae6f8b813c1b3ac38120825/fs/timerfd.c#L426
FreeBSD (#20308): On FreeBSD only
CLOCK_REALTIME
,CLOCK_MONOTONIC
, andCLOCK_UPTIME
are allowed, which is also a subset of the clock ids on FreeBSD. (CLOCK_UPTIME
is not listed as allowed in the man pages, but the source code allows it and my testing shows that it is working)https://github.com/freebsd/freebsd-src/blob/1389314d53531e06c7ec02406b0addf7d77e7db7/sys/kern/sys_timerfd.c#L447
https://man.freebsd.org/cgi/man.cgi?query=clock_gettime
As I see it, there are two alternatives:
std.posix.timerfd_create
should take anenum
as clock id (which will have to be specific to timerfd_create, as it uses a smaller subset) instead of ani32
unreachable
I'm very much in favor of option 1.
The text was updated successfully, but these errors were encountered: