upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/runtime/shims/xmem.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'runtime/shims/xmem.cpp')
-rw-r--r--runtime/shims/xmem.cpp11
1 files changed, 3 insertions, 8 deletions
diff --git a/runtime/shims/xmem.cpp b/runtime/shims/xmem.cpp
index e97f60f1e..9665a8766 100644
--- a/runtime/shims/xmem.cpp
+++ b/runtime/shims/xmem.cpp
@@ -453,19 +453,14 @@ void* WINAPI XMemVirtualAlloc(void* address, SIZE_T size, DWORD allocation_type,
453 453
454// With g_phys_mutex held. Unmaps the page at `address` if one is mapped there; the address becomes a placeholder again. 454// With g_phys_mutex held. Unmaps the page at `address` if one is mapped there; the address becomes a placeholder again.
455bool unmap_page(uintptr_t address) { 455bool unmap_page(uintptr_t address) {
456 const FaultLockExclusive lock;
456 const auto it = g_mapped.find(address); 457 const auto it = g_mapped.find(address);
457 if (it == g_mapped.end()) return true; 458 if (it == g_mapped.end()) return true;
458 MappedPage mapped = std::move(it->second);
459 {
460 const FaultLockExclusive lock;
461 g_mapped.erase(it);
462 }
463 if (!placeholder_api().unmap_view2(GetCurrentProcess(), reinterpret_cast<void*>(address), 459 if (!placeholder_api().unmap_view2(GetCurrentProcess(), reinterpret_cast<void*>(address),
464 MEM_PRESERVE_PLACEHOLDER)) { 460 MEM_PRESERVE_PLACEHOLDER)) {
465 const FaultLockExclusive lock;
466 g_mapped.emplace(address, std::move(mapped));
467 return false; 461 return false;
468 } 462 }
463 g_mapped.erase(it);
469 return true; 464 return true;
470} 465}
471 466
@@ -481,11 +476,11 @@ bool map_page(uintptr_t address, uint64_t page, DWORD protect) {
481 } 476 }
482 void* const target = reinterpret_cast<void*>(address); 477 void* const target = reinterpret_cast<void*>(address);
483 if (!isolate_placeholder(target, kPhysicalPageSize)) return false; 478 if (!isolate_placeholder(target, kPhysicalPageSize)) return false;
479 const FaultLockExclusive lock;
484 void* const view = placeholder_api().map_view3(it->second.section->handle, GetCurrentProcess(), target, 480 void* const view = placeholder_api().map_view3(it->second.section->handle, GetCurrentProcess(), target,
485 it->second.offset, kPhysicalPageSize, MEM_REPLACE_PLACEHOLDER, 481 it->second.offset, kPhysicalPageSize, MEM_REPLACE_PLACEHOLDER,
486 protect, nullptr, 0); 482 protect, nullptr, 0);
487 if (!view) return false; 483 if (!view) return false;
488 const FaultLockExclusive lock;
489 g_mapped[address] = MappedPage{page, it->second.section, it->second.offset}; 484 g_mapped[address] = MappedPage{page, it->second.section, it->second.offset};
490 return true; 485 return true;
491} 486}