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
Add linux support for sched_attr
and related syscalls
#3494
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @JohnTitor (or someone else) soon. Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (
|
// This is a workaround since glibc provides no wrappers for these syscalls. | ||
// Therefore we implement them directly through `syscall` | ||
pub fn sched_getattr( | ||
pid: ::pid_t, | ||
attr: *mut ::sched_attr, | ||
size: ::c_uint, | ||
flags: ::c_uint | ||
) -> ::c_int { | ||
::syscall(::SYS_sched_getattr, pid, attr, size, flags) as ::c_int | ||
} | ||
pub fn sched_setattr(pid: ::pid_t, attr: *mut ::sched_attr, flags: ::c_uint) -> ::c_int { | ||
::syscall(::SYS_sched_setattr, pid, attr, flags) as ::c_int | ||
} |
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.
The libc crate is a thin wrapper, and if glibc doesn't expose it, it shouldn't be added.
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.
Thanks for your response.
Before opening this PR I had seen that there are already some methods in the android target which are not exposed and use the syscall directly, so I hoped this might also be applicable here.
E.g.
libc/src/unix/linux_like/android/b32/x86/mod.rs
Lines 591 to 615 in e077dbf
f! { | |
// Sadly, Android before 5.0 (API level 21), the accept4 syscall is not | |
// exposed by the libc. As work-around, we implement it as raw syscall. | |
// Note that for x86, the `accept4` syscall is not available either, | |
// and we must use the `socketcall` syscall instead. | |
// This workaround can be removed if the minimum Android version is bumped. | |
// When the workaround is removed, `accept4` can be moved back | |
// to `linux_like/mod.rs` | |
pub fn accept4( | |
fd: ::c_int, | |
addr: *mut ::sockaddr, | |
len: *mut ::socklen_t, | |
flg: ::c_int | |
) -> ::c_int { | |
// Arguments are passed as array of `long int` | |
// (which is big enough on x86 for a pointer). | |
let mut args = [ | |
fd as ::c_long, | |
addr as ::c_long, | |
len as ::c_long, | |
flg as ::c_long, | |
]; | |
::syscall(SYS_socketcall, SYS_ACCEPT4, args[..].as_mut_ptr()) | |
} | |
} |
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.
Note that it's just a temporal workaround, I mean it should also be removed but it isn't now.
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.
I understand, thanks again for your time.
Hi,
I this PR should add support for the
sched_attr
config struct and the relatedsched_getattr
andsched_setattr
syscalls.Since this is my first PR to this repo and I'm not that experienced with the different standard libraries I encountered some problems and wanted to ask for some assistance/ hints on how this best implemented in the interests of this project.
sched_attr
struct is defined inlinux/sched/types.h
but when I add this file to the includes in thebuild.rs
file I get some build errors since the file additionally defines thesched_param
struct which is also defined by thebits/types/struct_sched_param.h
header which is included bypthread.h
.Can you point me in the right direction how this is best resolved?
sched_attr
struct which are distinguished by thesize
field of the struct.Whats in your opinion the best way to represent this in this crate?
Many thanks in advance and sorry for the wall of text above :D