msvcrt: symbol undecoration: Added support for a couple of more calling conventions.
[wine] / dlls / msvcrt / main.c
1 /*
2  * msvcrt.dll initialisation functions
3  *
4  * Copyright 2000 Jon Griffiths
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19  */
20 #include "msvcrt.h"
21 #include "msvcrt/mbctype.h"
22
23 #include "wine/debug.h"
24
25 WINE_DEFAULT_DEBUG_CHANNEL(msvcrt);
26
27 /* Index to TLS */
28 DWORD msvcrt_tls_index;
29
30 static const char* msvcrt_get_reason(DWORD reason)
31 {
32   switch (reason)
33   {
34   case DLL_PROCESS_ATTACH: return "DLL_PROCESS_ATTACH";
35   case DLL_PROCESS_DETACH: return "DLL_PROCESS_DETACH";
36   case DLL_THREAD_ATTACH:  return "DLL_THREAD_ATTACH";
37   case DLL_THREAD_DETACH:  return "DLL_THREAD_DETACH";
38   }
39   return "UNKNOWN";
40 }
41
42 static inline BOOL msvcrt_init_tls(void)
43 {
44   msvcrt_tls_index = TlsAlloc();
45
46   if (msvcrt_tls_index == TLS_OUT_OF_INDEXES)
47   {
48     ERR("TlsAlloc() failed!\n");
49     return FALSE;
50   }
51   return TRUE;
52 }
53
54 static inline BOOL msvcrt_free_tls(void)
55 {
56   if (!TlsFree(msvcrt_tls_index))
57   {
58     ERR("TlsFree() failed!\n");
59     return FALSE;
60   }
61   return TRUE;
62 }
63
64 /*********************************************************************
65  *                  Init
66  */
67 BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
68 {
69   thread_data_t *tls;
70
71   TRACE("(%p, %s, %p) pid(%x), tid(%x), tls(%ld)\n",
72         hinstDLL, msvcrt_get_reason(fdwReason), lpvReserved,
73         GetCurrentProcessId(), GetCurrentThreadId(),
74         (long)msvcrt_tls_index);
75
76   switch (fdwReason)
77   {
78   case DLL_PROCESS_ATTACH:
79     if (!msvcrt_init_tls())
80       return FALSE;
81     msvcrt_init_mt_locks();
82     msvcrt_init_io();
83     msvcrt_init_console();
84     msvcrt_init_args();
85     msvcrt_init_signals();
86     MSVCRT_setlocale(0, "C");
87     _setmbcp(_MB_CP_LOCALE);
88     TRACE("finished process init\n");
89     break;
90   case DLL_THREAD_ATTACH:
91     break;
92   case DLL_PROCESS_DETACH:
93     msvcrt_free_mt_locks();
94     msvcrt_free_io();
95     msvcrt_free_console();
96     msvcrt_free_args();
97     msvcrt_free_signals();
98     if (!msvcrt_free_tls())
99       return FALSE;
100     TRACE("finished process free\n");
101     break;
102   case DLL_THREAD_DETACH:
103     /* Free TLS */
104     tls = TlsGetValue(msvcrt_tls_index);
105     if (tls)
106     {
107         HeapFree(GetProcessHeap(),0,tls->efcvt_buffer);
108         HeapFree(GetProcessHeap(),0,tls->asctime_buffer);
109         HeapFree(GetProcessHeap(),0,tls->wasctime_buffer);
110         HeapFree(GetProcessHeap(),0,tls->strerror_buffer);
111     }
112     HeapFree(GetProcessHeap(), 0, tls);
113     TRACE("finished thread free\n");
114     break;
115   }
116   return TRUE;
117 }
118
119 /*********************************************************************
120  *              $I10_OUTPUT (MSVCRT.@)
121  * Function not really understood but needed to make the DLL work
122  */
123 void CDECL MSVCRT_I10_OUTPUT(void)
124 {
125   /* FIXME: This is probably data, not a function */
126   /* no it is a function. I10 is an Int of 10 bytes */
127   /* also known as 80 bit flotaing point (long double */
128   /* for some compilers, not MSVC) */
129 }
130
131 /*********************************************************************
132  *              _adjust_fdiv (MSVCRT.@)
133  * Used by the MSVC compiler to work around the Pentium FDIV bug.
134  */
135 int MSVCRT__adjust_fdiv = 0;