Skip to content

Commit 09ccbfc

Browse files
authored
Allow for registering "signal" handlers for exceptions (#501)
* There are four categories of "signals" that correspond loosely to POSIX error-related signals: SIGSEGV, SIGBUS, SIGFPE, SIGILL. * Clean up exception handling code, including logging faults and killing tasks.
1 parent 78d0e00 commit 09ccbfc

File tree

6 files changed

+323
-88
lines changed

6 files changed

+323
-88
lines changed

Cargo.lock

+14-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

kernel/exceptions_early/src/lib.rs

+22-20
Original file line numberDiff line numberDiff line change
@@ -108,43 +108,43 @@ pub fn init(double_fault_stack_top_unusable: Option<memory::VirtualAddress>) {
108108

109109

110110
/// exception 0x00
111-
pub extern "x86-interrupt" fn divide_error_handler(stack_frame: InterruptStackFrame) {
111+
extern "x86-interrupt" fn divide_error_handler(stack_frame: InterruptStackFrame) {
112112
println_raw!("\nEXCEPTION (early): DIVIDE ERROR\n{:#X?}", stack_frame);
113113
loop {}
114114
}
115115

116116
/// exception 0x01
117-
pub extern "x86-interrupt" fn debug_handler(stack_frame: InterruptStackFrame) {
117+
extern "x86-interrupt" fn debug_handler(stack_frame: InterruptStackFrame) {
118118
println_raw!("\nEXCEPTION (early): DEBUG EXCEPTION\n{:#X?}", stack_frame);
119119
// don't halt here, this isn't a fatal/permanent failure, just a brief pause.
120120
}
121121

122122
/// exception 0x02
123-
pub extern "x86-interrupt" fn nmi_handler(stack_frame: InterruptStackFrame) {
123+
extern "x86-interrupt" fn nmi_handler(stack_frame: InterruptStackFrame) {
124124
println_raw!("\nEXCEPTION (early): NON-MASKABLE INTERRUPT\n{:#X?}", stack_frame);
125125
loop { }
126126
}
127127

128128
/// exception 0x03
129-
pub extern "x86-interrupt" fn breakpoint_handler(stack_frame: InterruptStackFrame) {
129+
extern "x86-interrupt" fn breakpoint_handler(stack_frame: InterruptStackFrame) {
130130
println_raw!("\nEXCEPTION (early): BREAKPOINT\n{:#X?}", stack_frame);
131131
// don't halt here, this isn't a fatal/permanent failure, just a brief pause.
132132
}
133133

134134
/// exception 0x04
135-
pub extern "x86-interrupt" fn overflow_handler(stack_frame: InterruptStackFrame) {
135+
extern "x86-interrupt" fn overflow_handler(stack_frame: InterruptStackFrame) {
136136
println_raw!("\nEXCEPTION (early): OVERFLOW\n{:#X?}", stack_frame);
137137
loop { }
138138
}
139139

140140
/// exception 0x05
141-
pub extern "x86-interrupt" fn bound_range_exceeded_handler(stack_frame: InterruptStackFrame) {
141+
extern "x86-interrupt" fn bound_range_exceeded_handler(stack_frame: InterruptStackFrame) {
142142
println_raw!("\nEXCEPTION (early): BOUND RANGE EXCEEDED\n{:#X?}", stack_frame);
143143
loop { }
144144
}
145145

146146
/// exception 0x06
147-
pub extern "x86-interrupt" fn invalid_opcode_handler(stack_frame: InterruptStackFrame) {
147+
extern "x86-interrupt" fn invalid_opcode_handler(stack_frame: InterruptStackFrame) {
148148
println_raw!("\nEXCEPTION (early): INVALID OPCODE\n{:#X?}", stack_frame);
149149
loop {}
150150
}
@@ -153,44 +153,46 @@ pub extern "x86-interrupt" fn invalid_opcode_handler(stack_frame: InterruptStack
153153
///
154154
/// For more information about "spurious interrupts",
155155
/// see [here](http://wiki.osdev.org/I_Cant_Get_Interrupts_Working#I_keep_getting_an_IRQ7_for_no_apparent_reason).
156-
pub extern "x86-interrupt" fn device_not_available_handler(stack_frame: InterruptStackFrame) {
156+
extern "x86-interrupt" fn device_not_available_handler(stack_frame: InterruptStackFrame) {
157157
println_raw!("\nEXCEPTION (early): DEVICE NOT AVAILABLE\n{:#X?}", stack_frame);
158158
loop {}
159159
}
160160

161161
/// exception 0x08
162+
///
163+
/// Note: this is `pub` so we can access it within `interrupts::init()`.
162164
pub extern "x86-interrupt" fn double_fault_handler(stack_frame: InterruptStackFrame, error_code: u64) -> ! {
163165
println_raw!("\nEXCEPTION (early): DOUBLE FAULT\n{:#X?}\nError code: {:#b}", stack_frame, error_code);
164166
println_raw!("\nNote: this may be caused by stack overflow. Is the size of the initial_bsp_stack is too small?");
165167
loop {}
166168
}
167169

168170
/// exception 0x0A
169-
pub extern "x86-interrupt" fn invalid_tss_handler(stack_frame: InterruptStackFrame, error_code: u64) {
171+
extern "x86-interrupt" fn invalid_tss_handler(stack_frame: InterruptStackFrame, error_code: u64) {
170172
println_raw!("\nEXCEPTION (early): INVALID TSS\n{:#X?}\nError code: {:#b}", stack_frame, error_code);
171173
loop {}
172174
}
173175

174176
/// exception 0x0B
175-
pub extern "x86-interrupt" fn segment_not_present_handler(stack_frame: InterruptStackFrame, error_code: u64) {
177+
extern "x86-interrupt" fn segment_not_present_handler(stack_frame: InterruptStackFrame, error_code: u64) {
176178
println_raw!("\nEXCEPTION (early): SEGMENT NOT PRESENT\n{:#X?}\nError code: {:#b}", stack_frame, error_code);
177179
loop {}
178180
}
179181

180182
/// exception 0x0C
181-
pub extern "x86-interrupt" fn stack_segment_fault_handler(stack_frame: InterruptStackFrame, error_code: u64) {
183+
extern "x86-interrupt" fn stack_segment_fault_handler(stack_frame: InterruptStackFrame, error_code: u64) {
182184
println_raw!("\nEXCEPTION (early): STACK SEGMENT FAULT\n{:#X?}\nError code: {:#b}", stack_frame, error_code);
183185
loop {}
184186
}
185187

186188
/// exception 0x0D
187-
pub extern "x86-interrupt" fn general_protection_fault_handler(stack_frame: InterruptStackFrame, error_code: u64) {
189+
extern "x86-interrupt" fn general_protection_fault_handler(stack_frame: InterruptStackFrame, error_code: u64) {
188190
println_raw!("\nEXCEPTION (early): GENERAL PROTECTION FAULT\n{:#X?}\nError code: {:#b}", stack_frame, error_code);
189191
loop {}
190192
}
191193

192194
/// exception 0x0E
193-
pub extern "x86-interrupt" fn early_page_fault_handler(stack_frame: InterruptStackFrame, error_code: PageFaultErrorCode) {
195+
extern "x86-interrupt" fn early_page_fault_handler(stack_frame: InterruptStackFrame, error_code: PageFaultErrorCode) {
194196
let accessed_address = x86_64::registers::control::Cr2::read_raw();
195197
println_raw!("\nEXCEPTION (early): PAGE FAULT (early handler) while accessing {:#x}\n\
196198
error code: {:?}\n{:#X?}",
@@ -217,43 +219,43 @@ pub extern "x86-interrupt" fn early_page_fault_handler(stack_frame: InterruptSta
217219
}
218220

219221
/// exception 0x10
220-
pub extern "x86-interrupt" fn x87_floating_point_handler(stack_frame: InterruptStackFrame) {
222+
extern "x86-interrupt" fn x87_floating_point_handler(stack_frame: InterruptStackFrame) {
221223
println_raw!("\nEXCEPTION (early): x87 FLOATING POINT\n{:#X?}", stack_frame);
222224
loop {}
223225
}
224226

225227
/// exception 0x11
226-
pub extern "x86-interrupt" fn alignment_check_handler(stack_frame: InterruptStackFrame, error_code: u64) {
228+
extern "x86-interrupt" fn alignment_check_handler(stack_frame: InterruptStackFrame, error_code: u64) {
227229
println_raw!("\nEXCEPTION (early): ALIGNMENT CHECK\n{:#X?}\nError code: {:#b}", stack_frame, error_code);
228230
loop {}
229231
}
230232

231233
/// exception 0x12
232-
pub extern "x86-interrupt" fn machine_check_handler(stack_frame: InterruptStackFrame) -> ! {
234+
extern "x86-interrupt" fn machine_check_handler(stack_frame: InterruptStackFrame) -> ! {
233235
println_raw!("\nEXCEPTION (early): MACHINE CHECK\n{:#X?}", stack_frame);
234236
loop {}
235237
}
236238

237239
/// exception 0x13
238-
pub extern "x86-interrupt" fn simd_floating_point_handler(stack_frame: InterruptStackFrame) {
240+
extern "x86-interrupt" fn simd_floating_point_handler(stack_frame: InterruptStackFrame) {
239241
println_raw!("\nEXCEPTION (early): SIMD FLOATING POINT\n{:#X?}", stack_frame);
240242
loop {}
241243
}
242244

243245
/// exception 0x14
244-
pub extern "x86-interrupt" fn virtualization_handler(stack_frame: InterruptStackFrame) {
246+
extern "x86-interrupt" fn virtualization_handler(stack_frame: InterruptStackFrame) {
245247
println_raw!("\nEXCEPTION (early): VIRTUALIZATION\n{:#X?}", stack_frame);
246248
loop {}
247249
}
248250

249251
/// exception 0x1D
250-
pub extern "x86-interrupt" fn vmm_communication_exception_handler(stack_frame: InterruptStackFrame, error_code: u64) {
252+
extern "x86-interrupt" fn vmm_communication_exception_handler(stack_frame: InterruptStackFrame, error_code: u64) {
251253
println_raw!("\nEXCEPTION (early): VMM COMMUNICATION EXCEPTION\n{:#X?}\nError code: {:#b}", stack_frame, error_code);
252254
loop {}
253255
}
254256

255257
/// exception 0x1E
256-
pub extern "x86-interrupt" fn security_exception_handler(stack_frame: InterruptStackFrame, error_code: u64) {
258+
extern "x86-interrupt" fn security_exception_handler(stack_frame: InterruptStackFrame, error_code: u64) {
257259
println_raw!("\nEXCEPTION (early): SECURITY EXCEPTION\n{:#X?}\nError code: {:#b}", stack_frame, error_code);
258260
loop {}
259261
}

kernel/exceptions_full/Cargo.toml

+4-8
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,7 @@ build = "../../build.rs"
77

88
[dependencies]
99
x86_64 = { path = "../../libs/x86_64" } # currently using our local copy, forked from Phil Opp's crate
10-
11-
[dependencies.log]
12-
version = "0.4.8"
13-
14-
[dependencies.gimli]
15-
version = "0.19.0"
16-
default-features = false
17-
features = [ "read", "alloc" ]
10+
log = "0.4.8"
1811

1912
[dependencies.vga_buffer]
2013
path = "../vga_buffer"
@@ -55,5 +48,8 @@ path = "../tss"
5548
[dependencies.debug_info]
5649
path = "../debug_info"
5750

51+
[dependencies.signal_handler]
52+
path = "../signal_handler"
53+
5854
[lib]
5955
crate-type = ["rlib"]

0 commit comments

Comments
 (0)