2011年9月16日 星期五

System Call

System call
- System call 也是一種interrupt, 早期是利用int 0x80來產生software interrupt
- the dispatch routine 就是interrupt handler, Linux check arch/x86/kernel/syscall_table_32.S去執行對應到的function, or interrupt handler.
-  interrupt 的index存在eax, 然後開始執行

有兩種方法
1. int 0x80, iret (把syscall當作一種interrupt, 但比較慢)
“The int assembly language instruction is inherently slow because it performs several consistency and security checks. (The instruction is described in detail in the section "Hardware Handling of Interrupts and Exceptions" in Chapter 4.)”

2. Intel Pentium II 之後支援 instruction: sysenter / sysexit (比較快 但不是每個processor都支援)
These instructions use MSRs (machine specific registers) to store: (多利用三個register去儲存)
- Syscall entry point and code segment
- Kernel stack
- Syscall return address

好處 :
1. Indeed faster than int instruction
2. Security arguments:
- Easier to sandbox a program (prevent illegal system calls) 
- Limits ability of a program to issue errant system calls

壞處: Programmer inconvenience
1. Can’t just drop an ‘int 0x80’ in my program anymore
2. Tighter contract between program and kernel
3. Also, not all x86 CPUs have this instruction

Reference: CSE506 slides interrupt.pdf

沒有留言:

張貼留言