| 1 | // SPDX-License-Identifier: GPL-3.0-or-later |
| 2 | // Preamble for MOS standard library headers. |
| 3 | |
| 4 | #pragma once |
| 5 | |
| 6 | #include <mos/types.h> |
| 7 | |
| 8 | /** |
| 9 | * @defgroup libs MOS Libraries |
| 10 | * @brief A platform-independent library of useful data structures and functions. |
| 11 | * @{ |
| 12 | */ |
| 13 | |
| 14 | #define MOS_LIB_ASSERT(cond) MOS_LIB_ASSERT_X(cond, "") |
| 15 | |
| 16 | #ifdef __MOS_KERNEL__ // ! Kernel |
| 17 | |
| 18 | #include "mos/assert.hpp" |
| 19 | |
| 20 | #define MOS_LIB_ASSERT_X(cond, msg, ...) MOS_ASSERT_X(cond, "" msg, ##__VA_ARGS__) |
| 21 | #define MOS_LIB_UNIMPLEMENTED(content) MOS_UNIMPLEMENTED(content) |
| 22 | #define MOS_LIB_UNREACHABLE() MOS_UNREACHABLE() |
| 23 | |
| 24 | #else // ! Userspace |
| 25 | |
| 26 | #include <mos/platform_syscall.h> |
| 27 | #include <mos/syscall/usermode.h> |
| 28 | |
| 29 | #define MOS_LIB_ASSERT_X(cond, msg, ...) \ |
| 30 | do \ |
| 31 | { \ |
| 32 | if (unlikely(!(cond))) \ |
| 33 | fatal_abort("Assertion failed: '%s', " msg "\n", #cond, ##__VA_ARGS__); \ |
| 34 | } while (0) |
| 35 | |
| 36 | MOSAPI void __printf(1, 2) fatal_abort(const char *fmt, ...); |
| 37 | |
| 38 | #define MOS_LIB_UNIMPLEMENTED(content) fatal_abort("Unimplemented: %s", content) |
| 39 | #define MOS_LIB_UNREACHABLE() fatal_abort("Unreachable code reached") |
| 40 | #define mos_panic(fmt, ...) fatal_abort(fmt "\n", ##__VA_ARGS__) |
| 41 | #define mos_warn(fmt, ...) fprintf(stderr, "WARN: " fmt "\n", ##__VA_ARGS__) |
| 42 | #endif |
| 43 | |
| 44 | /** @} */ |
| 45 | |