Skip to content

Commit

Permalink
memory: avoid printing unmapped memory
Browse files Browse the repository at this point in the history
  • Loading branch information
edrflt committed May 23, 2022
1 parent b36fce9 commit 0ab4a29
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/ferramenta.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use core::slice;
use core::arch::asm;
use crate::memory;

pub fn shutdown_qemu()
{
Expand Down Expand Up @@ -68,6 +69,11 @@ pub unsafe fn print_memory(ptr: *const u8, n: usize)
{
let mut i: usize = 0;

if !memory::is_range_mapped(ptr, n)
{
crate::oops!("cannot print unmapped memory from {:#08x} to {:#08x}", ptr as usize, ptr as usize + n);
return;
}
while i < n
{
if i % 16 == 0
Expand Down Expand Up @@ -99,6 +105,11 @@ pub unsafe fn print_memory_bin(ptr: *const u8, n: usize)
{
let mut i: usize = 0;

if !memory::is_range_mapped(ptr, n)
{
crate::oops!("cannot print unmapped memory from {:#08x} to {:#08x}", ptr as usize, ptr as usize + n);
return;
}
while i < n
{
if i % 4 == 0
Expand Down
16 changes: 16 additions & 0 deletions src/memory/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,3 +116,19 @@ pub fn page_map_indexer(v_addr: usize) -> (usize, usize)

return (pdindex, ptindex);
}

pub fn is_range_mapped(ptr: *const u8, n: usize) -> bool
{
let pt_manager = unsafe
{
&PT_MANAGER
};
if ptr as usize >= pt_manager.last_mapped + PAGE_SIZE || ptr as usize + n > pt_manager.last_mapped + PAGE_SIZE
{
false
}
else
{
true
}
}

0 comments on commit 0ab4a29

Please sign in to comment.