-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprocess.c
More file actions
54 lines (46 loc) · 1.51 KB
/
process.c
File metadata and controls
54 lines (46 loc) · 1.51 KB
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
https://powcoder.com
代写代考加微信 powcoder
Assignment Project Exam Help
Add WeChat powcoder
#include "process.h"
// app_printf
// A version of console_printf that picks a sensible color by process ID.
void app_printf(int colorid, const char* format, ...) {
int color;
if (colorid < 0) {
color = 0x0700;
} else {
static const uint8_t col[] = { 0x0E, 0x0F, 0x0C, 0x0A, 0x09 };
color = col[colorid % sizeof(col)] << 8;
}
va_list val;
va_start(val, format);
cursorpos = console_vprintf(cursorpos, color, format, val);
va_end(val);
if (CROW(cursorpos) >= 23) {
cursorpos = CPOS(0, 0);
}
}
// panic, assert_fail
// Call the INT_SYS_PANIC system call so the kernel loops until Control-C.
void panic(const char* format, ...) {
va_list val;
va_start(val, format);
char buf[160];
memcpy(buf, "PANIC: ", 7);
int len = vsnprintf(&buf[7], sizeof(buf) - 7, format, val) + 7;
va_end(val);
if (len > 0 && buf[len - 1] != '\n') {
strcpy(buf + len - (len == (int) sizeof(buf) - 1), "\n");
}
(void) console_printf(CPOS(23, 0), 0xC000, "%s", buf);
sys_panic(NULL);
spinloop: goto spinloop; // should never get here
}
void assert_fail(const char* file, int line, const char* msg) {
(void) console_printf(CPOS(23, 0), 0xC000,
"PANIC: %s:%d: assertion '%s' failed\n",
file, line, msg);
sys_panic(NULL);
spinloop: goto spinloop; // should never get here
}