Atmosphere/libraries/libmesosphere/include/mesosphere/kern_panic.hpp

81 lines
3.6 KiB
C++
Raw Normal View History

/*
* Copyright (c) 2018-2020 Atmosphère-NX
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <mesosphere/kern_common.hpp>
2020-02-06 04:05:35 -05:00
#include <mesosphere/kern_debug_log.hpp>
namespace ams::kern {
2020-02-07 09:26:01 -05:00
NORETURN void Panic(const char *file, int line, const char *format, ...) __attribute__((format(printf, 3, 4)));
NORETURN void Panic();
}
#ifdef MESOSPHERE_ENABLE_DEBUG_PRINT
2020-02-08 05:49:32 -05:00
#define MESOSPHERE_PANIC(...) ::ams::kern::Panic(__FILE__, __LINE__, __VA_ARGS__)
#else
2020-02-08 05:49:32 -05:00
#define MESOSPHERE_PANIC(...) ::ams::kern::Panic()
#endif
#ifdef MESOSPHERE_ENABLE_ASSERTIONS
2020-02-07 09:26:01 -05:00
#define MESOSPHERE_ASSERT_IMPL(expr, ...) \
({ \
const bool __tmp_meso_assert_val = (expr); \
if (AMS_UNLIKELY(!__tmp_meso_assert_val)) { \
MESOSPHERE_PANIC(__VA_ARGS__); \
} \
})
#else
#define MESOSPHERE_ASSERT_IMPL(expr, ...) do { static_cast<void>(expr); } while (0)
#endif
#define MESOSPHERE_ASSERT(expr) MESOSPHERE_ASSERT_IMPL(expr, "Assertion failed: %s", #expr)
#define MESOSPHERE_R_ASSERT(expr) MESOSPHERE_ASSERT_IMPL(R_SUCCEEDED(expr), "Result assertion failed: %s", #expr)
2020-02-06 20:40:57 -05:00
#define MESOSPHERE_UNREACHABLE_DEFAULT_CASE() default: MESOSPHERE_PANIC("Unreachable default case entered")
#ifdef MESOSPHERE_ENABLE_THIS_ASSERT
#define MESOSPHERE_ASSERT_THIS() MESOSPHERE_ASSERT(this != nullptr)
#else
#define MESOSPHERE_ASSERT_THIS()
#endif
#define MESOSPHERE_ABORT() MESOSPHERE_PANIC("Abort()");
#define MESOSPHERE_INIT_ABORT() do { /* ... */ } while (true)
#define MESOSPHERE_ABORT_UNLESS(expr) \
({ \
2020-02-07 09:26:01 -05:00
const bool _tmp_meso_assert_val = (expr); \
if (AMS_UNLIKELY(!_tmp_meso_assert_val)) { \
MESOSPHERE_PANIC("Abort(): %s", #expr); \
} \
})
#define MESOSPHERE_INIT_ABORT_UNLESS(expr) \
({ \
2020-02-07 09:26:01 -05:00
const bool __tmp_meso_assert_val = (expr); \
if (AMS_UNLIKELY(!__tmp_meso_assert_val)) { \
MESOSPHERE_INIT_ABORT(); \
} \
})
2020-01-30 19:51:35 -05:00
#define MESOSPHERE_R_ABORT_UNLESS(expr) \
({ \
2020-02-06 08:34:38 -05:00
const ::ams::Result _tmp_meso_r_abort_res = static_cast<::ams::Result>((expr)); \
if (AMS_UNLIKELY((R_FAILED(_tmp_meso_r_abort_res)))) { \
2020-01-30 19:51:35 -05:00
MESOSPHERE_PANIC("Result Abort(): %s 2%03d-%04d", #expr, _tmp_meso_r_abort_res.GetModule(), _tmp_meso_r_abort_res.GetDescription()); \
} \
})