upleb.uk

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

summaryrefslogtreecommitdiff
path: root/runtime/shims/registry.cpp
diff options
context:
space:
mode:
authorKhuraie <83483964+Khuraie@users.noreply.github.com>2026-11-23 23:42:39 +0800
committerMumogg <104529023+Mumogg@users.noreply.github.com>2026-11-24 03:47:22 -0600
commit522faa2ee4ad77b00d11057543497f9e31c3ff05 (patch)
tree548eda8cf594a5889b7cf861f8820acd5e6356b0 /runtime/shims/registry.cpp
parentd7576d56ae2c77564c84ffae724ffe9bdd2e6701 (diff)
d3d12_xs: honour __XMemAllocationHooks__ for descriptor heaps and translate CPU handles
(cherry picked from commit 355201c51e6aba95c582e2df344782b22e97bb31)
Diffstat (limited to 'runtime/shims/registry.cpp')
-rw-r--r--runtime/shims/registry.cpp39
1 files changed, 39 insertions, 0 deletions
diff --git a/runtime/shims/registry.cpp b/runtime/shims/registry.cpp
index 6ec36e31c..c0d826e31 100644
--- a/runtime/shims/registry.cpp
+++ b/runtime/shims/registry.cpp
@@ -390,6 +390,11 @@ struct BundledLoaderEntry {
390 const BundledModuleOps* ops; 390 const BundledModuleOps* ops;
391}; 391};
392 392
393struct XMemHooksEntry {
394 const void* owner;
395 const XMemAllocationHooks* hooks;
396};
397
393// Immortal: late mapped-DLL detach or atexit handlers may call GetProcAddress/FreeLibrary during process teardown. 398// Immortal: late mapped-DLL detach or atexit handlers may call GetProcAddress/FreeLibrary during process teardown.
394std::mutex& bundled_loader_mutex() { 399std::mutex& bundled_loader_mutex() {
395 static auto* m = new std::mutex; 400 static auto* m = new std::mutex;
@@ -401,6 +406,16 @@ std::vector<BundledLoaderEntry>& bundled_loaders() {
401 return *v; 406 return *v;
402} 407}
403 408
409std::mutex& xmem_hooks_mutex() {
410 static auto* m = new std::mutex;
411 return *m;
412}
413
414std::vector<XMemHooksEntry>& xmem_hooks_entries() {
415 static auto* v = new std::vector<XMemHooksEntry>;
416 return *v;
417}
418
404std::vector<BundledLoaderEntry> snapshot_bundled_loaders() { 419std::vector<BundledLoaderEntry> snapshot_bundled_loaders() {
405 std::lock_guard lock(bundled_loader_mutex()); 420 std::lock_guard lock(bundled_loader_mutex());
406 return bundled_loaders(); 421 return bundled_loaders();
@@ -483,6 +498,30 @@ bool owns_bundled_module_handle(void* module) {
483 return false; 498 return false;
484} 499}
485 500
501void add_xmem_allocation_hooks(const void* owner, const XMemAllocationHooks* hooks) {
502 if (!owner || !hooks) return;
503 std::lock_guard lock(xmem_hooks_mutex());
504 xmem_hooks_entries().push_back({owner, hooks});
505}
506
507void remove_xmem_allocation_hooks(const void* owner) {
508 std::lock_guard lock(xmem_hooks_mutex());
509 auto& list = xmem_hooks_entries();
510 for (auto it = list.begin(); it != list.end();) {
511 if (it->owner == owner) {
512 it = list.erase(it);
513 } else {
514 ++it;
515 }
516 }
517}
518
519const XMemAllocationHooks* xmem_allocation_hooks() {
520 std::lock_guard lock(xmem_hooks_mutex());
521 const auto& list = xmem_hooks_entries();
522 return list.empty() ? nullptr : list.back().hooks;
523}
524
486Table::Table(const Entry* entries, size_t count) { 525Table::Table(const Entry* entries, size_t count) {
487 for (size_t i = 0; i < count; ++i) table()[lower_ascii(entries[i].dll) + "!" + entries[i].name] = entries[i].fn; 526 for (size_t i = 0; i < count; ++i) table()[lower_ascii(entries[i].dll) + "!" + entries[i].name] = entries[i].fn;
488} 527}