From 8fae948c3243b4ca35313df38afca7f463278a9a Mon Sep 17 00:00:00 2001 From: Amoelle Date: Fri, 18 Jul 2025 12:36:18 +0300 Subject: [PATCH] implement kernel panic --- common.c | 4 +++- kernel.c | 15 ++++++++++----- kernel.h | 6 ++++++ 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/common.c b/common.c index e273a27..67894f4 100644 --- a/common.c +++ b/common.c @@ -84,7 +84,9 @@ char *strcpy(char *dst, const char *src) { *d++ = *src++; *d = '\0'; return dst; -} +} // The strcpy function continues copying even if + // src is longer than the memory area of dst. + // This can easily lead to bugs and vulnerabilities int strcmp(const char *s1, const char *s2) { while (*s1 && *s2) { diff --git a/kernel.c b/kernel.c index 0bc2384..6a9c271 100644 --- a/kernel.c +++ b/kernel.c @@ -27,12 +27,17 @@ void putchar(char ch) { } void kernel_main(void) { - printf("\n\nHello %s\n", "RETARD!"); - printf("60 + 9 = %d, %x\n", 60 + 9, 0x1234abcd); + // printf("\n\nHello %s\n", "friend :3"); + // printf("60 + 9 = %d, %x\n", 60 + 9, 0x1234abcd); + // + // for (;;) { + // __asm__ __volatile__("wfi"); + // } + + memset(__bss, 0, (size_t) __bss_end - (size_t) __bss); - for (;;) { - __asm__ __volatile__("wfi"); - } + PANIC("BOOOO!!! GET INFECTED WITH BOOTKID YOU SKID! 0x1337h@x0r"); + printf("you lucky bitch got away\n"); } __attribute__((section(".text.boot"))) diff --git a/kernel.h b/kernel.h index 4faa208..d8027d0 100644 --- a/kernel.h +++ b/kernel.h @@ -4,3 +4,9 @@ struct sbiret { long error; long value; }; + +#define PANIC(fmt, ...) \ + do { \ + printf("YOU GOT A PANIC ERROR: %s:%d: " fmt "\n", __FILE__, __LINE__, ##__VA_ARGS__); \ + while (1) {} \ + } while (0)