From 1fd5e000ace55b323124c7e556a7a864b972a5c4 Mon Sep 17 00:00:00 2001 From: Christopher Faylor Date: Thu, 17 Feb 2000 19:38:33 +0000 Subject: import winsup-2000-02-17 snapshot --- winsup/mingw/dllcrt1.c | 89 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 winsup/mingw/dllcrt1.c (limited to 'winsup/mingw/dllcrt1.c') diff --git a/winsup/mingw/dllcrt1.c b/winsup/mingw/dllcrt1.c new file mode 100644 index 000000000..a0055d8b0 --- /dev/null +++ b/winsup/mingw/dllcrt1.c @@ -0,0 +1,89 @@ +/* + * dllcrt1.c + * + * Initialization code for DLLs. + * + * This file is part of the Mingw32 package. + * + * Contributors: + * Created by Colin Peters + * DLL support adapted from Gunther Ebert + * Maintained by Mumit Khan + * + * THIS SOFTWARE IS NOT COPYRIGHTED + * + * This source code is offered for use in the public domain. You may + * use, modify or distribute it freely. + * + * This code is distributed in the hope that it will be useful but + * WITHOUT ANY WARRANTY. ALL WARRENTIES, EXPRESS OR IMPLIED ARE HEREBY + * DISCLAMED. This includes but is not limited to warrenties of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * + * $Revision$ + * $Author$ + * $Date$ + * + */ + +#include +#include +#include +#include + +/* Unlike normal crt1, I don't initialize the FPU, because the process + * should have done that already. I also don't set the file handle modes, + * because that would be rude. */ + +#ifdef __GNUC__ +extern void __main (); +extern void __do_global_dtors (); +#endif + +extern BOOL WINAPI DllMain (HANDLE, DWORD, LPVOID); + +BOOL WINAPI +DllMainCRTStartup (HANDLE hDll, DWORD dwReason, LPVOID lpReserved) +{ + BOOL bRet; + + if (dwReason == DLL_PROCESS_ATTACH) + { +#ifdef __GNUC__ + /* From libgcc.a, calls global class constructors. */ + __main (); +#endif + } + + /* + * Call the user-supplied DllMain subroutine + * NOTE: DllMain is optional, so libmingw32.a includes a stub + * which will be used if the user does not supply one. + */ + bRet = DllMain (hDll, dwReason, lpReserved); + +#ifdef __GNUC__ + if (dwReason == DLL_PROCESS_DETACH) + { + /* From libgcc.a, calls global class destructors. */ + __do_global_dtors (); + } +#endif + + return bRet; +} + +/* + * For the moment a dummy atexit. Atexit causes problems in DLLs, especially + * if they are dynamically loaded. For now atexit inside a DLL does nothing. + * NOTE: We need this even if the DLL author never calls atexit because + * the global constructor function __do_global_ctors called from __main + * will attempt to register __do_global_dtors using atexit. + * Thanks to Andrey A. Smirnov for pointing this one out. + */ +int +atexit (void (*pfn) ()) +{ + return 0; +} + -- cgit v1.2.3