Skip to content

Commit 0ab4a29

Browse files
committed
memory: avoid printing unmapped memory
1 parent b36fce9 commit 0ab4a29

2 files changed

Lines changed: 27 additions & 0 deletions

File tree

src/ferramenta.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use core::slice;
22
use core::arch::asm;
3+
use crate::memory;
34

45
pub fn shutdown_qemu()
56
{
@@ -68,6 +69,11 @@ pub unsafe fn print_memory(ptr: *const u8, n: usize)
6869
{
6970
let mut i: usize = 0;
7071

72+
if !memory::is_range_mapped(ptr, n)
73+
{
74+
crate::oops!("cannot print unmapped memory from {:#08x} to {:#08x}", ptr as usize, ptr as usize + n);
75+
return;
76+
}
7177
while i < n
7278
{
7379
if i % 16 == 0
@@ -99,6 +105,11 @@ pub unsafe fn print_memory_bin(ptr: *const u8, n: usize)
99105
{
100106
let mut i: usize = 0;
101107

108+
if !memory::is_range_mapped(ptr, n)
109+
{
110+
crate::oops!("cannot print unmapped memory from {:#08x} to {:#08x}", ptr as usize, ptr as usize + n);
111+
return;
112+
}
102113
while i < n
103114
{
104115
if i % 4 == 0

src/memory/mod.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,3 +116,19 @@ pub fn page_map_indexer(v_addr: usize) -> (usize, usize)
116116

117117
return (pdindex, ptindex);
118118
}
119+
120+
pub fn is_range_mapped(ptr: *const u8, n: usize) -> bool
121+
{
122+
let pt_manager = unsafe
123+
{
124+
&PT_MANAGER
125+
};
126+
if ptr as usize >= pt_manager.last_mapped + PAGE_SIZE || ptr as usize + n > pt_manager.last_mapped + PAGE_SIZE
127+
{
128+
false
129+
}
130+
else
131+
{
132+
true
133+
}
134+
}

0 commit comments

Comments
 (0)