1/* Copyright (C) 2003-2022 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
24extern void _pthread_cleanup_push (struct _pthread_cleanup_buffer *__buffer,
25 void (*__routine) (void *),
26 void *__arg);
27compat_symbol_reference (libpthread, _pthread_cleanup_push,
28 _pthread_cleanup_push, GLIBC_2_0);
29extern void _pthread_cleanup_pop (struct _pthread_cleanup_buffer *__buffer,
30 int __execute);
31compat_symbol_reference (libpthread, _pthread_cleanup_pop,
32 _pthread_cleanup_pop, GLIBC_2_0);
33
34extern void clh (void *arg);
35extern void fn0 (void);
36extern void fn1 (void);
37extern void fn5 (void);
38extern void fn7 (void);
39extern void fn9 (void);
40
41
42static __attribute__((noinline)) void
43fn3 (void)
44{
45 /* This is the old LinuxThreads pthread_cleanup_{push,pop}. */
46 struct _pthread_cleanup_buffer b;
47 _pthread_cleanup_push (buffer: &b, routine: clh, arg: (void *) 4l);
48
49 fn0 ();
50
51 _pthread_cleanup_pop (buffer: &b, execute: 1);
52}
53
54
55static __attribute__((noinline)) void
56fn4 (void)
57{
58 pthread_cleanup_push (clh, (void *) 5l);
59
60 fn3 ();
61
62 pthread_cleanup_pop (1);
63}
64
65
66void
67fn5 (void)
68{
69 /* This is the old LinuxThreads pthread_cleanup_{push,pop}. */
70 struct _pthread_cleanup_buffer b;
71 _pthread_cleanup_push (buffer: &b, routine: clh, arg: (void *) 6l);
72
73 fn4 ();
74
75 _pthread_cleanup_pop (buffer: &b, execute: 1);
76}
77
78
79static __attribute__((noinline)) void
80fn6 (void)
81{
82 pthread_cleanup_push (clh, (void *) 7l);
83
84 fn0 ();
85
86 pthread_cleanup_pop (1);
87}
88
89
90void
91fn7 (void)
92{
93 /* This is the old LinuxThreads pthread_cleanup_{push,pop}. */
94 struct _pthread_cleanup_buffer b;
95 _pthread_cleanup_push (buffer: &b, routine: clh, arg: (void *) 8l);
96
97 fn6 ();
98
99 _pthread_cleanup_pop (buffer: &b, execute: 1);
100}
101
102
103static __attribute__((noinline)) void
104fn8 (void)
105{
106 pthread_cleanup_push (clh, (void *) 9l);
107
108 fn1 ();
109
110 pthread_cleanup_pop (1);
111}
112
113
114void
115fn9 (void)
116{
117 /* This is the old LinuxThreads pthread_cleanup_{push,pop}. */
118 struct _pthread_cleanup_buffer b;
119 _pthread_cleanup_push (buffer: &b, routine: clh, arg: (void *) 10l);
120
121 fn8 ();
122
123 _pthread_cleanup_pop (buffer: &b, execute: 1);
124}
125

source code of glibc/nptl/tst-cleanup4aux.c