Skip to content

Commit 1eb0260

Browse files
add libc support
1 parent 75da5f8 commit 1eb0260

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

src/backend/libc/thread/syscalls.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -709,6 +709,28 @@ pub(crate) fn sched_getcpu() -> usize {
709709
r as usize
710710
}
711711

712+
#[cfg(linux_kernel)]
713+
#[inline]
714+
pub(crate) fn getcpu() -> (usize, usize) {
715+
let (mut cpu, mut node): (core::mem::MaybeUninit<u32>, core::mem::MaybeUninit<u32>) = (
716+
core::mem::MaybeUninit::uninit(),
717+
core::mem::MaybeUninit::uninit(),
718+
);
719+
720+
let r = unsafe {
721+
libc::syscall(
722+
libc::SYS_getcpu,
723+
cpu.as_mut_ptr(),
724+
node.as_mut_ptr(),
725+
core::ptr::null::<libc::c_void>(),
726+
)
727+
};
728+
729+
debug_assert!(r >= 0);
730+
731+
unsafe { (cpu.assume_init() as usize, node.assume_init() as usize) }
732+
}
733+
712734
#[cfg(any(freebsdlike, linux_kernel, target_os = "fuchsia"))]
713735
#[inline]
714736
pub(crate) fn sched_getaffinity(pid: Option<Pid>, cpuset: &mut RawCpuSet) -> io::Result<()> {

0 commit comments

Comments
 (0)