📄 002_arch_i386_mm_extabl.html
字号:
<html lang="zh-CN" xmlns:gdoc=""> <head> <meta content="text/html; charset=utf-8" http-equiv="Content-Type"> <style type="text/css">/* default css */table { font-size: 1em; line-height: inherit;}div, address, ol, ul, li, option, select { margin-top: 0px; margin-bottom: 0px;}p { margin: 0px;}body { margin: 0px; padding: 0px; font-family: Verdana, sans-serif; font-size: 10pt; background-color: #ffffff;}h6 { font-size: 10pt }h5 { font-size: 11pt }h4 { font-size: 12pt }h3 { font-size: 13pt }h2 { font-size: 14pt }h1 { font-size: 16pt }blockquote {padding: 10px; border: 1px #DDD dashed }a img {border: 0}div.google_header, div.google_footer { position: relative; margin-top: 1em; margin-bottom: 1em;}/* end default css */ /* default print css */ @media print { body { padding: 0; margin: 0; } div.google_header, div.google_footer { display: block; min-height: 0; border: none; } div.google_header { flow: static(header); } /* used to insert page numbers */ div.google_header::before, div.google_footer::before { position: absolute; top: 0; } div.google_footer { flow: static(footer); } /* always consider this element at the start of the doc */ div#google_footer { flow: static(footer, start); } span.google_pagenumber { content: counter(page); } span.google_pagecount { content: counter(pages); } } @page { @top { content: flow(header); } @bottom { content: flow(footer); } } /* end default print css */ /* custom css *//* end custom css */ /* ui edited css */ body { font-family: Verdana; font-size: 10.0pt; line-height: normal; background-color: #ffffff; } .documentBG { background-color: #ffffff; } /* end ui edited css */</style> </head> <body revision="dcbsxfpf_43c5mmszfc:7"> <table align=center cellpadding=0 cellspacing=0 height=5716 width=768>
<tbody>
<tr>
<td height=5716 valign=top width=802>
<pre>2005-10-17 <br> 简介:<br> 内核总要和用户打交道,比如从用户提供的buffer中拷贝数据等等。为了保证kernel的安<br>全,这种操作需要格外小心。 有可能用户提供的buffer没有初始化,或者是空指针,无论如何内<br>核都应该能应对这种事情。<br> 看一个例子,arch/i386/lib/usercopy.c<br><br>#define __do_strncpy_from_user \<br>do { \<br> int __d0, __d1, __d2; \<br> __asm__ __volatile__( \<br> " testl %1,%1\n" \<br> " jz 2f\n" \<br> "0: lodsb\n" \<br> " stosb\n" \<br> " testb %%al,%%al\n" \<br> " jz 1f\n" \<br> " decl %1\n" \<br> " jnz 0b\n" \<br> "1: subl %1,%0\n" \<br> "2:\n" \<br> ".section .fixup,\"ax\"\n" \<br> "3: movl %5,%0\n" \<br> " jmp 2b\n" \<br> ".previous\n" \<br> ".section __ex_table,\"a\"\n" \<br> " .align 4\n" \<br> " .long 0b,3b\n" \<br> ".previous" \<br> : "=d"(res), "=c"(count), "=&a" (__d0), "=&S" (__d1), \<br> "=&D" (__d2) \<br> : "i"(-EFAULT), "0"(count), "1"(count), "3"(src), "4"(dst) \<br> : "memory"); \<br>} while (0)<br><br> 首先注意到.section .fixup 链接指令将修复内核的代码放入代码断.fixup, 将一个对应<br>关系 0b,3b(这是内嵌汇编的label)放入section __ex_table, 意思是说,如果0b出现page fault,<br>GP错误等就跳转到3b执行.<br><br> 而/arch/i386/extable.c正是实现在__ex_table中查找0b返回3b的功能.代码极为简单不再<br>列举代码. 只是注意,内核模块也是内核的一部分,也会有这种事情需要处理,这个文件中也有对模<br>块进行搜索查找. <br><br> 文件提供的函数search_exception_table在do_page_fault,do_trap,do_general_protection<br>都有使用,正是这一机制的具体实现.<br><br> <br> <br> <br></pre>
</td>
</tr>
</tbody>
</table></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -