@@ -83,6 +83,7 @@ pub(crate) struct BasicMemory {
83
83
aux : Vec < u8 > ,
84
84
is_memory_dirty : bool ,
85
85
heap_size : u32 ,
86
+ accessible_aux_size : usize ,
86
87
}
87
88
88
89
impl BasicMemory {
@@ -93,6 +94,7 @@ impl BasicMemory {
93
94
aux : Vec :: new ( ) ,
94
95
is_memory_dirty : false ,
95
96
heap_size : 0 ,
97
+ accessible_aux_size : usize:: MAX ,
96
98
}
97
99
}
98
100
@@ -116,6 +118,7 @@ impl BasicMemory {
116
118
self . aux . clear ( ) ;
117
119
self . heap_size = 0 ;
118
120
self . is_memory_dirty = false ;
121
+ self . accessible_aux_size = 0 ;
119
122
120
123
if let Some ( interpreted_module) = module. interpreted_module ( ) . as_ref ( ) {
121
124
self . rw_data . extend_from_slice ( & interpreted_module. rw_data ) ;
@@ -124,21 +127,26 @@ impl BasicMemory {
124
127
125
128
// TODO: Do this lazily?
126
129
self . aux . resize ( cast ( module. memory_map ( ) . aux_data_size ( ) ) . to_usize ( ) , 0 ) ;
130
+ self . accessible_aux_size = cast ( module. memory_map ( ) . aux_data_size ( ) ) . to_usize ( ) ;
127
131
}
128
132
}
129
133
134
+ fn set_accessible_aux_size ( & mut self , size : u32 ) {
135
+ self . accessible_aux_size = cast ( size) . to_usize ( ) ;
136
+ }
137
+
130
138
#[ inline]
131
139
fn get_memory_slice < ' a > ( & ' a self , module : & ' a Module , address : u32 , length : u32 ) -> Option < & ' a [ u8 ] > {
132
140
let memory_map = module. memory_map ( ) ;
133
141
let ( start, memory_slice) = if address >= memory_map. aux_data_address ( ) {
134
- ( memory_map. aux_data_address ( ) , & self . aux )
142
+ ( memory_map. aux_data_address ( ) , & self . aux [ .. self . accessible_aux_size ] )
135
143
} else if address >= memory_map. stack_address_low ( ) {
136
- ( memory_map. stack_address_low ( ) , & self . stack )
144
+ ( memory_map. stack_address_low ( ) , & self . stack [ .. ] )
137
145
} else if address >= memory_map. rw_data_address ( ) {
138
- ( memory_map. rw_data_address ( ) , & self . rw_data )
146
+ ( memory_map. rw_data_address ( ) , & self . rw_data [ .. ] )
139
147
} else if address >= memory_map. ro_data_address ( ) {
140
148
let module = module. interpreted_module ( ) . unwrap ( ) ;
141
- ( memory_map. ro_data_address ( ) , & module. ro_data )
149
+ ( memory_map. ro_data_address ( ) , & module. ro_data [ .. ] )
142
150
} else {
143
151
return None ;
144
152
} ;
@@ -153,11 +161,11 @@ impl BasicMemory {
153
161
fn get_memory_slice_mut < const IS_EXTERNAL : bool > ( & mut self , module : & Module , address : u32 , length : u32 ) -> Option < & mut [ u8 ] > {
154
162
let memory_map = module. memory_map ( ) ;
155
163
let ( start, memory_slice) = if IS_EXTERNAL && address >= memory_map. aux_data_address ( ) {
156
- ( memory_map. aux_data_address ( ) , & mut self . aux )
164
+ ( memory_map. aux_data_address ( ) , & mut self . aux [ .. self . accessible_aux_size ] )
157
165
} else if address >= memory_map. stack_address_low ( ) {
158
- ( memory_map. stack_address_low ( ) , & mut self . stack )
166
+ ( memory_map. stack_address_low ( ) , & mut self . stack [ .. ] )
159
167
} else if address >= memory_map. rw_data_address ( ) {
160
- ( memory_map. rw_data_address ( ) , & mut self . rw_data )
168
+ ( memory_map. rw_data_address ( ) , & mut self . rw_data [ .. ] )
161
169
} else {
162
170
return None ;
163
171
} ;
@@ -440,6 +448,11 @@ impl InterpretedInstance {
440
448
self . next_program_counter_changed = true ;
441
449
}
442
450
451
+ pub fn set_accessible_aux_size ( & mut self , size : u32 ) {
452
+ assert ! ( !self . module. is_dynamic_paging( ) ) ;
453
+ self . basic_memory . set_accessible_aux_size ( size) ;
454
+ }
455
+
443
456
#[ allow( clippy:: unused_self) ]
444
457
pub fn next_native_program_counter ( & self ) -> Option < usize > {
445
458
None
0 commit comments