2019-12-12 14:29:37 +00:00
|
|
|
/*
|
2020-01-24 10:10:40 +00:00
|
|
|
* Copyright (c) 2018-2020 Atmosphère-NX
|
2019-12-12 14:29:37 +00:00
|
|
|
*
|
|
|
|
* 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
|
2020-01-30 23:29:51 +00:00
|
|
|
#include <mesosphere/kern_common.hpp>
|
2020-02-06 09:05:35 +00:00
|
|
|
#include <mesosphere/kern_debug_log.hpp>
|
2019-12-12 14:29:37 +00:00
|
|
|
|
|
|
|
namespace ams::kern {
|
|
|
|
|
2020-02-20 18:14:27 +00:00
|
|
|
template<typename... ArgTypes>
|
2020-07-11 03:09:06 +00:00
|
|
|
ALWAYS_INLINE void UnusedImpl(ArgTypes &&... args) {
|
2020-02-20 18:14:27 +00:00
|
|
|
(static_cast<void>(args), ...);
|
|
|
|
}
|
|
|
|
|
|
|
|
NORETURN NOINLINE void Panic(const char *file, int line, const char *format, ...) __attribute__((format(printf, 3, 4)));
|
|
|
|
NORETURN NOINLINE void Panic();
|
2019-12-12 14:29:37 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-02-20 18:14:27 +00:00
|
|
|
#define MESOSPHERE_UNUSED(...) ::ams::kern::UnusedImpl(__VA_ARGS__)
|
|
|
|
|
2019-12-12 14:29:37 +00:00
|
|
|
#ifdef MESOSPHERE_ENABLE_DEBUG_PRINT
|
2020-03-10 06:23:38 +00:00
|
|
|
#define MESOSPHERE_PANIC(...) do { ::ams::kern::Panic(__FILE__, __LINE__, ## __VA_ARGS__); } while(0)
|
2019-12-12 14:29:37 +00:00
|
|
|
#else
|
2020-02-20 18:14:27 +00:00
|
|
|
#define MESOSPHERE_PANIC(...) do { MESOSPHERE_UNUSED(__VA_ARGS__); ::ams::kern::Panic(); } while(0)
|
2019-12-12 14:29:37 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef MESOSPHERE_ENABLE_ASSERTIONS
|
2020-02-07 14:26:01 +00:00
|
|
|
#define MESOSPHERE_ASSERT_IMPL(expr, ...) \
|
|
|
|
({ \
|
|
|
|
const bool __tmp_meso_assert_val = (expr); \
|
|
|
|
if (AMS_UNLIKELY(!__tmp_meso_assert_val)) { \
|
|
|
|
MESOSPHERE_PANIC(__VA_ARGS__); \
|
|
|
|
} \
|
2019-12-12 14:29:37 +00:00
|
|
|
})
|
|
|
|
#else
|
2020-01-30 23:29:51 +00:00
|
|
|
#define MESOSPHERE_ASSERT_IMPL(expr, ...) do { static_cast<void>(expr); } while (0)
|
2019-12-12 14:29:37 +00:00
|
|
|
#endif
|
|
|
|
|
2020-02-14 06:05:20 +00:00
|
|
|
#define MESOSPHERE_ASSERT(expr) MESOSPHERE_ASSERT_IMPL(expr, "Assertion failed: %s\n", #expr)
|
|
|
|
#define MESOSPHERE_R_ASSERT(expr) MESOSPHERE_ASSERT_IMPL(R_SUCCEEDED(expr), "Result assertion failed: %s\n", #expr)
|
2020-02-07 01:40:57 +00:00
|
|
|
#define MESOSPHERE_UNREACHABLE_DEFAULT_CASE() default: MESOSPHERE_PANIC("Unreachable default case entered")
|
2019-12-12 14:29:37 +00:00
|
|
|
|
2020-01-30 23:29:51 +00:00
|
|
|
#ifdef MESOSPHERE_ENABLE_THIS_ASSERT
|
|
|
|
#define MESOSPHERE_ASSERT_THIS() MESOSPHERE_ASSERT(this != nullptr)
|
|
|
|
#else
|
|
|
|
#define MESOSPHERE_ASSERT_THIS()
|
|
|
|
#endif
|
|
|
|
|
2020-02-10 09:50:23 +00:00
|
|
|
#ifdef MESOSPHERE_BUILD_FOR_AUDITING
|
|
|
|
#define MESOSPHERE_AUDIT(expr) MESOSPHERE_ASSERT(expr)
|
|
|
|
#else
|
|
|
|
#define MESOSPHERE_AUDIT(expr) do { static_cast<void>(expr); } while (0)
|
|
|
|
#endif
|
|
|
|
|
2020-02-20 18:14:27 +00:00
|
|
|
#define MESOSPHERE_TODO(arg) ({ constexpr const char *__mesosphere_todo = arg; static_cast<void>(__mesosphere_todo); MESOSPHERE_PANIC("TODO (%s): %s\n", __PRETTY_FUNCTION__, __mesosphere_todo); })
|
2020-02-22 13:42:46 +00:00
|
|
|
#define MESOSPHERE_UNIMPLEMENTED() MESOSPHERE_PANIC("%s: Unimplemented\n", __PRETTY_FUNCTION__)
|
2020-02-08 11:18:08 +00:00
|
|
|
|
2020-02-14 06:05:20 +00:00
|
|
|
#define MESOSPHERE_ABORT() MESOSPHERE_PANIC("Abort()\n");
|
2020-08-14 00:28:29 +00:00
|
|
|
#define MESOSPHERE_INIT_ABORT() AMS_INFINITE_LOOP()
|
2019-12-12 14:29:37 +00:00
|
|
|
|
|
|
|
#define MESOSPHERE_ABORT_UNLESS(expr) \
|
|
|
|
({ \
|
2020-02-07 14:26:01 +00:00
|
|
|
const bool _tmp_meso_assert_val = (expr); \
|
|
|
|
if (AMS_UNLIKELY(!_tmp_meso_assert_val)) { \
|
2019-12-12 14:29:37 +00:00
|
|
|
MESOSPHERE_PANIC("Abort(): %s", #expr); \
|
|
|
|
} \
|
|
|
|
})
|
2020-01-29 06:09:47 +00:00
|
|
|
|
|
|
|
#define MESOSPHERE_INIT_ABORT_UNLESS(expr) \
|
|
|
|
({ \
|
2020-02-07 14:26:01 +00:00
|
|
|
const bool __tmp_meso_assert_val = (expr); \
|
|
|
|
if (AMS_UNLIKELY(!__tmp_meso_assert_val)) { \
|
2020-01-29 06:09:47 +00:00
|
|
|
MESOSPHERE_INIT_ABORT(); \
|
|
|
|
} \
|
|
|
|
})
|
2020-01-31 00:51:35 +00:00
|
|
|
|
2020-02-14 06:05:20 +00:00
|
|
|
#define MESOSPHERE_R_ABORT_UNLESS(expr) \
|
|
|
|
({ \
|
|
|
|
const ::ams::Result _tmp_meso_r_abort_res = static_cast<::ams::Result>((expr)); \
|
|
|
|
if (AMS_UNLIKELY((R_FAILED(_tmp_meso_r_abort_res)))) { \
|
|
|
|
MESOSPHERE_PANIC("Result Abort(): %s 2%03d-%04d\n", #expr, _tmp_meso_r_abort_res.GetModule(), _tmp_meso_r_abort_res.GetDescription()); \
|
|
|
|
} \
|
2020-01-31 00:51:35 +00:00
|
|
|
})
|