stivale: Add requested stack sanity checks. Closes #95

This commit is contained in:
mintsuki 2021-07-26 19:25:59 +02:00
parent 9d68787fe1
commit db561393dd
2 changed files with 20 additions and 0 deletions

View File

@ -174,6 +174,16 @@ void stivale_load(char *config, char *cmdline) {
print("stivale: Requested stack at: %X\n", stivale_hdr.stack); print("stivale: Requested stack at: %X\n", stivale_hdr.stack);
} }
// The spec says the stack has to be 16-byte aligned
if ((stivale_hdr.stack & (16 - 1)) != 0) {
panic("stivale: Requested stack is not 16-byte aligned\n");
}
// It also says the stack cannot be NULL for 32-bit kernels
if (bits == 32 && stivale_hdr.stack == 0) {
panic("stivale: The stack cannot be 0 for 32-bit kernels");
}
stivale_struct.module_count = 0; stivale_struct.module_count = 0;
uint64_t *prev_mod_ptr = &stivale_struct.modules; uint64_t *prev_mod_ptr = &stivale_struct.modules;
for (int i = 0; ; i++) { for (int i = 0; ; i++) {

View File

@ -193,6 +193,16 @@ failed_to_load_header_section:
print("stivale2: Requested stack at: %X\n", stivale2_hdr.stack); print("stivale2: Requested stack at: %X\n", stivale2_hdr.stack);
} }
// The spec says the stack has to be 16-byte aligned
if ((stivale2_hdr.stack & (16 - 1)) != 0) {
panic("stivale2: Requested stack is not 16-byte aligned");
}
// It also says the stack cannot be NULL for 32-bit kernels
if (bits == 32 && stivale2_hdr.stack == 0) {
panic("stivale2: The stack cannot be 0 for 32-bit kernels");
}
strcpy(stivale2_struct.bootloader_brand, "Limine"); strcpy(stivale2_struct.bootloader_brand, "Limine");
strcpy(stivale2_struct.bootloader_version, LIMINE_VERSION); strcpy(stivale2_struct.bootloader_version, LIMINE_VERSION);