Skip to content

Commit

Permalink
Resolve simple issues on the review of kaist-cp#52
Browse files Browse the repository at this point in the history
  • Loading branch information
efenniht committed Nov 13, 2019
1 parent 9d10778 commit 6beb763
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 26 deletions.
4 changes: 3 additions & 1 deletion hfo2/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ pub unsafe extern "C" fn api_vcpu_get_count(

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

vm.vcpus.len() as spci_vcpu_count_t
vm.vcpus.len() as _
}

/// This function is called by the architecture-specific context switching
Expand Down Expand Up @@ -584,6 +584,8 @@ pub unsafe extern "C" fn api_spci_msg_send(
// at spci_msg_handle_architected_message will make several accesses to
// fields in message_buffer. The memory area message_buffer must be
// exclusively owned by Hf so that TOCTOU issues do not arise.
// TODO(HfO2): Refactor `spci_*` functions, in order to pass references
// to VmInner.
let ret = spci_msg_handle_architected_message(
&ManuallyDrop::new(VmLocked::from_raw(to as *const _ as usize as *mut _)),
&ManuallyDrop::new(VmLocked::from_raw(from)),
Expand Down
10 changes: 5 additions & 5 deletions hfo2/src/fdt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,10 @@ impl FdtTokenizer {
self.cur = round_up(self.cur as usize, FDT_TOKEN_ALIGNMENT) as _;
}

unsafe fn iter(&self) -> impl Iterator<Item = *const u8> {
slice::from_raw_parts(self.cur, self.end.offset_from(self.cur) as usize).iter().map(|p| p as *const u8)
}

unsafe fn u32(&mut self) -> Option<u32> {
let next = self.cur.add(mem::size_of::<u32>());
if next > self.end {
Expand Down Expand Up @@ -143,18 +147,14 @@ impl FdtTokenizer {
}

unsafe fn str(&mut self) -> Option<*const u8> {
let mut p = self.cur;

while p < self.end {
for p in self.iter() {
if *p == 0 {
// Found the end of the string.
let res = self.cur;
self.cur = p.add(1);
self.align();
return Some(res);
}

p = p.add(1);
}

None
Expand Down
30 changes: 12 additions & 18 deletions hfo2/src/fdt_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,16 +126,13 @@ impl FdtNode {
}
}

let (mut data, mut size) =
if let Ok((data, size)) = node.read_property("reg\0".as_ptr()) {
(data, size)
let (mut data, mut size) = ok_or!(node.read_property("reg\0".as_ptr()), {
if node.next_sibling().is_none() {
break;
} else {
if node.next_sibling().is_none() {
break;
} else {
continue;
}
};
continue;
}
});

// Get all entries for this CPU.
while size as usize >= address_size {
Expand Down Expand Up @@ -200,16 +197,13 @@ impl FdtNode {
continue;
}
}
let (mut data, mut size) =
if let Ok((data, size)) = node.read_property("reg\0".as_ptr()) {
(data, size)
let (mut data, mut size) = ok_or!(node.read_property("reg\0".as_ptr()), {
if node.next_sibling().is_none() {
break;
} else {
if node.next_sibling().is_none() {
break;
} else {
continue;
}
};
continue;
}
});

// Traverse all memory ranges within this node.
while size as usize >= entry_size {
Expand Down
5 changes: 3 additions & 2 deletions hfo2/src/mm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1238,8 +1238,9 @@ pub unsafe extern "C" fn mm_unmap(
stage1_locked.unmap(begin, end, mpool).is_ok()
}

/// This function is only used in one unit test (fdt/find_memory_ranges.)
/// Unsafety doesn't really matter.
/// TODO(HfO2): This function is only used in one unit test
/// (fdt/find_memory_ranges.) Unsafety doesn't really matter. Resolve #46, then
/// we can remove this.
#[no_mangle]
pub unsafe extern "C" fn mm_init(mpool: *const MPool) -> bool {
let mm = some_or!(MemoryManager::new(&*mpool), return false);
Expand Down

0 comments on commit 6beb763

Please sign in to comment.