• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

google / alioth / 17385983897

01 Sep 2025 07:41PM UTC coverage: 18.009% (-0.1%) from 18.149%
17385983897

Pull #281

github

web-flow
Merge 782c57b11 into 6ec9a6d6b
Pull Request #281: Port to Apple Hypervisor framework

0 of 154 new or added lines in 11 files covered. (0.0%)

1166 existing lines in 29 files now uncovered.

1362 of 7563 relevant lines covered (18.01%)

18.77 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/alioth/src/hv/kvm/device.rs
1
// Copyright 2024 Google LLC
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
//     https://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14

15
use std::mem::{MaybeUninit, size_of_val};
16
use std::os::fd::{AsFd, BorrowedFd, FromRawFd, OwnedFd};
17

18
use snafu::ResultExt;
19

20
use crate::hv::kvm::bindings::{KvmCreateDevice, KvmDevType, KvmDeviceAttr};
21
use crate::hv::kvm::ioctls::{kvm_create_device, kvm_get_device_attr, kvm_set_device_attr};
22
use crate::hv::kvm::kvm_error;
23
use crate::hv::{KvmError, Result};
24

25
#[derive(Debug)]
26
pub(super) struct KvmDevice(pub OwnedFd);
27

28
impl KvmDevice {
UNCOV
29
    pub fn new(vm_fd: &impl AsFd, type_: KvmDevType) -> Result<KvmDevice, KvmError> {
30
        let mut create_device = KvmCreateDevice {
31
            type_,
32
            fd: 0,
33
            flags: 0,
34
        };
UNCOV
35
        unsafe { kvm_create_device(vm_fd, &mut create_device) }
UNCOV
36
            .context(kvm_error::CreateDevice { type_ })?;
UNCOV
37
        Ok(KvmDevice(unsafe { OwnedFd::from_raw_fd(create_device.fd) }))
38
    }
39
}
40

41
impl AsFd for KvmDevice {
UNCOV
42
    fn as_fd(&self) -> BorrowedFd<'_> {
UNCOV
43
        self.0.as_fd()
44
    }
45
}
46

47
impl KvmDevice {
48
    pub fn set_attr<T>(&self, group: u32, attr: u64, val: &T) -> Result<(), KvmError> {
×
49
        let attr = KvmDeviceAttr {
50
            group,
51
            attr,
52
            addr: if size_of_val(val) == 0 {
×
53
                0
54
            } else {
55
                val as *const _ as _
56
            },
57
            _flags: 0,
58
        };
59
        unsafe { kvm_set_device_attr(self, &attr) }.context(kvm_error::DeviceAttr)?;
×
60
        Ok(())
×
61
    }
62

63
    pub fn get_attr<T>(&self, group: u32, attr: u64) -> Result<T, KvmError> {
×
64
        let mut val = MaybeUninit::uninit();
×
65
        let attr = KvmDeviceAttr {
66
            group,
67
            attr,
68
            addr: val.as_mut_ptr() as _,
×
69
            _flags: 0,
70
        };
71
        unsafe { kvm_get_device_attr(self, &attr) }.context(kvm_error::DeviceAttr)?;
×
72
        Ok(unsafe { val.assume_init() })
×
73
    }
74
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc