-
Notifications
You must be signed in to change notification settings - Fork 0
/
assert.cpp
115 lines (100 loc) · 3 KB
/
assert.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#include "assert.h"
#include "SMP.h"
#include "Scheduler.h"
#include "SystemState.h"
#include "Thread.h"
#include "debug_bochs.h"
#include "kprintf.h"
#include "ArchCpuLocalStorage.h"
#include "ArchInterrupts.h"
#include "ArchMulticore.h"
__attribute__((noreturn)) void pre_new_sweb_assert(const char* condition, uint32 line, const char* file)
{
system_state = KPANIC;
const char* error_string = "KERNEL PANIC: Assertion Failed in File: on Line: ";
char line_string[5];
ArchInterrupts::disableInterrupts();
writeChar2Bochs('\n');
writeLine2Bochs(condition);
writeChar2Bochs('\n');
writeLine2Bochs(error_string);
writeChar2Bochs('\n');
writeLine2Bochs(file);
writeChar2Bochs('\n');
if (currentThread)
currentThread->printBacktrace(false);
uint8 * fb = (uint8*)0xC00B8000;
uint32 s=0;
uint32 i=0;
for (s=0; s<40; ++s)
{
fb[i++] = error_string[s];
fb[i++] = 0x9f;
}
while (file && *file)
{
fb[i++] = *file++;
fb[i++] = 0x9f;
}
for (s=40; s<54; ++s)
{
fb[i++] = error_string[s];
fb[i++] = 0x9f;
}
i-=4;
for (s=0; s < (sizeof(line_string) - 1); ++s)
{
line_string[s]=' ';
}
line_string[s]='\0';
while (line>0)
{
fb[i++] = (uint8) ( 0x30 + (line%10) );
fb[i] = 0x9f;
line_string[--s] = ( 0x30 + (line%10) );
i-=3;
line /= 10;
}
writeLine2Bochs(line_string);
writeChar2Bochs('\n');
while(true)
ArchCommon::halt();
unreachable();
}
eastl::atomic_flag assert_print_lock;
__cpu bool in_assert = false;
bool in_assert_pre_cls = false;
[[noreturn]] void sweb_assert(const char *condition, uint32 line, const char* file, const char* function)
{
bool prev_intr = ArchInterrupts::disableInterrupts();
system_state = KPANIC;
debug_print_to_fb = false;
Thread* calling_thread = CpuLocalStorage::ClsInitialized() ? currentThread : nullptr;
bool* in_assert_p = CpuLocalStorage::ClsInitialized() ? &in_assert : &in_assert_pre_cls;
if (*in_assert_p) {
assert_print_lock.clear(eastl::memory_order_release);
kprintfd("PANIC LOOP: How did we get here?\n");
while(true)
ArchCommon::halt();
unreachable();
}
*in_assert_p = true;
if (SMP::numRunningCpus() > 1)
{
ArchMulticore::stopOtherCpus();
}
while (assert_print_lock.test_and_set(eastl::memory_order_acquire));
if (calling_thread)
{
debug(BACKTRACE, "CPU %zu backtrace:\n", SMP::currentCpuId());
if (!prev_intr)
debug(BACKTRACE, "CAUTION: Assertion occurred in interrupt handler that is potentially unrelated to normal thread execution\n");
calling_thread->printBacktrace(false);
}
kprintfd("KERNEL PANIC: Assertion %s failed in File %s, Function %s on Line %d, CPU %zd\n", condition, file, function, line, SMP::currentCpuId());
kprintf("KERNEL PANIC: Assertion %s failed in File %s, Function %s on Line %d, CPU %zd\n", condition, file, function, line, SMP::currentCpuId());
assert_print_lock.clear(eastl::memory_order_release);
while(true)
ArchCommon::halt();
unreachable();
}