msvcrt: Only add the onexit functions to the import library of msvcrt itself.

This partially reverts 0673ddf3a5.

Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Alexandre Julliard 2019-03-29 11:37:27 +01:00
parent 62fd803e52
commit 4a5bff8368
10 changed files with 135 additions and 23 deletions

View File

@ -26,7 +26,6 @@ C_SRCS = \
math.c \
mbcs.c \
misc.c \
onexit.c \
process.c \
scanf.c \
scheduler.c \

View File

@ -26,7 +26,6 @@ C_SRCS = \
math.c \
mbcs.c \
misc.c \
onexit.c \
process.c \
scanf.c \
scheduler.c \

View File

@ -26,7 +26,6 @@ C_SRCS = \
math.c \
mbcs.c \
misc.c \
onexit.c \
process.c \
scanf.c \
scheduler.c \

View File

@ -26,7 +26,6 @@ C_SRCS = \
math.c \
mbcs.c \
misc.c \
onexit.c \
process.c \
scanf.c \
string.c \

View File

@ -26,7 +26,6 @@ C_SRCS = \
math.c \
mbcs.c \
misc.c \
onexit.c \
process.c \
scanf.c \
string.c \

View File

@ -26,7 +26,6 @@ C_SRCS = \
math.c \
mbcs.c \
misc.c \
onexit.c \
process.c \
scanf.c \
string.c \

View File

@ -26,7 +26,6 @@ C_SRCS = \
math.c \
mbcs.c \
misc.c \
onexit.c \
process.c \
scanf.c \
string.c \

View File

@ -32,11 +32,19 @@ WINE_DEFAULT_DEBUG_CHANNEL(msvcrt);
static MSVCRT_purecall_handler purecall_handler = NULL;
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;
@ -45,15 +53,93 @@ static int MSVCRT_error_mode = MSVCRT__OUT_TO_DEFAULT;
void (*CDECL _aexit_rtn)(int) = MSVCRT__exit;
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 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;
}
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);
}
/*********************************************************************
@ -269,7 +355,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;
@ -309,23 +395,26 @@ int CDECL MSVCRT_atexit(void (__cdecl *func)(void))
return MSVCRT__onexit((MSVCRT__onexit_t)func) == (MSVCRT__onexit_t)func ? 0 : -1;
}
#if _MSVCR_VER >= 140
static MSVCRT__onexit_table_t MSVCRT_quick_exit_table;
/*********************************************************************
* _crt_at_quick_exit (UCRTBASE.@)
*/
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);
}
/*********************************************************************
* quick_exit (MSVCRT.@)
* quick_exit (UCRTBASE.@)
*/
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);
}
@ -338,6 +427,37 @@ 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);
}
#endif
/*********************************************************************
* _register_thread_local_exe_atexit_callback (UCRTBASE.@)
*/

View File

@ -26,7 +26,6 @@ C_SRCS = \
math.c \
mbcs.c \
misc.c \
onexit.c \
process.c \
scanf.c \
string.c \

View File

@ -279,7 +279,7 @@
@ varargs _execle(str str)
@ varargs _execlp(str str)
@ varargs _execlpe(str str)
@ cdecl _execute_onexit_table(ptr)
@ cdecl _execute_onexit_table(ptr) MSVCRT__execute_onexit_table
@ 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)
@ cdecl _initialize_onexit_table(ptr) MSVCRT__initialize_onexit_table
@ 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) _execute_onexit_table
@ cdecl _o__execute_onexit_table(ptr) MSVCRT__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) _initialize_onexit_table
@ cdecl _o__initialize_onexit_table(ptr) MSVCRT__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) _register_onexit_function
@ cdecl _o__register_onexit_function(ptr ptr) MSVCRT__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)
@ cdecl _register_onexit_function(ptr ptr) MSVCRT__register_onexit_function
@ cdecl _register_thread_local_exe_atexit_callback(ptr)
@ cdecl _resetstkoflw() MSVCRT__resetstkoflw
@ cdecl _rmdir(str) MSVCRT__rmdir