2001-01-10 23:59:25 +00:00
|
|
|
/*
|
|
|
|
* msvcrt.dll initialisation functions
|
|
|
|
*
|
|
|
|
* Copyright 2000 Jon Griffiths
|
2002-03-09 23:29:33 +00:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
2001-01-10 23:59:25 +00:00
|
|
|
*/
|
|
|
|
#include "msvcrt.h"
|
|
|
|
|
2001-09-19 20:29:33 +00:00
|
|
|
#include "msvcrt/locale.h"
|
2001-04-10 23:25:25 +00:00
|
|
|
#include "msvcrt/stdio.h"
|
|
|
|
|
2002-01-22 00:57:16 +00:00
|
|
|
#include "wine/debug.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(msvcrt);
|
2001-01-10 23:59:25 +00:00
|
|
|
|
|
|
|
/* Index to TLS */
|
|
|
|
DWORD MSVCRT_tls_index;
|
|
|
|
|
2001-04-10 21:16:07 +00:00
|
|
|
static inline BOOL msvcrt_init_tls(void);
|
|
|
|
static inline BOOL msvcrt_free_tls(void);
|
2001-04-10 23:25:25 +00:00
|
|
|
const char* msvcrt_get_reason(DWORD reason) WINE_UNUSED;
|
2001-01-10 23:59:25 +00:00
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* Init
|
|
|
|
*/
|
2002-11-04 23:53:41 +00:00
|
|
|
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
|
2001-01-10 23:59:25 +00:00
|
|
|
{
|
|
|
|
MSVCRT_thread_data *tls;
|
|
|
|
|
2003-02-18 23:29:47 +00:00
|
|
|
TRACE("(%p, %s, %p) pid(%lx), tid(%lx), tls(%ld)\n",
|
2001-04-10 21:16:07 +00:00
|
|
|
hinstDLL, msvcrt_get_reason(fdwReason), lpvReserved,
|
2003-02-18 23:29:47 +00:00
|
|
|
GetCurrentProcessId(), GetCurrentThreadId(),
|
2001-01-10 23:59:25 +00:00
|
|
|
(long)MSVCRT_tls_index);
|
|
|
|
|
|
|
|
switch (fdwReason)
|
|
|
|
{
|
|
|
|
case DLL_PROCESS_ATTACH:
|
2001-04-10 21:16:07 +00:00
|
|
|
if (!msvcrt_init_tls())
|
2001-01-10 23:59:25 +00:00
|
|
|
return FALSE;
|
2002-02-21 20:22:00 +00:00
|
|
|
msvcrt_init_mt_locks();
|
2001-04-10 21:16:07 +00:00
|
|
|
msvcrt_init_io();
|
|
|
|
msvcrt_init_console();
|
|
|
|
msvcrt_init_args();
|
2001-01-10 23:59:25 +00:00
|
|
|
MSVCRT_setlocale(0, "C");
|
|
|
|
TRACE("finished process init\n");
|
2002-07-19 03:24:50 +00:00
|
|
|
break;
|
2001-01-10 23:59:25 +00:00
|
|
|
case DLL_THREAD_ATTACH:
|
|
|
|
break;
|
|
|
|
case DLL_PROCESS_DETACH:
|
2002-02-21 20:22:00 +00:00
|
|
|
msvcrt_free_mt_locks();
|
2002-07-05 21:23:07 +00:00
|
|
|
msvcrt_free_io();
|
2001-04-10 21:16:07 +00:00
|
|
|
msvcrt_free_console();
|
|
|
|
msvcrt_free_args();
|
|
|
|
if (!msvcrt_free_tls())
|
2001-01-10 23:59:25 +00:00
|
|
|
return FALSE;
|
|
|
|
TRACE("finished process free\n");
|
|
|
|
break;
|
|
|
|
case DLL_THREAD_DETACH:
|
|
|
|
/* Free TLS */
|
|
|
|
tls = TlsGetValue(MSVCRT_tls_index);
|
2002-07-19 03:24:50 +00:00
|
|
|
if (tls) HeapFree(GetProcessHeap(), 0, tls);
|
2001-01-10 23:59:25 +00:00
|
|
|
TRACE("finished thread free\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2001-04-10 21:16:07 +00:00
|
|
|
static inline BOOL msvcrt_init_tls(void)
|
2001-01-10 23:59:25 +00:00
|
|
|
{
|
|
|
|
MSVCRT_tls_index = TlsAlloc();
|
|
|
|
|
|
|
|
if (MSVCRT_tls_index == TLS_OUT_OF_INDEXES)
|
|
|
|
{
|
|
|
|
ERR("TlsAlloc() failed!\n");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2001-04-10 21:16:07 +00:00
|
|
|
static inline BOOL msvcrt_free_tls(void)
|
2001-01-10 23:59:25 +00:00
|
|
|
{
|
|
|
|
if (!TlsFree(MSVCRT_tls_index))
|
|
|
|
{
|
|
|
|
ERR("TlsFree() failed!\n");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2001-04-10 21:16:07 +00:00
|
|
|
const char* msvcrt_get_reason(DWORD reason)
|
2001-01-10 23:59:25 +00:00
|
|
|
{
|
|
|
|
switch (reason)
|
|
|
|
{
|
|
|
|
case DLL_PROCESS_ATTACH: return "DLL_PROCESS_ATTACH";
|
|
|
|
case DLL_PROCESS_DETACH: return "DLL_PROCESS_DETACH";
|
|
|
|
case DLL_THREAD_ATTACH: return "DLL_THREAD_ATTACH";
|
|
|
|
case DLL_THREAD_DETACH: return "DLL_THREAD_DETACH";
|
|
|
|
}
|
|
|
|
return "UNKNOWN";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*********************************************************************
|
2001-07-11 18:56:41 +00:00
|
|
|
* $I10_OUTPUT (MSVCRT.@)
|
|
|
|
* Function not really understood but needed to make the DLL work
|
2001-01-10 23:59:25 +00:00
|
|
|
*/
|
|
|
|
void MSVCRT_I10_OUTPUT(void)
|
|
|
|
{
|
|
|
|
/* FIXME: This is probably data, not a function */
|
|
|
|
}
|
|
|
|
|
2001-07-11 18:56:41 +00:00
|
|
|
/*********************************************************************
|
2004-01-13 22:56:59 +00:00
|
|
|
* __unDNameEx (MSVCRT.@)
|
2003-03-17 21:21:59 +00:00
|
|
|
*
|
|
|
|
* Demangle a C++ identifier.
|
|
|
|
*
|
|
|
|
* PARAMS
|
2004-01-13 22:56:59 +00:00
|
|
|
* OutStr [O] If not NULL, the place to put the demangled string
|
2003-03-17 21:21:59 +00:00
|
|
|
* mangled [I] Mangled name of the function
|
2004-01-13 22:56:59 +00:00
|
|
|
* OutStrLen[I] Length of OutStr
|
2003-03-17 21:21:59 +00:00
|
|
|
* memget [I] Function to allocate memory with
|
|
|
|
* memfree [I] Function to free memory with
|
2004-01-13 22:56:59 +00:00
|
|
|
* unknown [?] Unknown, possibly a call back
|
2003-03-17 21:21:59 +00:00
|
|
|
* flags [I] Flags determining demangled format
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: A string pointing to the unmangled name, allocated with memget.
|
|
|
|
* Failure: NULL.
|
2001-07-11 18:56:41 +00:00
|
|
|
*/
|
2004-01-13 22:56:59 +00:00
|
|
|
char* MSVCRT___unDNameEx(char * OutStr, const char* mangled, int OutStrLen,
|
2001-12-21 20:27:39 +00:00
|
|
|
MSVCRT_malloc_func memget,
|
|
|
|
MSVCRT_free_func memfree,
|
2004-01-13 22:56:59 +00:00
|
|
|
void * unknown,
|
|
|
|
unsigned short int flags)
|
2001-01-10 23:59:25 +00:00
|
|
|
{
|
2004-01-13 22:56:59 +00:00
|
|
|
FIXME("(%p,%s,%d,%p,%p,%p,%x) stub!\n",
|
|
|
|
OutStr, mangled, OutStrLen, memget, memfree, unknown, flags);
|
2003-03-17 21:21:59 +00:00
|
|
|
|
|
|
|
/* FIXME: The code in tools/winebuild/msmangle.c is pretty complete and
|
|
|
|
* could be used here.
|
|
|
|
*/
|
2001-12-21 20:27:39 +00:00
|
|
|
|
|
|
|
/* Experimentation reveals the following flag meanings when set:
|
2004-01-06 22:08:33 +00:00
|
|
|
* 0x0001 - Don't show __ in calling convention
|
|
|
|
* 0x0002 - Don't show calling convention at all
|
|
|
|
* 0x0004 - Don't show function/method return value
|
2001-12-21 20:27:39 +00:00
|
|
|
* 0x0010 - Same as 0x1
|
2004-01-06 22:08:33 +00:00
|
|
|
* 0x0080 - Don't show access specifier (public/protected/private)
|
|
|
|
* 0x0200 - Don't show static specifier
|
2003-03-17 21:21:59 +00:00
|
|
|
* 0x0800 - Unknown, passed by type_info::name()
|
2001-12-21 20:27:39 +00:00
|
|
|
* 0x1000 - Only report the variable/class name
|
2003-03-17 21:21:59 +00:00
|
|
|
* 0x2000 - Unknown, passed by type_info::name()
|
2001-12-21 20:27:39 +00:00
|
|
|
*/
|
|
|
|
/* Duplicate the mangled name; for comparisons it doesn't matter anyway */
|
2004-01-13 22:56:59 +00:00
|
|
|
if( OutStr == NULL) {
|
|
|
|
OutStrLen = strlen(mangled) + 1;
|
|
|
|
OutStr = memget( OutStrLen);
|
|
|
|
}
|
|
|
|
strncpy( OutStr, mangled, OutStrLen);
|
|
|
|
return OutStr;
|
2001-01-10 23:59:25 +00:00
|
|
|
}
|
|
|
|
|
2001-12-21 20:27:39 +00:00
|
|
|
|
2001-07-11 18:56:41 +00:00
|
|
|
/*********************************************************************
|
2004-01-13 22:56:59 +00:00
|
|
|
* __unDName (MSVCRT.@)
|
2001-07-11 18:56:41 +00:00
|
|
|
*/
|
2004-01-13 22:56:59 +00:00
|
|
|
char* MSVCRT___unDName(char * OutStr, const char* mangled, int OutStrLen,
|
|
|
|
MSVCRT_malloc_func memget,
|
|
|
|
MSVCRT_free_func memfree,
|
|
|
|
unsigned short int flags)
|
2001-01-10 23:59:25 +00:00
|
|
|
{
|
2004-01-13 22:56:59 +00:00
|
|
|
return MSVCRT___unDNameEx( OutStr, mangled, OutStrLen, memget, memfree,
|
|
|
|
NULL, flags);
|
2001-01-10 23:59:25 +00:00
|
|
|
}
|