@@ -513,22 +513,37 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
513513 }
514514
515515 // Rust allocation
516- "__rust_alloc" => {
516+ "__rust_alloc" | "miri_alloc" => {
517517 let [ size, align] = this. check_shim ( abi, Abi :: Rust , link_name, args) ?;
518518 let size = this. read_scalar ( size) ?. to_machine_usize ( this) ?;
519519 let align = this. read_scalar ( align) ?. to_machine_usize ( this) ?;
520520
521- return this. emulate_allocator ( Symbol :: intern ( "__rg_alloc" ) , |this | {
521+ let default = | this : & mut MiriInterpCx < ' mir , ' tcx > | {
522522 Self :: check_alloc_request ( size, align) ?;
523523
524+ let memory_kind = match link_name. as_str ( ) {
525+ "__rust_alloc" => MiriMemoryKind :: Rust ,
526+ "miri_alloc" => MiriMemoryKind :: Miri ,
527+ _ => unreachable ! ( ) ,
528+ } ;
529+
524530 let ptr = this. allocate_ptr (
525531 Size :: from_bytes ( size) ,
526532 Align :: from_bytes ( align) . unwrap ( ) ,
527- MiriMemoryKind :: Rust . into ( ) ,
533+ memory_kind . into ( ) ,
528534 ) ?;
529535
530536 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+ }
532547 }
533548 "__rust_alloc_zeroed" => {
534549 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> {
549564 this. write_pointer ( ptr, dest)
550565 } ) ;
551566 }
552- "__rust_dealloc" => {
567+ "__rust_dealloc" | "miri_dealloc" => {
553568 let [ ptr, old_size, align] = this. check_shim ( abi, Abi :: Rust , link_name, args) ?;
554569 let ptr = this. read_pointer ( ptr) ?;
555570 let old_size = this. read_scalar ( old_size) ?. to_machine_usize ( this) ?;
556571 let align = this. read_scalar ( align) ?. to_machine_usize ( this) ?;
557572
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+
559580 // No need to check old_size/align; we anyway check that they match the allocation.
560581 this. deallocate_ptr (
561582 ptr,
562583 Some ( ( Size :: from_bytes ( old_size) , Align :: from_bytes ( align) . unwrap ( ) ) ) ,
563- MiriMemoryKind :: Rust . into ( ) ,
584+ memory_kind . into ( ) ,
564585 )
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+ }
566596 }
567597 "__rust_realloc" => {
568598 let [ ptr, old_size, align, new_size] = this. check_shim ( abi, Abi :: Rust , link_name, args) ?;
0 commit comments