diff --git a/Utilities/Thread.cpp b/Utilities/Thread.cpp index b48ef55715..5bc5d61181 100644 --- a/Utilities/Thread.cpp +++ b/Utilities/Thread.cpp @@ -2283,7 +2283,7 @@ std::string named_thread::get_name() const void named_thread::start_thread(const std::shared_ptr& _this) { // Ensure it's not called from the constructor and the correct object is passed - ENSURES(_this.get() == this); + verify("named_thread::start_thread" HERE), _this.get() == this; // Run thread thread_ctrl::spawn(m_thread, get_name(), [this, _this]() diff --git a/Utilities/VirtualMemory.cpp b/Utilities/VirtualMemory.cpp index f3fb78af3f..0dd7b6c3bd 100644 --- a/Utilities/VirtualMemory.cpp +++ b/Utilities/VirtualMemory.cpp @@ -16,30 +16,27 @@ namespace memory_helper void* reserve_memory(size_t size) { #ifdef _WIN32 - void* ret = VirtualAlloc(NULL, size, MEM_RESERVE, PAGE_NOACCESS); - ENSURES(ret != NULL); + return verify(VirtualAlloc(NULL, size, MEM_RESERVE, PAGE_NOACCESS), "reserve_memory" HERE); #else - void* ret = mmap(nullptr, size, PROT_NONE, MAP_ANON | MAP_PRIVATE, -1, 0); - ENSURES(ret != 0); + return verify(::mmap(nullptr, size, PROT_NONE, MAP_ANON | MAP_PRIVATE, -1, 0), "reserve_memory" HERE); #endif - return ret; } void commit_page_memory(void* pointer, size_t size) { #ifdef _WIN32 - VERIFY(VirtualAlloc(pointer, size, MEM_COMMIT, PAGE_READWRITE) != NULL); + verify(HERE), VirtualAlloc(pointer, size, MEM_COMMIT, PAGE_READWRITE); #else - VERIFY(mprotect((void*)((u64)pointer & -4096), size, PROT_READ | PROT_WRITE) != -1); + verify(HERE), ::mprotect((void*)((u64)pointer & -4096), size, PROT_READ | PROT_WRITE) != -1; #endif } void free_reserved_memory(void* pointer, size_t size) { #ifdef _WIN32 - VERIFY(VirtualFree(pointer, 0, MEM_DECOMMIT) != 0); + verify(HERE), VirtualFree(pointer, 0, MEM_DECOMMIT); #else - VERIFY(mprotect(pointer, size, PROT_NONE) != -1); + verify(HERE), ::mprotect(pointer, size, PROT_NONE) != -1; #endif } } diff --git a/Utilities/types.h b/Utilities/types.h index ea83a3f90f..27c4acaf58 100644 --- a/Utilities/types.h +++ b/Utilities/types.h @@ -58,14 +58,12 @@ #define HERE "\n(in file " __FILE__ ":" STRINGIZE(__LINE__) ")" -// Wrap an expression into lambda +// Wrap an expression into lambda. Obsolete. #define WRAP_EXPR(...) [&] { return __VA_ARGS__; } -// Ensure that the expression is evaluated to true. Always evaluated and allowed to have side effects (unlike assert() macro). +// Ensure that the expression is evaluated to true. Obsolete. #define VERIFY(...) do { if (!(__VA_ARGS__)) fmt::raw_error("Verification failed: " #__VA_ARGS__ HERE); } while (0) -// EXPECTS() and ENSURES() are intended to check function arguments and results. -// Expressions are not guaranteed to evaluate. #define EXPECTS(...) do { if (!(__VA_ARGS__)) fmt::raw_error("Precondition failed: " #__VA_ARGS__ HERE); } while (0) #define ENSURES(...) do { if (!(__VA_ARGS__)) fmt::raw_error("Postcondition failed: " #__VA_ARGS__ HERE); } while (0) diff --git a/rpcs3/Emu/Cell/SPUThread.cpp b/rpcs3/Emu/Cell/SPUThread.cpp index 8df2900ca8..f5f07c21a7 100644 --- a/rpcs3/Emu/Cell/SPUThread.cpp +++ b/rpcs3/Emu/Cell/SPUThread.cpp @@ -249,9 +249,8 @@ SPUThread::SPUThread(const std::string& name, u32 index) : cpu_thread() , m_name(name) , index(index) - , offset(vm::alloc(0x40000, vm::main)) + , offset(verify(vm::alloc(0x40000, vm::main), __func__)) { - ENSURES(offset); } void SPUThread::push_snr(u32 number, u32 value) diff --git a/rpcs3/Emu/Cell/lv2/sys_event.cpp b/rpcs3/Emu/Cell/lv2/sys_event.cpp index c3290c639a..6fc46359e2 100644 --- a/rpcs3/Emu/Cell/lv2/sys_event.cpp +++ b/rpcs3/Emu/Cell/lv2/sys_event.cpp @@ -276,7 +276,6 @@ s32 sys_event_queue_receive(ppu_thread& ppu, u32 equeue_id, vm::ptr if (ppu.gpr[3]) { - ENSURES(!idm::check(equeue_id)); return CELL_ECANCELED; } diff --git a/rpcs3/Emu/RSX/CgBinaryFragmentProgram.cpp b/rpcs3/Emu/RSX/CgBinaryFragmentProgram.cpp index 14c969b960..4973a478c1 100644 --- a/rpcs3/Emu/RSX/CgBinaryFragmentProgram.cpp +++ b/rpcs3/Emu/RSX/CgBinaryFragmentProgram.cpp @@ -473,7 +473,7 @@ void CgBinaryDisasm::TaskFP() break; } - ENSURES(m_step % sizeof(u32) == 0); + verify(HERE), m_step % sizeof(u32) == 0; data += m_step / sizeof(u32); } } diff --git a/rpcs3/Emu/RSX/CgBinaryProgram.h b/rpcs3/Emu/RSX/CgBinaryProgram.h index 0b1752347c..117d407737 100644 --- a/rpcs3/Emu/RSX/CgBinaryProgram.h +++ b/rpcs3/Emu/RSX/CgBinaryProgram.h @@ -373,7 +373,7 @@ public: m_offset = prog.ucode; u32* vdata = (u32*)&m_buffer[m_offset]; - ENSURES((m_buffer_size - m_offset) % sizeof(u32) == 0); + verify(HERE), (m_buffer_size - m_offset) % sizeof(u32) == 0; for (u32 i = 0; i < (m_buffer_size - m_offset) / sizeof(u32); i++) { vdata[i] = se_storage::swap(vdata[i]); // WTF, cannot use be_t<> there? @@ -394,4 +394,4 @@ public: u32 GetData(const u32 d) const { return d << 16 | d >> 16; } void TaskFP(); void TaskVP(); -}; \ No newline at end of file +}; diff --git a/rpcs3/Emu/RSX/Common/FragmentProgramDecompiler.cpp b/rpcs3/Emu/RSX/Common/FragmentProgramDecompiler.cpp index b104e09db7..ce31da3d7f 100644 --- a/rpcs3/Emu/RSX/Common/FragmentProgramDecompiler.cpp +++ b/rpcs3/Emu/RSX/Common/FragmentProgramDecompiler.cpp @@ -662,7 +662,7 @@ std::string FragmentProgramDecompiler::Decompile() if (dst.end) break; - ENSURES(m_offset % sizeof(u32) == 0); + verify(HERE), m_offset % sizeof(u32) == 0; data += m_offset / sizeof(u32); } diff --git a/rpcs3/Emu/RSX/D3D12/D3D12GSRender.cpp b/rpcs3/Emu/RSX/D3D12/D3D12GSRender.cpp index 2ebf9269ed..48c3752719 100644 --- a/rpcs3/Emu/RSX/D3D12/D3D12GSRender.cpp +++ b/rpcs3/Emu/RSX/D3D12/D3D12GSRender.cpp @@ -44,13 +44,13 @@ HMODULE D3DCompiler; void loadD3D12FunctionPointers() { - VERIFY(D3D12Module = LoadLibrary(L"d3d12.dll")); + D3D12Module = verify(LoadLibrary(L"d3d12.dll"), "d3d12.dll"); wrapD3D12CreateDevice = (PFN_D3D12_CREATE_DEVICE)GetProcAddress(D3D12Module, "D3D12CreateDevice"); wrapD3D12GetDebugInterface = (PFN_D3D12_GET_DEBUG_INTERFACE)GetProcAddress(D3D12Module, "D3D12GetDebugInterface"); wrapD3D12SerializeRootSignature = (PFN_D3D12_SERIALIZE_ROOT_SIGNATURE)GetProcAddress(D3D12Module, "D3D12SerializeRootSignature"); - VERIFY(D3D11Module = LoadLibrary(L"d3d11.dll")); + D3D11Module = verify(LoadLibrary(L"d3d11.dll"), "d3d11.dll"); wrapD3D11On12CreateDevice = (PFN_D3D11ON12_CREATE_DEVICE)GetProcAddress(D3D11Module, "D3D11On12CreateDevice"); - VERIFY(D3DCompiler = LoadLibrary(L"d3dcompiler_47.dll")); + D3DCompiler = verify(LoadLibrary(L"d3dcompiler_47.dll"), "d3dcompiler_47.dll"); wrapD3DCompile = (pD3DCompile)GetProcAddress(D3DCompiler, "D3DCompile"); }