@@ -521,80 +521,33 @@ trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> {
521521 }
522522
523523 // Rust allocation
524- "__rust_alloc" | "miri_alloc" => {
525- let default = |ecx : & mut MiriInterpCx < ' tcx > | {
526- // Only call `check_shim` when `#[global_allocator]` isn't used. When that
527- // macro is used, we act like no shim exists, so that the exported function can run.
528- let [ size, align] = ecx. check_shim ( abi, Conv :: Rust , link_name, args) ?;
529- let size = ecx. read_target_usize ( size) ?;
530- let align = ecx. read_target_usize ( align) ?;
531-
532- ecx. check_rustc_alloc_request ( size, align) ?;
533-
534- let memory_kind = match link_name. as_str ( ) {
535- "__rust_alloc" => MiriMemoryKind :: Rust ,
536- "miri_alloc" => MiriMemoryKind :: Miri ,
537- _ => unreachable ! ( ) ,
538- } ;
524+ "miri_alloc" => {
525+ let [ size, align] = this. check_shim ( abi, Conv :: Rust , link_name, args) ?;
526+ let size = this. read_target_usize ( size) ?;
527+ let align = this. read_target_usize ( align) ?;
539528
540- let ptr = ecx. allocate_ptr (
541- Size :: from_bytes ( size) ,
542- Align :: from_bytes ( align) . unwrap ( ) ,
543- memory_kind. into ( ) ,
544- ) ?;
529+ this. check_rustc_alloc_request ( size, align) ?;
545530
546- ecx. write_pointer ( ptr, dest)
547- } ;
531+ let ptr = this. allocate_ptr (
532+ Size :: from_bytes ( size) ,
533+ Align :: from_bytes ( align) . unwrap ( ) ,
534+ MiriMemoryKind :: Miri . into ( ) ,
535+ ) ?;
548536
549- match link_name. as_str ( ) {
550- "__rust_alloc" => return this. emulate_allocator ( ) ,
551- "miri_alloc" => {
552- default ( this) ?;
553- return interp_ok ( EmulateItemResult :: NeedsReturn ) ;
554- }
555- _ => unreachable ! ( ) ,
556- }
537+ this. write_pointer ( ptr, dest) ?;
557538 }
558- "__rust_alloc_zeroed" => {
559- return this. emulate_allocator ( ) ;
560- }
561- "__rust_dealloc" | "miri_dealloc" => {
562- let default = |ecx : & mut MiriInterpCx < ' tcx > | {
563- // See the comment for `__rust_alloc` why `check_shim` is only called in the
564- // default case.
565- let [ ptr, old_size, align] =
566- ecx. check_shim ( abi, Conv :: Rust , link_name, args) ?;
567- let ptr = ecx. read_pointer ( ptr) ?;
568- let old_size = ecx. read_target_usize ( old_size) ?;
569- let align = ecx. read_target_usize ( align) ?;
570-
571- let memory_kind = match link_name. as_str ( ) {
572- "__rust_dealloc" => MiriMemoryKind :: Rust ,
573- "miri_dealloc" => MiriMemoryKind :: Miri ,
574- _ => unreachable ! ( ) ,
575- } ;
576-
577- // No need to check old_size/align; we anyway check that they match the allocation.
578- ecx. deallocate_ptr (
579- ptr,
580- Some ( ( Size :: from_bytes ( old_size) , Align :: from_bytes ( align) . unwrap ( ) ) ) ,
581- memory_kind. into ( ) ,
582- )
583- } ;
539+ "miri_dealloc" => {
540+ let [ ptr, old_size, align] = this. check_shim ( abi, Conv :: Rust , link_name, args) ?;
541+ let ptr = this. read_pointer ( ptr) ?;
542+ let old_size = this. read_target_usize ( old_size) ?;
543+ let align = this. read_target_usize ( align) ?;
584544
585- match link_name. as_str ( ) {
586- "__rust_dealloc" => {
587- return this. emulate_allocator ( ) ;
588- }
589- "miri_dealloc" => {
590- default ( this) ?;
591- return interp_ok ( EmulateItemResult :: NeedsReturn ) ;
592- }
593- _ => unreachable ! ( ) ,
594- }
595- }
596- "__rust_realloc" => {
597- return this. emulate_allocator ( ) ;
545+ // No need to check old_size/align; we anyway check that they match the allocation.
546+ this. deallocate_ptr (
547+ ptr,
548+ Some ( ( Size :: from_bytes ( old_size) , Align :: from_bytes ( align) . unwrap ( ) ) ) ,
549+ MiriMemoryKind :: Miri . into ( ) ,
550+ ) ?;
598551 }
599552
600553 // C memory handling functions
0 commit comments