PEXCEPTION_ROUTINE is a SEH handler function in which callee does not pop
passed arguments, so it should have __cdecl keyword.

In MS DDK this PEXCEPTION_ROUTINE type definition in ntdef.h was without an
explicit calling convention up to the (including) DDK 3790.1830 (Windows
Server 2003 with Service Pack 1 DDK), which correspondents to __cdecl.

Starting from WDK 6000 (Windows Driver Kit for Windows Vista) there is
NTAPI marker (which is __stdcall calling convention). MS probably added it
here because no one was defined and most NT functions are using __stdcall.
This is fine for AMD64 where both __stdcall and __cdecl are aliases, but it
is incorrect for I386.

In all I386 CRT libraries are all known I386 SEH handlers
(_except_handler2, _except_handler3, _except_handler4_common) of
PEXCEPTION_ROUTINE type using __cdecl calling convention. This can be
simple verified by gendef or examining output of objdump.

So fix the incorrect calling convention marker for PEXCEPTION_ROUTINE in
ntdef.h and winnt.h files. This fixes compile warnings generated by gcc
that calling convention mismatch when trying to assign SEH handler function
into the EXCEPTION_REGISTRATION_RECORD.Handler structure member.

And also throw compile warning in case user code incorrectly define calling
convention for its own SEH handler function.

Note that excpt.h header file has also defined PEXCEPTION_REGISTRATION
structure and this definition is already without the __stdcall marker.
---
 mingw-w64-headers/include/ntdef.h | 2 +-
 mingw-w64-headers/include/winnt.h | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/mingw-w64-headers/include/ntdef.h 
b/mingw-w64-headers/include/ntdef.h
index e8470243669d..f083abd1a9a2 100644
--- a/mingw-w64-headers/include/ntdef.h
+++ b/mingw-w64-headers/include/ntdef.h
@@ -723,7 +723,7 @@ struct _EXCEPTION_RECORD;
 #ifndef __PEXCEPTION_ROUTINE_DEFINED
 #define __PEXCEPTION_ROUTINE_DEFINED
 typedef EXCEPTION_DISPOSITION
-(NTAPI *PEXCEPTION_ROUTINE)(
+(__cdecl *PEXCEPTION_ROUTINE)(
   struct _EXCEPTION_RECORD *ExceptionRecord,
   PVOID EstablisherFrame,
   struct _CONTEXT *ContextRecord,
diff --git a/mingw-w64-headers/include/winnt.h 
b/mingw-w64-headers/include/winnt.h
index 188234a1c904..c713e122e55b 100644
--- a/mingw-w64-headers/include/winnt.h
+++ b/mingw-w64-headers/include/winnt.h
@@ -735,7 +735,7 @@ __MINGW_CXX14_CONSTEXPR inline ENUMTYPE& operator ^= 
(ENUMTYPE& a, ENUMTYPE b) {
 #define RTL_BITS_OF_FIELD(type,field) (RTL_BITS_OF(RTL_FIELD_TYPE(type,field)))
 #define CONTAINING_RECORD(address,type,field) ((type *)((PCHAR)(address) - 
(ULONG_PTR)(&((type *)0)->field)))
 
-    typedef EXCEPTION_DISPOSITION NTAPI EXCEPTION_ROUTINE (struct 
_EXCEPTION_RECORD *ExceptionRecord, PVOID EstablisherFrame, struct _CONTEXT 
*ContextRecord, PVOID DispatcherContext);
+    typedef EXCEPTION_DISPOSITION __cdecl EXCEPTION_ROUTINE (struct 
_EXCEPTION_RECORD *ExceptionRecord, PVOID EstablisherFrame, struct _CONTEXT 
*ContextRecord, PVOID DispatcherContext);
 #ifndef __PEXCEPTION_ROUTINE_DEFINED
 #define __PEXCEPTION_ROUTINE_DEFINED
     typedef EXCEPTION_ROUTINE *PEXCEPTION_ROUTINE;
-- 
2.20.1



_______________________________________________
Mingw-w64-public mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public

Reply via email to