[9633] | 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
---|
| 19 | */
|
---|
| 20 | #include "msvcrt.h"
|
---|
| 21 | #define TLS_OUT_OF_INDEXES ((DWORD)0xFFFFFFFF)
|
---|
| 22 | #include "msvcrt/locale.h"
|
---|
| 23 | #include "msvcrt/stdio.h"
|
---|
[10005] | 24 | #include <string.h>
|
---|
[9633] | 25 | #include "wine/debug.h"
|
---|
| 26 |
|
---|
| 27 | WINE_DEFAULT_DEBUG_CHANNEL(msvcrt);
|
---|
| 28 |
|
---|
| 29 | /* Index to TLS */
|
---|
| 30 | DWORD MSVCRT_tls_index;
|
---|
| 31 |
|
---|
| 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;
|
---|
| 35 |
|
---|
| 36 | typedef void* (*MSVCRT_malloc_func)(unsigned int);
|
---|
| 37 | typedef void (*MSVCRT_free_func)(void*);
|
---|
| 38 |
|
---|
| 39 | int _CRT_init (void);
|
---|
| 40 | void _CRT_term (void);
|
---|
| 41 | void __ctordtorInit (void);
|
---|
| 42 | void __ctordtorTerm (void);
|
---|
| 43 |
|
---|
| 44 | static HMODULE dllHandle = 0;
|
---|
| 45 |
|
---|
| 46 | BOOL WINAPI MSVCRT_Init(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved);
|
---|
| 47 |
|
---|
| 48 |
|
---|
| 49 | /*********************************************************************
|
---|
| 50 | * Init
|
---|
| 51 | */
|
---|
| 52 | BOOL WINAPI MSVCRT_Init(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
|
---|
| 53 | {
|
---|
| 54 | MSVCRT_thread_data *tls;
|
---|
| 55 |
|
---|
| 56 | TRACE("(0x%08x, %s, %p) pid(%ld), tid(%ld), tls(%ld)\n",
|
---|
| 57 | hinstDLL, msvcrt_get_reason(fdwReason), lpvReserved,
|
---|
| 58 | (long)GetCurrentProcessId(), (long)GetCurrentThreadId(),
|
---|
| 59 | (long)MSVCRT_tls_index);
|
---|
| 60 |
|
---|
| 61 | switch (fdwReason)
|
---|
| 62 | {
|
---|
| 63 | case DLL_PROCESS_ATTACH:
|
---|
[10005] | 64 | if (!msvcrt_init_tls())
|
---|
[9633] | 65 | return FALSE;
|
---|
| 66 | msvcrt_init_mt_locks();
|
---|
| 67 | msvcrt_init_vtables();
|
---|
| 68 | msvcrt_init_io();
|
---|
| 69 | msvcrt_init_console();
|
---|
| 70 | msvcrt_init_args();
|
---|
| 71 | MSVCRT_setlocale(0, "C");
|
---|
| 72 | TRACE("finished process init\n");
|
---|
| 73 | break;
|
---|
| 74 | case DLL_THREAD_ATTACH:
|
---|
| 75 | break;
|
---|
| 76 | case DLL_PROCESS_DETACH:
|
---|
| 77 | msvcrt_free_mt_locks();
|
---|
| 78 | msvcrt_free_io();
|
---|
| 79 | msvcrt_free_console();
|
---|
| 80 | msvcrt_free_args();
|
---|
| 81 | if (!msvcrt_free_tls())
|
---|
| 82 | return FALSE;
|
---|
| 83 | TRACE("finished process free\n");
|
---|
| 84 | break;
|
---|
| 85 | case DLL_THREAD_DETACH:
|
---|
| 86 | /* Free TLS */
|
---|
| 87 | tls = TlsGetValue(MSVCRT_tls_index);
|
---|
| 88 | if (tls) HeapFree(GetProcessHeap(), 0, tls);
|
---|
| 89 | TRACE("finished thread free\n");
|
---|
| 90 | break;
|
---|
| 91 | }
|
---|
| 92 | return TRUE;
|
---|
| 93 | }
|
---|
| 94 |
|
---|
| 95 | static inline BOOL msvcrt_init_tls(void)
|
---|
| 96 | {
|
---|
| 97 | MSVCRT_tls_index = TlsAlloc();
|
---|
| 98 |
|
---|
| 99 | if (MSVCRT_tls_index == TLS_OUT_OF_INDEXES)
|
---|
| 100 | {
|
---|
| 101 | ERR("TlsAlloc() failed!\n");
|
---|
| 102 | return FALSE;
|
---|
| 103 | }
|
---|
| 104 | return TRUE;
|
---|
| 105 | }
|
---|
| 106 |
|
---|
| 107 | static inline BOOL msvcrt_free_tls(void)
|
---|
| 108 | {
|
---|
| 109 | if (!TlsFree(MSVCRT_tls_index))
|
---|
| 110 | {
|
---|
| 111 | ERR("TlsFree() failed!\n");
|
---|
| 112 | return FALSE;
|
---|
| 113 | }
|
---|
| 114 | return TRUE;
|
---|
| 115 | }
|
---|
| 116 |
|
---|
| 117 | const char* msvcrt_get_reason(DWORD reason)
|
---|
| 118 | {
|
---|
| 119 | switch (reason)
|
---|
| 120 | {
|
---|
| 121 | case DLL_PROCESS_ATTACH: return "DLL_PROCESS_ATTACH";
|
---|
| 122 | case DLL_PROCESS_DETACH: return "DLL_PROCESS_DETACH";
|
---|
| 123 | case DLL_THREAD_ATTACH: return "DLL_THREAD_ATTACH";
|
---|
| 124 | case DLL_THREAD_DETACH: return "DLL_THREAD_DETACH";
|
---|
| 125 | }
|
---|
| 126 | return "UNKNOWN";
|
---|
| 127 | }
|
---|
| 128 |
|
---|
| 129 |
|
---|
| 130 | /*********************************************************************
|
---|
| 131 | * $I10_OUTPUT (MSVCRT.@)
|
---|
| 132 | * Function not really understood but needed to make the DLL work
|
---|
| 133 | */
|
---|
| 134 | void MSVCRT_I10_OUTPUT(void)
|
---|
| 135 | {
|
---|
| 136 | /* FIXME: This is probably data, not a function */
|
---|
| 137 | }
|
---|
| 138 |
|
---|
| 139 |
|
---|
| 140 | /*********************************************************************
|
---|
| 141 | * __unDName (MSVCRT.@)
|
---|
| 142 | * Function not really understood but needed to make the DLL work
|
---|
| 143 | */
|
---|
| 144 | char* MSVCRT___unDName(int unknown, const char* mangled,
|
---|
| 145 | MSVCRT_malloc_func memget,
|
---|
| 146 | MSVCRT_free_func memfree,
|
---|
| 147 | unsigned int flags)
|
---|
| 148 | {
|
---|
| 149 | char* ret;
|
---|
| 150 |
|
---|
| 151 | FIXME("(%d,%s,%p,%p,%x) stub!\n", unknown, mangled, memget, memfree, flags);
|
---|
| 152 |
|
---|
| 153 | /* Experimentation reveals the following flag meanings when set:
|
---|
| 154 | * 0x0001 - Dont show __ in calling convention
|
---|
| 155 | * 0x0002 - Dont show calling convention at all
|
---|
| 156 | * 0x0004 - Dont show function/method return value
|
---|
| 157 | * 0x0010 - Same as 0x1
|
---|
| 158 | * 0x0080 - Dont show access specifier (public/protected/private)
|
---|
| 159 | * 0x0200 - Dont show static specifier
|
---|
| 160 | * 0x1000 - Only report the variable/class name
|
---|
| 161 | */
|
---|
| 162 | /* Duplicate the mangled name; for comparisons it doesn't matter anyway */
|
---|
| 163 | ret = memget(strlen(mangled) + 1);
|
---|
| 164 | strcpy(ret, mangled);
|
---|
| 165 | return ret;
|
---|
| 166 | }
|
---|
| 167 |
|
---|
| 168 |
|
---|
| 169 | /*********************************************************************
|
---|
| 170 | * __unDNameEx (MSVCRT.@)
|
---|
| 171 | * Function not really understood but needed to make the DLL work
|
---|
| 172 | */
|
---|
| 173 | char* MSVCRT___unDNameEx(void)
|
---|
| 174 | {
|
---|
| 175 | return NULL;
|
---|
| 176 | }
|
---|