首页软件新闻工具软件操作系统办公软件聊天工具多媒体网页制作网页设计网站运营平面设计作品欣赏数据库程序组网
Ghost | Kugoo | 遨游 | Xp | Dw | Fw | Flash | Ps | 迅雷 | CD | ill | CAD | 五笔 | Word | Excel | Wps | Msn | QQ | 学电脑 | Asp | Php | Jsp | 3Dmax | 海报 | 包装 | 标志 | 地产 | 插画

Linux操作系统下糟糕的异常处理方式

来源:天极(读取中...) 2006-11-21 【字体: 】 切换为

  搜索异常处理程序代码文件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; 
}

  看看上面搜索异常处理程序的算法就知道了,有个异常模块表,保存会发生异常时候的eip和异常处理程序指针,发生异常的时候就根据异常时候的 eip搜索表里面的eip,发现相等就找到了异常处理指针。这是什么意思呢,就是说你编写的内核程序必须精确的知道哪条指令可能会发生异常,要求真够高的。想想windows下的异常编程是多么轻松?程序员只需要知道哪一段程序可能出现异常,就只需要一个括号一个异常语句保护这段程序就是了。

光看上面算法可能对其这异常的处理还没怎么有感性认识,那么我们再看看其内核的异常形式、编写方式吧。

上一页  [1] [2] [3] 下一页

    相关新闻
    用户评论
数据载入中,请稍后……
评论内容:不能超过250字,不需审核,请自觉遵守互联网相关政策法规。
发表评论: 匿名发表 用户名: loading 位网友发表了评论 查看评论
(0/250)
    推广服务
IT部落推荐阅读
·生活服务
·精彩图文
·赞助商链接