【问题标题】:Kernel triple-faults after calling function调用函数后内核三重故障
【发布时间】:2013-04-15 03:11:28
【问题描述】:

我有两个函数在内核中运行,函数 A 和函数 B。函数 A 清除屏幕并将控制权传递给函数 B(它目前什么都不做)。当控制权返回给功能 A 时,会发生三重故障。 (这是 x86 Intel 语法)


功能A

function_a:
pop edx
push ebp
mov ebp, esp
sub esp, 8
push dword 0
pop eax
mov [ebp-4], eax
jmp .il_15
.il_7:
push dword 753664
mov eax, [ebp-4]
push eax
pop eax
pop ebx
add eax, ebx
push eax
push dword 0
pop eax
pop ebx
mov [ebx],al
mov eax, [ebp-4]
push eax
push dword 1
pop eax
pop ebx
add eax, ebx
push eax
pop eax
mov [ebp-4], eax
.il_15:
mov eax, [ebp-4]
push eax
push dword 4000
pop eax
pop ebx
cmp ebx, eax
jl .il_7
push dword 4
call function_b
jmp .methodend
.methodend:
add esp, 8
pop ebp
push edx
ret

功能 B

function_b:
pop edx
push ebp
mov ebp, esp
sub esp, 4
jmp .methodend ;This is just an empty function
.methodend:
add esp, 4
pop ebp
push edx
ret

我很确定我已经为每个函数正确设置了堆栈(弹出返回值、推送 ebp 等),所以我不确定是什么导致了崩溃

【问题讨论】:

    标签: assembly crash kernel nasm


    【解决方案1】:

    function_bfunction_a 中似乎没有任何内容在调用 function_b 之前清理压入堆栈的单词:

    push dword 4
    call function_b
    

    另外,function_b 会丢弃 edx 用于存储来自function_a 的返回地址。

    我不确定为什么这些函数有将返回地址弹出到edx 的模式,以便可以在返回之前将其推回 - 为什么不将返回地址完全留在堆栈上?如果您不想这样做,那么您需要在调用function_b 之前保存edx(可能通过将其压入堆栈)并在之后恢复它。

    【讨论】:

    • 我在通话后插入了add esp, 4,但仍然出现三重故障
    • 啊!我很笨。我将更改退货地址然后XD。
    猜你喜欢
    • 2020-06-10
    • 1970-01-01
    • 2016-07-24
    • 2021-02-28
    • 2012-10-14
    • 2016-11-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多