4
4
use crate :: api:: { MemoryAccessError , Module , RegValue , SetCacheSizeLimitArgs } ;
5
5
use crate :: error:: Error ;
6
6
use crate :: gas:: { GasVisitor , GasVisitorT } ;
7
- use crate :: utils:: { FlatMap , GuestInit , InterruptKind , Segfault } ;
7
+ use crate :: utils:: { FlatMap , InterruptKind , Segfault } ;
8
8
use crate :: { Gas , GasMeteringKind , ProgramCounter } ;
9
9
use alloc:: boxed:: Box ;
10
10
use alloc:: collections:: btree_map:: Entry ;
@@ -62,25 +62,8 @@ impl IntoRegImm for u32 {
62
62
}
63
63
}
64
64
65
- pub ( crate ) struct InterpretedModule {
66
- ro_data : Vec < u8 > ,
67
- rw_data : Vec < u8 > ,
68
- }
69
-
70
- impl InterpretedModule {
71
- pub fn new ( init : GuestInit ) -> Result < Self , Error > {
72
- let memory_map = init. memory_map ( ) . map_err ( Error :: from_static_str) ?;
73
- let mut ro_data: Vec < _ > = init. ro_data . into ( ) ;
74
- ro_data. resize ( cast ( memory_map. ro_data_size ( ) ) . to_usize ( ) , 0 ) ;
75
-
76
- Ok ( InterpretedModule {
77
- ro_data,
78
- rw_data : init. rw_data . into ( ) ,
79
- } )
80
- }
81
- }
82
-
83
65
pub ( crate ) struct BasicMemory {
66
+ ro_data : Vec < u8 > ,
84
67
rw_data : Vec < u8 > ,
85
68
stack : Vec < u8 > ,
86
69
aux : Vec < u8 > ,
@@ -92,6 +75,7 @@ pub(crate) struct BasicMemory {
92
75
impl BasicMemory {
93
76
fn new ( ) -> Self {
94
77
Self {
78
+ ro_data : Vec :: new ( ) ,
95
79
rw_data : Vec :: new ( ) ,
96
80
stack : Vec :: new ( ) ,
97
81
aux : Vec :: new ( ) ,
@@ -116,22 +100,26 @@ impl BasicMemory {
116
100
}
117
101
118
102
fn force_reset ( & mut self , module : & Module ) {
103
+ self . ro_data . clear ( ) ;
119
104
self . rw_data . clear ( ) ;
120
105
self . stack . clear ( ) ;
121
106
self . aux . clear ( ) ;
122
107
self . heap_size = 0 ;
123
108
self . is_memory_dirty = false ;
124
109
self . accessible_aux_size = 0 ;
125
110
126
- if let Some ( interpreted_module) = module. interpreted_module ( ) . as_ref ( ) {
127
- self . rw_data . extend_from_slice ( & interpreted_module. rw_data ) ;
128
- self . rw_data . resize ( cast ( module. memory_map ( ) . rw_data_size ( ) ) . to_usize ( ) , 0 ) ;
129
- self . stack . resize ( cast ( module. memory_map ( ) . stack_size ( ) ) . to_usize ( ) , 0 ) ;
111
+ let blob = module. blob ( ) ;
112
+ self . rw_data . extend_from_slice ( blob. rw_data ( ) ) ;
113
+ self . rw_data . resize ( cast ( module. memory_map ( ) . rw_data_size ( ) ) . to_usize ( ) , 0 ) ;
130
114
131
- // TODO: Do this lazily?
132
- self . aux . resize ( cast ( module. memory_map ( ) . aux_data_size ( ) ) . to_usize ( ) , 0 ) ;
133
- self . accessible_aux_size = cast ( module. memory_map ( ) . aux_data_size ( ) ) . to_usize ( ) ;
134
- }
115
+ self . ro_data . extend_from_slice ( blob. ro_data ( ) ) ;
116
+ self . ro_data . resize ( cast ( module. memory_map ( ) . ro_data_size ( ) ) . to_usize ( ) , 0 ) ;
117
+
118
+ self . stack . resize ( cast ( module. memory_map ( ) . stack_size ( ) ) . to_usize ( ) , 0 ) ;
119
+
120
+ // TODO: Do this lazily?
121
+ self . aux . resize ( cast ( module. memory_map ( ) . aux_data_size ( ) ) . to_usize ( ) , 0 ) ;
122
+ self . accessible_aux_size = cast ( module. memory_map ( ) . aux_data_size ( ) ) . to_usize ( ) ;
135
123
}
136
124
137
125
fn accessible_aux_size ( & self ) -> u32 {
@@ -152,8 +140,7 @@ impl BasicMemory {
152
140
} else if address >= memory_map. rw_data_address ( ) {
153
141
( memory_map. rw_data_address ( ) , & self . rw_data [ ..] )
154
142
} else if address >= memory_map. ro_data_address ( ) {
155
- let module = module. interpreted_module ( ) . unwrap ( ) ;
156
- ( memory_map. ro_data_address ( ) , & module. ro_data [ ..] )
143
+ ( memory_map. ro_data_address ( ) , & self . ro_data [ ..] )
157
144
} else {
158
145
return None ;
159
146
} ;
0 commit comments