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>
|
2019-12-12 14:29:37 +00:00
|
|
|
|
|
|
|
namespace ams::kern {
|
|
|
|
|
|
|
|
NORETURN void Panic(const char *file, int line, const char *format, ...);
|
|
|
|
NORETURN void Panic();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef MESOSPHERE_ENABLE_DEBUG_PRINT
|
|
|
|
#define MESOSPHERE_PANIC(...) ams::kern::Panic(__FILE__, __LINE__, __VA_ARGS__)
|
|
|
|
#else
|
|
|
|
#define MESOSPHERE_PANIC(...) ams::kern::Panic()
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef MESOSPHERE_ENABLE_ASSERTIONS
|
|
|
|
#define MESOSPHERE_ASSERT_IMPL(expr, ...) \
|
|
|
|
({ \
|
2019-12-13 09:21:43 +00:00
|
|
|
if (AMS_UNLIKELY(!(expr))) { \
|
2019-12-12 14:29:37 +00:00
|
|
|
MESOSPHERE_PANIC(__VA_ARGS__); \
|
|
|
|
} \
|
|
|
|
})
|
|
|
|
#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
|
|
|
|
|
|
|
|
#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-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
|
|
|
|
|
2019-12-12 14:29:37 +00:00
|
|
|
#define MESOSPHERE_ABORT() MESOSPHERE_PANIC("Abort()");
|
2020-01-29 06:09:47 +00:00
|
|
|
#define MESOSPHERE_INIT_ABORT() do { /* ... */ } while (true)
|
2019-12-12 14:29:37 +00:00
|
|
|
|
|
|
|
#define MESOSPHERE_ABORT_UNLESS(expr) \
|
|
|
|
({ \
|
2020-01-29 06:09:47 +00:00
|
|
|
if (AMS_UNLIKELY(!(expr))) { \
|
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) \
|
|
|
|
({ \
|
|
|
|
if (AMS_UNLIKELY(!(expr))) { \
|
|
|
|
MESOSPHERE_INIT_ABORT(); \
|
|
|
|
} \
|
|
|
|
})
|