[PATCH] htl: move pthread_setcancelstate into libc.

Samuel Thibault samuel.thibault@aquilenet.fr
Sat Feb 1 10:51:55 GMT 2025


Applied, thanks!

gfleury, le sam. 01 févr. 2025 10:02:02 +0200, a ecrit:
> sysdeps/pthread/sem_open.c: call pthread_setcancelstate directely
> since forward declaration is gone on hurd too
> ---
>  htl/Makefile                                |  2 +-
>  htl/Versions                                |  3 ++-
>  htl/forward.c                               |  4 ----
>  htl/pt-initialize.c                         |  1 -
>  htl/pt-setcancelstate.c                     |  8 ++++++--
>  sysdeps/htl/libc-lockP.h                    |  5 ++---
>  sysdeps/htl/pthread-functions.h             |  2 --
>  sysdeps/htl/pthreadP.h                      |  2 --
>  sysdeps/mach/hurd/i386/libc.abilist         |  1 +
>  sysdeps/mach/hurd/i386/libpthread.abilist   |  1 -
>  sysdeps/mach/hurd/x86_64/libpthread.abilist |  1 -
>  sysdeps/pthread/sem_open.c                  | 11 +++--------
>  12 files changed, 15 insertions(+), 26 deletions(-)
> 
> diff --git a/htl/Makefile b/htl/Makefile
> index d4418ab9..a4192a56 100644
> --- a/htl/Makefile
> +++ b/htl/Makefile
> @@ -50,7 +50,6 @@ libpthread-routines := \
>    pt-join \
>    pt-spin-inlines \
>    pt-cleanup \
> -  pt-setcancelstate \
>    pt-testcancel \
>    pt-cancel \
>    pt-mutex-transfer-np \
> @@ -203,6 +202,7 @@ routines := \
>    pt-nthreads \
>    pt-pthread_self \
>    pt-self pt-equal \
> +  pt-setcancelstate \
>    pt-setcanceltype \
>    pt-setschedparam \
>    pt-sigmask \
> diff --git a/htl/Versions b/htl/Versions
> index 6801d121..d8f1c7f4 100644
> --- a/htl/Versions
> +++ b/htl/Versions
> @@ -56,6 +56,7 @@ libc {
>      pthread_mutexattr_setprotocol;
>      pthread_mutexattr_setpshared;
>      pthread_mutexattr_settype;
> +    pthread_setcancelstate;
>      pthread_setcanceltype;
>      pthread_sigmask;
>    }
> @@ -146,6 +147,7 @@ libc {
>      __pthread_attr_setstacksize;
>      __pthread_attr_setstackaddr;
>      __pthread_attr_setstack;
> +    __pthread_setcancelstate;
>      __pthread_cond_broadcast;
>      __pthread_cond_destroy;
>      __pthread_cond_init;
> @@ -232,7 +234,6 @@ libpthread {
>      pthread_rwlockattr_destroy; pthread_rwlockattr_getpshared;
>      pthread_rwlockattr_init; pthread_rwlockattr_setpshared;
>  
> -    pthread_setcancelstate;
>      pthread_setconcurrency;
>      pthread_setschedprio; pthread_setspecific;
>  
> diff --git a/htl/forward.c b/htl/forward.c
> index 9455df73..0a7a6964 100644
> --- a/htl/forward.c
> +++ b/htl/forward.c
> @@ -58,9 +58,5 @@ FORWARD_NORETURN (__pthread_exit, void, (void *retval), (retval),
>  		  exit (EXIT_SUCCESS))
>  strong_alias (__pthread_exit, pthread_exit);
>  
> -FORWARD (__pthread_setcancelstate, (int state, int *oldstate),
> -	 (state, oldstate), 0)
> -strong_alias (__pthread_setcancelstate, pthread_setcancelstate);
> -
>  FORWARD2 (__pthread_get_cleanup_stack, struct __pthread_cancelation_handler **,
>  	  (void), (), return &__pthread_cleanup_stack);
> diff --git a/htl/pt-initialize.c b/htl/pt-initialize.c
> index eba9e12d..53b9c76e 100644
> --- a/htl/pt-initialize.c
> +++ b/htl/pt-initialize.c
> @@ -28,7 +28,6 @@
>  #if IS_IN (libpthread)
>  static const struct pthread_functions pthread_functions = {
>    .ptr___pthread_exit = __pthread_exit,
> -  .ptr___pthread_setcancelstate = __pthread_setcancelstate,
>    .ptr___pthread_get_cleanup_stack = __pthread_get_cleanup_stack,
>    .ptr_pthread_once = __pthread_once,
>    .ptr_pthread_rwlock_rdlock = __pthread_rwlock_rdlock,
> diff --git a/htl/pt-setcancelstate.c b/htl/pt-setcancelstate.c
> index 57894de7..6e09c260 100644
> --- a/htl/pt-setcancelstate.c
> +++ b/htl/pt-setcancelstate.c
> @@ -17,7 +17,7 @@
>     <https://www.gnu.org/licenses/>.  */
>  
>  #include <pthread.h>
> -
> +#include <shlib-compat.h>
>  #include <pt-internal.h>
>  
>  int
> @@ -42,5 +42,9 @@ __pthread_setcancelstate (int state, int *oldstate)
>  
>    return 0;
>  }
> +libc_hidden_def (__pthread_setcancelstate)
> +versioned_symbol (libc, __pthread_setcancelstate, pthread_setcancelstate, GLIBC_2_21);
>  
> -weak_alias (__pthread_setcancelstate, pthread_setcancelstate);
> +#if OTHER_SHLIB_COMPAT (libpthread, GLIBC_2_12, GLIBC_2_21)
> +compat_symbol (libc, __pthread_setcancelstate, pthread_setcancelstate, GLIBC_2_12);
> +#endif
> diff --git a/sysdeps/htl/libc-lockP.h b/sysdeps/htl/libc-lockP.h
> index f39c8bba..6804c0d6 100644
> --- a/sysdeps/htl/libc-lockP.h
> +++ b/sysdeps/htl/libc-lockP.h
> @@ -75,7 +75,6 @@
>  
>  extern int __pthread_mutex_init (pthread_mutex_t *__mutex,
>  				 const pthread_mutexattr_t *__mutex_attr);
> -
>  extern int __pthread_mutex_destroy (pthread_mutex_t *__mutex);
>  libc_hidden_proto (__pthread_mutex_destroy)
>  
> @@ -113,6 +112,8 @@ extern int __pthread_atfork (void (*__prepare) (void),
>  			     void (*__parent) (void),
>  			     void (*__child) (void));
>  
> +extern int __pthread_setcancelstate (int state, int *oldstate);
> +libc_hidden_proto (__pthread_setcancelstate)
>  /* Make the pthread functions weak so that we can elide them from
>     single-threaded processes.  */
>  #if !defined(__NO_WEAK_PTHREAD_ALIASES) && !IS_IN (libpthread)
> @@ -130,7 +131,6 @@ weak_extern (__pthread_getspecific)
>  weak_extern (__pthread_once)
>  weak_extern (__pthread_initialize)
>  weak_extern (__pthread_atfork)
> -weak_extern (__pthread_setcancelstate)
>  # else
>  #  pragma weak __pthread_rwlock_destroy
>  #  pragma weak __pthread_rwlock_rdlock
> @@ -144,7 +144,6 @@ weak_extern (__pthread_setcancelstate)
>  #  pragma weak __pthread_once
>  #  pragma weak __pthread_initialize
>  #  pragma weak __pthread_atfork
> -#  pragma weak __pthread_setcancelstate
>  # endif
>  #endif
>  
> diff --git a/sysdeps/htl/pthread-functions.h b/sysdeps/htl/pthread-functions.h
> index 9788085b..56b5b238 100644
> --- a/sysdeps/htl/pthread-functions.h
> +++ b/sysdeps/htl/pthread-functions.h
> @@ -22,7 +22,6 @@
>  #include <pthread.h>
>  
>  void __pthread_exit (void *) __attribute__ ((__noreturn__));
> -int __pthread_setcancelstate (int, int *);
>  struct __pthread_cancelation_handler **__pthread_get_cleanup_stack (void);
>  int __pthread_once (pthread_once_t *, void (*) (void));
>  int __pthread_rwlock_rdlock (pthread_rwlock_t *);
> @@ -42,7 +41,6 @@ int _cthreads_ftrylockfile (FILE *);
>  struct pthread_functions
>  {
>    void (*ptr___pthread_exit) (void *) __attribute__ ((__noreturn__));
> -  int (*ptr___pthread_setcancelstate) (int, int *);
>    struct __pthread_cancelation_handler **(*ptr___pthread_get_cleanup_stack) (void);
>    int (*ptr_pthread_once) (pthread_once_t *, void (*) (void));
>    int (*ptr_pthread_rwlock_rdlock) (pthread_rwlock_t *);
> diff --git a/sysdeps/htl/pthreadP.h b/sysdeps/htl/pthreadP.h
> index 889a6320..1a1b9ff3 100644
> --- a/sysdeps/htl/pthreadP.h
> +++ b/sysdeps/htl/pthreadP.h
> @@ -146,8 +146,6 @@ int __pthread_setspecific (pthread_key_t key, const void *value);
>  int __pthread_key_delete (pthread_key_t key);
>  int __pthread_once (pthread_once_t *once_control, void (*init_routine) (void));
>  
> -int __pthread_setcancelstate (int state, int *oldstate);
> -
>  int __pthread_getattr_np (pthread_t, pthread_attr_t *);
>  int __pthread_attr_getstackaddr (const pthread_attr_t *__restrict __attr,
>  				 void **__restrict __stackaddr);
> diff --git a/sysdeps/mach/hurd/i386/libc.abilist b/sysdeps/mach/hurd/i386/libc.abilist
> index c26eddba..30c01aaf 100644
> --- a/sysdeps/mach/hurd/i386/libc.abilist
> +++ b/sysdeps/mach/hurd/i386/libc.abilist
> @@ -82,6 +82,7 @@ GLIBC_2.12 pthread_mutexattr_setprotocol F
>  GLIBC_2.12 pthread_mutexattr_setpshared F
>  GLIBC_2.12 pthread_mutexattr_settype F
>  GLIBC_2.12 pthread_self F
> +GLIBC_2.12 pthread_setcancelstate F
>  GLIBC_2.12 pthread_setcanceltype F
>  GLIBC_2.12 pthread_setschedparam F
>  GLIBC_2.12 pthread_sigmask F
> diff --git a/sysdeps/mach/hurd/i386/libpthread.abilist b/sysdeps/mach/hurd/i386/libpthread.abilist
> index 30b598ff..0cefd914 100644
> --- a/sysdeps/mach/hurd/i386/libpthread.abilist
> +++ b/sysdeps/mach/hurd/i386/libpthread.abilist
> @@ -56,7 +56,6 @@ GLIBC_2.12 pthread_rwlockattr_destroy F
>  GLIBC_2.12 pthread_rwlockattr_getpshared F
>  GLIBC_2.12 pthread_rwlockattr_init F
>  GLIBC_2.12 pthread_rwlockattr_setpshared F
> -GLIBC_2.12 pthread_setcancelstate F
>  GLIBC_2.12 pthread_setconcurrency F
>  GLIBC_2.12 pthread_setschedprio F
>  GLIBC_2.12 pthread_setspecific F
> diff --git a/sysdeps/mach/hurd/x86_64/libpthread.abilist b/sysdeps/mach/hurd/x86_64/libpthread.abilist
> index 800b7935..0812c7c7 100644
> --- a/sysdeps/mach/hurd/x86_64/libpthread.abilist
> +++ b/sysdeps/mach/hurd/x86_64/libpthread.abilist
> @@ -78,7 +78,6 @@ GLIBC_2.38 pthread_rwlockattr_destroy F
>  GLIBC_2.38 pthread_rwlockattr_getpshared F
>  GLIBC_2.38 pthread_rwlockattr_init F
>  GLIBC_2.38 pthread_rwlockattr_setpshared F
> -GLIBC_2.38 pthread_setcancelstate F
>  GLIBC_2.38 pthread_setconcurrency F
>  GLIBC_2.38 pthread_setschedprio F
>  GLIBC_2.38 pthread_setspecific F
> diff --git a/sysdeps/pthread/sem_open.c b/sysdeps/pthread/sem_open.c
> index 9f242599..e5eacb5f 100644
> --- a/sysdeps/pthread/sem_open.c
> +++ b/sysdeps/pthread/sem_open.c
> @@ -26,6 +26,7 @@
>  #include <futex-internal.h>
>  #include <libc-lock.h>
>  
> +
>  #if !PTHREAD_IN_LIBC
>  /* The private names are not exported from libc.  */
>  # define __link link
> @@ -57,11 +58,7 @@ __sem_open (const char *name, int oflag, ...)
>      }
>  
>    /* Disable asynchronous cancellation.  */
> -#ifdef __libc_ptf_call
> -  int state;
> -  __libc_ptf_call (__pthread_setcancelstate,
> -                   (PTHREAD_CANCEL_DISABLE, &state), 0);
> -#endif
> +  int state = __pthread_setcancelstate (PTHREAD_CANCEL_DISABLE, &state);
>  
>    /* If the semaphore object has to exist simply open it.  */
>    if ((oflag & O_CREAT) == 0 || (oflag & O_EXCL) == 0)
> @@ -214,9 +211,7 @@ __sem_open (const char *name, int oflag, ...)
>      }
>  
>  out:
> -#ifdef __libc_ptf_call
> -  __libc_ptf_call (__pthread_setcancelstate, (state, NULL), 0);
> -#endif
> +  __pthread_setcancelstate (state, NULL);
>  
>    return result;
>  }
> -- 
> 2.39.5
> 

-- 
Samuel
<c> tiens, je suis déçu
<c> quand on clique sur le bouton random de http://xkcd.com/221/ on ne tombe pas (toujours) sur http://xkcd.com/4/
<c> bon, j'envoie un bug-report à l'auteur


More information about the Libc-alpha mailing list