My Project
Loading...
Searching...
No Matches
assert.h
Go to the documentation of this file.
1
/*
2
* PROJECT: MatanelOS Kernel
3
* LICENSE: NONE
4
* PURPOSE: Runtime Assertion Implementation.
5
*/
6
7
#ifndef X86_ASSERT_H
8
#define X86_ASSERT_H
9
10
#ifdef DEBUG
11
#include <stddef.h>
12
#include <stdbool.h>
13
#include <stdint.h>
14
#include "
includes/me.h
"
15
#include "
includes/mg.h
"
16
17
__attribute__
((noreturn))
18
static
void
assert_fail(
const
char
* expr,
const
char
* reason,
const
char
* file,
const
char
* func,
int
line) {
19
// Getting here means a runtime assertion has failed (assert())
20
(void)(func);
21
22
// Check if expr is 0 or 1 (only) to make it true/false for readability.
23
if
(!
kstrcmp
(expr,
"0"
)) {
24
expr =
"false"
;
25
}
26
if
(!
kstrcmp
(expr,
"1"
)) {
27
expr =
"true"
;
28
}
29
30
// It can be versatile, with a reason or not.
31
if
(reason) {
32
MeBugCheckEx
(
ASSERTION_FAILURE
, (
void
*)expr, (
void
*)reason, (
void
*)file, (
void
*)(uintptr_t)line);
33
}
34
else
{
35
reason =
"NO_REASON_SPECIFIED"
;
36
MeBugCheckEx
(
ASSERTION_FAILURE
, (
void
*)expr, (
void
*)reason, (
void
*)file, (
void
*)(uintptr_t)line);
37
}
38
39
__builtin_unreachable();
40
}
41
42
// Helper macros for argument counting
43
#define GET_MACRO(_1,_2,NAME,...) NAME
44
45
// Base macros
46
#define ASSERT1(expr) \
47
((expr) ? (void)0 : assert_fail(#expr, NULL, __FILE__, __func__, __LINE__))
48
49
#define ASSERT2(expr, reason) \
50
((expr) ? (void)0 : assert_fail(#expr, reason, __FILE__, __func__, __LINE__))
51
52
// assert(expression) OR assert(expression, "expression must be true")
53
#define assert(...) GET_MACRO(__VA_ARGS__, ASSERT2, ASSERT1)(__VA_ARGS__)
54
55
#else
56
// assert(expression) OR assert(expression, "expression must be true")
57
#define assert(...) do { } while(0)
58
#endif
59
60
#endif
MeBugCheckEx
NORETURN void MeBugCheckEx(IN enum _BUGCHECK_CODES BugCheckCode, IN void *BugCheckParameter1, IN void *BugCheckParameter2, IN void *BugCheckParameter3, IN void *BugCheckParameter4)
Definition
bugcheck.c:305
kstrcmp
int kstrcmp(const char *s1, const char *s2)
Definition
gop.c:657
me.h
ASSERTION_FAILURE
@ ASSERTION_FAILURE
Definition
me.h:111
mg.h
__attribute__
typedef __attribute__
Definition
fat32.h:63
Users
matanel
Desktop
Projects
KernelDevelopment
kernel
assert.h
Generated by
1.14.0