Browse Source

[common] Do not expose platform specific Crash() macro that is only used ever once (#2909)

thing is only ever used once and its also platform specific... uh

Signed-off-by: lizzie <lizzie@eden-emu.dev>

Reviewed-on: https://git.eden-emu.dev/eden-emu/eden/pulls/2909
Reviewed-by: crueter <crueter@eden-emu.dev>
Reviewed-by: Shinmegumi <shinmegumi@eden-emu.dev>
Reviewed-by: MaranBr <maranbr@eden-emu.dev>
Reviewed-by: Caio Oliveira <caiooliveirafarias0@gmail.com>
Co-authored-by: lizzie <lizzie@eden-emu.dev>
Co-committed-by: lizzie <lizzie@eden-emu.dev>
pull/2948/head
lizzie 2 months ago
committed by crueter
parent
commit
8a7fe32a2c
No known key found for this signature in database GPG Key ID: 425ACD2D4830EBC6
  1. 28
      src/common/assert.cpp
  2. 23
      src/common/assert.h
  3. 24
      src/common/common_funcs.h

28
src/common/assert.cpp

@ -1,21 +1,35 @@
// SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project
// SPDX-License-Identifier: GPL-3.0-or-later
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#include "common/assert.h"
#include "common/common_funcs.h"
#include "common/logging/backend.h"
#include "common/settings.h"
void assert_fail_impl() {
#ifdef _MSC_VER
extern "C" {
__declspec(dllimport) void __stdcall DebugBreak(void);
}
#endif
void AssertFailSoftImpl() {
if (Settings::values.use_debug_asserts) {
Common::Log::Stop();
Crash();
#ifndef _MSC_VER
# if defined(ARCHITECTURE_x86_64)
__asm__ __volatile__("int $3");
# elif defined(ARCHITECTURE_arm64)
__asm__ __volatile__("brk #0");
# else
exit(1);
# endif
#else // POSIX ^^^ _MSC_VER vvv
DebugBreak();
#endif
}
}
[[noreturn]] void unreachable_impl() {
void AssertFatalImpl() {
Common::Log::Stop();
Crash();
throw std::runtime_error("Unreachable code");
std::abort();
}

23
src/common/assert.h

@ -1,3 +1,6 @@
// SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project
// SPDX-License-Identifier: GPL-3.0-or-later
// SPDX-FileCopyrightText: 2013 Dolphin Emulator Project
// SPDX-FileCopyrightText: 2014 Citra Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
@ -10,8 +13,8 @@
// However touching this file yields a global recompilation as this header is included almost
// everywhere. So let's just move the handling of the failed assert to a single cpp file.
void assert_fail_impl();
[[noreturn]] void unreachable_impl();
void AssertFailSoftImpl();
[[noreturn]] void AssertFatalImpl();
#ifdef _MSC_VER
#define YUZU_NO_INLINE __declspec(noinline)
@ -22,29 +25,29 @@ void assert_fail_impl();
#define ASSERT(_a_) \
([&]() YUZU_NO_INLINE { \
if (!(_a_)) [[unlikely]] { \
LOG_CRITICAL(Debug, "Assertion Failed!"); \
assert_fail_impl(); \
LOG_CRITICAL(Debug, "Assert"); \
AssertFailSoftImpl(); \
} \
}())
#define ASSERT_MSG(_a_, ...) \
([&]() YUZU_NO_INLINE { \
if (!(_a_)) [[unlikely]] { \
LOG_CRITICAL(Debug, "Assertion Failed!\n" __VA_ARGS__); \
assert_fail_impl(); \
LOG_CRITICAL(Debug, "Assert\n" __VA_ARGS__); \
AssertFailSoftImpl(); \
} \
}())
#define UNREACHABLE() \
do { \
LOG_CRITICAL(Debug, "Unreachable code!"); \
unreachable_impl(); \
LOG_CRITICAL(Debug, "Unreachable"); \
AssertFatalImpl(); \
} while (0)
#define UNREACHABLE_MSG(...) \
do { \
LOG_CRITICAL(Debug, "Unreachable code!\n" __VA_ARGS__); \
unreachable_impl(); \
LOG_CRITICAL(Debug, "Unreachable\n" __VA_ARGS__); \
AssertFatalImpl(); \
} while (0)
#ifdef _DEBUG

24
src/common/common_funcs.h

@ -32,27 +32,9 @@
#define INSERT_PADDING_WORDS_NOINIT(num_words) \
[[maybe_unused]] std::array<u32, num_words> CONCAT2(pad, __LINE__)
#ifndef _MSC_VER
#if defined(ARCHITECTURE_x86_64)
#define Crash() __asm__ __volatile__("int $3")
#elif defined(ARCHITECTURE_arm64)
#define Crash() __asm__ __volatile__("brk #0")
#else
#define Crash() exit(1)
#endif
#else // _MSC_VER
// Locale Cross-Compatibility
#define locale_t _locale_t
extern "C" {
__declspec(dllimport) void __stdcall DebugBreak(void);
}
#define Crash() DebugBreak()
#endif // _MSC_VER ndef
#ifdef _MSC_VER
# define locale_t _locale_t // Locale Cross-Compatibility
#endif // _MSC_VER
#define DECLARE_ENUM_FLAG_OPERATORS(type) \
[[nodiscard]] constexpr type operator|(type a, type b) noexcept { \

Loading…
Cancel
Save