summary refs log tree commit diff
path: root/kvm/src/lib.rs
diff options
context:
space:
mode:
authorZach Reizner <zachr@google.com>2018-01-09 15:49:04 -0800
committerchrome-bot <chrome-bot@chromium.org>2018-01-10 15:44:31 -0800
commitee2f1fe7708e1ec164c5da2483c26830e9c69373 (patch)
tree06a66c73fe292632fec0d56c5b3ebb4771787e25 /kvm/src/lib.rs
parent20bb5976367883b43d5d07c2bcc33d68dab25cd7 (diff)
downloadcrosvm-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 'kvm/src/lib.rs')
-rw-r--r--kvm/src/lib.rs8
1 files changed, 4 insertions, 4 deletions
diff --git a/kvm/src/lib.rs b/kvm/src/lib.rs
index 51e8f3a..cb194f8 100644
--- a/kvm/src/lib.rs
+++ b/kvm/src/lib.rs
@@ -17,11 +17,11 @@ use std::collections::hash_map::Entry;
 use std::os::raw::*;
 use std::os::unix::io::{AsRawFd, FromRawFd, RawFd};
 
-use libc::{open, sysconf, O_RDWR, O_CLOEXEC, EINVAL, ENOSPC, ENOENT, _SC_PAGESIZE};
+use libc::{open, O_RDWR, O_CLOEXEC, EINVAL, ENOSPC, ENOENT};
 
 use kvm_sys::*;
 
-use sys_util::{GuestAddress, GuestMemory, MemoryMapping, EventFd, Error, Result};
+use sys_util::{GuestAddress, GuestMemory, MemoryMapping, EventFd, Error, Result, pagesize};
 #[allow(unused_imports)]
 use sys_util::{ioctl, ioctl_with_val, ioctl_with_ref, ioctl_with_mut_ref, ioctl_with_ptr,
                ioctl_with_mut_ptr};
@@ -266,7 +266,7 @@ impl Vm {
     /// region `slot` represents. For example, if the size of `slot` is 16 pages, `dirty_log` must
     /// be 2 bytes or greater.
     pub fn get_dirty_log(&self, slot: u32, dirty_log: &mut [u8]) -> Result<()> {
-        let page_size = unsafe { sysconf(_SC_PAGESIZE) } as usize;
+        let page_size = pagesize();
         match self.device_memory.get(&slot) {
             Some(mmap) => {
                 // Ensures that there are as many bits in dirty_log as there are pages in the mmap.
@@ -907,7 +907,7 @@ mod tests {
     fn vcpu_mmap_size() {
         let kvm = Kvm::new().unwrap();
         let mmap_size = kvm.get_vcpu_mmap_size().unwrap();
-        let page_size = unsafe { libc::sysconf(libc::_SC_PAGESIZE) } as usize;
+        let page_size = pagesize();
         assert!(mmap_size >= page_size);
         assert!(mmap_size % page_size == 0);
     }