Saturday 15 August 2015

c++ - Call naked function from one to another? -



c++ - Call naked function from one to another? -

when seek phone call declspec(naked) function function, error according function prototype must returns value when seek homecoming value error says naked function not homecoming value.

__declspec(naked) void bar() { __asm { nop ret } } __declspec(naked) ntstatus winapi foo(int a, int b) { bar(); homecoming ntstatus(1); }

all of reasonable because naked functions dont create stackframe function, hence calling function error unless programmer explicitly creates stackframe. when seek create stackframe , stack alignment in right way error.

how can phone call naked function correctly?

naked functions don't back upwards homecoming statements

the next rules , limitations apply naked functions:

the homecoming statement not permitted.

you should deal stack frame and homecoming value yourself, e.g.

__declspec( naked ) void bar() { __asm { nop ret } } __declspec(naked) bool foo(int a, int b) { bar(); __asm { mov al,1 ret } } int main() { bool return_value = foo(2, 2); std::cout << return_value; // 1 }

c++ c assembly

No comments:

Post a Comment