update for HEAD-2003091401
[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 <msvcrt/stdio.h>
30 #include <msvcrt/io.h>
31 #include <msvcrt/process.h>
32 #include <windows.h>
33
34
35 /* See note in crt0.c */
36 #include "init.c"
37
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. */
41
42 #ifdef  __GNUC__
43 extern void __main();
44 extern void __do_global_dtors();
45 #endif
46
47 extern BOOL WINAPI DllMain(HANDLE, DWORD, LPVOID);
48
49 BOOL WINAPI
50 DllMainCRTStartup(HANDLE hDll, DWORD dwReason, LPVOID lpReserved)
51 {
52         BOOL bRet;
53  
54         if (dwReason == DLL_PROCESS_ATTACH)     {
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                 /* From libgcc.a, calls global class destructors. */
73                 __do_global_dtors();
74         }
75 #endif
76
77         return bRet;
78 }
79
80 /*
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.
87  *
88  * @unimplemented
89  */
90 int
91 atexit(void (*pfn)())
92 {
93         return 0;
94 }
95
96 /* With the EGCS snapshot from Mumit Khan (or b19 from Cygnus I hear) this
97  * is no longer necessary. */
98 #if 0
99 #ifdef  __GNUC__
100 /*
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.
103  */
104 asm (".section .idata$3\n" ".long 0,0,0,0,0,0,0,0");
105 #endif
106 #endif