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 "msvcrt/locale.h"
23 #include "msvcrt/stdio.h"
25 #include "wine/debug.h"
27 WINE_DEFAULT_DEBUG_CHANNEL(msvcrt);
30 DWORD MSVCRT_tls_index;
32 static inline BOOL msvcrt_init_tls(void);
33 static inline BOOL msvcrt_free_tls(void);
34 const char* msvcrt_get_reason(DWORD reason) WINE_UNUSED;
36 /*********************************************************************
39 BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
41 MSVCRT_thread_data *tls;
43 TRACE("(%p, %s, %p) pid(%lx), tid(%lx), tls(%ld)\n",
44 hinstDLL, msvcrt_get_reason(fdwReason), lpvReserved,
45 GetCurrentProcessId(), GetCurrentThreadId(),
46 (long)MSVCRT_tls_index);
50 case DLL_PROCESS_ATTACH:
51 if (!msvcrt_init_tls())
53 msvcrt_init_mt_locks();
55 msvcrt_init_console();
57 MSVCRT_setlocale(0, "C");
58 TRACE("finished process init\n");
60 case DLL_THREAD_ATTACH:
62 case DLL_PROCESS_DETACH:
63 msvcrt_free_mt_locks();
65 msvcrt_free_console();
67 if (!msvcrt_free_tls())
69 TRACE("finished process free\n");
71 case DLL_THREAD_DETACH:
73 tls = TlsGetValue(MSVCRT_tls_index);
74 if (tls) HeapFree(GetProcessHeap(), 0, tls);
75 TRACE("finished thread free\n");
81 static inline BOOL msvcrt_init_tls(void)
83 MSVCRT_tls_index = TlsAlloc();
85 if (MSVCRT_tls_index == TLS_OUT_OF_INDEXES)
87 ERR("TlsAlloc() failed!\n");
93 static inline BOOL msvcrt_free_tls(void)
95 if (!TlsFree(MSVCRT_tls_index))
97 ERR("TlsFree() failed!\n");
103 const char* msvcrt_get_reason(DWORD reason)
107 case DLL_PROCESS_ATTACH: return "DLL_PROCESS_ATTACH";
108 case DLL_PROCESS_DETACH: return "DLL_PROCESS_DETACH";
109 case DLL_THREAD_ATTACH: return "DLL_THREAD_ATTACH";
110 case DLL_THREAD_DETACH: return "DLL_THREAD_DETACH";
116 /*********************************************************************
117 * $I10_OUTPUT (MSVCRT.@)
118 * Function not really understood but needed to make the DLL work
120 void MSVCRT_I10_OUTPUT(void)
122 /* FIXME: This is probably data, not a function */
125 /*********************************************************************
126 * __unDNameEx (MSVCRT.@)
128 * Demangle a C++ identifier.
131 * OutStr [O] If not NULL, the place to put the demangled string
132 * mangled [I] Mangled name of the function
133 * OutStrLen[I] Length of OutStr
134 * memget [I] Function to allocate memory with
135 * memfree [I] Function to free memory with
136 * unknown [?] Unknown, possibly a call back
137 * flags [I] Flags determining demangled format
140 * Success: A string pointing to the unmangled name, allocated with memget.
143 char* MSVCRT___unDNameEx(char * OutStr, const char* mangled, int OutStrLen,
144 MSVCRT_malloc_func memget,
145 MSVCRT_free_func memfree,
147 unsigned short int flags)
149 FIXME("(%p,%s,%d,%p,%p,%p,%x) stub!\n",
150 OutStr, mangled, OutStrLen, memget, memfree, unknown, flags);
152 /* FIXME: The code in tools/winebuild/msmangle.c is pretty complete and
153 * could be used here.
156 /* Experimentation reveals the following flag meanings when set:
157 * 0x0001 - Don't show __ in calling convention
158 * 0x0002 - Don't show calling convention at all
159 * 0x0004 - Don't show function/method return value
160 * 0x0010 - Same as 0x1
161 * 0x0080 - Don't show access specifier (public/protected/private)
162 * 0x0200 - Don't show static specifier
163 * 0x0800 - Unknown, passed by type_info::name()
164 * 0x1000 - Only report the variable/class name
165 * 0x2000 - Unknown, passed by type_info::name()
167 /* Duplicate the mangled name; for comparisons it doesn't matter anyway */
168 if( OutStr == NULL) {
169 OutStrLen = strlen(mangled) + 1;
170 OutStr = memget( OutStrLen);
172 strncpy( OutStr, mangled, OutStrLen);
177 /*********************************************************************
178 * __unDName (MSVCRT.@)
180 char* MSVCRT___unDName(char * OutStr, const char* mangled, int OutStrLen,
181 MSVCRT_malloc_func memget,
182 MSVCRT_free_func memfree,
183 unsigned short int flags)
185 return MSVCRT___unDNameEx( OutStr, mangled, OutStrLen, memget, memfree,