13
13
use super :: {
14
14
UndefMask ,
15
15
Relocations ,
16
+ EvalResult ,
17
+ Pointer ,
18
+ AllocId ,
19
+ Scalar ,
20
+ ScalarMaybeUndef ,
21
+ write_target_uint,
22
+ read_target_uint,
23
+ truncate,
16
24
} ;
17
25
18
- use ty:: layout:: { Size , Align } ;
26
+ use std:: ptr;
27
+ use ty:: layout:: { self , Size , Align } ;
19
28
use syntax:: ast:: Mutability ;
20
29
21
30
#[ derive( Clone , Debug , Eq , PartialEq , PartialOrd , Ord , Hash , RustcEncodable , RustcDecodable ) ]
@@ -85,7 +94,7 @@ impl<'tcx, Tag, Extra> Allocation<Tag, Extra> {
85
94
/// on that.
86
95
fn get_bytes_internal (
87
96
& self ,
88
- ptr : Pointer < M :: PointerTag > ,
97
+ ptr : Pointer < Tag > ,
89
98
size : Size ,
90
99
align : Align ,
91
100
check_defined_and_ptr : bool ,
@@ -114,7 +123,7 @@ impl<'tcx, Tag, Extra> Allocation<Tag, Extra> {
114
123
#[ inline]
115
124
fn get_bytes (
116
125
& self ,
117
- ptr : Pointer < M :: PointerTag > ,
126
+ ptr : Pointer < Tag > ,
118
127
size : Size ,
119
128
align : Align
120
129
) -> EvalResult < ' tcx , & [ u8 ] > {
@@ -126,7 +135,7 @@ impl<'tcx, Tag, Extra> Allocation<Tag, Extra> {
126
135
#[ inline]
127
136
fn get_bytes_with_undef_and_ptr (
128
137
& self ,
129
- ptr : Pointer < M :: PointerTag > ,
138
+ ptr : Pointer < Tag > ,
130
139
size : Size ,
131
140
align : Align
132
141
) -> EvalResult < ' tcx , & [ u8 ] > {
@@ -137,7 +146,7 @@ impl<'tcx, Tag, Extra> Allocation<Tag, Extra> {
137
146
/// so be sure to actually put data there!
138
147
fn get_bytes_mut (
139
148
& mut self ,
140
- ptr : Pointer < M :: PointerTag > ,
149
+ ptr : Pointer < Tag > ,
141
150
size : Size ,
142
151
align : Align ,
143
152
) -> EvalResult < ' tcx , & mut [ u8 ] > {
@@ -162,9 +171,9 @@ impl<'tcx, Tag, Extra> Allocation<Tag, Extra> {
162
171
impl < ' tcx , Tag , Extra > Allocation < Tag , Extra > {
163
172
pub fn copy (
164
173
& mut self ,
165
- src : Scalar < M :: PointerTag > ,
174
+ src : Scalar < Tag > ,
166
175
src_align : Align ,
167
- dest : Scalar < M :: PointerTag > ,
176
+ dest : Scalar < Tag > ,
168
177
dest_align : Align ,
169
178
size : Size ,
170
179
nonoverlapping : bool ,
@@ -174,9 +183,9 @@ impl<'tcx, Tag, Extra> Allocation<Tag, Extra> {
174
183
175
184
pub fn copy_repeatedly (
176
185
& mut self ,
177
- src : Scalar < M :: PointerTag > ,
186
+ src : Scalar < Tag > ,
178
187
src_align : Align ,
179
- dest : Scalar < M :: PointerTag > ,
188
+ dest : Scalar < Tag > ,
180
189
dest_align : Align ,
181
190
size : Size ,
182
191
length : u64 ,
@@ -257,7 +266,7 @@ impl<'tcx, Tag, Extra> Allocation<Tag, Extra> {
257
266
Ok ( ( ) )
258
267
}
259
268
260
- pub fn read_c_str ( & self , ptr : Pointer < M :: PointerTag > ) -> EvalResult < ' tcx , & [ u8 ] > {
269
+ pub fn read_c_str ( & self , ptr : Pointer < Tag > ) -> EvalResult < ' tcx , & [ u8 ] > {
261
270
let alloc = self . get ( ptr. alloc_id ) ?;
262
271
assert_eq ! ( ptr. offset. bytes( ) as usize as u64 , ptr. offset. bytes( ) ) ;
263
272
let offset = ptr. offset . bytes ( ) as usize ;
@@ -274,7 +283,7 @@ impl<'tcx, Tag, Extra> Allocation<Tag, Extra> {
274
283
275
284
pub fn check_bytes (
276
285
& self ,
277
- ptr : Scalar < M :: PointerTag > ,
286
+ ptr : Scalar < Tag > ,
278
287
size : Size ,
279
288
allow_ptr_and_undef : bool ,
280
289
) -> EvalResult < ' tcx > {
@@ -295,7 +304,7 @@ impl<'tcx, Tag, Extra> Allocation<Tag, Extra> {
295
304
Ok ( ( ) )
296
305
}
297
306
298
- pub fn read_bytes ( & self , ptr : Scalar < M :: PointerTag > , size : Size ) -> EvalResult < ' tcx , & [ u8 ] > {
307
+ pub fn read_bytes ( & self , ptr : Scalar < Tag > , size : Size ) -> EvalResult < ' tcx , & [ u8 ] > {
299
308
// Empty accesses don't need to be valid pointers, but they should still be non-NULL
300
309
let align = Align :: from_bytes ( 1 , 1 ) . unwrap ( ) ;
301
310
if size. bytes ( ) == 0 {
@@ -305,7 +314,7 @@ impl<'tcx, Tag, Extra> Allocation<Tag, Extra> {
305
314
self . get_bytes ( ptr. to_ptr ( ) ?, size, align)
306
315
}
307
316
308
- pub fn write_bytes ( & mut self , ptr : Scalar < M :: PointerTag > , src : & [ u8 ] ) -> EvalResult < ' tcx > {
317
+ pub fn write_bytes ( & mut self , ptr : Scalar < Tag > , src : & [ u8 ] ) -> EvalResult < ' tcx > {
309
318
// Empty accesses don't need to be valid pointers, but they should still be non-NULL
310
319
let align = Align :: from_bytes ( 1 , 1 ) . unwrap ( ) ;
311
320
if src. is_empty ( ) {
@@ -319,7 +328,7 @@ impl<'tcx, Tag, Extra> Allocation<Tag, Extra> {
319
328
320
329
pub fn write_repeat (
321
330
& mut self ,
322
- ptr : Scalar < M :: PointerTag > ,
331
+ ptr : Scalar < Tag > ,
323
332
val : u8 ,
324
333
count : Size
325
334
) -> EvalResult < ' tcx > {
@@ -339,10 +348,10 @@ impl<'tcx, Tag, Extra> Allocation<Tag, Extra> {
339
348
/// Read a *non-ZST* scalar
340
349
pub fn read_scalar (
341
350
& self ,
342
- ptr : Pointer < M :: PointerTag > ,
351
+ ptr : Pointer < Tag > ,
343
352
ptr_align : Align ,
344
353
size : Size
345
- ) -> EvalResult < ' tcx , ScalarMaybeUndef < M :: PointerTag > > {
354
+ ) -> EvalResult < ' tcx , ScalarMaybeUndef < Tag > > {
346
355
// get_bytes_unchecked tests alignment and relocation edges
347
356
let bytes = self . get_bytes_with_undef_and_ptr (
348
357
ptr, size, ptr_align. min ( self . int_align ( size) )
@@ -376,18 +385,18 @@ impl<'tcx, Tag, Extra> Allocation<Tag, Extra> {
376
385
377
386
pub fn read_ptr_sized (
378
387
& self ,
379
- ptr : Pointer < M :: PointerTag > ,
388
+ ptr : Pointer < Tag > ,
380
389
ptr_align : Align
381
- ) -> EvalResult < ' tcx , ScalarMaybeUndef < M :: PointerTag > > {
390
+ ) -> EvalResult < ' tcx , ScalarMaybeUndef < Tag > > {
382
391
self . read_scalar ( ptr, ptr_align, self . pointer_size ( ) )
383
392
}
384
393
385
394
/// Write a *non-ZST* scalar
386
395
pub fn write_scalar (
387
396
& mut self ,
388
- ptr : Pointer < M :: PointerTag > ,
397
+ ptr : Pointer < Tag > ,
389
398
ptr_align : Align ,
390
- val : ScalarMaybeUndef < M :: PointerTag > ,
399
+ val : ScalarMaybeUndef < Tag > ,
391
400
type_size : Size ,
392
401
) -> EvalResult < ' tcx > {
393
402
let val = match val {
@@ -432,9 +441,9 @@ impl<'tcx, Tag, Extra> Allocation<Tag, Extra> {
432
441
433
442
pub fn write_ptr_sized (
434
443
& mut self ,
435
- ptr : Pointer < M :: PointerTag > ,
444
+ ptr : Pointer < Tag > ,
436
445
ptr_align : Align ,
437
- val : ScalarMaybeUndef < M :: PointerTag >
446
+ val : ScalarMaybeUndef < Tag >
438
447
) -> EvalResult < ' tcx > {
439
448
let ptr_size = self . pointer_size ( ) ;
440
449
self . write_scalar ( ptr. into ( ) , ptr_align, val, ptr_size)
@@ -460,9 +469,9 @@ impl<'tcx, Tag, Extra> Allocation<Tag, Extra> {
460
469
/// Return all relocations overlapping with the given ptr-offset pair.
461
470
fn relocations (
462
471
& self ,
463
- ptr : Pointer < M :: PointerTag > ,
472
+ ptr : Pointer < Tag > ,
464
473
size : Size ,
465
- ) -> EvalResult < ' tcx , & [ ( Size , ( M :: PointerTag , AllocId ) ) ] > {
474
+ ) -> EvalResult < ' tcx , & [ ( Size , ( Tag , AllocId ) ) ] > {
466
475
// We have to go back `pointer_size - 1` bytes, as that one would still overlap with
467
476
// the beginning of this range.
468
477
let start = ptr. offset . bytes ( ) . saturating_sub ( self . pointer_size ( ) . bytes ( ) - 1 ) ;
@@ -472,7 +481,7 @@ impl<'tcx, Tag, Extra> Allocation<Tag, Extra> {
472
481
473
482
/// Check that there ar eno relocations overlapping with the given range.
474
483
#[ inline( always) ]
475
- fn check_relocations ( & self , ptr : Pointer < M :: PointerTag > , size : Size ) -> EvalResult < ' tcx > {
484
+ fn check_relocations ( & self , ptr : Pointer < Tag > , size : Size ) -> EvalResult < ' tcx > {
476
485
if self . relocations ( ptr, size) ?. len ( ) != 0 {
477
486
err ! ( ReadPointerAsBytes )
478
487
} else {
@@ -486,7 +495,7 @@ impl<'tcx, Tag, Extra> Allocation<Tag, Extra> {
486
495
/// uninitialized. This is a somewhat odd "spooky action at a distance",
487
496
/// but it allows strictly more code to run than if we would just error
488
497
/// immediately in that case.
489
- fn clear_relocations ( & mut self , ptr : Pointer < M :: PointerTag > , size : Size ) -> EvalResult < ' tcx > {
498
+ fn clear_relocations ( & mut self , ptr : Pointer < Tag > , size : Size ) -> EvalResult < ' tcx > {
490
499
// Find the start and end of the given range and its outermost relocations.
491
500
let ( first, last) = {
492
501
// Find all relocations overlapping the given range.
@@ -521,7 +530,7 @@ impl<'tcx, Tag, Extra> Allocation<Tag, Extra> {
521
530
/// Error if there are relocations overlapping with the egdes of the
522
531
/// given memory range.
523
532
#[ inline]
524
- fn check_relocation_edges ( & self , ptr : Pointer < M :: PointerTag > , size : Size ) -> EvalResult < ' tcx > {
533
+ fn check_relocation_edges ( & self , ptr : Pointer < Tag > , size : Size ) -> EvalResult < ' tcx > {
525
534
self . check_relocations ( ptr, Size :: ZERO ) ?;
526
535
self . check_relocations ( ptr. offset ( size, self ) ?, Size :: ZERO ) ?;
527
536
Ok ( ( ) )
@@ -533,8 +542,8 @@ impl<'tcx, Tag, Extra> Allocation<Tag, Extra> {
533
542
// FIXME: Add a fast version for the common, nonoverlapping case
534
543
fn copy_undef_mask (
535
544
& mut self ,
536
- src : Pointer < M :: PointerTag > ,
537
- dest : Pointer < M :: PointerTag > ,
545
+ src : Pointer < Tag > ,
546
+ dest : Pointer < Tag > ,
538
547
size : Size ,
539
548
repeat : u64 ,
540
549
) -> EvalResult < ' tcx > {
@@ -561,7 +570,7 @@ impl<'tcx, Tag, Extra> Allocation<Tag, Extra> {
561
570
/// Checks that a range of bytes is defined. If not, returns the `ReadUndefBytes`
562
571
/// error which will report the first byte which is undefined.
563
572
#[ inline]
564
- fn check_defined ( & self , ptr : Pointer < M :: PointerTag > , size : Size ) -> EvalResult < ' tcx > {
573
+ fn check_defined ( & self , ptr : Pointer < Tag > , size : Size ) -> EvalResult < ' tcx > {
565
574
let alloc = self . get ( ptr. alloc_id ) ?;
566
575
alloc. undef_mask . is_range_defined (
567
576
ptr. offset ,
@@ -571,7 +580,7 @@ impl<'tcx, Tag, Extra> Allocation<Tag, Extra> {
571
580
572
581
pub fn mark_definedness (
573
582
& mut self ,
574
- ptr : Pointer < M :: PointerTag > ,
583
+ ptr : Pointer < Tag > ,
575
584
size : Size ,
576
585
new_state : bool ,
577
586
) -> EvalResult < ' tcx > {
@@ -593,7 +602,7 @@ impl<'tcx, Tag, Extra> Allocation<Tag, Extra> {
593
602
/// You can pass a scalar, and a `Pointer` does not have to actually still be allocated.
594
603
pub fn check_align (
595
604
& self ,
596
- ptr : Scalar < M :: PointerTag > ,
605
+ ptr : Scalar < Tag > ,
597
606
required_align : Align
598
607
) -> EvalResult < ' tcx > {
599
608
// Check non-NULL/Undef, extract offset
@@ -648,7 +657,7 @@ impl<'tcx, Tag, Extra> Allocation<Tag, Extra> {
648
657
/// If you want to check bounds before doing a memory access, be sure to
649
658
/// check the pointer one past the end of your access, then everything will
650
659
/// work out exactly.
651
- pub fn check_bounds_ptr ( & self , ptr : Pointer < M :: PointerTag > , access : bool ) -> EvalResult < ' tcx > {
660
+ pub fn check_bounds_ptr ( & self , ptr : Pointer < Tag > , access : bool ) -> EvalResult < ' tcx > {
652
661
let alloc = self . get ( ptr. alloc_id ) ?;
653
662
let allocation_size = alloc. bytes . len ( ) as u64 ;
654
663
if ptr. offset . bytes ( ) > allocation_size {
@@ -665,7 +674,7 @@ impl<'tcx, Tag, Extra> Allocation<Tag, Extra> {
665
674
#[ inline( always) ]
666
675
pub fn check_bounds (
667
676
& self ,
668
- ptr : Pointer < M :: PointerTag > ,
677
+ ptr : Pointer < Tag > ,
669
678
size : Size ,
670
679
access : bool
671
680
) -> EvalResult < ' tcx > {
0 commit comments