diff options
author | Raghuram Subramani <raghus2247@gmail.com> | 2024-12-30 12:40:19 -0500 |
---|---|---|
committer | Raghuram Subramani <raghus2247@gmail.com> | 2024-12-30 12:40:19 -0500 |
commit | bc0153eb0a05725c9ccfd7a18ca446eea1fd7477 (patch) | |
tree | 99cf9e12b5d8e5584149f9ed6b407cea0141e09b | |
parent | 0044ce92eac84c03c2e00227f9e52d22fb5b3160 (diff) |
kernel: Add halt()
-rw-r--r-- | kernel/CMakeLists.txt | 1 | ||||
-rw-r--r-- | kernel/include/kernel/halt.h | 24 | ||||
-rw-r--r-- | kernel/kernel/halt.c | 30 | ||||
-rw-r--r-- | kernel/kernel/stack_smashing_protector/stack_smashing_protector.c | 4 | ||||
-rw-r--r-- | kernel/libk/printk.c | 1 |
5 files changed, 60 insertions, 0 deletions
diff --git a/kernel/CMakeLists.txt b/kernel/CMakeLists.txt index 47b1ac2..ca8dc85 100644 --- a/kernel/CMakeLists.txt +++ b/kernel/CMakeLists.txt @@ -5,6 +5,7 @@ set(KERNEL_SRC boot/init/boot.s kernel/kernel.c + kernel/halt.c kernel/stack_smashing_protector/stack_smashing_protector.c drivers/vga_text_buffer/vga_text_buffer.c diff --git a/kernel/include/kernel/halt.h b/kernel/include/kernel/halt.h new file mode 100644 index 0000000..5735a06 --- /dev/null +++ b/kernel/include/kernel/halt.h @@ -0,0 +1,24 @@ +/* + * CMOS + * Copyright (C) 2024 Raghuram Subramani <raghus2247@gmail.com> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef __kernel_halt_h +#define __kernel_halt_h + +void halt(void); + +#endif diff --git a/kernel/kernel/halt.c b/kernel/kernel/halt.c new file mode 100644 index 0000000..894ee8a --- /dev/null +++ b/kernel/kernel/halt.c @@ -0,0 +1,30 @@ +/* + * CMOS + * Copyright (C) 2024 Raghuram Subramani <raghus2247@gmail.com> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#include <libk/io.h> + +#include <kernel/halt.h> + +void +halt(void) +{ + printk("kernel: halted."); + + for (;;) + ; +} diff --git a/kernel/kernel/stack_smashing_protector/stack_smashing_protector.c b/kernel/kernel/stack_smashing_protector/stack_smashing_protector.c index 92612de..3cff7dc 100644 --- a/kernel/kernel/stack_smashing_protector/stack_smashing_protector.c +++ b/kernel/kernel/stack_smashing_protector/stack_smashing_protector.c @@ -1,6 +1,9 @@ #include <stdint.h> + #include <libk/io.h> +#include <kernel/halt.h> + /* TODO: Randomize */ #define STACK_CHK_GUARD 0xe2dee396 @@ -11,4 +14,5 @@ __stack_chk_fail(void) { /* TODO: Panic the kernel */ printk("SSP: Stack smashing detected!\n"); + halt(); } diff --git a/kernel/libk/printk.c b/kernel/libk/printk.c index 9773e6b..f3a5085 100644 --- a/kernel/libk/printk.c +++ b/kernel/libk/printk.c @@ -17,6 +17,7 @@ */ #include <drivers/vga_text_buffer.h> + #include <libk/io.h> void |