msvcrt: Export the onexit functions from the import library.

Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Alexandre Julliard 2019-03-26 20:21:14 +01:00
parent 59e6cc1645
commit 0673ddf3a5
14 changed files with 148 additions and 140 deletions

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -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.@)
*/

View file

@ -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;

View file

@ -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

119
dlls/msvcrt/onexit.c Normal file
View file

@ -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;
}

View file

@ -26,6 +26,7 @@ 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) 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