2001-01-11 00:59:25 +01:00
|
|
|
/*
|
|
|
|
* msvcrt.dll initialisation functions
|
|
|
|
*
|
|
|
|
* Copyright 2000 Jon Griffiths
|
|
|
|
*/
|
|
|
|
#include "msvcrt.h"
|
|
|
|
|
2001-09-19 22:29:33 +02:00
|
|
|
#include "msvcrt/locale.h"
|
2001-04-11 01:25:25 +02:00
|
|
|
#include "msvcrt/stdio.h"
|
|
|
|
|
|
|
|
|
2002-01-22 01:57:16 +01:00
|
|
|
#include "wine/debug.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(msvcrt);
|
2001-01-11 00:59:25 +01:00
|
|
|
|
|
|
|
/* Index to TLS */
|
|
|
|
DWORD MSVCRT_tls_index;
|
|
|
|
|
|
|
|
/* MT locks */
|
|
|
|
CRITICAL_SECTION MSVCRT_heap_cs;
|
|
|
|
CRITICAL_SECTION MSVCRT_file_cs;
|
|
|
|
CRITICAL_SECTION MSVCRT_exit_cs;
|
|
|
|
CRITICAL_SECTION MSVCRT_console_cs;
|
|
|
|
CRITICAL_SECTION MSVCRT_locale_cs;
|
|
|
|
|
2001-04-10 23:16:07 +02:00
|
|
|
static inline BOOL msvcrt_init_tls(void);
|
|
|
|
static inline BOOL msvcrt_free_tls(void);
|
|
|
|
static inline void msvcrt_init_critical_sections(void);
|
|
|
|
static inline void msvcrt_free_critical_sections(void);
|
2001-04-11 01:25:25 +02:00
|
|
|
const char* msvcrt_get_reason(DWORD reason) WINE_UNUSED;
|
2001-01-11 00:59:25 +01:00
|
|
|
|
2001-04-10 23:16:07 +02:00
|
|
|
void msvcrt_init_io(void);
|
|
|
|
void msvcrt_init_console(void);
|
|
|
|
void msvcrt_free_console(void);
|
|
|
|
void msvcrt_init_args(void);
|
|
|
|
void msvcrt_free_args(void);
|
|
|
|
void msvcrt_init_vtables(void);
|
2001-01-11 00:59:25 +01:00
|
|
|
|
2001-12-21 21:27:39 +01:00
|
|
|
typedef void* (*MSVCRT_malloc_func)(unsigned int);
|
|
|
|
typedef void (*MSVCRT_free_func)(void*);
|
2001-01-11 00:59:25 +01:00
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* Init
|
|
|
|
*/
|
|
|
|
BOOL WINAPI MSVCRT_Init(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
|
|
|
|
{
|
|
|
|
MSVCRT_thread_data *tls;
|
|
|
|
|
|
|
|
TRACE("(0x%08x, %s, %p) pid(%ld), tid(%ld), tls(%ld)\n",
|
2001-04-10 23:16:07 +02:00
|
|
|
hinstDLL, msvcrt_get_reason(fdwReason), lpvReserved,
|
2001-01-11 00:59:25 +01:00
|
|
|
(long)GetCurrentProcessId(), (long)GetCurrentThreadId(),
|
|
|
|
(long)MSVCRT_tls_index);
|
|
|
|
|
|
|
|
switch (fdwReason)
|
|
|
|
{
|
|
|
|
case DLL_PROCESS_ATTACH:
|
2001-04-10 23:16:07 +02:00
|
|
|
if (!msvcrt_init_tls())
|
2001-01-11 00:59:25 +01:00
|
|
|
return FALSE;
|
2001-04-10 23:16:07 +02:00
|
|
|
msvcrt_init_vtables();
|
|
|
|
msvcrt_init_critical_sections();
|
|
|
|
msvcrt_init_io();
|
|
|
|
msvcrt_init_console();
|
|
|
|
msvcrt_init_args();
|
2001-01-11 00:59:25 +01:00
|
|
|
MSVCRT_setlocale(0, "C");
|
|
|
|
TRACE("finished process init\n");
|
|
|
|
/* FALL THROUGH for Initial TLS allocation!! */
|
|
|
|
case DLL_THREAD_ATTACH:
|
|
|
|
TRACE("starting thread init\n");
|
|
|
|
/* Create TLS */
|
|
|
|
tls = (MSVCRT_thread_data*) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
|
|
|
|
sizeof(MSVCRT_thread_data));
|
|
|
|
if (!tls || !TlsSetValue(MSVCRT_tls_index, tls))
|
|
|
|
{
|
|
|
|
ERR("TLS init failed! error = %ld\n", GetLastError());
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
TRACE("finished thread init\n");
|
|
|
|
break;
|
|
|
|
case DLL_PROCESS_DETACH:
|
2001-04-10 23:16:07 +02:00
|
|
|
msvcrt_free_critical_sections();
|
|
|
|
_fcloseall();
|
|
|
|
msvcrt_free_console();
|
|
|
|
msvcrt_free_args();
|
|
|
|
if (!msvcrt_free_tls())
|
2001-01-11 00:59:25 +01:00
|
|
|
return FALSE;
|
|
|
|
TRACE("finished process free\n");
|
|
|
|
break;
|
|
|
|
case DLL_THREAD_DETACH:
|
|
|
|
/* Free TLS */
|
|
|
|
tls = TlsGetValue(MSVCRT_tls_index);
|
|
|
|
|
|
|
|
if (!tls)
|
|
|
|
{
|
|
|
|
ERR("TLS free failed! error = %ld\n", GetLastError());
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
HeapFree(GetProcessHeap(), 0, tls);
|
|
|
|
TRACE("finished thread free\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2001-04-10 23:16:07 +02:00
|
|
|
static inline BOOL msvcrt_init_tls(void)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
|
|
|
MSVCRT_tls_index = TlsAlloc();
|
|
|
|
|
|
|
|
if (MSVCRT_tls_index == TLS_OUT_OF_INDEXES)
|
|
|
|
{
|
|
|
|
ERR("TlsAlloc() failed!\n");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2001-04-10 23:16:07 +02:00
|
|
|
static inline BOOL msvcrt_free_tls(void)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
|
|
|
if (!TlsFree(MSVCRT_tls_index))
|
|
|
|
{
|
|
|
|
ERR("TlsFree() failed!\n");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2001-04-10 23:16:07 +02:00
|
|
|
static inline void msvcrt_init_critical_sections(void)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
|
|
|
InitializeCriticalSectionAndSpinCount(&MSVCRT_heap_cs, 4000);
|
|
|
|
InitializeCriticalSection(&MSVCRT_file_cs);
|
|
|
|
InitializeCriticalSection(&MSVCRT_exit_cs);
|
|
|
|
InitializeCriticalSection(&MSVCRT_console_cs);
|
|
|
|
InitializeCriticalSection(&MSVCRT_locale_cs);
|
|
|
|
}
|
|
|
|
|
2001-04-10 23:16:07 +02:00
|
|
|
static inline void msvcrt_free_critical_sections(void)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
|
|
|
DeleteCriticalSection(&MSVCRT_locale_cs);
|
|
|
|
DeleteCriticalSection(&MSVCRT_console_cs);
|
|
|
|
DeleteCriticalSection(&MSVCRT_exit_cs);
|
|
|
|
DeleteCriticalSection(&MSVCRT_file_cs);
|
|
|
|
DeleteCriticalSection(&MSVCRT_heap_cs);
|
|
|
|
}
|
|
|
|
|
2001-04-10 23:16:07 +02:00
|
|
|
const char* msvcrt_get_reason(DWORD reason)
|
2001-01-11 00:59:25 +01: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 20:56:41 +02:00
|
|
|
* $I10_OUTPUT (MSVCRT.@)
|
|
|
|
* Function not really understood but needed to make the DLL work
|
2001-01-11 00:59:25 +01:00
|
|
|
*/
|
|
|
|
void MSVCRT_I10_OUTPUT(void)
|
|
|
|
{
|
|
|
|
/* FIXME: This is probably data, not a function */
|
|
|
|
}
|
|
|
|
|
2001-12-21 21:27:39 +01:00
|
|
|
|
2001-07-11 20:56:41 +02:00
|
|
|
/*********************************************************************
|
|
|
|
* __unDName (MSVCRT.@)
|
|
|
|
* Function not really understood but needed to make the DLL work
|
|
|
|
*/
|
2001-12-21 21:27:39 +01:00
|
|
|
char* MSVCRT___unDName(int unknown, const char* mangled,
|
|
|
|
MSVCRT_malloc_func memget,
|
|
|
|
MSVCRT_free_func memfree,
|
|
|
|
unsigned int flags)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
2001-12-21 21:27:39 +01:00
|
|
|
char* ret;
|
|
|
|
|
|
|
|
FIXME("(%d,%s,%p,%p,%x) stub!\n", unknown, mangled, memget, memfree, flags);
|
|
|
|
|
|
|
|
/* Experimentation reveals the following flag meanings when set:
|
|
|
|
* 0x0001 - Dont show __ in calling convention
|
|
|
|
* 0x0002 - Dont show calling convention at all
|
|
|
|
* 0x0004 - Dont show function/method return value
|
|
|
|
* 0x0010 - Same as 0x1
|
|
|
|
* 0x0080 - Dont show access specifier (public/protected/private)
|
|
|
|
* 0x0200 - Dont show static specifier
|
|
|
|
* 0x1000 - Only report the variable/class name
|
|
|
|
*/
|
|
|
|
/* Duplicate the mangled name; for comparisons it doesn't matter anyway */
|
|
|
|
ret = memget(strlen(mangled) + 1);
|
|
|
|
strcpy(ret, mangled);
|
|
|
|
return ret;
|
2001-01-11 00:59:25 +01:00
|
|
|
}
|
|
|
|
|
2001-12-21 21:27:39 +01:00
|
|
|
|
2001-07-11 20:56:41 +02:00
|
|
|
/*********************************************************************
|
|
|
|
* __unDNameEx (MSVCRT.@)
|
|
|
|
* Function not really understood but needed to make the DLL work
|
|
|
|
*/
|
2001-12-21 21:27:39 +01:00
|
|
|
char* MSVCRT___unDNameEx(void)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
2001-12-21 21:27:39 +01:00
|
|
|
return NULL;
|
2001-01-11 00:59:25 +01:00
|
|
|
}
|