有什么不对这个__usercall包装? [英] What is wrong with this __usercall wrapper?

查看:262
本文介绍了有什么不对这个__usercall包装?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  / *
 *从包装
 * INT FUNC(int类型的,INT B,INT C,无符号整型D,符号整数E);
 * 至
 * INT __usercall FUNC<&EAX GT;(INT A< EAX>中INT B< ECX>中诠释三,无符号整型D,符号整数E);
 * /
INT FUNC(int类型的,INT B,INT C,无符号整型D,符号整型E)
{
    __asm
    {
        推送
        推ð
        推ç
        MOV ECX,B
        MOV EAX,一
        地方叫__usercall_func //访问冲突内这里
        ADD ESP,12
    }
}


解决方案

您不能执行 RET 自己从内联汇编块内,因为你不知道什么外部函数堆栈指针完成。相反,你需要为大会code安排留在一个局部变量的返回值,该包装函数可以用普通的C返回收益语句。

您还可能需要从 __ usercall_func 回归后修正堆栈指针,除非它使用它弹出自己的参数从堆栈中反常调用约定。

/*
 * 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
    }
}

解决方案

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 C return 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.

这篇关于有什么不对这个__usercall包装?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆