@@ -513,22 +513,37 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
513
513
}
514
514
515
515
// Rust allocation
516
- "__rust_alloc" => {
516
+ "__rust_alloc" | "miri_alloc" => {
517
517
let [ size, align] = this. check_shim ( abi, Abi :: Rust , link_name, args) ?;
518
518
let size = this. read_scalar ( size) ?. to_machine_usize ( this) ?;
519
519
let align = this. read_scalar ( align) ?. to_machine_usize ( this) ?;
520
520
521
- return this. emulate_allocator ( Symbol :: intern ( "__rg_alloc" ) , |this | {
521
+ let default = | this : & mut MiriInterpCx < ' mir , ' tcx > | {
522
522
Self :: check_alloc_request ( size, align) ?;
523
523
524
+ let memory_kind = match link_name. as_str ( ) {
525
+ "__rust_alloc" => MiriMemoryKind :: Rust ,
526
+ "miri_alloc" => MiriMemoryKind :: Miri ,
527
+ _ => unreachable ! ( ) ,
528
+ } ;
529
+
524
530
let ptr = this. allocate_ptr (
525
531
Size :: from_bytes ( size) ,
526
532
Align :: from_bytes ( align) . unwrap ( ) ,
527
- MiriMemoryKind :: Rust . into ( ) ,
533
+ memory_kind . into ( ) ,
528
534
) ?;
529
535
530
536
this. write_pointer ( ptr, dest)
531
- } ) ;
537
+ } ;
538
+
539
+ match link_name. as_str ( ) {
540
+ "__rust_alloc" => return this. emulate_allocator ( Symbol :: intern ( "__rg_alloc" ) , default) ,
541
+ "miri_alloc" => {
542
+ default ( this) ?;
543
+ return Ok ( EmulateByNameResult :: NeedsJumping ) ;
544
+ } ,
545
+ _ => unreachable ! ( ) ,
546
+ }
532
547
}
533
548
"__rust_alloc_zeroed" => {
534
549
let [ size, align] = this. check_shim ( abi, Abi :: Rust , link_name, args) ?;
@@ -549,20 +564,35 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
549
564
this. write_pointer ( ptr, dest)
550
565
} ) ;
551
566
}
552
- "__rust_dealloc" => {
567
+ "__rust_dealloc" | "miri_dealloc" => {
553
568
let [ ptr, old_size, align] = this. check_shim ( abi, Abi :: Rust , link_name, args) ?;
554
569
let ptr = this. read_pointer ( ptr) ?;
555
570
let old_size = this. read_scalar ( old_size) ?. to_machine_usize ( this) ?;
556
571
let align = this. read_scalar ( align) ?. to_machine_usize ( this) ?;
557
572
558
- return this. emulate_allocator ( Symbol :: intern ( "__rg_dealloc" ) , |this| {
573
+ let default = |this : & mut MiriInterpCx < ' mir , ' tcx > | {
574
+ let memory_kind = match link_name. as_str ( ) {
575
+ "__rust_dealloc" => MiriMemoryKind :: Rust ,
576
+ "miri_dealloc" => MiriMemoryKind :: Miri ,
577
+ _ => unreachable ! ( ) ,
578
+ } ;
579
+
559
580
// No need to check old_size/align; we anyway check that they match the allocation.
560
581
this. deallocate_ptr (
561
582
ptr,
562
583
Some ( ( Size :: from_bytes ( old_size) , Align :: from_bytes ( align) . unwrap ( ) ) ) ,
563
- MiriMemoryKind :: Rust . into ( ) ,
584
+ memory_kind . into ( ) ,
564
585
)
565
- } ) ;
586
+ } ;
587
+
588
+ match link_name. as_str ( ) {
589
+ "__rust_dealloc" => return this. emulate_allocator ( Symbol :: intern ( "__rg_dealloc" ) , default) ,
590
+ "miri_dealloc" => {
591
+ default ( this) ?;
592
+ return Ok ( EmulateByNameResult :: NeedsJumping ) ;
593
+ }
594
+ _ => unreachable ! ( ) ,
595
+ }
566
596
}
567
597
"__rust_realloc" => {
568
598
let [ ptr, old_size, align, new_size] = this. check_shim ( abi, Abi :: Rust , link_name, args) ?;
0 commit comments