(root)/
glibc-2.38/
nptl/
tst-cleanup4aux.c
       1  /* Copyright (C) 2003-2023 Free Software Foundation, Inc.
       2     This file is part of the GNU C Library.
       3  
       4     The GNU C Library is free software; you can redistribute it and/or
       5     modify it under the terms of the GNU Lesser General Public
       6     License as published by the Free Software Foundation; either
       7     version 2.1 of the License, or (at your option) any later version.
       8  
       9     The GNU C Library is distributed in the hope that it will be useful,
      10     but WITHOUT ANY WARRANTY; without even the implied warranty of
      11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      12     Lesser General Public License for more details.
      13  
      14     You should have received a copy of the GNU Lesser General Public
      15     License along with the GNU C Library; if not, see
      16     <https://www.gnu.org/licenses/>.  */
      17  
      18  #include <pthread.h>
      19  #include <shlib-compat.h>
      20  #include <stdio.h>
      21  #include <stdlib.h>
      22  #include <unistd.h>
      23  
      24  extern void _pthread_cleanup_push (struct _pthread_cleanup_buffer *__buffer,
      25                                     void (*__routine) (void *),
      26                                     void *__arg);
      27  compat_symbol_reference (libpthread, _pthread_cleanup_push,
      28                           _pthread_cleanup_push, GLIBC_2_0);
      29  extern void _pthread_cleanup_pop (struct _pthread_cleanup_buffer *__buffer,
      30                                    int __execute);
      31  compat_symbol_reference (libpthread, _pthread_cleanup_pop,
      32                           _pthread_cleanup_pop, GLIBC_2_0);
      33  
      34  extern void clh (void *arg);
      35  extern void fn0 (void);
      36  extern void fn1 (void);
      37  extern void fn5 (void);
      38  extern void fn7 (void);
      39  extern void fn9 (void);
      40  
      41  
      42  static __attribute__((noinline)) void
      43  fn3 (void)
      44  {
      45    /* This is the old LinuxThreads pthread_cleanup_{push,pop}.  */
      46       struct _pthread_cleanup_buffer b;
      47    _pthread_cleanup_push (&b, clh, (void *) 4l);
      48  
      49    fn0 ();
      50  
      51    _pthread_cleanup_pop (&b, 1);
      52  }
      53  
      54  
      55  static __attribute__((noinline)) void
      56  fn4 (void)
      57  {
      58    pthread_cleanup_push (clh, (void *) 5l);
      59  
      60    fn3 ();
      61  
      62    pthread_cleanup_pop (1);
      63  }
      64  
      65  
      66  void
      67  fn5 (void)
      68  {
      69    /* This is the old LinuxThreads pthread_cleanup_{push,pop}.  */
      70       struct _pthread_cleanup_buffer b;
      71    _pthread_cleanup_push (&b, clh, (void *) 6l);
      72  
      73    fn4 ();
      74  
      75    _pthread_cleanup_pop (&b, 1);
      76  }
      77  
      78  
      79  static __attribute__((noinline)) void
      80  fn6 (void)
      81  {
      82    pthread_cleanup_push (clh, (void *) 7l);
      83  
      84    fn0 ();
      85  
      86    pthread_cleanup_pop (1);
      87  }
      88  
      89  
      90  void
      91  fn7 (void)
      92  {
      93    /* This is the old LinuxThreads pthread_cleanup_{push,pop}.  */
      94       struct _pthread_cleanup_buffer b;
      95    _pthread_cleanup_push (&b, clh, (void *) 8l);
      96  
      97    fn6 ();
      98  
      99    _pthread_cleanup_pop (&b, 1);
     100  }
     101  
     102  
     103  static __attribute__((noinline)) void
     104  fn8 (void)
     105  {
     106    pthread_cleanup_push (clh, (void *) 9l);
     107  
     108    fn1 ();
     109  
     110    pthread_cleanup_pop (1);
     111  }
     112  
     113  
     114  void
     115  fn9 (void)
     116  {
     117    /* This is the old LinuxThreads pthread_cleanup_{push,pop}.  */
     118       struct _pthread_cleanup_buffer b;
     119    _pthread_cleanup_push (&b, clh, (void *) 10l);
     120  
     121    fn8 ();
     122  
     123    _pthread_cleanup_pop (&b, 1);
     124  }