File tree Expand file tree Collapse file tree 1 file changed +10
-0
lines changed Expand file tree Collapse file tree 1 file changed +10
-0
lines changed Original file line number Diff line number Diff line change @@ -11,6 +11,8 @@ use crate::structures::paging::page_table::PageTableLevel;
11
11
use crate :: structures:: paging:: { PageOffset , PageTableIndex } ;
12
12
use bit_field:: BitField ;
13
13
14
+ const ADDRESS_SPACE_SIZE : u64 = 0x1_0000_0000_0000 ;
15
+
14
16
/// A canonical 64-bit virtual memory address.
15
17
///
16
18
/// This is a wrapper type around an `u64`, so it is always 8 bytes, even when compiled
@@ -341,6 +343,10 @@ impl Step for VirtAddr {
341
343
342
344
fn forward_checked ( start : Self , count : usize ) -> Option < Self > {
343
345
let offset = u64:: try_from ( count) . ok ( ) ?;
346
+ if offset > ADDRESS_SPACE_SIZE {
347
+ return None ;
348
+ }
349
+
344
350
let mut addr = start. 0 . checked_add ( offset) ?;
345
351
346
352
// Jump the gap by sign extending the 47th bit.
@@ -353,6 +359,10 @@ impl Step for VirtAddr {
353
359
354
360
fn backward_checked ( start : Self , count : usize ) -> Option < Self > {
355
361
let offset = u64:: try_from ( count) . ok ( ) ?;
362
+ if offset > ADDRESS_SPACE_SIZE {
363
+ return None ;
364
+ }
365
+
356
366
let mut addr = start. 0 . checked_sub ( offset) ?;
357
367
358
368
// Jump the gap by sign extending the 47th bit.
You can’t perform that action at this time.
0 commit comments