From 3e7fc94ca779fc91c0131221222d81b1c217441f Mon Sep 17 00:00:00 2001 From: Shuocheng Wang Date: Mon, 19 Jul 2021 10:49:30 +0800 Subject: [PATCH] Fix the return value of sched_getaffinity. --- src/libos/src/sched/cpu_set.rs | 4 +++- src/libos/src/sched/syscalls.rs | 5 ----- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/src/libos/src/sched/cpu_set.rs b/src/libos/src/sched/cpu_set.rs index bdedf415..f0175940 100644 --- a/src/libos/src/sched/cpu_set.rs +++ b/src/libos/src/sched/cpu_set.rs @@ -20,8 +20,10 @@ pub struct CpuSet { impl CpuSet { /// 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 { - 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. diff --git a/src/libos/src/sched/syscalls.rs b/src/libos/src/sched/syscalls.rs index 13dd128f..e3741b09 100644 --- a/src/libos/src/sched/syscalls.rs +++ b/src/libos/src/sched/syscalls.rs @@ -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"); } - // 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::() - 1) != 0) { - warn!("cpuset buf size is not a multiple of unsigned long"); - } CpuSet::len() }; let mut buf_slice = {