Re: Calling convention
- From: "xcal" <a@xxxxx>
- Date: Wed, 29 Oct 2008 06:46:59 -0300
hi Hongye, thanks for your good answer.
Yes, this explain my main doubt, it was a difficult for me because I don't know
anything about assembly language programming.
best regards, Carlos.
""Hongye Sun [MSFT]"" <hongyes@xxxxxxxxxxxxxxxxxxxx> wrote in message
news:DdZJ6hZOJHA.1644@xxxxxxxxxxxxxxxxxxxxxxxxx
Hi Carlos,
For calling conventions, cleaning stack means remove parameters info from
the stack. I will explain cdecl, stdcall and fastcall calling conventions
in detail to answer your question.
#1 cdecl
In this calling convention, the stack is cleaned by the calling code. So
the disassembly of calling code looks like:
---------------------------
CDeclFunction ( g_szCdeclCall , 1 , 'a' ) ;
push 61h
push 1
mov eax,[00403014]
push eax
call 0040105C
add esp,0Ch
---------------------------
The last line "add esp,0Ch" cleans the previous 3 parameters on the stack.
Here explains why it clears the stack:
http://en.wikibooks.org/wiki/Reverse_Engineering/The_Stack.
#2 stdcall
In this calling convention, the stack is cleaned in the called code. So the
disassembly of called code looks like:
---------------------------
void __stdcall StdCallFunction ( char * szString , unsigned long ulLong,
char chChar)
{
push ebp
mov ebp,esp
push ebx
push esi
push edi
__asm NOP __asm NOP
nop
nop
}
pop edi
pop esi
pop ebx
pop ebp
ret 0Ch
---------------------------
Like cdecl, the last line "ret 0Ch" clears 3 parameters on the stack.
#3 fastcall
In this calling convention, according to MSDN documentation at
http://msdn.microsoft.com/en-us/library/6xa169sk.aspx, it passes the first
two DWORD or smaller arguments are passed in ECX and EDX registers ; all
other arguments are passed right to left. The called function is
responsible for cleaning the arguments from the stack. Let's take a look of
its disassembly of called code:
---------------------------
void __fastcall FastCallFunction (char * szString, unsigned long ulLong,
char chChar)
{
push ebp
mov ebp,esp
sub esp,8
push ebx
push esi
push edi
mov dword ptr [ebp-8],edx
mov dword ptr [ebp-4],ecx
__asm NOP __asm NOP
nop
nop
}
pop edi
pop esi
pop ebx
mov esp,ebp
pop ebp
ret 4
---------------------------
In this fast call function, the first two parameters are passed in by ECX
and EDX, while the other one parameter is in the stack. In the end of the
fast call function, it cleans the last one parameter from the stack by
using "ret 4". However, it doesn't clear the first two parameters in ECX
and EDX.
So the conclusion is that all the three calling conventions only clean the
parameters from the stack. Does that answer your question? Please let me
know. Thanks.
Regards,
Hongye Sun (hongyes@xxxxxxxxxxxxxxxxxxxx, remove 'online.')
Microsoft Online Community Support
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
msdnmg@xxxxxxxxxxxxxx
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subscriptions/aa948868.aspx#notifications.
Note: MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 2 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions. Issues of this
nature are best handled working with a dedicated Microsoft Support Engineer
by contacting Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/en-us/subscriptions/aa948874.aspx
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
.
- References:
- Calling convention
- From: xcal
- RE: Calling convention
- From: "Hongye Sun [MSFT]"
- Calling convention
- Prev by Date: RE: Calling convention
- Next by Date: Re: Access to signature of a DLL accessed by PInvoke
- Previous by thread: RE: Calling convention
- Next by thread: Re: Access to signature of a DLL accessed by PInvoke
- Index(es):
Relevant Pages
|
Loading