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 typedef void* (*MSVCRT_malloc_func
)(unsigned int);
37 typedef void (*MSVCRT_free_func
)(void*);
39 /*********************************************************************
42 BOOL WINAPI
MSVCRT_Init(HINSTANCE hinstDLL
, DWORD fdwReason
, LPVOID lpvReserved
)
44 MSVCRT_thread_data
*tls
;
46 TRACE("(0x%08x, %s, %p) pid(%ld), tid(%ld), tls(%ld)\n",
47 hinstDLL
, msvcrt_get_reason(fdwReason
), lpvReserved
,
48 (long)GetCurrentProcessId(), (long)GetCurrentThreadId(),
49 (long)MSVCRT_tls_index
);
53 case DLL_PROCESS_ATTACH
:
54 if (!msvcrt_init_tls())
56 msvcrt_init_mt_locks();
57 msvcrt_init_vtables();
59 msvcrt_init_console();
61 MSVCRT_setlocale(0, "C");
62 TRACE("finished process init\n");
63 /* FALL THROUGH for Initial TLS allocation!! */
64 case DLL_THREAD_ATTACH
:
65 TRACE("starting thread init\n");
67 tls
= (MSVCRT_thread_data
*) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
68 sizeof(MSVCRT_thread_data
));
69 if (!tls
|| !TlsSetValue(MSVCRT_tls_index
, tls
))
71 ERR("TLS init failed! error = %ld\n", GetLastError());
74 TRACE("finished thread init\n");
76 case DLL_PROCESS_DETACH
:
77 msvcrt_free_mt_locks();
79 msvcrt_free_console();
81 if (!msvcrt_free_tls())
83 TRACE("finished process free\n");
85 case DLL_THREAD_DETACH
:
87 tls
= TlsGetValue(MSVCRT_tls_index
);
91 ERR("TLS free failed! error = %ld\n", GetLastError());
94 HeapFree(GetProcessHeap(), 0, tls
);
95 TRACE("finished thread free\n");
101 static inline BOOL
msvcrt_init_tls(void)
103 MSVCRT_tls_index
= TlsAlloc();
105 if (MSVCRT_tls_index
== TLS_OUT_OF_INDEXES
)
107 ERR("TlsAlloc() failed!\n");
113 static inline BOOL
msvcrt_free_tls(void)
115 if (!TlsFree(MSVCRT_tls_index
))
117 ERR("TlsFree() failed!\n");
123 const char* msvcrt_get_reason(DWORD reason
)
127 case DLL_PROCESS_ATTACH
: return "DLL_PROCESS_ATTACH";
128 case DLL_PROCESS_DETACH
: return "DLL_PROCESS_DETACH";
129 case DLL_THREAD_ATTACH
: return "DLL_THREAD_ATTACH";
130 case DLL_THREAD_DETACH
: return "DLL_THREAD_DETACH";
136 /*********************************************************************
137 * $I10_OUTPUT (MSVCRT.@)
138 * Function not really understood but needed to make the DLL work
140 void MSVCRT_I10_OUTPUT(void)
142 /* FIXME: This is probably data, not a function */
146 /*********************************************************************
147 * __unDName (MSVCRT.@)
148 * Function not really understood but needed to make the DLL work
150 char* MSVCRT___unDName(int unknown
, const char* mangled
,
151 MSVCRT_malloc_func memget
,
152 MSVCRT_free_func memfree
,
157 FIXME("(%d,%s,%p,%p,%x) stub!\n", unknown
, mangled
, memget
, memfree
, flags
);
159 /* Experimentation reveals the following flag meanings when set:
160 * 0x0001 - Dont show __ in calling convention
161 * 0x0002 - Dont show calling convention at all
162 * 0x0004 - Dont show function/method return value
163 * 0x0010 - Same as 0x1
164 * 0x0080 - Dont show access specifier (public/protected/private)
165 * 0x0200 - Dont show static specifier
166 * 0x1000 - Only report the variable/class name
168 /* Duplicate the mangled name; for comparisons it doesn't matter anyway */
169 ret
= memget(strlen(mangled
) + 1);
170 strcpy(ret
, mangled
);
175 /*********************************************************************
176 * __unDNameEx (MSVCRT.@)
177 * Function not really understood but needed to make the DLL work
179 char* MSVCRT___unDNameEx(void)