-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Linux: add getitimer()
/setitimer()
#3847
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -73,6 +73,14 @@ missing! { | |
pub enum fpos64_t {} // FIXME: fill this out with a struct | ||
} | ||
|
||
cfg_if! { | ||
if #[cfg(target_env = "musl")] { | ||
pub type __itimer_which_t = ::c_int; | ||
} else { | ||
pub type __itimer_which_t = ::c_uint; | ||
} | ||
} | ||
|
||
e! { | ||
pub enum tpacket_versions { | ||
TPACKET_V1, | ||
|
@@ -6116,6 +6124,28 @@ extern "C" { | |
pub fn ioctl(fd: ::c_int, request: ::Ioctl, ...) -> ::c_int; | ||
} | ||
|
||
cfg_if! { | ||
if #[cfg(target_env = "musl")] { | ||
extern "C" { | ||
pub fn getitimer(which: ::c_int, value: *mut ::itimerval) -> ::c_int; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not sure I follow, why not using the typedef you created above ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the result of a strange combination of issues. glibc and most other libc implementations typedef
By defining A more clean solution to this may be to develop There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Another possible approach is not to bother with enums at all. pub type __itimer_which_t = ::c_int;
...
pub const ITIMER_REAL: __itimer_which_t = 0;
... There are various places in this crate were C enums are handled as simple constants. Should pass in theory. |
||
pub fn setitimer( | ||
which: ::c_int, | ||
new: *const ::itimerval, | ||
old: *mut ::itimerval, | ||
) -> ::c_int; | ||
} | ||
} else { | ||
extern "C" { | ||
pub fn getitimer(which: ::__itimer_which_t, value: *mut ::itimerval) -> ::c_int; | ||
pub fn setitimer( | ||
which: ::__itimer_which_t, | ||
new: *const ::itimerval, | ||
old: *mut ::itimerval, | ||
) -> ::c_int; | ||
} | ||
} | ||
} | ||
|
||
// LFS64 extensions | ||
// | ||
// * musl has 64-bit versions only so aliases the LFS64 symbols to the standard ones | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
glibc has
int
when it is not defined as an enum, and musl doesn't seem to define this type at all - why is the definition done this way?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah nevermind, I see the reasoning below. I think we need to work with one of the ways that doesn't expose this on musl.
In general it is probably better to avoid Rust
enum
s to represent C types at all, given how easy it is to cause UB. So some sort of solution that just typedefs an int on glibc seems preferable to me.