File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11use core:: slice;
22use core:: arch:: asm;
3+ use crate :: memory;
34
45pub 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
Original file line number Diff line number Diff 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+ }
You can’t perform that action at this time.
0 commit comments