diff options
author | Zach Reizner <zachr@google.com> | 2018-01-09 15:49:04 -0800 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2018-01-10 15:44:31 -0800 |
commit | ee2f1fe7708e1ec164c5da2483c26830e9c69373 (patch) | |
tree | 06a66c73fe292632fec0d56c5b3ebb4771787e25 /sys_util/src/lib.rs | |
parent | 20bb5976367883b43d5d07c2bcc33d68dab25cd7 (diff) | |
download | crosvm-ee2f1fe7708e1ec164c5da2483c26830e9c69373.tar crosvm-ee2f1fe7708e1ec164c5da2483c26830e9c69373.tar.gz crosvm-ee2f1fe7708e1ec164c5da2483c26830e9c69373.tar.bz2 crosvm-ee2f1fe7708e1ec164c5da2483c26830e9c69373.tar.lz crosvm-ee2f1fe7708e1ec164c5da2483c26830e9c69373.tar.xz crosvm-ee2f1fe7708e1ec164c5da2483c26830e9c69373.tar.zst crosvm-ee2f1fe7708e1ec164c5da2483c26830e9c69373.zip |
sys_util: replace sysconf(_SC_PAGESIZE) with a safe wrapper
There were a few places that used this to get the page size inside of an unsafe block, For convenience, this adds a safe wrapper in sys_util and replaces all extant usage of sysconf with the wrapper version. BUG=chromium:800626 TEST=./build_test Change-Id: Ic65bf72aea90eabd4158fbdcdbe25c3f13ca93ac Reviewed-on: https://chromium-review.googlesource.com/857907 Commit-Ready: Zach Reizner <zachr@chromium.org> Tested-by: Zach Reizner <zachr@chromium.org> Reviewed-by: Stephen Barber <smbarber@chromium.org> Reviewed-by: Dylan Reid <dgreid@chromium.org>
Diffstat (limited to 'sys_util/src/lib.rs')
-rw-r--r-- | sys_util/src/lib.rs | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/sys_util/src/lib.rs b/sys_util/src/lib.rs index dea290a..7f9f034 100644 --- a/sys_util/src/lib.rs +++ b/sys_util/src/lib.rs @@ -55,10 +55,18 @@ pub use signalfd::Error as SignalFdError; use std::ffi::CStr; use std::ptr; -use libc::{kill, syscall, waitpid, c_long, pid_t, uid_t, gid_t, SIGKILL, WNOHANG}; +use libc::{kill, syscall, sysconf, waitpid, c_long, pid_t, uid_t, gid_t, _SC_PAGESIZE, + SIGKILL, WNOHANG}; use syscall_defines::linux::LinuxSyscall::SYS_getpid; +/// Safe wrapper for `sysconf(_SC_PAGESIZE)`. +#[inline(always)] +pub fn pagesize() -> usize { + // Trivially safe + unsafe { sysconf(_SC_PAGESIZE) as usize } +} + /// This bypasses `libc`'s caching `getpid(2)` wrapper which can be invalid if a raw clone was used /// elsewhere. #[inline(always)] |