Understanding the linux kernel-ch4-Exception Handling

Exception handlers have a standard structure consisting of three steps:
1.     Save the contents of most registers in the Kernel Mode stack (this part is coded in assembly language).
2.     Handle the exception by means of a high-level C function.



3.     Exit from the handler by means of the ret_from_exception( ) function.












trap_init( )//i386/kernel/traps.c















doublefault_fn() //i386/kernel/doublefault.c
























Saving the Registers for the Exception Handler





    handler_name:







        pushl $0 /* only for some exceptions */





        pushl $do_handler_name






        jmp error_code

















error_code: 







1. Saves the registers that might be used by the high-level C function on the stack.

2. Issues a cld instruction to clear the direction flag DF of eflags , 


   thus making sure that autoincreases on the edi and esi registers will be used with string instructions 
3. Copies the hardware error code saved in the stack at location esp+36 in edx. 


   Stores the value -1 in the same stack location




   this value is used to separate 0x80 exceptions from other exceptions.


4. Loads edi with the address of the high-level do_handler_name( ) C function


    saved in the stack at location esp+32; writes the contents of es in that stack location

5. Loads in the eax register the current top location of the Kernel Mode stack. 


   This address identifies the memory cell containing the last register value saved in step 1

6. Loads the user data Segment Selector into the ds and es registers.


7. Invokes the high-level C function whose address is now stored in edi












Entering and Leaving the Exception Handler





do_trap() 







store the hardware error code and the exception vector in the process descriptor of current, 

and then send a suitable signal to that process:




current->thread.error_code = error_code;





    current->thread.trap_no = vector;





    force_sig(sig_number, current);
















ret_from_exception()

















most exceptions are handled simply by sending a Unix signal to the process that caused the exception.
The action to be taken is thus deferred until the process receives the signal; as a result, 
the kernel is able to process the exception quickly      
          
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值