Fix the return value of sched_getaffinity.

This commit is contained in:
Shuocheng Wang 2021-07-19 10:49:30 +08:00 committed by Zongmin.Gu
parent eb07b01ac0
commit 3e7fc94ca7
2 changed files with 3 additions and 6 deletions

@ -20,8 +20,10 @@ pub struct CpuSet {
impl CpuSet { impl CpuSet {
/// Returns the length of a CPU set in bytes. /// Returns the length of a CPU set in bytes.
///
/// The length must be an integer multiple of sizeof(long) in Linux.
pub fn len() -> usize { pub fn len() -> usize {
align_up(Self::ncores(), 8) / 8 align_up(align_up(Self::ncores(), 8) / 8, 8)
} }
/// Returns the number CPU of cores in a CPU set. /// Returns the number CPU of cores in a CPU set.

@ -14,11 +14,6 @@ pub fn do_sched_getaffinity(pid: pid_t, buf_size: size_t, buf_ptr: *mut u8) -> R
return_errno!(EINVAL, "buf size is not big enough"); return_errno!(EINVAL, "buf size is not big enough");
} }
// Linux stores the cpumask in an array of "unsigned long" so the buffer needs to be
// multiple of unsigned long. However, Occlum doesn't have this restriction.
if (buf_size & (std::mem::size_of::<u64>() - 1) != 0) {
warn!("cpuset buf size is not a multiple of unsigned long");
}
CpuSet::len() CpuSet::len()
}; };
let mut buf_slice = { let mut buf_slice = {