aboutsummaryrefslogtreecommitdiff
path: root/libc/inc/assert.h
blob: 758c91bf886c87ac6c4b41a3b5b9bac7d0807ac1 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
// 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: Assertion '%s' failed\n", __FILE__, __LINE__, __func__, #exp);  \
		struct proc *proc = proc_current();                                                \
		if (proc)                                                                          \
			proc_exit(proc, 1);                                                        \
		else                                                                               \
			__asm__ volatile("cli\nhlt");                                              \
	}
#elif defined(userspace)
#include <sys.h>
#define assert(exp)                                                                                \
	if (!(exp)) {                                                                              \
		printf("%s:%d: %s: Assertion '%s' failed\n", __FILE__, __LINE__, __func__, #exp);  \
		sys1(SYS_EXIT, 1);                                                                 \
	}
#else
#error "No lib target specified. Please use -Dkernel or -Duserspace"
#endif

#endif