Chinaunix

标题: iret指令报错:general protection fault fffc [打印本页]

作者: hellolwq    时间: 2012-08-02 16:39
标题: iret指令报错:general protection fault fffc
本帖最后由 hellolwq 于 2012-08-02 16:51 编辑

我有一个内核模块((2.6.30 x86_64))手动调用iret,权限不变(ring->ring0),按照intel手册,进行了五个参数依序的压栈。但运行时,在iret处还是报了下面的错误:

general protection fault:fffc[#] SMP


代码如下:
  1. asm volatile(
  2.     "mov %%ss,%%ax \n\t"
  3.     "push %%rax \n\t"/*ss*/
  4.     "push %%rsp \n\t"/*rsp*/
  5.     "pushfq \n\t"/*rflags*/
  6.     "mov %%cs,%%ax \n\t"
  7.     "push %%rax \n\t"/*cs*/
  8.     "mov $._restart_code,%%rax \n\t"
  9.     "push %%rax \n\t"/*rip*/
  10.     "iret \n\t"/*here is the fault rip!!!!!!*/
  11.     "._restart_code:"
  12.     "nop" :);
复制代码

作者: hellolwq    时间: 2012-08-02 20:20
本帖最后由 hellolwq 于 2012-08-02 20:29 编辑

有两个错误:
1、64位下用iretq
2、使用了已经改变的rsp值,应该在所有PUSH之前保存RSP。
  1. asm volatile(
  2.         "mov %%rsp,%%rbx \n\t"/*####*/
  3.         "mov %%ss,%%ax \n\t"
  4.         "push %%rax \n\t"/*ss*/
  5.         "push %%rbx \n\t"/*rsp*/
  6.         "pushfq \n\t"/*rflags*/
  7.         "mov %%cs,%%ax \n\t"
  8.         "push %%rax \n\t"/*cs*/
  9.         "mov $._restart_code,%%rax \n\t"
  10.         "push %%rax \n\t"/*rip*/
  11.         "iretq \n\t"/*####*/
  12.         "._restart_code:"
  13.         "nop" :);
复制代码
都是新手犯下的错误啊,谨记教训!




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2