• 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/hvf/hvf.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
mod bindings;
16
#[path = "vcpu/vcpu.rs"]
17
mod vcpu;
18
mod vm;
19

20
use std::collections::HashMap;
21
use std::fmt::{Display, Formatter};
22
use std::io::ErrorKind;
23
use std::os::raw::c_void;
24
use std::ptr::null_mut;
25
use std::sync::Arc;
26

27
use parking_lot::Mutex;
28
use snafu::ResultExt;
29

30
use crate::hv::hvf::bindings::os_release;
31
use crate::hv::{Hypervisor, Result, VmConfig, error};
32

33
use self::bindings::hv_vm_create;
34
use self::vm::HvfVm;
35

36
#[derive(Debug, Clone, Copy)]
37
#[repr(transparent)]
38
pub struct HvReturn(i32);
39

40
impl Display for HvReturn {
41
    fn fmt(&self, f: &mut Formatter) -> std::fmt::Result {
×
NEW
42
        let msg = match self.0 & 0xff {
×
NEW
43
            0x01 => "Error",
×
NEW
44
            0x02 => "Busy",
×
NEW
45
            0x03 => "Bad argument",
×
NEW
46
            0x04 => "Illegal guest state",
×
NEW
47
            0x05 => "No resources",
×
NEW
48
            0x06 => "No device",
×
NEW
49
            0x07 => "Denied",
×
NEW
50
            0x0f => "Unsupported",
×
NEW
51
            _ => "Unknown",
×
52
        };
NEW
53
        write!(f, "{msg} {:#x}", self.0 as u32)
×
54
    }
55
}
56

57
impl std::error::Error for HvReturn {}
58

59
fn check_ret(ret: i32) -> std::io::Result<()> {
×
60
    if ret == 0 {
×
61
        return Ok(());
×
62
    }
63
    let kind = match (ret as u32) & 0xff {
NEW
64
        0x02 => ErrorKind::ResourceBusy,
×
NEW
65
        0x03 => ErrorKind::InvalidInput,
×
NEW
66
        0x05 => ErrorKind::NotFound,
×
NEW
67
        0x07 => ErrorKind::PermissionDenied,
×
NEW
68
        0x0f => ErrorKind::Unsupported,
×
NEW
69
        _ => ErrorKind::Other,
×
70
    };
71
    Err(std::io::Error::new(kind, HvReturn(ret)))
72
}
73

74
#[derive(Debug)]
75
struct OsObject {
76
    addr: usize,
77
}
78

79
impl Drop for OsObject {
NEW
80
    fn drop(&mut self) {
×
NEW
81
        let ptr = self.addr as *mut c_void;
×
NEW
82
        unsafe { os_release(ptr) };
×
83
    }
84
}
85

86
#[derive(Debug)]
87
pub struct Hvf {}
88

89
impl Hypervisor for Hvf {
90
    type Vm = HvfVm;
91

92
    fn create_vm(&self, _config: &VmConfig) -> Result<Self::Vm> {
×
93
        let ret = unsafe { hv_vm_create(null_mut()) };
×
94
        check_ret(ret).context(error::CreateVm)?;
×
95
        Ok(HvfVm {
×
NEW
96
            gic_config: Mutex::new((OsObject { addr: 0 }, false)),
×
UNCOV
97
            vcpus: Mutex::new(HashMap::new()),
×
NEW
98
            senders: Arc::new(Mutex::new(HashMap::new())),
×
99
        })
100
    }
101
}
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