在x86中恢复Stackframe
我正在尝试编写一个程序,将信号实现到xv6中 我已经知道了如何操作堆栈(我想),但是我在恢复它时遇到了困难。以下是我的信号传递代码: 此函数将信号帧添加到进程堆栈中,并保存易失性寄存器在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
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));
}