mirror of
https://chromium.googlesource.com/crosvm/crosvm
synced 2024-11-25 05:03:05 +00:00
kvm: fix invocation of KVM_SET_SIGNAL_MASK ioctl
Linux kernel expects size of sigset passed in through KVM_SET_SIGNAL_MASK ioctl to be exactly 8, but Rust's sigset size is 128 bytes, so we can not use sizeof to set up the size. Also let's add test set_signal_mask(). TEST=cargo test --features plugin; cargo test -p kvm; ./build_test BUG=chromium:800626 Change-Id: Ica757ad63d6754d5c8008ba1735982c7ca026f33 Signed-off-by: Dmitry Torokhov <dtor@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/944849 Reviewed-by: Zach Reizner <zachr@chromium.org>
This commit is contained in:
parent
818afd6eb0
commit
e423460238
1 changed files with 18 additions and 1 deletions
|
@ -967,7 +967,15 @@ impl Vcpu {
|
|||
// ensures no out-of-bounds errors below.
|
||||
&mut *(vec.as_ptr() as *mut kvm_signal_mask)
|
||||
};
|
||||
kvm_sigmask.len = size_of::<sigset_t>() as u32;
|
||||
|
||||
// Rust definition of sigset_t takes 128 bytes, but the kernel only
|
||||
// expects 8-bytes structure, so we can't write
|
||||
// kvm_sigmask.len = size_of::<sigset_t>() as u32;
|
||||
kvm_sigmask.len = 8;
|
||||
// Ensure the length is not too big.
|
||||
const _ASSERT: usize = size_of::<sigset_t>() - 8 as usize;
|
||||
|
||||
// Safe as we allocated exactly the needed space
|
||||
unsafe {
|
||||
std::ptr::copy(&sigset, kvm_sigmask.sigset.as_mut_ptr() as *mut sigset_t, 1);
|
||||
}
|
||||
|
@ -1301,6 +1309,15 @@ mod tests {
|
|||
.unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn set_signal_mask() {
|
||||
let kvm = Kvm::new().unwrap();
|
||||
let gm = GuestMemory::new(&vec![(GuestAddress(0), 0x10000)]).unwrap();
|
||||
let vm = Vm::new(&kvm, gm).unwrap();
|
||||
let vcpu = Vcpu::new(0, &kvm, &vm).unwrap();
|
||||
vcpu.set_signal_mask(&[sys_util::SIGRTMIN() + 0]).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn vcpu_mmap_size() {
|
||||
let kvm = Kvm::new().unwrap();
|
||||
|
|
Loading…
Reference in a new issue