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.
30 #include <msvcrt/stdio.h>
31 #include <msvcrt/io.h>
32 #include <msvcrt/process.h>
35 /* See note in crt0.c */
38 /* Unlike normal crt0, I don't initialize the FPU, because the process
39 * should have done that already. I also don't set the file handle modes,
40 * because that would be rude. */
44 extern void __do_global_dtors();
47 extern BOOL WINAPI
DllMain(HANDLE
, DWORD
, LPVOID
);
50 DllMainCRTStartup(HANDLE hDll
, DWORD dwReason
, LPVOID lpReserved
)
54 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
) {
72 /* From libgcc.a, calls global class destructors. */
81 * For the moment a dummy atexit. Atexit causes problems in DLLs, especially
82 * if they are dynamically loaded. For now atexit inside a DLL does nothing.
83 * NOTE: We need this even if the DLL author never calls atexit because
84 * the global constructor function __do_global_ctors called from __main
85 * will attempt to register __do_global_dtors using atexit.
86 * Thanks to Andrey A. Smirnov for pointing this one out.
96 /* With the EGCS snapshot from Mumit Khan (or b19 from Cygnus I hear) this
97 * is no longer necessary. */
101 * This section terminates the list of imports under GCC. If you do not
102 * include this then you will have problems when linking with DLLs.
104 asm (".section .idata$3\n" ".long 0,0,0,0,0,0,0,0");