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