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("(%p, %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");
64 case DLL_THREAD_ATTACH
:
66 case DLL_PROCESS_DETACH
:
67 msvcrt_free_mt_locks();
69 msvcrt_free_console();
71 if (!msvcrt_free_tls())
73 TRACE("finished process free\n");
75 case DLL_THREAD_DETACH
:
77 tls
= TlsGetValue(MSVCRT_tls_index
);
78 if (tls
) HeapFree(GetProcessHeap(), 0, tls
);
79 TRACE("finished thread free\n");
85 static inline BOOL
msvcrt_init_tls(void)
87 MSVCRT_tls_index
= TlsAlloc();
89 if (MSVCRT_tls_index
== TLS_OUT_OF_INDEXES
)
91 ERR("TlsAlloc() failed!\n");
97 static inline BOOL
msvcrt_free_tls(void)
99 if (!TlsFree(MSVCRT_tls_index
))
101 ERR("TlsFree() failed!\n");
107 const char* msvcrt_get_reason(DWORD reason
)
111 case DLL_PROCESS_ATTACH
: return "DLL_PROCESS_ATTACH";
112 case DLL_PROCESS_DETACH
: return "DLL_PROCESS_DETACH";
113 case DLL_THREAD_ATTACH
: return "DLL_THREAD_ATTACH";
114 case DLL_THREAD_DETACH
: return "DLL_THREAD_DETACH";
120 /*********************************************************************
121 * $I10_OUTPUT (MSVCRT.@)
122 * Function not really understood but needed to make the DLL work
124 void MSVCRT_I10_OUTPUT(void)
126 /* FIXME: This is probably data, not a function */
130 /*********************************************************************
131 * __unDName (MSVCRT.@)
132 * Function not really understood but needed to make the DLL work
134 char* MSVCRT___unDName(int unknown
, const char* mangled
,
135 MSVCRT_malloc_func memget
,
136 MSVCRT_free_func memfree
,
141 FIXME("(%d,%s,%p,%p,%x) stub!\n", unknown
, mangled
, memget
, memfree
, flags
);
143 /* Experimentation reveals the following flag meanings when set:
144 * 0x0001 - Dont show __ in calling convention
145 * 0x0002 - Dont show calling convention at all
146 * 0x0004 - Dont show function/method return value
147 * 0x0010 - Same as 0x1
148 * 0x0080 - Dont show access specifier (public/protected/private)
149 * 0x0200 - Dont show static specifier
150 * 0x1000 - Only report the variable/class name
152 /* Duplicate the mangled name; for comparisons it doesn't matter anyway */
153 ret
= memget(strlen(mangled
) + 1);
154 strcpy(ret
, mangled
);
159 /*********************************************************************
160 * __unDNameEx (MSVCRT.@)
161 * Function not really understood but needed to make the DLL work
163 char* MSVCRT___unDNameEx(void)