Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/67.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在x86中恢复Stackframe_C_X86_Xv6 - Fatal编程技术网

在x86中恢复Stackframe

在x86中恢复Stackframe,c,x86,xv6,C,X86,Xv6,我正在尝试编写一个程序,将信号实现到xv6中 我已经知道了如何操作堆栈(我想),但是我在恢复它时遇到了困难。以下是我的信号传递代码: 此函数将信号帧添加到进程堆栈中,并保存易失性寄存器 void signal_deliver(int signum) { *((uint*) (proc->tf->esp-4)) = proc->tf->eip; *((uint*) (proc->tf->esp-8)) = proc->tf->eax; *((uint

我正在尝试编写一个程序,将信号实现到xv6中

我已经知道了如何操作堆栈(我想),但是我在恢复它时遇到了困难。以下是我的信号传递代码:

此函数将信号帧添加到进程堆栈中,并保存易失性寄存器

void signal_deliver(int signum)
{
*((uint*) (proc->tf->esp-4)) = proc->tf->eip;
*((uint*) (proc->tf->esp-8)) = proc->tf->eax;
*((uint*) (proc->tf->esp-12)) = proc->tf->ecx;
*((uint*) (proc->tf->esp-16)) = proc->tf->edx;
*((uint*) (proc->tf->esp-20)) = signum;
*((uint*) (proc->tf->esp-24)) = *(uint*) proc -> signal_trampoline;
proc->tf->esp = proc->tf->esp-24;
proc->tf->eip = (uint) (proc->signal_handlers[signum]);
}
在我的
void signal\u return(void)
中恢复trapframe进程时遇到问题

我尝试还原帧的步骤是:

    proc->tf->esp = proc->tf->esp + 24;
    *((uint*)(proc->tf->esp - 16)) = proc->tf->esp;
    *((uint*)(proc->tf->esp - 12)) = proc->tf->esp;
    *((uint*)(proc->tf->esp - 8)) = proc->tf->esp;
    proc->tf->eip = *((uint*)(proc->tf->esp - 4));

谁能给我指出正确的方向吗

修复应该做什么?
proc->tf->esp=proc->tf->esp+24
将恢复
信号传递
的操作,最后一个
eip=
将恢复
eip
变量。但是,为什么要将堆栈指针本身写入已发布的堆栈中,在
eax/ecx/edx
存储在
signal\u deliver
中的位置?你不想恢复这些吗?即
proc->tf->eax=*((uint*)(proc->tf->esp-8))。。。(注意,我不知道代码中发生了什么,也不知道什么是
proc->tf
,如果这是实时的CPU regs,我想知道如何在不因中断而崩溃的情况下工作。)@Ped7g您能够帮助我理解如何实现
信号传递
谢谢。也许你想发布答案?我已经完成了,如果你不想,我可以把它作为答案发布。继续,发布工作解决方案。
void signal_return(void) {
    proc->tf->esp = proc->tf->esp + 24;
    proc->tf->edx = *((uint*)(proc->tf->esp - 16));
    proc->tf->ecx = *((uint*)(proc->tf->esp - 12));
    proc->tf->eax = *((uint*)(proc->tf->esp - 8));
    proc->tf->eip = *((uint*)(proc->tf->esp - 4)); 
}