aboutsummaryrefslogtreecommitdiff
path: root/libs/libc/inc/assert.h
diff options
context:
space:
mode:
Diffstat (limited to 'libs/libc/inc/assert.h')
-rw-r--r--libs/libc/inc/assert.h28
1 files changed, 28 insertions, 0 deletions
diff --git a/libs/libc/inc/assert.h b/libs/libc/inc/assert.h
new file mode 100644
index 0000000..3656c33
--- /dev/null
+++ b/libs/libc/inc/assert.h
@@ -0,0 +1,28 @@
+// MIT License, Copyright (c) 2020 Marvin Borner
+
+#ifndef ASSERT_H
+#define ASSERT_H
+
+#include <print.h>
+
+#ifdef kernel
+#include <proc.h>
+#define assert(exp) \
+ if (!(exp)) { \
+ printf("%s:%d: %s: Kernel assertion '%s' failed\n", __FILE__, __LINE__, __func__, \
+ #exp); \
+ struct proc *assert_proc = proc_current(); \
+ if (assert_proc) \
+ proc_exit(assert_proc, 1); \
+ else \
+ __asm__ volatile("cli\nhlt"); \
+ }
+#elif defined(userspace)
+#define assert(exp) \
+ if (!(exp)) \
+ err(1, "%s:%d: %s: Assertion '%s' failed\n", __FILE__, __LINE__, __func__, #exp);
+#else
+#error "No lib target specified. Please use -Dkernel or -Duserspace"
+#endif
+
+#endif