Jon Griffiths | 1db20bf | 2001-01-10 23:59:25 +0000 | [diff] [blame] | 1 | /* |
| 2 | * msvcrt.dll initialisation functions |
| 3 | * |
| 4 | * Copyright 2000 Jon Griffiths |
Alexandre Julliard | 0799c1a | 2002-03-09 23:29:33 +0000 | [diff] [blame] | 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 |
Jonathan Ernst | 360a3f9 | 2006-05-18 14:49:52 +0200 | [diff] [blame] | 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA |
Jon Griffiths | 1db20bf | 2001-01-10 23:59:25 +0000 | [diff] [blame] | 19 | */ |
| 20 | #include "msvcrt.h" |
| 21 | |
Alexandre Julliard | bd1689e | 2002-01-22 00:57:16 +0000 | [diff] [blame] | 22 | #include "wine/debug.h" |
| 23 | |
| 24 | WINE_DEFAULT_DEBUG_CHANNEL(msvcrt); |
Jon Griffiths | 1db20bf | 2001-01-10 23:59:25 +0000 | [diff] [blame] | 25 | |
| 26 | /* Index to TLS */ |
Dimitrie O. Paun | 0377462 | 2004-06-25 01:19:15 +0000 | [diff] [blame] | 27 | DWORD msvcrt_tls_index; |
Jon Griffiths | 1db20bf | 2001-01-10 23:59:25 +0000 | [diff] [blame] | 28 | |
Dmitry Timoshkov | ada9dc9 | 2006-12-25 16:41:14 +0800 | [diff] [blame] | 29 | static const char* msvcrt_get_reason(DWORD reason) |
| 30 | { |
| 31 | switch (reason) |
| 32 | { |
| 33 | case DLL_PROCESS_ATTACH: return "DLL_PROCESS_ATTACH"; |
| 34 | case DLL_PROCESS_DETACH: return "DLL_PROCESS_DETACH"; |
| 35 | case DLL_THREAD_ATTACH: return "DLL_THREAD_ATTACH"; |
| 36 | case DLL_THREAD_DETACH: return "DLL_THREAD_DETACH"; |
| 37 | } |
| 38 | return "UNKNOWN"; |
| 39 | } |
Jon Griffiths | 1db20bf | 2001-01-10 23:59:25 +0000 | [diff] [blame] | 40 | |
Michael Stefaniuc | 814ca12 | 2007-06-19 22:49:04 +0200 | [diff] [blame] | 41 | static inline BOOL msvcrt_init_tls(void) |
| 42 | { |
| 43 | msvcrt_tls_index = TlsAlloc(); |
| 44 | |
| 45 | if (msvcrt_tls_index == TLS_OUT_OF_INDEXES) |
| 46 | { |
| 47 | ERR("TlsAlloc() failed!\n"); |
| 48 | return FALSE; |
| 49 | } |
| 50 | return TRUE; |
| 51 | } |
| 52 | |
| 53 | static inline BOOL msvcrt_free_tls(void) |
| 54 | { |
| 55 | if (!TlsFree(msvcrt_tls_index)) |
| 56 | { |
| 57 | ERR("TlsFree() failed!\n"); |
| 58 | return FALSE; |
| 59 | } |
| 60 | return TRUE; |
| 61 | } |
| 62 | |
Jon Griffiths | 1db20bf | 2001-01-10 23:59:25 +0000 | [diff] [blame] | 63 | /********************************************************************* |
| 64 | * Init |
| 65 | */ |
Alexandre Julliard | 1e1313d | 2002-11-04 23:53:41 +0000 | [diff] [blame] | 66 | BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) |
Jon Griffiths | 1db20bf | 2001-01-10 23:59:25 +0000 | [diff] [blame] | 67 | { |
Dimitrie O. Paun | 0377462 | 2004-06-25 01:19:15 +0000 | [diff] [blame] | 68 | thread_data_t *tls; |
Jon Griffiths | 1db20bf | 2001-01-10 23:59:25 +0000 | [diff] [blame] | 69 | |
Alexandre Julliard | 4305e6d | 2008-12-11 21:13:20 +0100 | [diff] [blame] | 70 | TRACE("(%p, %s, %p) pid(%x), tid(%x), tls(%u)\n", |
Francois Gouget | 203a8f8 | 2001-04-10 21:16:07 +0000 | [diff] [blame] | 71 | hinstDLL, msvcrt_get_reason(fdwReason), lpvReserved, |
Alexandre Julliard | ac13d2f | 2003-02-18 23:29:47 +0000 | [diff] [blame] | 72 | GetCurrentProcessId(), GetCurrentThreadId(), |
Alexandre Julliard | 4305e6d | 2008-12-11 21:13:20 +0100 | [diff] [blame] | 73 | msvcrt_tls_index); |
Jon Griffiths | 1db20bf | 2001-01-10 23:59:25 +0000 | [diff] [blame] | 74 | |
| 75 | switch (fdwReason) |
| 76 | { |
| 77 | case DLL_PROCESS_ATTACH: |
Francois Gouget | 203a8f8 | 2001-04-10 21:16:07 +0000 | [diff] [blame] | 78 | if (!msvcrt_init_tls()) |
Jon Griffiths | 1db20bf | 2001-01-10 23:59:25 +0000 | [diff] [blame] | 79 | return FALSE; |
Peter Hunnisett | d1a79ea | 2002-02-21 20:22:00 +0000 | [diff] [blame] | 80 | msvcrt_init_mt_locks(); |
Francois Gouget | 203a8f8 | 2001-04-10 21:16:07 +0000 | [diff] [blame] | 81 | msvcrt_init_io(); |
| 82 | msvcrt_init_console(); |
| 83 | msvcrt_init_args(); |
Juan Lang | e5b4a69 | 2005-05-13 17:44:28 +0000 | [diff] [blame] | 84 | msvcrt_init_signals(); |
Jon Griffiths | 1db20bf | 2001-01-10 23:59:25 +0000 | [diff] [blame] | 85 | MSVCRT_setlocale(0, "C"); |
Mikolaj Zalewski | ea824f8 | 2007-08-19 20:19:37 -0700 | [diff] [blame] | 86 | _setmbcp(_MB_CP_LOCALE); |
Jon Griffiths | 1db20bf | 2001-01-10 23:59:25 +0000 | [diff] [blame] | 87 | TRACE("finished process init\n"); |
Alexandre Julliard | 44b4235 | 2002-07-19 03:24:50 +0000 | [diff] [blame] | 88 | break; |
Jon Griffiths | 1db20bf | 2001-01-10 23:59:25 +0000 | [diff] [blame] | 89 | case DLL_THREAD_ATTACH: |
Jon Griffiths | 1db20bf | 2001-01-10 23:59:25 +0000 | [diff] [blame] | 90 | break; |
| 91 | case DLL_PROCESS_DETACH: |
Peter Hunnisett | d1a79ea | 2002-02-21 20:22:00 +0000 | [diff] [blame] | 92 | msvcrt_free_mt_locks(); |
Alexandre Julliard | af0d206 | 2002-07-05 21:23:07 +0000 | [diff] [blame] | 93 | msvcrt_free_io(); |
Francois Gouget | 203a8f8 | 2001-04-10 21:16:07 +0000 | [diff] [blame] | 94 | msvcrt_free_console(); |
| 95 | msvcrt_free_args(); |
Juan Lang | e5b4a69 | 2005-05-13 17:44:28 +0000 | [diff] [blame] | 96 | msvcrt_free_signals(); |
Francois Gouget | 203a8f8 | 2001-04-10 21:16:07 +0000 | [diff] [blame] | 97 | if (!msvcrt_free_tls()) |
Jon Griffiths | 1db20bf | 2001-01-10 23:59:25 +0000 | [diff] [blame] | 98 | return FALSE; |
| 99 | TRACE("finished process free\n"); |
| 100 | break; |
| 101 | case DLL_THREAD_DETACH: |
| 102 | /* Free TLS */ |
Dimitrie O. Paun | 0377462 | 2004-06-25 01:19:15 +0000 | [diff] [blame] | 103 | tls = TlsGetValue(msvcrt_tls_index); |
Maxime Bellengé | def7563 | 2005-12-26 12:57:06 +0100 | [diff] [blame] | 104 | if (tls) |
| 105 | { |
| 106 | HeapFree(GetProcessHeap(),0,tls->efcvt_buffer); |
Alexandre Julliard | f9e5b0f | 2006-01-14 17:22:03 +0100 | [diff] [blame] | 107 | HeapFree(GetProcessHeap(),0,tls->asctime_buffer); |
Maxime Bellengé | def7563 | 2005-12-26 12:57:06 +0100 | [diff] [blame] | 108 | HeapFree(GetProcessHeap(),0,tls->wasctime_buffer); |
Alexandre Julliard | 2dacd3c | 2006-01-23 19:58:10 +0100 | [diff] [blame] | 109 | HeapFree(GetProcessHeap(),0,tls->strerror_buffer); |
Maxime Bellengé | def7563 | 2005-12-26 12:57:06 +0100 | [diff] [blame] | 110 | } |
Michael Stefaniuc | 5ad7d85 | 2004-12-23 17:06:43 +0000 | [diff] [blame] | 111 | HeapFree(GetProcessHeap(), 0, tls); |
Jon Griffiths | 1db20bf | 2001-01-10 23:59:25 +0000 | [diff] [blame] | 112 | TRACE("finished thread free\n"); |
| 113 | break; |
| 114 | } |
| 115 | return TRUE; |
| 116 | } |
| 117 | |
Jon Griffiths | 1db20bf | 2001-01-10 23:59:25 +0000 | [diff] [blame] | 118 | /********************************************************************* |
Patrik Stridvall | 044855c | 2001-07-11 18:56:41 +0000 | [diff] [blame] | 119 | * $I10_OUTPUT (MSVCRT.@) |
| 120 | * Function not really understood but needed to make the DLL work |
Jon Griffiths | 1db20bf | 2001-01-10 23:59:25 +0000 | [diff] [blame] | 121 | */ |
Alexandre Julliard | 24beabf | 2006-06-13 11:21:19 +0200 | [diff] [blame] | 122 | void CDECL MSVCRT_I10_OUTPUT(void) |
Jon Griffiths | 1db20bf | 2001-01-10 23:59:25 +0000 | [diff] [blame] | 123 | { |
| 124 | /* FIXME: This is probably data, not a function */ |
Rein Klazes | 03d9cf2 | 2004-12-10 15:28:25 +0000 | [diff] [blame] | 125 | /* no it is a function. I10 is an Int of 10 bytes */ |
Austin English | 05faae7 | 2008-04-08 16:22:43 -0500 | [diff] [blame] | 126 | /* also known as 80 bit floating point (long double */ |
Rein Klazes | 03d9cf2 | 2004-12-10 15:28:25 +0000 | [diff] [blame] | 127 | /* for some compilers, not MSVC) */ |
Jon Griffiths | 1db20bf | 2001-01-10 23:59:25 +0000 | [diff] [blame] | 128 | } |