4 * Initialization code for DLLs.
6 * This file is part of the Mingw32 package.
9 * Created by Colin Peters <colin@bird.fu.is.saga-u.ac.jp>
10 * DLL support adapted from Gunther Ebert <gunther.ebert@ixos-leipzig.de>
13 * THIS SOFTWARE IS NOT COPYRIGHTED
15 * This source code is offered for use in the public domain. You may
16 * use, modify or distribute it freely.
18 * This code is distributed in the hope that it will be useful but
19 * WITHOUT ANY WARRANTY. ALL WARRENTIES, EXPRESS OR IMPLIED ARE HEREBY
20 * DISCLAMED. This includes but is not limited to warrenties of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
29 #include <crtdll/stdio.h>
30 #include <crtdll/io.h>
31 #include <crtdll/process.h>
34 /* See note in crt0.c */
37 /* Unlike normal crt0, I don't initialize the FPU, because the process
38 * should have done that already. I also don't set the file handle modes,
39 * because that would be rude. */
43 extern void __do_global_dtors();
46 extern BOOL WINAPI DllMain(HANDLE, DWORD, LPVOID);
49 DllMainCRTStartup (HANDLE hDll, DWORD dwReason, LPVOID lpReserved)
53 if (dwReason == DLL_PROCESS_ATTACH)
55 _mingw32_init_mainargs();
58 /* From libgcc.a, calls global class constructors. */
64 * Call the user-supplied DllMain subroutine
65 * NOTE: DllMain is optional, so libmingw32.a includes a stub
66 * which will be used if the user does not supply one.
68 bRet = DllMain(hDll, dwReason, lpReserved);
71 if (dwReason == DLL_PROCESS_DETACH)
73 /* From libgcc.a, calls global class destructors. */
82 * For the moment a dummy atexit. Atexit causes problems in DLLs, especially
83 * if they are dynamically loaded. For now atexit inside a DLL does nothing.
84 * NOTE: We need this even if the DLL author never calls atexit because
85 * the global constructor function __do_global_ctors called from __main
86 * will attempt to register __do_global_dtors using atexit.
87 * Thanks to Andrey A. Smirnov for pointing this one out.
90 atexit (void (*pfn)())
95 /* With the EGCS snapshot from Mumit Khan (or b19 from Cygnus I hear) this
96 * is no longer necessary. */
100 * This section terminates the list of imports under GCC. If you do not
101 * include this then you will have problems when linking with DLLs.
103 asm (".section .idata$3\n" ".long 0,0,0,0,0,0,0,0");