From 915aa572c0e64eda99b3ea442c15caf0b1ba8e12 Mon Sep 17 00:00:00 2001 From: Megamouse Date: Sat, 28 Dec 2024 22:24:33 +0100 Subject: [PATCH] Fix idm remove idm remove calls shared_ptr::exchange with a null_ptr. This calls the stored object's constructor with null args. Let's just add an exchange overload for null_ptr --- rpcs3/Emu/NP/np_contexts.cpp | 4 ++-- rpcs3/Emu/NP/np_contexts.h | 4 ++-- rpcs3/util/shared_ptr.hpp | 14 ++++++++++++++ 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/rpcs3/Emu/NP/np_contexts.cpp b/rpcs3/Emu/NP/np_contexts.cpp index cd9a11f28d..e448a3f56c 100644 --- a/rpcs3/Emu/NP/np_contexts.cpp +++ b/rpcs3/Emu/NP/np_contexts.cpp @@ -238,7 +238,7 @@ matching_ctx::matching_ctx(vm::ptr npId, vm::ptr this->handler = handler; this->arg = arg; } -void matching_ctx::queue_callback(u32 req_id, s32 event, s32 error_code) +void matching_ctx::queue_callback(u32 req_id, s32 event, s32 error_code) const { if (handler) { @@ -249,7 +249,7 @@ void matching_ctx::queue_callback(u32 req_id, s32 event, s32 error_code) }); } } -void matching_ctx::queue_gui_callback(s32 event, s32 error_code) +void matching_ctx::queue_gui_callback(s32 event, s32 error_code) const { if (gui_handler) { diff --git a/rpcs3/Emu/NP/np_contexts.h b/rpcs3/Emu/NP/np_contexts.h index cf11098dd8..d82410c0a2 100644 --- a/rpcs3/Emu/NP/np_contexts.h +++ b/rpcs3/Emu/NP/np_contexts.h @@ -289,8 +289,8 @@ struct matching_ctx { matching_ctx(vm::ptr npid, vm::ptr handler, vm::ptr arg); - void queue_callback(u32 req_id, s32 event, s32 error_code); - void queue_gui_callback(s32 event, s32 error_code); + void queue_callback(u32 req_id, s32 event, s32 error_code) const; + void queue_gui_callback(s32 event, s32 error_code) const; static const u32 id_base = 0x9001; static const u32 id_step = 1; diff --git a/rpcs3/util/shared_ptr.hpp b/rpcs3/util/shared_ptr.hpp index 06f1d2a380..5488cd4cec 100644 --- a/rpcs3/util/shared_ptr.hpp +++ b/rpcs3/util/shared_ptr.hpp @@ -895,6 +895,8 @@ namespace stx return value; } + [[nodiscard]] shared_type exchange(struct null_ptr_t) noexcept; + // Ineffective [[nodiscard]] bool compare_exchange(shared_type& cmp_and_old, shared_type exch) { @@ -1141,6 +1143,18 @@ namespace stx } } null_ptr; + + template + atomic_ptr::shared_type atomic_ptr::exchange(null_ptr_t) noexcept + { + atomic_ptr old; + old.m_val.raw() = m_val.exchange(0); + old.m_val.raw() += 1; + + shared_type result; + result.m_ptr = std::launder(ptr_to(old.m_val)); + return result; + } } template