gpt4 book ai didi

c - 在 x86 中恢复 Stackframe

转载 作者:太空宇宙 更新时间:2023-11-03 23:20:54 27 4
gpt4 key购买 nike

我正在尝试编写一个将信号实现为 xv6 的程序

我已经弄清楚如何操纵堆栈(我认为),但我只是无法恢复它。这是我的信号传递代码:

此函数将信号帧添加到进程堆栈并保存 volatile 寄存器

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));
}

关于c - 在 x86 中恢复 Stackframe,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40052706/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com