2 * msvcrt.dll initialisation functions
4 * Copyright 2000 Jon Griffiths
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.
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.
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include "wine/debug.h"
24 WINE_DEFAULT_DEBUG_CHANNEL(msvcrt);
27 DWORD msvcrt_tls_index;
29 static inline BOOL msvcrt_init_tls(void);
30 static inline BOOL msvcrt_free_tls(void);
31 const char* msvcrt_get_reason(DWORD reason);
33 /*********************************************************************
36 BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
40 TRACE("(%p, %s, %p) pid(%lx), tid(%lx), tls(%ld)\n",
41 hinstDLL, msvcrt_get_reason(fdwReason), lpvReserved,
42 GetCurrentProcessId(), GetCurrentThreadId(),
43 (long)msvcrt_tls_index);
47 case DLL_PROCESS_ATTACH:
48 if (!msvcrt_init_tls())
50 msvcrt_init_mt_locks();
52 msvcrt_init_console();
54 MSVCRT_setlocale(0, "C");
55 TRACE("finished process init\n");
57 case DLL_THREAD_ATTACH:
59 case DLL_PROCESS_DETACH:
60 msvcrt_free_mt_locks();
62 msvcrt_free_console();
64 if (!msvcrt_free_tls())
66 TRACE("finished process free\n");
68 case DLL_THREAD_DETACH:
70 tls = TlsGetValue(msvcrt_tls_index);
71 HeapFree(GetProcessHeap(), 0, tls);
72 TRACE("finished thread free\n");
78 static inline BOOL msvcrt_init_tls(void)
80 msvcrt_tls_index = TlsAlloc();
82 if (msvcrt_tls_index == TLS_OUT_OF_INDEXES)
84 ERR("TlsAlloc() failed!\n");
90 static inline BOOL msvcrt_free_tls(void)
92 if (!TlsFree(msvcrt_tls_index))
94 ERR("TlsFree() failed!\n");
100 const char* msvcrt_get_reason(DWORD reason)
104 case DLL_PROCESS_ATTACH: return "DLL_PROCESS_ATTACH";
105 case DLL_PROCESS_DETACH: return "DLL_PROCESS_DETACH";
106 case DLL_THREAD_ATTACH: return "DLL_THREAD_ATTACH";
107 case DLL_THREAD_DETACH: return "DLL_THREAD_DETACH";
113 /*********************************************************************
114 * $I10_OUTPUT (MSVCRT.@)
115 * Function not really understood but needed to make the DLL work
117 void MSVCRT_I10_OUTPUT(void)
119 /* FIXME: This is probably data, not a function */
120 /* no it is a function. I10 is an Int of 10 bytes */
121 /* also known as 80 bit flotaing point (long double */
122 /* for some compilers, not MSVC) */
125 /*********************************************************************
126 * _adjust_fdiv (MSVCRT.@)
127 * Used by the MSVC compiler to work around the Pentium FDIV bug.
129 int MSVCRT__adjust_fdiv = 0;