MCPcopy Create free account
hub / github.com/elast0ny/shared_memory / new_map

Function new_map

src/windows.rs:134–267  ·  view source on GitHub ↗
(
    unique_id: &str,
    mut map_size: usize,
    create: bool,
    allow_raw: bool,
)

Source from the content-addressed store, hash-verified

132}
133
134fn new_map(
135 unique_id: &str,
136 mut map_size: usize,
137 create: bool,
138 allow_raw: bool,
139) -> Result<MapData, ShmemError> {
140 // Create file to back the shared memory
141 let mut file_path = get_tmp_dir()?;
142 file_path.push(unique_id.trim_start_matches('/'));
143 debug!(
144 "{} persistent_file at {}",
145 if create { "Creating" } else { "Openning" },
146 file_path.to_string_lossy()
147 );
148
149 let mut opt = OpenOptions::new();
150 opt.read(true)
151 .write(true)
152 .share_mode((FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE).0)
153 .attributes((FILE_ATTRIBUTE_TEMPORARY).0);
154 if create {
155 opt.create_new(true);
156 } else {
157 opt.create(false);
158 };
159
160 let mut persistent_file = None;
161 let map_h = match opt.open(&file_path) {
162 Ok(f) => {
163 //Create/open Mapping using persistent file
164 debug!(
165 "{} memory mapping",
166 if create { "Creating" } else { "Openning" },
167 );
168 let high_size: u32 = ((map_size as u64 & 0xFFFF_FFFF_0000_0000_u64) >> 32) as u32;
169 let low_size: u32 = (map_size as u64 & 0xFFFF_FFFF_u64) as u32;
170 trace!(
171 "CreateFileMapping({:?}, NULL, {:X}, {}, {}, '{}')",
172 HANDLE(f.as_raw_handle() as _),
173 PAGE_READWRITE.0,
174 high_size,
175 low_size,
176 unique_id,
177 );
178
179 match CreateFileMapping(
180 HANDLE(f.as_raw_handle() as _),
181 None,
182 PAGE_READWRITE,
183 high_size,
184 low_size,
185 unique_id,
186 ) {
187 Ok(v) => {
188 persistent_file = Some(f);
189 v
190 }
191 Err(e) => {

Callers 2

create_mappingFunction · 0.85
open_mappingFunction · 0.85

Calls 4

get_tmp_dirFunction · 0.85
createMethod · 0.80
openMethod · 0.80
as_mut_ptrMethod · 0.45

Tested by

no test coverage detected