:pserver:cvsanon@mok.lvcm.com:/CVS/ReactOS reactos
[reactos.git] / lib / crtdll / misc / dllcrt1.c
1 /*
2  * dllcrt1.c
3  *
4  * Initialization code for DLLs.
5  *
6  * This file is part of the Mingw32 package.
7  *
8  * Contributors:
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>
11  *
12  *
13  *  THIS SOFTWARE IS NOT COPYRIGHTED
14  *
15  *  This source code is offered for use in the public domain. You may
16  *  use, modify or distribute it freely.
17  *
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.
22  *
23  * $Revision$
24  * $Author$
25  * $Date$
26  * 
27  */
28
29 #include <crtdll/stdio.h>
30 #include <crtdll/io.h>
31 #include <crtdll/process.h>
32 #include <windows.h>
33
34 /* See note in crt0.c */
35 #include "init.c"
36
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. */
40
41 #ifdef  __GNUC__
42 extern void __main();
43 extern void __do_global_dtors();
44 #endif
45
46 extern BOOL WINAPI DllMain(HANDLE, DWORD, LPVOID);
47
48 BOOL WINAPI
49 DllMainCRTStartup (HANDLE hDll, DWORD dwReason, LPVOID lpReserved)
50 {
51         BOOL bRet;
52  
53         if (dwReason == DLL_PROCESS_ATTACH)
54         {
55                 _mingw32_init_mainargs();
56
57 #ifdef  __GNUC__
58                 /* From libgcc.a, calls global class constructors. */
59                 __main();
60 #endif
61         }
62
63         /*
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.
67          */
68         bRet = DllMain(hDll, dwReason, lpReserved);
69
70 #ifdef  __GNUC__
71         if (dwReason == DLL_PROCESS_DETACH)
72         {
73                 /* From libgcc.a, calls global class destructors. */
74                 __do_global_dtors();
75         }
76 #endif
77
78         return bRet;
79 }
80
81 /*
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.
88  */
89 int
90 atexit (void (*pfn)())
91 {
92         return 0;
93 }
94
95 /* With the EGCS snapshot from Mumit Khan (or b19 from Cygnus I hear) this
96  * is no longer necessary. */
97 #if 0
98 #ifdef  __GNUC__
99 /*
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.
102  */
103 asm (".section .idata$3\n" ".long 0,0,0,0,0,0,0,0");
104 #endif
105 #endif