@@ -25,35 +25,19 @@ pub enum InboundsCheck {
25
25
/// Used by `check_in_alloc` to indicate context of check
26
26
#[ derive( Debug , Copy , Clone , RustcEncodable , RustcDecodable , HashStable ) ]
27
27
pub enum CheckInAllocMsg {
28
- ReadCStr ,
29
- CheckBytes ,
30
- WriteBytes ,
31
- WriteRepeat ,
32
- ReadScalar ,
33
- WriteScalar ,
34
- SlicePatCoveredByConst ,
35
- ReadDiscriminant ,
36
- CheckAlign ,
37
- ReadBytes ,
38
- CopyRepeatedly ,
39
- CheckBounds ,
28
+ MemoryAccess ,
29
+ NullPointer ,
30
+ PointerArithmetic ,
31
+ OutOfBounds ,
40
32
}
41
33
42
34
impl Display for CheckInAllocMsg {
43
35
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
44
36
write ! ( f, "{}" , match * self {
45
- CheckInAllocMsg :: ReadCStr => "read C str" ,
46
- CheckInAllocMsg :: CheckBytes => "check bytes" ,
47
- CheckInAllocMsg :: WriteBytes => "write bytes" ,
48
- CheckInAllocMsg :: WriteRepeat => "write repeat" ,
49
- CheckInAllocMsg :: ReadScalar => "read scalar" ,
50
- CheckInAllocMsg :: WriteScalar => "write scalar" ,
51
- CheckInAllocMsg :: SlicePatCoveredByConst => "slice pat covered by const" ,
52
- CheckInAllocMsg :: ReadDiscriminant => "read discriminant" ,
53
- CheckInAllocMsg :: CheckAlign => "check align" ,
54
- CheckInAllocMsg :: ReadBytes => "read bytes" ,
55
- CheckInAllocMsg :: CopyRepeatedly => "copy repeatedly" ,
56
- CheckInAllocMsg :: CheckBounds => "check bounds" ,
37
+ CheckInAllocMsg :: MemoryAccess => "memory access" ,
38
+ CheckInAllocMsg :: NullPointer => "null pointer" ,
39
+ CheckInAllocMsg :: PointerArithmetic => "pointer arithmetic" ,
40
+ CheckInAllocMsg :: OutOfBounds => "out of bounds" ,
57
41
} )
58
42
}
59
43
}
@@ -311,7 +295,7 @@ impl<'tcx, Tag: Copy, Extra> Allocation<Tag, Extra> {
311
295
// Go through `get_bytes` for checks and AllocationExtra hooks.
312
296
// We read the null, so we include it in the request, but we want it removed
313
297
// from the result!
314
- Ok ( & self . get_bytes ( cx, ptr, size_with_null, CheckInAllocMsg :: ReadCStr ) ?[ ..size] )
298
+ Ok ( & self . get_bytes ( cx, ptr, size_with_null, CheckInAllocMsg :: NullPointer ) ?[ ..size] )
315
299
}
316
300
None => err ! ( UnterminatedCString ( ptr. erase_tag( ) ) ) ,
317
301
}
@@ -331,7 +315,7 @@ impl<'tcx, Tag: Copy, Extra> Allocation<Tag, Extra> {
331
315
where Extra : AllocationExtra < Tag , MemoryExtra >
332
316
{
333
317
// Check bounds and relocations on the edges
334
- self . get_bytes_with_undef_and_ptr ( cx, ptr, size, CheckInAllocMsg :: CheckBytes ) ?;
318
+ self . get_bytes_with_undef_and_ptr ( cx, ptr, size, CheckInAllocMsg :: OutOfBounds ) ?;
335
319
// Check undef and ptr
336
320
if !allow_ptr_and_undef {
337
321
self . check_defined ( ptr, size) ?;
@@ -353,7 +337,7 @@ impl<'tcx, Tag: Copy, Extra> Allocation<Tag, Extra> {
353
337
where Extra : AllocationExtra < Tag , MemoryExtra >
354
338
{
355
339
let bytes = self . get_bytes_mut ( cx, ptr, Size :: from_bytes ( src. len ( ) as u64 ) ,
356
- CheckInAllocMsg :: WriteBytes ) ?;
340
+ CheckInAllocMsg :: MemoryAccess ) ?;
357
341
bytes. clone_from_slice ( src) ;
358
342
Ok ( ( ) )
359
343
}
@@ -369,7 +353,7 @@ impl<'tcx, Tag: Copy, Extra> Allocation<Tag, Extra> {
369
353
// FIXME: Working around https://github.com/rust-lang/rust/issues/56209
370
354
where Extra : AllocationExtra < Tag , MemoryExtra >
371
355
{
372
- let bytes = self . get_bytes_mut ( cx, ptr, count, CheckInAllocMsg :: WriteRepeat ) ?;
356
+ let bytes = self . get_bytes_mut ( cx, ptr, count, CheckInAllocMsg :: MemoryAccess ) ?;
373
357
for b in bytes {
374
358
* b = val;
375
359
}
@@ -394,7 +378,7 @@ impl<'tcx, Tag: Copy, Extra> Allocation<Tag, Extra> {
394
378
where Extra : AllocationExtra < Tag , MemoryExtra >
395
379
{
396
380
// get_bytes_unchecked tests relocation edges
397
- let bytes = self . get_bytes_with_undef_and_ptr ( cx, ptr, size, CheckInAllocMsg :: ReadScalar ) ?;
381
+ let bytes = self . get_bytes_with_undef_and_ptr ( cx, ptr, size, CheckInAllocMsg :: PointerArithmetic ) ?;
398
382
// Undef check happens *after* we established that the alignment is correct.
399
383
// We must not return Ok() for unaligned pointers!
400
384
if self . check_defined ( ptr, size) . is_err ( ) {
@@ -471,7 +455,7 @@ impl<'tcx, Tag: Copy, Extra> Allocation<Tag, Extra> {
471
455
} ;
472
456
473
457
let endian = cx. data_layout ( ) . endian ;
474
- let dst = self . get_bytes_mut ( cx, ptr, type_size, CheckInAllocMsg :: WriteScalar ) ?;
458
+ let dst = self . get_bytes_mut ( cx, ptr, type_size, CheckInAllocMsg :: PointerArithmetic ) ?;
475
459
write_target_uint ( endian, dst, bytes) . unwrap ( ) ;
476
460
477
461
// See if we have to also write a relocation
0 commit comments