[英]Is it correct to perform a function call like this?
我有一个32位值的数组( nativeParameters
长度为nativeParameterCount
)和一个指向函数的指针( void*
到cdecl函数,这里是method->nativeFunction
),它应该被调用。 现在我正在尝试这样做:
// Push parameters for call
if (nativeParameterCount != 0) {
uint32_t count = 0;
pushParameter:
uint32_t value = nativeParameters[nativeParameterCount - count - 1];
asm("push %0" : : "r"(value));
if (++count < nativeParameterCount) goto pushParameter;
}
// Call method
asm("call *%0" : : "r"(method->nativeFunction));
// Return value
uint32_t eax;
uint32_t edx;
asm("push %eax");
asm("push %edx");
asm("pop %0" : "=r"(edx));
asm("pop %0" : "=r"(eax));
uint64_t returnValue = eax;
// If the typesize of the methods return type is >4 bytes, or with EDX
Type returnType = method->returnType.type;
if (TYPE_SIZES[returnType] > 4) {
returnValue |= (((uint64_t) edx) << 32);
}
// Clean stack
asm("add %%esp, %0" : : "r"(parameterByteSize));
此方法是否适合执行本机调用(假设所有目标函数仅接受32位值作为参数)? 我可以确定它不会破坏堆栈或乱用寄存器,或者以某种方式影响正常流量吗? 此外,还有其他方法吗?
您可能希望使用dyncall libary来完成所有这些处理,而不是自己手动执行此操作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.