2007-03-14 20:24:57 +00:00
|
|
|
#include <precomp.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <internal/tls.h>
|
|
|
|
#include <internal/rterror.h>
|
|
|
|
|
2011-12-02 21:18:42 +00:00
|
|
|
/* Index to TLS */
|
|
|
|
static DWORD msvcrt_tls_index;
|
2007-03-14 20:24:57 +00:00
|
|
|
|
2016-08-05 21:33:54 +00:00
|
|
|
BOOL msvcrt_init_tls(void)
|
2007-03-14 20:24:57 +00:00
|
|
|
{
|
2011-12-02 21:18:42 +00:00
|
|
|
msvcrt_tls_index = TlsAlloc();
|
|
|
|
|
|
|
|
if (msvcrt_tls_index == TLS_OUT_OF_INDEXES)
|
|
|
|
{
|
|
|
|
ERR("TlsAlloc() failed!\n");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
return TRUE;
|
2007-03-14 20:24:57 +00:00
|
|
|
}
|
|
|
|
|
2016-08-05 21:33:54 +00:00
|
|
|
BOOL msvcrt_free_tls(void)
|
2007-03-14 20:24:57 +00:00
|
|
|
{
|
2011-12-02 21:18:42 +00:00
|
|
|
if (!TlsFree(msvcrt_tls_index))
|
|
|
|
{
|
|
|
|
ERR("TlsFree() failed!\n");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
return TRUE;
|
2007-03-14 20:24:57 +00:00
|
|
|
}
|
|
|
|
|
2011-12-02 21:18:42 +00:00
|
|
|
thread_data_t *msvcrt_get_thread_data(void)
|
2007-03-14 20:24:57 +00:00
|
|
|
{
|
2011-12-02 21:18:42 +00:00
|
|
|
thread_data_t *ptr;
|
|
|
|
DWORD err = GetLastError(); /* need to preserve last error */
|
|
|
|
|
|
|
|
if (!(ptr = TlsGetValue( msvcrt_tls_index )))
|
|
|
|
{
|
|
|
|
if (!(ptr = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*ptr) )))
|
|
|
|
_amsg_exit( _RT_THREAD );
|
|
|
|
if (!TlsSetValue( msvcrt_tls_index, ptr )) _amsg_exit( _RT_THREAD );
|
|
|
|
ptr->tid = GetCurrentThreadId();
|
|
|
|
ptr->handle = INVALID_HANDLE_VALUE;
|
|
|
|
ptr->random_seed = 1;
|
2012-12-09 03:17:14 +00:00
|
|
|
ptr->locinfo = MSVCRT_locale->locinfo;
|
|
|
|
ptr->mbcinfo = MSVCRT_locale->mbcinfo;
|
2011-12-02 21:18:42 +00:00
|
|
|
}
|
|
|
|
SetLastError( err );
|
|
|
|
return ptr;
|
2007-03-14 20:24:57 +00:00
|
|
|
}
|
|
|
|
|
2016-08-05 21:33:54 +00:00
|
|
|
void msvcrt_free_tls_mem(void)
|
2007-03-14 20:24:57 +00:00
|
|
|
{
|
2011-12-02 21:18:42 +00:00
|
|
|
thread_data_t *tls = TlsGetValue(msvcrt_tls_index);
|
|
|
|
|
|
|
|
if (tls)
|
|
|
|
{
|
|
|
|
CloseHandle(tls->handle);
|
|
|
|
HeapFree(GetProcessHeap(),0,tls->efcvt_buffer);
|
|
|
|
HeapFree(GetProcessHeap(),0,tls->asctime_buffer);
|
|
|
|
HeapFree(GetProcessHeap(),0,tls->wasctime_buffer);
|
|
|
|
HeapFree(GetProcessHeap(),0,tls->strerror_buffer);
|
|
|
|
HeapFree(GetProcessHeap(),0,tls->wcserror_buffer);
|
|
|
|
HeapFree(GetProcessHeap(),0,tls->time_buffer);
|
|
|
|
//if(tls->have_locale) {
|
|
|
|
// free_locinfo(tls->locinfo);
|
|
|
|
// free_mbcinfo(tls->mbcinfo);
|
|
|
|
//}
|
|
|
|
}
|
|
|
|
HeapFree(GetProcessHeap(), 0, tls);
|
2007-03-14 20:24:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* EOF */
|
|
|
|
|