Discussion:
Where is document for Win32 ABI?
(too old to reply)
J. L. Schilling
2004-01-04 14:45:41 UTC
Permalink
I've been looking for a document (from Microsoft or somebody)
that describes the Win32 application binary interface (ABI).
In particular, the compiled code conventions, such as stack
and frame layout, parameter passing (stdcall, cdecl, etc.),
structure layout, bit fields layout, and so forth. Also
something that describes DLL semantics at the ABI level.

I've done lots of web searches but haven't found any central
document that describes all of this. It must exist somewhere ...
I know where to find the equivalent documents for Unix systems,
but am stumped for Windows. Any URL pointers appreciated.

Jonathan
Boris Dynin
2004-01-04 15:48:45 UTC
Permalink
WIN32 was originally implemented as C API, although bindings for other
languages were added later.

1. WIN32 string parameters are always C strings: either ASCII (multi-byte)
or Unicode flavor.

2. All WIN32 functions are 'stdcall':
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vccore98/html/_core___stdcall.asp

3. Stack frame layout:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vccelng/htm/msmod_15.asp

4. Bit fields:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclang/html/_pluslang_c.2b2b_.bit_fields.asp

5. I'm not sure about where 'struct' alignment is covered. Basically, 16-bit
words are 16-bit aligned; similar for 32 bit.

As far as DLLs are concerned, there are no general rules on what calling
conventions to use (in order to call exported functions).

Boris
Post by J. L. Schilling
I've been looking for a document (from Microsoft or somebody)
that describes the Win32 application binary interface (ABI).
In particular, the compiled code conventions, such as stack
and frame layout, parameter passing (stdcall, cdecl, etc.),
structure layout, bit fields layout, and so forth. Also
something that describes DLL semantics at the ABI level.
I've done lots of web searches but haven't found any central
document that describes all of this. It must exist somewhere ...
I know where to find the equivalent documents for Unix systems,
but am stumped for Windows. Any URL pointers appreciated.
Jonathan
J. L. Schilling
2004-01-05 13:41:15 UTC
Permalink
Subject: Re: Where is document for Win32 ABI?
Date: 1/4/04 10:48 AM Eastern Standard Time
WIN32 was originally implemented as C API, although bindings for other
languages were added later.
1. WIN32 string parameters are always C strings: either ASCII (multi-byte)
or Unicode flavor.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vccore98
/html/_core___stdcall.asp
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vccelng/
htm/msmod_15.asp
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclang/h
tml/_pluslang_c.2b2b_.bit_fields.asp
5. I'm not sure about where 'struct' alignment is covered. Basically, 16-bit
words are 16-bit aligned; similar for 32 bit.
Thanks very much for these items and links.

But it still puzzles me that all of this can't be found in one
central document. Are writers of compilers, debuggers,
and similar tools really supposed to search through the
MSDN library for each individual answer they need?

Jonathan
Matti Vuori
2004-01-05 14:03:24 UTC
Permalink
Post by J. L. Schilling
But it still puzzles me that all of this can't be found in one
central document. Are writers of compilers, debuggers,
and similar tools really supposed to search through the
MSDN library for each individual answer they need?
Of course nobody is supposed to even write compilers etc. for Win32 -
Microsoft wouldn't mind if everyone uses Visual C++...
--
Matti Vuori, <http://sivut.koti.soon.fi/mvuori/index-e.htm>
Martijn
2004-01-05 16:37:17 UTC
Permalink
Post by J. L. Schilling
But it still puzzles me that all of this can't be found in one
central document. Are writers of compilers, debuggers,
and similar tools really supposed to search through the
MSDN library for each individual answer they need?
What's holdin' ya back? :)

Martijn
http://www.sereneconcepts.nl
Norman Black
2004-01-05 20:55:41 UTC
Permalink
I have developed Modula-2, Pascal and Ada compilers for windows and this
is how I would describe the windows calling convention.

Procedure parameter pass, function return and register preservation is
the Microsoft "stdcall" convention.

There is no defined stack frame convention. You can do has you please,
but everybody basically does it the same way. Various Microsoft
"internal" calls such as exception frame unwinding depend on the
convention the Microsoft C compiler uses.

Structure layout. With few exceptions, which are maintained due to
legacy, Microsoft never depends on the compiler to pad/align structure
fields. They arrange and have their own manual padding fields to get
proper alignment. This basically means a packed structure works. Better
safe that sorry though, because of the exceptions. The field alignment
is obvious. 1=byte integer => 1-byte alignment, 2 => 2, 4 => 4. 4-byte
real => 4. 8-byte real => 8.

Microsoft generally avoids bitfields, due to other languages not having
bitfields. Example languages would be the ones I have developed. There
are some old exceptions, which still exist due to legacy. For this there
is no defined structure except "what the Microsoft C compiler does".

What do you mean by DLL semantics. If you mean resolving exported symbol
names then there is no need for semantics since in the Windows world one
references DLL symbols to specific DLLs. For example in the Unix world
an applications "imports" an external symbol. Exactly what shared object
that symbol comes from is not defined. It could be any shared object
that the application references. In Windows if I import the symbol API
CreateWindowEx, it always comes from the USRE32.dll, unless you are not
using the standard DLL resolution library files.

--
Norman Black
Stony Brook Software
Post by J. L. Schilling
I've been looking for a document (from Microsoft or somebody)
that describes the Win32 application binary interface (ABI).
In particular, the compiled code conventions, such as stack
and frame layout, parameter passing (stdcall, cdecl, etc.),
structure layout, bit fields layout, and so forth. Also
something that describes DLL semantics at the ABI level.
I've done lots of web searches but haven't found any central
document that describes all of this. It must exist somewhere ...
I know where to find the equivalent documents for Unix systems,
but am stumped for Windows. Any URL pointers appreciated.
Jonathan
Continue reading on narkive:
Loading...