From 0673ddf3a55eb524f8284be3b2fc9ab62a2acf52 Mon Sep 17 00:00:00 2001 From: Alexandre Julliard Date: Tue, 26 Mar 2019 20:21:14 +0100 Subject: [PATCH] msvcrt: Export the onexit functions from the import library. Signed-off-by: Alexandre Julliard --- dlls/msvcr100/Makefile.in | 1 + dlls/msvcr110/Makefile.in | 1 + dlls/msvcr120/Makefile.in | 1 + dlls/msvcr70/Makefile.in | 1 + dlls/msvcr71/Makefile.in | 1 + dlls/msvcr80/Makefile.in | 1 + dlls/msvcr90/Makefile.in | 1 + dlls/msvcrt/Makefile.in | 1 + dlls/msvcrt/exit.c | 138 ++---------------------------------- dlls/msvcrt/msvcrt.h | 7 ++ dlls/msvcrt/msvcrt.spec | 3 - dlls/msvcrt/onexit.c | 119 +++++++++++++++++++++++++++++++ dlls/ucrtbase/Makefile.in | 1 + dlls/ucrtbase/ucrtbase.spec | 12 ++-- 14 files changed, 148 insertions(+), 140 deletions(-) create mode 100644 dlls/msvcrt/onexit.c diff --git a/dlls/msvcr100/Makefile.in b/dlls/msvcr100/Makefile.in index 07a3ece3cbb..50182263a47 100644 --- a/dlls/msvcr100/Makefile.in +++ b/dlls/msvcr100/Makefile.in @@ -26,6 +26,7 @@ C_SRCS = \ math.c \ mbcs.c \ misc.c \ + onexit.c \ process.c \ scanf.c \ scheduler.c \ diff --git a/dlls/msvcr110/Makefile.in b/dlls/msvcr110/Makefile.in index 056eb3989f1..d00d24e36b0 100644 --- a/dlls/msvcr110/Makefile.in +++ b/dlls/msvcr110/Makefile.in @@ -26,6 +26,7 @@ C_SRCS = \ math.c \ mbcs.c \ misc.c \ + onexit.c \ process.c \ scanf.c \ scheduler.c \ diff --git a/dlls/msvcr120/Makefile.in b/dlls/msvcr120/Makefile.in index 1ee05d9a1be..7f32a175d01 100644 --- a/dlls/msvcr120/Makefile.in +++ b/dlls/msvcr120/Makefile.in @@ -26,6 +26,7 @@ C_SRCS = \ math.c \ mbcs.c \ misc.c \ + onexit.c \ process.c \ scanf.c \ scheduler.c \ diff --git a/dlls/msvcr70/Makefile.in b/dlls/msvcr70/Makefile.in index e068b13c235..f44f43787cb 100644 --- a/dlls/msvcr70/Makefile.in +++ b/dlls/msvcr70/Makefile.in @@ -26,6 +26,7 @@ C_SRCS = \ math.c \ mbcs.c \ misc.c \ + onexit.c \ process.c \ scanf.c \ string.c \ diff --git a/dlls/msvcr71/Makefile.in b/dlls/msvcr71/Makefile.in index 58563b7f5cb..e2a86798ea7 100644 --- a/dlls/msvcr71/Makefile.in +++ b/dlls/msvcr71/Makefile.in @@ -26,6 +26,7 @@ C_SRCS = \ math.c \ mbcs.c \ misc.c \ + onexit.c \ process.c \ scanf.c \ string.c \ diff --git a/dlls/msvcr80/Makefile.in b/dlls/msvcr80/Makefile.in index 05b7a5b5af2..e9355091052 100644 --- a/dlls/msvcr80/Makefile.in +++ b/dlls/msvcr80/Makefile.in @@ -26,6 +26,7 @@ C_SRCS = \ math.c \ mbcs.c \ misc.c \ + onexit.c \ process.c \ scanf.c \ string.c \ diff --git a/dlls/msvcr90/Makefile.in b/dlls/msvcr90/Makefile.in index 590b4b87075..550878f72e6 100644 --- a/dlls/msvcr90/Makefile.in +++ b/dlls/msvcr90/Makefile.in @@ -26,6 +26,7 @@ C_SRCS = \ math.c \ mbcs.c \ misc.c \ + onexit.c \ process.c \ scanf.c \ string.c \ diff --git a/dlls/msvcrt/Makefile.in b/dlls/msvcrt/Makefile.in index ad6864a028a..b563516508d 100644 --- a/dlls/msvcrt/Makefile.in +++ b/dlls/msvcrt/Makefile.in @@ -25,6 +25,7 @@ C_SRCS = \ math.c \ mbcs.c \ misc.c \ + onexit.c \ process.c \ scanf.c \ scheduler.c \ diff --git a/dlls/msvcrt/exit.c b/dlls/msvcrt/exit.c index 0a7e303d461..61112993bb9 100644 --- a/dlls/msvcrt/exit.c +++ b/dlls/msvcrt/exit.c @@ -31,28 +31,12 @@ WINE_DEFAULT_DEBUG_CHANNEL(msvcrt); static MSVCRT_purecall_handler purecall_handler = NULL; -typedef struct MSVCRT__onexit_table_t -{ - MSVCRT__onexit_t *_first; - MSVCRT__onexit_t *_last; - MSVCRT__onexit_t *_end; -} MSVCRT__onexit_table_t; - static MSVCRT__onexit_table_t MSVCRT_atexit_table; static MSVCRT__onexit_table_t MSVCRT_quick_exit_table; typedef void (__stdcall *_tls_callback_type)(void*,ULONG,void*); static _tls_callback_type tls_atexit_callback; -static CRITICAL_SECTION MSVCRT_onexit_cs; -static CRITICAL_SECTION_DEBUG MSVCRT_onexit_cs_debug = -{ - 0, 0, &MSVCRT_onexit_cs, - { &MSVCRT_onexit_cs_debug.ProcessLocksList, &MSVCRT_onexit_cs_debug.ProcessLocksList }, - 0, 0, { (DWORD_PTR)(__FILE__ ": MSVCRT_onexit_cs") } -}; -static CRITICAL_SECTION MSVCRT_onexit_cs = { &MSVCRT_onexit_cs_debug, -1, 0, 0, 0, 0 }; - extern int MSVCRT_app_type; extern MSVCRT_wchar_t *MSVCRT__wpgmptr; @@ -61,93 +45,15 @@ static int MSVCRT_error_mode = MSVCRT__OUT_TO_DEFAULT; void (*CDECL _aexit_rtn)(int) = MSVCRT__exit; -static int initialize_onexit_table(MSVCRT__onexit_table_t *table) -{ - if (!table) - return -1; - - if (table->_first == table->_end) - table->_last = table->_end = table->_first = NULL; - return 0; -} - -static int register_onexit_function(MSVCRT__onexit_table_t *table, MSVCRT__onexit_t func) -{ - if (!table) - return -1; - - EnterCriticalSection(&MSVCRT_onexit_cs); - if (!table->_first) - { - table->_first = MSVCRT_calloc(32, sizeof(void *)); - if (!table->_first) - { - WARN("failed to allocate initial table.\n"); - LeaveCriticalSection(&MSVCRT_onexit_cs); - return -1; - } - table->_last = table->_first; - table->_end = table->_first + 32; - } - - /* grow if full */ - if (table->_last == table->_end) - { - int len = table->_end - table->_first; - MSVCRT__onexit_t *tmp = MSVCRT_realloc(table->_first, 2 * len * sizeof(void *)); - if (!tmp) - { - WARN("failed to grow table.\n"); - LeaveCriticalSection(&MSVCRT_onexit_cs); - return -1; - } - table->_first = tmp; - table->_end = table->_first + 2 * len; - table->_last = table->_first + len; - } - - *table->_last = func; - table->_last++; - LeaveCriticalSection(&MSVCRT_onexit_cs); - return 0; -} - -static int execute_onexit_table(MSVCRT__onexit_table_t *table) -{ - MSVCRT__onexit_t *func; - MSVCRT__onexit_table_t copy; - - if (!table) - return -1; - - EnterCriticalSection(&MSVCRT_onexit_cs); - if (!table->_first || table->_first >= table->_last) - { - LeaveCriticalSection(&MSVCRT_onexit_cs); - return 0; - } - copy._first = table->_first; - copy._last = table->_last; - copy._end = table->_end; - memset(table, 0, sizeof(*table)); - initialize_onexit_table(table); - LeaveCriticalSection(&MSVCRT_onexit_cs); - - for (func = copy._last - 1; func >= copy._first; func--) - { - if (*func) - (*func)(); - } - - MSVCRT_free(copy._first); - return 0; -} +extern int CDECL _initialize_onexit_table(MSVCRT__onexit_table_t *table); +extern int CDECL _register_onexit_function(MSVCRT__onexit_table_t *table, MSVCRT__onexit_t func); +extern int CDECL _execute_onexit_table(MSVCRT__onexit_table_t *table); static void call_atexit(void) { /* Note: should only be called with the exit lock held */ if (tls_atexit_callback) tls_atexit_callback(NULL, DLL_PROCESS_DETACH, NULL); - execute_onexit_table(&MSVCRT_atexit_table); + _execute_onexit_table(&MSVCRT_atexit_table); } /********************************************************************* @@ -363,7 +269,7 @@ MSVCRT__onexit_t CDECL MSVCRT__onexit(MSVCRT__onexit_t func) return NULL; LOCK_EXIT; - register_onexit_function(&MSVCRT_atexit_table, func); + _register_onexit_function(&MSVCRT_atexit_table, func); UNLOCK_EXIT; return func; @@ -409,7 +315,7 @@ int CDECL MSVCRT_atexit(void (__cdecl *func)(void)) int CDECL MSVCRT__crt_at_quick_exit(void (__cdecl *func)(void)) { TRACE("(%p)\n", func); - return register_onexit_function(&MSVCRT_quick_exit_table, (MSVCRT__onexit_t)func); + return _register_onexit_function(&MSVCRT_quick_exit_table, (MSVCRT__onexit_t)func); } /********************************************************************* @@ -419,7 +325,7 @@ void CDECL MSVCRT_quick_exit(int exitcode) { TRACE("(%d)\n", exitcode); - execute_onexit_table(&MSVCRT_quick_exit_table); + _execute_onexit_table(&MSVCRT_quick_exit_table); MSVCRT__exit(exitcode); } @@ -432,36 +338,6 @@ int CDECL MSVCRT__crt_atexit(void (__cdecl *func)(void)) return MSVCRT__onexit((MSVCRT__onexit_t)func) == (MSVCRT__onexit_t)func ? 0 : -1; } -/********************************************************************* - * _initialize_onexit_table (UCRTBASE.@) - */ -int CDECL MSVCRT__initialize_onexit_table(MSVCRT__onexit_table_t *table) -{ - TRACE("(%p)\n", table); - - return initialize_onexit_table(table); -} - -/********************************************************************* - * _register_onexit_function (UCRTBASE.@) - */ -int CDECL MSVCRT__register_onexit_function(MSVCRT__onexit_table_t *table, MSVCRT__onexit_t func) -{ - TRACE("(%p %p)\n", table, func); - - return register_onexit_function(table, func); -} - -/********************************************************************* - * _execute_onexit_table (UCRTBASE.@) - */ -int CDECL MSVCRT__execute_onexit_table(MSVCRT__onexit_table_t *table) -{ - TRACE("(%p)\n", table); - - return execute_onexit_table(table); -} - /********************************************************************* * _register_thread_local_exe_atexit_callback (UCRTBASE.@) */ diff --git a/dlls/msvcrt/msvcrt.h b/dlls/msvcrt/msvcrt.h index 10f3dc1b97c..4be54f58209 100644 --- a/dlls/msvcrt/msvcrt.h +++ b/dlls/msvcrt/msvcrt.h @@ -206,6 +206,13 @@ typedef struct MSVCRT_localeinfo_struct MSVCRT_pthreadmbcinfo mbcinfo; } MSVCRT__locale_tstruct, *MSVCRT__locale_t; +typedef struct MSVCRT__onexit_table_t +{ + MSVCRT__onexit_t *_first; + MSVCRT__onexit_t *_last; + MSVCRT__onexit_t *_end; +} MSVCRT__onexit_table_t; + typedef struct _frame_info { void *object; diff --git a/dlls/msvcrt/msvcrt.spec b/dlls/msvcrt/msvcrt.spec index c2c272b6376..91cc233f385 100644 --- a/dlls/msvcrt/msvcrt.spec +++ b/dlls/msvcrt/msvcrt.spec @@ -422,7 +422,6 @@ @ varargs _execle(str str) @ varargs _execlp(str str) @ varargs _execlpe(str str) -@ cdecl _execute_onexit_table(ptr) MSVCRT__execute_onexit_table # for compatibility with Mingw @ cdecl _execv(str ptr) @ cdecl _execve(str ptr ptr) MSVCRT__execve @ cdecl _execvp(str ptr) @@ -555,7 +554,6 @@ @ cdecl _i64toa_s(int64 ptr long long) MSVCRT__i64toa_s @ cdecl _i64tow(int64 ptr long) ntdll._i64tow @ cdecl _i64tow_s(int64 ptr long long) MSVCRT__i64tow_s -@ cdecl _initialize_onexit_table(ptr) MSVCRT__initialize_onexit_table # for compatibility with Mingw @ cdecl _initterm(ptr ptr) @ cdecl _initterm_e(ptr ptr) @ stub -arch=i386 _inp(long) @@ -869,7 +867,6 @@ # extern _pwctype @ cdecl _read(long ptr long) MSVCRT__read # stub _realloc_dbg(ptr long long str long) -@ cdecl _register_onexit_function(ptr ptr) MSVCRT__register_onexit_function # for compatibility with Mingw @ cdecl _resetstkoflw() MSVCRT__resetstkoflw @ cdecl _rmdir(str) MSVCRT__rmdir @ cdecl _rmtmp() MSVCRT__rmtmp diff --git a/dlls/msvcrt/onexit.c b/dlls/msvcrt/onexit.c new file mode 100644 index 00000000000..d1877a1c38e --- /dev/null +++ b/dlls/msvcrt/onexit.c @@ -0,0 +1,119 @@ +/* + * msvcrt onexit functions + * + * Copyright 2016 Nikolay Sivov + * + * 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA + */ + +/* these functions are part of the import lib for compatibility with the Mingw runtime */ +#if 0 +#pragma makedep implib +#endif + +#include "msvcrt.h" +#include "mtdll.h" + + +/********************************************************************* + * _initialize_onexit_table (UCRTBASE.@) + */ +int CDECL _initialize_onexit_table(MSVCRT__onexit_table_t *table) +{ + if (!table) + return -1; + + if (table->_first == table->_end) + table->_last = table->_end = table->_first = NULL; + return 0; +} + + +/********************************************************************* + * _register_onexit_function (UCRTBASE.@) + */ +int CDECL _register_onexit_function(MSVCRT__onexit_table_t *table, MSVCRT__onexit_t func) +{ + if (!table) + return -1; + + _mlock(_EXIT_LOCK1); + if (!table->_first) + { + table->_first = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, 32 * sizeof(void *)); + if (!table->_first) + { + _munlock(_EXIT_LOCK1); + return -1; + } + table->_last = table->_first; + table->_end = table->_first + 32; + } + + /* grow if full */ + if (table->_last == table->_end) + { + int len = table->_end - table->_first; + MSVCRT__onexit_t *tmp = HeapReAlloc(GetProcessHeap(), 0, table->_first, 2 * len * sizeof(void *)); + if (!tmp) + { + _munlock(_EXIT_LOCK1); + return -1; + } + table->_first = tmp; + table->_end = table->_first + 2 * len; + table->_last = table->_first + len; + } + + *table->_last = func; + table->_last++; + _munlock(_EXIT_LOCK1); + return 0; +} + + +/********************************************************************* + * _execute_onexit_table (UCRTBASE.@) + */ +int CDECL _execute_onexit_table(MSVCRT__onexit_table_t *table) +{ + MSVCRT__onexit_t *func; + MSVCRT__onexit_table_t copy; + + if (!table) + return -1; + + _mlock(_EXIT_LOCK1); + if (!table->_first || table->_first >= table->_last) + { + _munlock(_EXIT_LOCK1); + return 0; + } + copy._first = table->_first; + copy._last = table->_last; + copy._end = table->_end; + memset(table, 0, sizeof(*table)); + _initialize_onexit_table(table); + _munlock(_EXIT_LOCK1); + + for (func = copy._last - 1; func >= copy._first; func--) + { + if (*func) + (*func)(); + } + + HeapFree(GetProcessHeap(), 0, copy._first); + return 0; +} diff --git a/dlls/ucrtbase/Makefile.in b/dlls/ucrtbase/Makefile.in index 23d8292a535..c7cc63df25e 100644 --- a/dlls/ucrtbase/Makefile.in +++ b/dlls/ucrtbase/Makefile.in @@ -26,6 +26,7 @@ C_SRCS = \ math.c \ mbcs.c \ misc.c \ + onexit.c \ process.c \ scanf.c \ string.c \ diff --git a/dlls/ucrtbase/ucrtbase.spec b/dlls/ucrtbase/ucrtbase.spec index 544ebf8c926..6dab5e7d4c5 100644 --- a/dlls/ucrtbase/ucrtbase.spec +++ b/dlls/ucrtbase/ucrtbase.spec @@ -279,7 +279,7 @@ @ varargs _execle(str str) @ varargs _execlp(str str) @ varargs _execlpe(str str) -@ cdecl _execute_onexit_table(ptr) MSVCRT__execute_onexit_table +@ cdecl _execute_onexit_table(ptr) @ cdecl _execv(str ptr) @ cdecl _execve(str ptr ptr) MSVCRT__execve @ cdecl _execvp(str ptr) @@ -419,7 +419,7 @@ @ cdecl _i64tow(int64 ptr long) ntdll._i64tow @ cdecl _i64tow_s(int64 ptr long long) MSVCRT__i64tow_s @ cdecl _initialize_narrow_environment() -@ cdecl _initialize_onexit_table(ptr) MSVCRT__initialize_onexit_table +@ cdecl _initialize_onexit_table(ptr) @ cdecl _initialize_wide_environment() @ cdecl _initterm(ptr ptr) @ cdecl _initterm_e(ptr ptr) @@ -906,7 +906,7 @@ @ stub _o__eof @ cdecl _o__errno() MSVCRT__errno @ stub _o__except1 -@ cdecl _o__execute_onexit_table(ptr) MSVCRT__execute_onexit_table +@ cdecl _o__execute_onexit_table(ptr) _execute_onexit_table @ stub _o__execv @ stub _o__execve @ stub _o__execvp @@ -1029,7 +1029,7 @@ @ stub _o__i64tow @ stub _o__i64tow_s @ stub _o__initialize_narrow_environment -@ cdecl _o__initialize_onexit_table(ptr) MSVCRT__initialize_onexit_table +@ cdecl _o__initialize_onexit_table(ptr) _initialize_onexit_table @ cdecl _o__initialize_wide_environment() _initialize_wide_environment @ stub _o__invalid_parameter_noinfo @ stub _o__invalid_parameter_noinfo_noreturn @@ -1316,7 +1316,7 @@ @ stub _o__read @ stub _o__realloc_base @ stub _o__recalloc -@ cdecl _o__register_onexit_function(ptr ptr) MSVCRT__register_onexit_function +@ cdecl _o__register_onexit_function(ptr ptr) _register_onexit_function @ stub _o__resetstkoflw @ stub _o__rmdir @ stub _o__rmtmp @@ -1861,7 +1861,7 @@ @ cdecl _read(long ptr long) MSVCRT__read @ cdecl _realloc_base(ptr long) @ cdecl _recalloc(ptr long long) -@ cdecl _register_onexit_function(ptr ptr) MSVCRT__register_onexit_function +@ cdecl _register_onexit_function(ptr ptr) @ cdecl _register_thread_local_exe_atexit_callback(ptr) @ cdecl _resetstkoflw() MSVCRT__resetstkoflw @ cdecl _rmdir(str) MSVCRT__rmdir