mirror of
https://sourceware.org/git/glibc.git
synced 2024-11-22 13:00:06 +00:00
htl: Move cleanup handling to non-private libc-lock
This adds sysdeps/htl/libc-lock.h which augments sysdeps/mach/libc-lock.h with the htl-aware cleanup handling. Otherwise inclusion of libc-lock.h without libc-lockP.h would keep only the mach-aware handling. This also fixes cleanup getting called when the binary is statically-linked without libpthread. * sysdeps/htl/libc-lockP.h (__libc_cleanup_region_start, __libc_cleanup_end, __libc_cleanup_region_end, __pthread_get_cleanup_stack): Move to... * sysdeps/htl/libc-lock.h: ... new file. (__libc_cleanup_region_start): Always set handler and arg. (__libc_cleanup_end): Always call the cleanup handler. (__libc_cleanup_push, __libc_cleanup_pop): New macros.
This commit is contained in:
parent
cf2c8cc2c6
commit
6414eef6e0
70
sysdeps/htl/libc-lock.h
Normal file
70
sysdeps/htl/libc-lock.h
Normal file
@ -0,0 +1,70 @@
|
|||||||
|
/* Private libc-internal interface for mutex locks.
|
||||||
|
Copyright (C) 2015-2020 Free Software Foundation, Inc.
|
||||||
|
This file is part of the GNU C Library.
|
||||||
|
|
||||||
|
The GNU C 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.
|
||||||
|
|
||||||
|
The GNU C 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 the GNU C Library; see the file COPYING.LIB. If
|
||||||
|
not, see <https://www.gnu.org/licenses/>. */
|
||||||
|
|
||||||
|
#ifndef _HTL_LIBC_LOCK_H
|
||||||
|
#define _HTL_LIBC_LOCK_H 1
|
||||||
|
|
||||||
|
#include_next <libc-lock.h>
|
||||||
|
#include <bits/cancelation.h>
|
||||||
|
|
||||||
|
#undef __libc_cleanup_region_start
|
||||||
|
#undef __libc_cleanup_region_end
|
||||||
|
#undef __libc_cleanup_end
|
||||||
|
#undef __libc_cleanup_push
|
||||||
|
#undef __libc_cleanup_pop
|
||||||
|
|
||||||
|
#define __libc_cleanup_region_start(DOIT, FCT, ARG) \
|
||||||
|
{ \
|
||||||
|
struct __pthread_cancelation_handler **__handlers = NULL; \
|
||||||
|
struct __pthread_cancelation_handler __handler; \
|
||||||
|
int __registered = 0; \
|
||||||
|
if (DOIT) \
|
||||||
|
{ \
|
||||||
|
__handler.__handler = FCT; \
|
||||||
|
__handler.__arg = ARG; \
|
||||||
|
if (__pthread_get_cleanup_stack != NULL) \
|
||||||
|
{ \
|
||||||
|
__handlers = __pthread_get_cleanup_stack (); \
|
||||||
|
__handler.__next = *__handlers; \
|
||||||
|
*__handlers = &__handler; \
|
||||||
|
__registered = 1; \
|
||||||
|
} \
|
||||||
|
} \
|
||||||
|
|
||||||
|
#define __libc_cleanup_end(DOIT) \
|
||||||
|
if (__registered) \
|
||||||
|
*__handlers = __handler.__next; \
|
||||||
|
if (DOIT) \
|
||||||
|
__handler.__handler (__handler.__arg); \
|
||||||
|
|
||||||
|
#define __libc_cleanup_region_end(DOIT) \
|
||||||
|
__libc_cleanup_end(DOIT) \
|
||||||
|
}
|
||||||
|
|
||||||
|
#define __libc_cleanup_push(fct, arg) __libc_cleanup_region_start (1, fct, arg)
|
||||||
|
#define __libc_cleanup_pop(execute) __libc_cleanup_region_end (execute)
|
||||||
|
|
||||||
|
#if !IS_IN (libpthread)
|
||||||
|
# ifdef weak_extern
|
||||||
|
weak_extern (__pthread_get_cleanup_stack)
|
||||||
|
# else
|
||||||
|
# pragma weak __pthread_get_cleanup_stack
|
||||||
|
# endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
@ -19,7 +19,6 @@
|
|||||||
#ifndef _BITS_LIBC_LOCKP_H
|
#ifndef _BITS_LIBC_LOCKP_H
|
||||||
#define _BITS_LIBC_LOCKP_H 1
|
#define _BITS_LIBC_LOCKP_H 1
|
||||||
|
|
||||||
#include <libc-lock.h>
|
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
#include <pthread-functions.h>
|
#include <pthread-functions.h>
|
||||||
|
|
||||||
@ -74,36 +73,6 @@ typedef pthread_key_t __libc_key_t;
|
|||||||
__libc_ptf_call (__pthread_setspecific, (KEY, VALUE), 0)
|
__libc_ptf_call (__pthread_setspecific, (KEY, VALUE), 0)
|
||||||
|
|
||||||
|
|
||||||
#undef __libc_cleanup_region_start
|
|
||||||
#undef __libc_cleanup_region_end
|
|
||||||
#undef __libc_cleanup_end
|
|
||||||
|
|
||||||
#define __libc_cleanup_region_start(DOIT, FCT, ARG) \
|
|
||||||
{ \
|
|
||||||
struct __pthread_cancelation_handler **__handlers = NULL; \
|
|
||||||
struct __pthread_cancelation_handler __handler; \
|
|
||||||
int _ditit = 0; \
|
|
||||||
if (DOIT && __pthread_get_cleanup_stack != NULL) \
|
|
||||||
{ \
|
|
||||||
__handlers = __pthread_get_cleanup_stack (); \
|
|
||||||
__handler.__handler = FCT; \
|
|
||||||
__handler.__arg = ARG; \
|
|
||||||
__handler.__next = *__handlers; \
|
|
||||||
*__handlers = &__handler; \
|
|
||||||
_ditit = 1; \
|
|
||||||
}
|
|
||||||
|
|
||||||
#define __libc_cleanup_end(DOIT) \
|
|
||||||
if (_ditit) { \
|
|
||||||
if (DOIT) \
|
|
||||||
__handler.__handler (__handler.__arg); \
|
|
||||||
*__handlers = __handler.__next; \
|
|
||||||
}
|
|
||||||
|
|
||||||
#define __libc_cleanup_region_end(DOIT) \
|
|
||||||
__libc_cleanup_end(DOIT) \
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Functions that are used by this file and are internal to the GNU C
|
/* Functions that are used by this file and are internal to the GNU C
|
||||||
library. */
|
library. */
|
||||||
|
|
||||||
@ -185,7 +154,6 @@ weak_extern (__pthread_once)
|
|||||||
weak_extern (__pthread_initialize)
|
weak_extern (__pthread_initialize)
|
||||||
weak_extern (__pthread_atfork)
|
weak_extern (__pthread_atfork)
|
||||||
weak_extern (__pthread_setcancelstate)
|
weak_extern (__pthread_setcancelstate)
|
||||||
weak_extern (__pthread_get_cleanup_stack)
|
|
||||||
# else
|
# else
|
||||||
# pragma weak __pthread_mutex_init
|
# pragma weak __pthread_mutex_init
|
||||||
# pragma weak __pthread_mutex_destroy
|
# pragma weak __pthread_mutex_destroy
|
||||||
@ -208,7 +176,6 @@ weak_extern (__pthread_get_cleanup_stack)
|
|||||||
# pragma weak __pthread_initialize
|
# pragma weak __pthread_initialize
|
||||||
# pragma weak __pthread_atfork
|
# pragma weak __pthread_atfork
|
||||||
# pragma weak __pthread_setcancelstate
|
# pragma weak __pthread_setcancelstate
|
||||||
# pragma weak __pthread_get_cleanup_stack
|
|
||||||
# endif
|
# endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user