Skip to content

Commit

Permalink
Renaming unwrap_or, to some_or.
Browse files Browse the repository at this point in the history
  • Loading branch information
efenniht authored and hkim15 committed Nov 14, 2019
1 parent cbb2505 commit 315f5f3
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 23 deletions.
14 changes: 7 additions & 7 deletions hfo2/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ pub unsafe extern "C" fn api_vcpu_get_count(
return 0;
}

let vm = unwrap_or!(hafnium().vm_manager.get(vm_id), return 0);
let vm = some_or!(hafnium().vm_manager.get(vm_id), return 0);

vm.vcpus.len() as spci_vcpu_count_t
}
Expand Down Expand Up @@ -373,10 +373,10 @@ pub unsafe extern "C" fn api_vcpu_run(
}

// The requested VM must exist.
let vm = unwrap_or!(hafnium().vm_manager.get(vm_id), return ret.into_raw());
let vm = some_or!(hafnium().vm_manager.get(vm_id), return ret.into_raw());

// The requested vcpu must exist.
let vcpu = unwrap_or!(vm.vcpus.get(vcpu_idx as usize), return ret.into_raw());
let vcpu = some_or!(vm.vcpus.get(vcpu_idx as usize), return ret.into_raw());

// Update state if allowed.
let mut vcpu_locked = match vcpu_prepare_run(&current, vcpu, ret) {
Expand Down Expand Up @@ -519,7 +519,7 @@ pub unsafe extern "C" fn api_spci_msg_send(
}

// Ensure the target VM exists.
let to = unwrap_or!(
let to = some_or!(
hafnium().vm_manager.get(from_msg_replica.target_vm_id),
return SpciReturn::InvalidParameters
);
Expand Down Expand Up @@ -699,7 +699,7 @@ pub unsafe extern "C" fn api_mailbox_waiter_get(vm_id: spci_vm_id_t, current: *c
return -1;
}

let vm = unwrap_or!(hafnium().vm_manager.get(vm_id), return -1);
let vm = some_or!(hafnium().vm_manager.get(vm_id), return -1);

// Check if there are outstanding notifications from given vm.
let entry = (*vm).inner.lock().fetch_waiter();
Expand Down Expand Up @@ -799,7 +799,7 @@ pub unsafe extern "C" fn api_interrupt_inject(
next: *mut *mut VCpu,
) -> i64 {
let mut current = ManuallyDrop::new(VCpuExecutionLocked::from_raw(current));
let target_vm = unwrap_or!(hafnium().vm_manager.get(target_vm_id), return -1);
let target_vm = some_or!(hafnium().vm_manager.get(target_vm_id), return -1);

if intid >= HF_NUM_INTIDS {
return -1;
Expand All @@ -809,7 +809,7 @@ pub unsafe extern "C" fn api_interrupt_inject(
return -1;
}

let target_vcpu = unwrap_or!(target_vm.vcpus.get(target_vcpu_idx as usize), return -1);
let target_vcpu = some_or!(target_vm.vcpus.get(target_vcpu_idx as usize), return -1);

dlog!(
"Injecting IRQ {} for VM {} VCPU {} from VM {} VCPU {}\n",
Expand Down
10 changes: 5 additions & 5 deletions hfo2/src/fdt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ impl FdtTokenizer {
return None;
}

let name = unwrap_or!(self.str(), {
let name = some_or!(self.str(), {
// Move cursor to the end so that caller won't get any new
// tokens.
self.cur = self.end;
Expand Down Expand Up @@ -317,7 +317,7 @@ impl FdtHeader {
}

// Traverse the whole thing.
let node = unwrap_or!(FdtNode::new_root(self), {
let node = some_or!(FdtNode::new_root(self), {
dlog!("FDT failed validation.\n");
return;
});
Expand Down Expand Up @@ -423,7 +423,7 @@ pub unsafe extern "C" fn fdt_dump(hdr: *mut FdtHeader) {

#[no_mangle]
pub unsafe extern "C" fn fdt_root_node(node: *mut FdtNode, hdr: *const FdtHeader) -> bool {
let n = unwrap_or!(FdtNode::new_root(&*hdr), return false);
let n = some_or!(FdtNode::new_root(&*hdr), return false);
ptr::write(node, n);
true
}
Expand All @@ -435,7 +435,7 @@ pub unsafe extern "C" fn fdt_find_child(node: *mut FdtNode, child: *const u8) ->

#[no_mangle]
pub unsafe extern "C" fn fdt_first_child(node: *mut FdtNode, child_name: *mut *const u8) -> bool {
let name = unwrap_or!((*node).first_child(), return false);
let name = some_or!((*node).first_child(), return false);
ptr::write(child_name, name);
true
}
Expand All @@ -445,7 +445,7 @@ pub unsafe extern "C" fn fdt_next_sibling(
node: *mut FdtNode,
sibling_name: *mut *const u8,
) -> bool {
let name = unwrap_or!((*node).next_sibling(), return false);
let name = some_or!((*node).next_sibling(), return false);
ptr::write(sibling_name, name);
true
}
Expand Down
18 changes: 9 additions & 9 deletions hfo2/src/load.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ pub unsafe fn load_primary(
) -> Result<MemIter, ()> {
let primary_begin = layout_primary_begin();

let it = unwrap_or!(find_file(&mut cpio.clone(), "vmlinuz\0".as_ptr()), {
let it = some_or!(find_file(&mut cpio.clone(), "vmlinuz\0".as_ptr()), {
dlog!("Unable to find vmlinuz\n");
return Err(());
});
Expand All @@ -95,7 +95,7 @@ pub unsafe fn load_primary(
return Err(());
}

let initrd = unwrap_or!(find_file(&mut cpio.clone(), "initrd.img\0".as_ptr()), {
let initrd = some_or!(find_file(&mut cpio.clone(), "initrd.img\0".as_ptr()), {
dlog!("Unable to find initrd.img\n");
return Err(());
});
Expand All @@ -104,7 +104,7 @@ pub unsafe fn load_primary(
.new_vm(MAX_CPUS as spci_vcpu_count_t, ppool)
.ok_or_else(|| {
dlog!("Unable to initialise primary vm\n");
(())
()
})?;

if vm.id != HF_PRIMARY_VM_ID {
Expand Down Expand Up @@ -214,7 +214,7 @@ pub unsafe fn load_secondary(
mem_ranges_available.clone_from_slice(&params.mem_ranges);
mem_ranges_available.truncate(params.mem_ranges_count);

let mut it = unwrap_or!(find_file(&mut cpio.clone(), "vms.txt\0".as_ptr()), {
let mut it = some_or!(find_file(&mut cpio.clone(), "vms.txt\0".as_ptr()), {
dlog!("vms.txt is missing\n");
return Ok(());
});
Expand All @@ -227,14 +227,14 @@ pub unsafe fn load_secondary(
loop {
// Note(HfO2): There is `while let (Some(x), Some(y)) = (...) {}` but it
// is not short-circuiting.
let mut mem = unwrap_or!(it.parse_uint(), break);
let cpu = unwrap_or!(it.parse_uint(), break);
let name = unwrap_or!(it.parse_str(), break);
let mut mem = some_or!(it.parse_uint(), break);
let cpu = some_or!(it.parse_uint(), break);
let name = some_or!(it.parse_str(), break);
let name_str = str::from_utf8_unchecked(name.as_slice());

dlog!("Loading {}\n", name_str);

let kernel = unwrap_or!(find_file_memiter(&mut cpio.clone(), &name), {
let kernel = some_or!(find_file_memiter(&mut cpio.clone(), &name), {
dlog!("Unable to load kernel\n");
continue;
});
Expand Down Expand Up @@ -280,7 +280,7 @@ pub unsafe fn load_secondary(
return Err(());
}

let vm = unwrap_or!(vm_manager.new_vm(cpu as spci_vcpu_count_t, ppool), {
let vm = some_or!(vm_manager.new_vm(cpu as spci_vcpu_count_t, ppool), {
dlog!("Unable to initialise VM\n");
continue;
});
Expand Down
2 changes: 1 addition & 1 deletion hfo2/src/mm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1242,7 +1242,7 @@ pub unsafe extern "C" fn mm_unmap(
/// Unsafety doesn't really matter.
#[no_mangle]
pub unsafe extern "C" fn mm_init(mpool: *const MPool) -> bool {
let mm = unwrap_or!(MemoryManager::new(&*mpool), return false);
let mm = some_or!(MemoryManager::new(&*mpool), return false);
ptr::write(&mut HAFNIUM.get_mut().memory_manager, mm);

true
Expand Down
2 changes: 1 addition & 1 deletion hfo2/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ macro_rules! ok_or {
}

#[macro_export]
macro_rules! unwrap_or {
macro_rules! some_or {
($e:expr, $err:expr) => {{
match $e {
Some(r) => r,
Expand Down

0 comments on commit 315f5f3

Please sign in to comment.