mirror of
https://github.com/Fennix-Project/Kernel.git
synced 2025-07-11 07:19:20 +00:00
Update kernel
This commit is contained in:
@ -25,82 +25,82 @@
|
||||
|
||||
EXTERNC __weak __no_stack_protector uintptr_t __stack_chk_guard_init(void)
|
||||
{
|
||||
int MaxRetries = 0;
|
||||
int MaxRetries = 0;
|
||||
#if UINTPTR_MAX == UINT32_MAX
|
||||
uint32_t num;
|
||||
uint32_t num;
|
||||
Retry:
|
||||
num = Random::rand32();
|
||||
if (num < 0x1000 && MaxRetries++ < 10)
|
||||
goto Retry;
|
||||
return num;
|
||||
num = Random::rand32();
|
||||
if (num < 0x1000 && MaxRetries++ < 10)
|
||||
goto Retry;
|
||||
return num;
|
||||
|
||||
#else
|
||||
uint64_t num;
|
||||
uint64_t num;
|
||||
Retry:
|
||||
num = Random::rand64();
|
||||
if (num < 0x100000 && MaxRetries++ < 10)
|
||||
goto Retry;
|
||||
return num;
|
||||
num = Random::rand64();
|
||||
if (num < 0x100000 && MaxRetries++ < 10)
|
||||
goto Retry;
|
||||
return num;
|
||||
#endif
|
||||
}
|
||||
|
||||
EXTERNC __constructor __no_stack_protector void __guard_setup(void)
|
||||
{
|
||||
debug("__guard_setup");
|
||||
if (__stack_chk_guard == 0)
|
||||
__stack_chk_guard = __stack_chk_guard_init();
|
||||
debug("Stack guard value: %ld", __stack_chk_guard);
|
||||
debug("__guard_setup");
|
||||
if (__stack_chk_guard == 0)
|
||||
__stack_chk_guard = __stack_chk_guard_init();
|
||||
debug("Stack guard value: %ld", __stack_chk_guard);
|
||||
}
|
||||
|
||||
EXTERNC __weak __noreturn __no_stack_protector void __stack_chk_fail(void)
|
||||
{
|
||||
TaskingPanic();
|
||||
for (short i = 0; i < 10; i++)
|
||||
error("Stack smashing detected!");
|
||||
debug("Current stack check guard value: %#lx", __stack_chk_guard);
|
||||
KPrint("\eFF0000Stack smashing detected!");
|
||||
TaskingPanic();
|
||||
for (short i = 0; i < 10; i++)
|
||||
error("Stack smashing detected!");
|
||||
debug("Current stack check guard value: %#lx", __stack_chk_guard);
|
||||
KPrint("\eFF0000Stack smashing detected!");
|
||||
|
||||
void *Stack = nullptr;
|
||||
void *Stack = nullptr;
|
||||
#if defined(a86)
|
||||
|
||||
#if defined(a64)
|
||||
asmv("movq %%rsp, %0"
|
||||
: "=r"(Stack));
|
||||
asmv("movq %%rsp, %0"
|
||||
: "=r"(Stack));
|
||||
#elif defined(a32)
|
||||
asmv("movl %%esp, %0"
|
||||
: "=r"(Stack));
|
||||
asmv("movl %%esp, %0"
|
||||
: "=r"(Stack));
|
||||
#endif
|
||||
|
||||
#elif defined(aa64)
|
||||
|
||||
asmv("mov %%sp, %0"
|
||||
: "=r"(Stack));
|
||||
asmv("mov %%sp, %0"
|
||||
: "=r"(Stack));
|
||||
|
||||
#endif
|
||||
error("Stack address: %#lx", Stack);
|
||||
error("Stack address: %#lx", Stack);
|
||||
|
||||
if (DebuggerIsAttached)
|
||||
if (DebuggerIsAttached)
|
||||
#ifdef a86
|
||||
asmv("int $0x3");
|
||||
asmv("int $0x3");
|
||||
#elif defined(aa64)
|
||||
asmv("brk #0");
|
||||
asmv("brk #0");
|
||||
#endif
|
||||
|
||||
CPU::Stop();
|
||||
CPU::Stop();
|
||||
}
|
||||
|
||||
// https://github.com/gcc-mirror/gcc/blob/master/libssp/ssp.c
|
||||
EXTERNC __weak __noreturn __no_stack_protector void __chk_fail(void)
|
||||
{
|
||||
TaskingPanic();
|
||||
for (short i = 0; i < 10; i++)
|
||||
error("Buffer overflow detected!");
|
||||
KPrint("\eFF0000Buffer overflow detected!");
|
||||
TaskingPanic();
|
||||
for (short i = 0; i < 10; i++)
|
||||
error("Buffer overflow detected!");
|
||||
KPrint("\eFF0000Buffer overflow detected!");
|
||||
|
||||
#if defined(a86)
|
||||
while (1)
|
||||
asmv("cli; hlt");
|
||||
while (1)
|
||||
asmv("cli; hlt");
|
||||
#elif defined(aa64)
|
||||
asmv("wfe");
|
||||
asmv("wfe");
|
||||
#endif
|
||||
}
|
||||
|
Reference in New Issue
Block a user