11//! This module is responsible for handling CPU exceptions.
22
33use core:: mem:: offset_of;
4- use core:: { alloc:: Layout , arch:: asm, ptr:: null_mut} ;
4+ use core:: {
5+ alloc:: Layout ,
6+ arch:: { asm, naked_asm} ,
7+ ptr:: null_mut,
8+ } ;
59
610use crate :: spin:: lazy:: Lazy ;
711use alloc:: alloc:: alloc;
@@ -165,7 +169,7 @@ pub fn load_idt() {
165169#[ naked]
166170extern "x86-interrupt" fn divide_error_handler ( frame : InterruptStackFrame ) {
167171 unsafe {
168- asm ! (
172+ naked_asm ! (
169173 // Check whether the exception happened in userspace.
170174 "test word ptr [rsp+16], 3" ,
171175 "je {kernel_divide_error_handler}" ,
@@ -180,7 +184,6 @@ extern "x86-interrupt" fn divide_error_handler(frame: InterruptStackFrame) {
180184 kernel_divide_error_handler = sym kernel_divide_error_handler,
181185 VECTOR_OFFSET = const offset_of!( PerCpu , vector) ,
182186 HANDLER_OFFSET = const offset_of!( PerCpu , userspace_exception_exit_point) ,
183- options( noreturn) ,
184187 ) ;
185188 }
186189}
@@ -195,7 +198,7 @@ extern "x86-interrupt" fn page_fault_handler(
195198 error_code : PageFaultErrorCode ,
196199) {
197200 unsafe {
198- asm ! (
201+ naked_asm ! (
199202 // Check whether the exception happened in userspace.
200203 "test word ptr [rsp+16], 3" ,
201204 "je 66f" ,
@@ -256,7 +259,6 @@ extern "x86-interrupt" fn page_fault_handler(
256259 VECTOR_OFFSET = const offset_of!( PerCpu , vector) ,
257260 ERROR_CODE_OFFSET = const offset_of!( PerCpu , error_code) ,
258261 HANDLER_OFFSET = const offset_of!( PerCpu , userspace_exception_exit_point) ,
259- options( noreturn) ,
260262 ) ;
261263 }
262264}
@@ -300,7 +302,7 @@ extern "x86-interrupt" fn general_protection_fault_handler(
300302 error_code : u64 ,
301303) {
302304 unsafe {
303- asm ! (
305+ naked_asm ! (
304306 // Check whether the exception happened in userspace.
305307 "test word ptr [rsp+16], 3" ,
306308 "je {kernel_general_protection_fault_handler}" ,
@@ -317,7 +319,6 @@ extern "x86-interrupt" fn general_protection_fault_handler(
317319 VECTOR_OFFSET = const offset_of!( PerCpu , vector) ,
318320 ERROR_CODE_OFFSET = const offset_of!( PerCpu , error_code) ,
319321 HANDLER_OFFSET = const offset_of!( PerCpu , userspace_exception_exit_point) ,
320- options( noreturn) ,
321322 ) ;
322323 }
323324}
@@ -336,7 +337,7 @@ extern "x86-interrupt" fn double_fault_handler(frame: InterruptStackFrame, code:
336337#[ naked]
337338extern "x86-interrupt" fn vc_handler ( frame : InterruptStackFrame , error_code : u64 ) {
338339 unsafe {
339- asm ! (
340+ naked_asm ! (
340341 // Check whether the exception happened in userspace.
341342 "test word ptr [rsp+16], 3" ,
342343 "je {kernel_vc_handler}" ,
@@ -353,15 +354,14 @@ extern "x86-interrupt" fn vc_handler(frame: InterruptStackFrame, error_code: u64
353354 VECTOR_OFFSET = const offset_of!( PerCpu , vector) ,
354355 ERROR_CODE_OFFSET = const offset_of!( PerCpu , error_code) ,
355356 HANDLER_OFFSET = const offset_of!( PerCpu , userspace_exception_exit_point) ,
356- options( noreturn) ,
357357 ) ;
358358 }
359359}
360360
361361#[ naked]
362362extern "x86-interrupt" fn kernel_vc_handler ( frame : InterruptStackFrame , code : u64 ) {
363363 unsafe {
364- asm ! (
364+ naked_asm ! (
365365 "push r11" ,
366366 "push r10" ,
367367 "push r9" ,
@@ -390,7 +390,6 @@ extern "x86-interrupt" fn kernel_vc_handler(frame: InterruptStackFrame, code: u6
390390 "add rsp, 8" , // skip error code.
391391 "iretq" ,
392392 kernel_vc_handler_impl = sym kernel_vc_handler_impl,
393- options( noreturn)
394393 ) ;
395394 }
396395}
@@ -464,13 +463,12 @@ extern "x86-interrupt" fn int0x80_handler(frame: InterruptStackFrame) {
464463 // The code that entered userspace stored addresses where execution should
465464 // continue when userspace exits.
466465 unsafe {
467- asm ! (
466+ naked_asm ! (
468467 "swapgs" ,
469468 "mov byte ptr gs:[{VECTOR_OFFSET}], 0x80" ,
470469 "jmp gs:[{HANDLER_OFFSET}]" ,
471470 VECTOR_OFFSET = const offset_of!( PerCpu , vector) ,
472471 HANDLER_OFFSET = const offset_of!( PerCpu , userspace_exception_exit_point) ,
473- options( noreturn)
474472 ) ;
475473 }
476474}
0 commit comments