@@ -847,11 +847,11 @@ pub struct MemoryMap {
847
847
848
848
/// Type of memory map
849
849
pub enum MemoryMapKind {
850
- /// Memory-mapped file. On Windows, the inner pointer is a handle to the mapping, and
851
- /// corresponds to `CreateFileMapping`. Elsewhere, it is null.
852
- MapFile ( * u8 ) ,
853
850
/// Virtual memory map. Usually used to change the permissions of a given chunk of memory.
854
851
/// Corresponds to `VirtualAlloc` on Windows.
852
+ MapFile ( * u8 ) ,
853
+ /// Virtual memory map. Usually used to change the permissions of a given chunk of memory, or
854
+ /// for allocation. Corresponds to `VirtualAlloc` on Windows.
855
855
MapVirtual
856
856
}
857
857
@@ -868,7 +868,11 @@ pub enum MapOption {
868
868
/// Create a memory mapping for a file with a given fd.
869
869
MapFd ( c_int ) ,
870
870
/// When using `MapFd`, the start of the map is `uint` bytes from the start of the file.
871
- MapOffset ( uint )
871
+ MapOffset ( uint ) ,
872
+ /// On POSIX, this can be used to specify the default flags passed to `mmap`. By default it uses
873
+ /// `MAP_PRIVATE` and, if not using `MapFd`, `MAP_ANON`. This will override both of those. This
874
+ /// is platform-specific (the exact values used) and unused on Windows.
875
+ MapNonStandardFlags ( c_int ) ,
872
876
}
873
877
874
878
/// Possible errors when creating a map.
@@ -938,6 +942,7 @@ impl MemoryMap {
938
942
let mut flags = libc:: MAP_PRIVATE ;
939
943
let mut fd = -1 ;
940
944
let mut offset = 0 ;
945
+ let mut custom_flags = false ;
941
946
let len = round_up( min_len, page_size( ) ) ;
942
947
943
948
for & o in options. iter ( ) {
@@ -953,10 +958,11 @@ impl MemoryMap {
953
958
flags |= libc:: MAP_FILE ;
954
959
fd = fd_;
955
960
} ,
956
- MapOffset ( offset_) => { offset = offset_ as off_t ; }
961
+ MapOffset ( offset_) => { offset = offset_ as off_t ; } ,
962
+ MapNonStandardFlags ( f) => { custom_flags = true ; flags = f } ,
957
963
}
958
964
}
959
- if fd == -1 { flags |= libc:: MAP_ANON ; }
965
+ if fd == -1 && !custom_flags { flags |= libc:: MAP_ANON ; }
960
966
961
967
let r = unsafe {
962
968
libc : : mmap( addr as * c_void, len as size_t, prot, flags, fd, offset)
@@ -1027,7 +1033,9 @@ impl MemoryMap {
1027
1033
MapExecutable => { executable = true ; }
1028
1034
MapAddr ( addr_) => { lpAddress = addr_ as LPVOID ; } ,
1029
1035
MapFd ( fd_) => { fd = fd_; } ,
1030
- MapOffset ( offset_) => { offset = offset_; }
1036
+ MapOffset ( offset_) => { offset = offset_; } ,
1037
+ MapNonStandardFlags ( f) => info ! ( "MemoryMap::new: MapNonStandardFlags used on \
1038
+ Windows: {}", f) ,
1031
1039
}
1032
1040
}
1033
1041
0 commit comments