@@ -125,15 +125,15 @@ impl<'a, 'mir, 'tcx: 'mir + 'a> EvalContextExt<'tcx, 'mir> for super::MiriEvalCo
125
125
self . write_null ( dest) ?;
126
126
} else {
127
127
let align = self . tcx . data_layout . pointer_align ;
128
- let ptr = self . memory . allocate ( Size :: from_bytes ( size) , align, MiriMemoryKind :: C . into ( ) ) ?;
129
- self . write_scalar ( Scalar :: Ptr ( ptr) , dest) ?;
128
+ let ptr = self . memory_mut ( ) . allocate ( Size :: from_bytes ( size) , align, MiriMemoryKind :: C . into ( ) ) ?;
129
+ self . write_scalar ( Scalar :: Ptr ( ptr. with_default_tag ( ) ) , dest) ?;
130
130
}
131
131
}
132
132
133
133
"free" => {
134
134
let ptr = self . read_scalar ( args[ 0 ] ) ?. not_undef ( ) ?. erase_tag ( ) ; // raw ptr operation, no tag
135
135
if !ptr. is_null_ptr ( & self ) {
136
- self . memory . deallocate (
136
+ self . memory_mut ( ) . deallocate (
137
137
ptr. to_ptr ( ) ?. with_default_tag ( ) ,
138
138
None ,
139
139
MiriMemoryKind :: C . into ( ) ,
@@ -150,9 +150,13 @@ impl<'a, 'mir, 'tcx: 'mir + 'a> EvalContextExt<'tcx, 'mir> for super::MiriEvalCo
150
150
if !align. is_power_of_two ( ) {
151
151
return err ! ( HeapAllocNonPowerOfTwoAlignment ( align) ) ;
152
152
}
153
- let ptr = self . memory . allocate ( Size :: from_bytes ( size) ,
154
- Align :: from_bytes ( align, align) . unwrap ( ) ,
155
- MiriMemoryKind :: Rust . into ( ) ) ?;
153
+ let ptr = self . memory_mut ( )
154
+ . allocate (
155
+ Size :: from_bytes ( size) ,
156
+ Align :: from_bytes ( align, align) . unwrap ( ) ,
157
+ MiriMemoryKind :: Rust . into ( )
158
+ ) ?
159
+ . with_default_tag ( ) ;
156
160
self . write_scalar ( Scalar :: Ptr ( ptr) , dest) ?;
157
161
}
158
162
"__rust_alloc_zeroed" => {
@@ -164,10 +168,14 @@ impl<'a, 'mir, 'tcx: 'mir + 'a> EvalContextExt<'tcx, 'mir> for super::MiriEvalCo
164
168
if !align. is_power_of_two ( ) {
165
169
return err ! ( HeapAllocNonPowerOfTwoAlignment ( align) ) ;
166
170
}
167
- let ptr = self . memory . allocate ( Size :: from_bytes ( size) ,
168
- Align :: from_bytes ( align, align) . unwrap ( ) ,
169
- MiriMemoryKind :: Rust . into ( ) ) ?;
170
- self . memory . write_repeat ( ptr. into ( ) , 0 , Size :: from_bytes ( size) ) ?;
171
+ let ptr = self . memory_mut ( )
172
+ . allocate (
173
+ Size :: from_bytes ( size) ,
174
+ Align :: from_bytes ( align, align) . unwrap ( ) ,
175
+ MiriMemoryKind :: Rust . into ( )
176
+ ) ?
177
+ . with_default_tag ( ) ;
178
+ self . memory_mut ( ) . write_repeat ( ptr. into ( ) , 0 , Size :: from_bytes ( size) ) ?;
171
179
self . write_scalar ( Scalar :: Ptr ( ptr) , dest) ?;
172
180
}
173
181
"__rust_dealloc" => {
@@ -180,7 +188,7 @@ impl<'a, 'mir, 'tcx: 'mir + 'a> EvalContextExt<'tcx, 'mir> for super::MiriEvalCo
180
188
if !align. is_power_of_two ( ) {
181
189
return err ! ( HeapAllocNonPowerOfTwoAlignment ( align) ) ;
182
190
}
183
- self . memory . deallocate (
191
+ self . memory_mut ( ) . deallocate (
184
192
ptr. with_default_tag ( ) ,
185
193
Some ( ( Size :: from_bytes ( old_size) , Align :: from_bytes ( align, align) . unwrap ( ) ) ) ,
186
194
MiriMemoryKind :: Rust . into ( ) ,
@@ -197,15 +205,15 @@ impl<'a, 'mir, 'tcx: 'mir + 'a> EvalContextExt<'tcx, 'mir> for super::MiriEvalCo
197
205
if !align. is_power_of_two ( ) {
198
206
return err ! ( HeapAllocNonPowerOfTwoAlignment ( align) ) ;
199
207
}
200
- let new_ptr = self . memory . reallocate (
208
+ let new_ptr = self . memory_mut ( ) . reallocate (
201
209
ptr. with_default_tag ( ) ,
202
210
Size :: from_bytes ( old_size) ,
203
211
Align :: from_bytes ( align, align) . unwrap ( ) ,
204
212
Size :: from_bytes ( new_size) ,
205
213
Align :: from_bytes ( align, align) . unwrap ( ) ,
206
214
MiriMemoryKind :: Rust . into ( ) ,
207
215
) ?;
208
- self . write_scalar ( Scalar :: Ptr ( new_ptr) , dest) ?;
216
+ self . write_scalar ( Scalar :: Ptr ( new_ptr. with_default_tag ( ) ) , dest) ?;
209
217
}
210
218
211
219
"syscall" => {
@@ -231,7 +239,7 @@ impl<'a, 'mir, 'tcx: 'mir + 'a> EvalContextExt<'tcx, 'mir> for super::MiriEvalCo
231
239
"dlsym" => {
232
240
let _handle = self . read_scalar ( args[ 0 ] ) ?;
233
241
let symbol = self . read_scalar ( args[ 1 ] ) ?. to_ptr ( ) ?. erase_tag ( ) ;
234
- let symbol_name = self . memory . read_c_str ( symbol. with_default_tag ( ) ) ?;
242
+ let symbol_name = self . memory ( ) . read_c_str ( symbol. with_default_tag ( ) ) ?;
235
243
let err = format ! ( "bad c unicode symbol: {:?}" , symbol_name) ;
236
244
let symbol_name = :: std:: str:: from_utf8 ( symbol_name) . unwrap_or ( & err) ;
237
245
return err ! ( Unimplemented ( format!(
@@ -245,7 +253,7 @@ impl<'a, 'mir, 'tcx: 'mir + 'a> EvalContextExt<'tcx, 'mir> for super::MiriEvalCo
245
253
// We abort on panic, so not much is going on here, but we still have to call the closure
246
254
let f = self . read_scalar ( args[ 0 ] ) ?. to_ptr ( ) ?;
247
255
let data = self . read_scalar ( args[ 1 ] ) ?. not_undef ( ) ?;
248
- let f_instance = self . memory . get_fn ( f) ?;
256
+ let f_instance = self . memory ( ) . get_fn ( f) ?;
249
257
self . write_null ( dest) ?;
250
258
trace ! ( "__rust_maybe_catch_panic: {:?}" , f_instance) ;
251
259
@@ -289,8 +297,8 @@ impl<'a, 'mir, 'tcx: 'mir + 'a> EvalContextExt<'tcx, 'mir> for super::MiriEvalCo
289
297
let n = Size :: from_bytes ( self . read_scalar ( args[ 2 ] ) ?. to_usize ( & self ) ?) ;
290
298
291
299
let result = {
292
- let left_bytes = self . memory . read_bytes ( left. with_default_tag ( ) , n) ?;
293
- let right_bytes = self . memory . read_bytes ( right. with_default_tag ( ) , n) ?;
300
+ let left_bytes = self . memory ( ) . read_bytes ( left. with_default_tag ( ) , n) ?;
301
+ let right_bytes = self . memory ( ) . read_bytes ( right. with_default_tag ( ) , n) ?;
294
302
295
303
use std:: cmp:: Ordering :: * ;
296
304
match left_bytes. cmp ( right_bytes) {
@@ -311,7 +319,7 @@ impl<'a, 'mir, 'tcx: 'mir + 'a> EvalContextExt<'tcx, 'mir> for super::MiriEvalCo
311
319
let ptr = ptr. with_default_tag ( ) ;
312
320
let val = self . read_scalar ( args[ 1 ] ) ?. to_bytes ( ) ? as u8 ;
313
321
let num = self . read_scalar ( args[ 2 ] ) ?. to_usize ( & self ) ?;
314
- if let Some ( idx) = self . memory . read_bytes ( ptr, Size :: from_bytes ( num) ) ?
322
+ if let Some ( idx) = self . memory ( ) . read_bytes ( ptr, Size :: from_bytes ( num) ) ?
315
323
. iter ( ) . rev ( ) . position ( |& c| c == val)
316
324
{
317
325
let new_ptr = ptr. ptr_offset ( Size :: from_bytes ( num - idx as u64 - 1 ) , & self ) ?;
@@ -326,7 +334,7 @@ impl<'a, 'mir, 'tcx: 'mir + 'a> EvalContextExt<'tcx, 'mir> for super::MiriEvalCo
326
334
let ptr = ptr. with_default_tag ( ) ;
327
335
let val = self . read_scalar ( args[ 1 ] ) ?. to_bytes ( ) ? as u8 ;
328
336
let num = self . read_scalar ( args[ 2 ] ) ?. to_usize ( & self ) ?;
329
- if let Some ( idx) = self . memory . read_bytes ( ptr, Size :: from_bytes ( num) ) ?. iter ( ) . position (
337
+ if let Some ( idx) = self . memory ( ) . read_bytes ( ptr, Size :: from_bytes ( num) ) ?. iter ( ) . position (
330
338
|& c| c == val,
331
339
)
332
340
{
@@ -340,7 +348,7 @@ impl<'a, 'mir, 'tcx: 'mir + 'a> EvalContextExt<'tcx, 'mir> for super::MiriEvalCo
340
348
"getenv" => {
341
349
let result = {
342
350
let name_ptr = self . read_scalar ( args[ 0 ] ) ?. to_ptr ( ) ?. erase_tag ( ) ; // raw ptr operation
343
- let name = self . memory . read_c_str ( name_ptr. with_default_tag ( ) ) ?;
351
+ let name = self . memory ( ) . read_c_str ( name_ptr. with_default_tag ( ) ) ?;
344
352
match self . machine . env_vars . get ( name) {
345
353
Some ( & var) => Scalar :: Ptr ( var) ,
346
354
None => Scalar :: ptr_null ( * self . tcx ) ,
@@ -354,15 +362,16 @@ impl<'a, 'mir, 'tcx: 'mir + 'a> EvalContextExt<'tcx, 'mir> for super::MiriEvalCo
354
362
{
355
363
let name_ptr = self . read_scalar ( args[ 0 ] ) ?. not_undef ( ) ?. erase_tag ( ) ; // raw ptr operation
356
364
if !name_ptr. is_null_ptr ( & self ) {
357
- let name = self . memory . read_c_str ( name_ptr. to_ptr ( ) ?. with_default_tag ( ) ) ?;
365
+ let name = self . memory ( ) . read_c_str ( name_ptr. to_ptr ( ) ?
366
+ . with_default_tag ( ) ) ?. to_owned ( ) ;
358
367
if !name. is_empty ( ) && !name. contains ( & b'=' ) {
359
- success = Some ( self . machine . env_vars . remove ( name) ) ;
368
+ success = Some ( self . machine . env_vars . remove ( & name) ) ;
360
369
}
361
370
}
362
371
}
363
372
if let Some ( old) = success {
364
373
if let Some ( var) = old {
365
- self . memory . deallocate ( var, None , MiriMemoryKind :: Env . into ( ) ) ?;
374
+ self . memory_mut ( ) . deallocate ( var, None , MiriMemoryKind :: Env . into ( ) ) ?;
366
375
}
367
376
self . write_null ( dest) ?;
368
377
} else {
@@ -375,30 +384,30 @@ impl<'a, 'mir, 'tcx: 'mir + 'a> EvalContextExt<'tcx, 'mir> for super::MiriEvalCo
375
384
{
376
385
let name_ptr = self . read_scalar ( args[ 0 ] ) ?. not_undef ( ) ?. erase_tag ( ) ; // raw ptr operation
377
386
let value_ptr = self . read_scalar ( args[ 1 ] ) ?. to_ptr ( ) ?. erase_tag ( ) ; // raw ptr operation
378
- let value = self . memory . read_c_str ( value_ptr. with_default_tag ( ) ) ?;
387
+ let value = self . memory ( ) . read_c_str ( value_ptr. with_default_tag ( ) ) ?;
379
388
if !name_ptr. is_null_ptr ( & self ) {
380
- let name = self . memory . read_c_str ( name_ptr. to_ptr ( ) ?. with_default_tag ( ) ) ?;
389
+ let name = self . memory ( ) . read_c_str ( name_ptr. to_ptr ( ) ?. with_default_tag ( ) ) ?;
381
390
if !name. is_empty ( ) && !name. contains ( & b'=' ) {
382
391
new = Some ( ( name. to_owned ( ) , value. to_owned ( ) ) ) ;
383
392
}
384
393
}
385
394
}
386
395
if let Some ( ( name, value) ) = new {
387
396
// +1 for the null terminator
388
- let value_copy = self . memory . allocate (
397
+ let value_copy = self . memory_mut ( ) . allocate (
389
398
Size :: from_bytes ( ( value. len ( ) + 1 ) as u64 ) ,
390
399
Align :: from_bytes ( 1 , 1 ) . unwrap ( ) ,
391
400
MiriMemoryKind :: Env . into ( ) ,
392
- ) ?;
393
- self . memory . write_bytes ( value_copy. into ( ) , & value) ?;
401
+ ) ?. with_default_tag ( ) ;
402
+ self . memory_mut ( ) . write_bytes ( value_copy. into ( ) , & value) ?;
394
403
let trailing_zero_ptr = value_copy. offset ( Size :: from_bytes ( value. len ( ) as u64 ) , & self ) ?. into ( ) ;
395
- self . memory . write_bytes ( trailing_zero_ptr, & [ 0 ] ) ?;
404
+ self . memory_mut ( ) . write_bytes ( trailing_zero_ptr, & [ 0 ] ) ?;
396
405
if let Some ( var) = self . machine . env_vars . insert (
397
406
name. to_owned ( ) ,
398
407
value_copy,
399
408
)
400
409
{
401
- self . memory . deallocate ( var, None , MiriMemoryKind :: Env . into ( ) ) ?;
410
+ self . memory_mut ( ) . deallocate ( var, None , MiriMemoryKind :: Env . into ( ) ) ?;
402
411
}
403
412
self . write_null ( dest) ?;
404
413
} else {
@@ -415,7 +424,7 @@ impl<'a, 'mir, 'tcx: 'mir + 'a> EvalContextExt<'tcx, 'mir> for super::MiriEvalCo
415
424
// stdout/stderr
416
425
use std:: io:: { self , Write } ;
417
426
418
- let buf_cont = self . memory . read_bytes ( buf. with_default_tag ( ) , Size :: from_bytes ( n) ) ?;
427
+ let buf_cont = self . memory ( ) . read_bytes ( buf. with_default_tag ( ) , Size :: from_bytes ( n) ) ?;
419
428
let res = if fd == 1 {
420
429
io:: stdout ( ) . write ( buf_cont)
421
430
} else {
@@ -437,7 +446,7 @@ impl<'a, 'mir, 'tcx: 'mir + 'a> EvalContextExt<'tcx, 'mir> for super::MiriEvalCo
437
446
438
447
"strlen" => {
439
448
let ptr = self . read_scalar ( args[ 0 ] ) ?. to_ptr ( ) ?. erase_tag ( ) ;
440
- let n = self . memory . read_c_str ( ptr. with_default_tag ( ) ) ?. len ( ) ;
449
+ let n = self . memory ( ) . read_c_str ( ptr. with_default_tag ( ) ) ?. len ( ) ;
441
450
self . write_scalar ( Scalar :: from_uint ( n as u64 , dest. layout . size ) , dest) ?;
442
451
}
443
452
@@ -487,9 +496,9 @@ impl<'a, 'mir, 'tcx: 'mir + 'a> EvalContextExt<'tcx, 'mir> for super::MiriEvalCo
487
496
488
497
// Extract the function type out of the signature (that seems easier than constructing it ourselves...)
489
498
let dtor = match self . read_scalar ( args[ 1 ] ) ?. not_undef ( ) ? {
490
- Scalar :: Ptr ( dtor_ptr) => Some ( self . memory . get_fn ( dtor_ptr) ?) ,
499
+ Scalar :: Ptr ( dtor_ptr) => Some ( self . memory ( ) . get_fn ( dtor_ptr) ?) ,
491
500
Scalar :: Bits { bits : 0 , size } => {
492
- assert_eq ! ( size as u64 , self . memory. pointer_size( ) . bytes( ) ) ;
501
+ assert_eq ! ( size as u64 , self . memory( ) . pointer_size( ) . bytes( ) ) ;
493
502
None
494
503
} ,
495
504
Scalar :: Bits { .. } => return err ! ( ReadBytesAsPointer ) ,
@@ -505,7 +514,7 @@ impl<'a, 'mir, 'tcx: 'mir + 'a> EvalContextExt<'tcx, 'mir> for super::MiriEvalCo
505
514
if key_layout. size . bits ( ) < 128 && key >= ( 1u128 << key_layout. size . bits ( ) as u128 ) {
506
515
return err ! ( OutOfTls ) ;
507
516
}
508
- self . memory . write_scalar (
517
+ self . memory_mut ( ) . write_scalar (
509
518
key_ptr. with_default_tag ( ) ,
510
519
key_layout. align ,
511
520
Scalar :: from_uint ( key, key_layout. size ) . into ( ) ,
0 commit comments