spec files - syntax and generation
Shachar Shemesh
wine-devel at shemesh.biz
Tue Oct 28 15:26:14 CST 2003
Martin Tröster wrote:
>Hi,
>
>- Stdcall vs. cdecl
>How do I find out whether a function uses CDECL instead of STDCALL? I found the information (link lost unfortunately) that entries in the def file like testfunc1 at 0 are called via STDCALL, whereas in case of testfunc2 without any @ specifying the space is CDECL. Is this guess right? If not, how else do I find this out?
>
>
>
STDCALL means PASCAL call format. This means two things, mostly. First -
it means arguments are pushed on the stack left to right instead of
right to left (no way you can pass printf style variable length
arguments). The second is that it is the functions' responsibility,
rather than the caller, to remove the arguments from the stack.
With the C calling convention, if the caller places more arguments on
the stack than the function expects, nothing bad will happen. The same
caller (that presumably knows how much arguments there are on the stack)
releases the stack. As the arguments are pushed right to left, the first
argument is always in the same position in relation to the stack pointer
when calling the function. This means that if the function expects three
arguments, and the caller sends 4, noone will ever notice (assuming the
first three are understood correctly, of course).
With the Pascal calling convention, such a case is disastrous. As the
arguments are cleared by the called function, if it thinks there is a
different number or arguments on the stack than there really is, the
function will return to the caller with the stack pointer in the wrong
place. The program is most likely to crash the moment any further stack
activity takes place.
In order to avoid this problem, STDCALL functions mangle into the
function's name a number indicating the number of bytes the arguments
for the function take on the stack. This gives a certain assurance that
a mismatch between caller and callee notion of what the arguments are
will be translated into a linker failure, rather than inexplicable,
seemingly random, runtime crashes.
Warning: the following paragraph is pure guesswork. The long explanation
was just a way to say that your idea that symbols that have the form of
"name at number" are STDCALL symbols, while symobls that are pure name are
CDECL, seems the only way to understand things.
>Thanks again for any help!
>
>Cheers,
>Martin
>
>
Shachar
--
Shachar Shemesh
Open Source integration consultant
Home page & resume - http://www.shemesh.biz/
More information about the wine-devel
mailing list