@@ -12,13 +12,15 @@ use crate::vm::vm_memory::memory_segments::MemorySegmentManager;
1212#[ derive( Debug , Clone , PartialEq ) ]
1313pub struct OutputBuiltinState {
1414 pub base : usize ,
15+ pub base_offset : usize ,
1516 pub pages : Pages ,
1617 pub attributes : Attributes ,
1718}
1819
1920#[ derive( Debug , Clone ) ]
2021pub struct OutputBuiltinRunner {
2122 base : usize ,
23+ pub base_offset : usize ,
2224 pub ( crate ) pages : Pages ,
2325 pub ( crate ) attributes : Attributes ,
2426 pub ( crate ) stop_ptr : Option < usize > ,
@@ -29,15 +31,17 @@ impl OutputBuiltinRunner {
2931 pub fn new ( included : bool ) -> OutputBuiltinRunner {
3032 OutputBuiltinRunner {
3133 base : 0 ,
34+ base_offset : 0 ,
3235 pages : HashMap :: default ( ) ,
3336 attributes : HashMap :: default ( ) ,
3437 stop_ptr : None ,
3538 included,
3639 }
3740 }
3841
39- pub fn new_state ( & mut self , base : usize , included : bool ) {
42+ pub fn new_state ( & mut self , base : usize , base_offset : usize , included : bool ) {
4043 self . base = base;
44+ self . base_offset = base_offset;
4145 self . pages = HashMap :: default ( ) ;
4246 self . attributes = HashMap :: default ( ) ;
4347 self . stop_ptr = None ;
@@ -143,13 +147,15 @@ impl OutputBuiltinRunner {
143147
144148 pub fn set_state ( & mut self , new_state : OutputBuiltinState ) {
145149 self . base = new_state. base ;
150+ self . base_offset = new_state. base_offset ;
146151 self . pages = new_state. pages ;
147152 self . attributes = new_state. attributes ;
148153 }
149154
150155 pub fn get_state ( & mut self ) -> OutputBuiltinState {
151156 OutputBuiltinState {
152157 base : self . base ,
158+ base_offset : self . base_offset ,
153159 pages : self . pages . clone ( ) ,
154160 attributes : self . attributes . clone ( ) ,
155161 }
@@ -168,7 +174,7 @@ impl OutputBuiltinRunner {
168174 self . pages . insert (
169175 page_id,
170176 PublicMemoryPage {
171- start : page_start. offset ,
177+ start : page_start. offset - self . base_offset ,
172178 size : page_size,
173179 } ,
174180 ) ;
@@ -493,6 +499,7 @@ mod tests {
493499
494500 let new_state = OutputBuiltinState {
495501 base : 10 ,
502+ base_offset : 0 ,
496503 pages : HashMap :: from ( [ ( 1 , PublicMemoryPage { start : 0 , size : 3 } ) ] ) ,
497504 attributes : HashMap :: from ( [ ( "gps_fact_topology" . to_string ( ) , vec ! [ 0 , 2 , 0 ] ) ] ) ,
498505 } ;
@@ -510,6 +517,7 @@ mod tests {
510517 fn new_state ( ) {
511518 let mut builtin = OutputBuiltinRunner {
512519 base : 10 ,
520+ base_offset : 0 ,
513521 pages : HashMap :: from ( [ ( 1 , PublicMemoryPage { start : 0 , size : 3 } ) ] ) ,
514522 attributes : HashMap :: from ( [ ( "gps_fact_topology" . to_string ( ) , vec ! [ 0 , 2 , 0 ] ) ] ) ,
515523 stop_ptr : Some ( 10 ) ,
@@ -518,9 +526,10 @@ mod tests {
518526
519527 let new_base = 11 ;
520528 let new_included = false ;
521- builtin. new_state ( new_base, new_included) ;
529+ builtin. new_state ( new_base, 2 , new_included) ;
522530
523531 assert_eq ! ( builtin. base, new_base) ;
532+ assert_eq ! ( builtin. base_offset, 2 ) ;
524533 assert ! ( builtin. pages. is_empty( ) ) ;
525534 assert ! ( builtin. attributes. is_empty( ) ) ;
526535 assert_eq ! ( builtin. stop_ptr, None ) ;
@@ -614,6 +623,7 @@ mod tests {
614623 fn get_and_extend_additional_data ( ) {
615624 let builtin_a = OutputBuiltinRunner {
616625 base : 0 ,
626+ base_offset : 0 ,
617627 pages : HashMap :: from ( [ ( 1 , PublicMemoryPage { start : 0 , size : 3 } ) ] ) ,
618628 attributes : HashMap :: from ( [ ( "gps_fact_topology" . to_string ( ) , vec ! [ 0 , 2 , 0 ] ) ] ) ,
619629 stop_ptr : None ,
@@ -622,6 +632,7 @@ mod tests {
622632 let additional_data = builtin_a. get_additional_data ( ) ;
623633 let mut builtin_b = OutputBuiltinRunner {
624634 base : 0 ,
635+ base_offset : 0 ,
625636 pages : Default :: default ( ) ,
626637 attributes : Default :: default ( ) ,
627638 stop_ptr : None ,
0 commit comments