Skip to content
Snippets Groups Projects
Verified Commit 113cb5ed authored by Jacob Lorentzon's avatar Jacob Lorentzon :speech_balloon:
Browse files

Ensure pages cannot be both CoW and shared.

parent d3ecedef
No related branches found
No related tags found
1 merge request!238Demand paging
...@@ -899,7 +899,7 @@ impl Grant { ...@@ -899,7 +899,7 @@ impl Grant {
if let Some((phys, _)) = src_mapper.translate(src_page.start_address()) { if let Some((phys, _)) = src_mapper.translate(src_page.start_address()) {
Frame::containing_address(phys) Frame::containing_address(phys)
} else { } else {
let new_frame = init_frame(2, 2).expect("TODO: handle OOM"); let new_frame = init_frame(0, 2).expect("TODO: handle OOM");
let src_flush = unsafe { src_mapper.map_phys(src_page.start_address(), new_frame.start_address(), flags).expect("TODO: handle OOM") }; let src_flush = unsafe { src_mapper.map_phys(src_page.start_address(), new_frame.start_address(), flags).expect("TODO: handle OOM") };
src_flusher.consume(src_flush); src_flusher.consume(src_flush);
...@@ -907,9 +907,18 @@ impl Grant { ...@@ -907,9 +907,18 @@ impl Grant {
} }
}; };
let src_page_info = get_page_info(src_frame).expect("allocated page was not present in the global page array"); let src_frame = {
let guard = src_page_info.lock(); let src_page_info = get_page_info(src_frame).expect("allocated page was not present in the global page array");
guard.add_ref(is_cow); let mut guard = src_page_info.lock();
if *guard.borrowed_refcount.get_mut() > 0 {
// Cannot be shared and CoW simultaneously, so use a zeroed page instead.
init_frame(1, 0).map_err(|_| Enomem)?
} else {
guard.add_ref(is_cow);
src_frame
}
};
let Some(map_result) = (unsafe { dst_mapper.map_phys(dst_page, src_frame.start_address(), flags.write(flags.has_write() && !is_cow)) }) else { let Some(map_result) = (unsafe { dst_mapper.map_phys(dst_page, src_frame.start_address(), flags.write(flags.has_write() && !is_cow)) }) else {
break; break;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment