QUOTE: |
文件:entry.S: ENTRY(general_protection) pushl $ SYMBOL_NAME(do_general_protection) jmp error_code 這是異常中斷入口,顯然會執行do_general_protection。文件traps.c: asmlinkage void do_general_protection(struct pt_regs * regs, long error_code) { if (regs->eflags & VM_MASK) goto gp_in_vm86; /* 虛擬8086下發生的異常否 */ if (!(regs->xcs & 3)) goto gp_in_kernel; /* 內核發生的異常否 */ current->tss.error_code = error_code; current->tss.trap_no = 13; force_sig(SIGSEGV, current); /* 用戶程序發生的異常,產生異常信號, 根據異常信號的句柄回調處理函數 */ return; gp_in_vm86: lock_kernel(); handle_vm86_fault((struct kernel_vm86_regs *) regs, error_code); /* 虛擬8086的處理 */ unlock_kernel(); return; gp_in_kernel: { unsigned long fixup; fixup = search_exception_table(regs->eip); /* 根據異常時的eip搜索異常結構鏈 找到處理程序地址 */ if (fixup) { regs->eip = fixup; /* 找到異常處理地址,修改中斷返回地址,中斷返回時跳到異常處理程序處 */ return; } die("general protection fault", regs, error_code); /* 沒找到異常處理程序地址,顯示內核異常信息后死機 */ } } 搜索異常處理程序代碼文件extable.c: extern const struct exception_table_entry __start___ex_table[]; extern const struct exception_table_entry __stop___ex_table[]; unsigned long search_exception_table(unsigned long addr) { unsigned long ret; #ifndef CONFIG_MODULES /* There is only the kernel to search. */ ret = search_one_table(__start___ex_table, __stop___ex_table-1, addr); if (ret) return ret; #else /* The kernel is the last "module" -- no need to treat it special. */ struct module *mp; for (mp = module_list; mp != NULL; mp = mp->next) { if (mp->ex_table_start == NULL) continue; ret = search_one_table(mp->ex_table_start, mp->ex_table_end - 1, addr); if (ret) return ret; } #endif return 0; } static inline unsigned long search_one_table(const struct exception_table_entry *first, const struct exception_table_entry *last, unsigned long value) { while (first <= last) { const struct exception_table_entry *mid; long diff; mid = (last - first) / 2 + first; diff = mid->insn - value; if (diff == 0) return mid->fixup; else if (diff < 0) first = mid+1; else last = mid-1; } return 0; } |
[火星人 ] 在Linux中很不正常的異常處理方式已經有494次圍觀