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