mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 14:47:44 +00:00
Kernel+LibC: Make page fault crashes a bit more readable.
We'll now try to detect crashes that were due to dereferencing nullptr, uninitialized malloc() memory, or recently free()'d memory. It's not perfect but I think it's pretty good. :^) Also added some color to the most important parts of the crash log, and added some more modes to /bin/crash for exercising this code. Fixes #243.
This commit is contained in:
parent
15bea7153a
commit
8c0ae711d8
5 changed files with 76 additions and 11 deletions
|
@ -4,17 +4,22 @@
|
|||
|
||||
static void print_usage_and_exit()
|
||||
{
|
||||
printf("usage: crash -[sdia]\n");
|
||||
printf("usage: crash -[sdiamfMF]\n");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
#pragma GCC optimize("O0")
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
enum Mode {
|
||||
SegmentationViolation,
|
||||
DivisionByZero,
|
||||
IllegalInstruction,
|
||||
Abort
|
||||
Abort,
|
||||
WriteToUninitializedMallocMemory,
|
||||
WriteToFreedMemory,
|
||||
ReadFromUninitializedMallocMemory,
|
||||
ReadFromFreedMemory,
|
||||
};
|
||||
Mode mode = SegmentationViolation;
|
||||
|
||||
|
@ -29,6 +34,14 @@ int main(int argc, char** argv)
|
|||
mode = IllegalInstruction;
|
||||
else if (String(argv[1]) == "-a")
|
||||
mode = Abort;
|
||||
else if (String(argv[1]) == "-m")
|
||||
mode = ReadFromUninitializedMallocMemory;
|
||||
else if (String(argv[1]) == "-f")
|
||||
mode = ReadFromFreedMemory;
|
||||
else if (String(argv[1]) == "-M")
|
||||
mode = WriteToUninitializedMallocMemory;
|
||||
else if (String(argv[1]) == "-F")
|
||||
mode = WriteToFreedMemory;
|
||||
else
|
||||
print_usage_and_exit();
|
||||
|
||||
|
@ -55,6 +68,32 @@ int main(int argc, char** argv)
|
|||
ASSERT_NOT_REACHED();
|
||||
}
|
||||
|
||||
if (mode == ReadFromUninitializedMallocMemory) {
|
||||
auto* uninitialized_memory = (volatile dword**)malloc(1024);
|
||||
volatile auto x = uninitialized_memory[0][0];
|
||||
ASSERT_NOT_REACHED();
|
||||
}
|
||||
|
||||
if (mode == ReadFromFreedMemory) {
|
||||
auto* uninitialized_memory = (volatile dword**)malloc(1024);
|
||||
free(uninitialized_memory);
|
||||
volatile auto x = uninitialized_memory[4][0];
|
||||
ASSERT_NOT_REACHED();
|
||||
}
|
||||
|
||||
if (mode == WriteToUninitializedMallocMemory) {
|
||||
auto* uninitialized_memory = (volatile dword**)malloc(1024);
|
||||
uninitialized_memory[4][0] = 1;
|
||||
ASSERT_NOT_REACHED();
|
||||
}
|
||||
|
||||
if (mode == WriteToFreedMemory) {
|
||||
auto* uninitialized_memory = (volatile dword**)malloc(1024);
|
||||
free(uninitialized_memory);
|
||||
uninitialized_memory[4][0] = 1;
|
||||
ASSERT_NOT_REACHED();
|
||||
}
|
||||
|
||||
ASSERT_NOT_REACHED();
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue