kernel: add 'assert()'
This commit is contained in:
parent
042d30788c
commit
e22d6d84a4
4
base/usr/include/kernel/assert.h
Normal file
4
base/usr/include/kernel/assert.h
Normal file
@ -0,0 +1,4 @@
|
||||
#pragma once
|
||||
|
||||
extern void __assert_failed(const char * file, int line, const char * func, const char * cond);
|
||||
#define assert(condition) do { if (!(condition)) __assert_failed(__FILE__,__LINE__,__func__,#condition); } while (0)
|
@ -96,11 +96,16 @@ void arch_pause(void) {
|
||||
}
|
||||
|
||||
extern void lapic_send_ipi(int i, uint32_t val);
|
||||
void arch_fatal(void) {
|
||||
|
||||
void arch_fatal_prepare(void) {
|
||||
for (int i = 0; i < processor_count; ++i) {
|
||||
if (i == this_core->cpu_id) continue;
|
||||
lapic_send_ipi(processor_local_data[i].lapic_id, 0x447D);
|
||||
}
|
||||
}
|
||||
|
||||
void arch_fatal(void) {
|
||||
arch_fatal_prepare();
|
||||
while (1) {
|
||||
asm volatile (
|
||||
"cli\n"
|
||||
|
15
kernel/misc/assert.c
Normal file
15
kernel/misc/assert.c
Normal file
@ -0,0 +1,15 @@
|
||||
/**
|
||||
* @file kernel/misc/assert.h
|
||||
* @brief Kernel assertion handler.
|
||||
*/
|
||||
#include <kernel/assert.h>
|
||||
#include <kernel/printf.h>
|
||||
#include <kernel/misc.h>
|
||||
|
||||
extern void arch_fatal_prepare(void);
|
||||
|
||||
void __assert_failed(const char * file, int line, const char * func, const char * cond) {
|
||||
arch_fatal_prepare();
|
||||
printf("%s:%d (%s) Assertion failed: %s\n", file, line, func, cond);
|
||||
arch_fatal();
|
||||
}
|
@ -21,6 +21,7 @@
|
||||
* @author 2015 Dale Weiler
|
||||
*/
|
||||
#include <errno.h>
|
||||
#include <kernel/assert.h>
|
||||
#include <kernel/process.h>
|
||||
#include <kernel/printf.h>
|
||||
#include <kernel/string.h>
|
||||
@ -497,10 +498,8 @@ extern void tree_remove_reparent_root(tree_t * tree, tree_node_t * node);
|
||||
* Finally, the process is freed.
|
||||
*/
|
||||
void process_delete(process_t * proc) {
|
||||
if (proc == this_core->current_process) {
|
||||
printf("proc: tried to delete running process\n");
|
||||
arch_fatal();
|
||||
}
|
||||
assert(proc != this_core->current_process);
|
||||
|
||||
tree_node_t * entry = proc->tree_entry;
|
||||
if (!entry) {
|
||||
printf("Tried to delete process with no tree entry?\n");
|
||||
@ -626,7 +625,7 @@ volatile process_t * next_ready_process(void) {
|
||||
|
||||
node_t * np = list_dequeue(process_queue);
|
||||
|
||||
if ((uintptr_t)np < 0xFFFFff0000000000UL || (uintptr_t)np > 0xFFFFff0000f00000UL) {
|
||||
if ((uintptr_t)np < 0xFFFFff0000000000UL || (uintptr_t)np > 0xFFFFfff000000000UL) {
|
||||
printf("Suspicious pointer in queue: %#zx\n", (uintptr_t)np);
|
||||
arch_fatal();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user