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
|
//! Analyze Error Codes
pub const PageFaultError = struct {
present: bool,
write: bool,
user: bool,
reserved_write: bool,
instruction_fetch: bool,
pub fn from_error_code(code: u64) PageFaultError {
return PageFaultError{
.present = (code & 1) != 0,
.write = (code & 2) != 0,
.user = (code & 4) != 0,
.reserved_write = (code & 8) != 0,
.instruction_fetch = (code & 16) != 0,
};
}
pub fn is_not_present(self: PageFaultError) bool {
return !self.present;
}
pub fn is_write_access(self: PageFaultError) bool {
return self.write;
}
pub fn is_execute_access(self: PageFaultError) bool {
return self.instruction_fetch;
}
pub fn description(self: PageFaultError) []const u8 {
if (self.instruction_fetch) return if (self.present) "Execute on non-executable page" else "Execute on non-present page";
if (self.write) return if (self.present) "Write to read-only page" else "Write to non-present page";
return if (self.present) "Read from protected page" else "Read from non-present page";
}
};
pub const SelectorError = struct {
external: bool,
table: u2,
index: u13,
pub fn from_error_code(code: u64) SelectorError {
return SelectorError{ .external = (code & 1) != 0, .table = @truncate((code >> 1) & 0x3), .index = @truncate((code >> 3) & 0x1FFF) };
}
};
|