All 32-bit Windows NT systems contains system OS library msvcrt40.dll which
should be compatible with the original Visual C++ 4.0/4.1 msvcrt40.dll library.

The Windows NT implementation of msvcrt40.dll is very simple, it just
redirects function calls via symbol forwarding to msvcrt.dll library.

Since Windows XP, the msvcrt.dll changed ABI of __getmainargs() and
__wgetmainargs() functions, and so it is required also for msvcrt40.dll
builds to include ABI fix code which is already used for msvcrt.dll builds.
Otherwise applications compiled with new mingw-w64 checks introduced since
commit 3e043834e993 ("crt: Check for return value from __(w)getmainargs()
calls") would crash on Windows XP+ systems if they would use the system
msvcrt40.dll library.

Windows systems do not provide msvcr40d.dll and neither msvcrtd.dll
libraries, so for these builds there is no need to do new wrappers.
But for simplification of our build system, which does not have separate
source file definitions for msvcrt40.dll and msvcr40d.dll, use same
wrappers also for msvcr40d.dll and msvcrtd.dll.
---
 mingw-w64-crt/Makefile.am                   |  8 ++++----
 mingw-w64-crt/lib32/msvcr40d.def.in         |  4 ++--
 mingw-w64-crt/lib32/msvcrt40.def.in         |  4 ++--
 mingw-w64-crt/lib32/msvcrtd.def.in          |  4 ++--
 mingw-w64-crt/misc/msvcrt40__getmainargs.c  | 20 --------------------
 mingw-w64-crt/misc/msvcrt40__wgetmainargs.c | 20 --------------------
 mingw-w64-crt/misc/msvcrt__getmainargs.c    |  6 ++++++
 mingw-w64-crt/misc/msvcrt__wgetmainargs.c   |  6 ++++++
 8 files changed, 22 insertions(+), 50 deletions(-)
 delete mode 100644 mingw-w64-crt/misc/msvcrt40__getmainargs.c
 delete mode 100644 mingw-w64-crt/misc/msvcrt40__wgetmainargs.c

diff --git a/mingw-w64-crt/Makefile.am b/mingw-w64-crt/Makefile.am
index 5f5655b3b96b..6c1919eb9199 100644
--- a/mingw-w64-crt/Makefile.am
+++ b/mingw-w64-crt/Makefile.am
@@ -848,8 +848,8 @@ src_msvcrt40=\
   $(src_pre_msvcr80) \
   $(src_pre_msvcr100) \
   $(src_pre_msvcr120) \
-  misc/msvcrt40__getmainargs.c \
-  misc/msvcrt40__wgetmainargs.c
+  misc/msvcrt__getmainargs.c \
+  misc/msvcrt__wgetmainargs.c
 
 src_msvcrtd=\
   $(src_pre_msvcr70) \
@@ -857,8 +857,8 @@ src_msvcrtd=\
   $(src_pre_msvcr80) \
   $(src_pre_msvcr100) \
   $(src_pre_msvcr120) \
-  misc/msvcrt40__getmainargs.c \
-  misc/msvcrt40__wgetmainargs.c
+  misc/msvcrt__getmainargs.c \
+  misc/msvcrt__wgetmainargs.c
 
 src_msvcr70=\
   $(src_pre_msvcr71) \
diff --git a/mingw-w64-crt/lib32/msvcr40d.def.in 
b/mingw-w64-crt/lib32/msvcr40d.def.in
index 590400770339..1590e659077b 100644
--- a/mingw-w64-crt/lib32/msvcr40d.def.in
+++ b/mingw-w64-crt/lib32/msvcr40d.def.in
@@ -1022,7 +1022,7 @@ __STRINGTOLD
 __dllonexit
 __doserrno
 __fpecode
-__msvcrt40_getmainargs == __getmainargs ; msvcr40d.dll's __getmainargs is 
incompatible with mingw-w64's __getmainargs, real __getmainargs provided by emu
+__msvcrt_getmainargs == __getmainargs ; msvcr40d.dll's __getmainargs is 
incompatible with mingw-w64's __getmainargs, real __getmainargs provided by emu
 __isascii
 __iscsym
 __iscsymf
@@ -1063,7 +1063,7 @@ __threadhandle
 __threadid
 __toascii
 __unDName
-__msvcrt40_wgetmainargs == __wgetmainargs ; msvcr40d.dll's __wgetmainargs is 
incompatible with mingw-w64's __wgetmainargs, real __wgetmainargs provided by 
emu
+__msvcrt_wgetmainargs == __wgetmainargs ; msvcr40d.dll's __wgetmainargs is 
incompatible with mingw-w64's __wgetmainargs, real __wgetmainargs provided by 
emu
 _abnormal_termination
 _access
 _adj_fdiv_m16i ; msvc symbol is without decoration but callee pop stack (like 
stdcall @4)
diff --git a/mingw-w64-crt/lib32/msvcrt40.def.in 
b/mingw-w64-crt/lib32/msvcrt40.def.in
index 80541502a0b6..a061b15a8a65 100644
--- a/mingw-w64-crt/lib32/msvcrt40.def.in
+++ b/mingw-w64-crt/lib32/msvcrt40.def.in
@@ -999,7 +999,7 @@ __STRINGTOLD
 __dllonexit
 __doserrno
 __fpecode
-__msvcrt40_getmainargs == __getmainargs ; msvcrt40.dll's __getmainargs is 
incompatible with mingw-w64's __getmainargs, real __getmainargs provided by emu
+__msvcrt_getmainargs == __getmainargs ; msvcrt40.dll's __getmainargs has same 
API as msvcrt.dll's __getmainargs, real __getmainargs provided by emu
 __isascii
 __iscsym
 __iscsymf
@@ -1037,7 +1037,7 @@ __threadhandle
 __threadid
 __toascii
 __unDName
-__msvcrt40_wgetmainargs == __wgetmainargs ; msvcrt40.dll's __wgetmainargs is 
incompatible with mingw-w64's __wgetmainargs, real __wgetmainargs provided by 
emu
+__msvcrt_wgetmainargs == __wgetmainargs ; msvcrt40.dll's __wgetmainargs has 
same API as msvcrt.dll's __wgetmainargs, real __wgetmainargs provided by emu
 _abnormal_termination
 _access
 _adj_fdiv_m16i ; msvc symbol is without decoration but callee pop stack (like 
stdcall @4)
diff --git a/mingw-w64-crt/lib32/msvcrtd.def.in 
b/mingw-w64-crt/lib32/msvcrtd.def.in
index 976374a29c3a..36e9fa45eda0 100644
--- a/mingw-w64-crt/lib32/msvcrtd.def.in
+++ b/mingw-w64-crt/lib32/msvcrtd.def.in
@@ -165,7 +165,7 @@ __crtLCMapStringA
 __dllonexit
 __doserrno
 __fpecode
-__msvcrt40_getmainargs == __getmainargs ; msvcrtd.dll's __getmainargs has same 
API as msvcrt40.dll's __getmainargs, real __getmainargs provided by emu
+__msvcrt_getmainargs == __getmainargs ; msvcrtd.dll's __getmainargs has same 
API as msvcr40d.dll's __getmainargs, real __getmainargs provided by emu
 __initenv DATA
 __isascii
 __iscsym
@@ -216,7 +216,7 @@ __toascii
 __unDName
 __unguarded_readlc_active DATA
 __wargv DATA
-__msvcrt40_wgetmainargs == __wgetmainargs ; msvcrtd.dll's __wgetmainargs has 
same API as msvcrt40.dll's __wgetmainargs, real __wgetmainargs provided by emu
+__msvcrt_wgetmainargs == __wgetmainargs ; msvcrtd.dll's __wgetmainargs has 
same API as msvcr40d.dll's __wgetmainargs, real __wgetmainargs provided by emu
 __winitenv DATA
 _abnormal_termination
 _access
diff --git a/mingw-w64-crt/misc/msvcrt40__getmainargs.c 
b/mingw-w64-crt/misc/msvcrt40__getmainargs.c
deleted file mode 100644
index ae65f442bc08..000000000000
--- a/mingw-w64-crt/misc/msvcrt40__getmainargs.c
+++ /dev/null
@@ -1,20 +0,0 @@
-/**
- * This file has no copyright assigned and is placed in the Public Domain.
- * This file is part of the mingw-w64 runtime package.
- * No warranty is given; refer to the file DISCLAIMER.PD within this package.
- */
-
-#include <internal.h>
-
-/* Define __getmainargs() function via msvcrt40.dll __getmainargs() function */
-_CRTIMP void __cdecl __msvcrt40_getmainargs(int *argc, char ***argv, char 
***envp, int expand_wildcards, _startupinfo *startup_info);
-int __cdecl __getmainargs(int *argc, char ***argv, char ***envp, int 
expand_wildcards, _startupinfo *startup_info)
-{
-  /*
-   * msvcrt40.dll's __getmainargs() function terminates process on error.
-   * If it returns back to the caller then it means that it succeeded.
-   */
-  __msvcrt40_getmainargs(argc, argv, envp, expand_wildcards, startup_info);
-  return 0;
-}
-int __cdecl (*__MINGW_IMP_SYMBOL(__getmainargs))(int *, char ***, char ***, 
int, _startupinfo *) = __getmainargs;
diff --git a/mingw-w64-crt/misc/msvcrt40__wgetmainargs.c 
b/mingw-w64-crt/misc/msvcrt40__wgetmainargs.c
deleted file mode 100644
index da94bba64532..000000000000
--- a/mingw-w64-crt/misc/msvcrt40__wgetmainargs.c
+++ /dev/null
@@ -1,20 +0,0 @@
-/**
- * This file has no copyright assigned and is placed in the Public Domain.
- * This file is part of the mingw-w64 runtime package.
- * No warranty is given; refer to the file DISCLAIMER.PD within this package.
- */
-
-#include <internal.h>
-
-/* Define __wgetmainargs() function via msvcrt40.dll __wgetmainargs() function 
*/
-_CRTIMP void __cdecl __msvcrt40_wgetmainargs(int *argc, wchar_t ***argv, 
wchar_t ***envp, int expand_wildcards, _startupinfo *startup_info);
-int __cdecl __wgetmainargs(int *argc, wchar_t ***argv, wchar_t ***envp, int 
expand_wildcards, _startupinfo *startup_info)
-{
-  /*
-   * msvcrt40.dll's __wgetmainargs() function terminates process on error.
-   * If it returns back to the caller then it means that it succeeded.
-   */
-  __msvcrt40_wgetmainargs(argc, argv, envp, expand_wildcards, startup_info);
-  return 0;
-}
-int __cdecl (*__MINGW_IMP_SYMBOL(__wgetmainargs))(int *, wchar_t ***, wchar_t 
***, int, _startupinfo *) = __wgetmainargs;
diff --git a/mingw-w64-crt/misc/msvcrt__getmainargs.c 
b/mingw-w64-crt/misc/msvcrt__getmainargs.c
index cf1eac7c0d10..f0a37d960e44 100644
--- a/mingw-w64-crt/misc/msvcrt__getmainargs.c
+++ b/mingw-w64-crt/misc/msvcrt__getmainargs.c
@@ -21,6 +21,12 @@ int __cdecl __getmainargs(int *argc, char ***argv, char 
***envp, int expand_wild
    * declaration and ignoring it return value. This function does not touch
    * argc/argv/envp arguments on error, so we can use this fact to detect
    * failure independently of return value ABI.
+   *
+   * In the same way was changed also ABI of msvcrt40.dll __getmainargs()
+   * function. In the original Visual C++ 4.0/4.1 version and in Windows 9x
+   * versions, it had void return type. But in all Windows NT versions,
+   * it is just redirect to the msvcrt.dll __getmainargs() function. And
+   * since Windows XP, this function has int return type.
    */
   *argc = -1;
   *argv = NULL;
diff --git a/mingw-w64-crt/misc/msvcrt__wgetmainargs.c 
b/mingw-w64-crt/misc/msvcrt__wgetmainargs.c
index 9c3eed2528d0..f18549951ff7 100644
--- a/mingw-w64-crt/misc/msvcrt__wgetmainargs.c
+++ b/mingw-w64-crt/misc/msvcrt__wgetmainargs.c
@@ -21,6 +21,12 @@ int __cdecl __wgetmainargs(int *argc, wchar_t ***argv, 
wchar_t ***envp, int expa
    * declaration and ignoring it return value. This function does not touch
    * argc/argv/envp arguments on error, so we can use this fact to detect
    * failure independently of return value ABI.
+   *
+   * In the same way was changed also ABI of msvcrt40.dll __wgetmainargs()
+   * function. In the original Visual C++ 4.0/4.1 version and in Windows 9x
+   * versions, it had void return type. But in all Windows NT versions,
+   * it is just redirect to the msvcrt.dll __wgetmainargs() function. And
+   * since Windows XP, this function has int return type.
    */
   *argc = -1;
   *argv = NULL;
-- 
2.20.1



_______________________________________________
Mingw-w64-public mailing list
Mingw-w64-public@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public

Reply via email to