这个 __usercall 包装器有什么问题?
/*
* Wrapper from
* int func(int a, int b, int c, unsigned int d, signed int e);
* to
* int __usercall func<eax>(int a<eax>, int b<ecx>, int c, unsigned int d, signed int e);
*/
int func(int a, int b, int c, unsigned int d, signed int e)
{
__asm
{
push e
push d
push c
mov ecx, b
mov eax, a
call __usercall_func // access violation somewhere inside here
add esp, 12
}
}
/*
* Wrapper from
* int func(int a, int b, int c, unsigned int d, signed int e);
* to
* int __usercall func<eax>(int a<eax>, int b<ecx>, int c, unsigned int d, signed int e);
*/
int func(int a, int b, int c, unsigned int d, signed int e)
{
__asm
{
push e
push d
push c
mov ecx, b
mov eax, a
call __usercall_func // access violation somewhere inside here
add esp, 12
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您无法在内联 asm 块中自行执行 ret,因为您不知道外部函数对堆栈指针做了什么。相反,您需要安排汇编代码将返回值保留在局部变量中,包装函数可以使用普通的 C
return
语句返回该变量。您可能还需要在从 __usercall_func 返回后修复堆栈指针,除非它使用不正当的调用约定,将自己的参数从堆栈中弹出。
You cannot perform
ret
yourself from within an inline asm block, because you don't know what the outer function has done with the stack pointer. Instead you need to arrange for the assembly code to leave the return value in a local variable, which the wrapper function can return with the normal Creturn
statement.You also probably need to fix the stack pointer after the return from
__usercall_func
, unless it uses a perverse calling convention where it pops its own parameters off the stack.