@@ -12,13 +12,15 @@ use crate::vm::vm_memory::memory_segments::MemorySegmentManager;
12
12
#[ derive( Debug , Clone , PartialEq ) ]
13
13
pub struct OutputBuiltinState {
14
14
pub base : usize ,
15
+ pub base_offset : usize ,
15
16
pub pages : Pages ,
16
17
pub attributes : Attributes ,
17
18
}
18
19
19
20
#[ derive( Debug , Clone ) ]
20
21
pub struct OutputBuiltinRunner {
21
22
base : usize ,
23
+ pub base_offset : usize ,
22
24
pub ( crate ) pages : Pages ,
23
25
pub ( crate ) attributes : Attributes ,
24
26
pub ( crate ) stop_ptr : Option < usize > ,
@@ -29,15 +31,17 @@ impl OutputBuiltinRunner {
29
31
pub fn new ( included : bool ) -> OutputBuiltinRunner {
30
32
OutputBuiltinRunner {
31
33
base : 0 ,
34
+ base_offset : 0 ,
32
35
pages : HashMap :: default ( ) ,
33
36
attributes : HashMap :: default ( ) ,
34
37
stop_ptr : None ,
35
38
included,
36
39
}
37
40
}
38
41
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 ) {
40
43
self . base = base;
44
+ self . base_offset = base_offset;
41
45
self . pages = HashMap :: default ( ) ;
42
46
self . attributes = HashMap :: default ( ) ;
43
47
self . stop_ptr = None ;
@@ -143,13 +147,15 @@ impl OutputBuiltinRunner {
143
147
144
148
pub fn set_state ( & mut self , new_state : OutputBuiltinState ) {
145
149
self . base = new_state. base ;
150
+ self . base_offset = new_state. base_offset ;
146
151
self . pages = new_state. pages ;
147
152
self . attributes = new_state. attributes ;
148
153
}
149
154
150
155
pub fn get_state ( & mut self ) -> OutputBuiltinState {
151
156
OutputBuiltinState {
152
157
base : self . base ,
158
+ base_offset : self . base_offset ,
153
159
pages : self . pages . clone ( ) ,
154
160
attributes : self . attributes . clone ( ) ,
155
161
}
@@ -168,7 +174,7 @@ impl OutputBuiltinRunner {
168
174
self . pages . insert (
169
175
page_id,
170
176
PublicMemoryPage {
171
- start : page_start. offset ,
177
+ start : page_start. offset - self . base_offset ,
172
178
size : page_size,
173
179
} ,
174
180
) ;
@@ -493,6 +499,7 @@ mod tests {
493
499
494
500
let new_state = OutputBuiltinState {
495
501
base : 10 ,
502
+ base_offset : 0 ,
496
503
pages : HashMap :: from ( [ ( 1 , PublicMemoryPage { start : 0 , size : 3 } ) ] ) ,
497
504
attributes : HashMap :: from ( [ ( "gps_fact_topology" . to_string ( ) , vec ! [ 0 , 2 , 0 ] ) ] ) ,
498
505
} ;
@@ -510,6 +517,7 @@ mod tests {
510
517
fn new_state ( ) {
511
518
let mut builtin = OutputBuiltinRunner {
512
519
base : 10 ,
520
+ base_offset : 0 ,
513
521
pages : HashMap :: from ( [ ( 1 , PublicMemoryPage { start : 0 , size : 3 } ) ] ) ,
514
522
attributes : HashMap :: from ( [ ( "gps_fact_topology" . to_string ( ) , vec ! [ 0 , 2 , 0 ] ) ] ) ,
515
523
stop_ptr : Some ( 10 ) ,
@@ -518,9 +526,10 @@ mod tests {
518
526
519
527
let new_base = 11 ;
520
528
let new_included = false ;
521
- builtin. new_state ( new_base, new_included) ;
529
+ builtin. new_state ( new_base, 2 , new_included) ;
522
530
523
531
assert_eq ! ( builtin. base, new_base) ;
532
+ assert_eq ! ( builtin. base_offset, 2 ) ;
524
533
assert ! ( builtin. pages. is_empty( ) ) ;
525
534
assert ! ( builtin. attributes. is_empty( ) ) ;
526
535
assert_eq ! ( builtin. stop_ptr, None ) ;
@@ -614,6 +623,7 @@ mod tests {
614
623
fn get_and_extend_additional_data ( ) {
615
624
let builtin_a = OutputBuiltinRunner {
616
625
base : 0 ,
626
+ base_offset : 0 ,
617
627
pages : HashMap :: from ( [ ( 1 , PublicMemoryPage { start : 0 , size : 3 } ) ] ) ,
618
628
attributes : HashMap :: from ( [ ( "gps_fact_topology" . to_string ( ) , vec ! [ 0 , 2 , 0 ] ) ] ) ,
619
629
stop_ptr : None ,
@@ -622,6 +632,7 @@ mod tests {
622
632
let additional_data = builtin_a. get_additional_data ( ) ;
623
633
let mut builtin_b = OutputBuiltinRunner {
624
634
base : 0 ,
635
+ base_offset : 0 ,
625
636
pages : Default :: default ( ) ,
626
637
attributes : Default :: default ( ) ,
627
638
stop_ptr : None ,
0 commit comments