From b59bf98b93f998512af81c0d3571bb5c49c37ab6 Mon Sep 17 00:00:00 2001 From: Alexandre Julliard Date: Wed, 26 Mar 2003 01:33:48 +0000 Subject: [PATCH] Moved errno_location support to sysdeps.c. --- include/thread.h | 1 + libs/wine/errno.c | 39 --------------------------- scheduler/sysdeps.c | 64 +++++++++++++++++++++++++++++++++++++++++++++ scheduler/thread.c | 23 +--------------- 4 files changed, 66 insertions(+), 61 deletions(-) diff --git a/include/thread.h b/include/thread.h index 5dab1a6bdf7..5fadd2b5b5c 100644 --- a/include/thread.h +++ b/include/thread.h @@ -147,6 +147,7 @@ extern TEB *THREAD_IdToTEB( DWORD id ); /* scheduler/sysdeps.c */ extern int SYSDEPS_SpawnThread( TEB *teb ); extern void SYSDEPS_SetCurThread( TEB *teb ); +extern void SYSDEPS_InitErrno(void); extern void DECLSPEC_NORETURN SYSDEPS_ExitThread( int status ); extern void DECLSPEC_NORETURN SYSDEPS_AbortThread( int status ); extern void DECLSPEC_NORETURN SYSDEPS_SwitchToThreadStack( void (*func)(void) ); diff --git a/libs/wine/errno.c b/libs/wine/errno.c index f0b950d7ee0..081221f8a1b 100644 --- a/libs/wine/errno.c +++ b/libs/wine/errno.c @@ -22,45 +22,6 @@ #include -/* default errno before threading is initialized */ -static int *default_errno_location(void) -{ - static int errno; - return &errno; -} - -/* default h_errno before threading is initialized */ -static int *default_h_errno_location(void) -{ - static int h_errno; - return &h_errno; -} - -int* (*wine_errno_location)(void) = default_errno_location; -int* (*wine_h_errno_location)(void) = default_h_errno_location; - -/*********************************************************************** - * __errno_location/__error/___errno - * - * Get the per-thread errno location. - */ -#ifdef ERRNO_LOCATION -int *ERRNO_LOCATION(void) -{ - return wine_errno_location(); -} -#endif /* ERRNO_LOCATION */ - -/*********************************************************************** - * __h_errno_location - * - * Get the per-thread h_errno location. - */ -int *__h_errno_location(void) -{ - return wine_h_errno_location(); -} - /*********************************************************************** * pthread functions */ diff --git a/scheduler/sysdeps.c b/scheduler/sysdeps.c index 0c62aa803cf..7c322d120ea 100644 --- a/scheduler/sysdeps.c +++ b/scheduler/sysdeps.c @@ -318,6 +318,70 @@ void SYSDEPS_AbortThread( int status ) } +/* default errno before threading is initialized */ +static int *default_errno_location(void) +{ + static int errno; + return &errno; +} + +/* default h_errno before threading is initialized */ +static int *default_h_errno_location(void) +{ + static int h_errno; + return &h_errno; +} + +/* errno once threading is working */ +static int *thread_errno_location(void) +{ + return &NtCurrentTeb()->thread_errno; +} + +/* h_errno once threading is working */ +static int *thread_h_errno_location(void) +{ + return &NtCurrentTeb()->thread_h_errno; +} + +static int* (*errno_location_ptr)(void) = default_errno_location; +static int* (*h_errno_location_ptr)(void) = default_h_errno_location; + +/*********************************************************************** + * __errno_location/__error/___errno + * + * Get the per-thread errno location. + */ +#ifdef ERRNO_LOCATION +int *ERRNO_LOCATION(void) +{ + return errno_location_ptr(); +} +#endif /* ERRNO_LOCATION */ + +/*********************************************************************** + * __h_errno_location + * + * Get the per-thread h_errno location. + */ +int *__h_errno_location(void) +{ + return h_errno_location_ptr(); +} + + +/*********************************************************************** + * SYSDEPS_InitErrno + * + * Initialize errno handling. + */ +void SYSDEPS_InitErrno(void) +{ + errno_location_ptr = thread_errno_location; + h_errno_location_ptr = thread_h_errno_location; +} + + /********************************************************************** * NtCurrentTeb (NTDLL.@) * diff --git a/scheduler/thread.c b/scheduler/thread.c index 192f8915c86..7cdd8df554f 100644 --- a/scheduler/thread.c +++ b/scheduler/thread.c @@ -210,26 +210,6 @@ error: } -/*********************************************************************** - * thread_errno_location - * - * Get the per-thread errno location. - */ -static int *thread_errno_location(void) -{ - return &NtCurrentTeb()->thread_errno; -} - -/*********************************************************************** - * thread_h_errno_location - * - * Get the per-thread h_errno location. - */ -static int *thread_h_errno_location(void) -{ - return &NtCurrentTeb()->thread_h_errno; -} - /*********************************************************************** * THREAD_Init * @@ -245,8 +225,7 @@ void THREAD_Init(void) assert( initial_teb.teb_sel ); initial_teb.process = ¤t_process; SYSDEPS_SetCurThread( &initial_teb ); - wine_errno_location = thread_errno_location; - wine_h_errno_location = thread_h_errno_location; + SYSDEPS_InitErrno(); } }