2

我正在尝试编写一个将信号实现到 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));

谁能指出我正确的方向?

4

1 回答 1

2
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)); 
}
于 2016-10-19T02:31:16.030 回答