I am tearing my hair out trying to force the kernel to run a fault handler on stack overflow. I can touch the guard page and it works, but the overflow never does. It just does a default crash and core dump. sigaltstack() doesn't do shit to help
function void FaultHandler(int Signal, siginfo_t* SignalInfo, void*) {
if (Signal == SIGSEGV) {
byte* Address = SignalInfo->si_addr;
fprintf(stderr, "Fault at %p\n", Address);
fprintf(stderr, "In guard page? %s\n", (Address >= StackBoundary && Address < StackBoundary+StackBoundarySize) ? "true" : "false");
}
exit(1);
}
function void OverflowTest(void) {
uint64_t _;
OverflowTest();
return;
}
function void* Entry(void* Argument) {
fprintf(stderr, "Faulting...\n");
# if 0
{ // custom fault triggers in guard page
int _;
byte* Address = (byte*) &_;
Address -= StackSize;
Address[0] = 0;
}
# else
{ // custom fault does not trigger
OverflowTest();
}
# endif
return (null);
}
The kernel must be doing something I'm not understanding.