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
|
2006-05-18 12:49:52 +00:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2001-01-10 23:59:25 +00:00
|
|
|
*/
|
|
|
|
#include "msvcrt.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 */
|
2004-06-25 01:19:15 +00:00
|
|
|
DWORD msvcrt_tls_index;
|
2001-01-10 23:59:25 +00:00
|
|
|
|
2001-04-10 21:16:07 +00:00
|
|
|
static inline BOOL msvcrt_init_tls(void);
|
|
|
|
static inline BOOL msvcrt_free_tls(void);
|
2006-12-25 08:41:14 +00:00
|
|
|
|
|
|
|
static const char* msvcrt_get_reason(DWORD reason)
|
|
|
|
{
|
|
|
|
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-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
|
|
|
{
|
2004-06-25 01:19:15 +00:00
|
|
|
thread_data_t *tls;
|
2001-01-10 23:59:25 +00:00
|
|
|
|
2006-10-03 18:39:05 +00:00
|
|
|
TRACE("(%p, %s, %p) pid(%x), tid(%x), 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(),
|
2004-06-25 01:19:15 +00:00
|
|
|
(long)msvcrt_tls_index);
|
2001-01-10 23:59:25 +00:00
|
|
|
|
|
|
|
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();
|
2005-05-13 17:44:28 +00:00
|
|
|
msvcrt_init_signals();
|
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();
|
2005-05-13 17:44:28 +00:00
|
|
|
msvcrt_free_signals();
|
2001-04-10 21:16:07 +00:00
|
|
|
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 */
|
2004-06-25 01:19:15 +00:00
|
|
|
tls = TlsGetValue(msvcrt_tls_index);
|
2005-12-26 11:57:06 +00:00
|
|
|
if (tls)
|
|
|
|
{
|
|
|
|
HeapFree(GetProcessHeap(),0,tls->efcvt_buffer);
|
2006-01-14 16:22:03 +00:00
|
|
|
HeapFree(GetProcessHeap(),0,tls->asctime_buffer);
|
2005-12-26 11:57:06 +00:00
|
|
|
HeapFree(GetProcessHeap(),0,tls->wasctime_buffer);
|
2006-01-23 18:58:10 +00:00
|
|
|
HeapFree(GetProcessHeap(),0,tls->strerror_buffer);
|
2005-12-26 11:57:06 +00:00
|
|
|
}
|
2004-12-23 17:06:43 +00:00
|
|
|
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
|
|
|
{
|
2004-06-25 01:19:15 +00:00
|
|
|
msvcrt_tls_index = TlsAlloc();
|
2001-01-10 23:59:25 +00:00
|
|
|
|
2004-06-25 01:19:15 +00:00
|
|
|
if (msvcrt_tls_index == TLS_OUT_OF_INDEXES)
|
2001-01-10 23:59:25 +00:00
|
|
|
{
|
|
|
|
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
|
|
|
{
|
2004-06-25 01:19:15 +00:00
|
|
|
if (!TlsFree(msvcrt_tls_index))
|
2001-01-10 23:59:25 +00:00
|
|
|
{
|
|
|
|
ERR("TlsFree() failed!\n");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
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
|
|
|
*/
|
2006-06-13 09:21:19 +00:00
|
|
|
void CDECL MSVCRT_I10_OUTPUT(void)
|
2001-01-10 23:59:25 +00:00
|
|
|
{
|
|
|
|
/* FIXME: This is probably data, not a function */
|
2004-12-10 15:28:25 +00:00
|
|
|
/* no it is a function. I10 is an Int of 10 bytes */
|
|
|
|
/* also known as 80 bit flotaing point (long double */
|
|
|
|
/* for some compilers, not MSVC) */
|
2001-01-10 23:59:25 +00:00
|
|
|
}
|
2004-12-10 15:28:25 +00:00
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _adjust_fdiv (MSVCRT.@)
|
|
|
|
* Used by the MSVC compiler to work around the Pentium FDIV bug.
|
|
|
|
*/
|
|
|
|
int MSVCRT__adjust_fdiv = 0;
|