You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
let process_handle:HANDLE = self.process_receiver.recv()?.into();
149
+
let surrogate_process_handle:HANDLE = self.process_receiver.recv()?.into();
150
+
let mapping_file_handle:HANDLE = mmap_file_handle.into();
150
151
151
-
// allocate memory
152
+
// Allocate the memory by creating a view over the memory mapped file
153
+
154
+
// Use MapViewOfFile2 to map memoy into the surrogate process, the MapViewOfFile2 API is implemented in as an inline function in a windows header file
155
+
// (see https://learn.microsoft.com/en-us/windows/win32/api/memoryapi/nf-memoryapi-mapviewoffile2#remarks) so we use the same API it uses in the header file here instead of
156
+
// MapViewOfFile2 which does not exist in the rust crate (see https://github.com/microsoft/windows-rs/issues/2595)
157
+
constNUMA_NO_PREFERRED_NODE:u32 = 0xFFFFFFFF;
152
158
let allocated_address = unsafe{
153
-
VirtualAllocEx(
154
-
process_handle,
159
+
MapViewOfFileNuma2(
160
+
mapping_file_handle,
161
+
surrogate_process_handle,
162
+
0,
155
163
Some(raw_source_address),
156
164
raw_size,
157
-
MEM_COMMIT | MEM_RESERVE,
158
-
PAGE_READWRITE,
165
+
0,
166
+
PAGE_READWRITE.0,
167
+
NUMA_NO_PREFERRED_NODE,
159
168
)
160
169
};
161
-
if allocated_address.is_null(){
170
+
171
+
if allocated_address.Value.is_null(){
172
+
log_then_return!(
173
+
"MapViewOfFileNuma2 failed for mem address {:?}",
174
+
raw_source_address
175
+
);
176
+
}
177
+
178
+
if allocated_address.Valueas*constc_void != raw_source_address {
INVALID_HANDLE_VALUE,// Causes the page file to be used as the backing store
454
+
None,
455
+
PAGE_READWRITE | SEC_COMMIT,
456
+
dwmaximumsizehigh,
457
+
dwmaximumsizelow,
458
+
PCSTR::null(),
459
+
)
460
+
.unwrap()
428
461
};
462
+
463
+
let addr = unsafe{MapViewOfFile(handle,FILE_MAP_ALL_ACCESS,0,0,0)};
464
+
429
465
let timer = Instant::now();
430
466
let surrogate_process = {
431
-
let res = surrogate_process_manager
432
-
.get_surrogate_process(size, allocated_address)?;
467
+
let res = surrogate_process_manager.get_surrogate_process(
468
+
size,
469
+
addr.Value,
470
+
HandleWrapper::from(handle),
471
+
)?;
433
472
let elapsed = timer.elapsed();
434
473
// Print out the time it took to get the process if its greater than 150ms (this is just to allow us to see that threads are blocking on the process queue)
435
474
if(elapsed.as_millis()asu64) > 150{
@@ -454,10 +493,11 @@ mod tests {
454
493
// dropping the surrogate process, as we do in the line
455
494
// below, will return it to the surrogate process manager
456
495
drop(surrogate_process);
457
-
unsafe{
458
-
let res = VirtualFree(allocated_address,0,MEM_RELEASE);
459
-
assert!(res.is_ok())
460
-
}
496
+
let res = unsafe{UnmapViewOfFile(addr)};
497
+
assert!(res.is_ok(),"Failed to UnmapViewOfFile: {:?}", res.err());
498
+
499
+
let res = unsafe{CloseHandle(handle)};
500
+
assert!(res.is_ok(),"Failed to CloseHandle: {:?}", res.err());
461
501
}
462
502
Ok(())
463
503
});
@@ -516,7 +556,11 @@ mod tests {
516
556
let mem = ExclusiveSharedMemory::new(SIZE).unwrap();
0 commit comments