11//! Reading and writing of the rustc metadata for rlibs and dylibs
22
33use std:: fs:: File ;
4- use std:: ops:: Deref ;
54use std:: path:: Path ;
65
76use rustc_codegen_ssa:: METADATA_FILENAME ;
8- use rustc_data_structures:: owning_ref:: { OwningRef , StableAddress } ;
7+ use rustc_data_structures:: memmap:: Mmap ;
8+ use rustc_data_structures:: owning_ref:: OwningRef ;
99use rustc_data_structures:: rustc_erase_owner;
1010use rustc_data_structures:: sync:: MetadataRef ;
1111use rustc_middle:: middle:: cstore:: { EncodedMetadata , MetadataLoader } ;
@@ -17,26 +17,13 @@ use crate::backend::WriteMetadata;
1717
1818pub ( crate ) struct CraneliftMetadataLoader ;
1919
20- struct StableMmap ( memmap2:: Mmap ) ;
21-
22- impl Deref for StableMmap {
23- type Target = [ u8 ] ;
24-
25- fn deref ( & self ) -> & [ u8 ] {
26- & * self . 0
27- }
28- }
29-
30- unsafe impl StableAddress for StableMmap { }
31-
3220fn load_metadata_with (
3321 path : & Path ,
3422 f : impl for < ' a > FnOnce ( & ' a [ u8 ] ) -> Result < & ' a [ u8 ] , String > ,
3523) -> Result < MetadataRef , String > {
3624 let file = File :: open ( path) . map_err ( |e| format ! ( "{:?}" , e) ) ?;
37- let data = unsafe { memmap2:: MmapOptions :: new ( ) . map_copy_read_only ( & file) }
38- . map_err ( |e| format ! ( "{:?}" , e) ) ?;
39- let metadata = OwningRef :: new ( StableMmap ( data) ) . try_map ( f) ?;
25+ let data = unsafe { Mmap :: map ( file) } . map_err ( |e| format ! ( "{:?}" , e) ) ?;
26+ let metadata = OwningRef :: new ( data) . try_map ( f) ?;
4027 return Ok ( rustc_erase_owner ! ( metadata. map_owner_box( ) ) ) ;
4128}
4229
0 commit comments