在 x86 中恢复 Stackframe
Restoring Stackframe in x86
我正在尝试编写一个将信号实现到 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_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));
谁能指出我正确的方向?
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));
}
我正在尝试编写一个将信号实现到 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_return(void)
.
我尝试恢复的框架是:
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));
谁能指出我正确的方向?
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));
}