1
1
//! Reading and writing of the rustc metadata for rlibs and dylibs
2
2
3
3
use std:: fs:: File ;
4
- use std:: ops:: Deref ;
5
4
use std:: path:: Path ;
6
5
7
6
use 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 ;
9
9
use rustc_data_structures:: rustc_erase_owner;
10
10
use rustc_data_structures:: sync:: MetadataRef ;
11
11
use rustc_middle:: middle:: cstore:: { EncodedMetadata , MetadataLoader } ;
@@ -17,26 +17,13 @@ use crate::backend::WriteMetadata;
17
17
18
18
pub ( crate ) struct CraneliftMetadataLoader ;
19
19
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
-
32
20
fn load_metadata_with (
33
21
path : & Path ,
34
22
f : impl for < ' a > FnOnce ( & ' a [ u8 ] ) -> Result < & ' a [ u8 ] , String > ,
35
23
) -> Result < MetadataRef , String > {
36
24
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) ?;
40
27
return Ok ( rustc_erase_owner ! ( metadata. map_owner_box( ) ) ) ;
41
28
}
42
29
0 commit comments