summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/kernel/assert.c9
-rw-r--r--src/kernel/panic.h4
-rw-r--r--src/shared/fsutil.c4
-rw-r--r--src/shared/include/assert.h3
-rw-r--r--src/shared/path.c4
-rw-r--r--src/user/lib/assert.c8
6 files changed, 23 insertions, 9 deletions
diff --git a/src/kernel/assert.c b/src/kernel/assert.c
new file mode 100644
index 0000000..9bd1107
--- /dev/null
+++ b/src/kernel/assert.c
@@ -0,0 +1,9 @@
+#include <assert.h>
+#include <kernel/arch/generic.h>
+
+_Noreturn void __badassert(const char *func, const char *file, int line) {
+ /* same format as panics */
+ kprintf("\nan assert PANIC! at the %s (%s:%u)\n", func, file, line);
+ debug_stacktrace();
+ cpu_halt();
+}
diff --git a/src/kernel/panic.h b/src/kernel/panic.h
index 4e591f1..12c0d64 100644
--- a/src/kernel/panic.h
+++ b/src/kernel/panic.h
@@ -1,4 +1,5 @@
#pragma once
+#include <assert.h>
#include <kernel/arch/generic.h>
#include <kernel/util.h>
@@ -12,6 +13,3 @@
#define panic_invalid_state() _panic("invalid state")
#define panic_unimplemented() _panic("unimplemented")
-#define assert(stmt) do { if (!(stmt)) _panic("assert"); } while (0)
-
-#undef panic
diff --git a/src/shared/fsutil.c b/src/shared/fsutil.c
index a03ed0c..ffdcc43 100644
--- a/src/shared/fsutil.c
+++ b/src/shared/fsutil.c
@@ -1,9 +1,7 @@
+#include <assert.h>
#include <camellia/fsutil.h>
#include <limits.h>
-// TODO shared assert
-#define assert(...) {}
-
void fs_normslice(long *restrict offset, size_t *restrict length, size_t max, bool expand)
{
assert(max <= (size_t)LONG_MAX);
diff --git a/src/shared/include/assert.h b/src/shared/include/assert.h
new file mode 100644
index 0000000..7adf297
--- /dev/null
+++ b/src/shared/include/assert.h
@@ -0,0 +1,3 @@
+#pragma once
+#define assert(stmt) do { if (!(stmt)) __badassert(__func__, __FILE__, __LINE__); } while (0)
+_Noreturn void __badassert(const char *func, const char *file, int line);
diff --git a/src/shared/path.c b/src/shared/path.c
index 9d2eda3..175796f 100644
--- a/src/shared/path.c
+++ b/src/shared/path.c
@@ -1,10 +1,8 @@
+#include <assert.h>
#include <camellia/path.h>
#include <shared/mem.h>
#include <stdbool.h>
-// TODO shared assert
-#define assert(...)
-
int path_simplify(const char *in, char *out, size_t len) {
if (len == 0) return -1; // empty paths are invalid
if (in[0] != '/') return -1; // so are relative paths
diff --git a/src/user/lib/assert.c b/src/user/lib/assert.c
new file mode 100644
index 0000000..f42d696
--- /dev/null
+++ b/src/user/lib/assert.c
@@ -0,0 +1,8 @@
+#include <assert.h>
+#include <camellia/syscalls.h>
+#include <stdio.h>
+
+_Noreturn void __badassert(const char *func, const char *file, int line) {
+ fprintf(stderr, "assertion failure %s:%s:%u\n", file, func, line);
+ _syscall_exit(1);
+}