-
Notifications
You must be signed in to change notification settings - Fork 1
Development #122
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Development #122
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -71,7 +71,15 @@ asmlinkage void InterruptHandler(Registers* regs) { | |
|
||
// Print detailed information | ||
PrintDetailedFaultInfo(&ctx, regs); | ||
delay(100000000); | ||
RegistersDumpT dump = {0}; | ||
DumpRegisters(&dump); | ||
// Override with fault context where applicable | ||
dump.rip = regs->rip; | ||
dump.cs = regs->cs; | ||
dump.rflags = regs->rflags; | ||
dump.rsp = regs->rsp; | ||
dump.ss = regs->ss; | ||
PrintRegisters(&dump); | ||
// Still panic, but now with much more info | ||
Comment on lines
+74
to
83
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Verification agent 🧩 Analysis chainDouble-fault safety and panic CLI ordering — please verify. Printing on DF can triple-fault unless ISR #8 uses an IST stack; also ensure PanicFromInterrupt disables interrupts as its first instruction. 🏁 Script executed: #!/bin/bash
# 1) Verify DF (vector 8) uses IST in IDT setup / ASM stubs
rg -n -C3 -i 'double\s*fault|isr8|vector\s*8|ist' arch/x86_64
# 2) Confirm PanicFromInterrupt (and other panic entry points) execute cli first
rg -n -C3 'PanicFromInterrupt\s*\(|KernelPanicHandler\s*\(|Panic\w*\(' kernel | sed -n '1,200p'
rg -n 'asm\s+volatile\("cli"\)' kernel Length of output: 27567 Ensure double-fault uses an IST stack; panic CLI ordering is correct
|
||
PanicFromInterrupt(ctx.fault_reason, regs); | ||
break; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
#include "POST.h" | ||
#include "Console.h" | ||
#include "KernelHeap.h" | ||
#include "PMem.h" | ||
#include "Panic.h" | ||
#include "Serial.h" | ||
#include "VMem.h" | ||
#include "stdbool.h" | ||
|
||
#define N 512 | ||
void * ptrs[N] = {0}; | ||
|
||
uint64_t seed = 0x12345; | ||
uint64_t rnd() { seed = seed * 6364136223846793005ULL + 1; return seed; } | ||
|
||
bool SerialTest() { | ||
for (int i = 0; i < 128; i++) { | ||
if (SerialWrite(".") < 0) return false; | ||
} | ||
return true; | ||
} | ||
|
||
bool MemoryTest() { | ||
for (int i = 1; i < 1000; i++) { | ||
size_t sz = (i % 7 == 0) ? 4096 : (i % 100 + 1); | ||
void *ptr = KernelMemoryAlloc(sz); | ||
if (!ptr) return false; | ||
KernelFree(ptr); | ||
} | ||
// | ||
for (int i = 0; i < N; i++) ptrs[i] = KernelMemoryAlloc(128); | ||
|
||
// free every other block | ||
for (int i = 0; i < N; i += 2) KernelFree(ptrs[i]); | ||
|
||
// re-allocate in different sizes | ||
for (int i = 0; i < N/2; i++) { | ||
ptrs[i] = KernelMemoryAlloc((i % 2) ? 64 : 256); | ||
} | ||
|
||
for (int iter = 0; iter < 100000; iter++) { | ||
int idx = rnd() % N; | ||
if (ptrs[idx]) { | ||
KernelFree(ptrs[idx]); | ||
ptrs[idx] = NULL; | ||
} else { | ||
size_t sz = (rnd() % 8192) + 1; // 1–8K | ||
ptrs[idx] = KernelMemoryAlloc(sz); | ||
if (!ptrs[idx]) PANIC("OOM during fuzz"); | ||
} | ||
} | ||
|
||
for (uintptr_t addr = 0x400000; addr < 0x800000; addr += 0x1000) { | ||
void* frame = AllocPage(); | ||
VMemMap(addr, (uint64_t)frame, PAGE_PRESENT | PAGE_WRITABLE); | ||
VMemUnmap(addr, PAGE_SIZE); | ||
FreePage(frame); | ||
} | ||
Comment on lines
+53
to
+58
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Check map/unmap return codes and handle page alloc failure. Ignoring errors risks leaking mapped pages or freeing still-mapped frames. - for (uintptr_t addr = 0x400000; addr < 0x800000; addr += 0x1000) {
- void* frame = AllocPage();
- VMemMap(addr, (uint64_t)frame, PAGE_PRESENT | PAGE_WRITABLE);
- VMemUnmap(addr, PAGE_SIZE);
- FreePage(frame);
- }
+ for (uintptr_t addr = 0x400000; addr < 0x800000; addr += 0x1000) {
+ void* frame = AllocPage();
+ if (!frame) return false;
+ int rc = VMemMap(addr, (uint64_t)frame, PAGE_PRESENT | PAGE_WRITABLE);
+ if (rc != VMEM_SUCCESS) { FreePage(frame); return false; }
+ rc = VMemUnmap(addr, PAGE_SIZE);
+ if (rc != VMEM_SUCCESS) { FreePage(frame); return false; }
+ FreePage(frame);
+ }
|
||
|
||
for (int i = 0; i < 1000; i++) { | ||
size_t sz = (i % 500) + 1; | ||
uint8_t *p = (uint8_t*)KernelMemoryAlloc(sz); | ||
for (size_t j = 0; j < sz; j++) p[j] = (uint8_t)(i ^ j); | ||
for (size_t j = 0; j < sz; j++) | ||
if (p[j] != (uint8_t)(i ^ j)) PANIC("Memory corruption!"); | ||
KernelFree(p); | ||
} | ||
|
||
return true; | ||
} | ||
Comment on lines
+69
to
+70
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Free any remaining fuzz allocations to avoid a boot-time leak. POST runs once but leaking kernel heap here is avoidable. - return true;
+ // Cleanup any remaining allocations from fuzzing
+ for (int i = 0; i < N; i++) {
+ if (ptrs[i]) { KernelFree(ptrs[i]); ptrs[i] = NULL; }
+ }
+ return true;
🤖 Prompt for AI Agents
|
||
|
||
void POSTHandler(const char * args) { | ||
(void)args; | ||
if (!SerialTest()) PrintKernelWarning("Serial test failed\n"); | ||
if (!MemoryTest()) PrintKernelWarning("Memory test failed\n"); | ||
PrintKernelSuccess("POST test passed\n"); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#ifndef VOIDFRAME_POST_H | ||
#define VOIDFRAME_POST_H | ||
|
||
void POSTHandler(const char * args); | ||
|
||
#endif // VOIDFRAME_POST_H |
Uh oh!
There was an error while loading. Please reload this page.