1 /* Copyright (C) 2013 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
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.
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.
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 <http://www.gnu.org/licenses/>. */
19 /* This test checks that TLS in a dlopened object works when first accessed
20 from a signal handler. */
26 #include <semaphore.h>
44 static void (*tls7mod_action
) (int, siginfo_t
*, void *);
47 action (int signo
, siginfo_t
*info
, void *ignored
)
49 sem_t
*sem
= info
->si_value
.sival_ptr
;
51 atomic_read_barrier ();
52 assert (tls7mod_action
!= NULL
);
53 (*tls7mod_action
) (signo
, info
, ignored
);
55 /* This sem_post may trigger dlclose, which will invalidate tls7mod_action.
56 It is important to do that only after tls7mod_action is no longer
66 for (int i
= 0; i
< 10; ++i
)
68 if (pthread_create (&th
[i
], NULL
, spin
, NULL
))
70 puts ("pthread_create failed");
76 for (int i
= 0; i
< NITERS
; ++i
)
78 void *h
= dlopen ("tst-tls7mod.so", RTLD_LAZY
);
81 puts ("dlopen failed");
85 tls7mod_action
= dlsym (h
, "action");
86 if (tls7mod_action
== NULL
)
88 puts ("dlsym for action failed");
91 atomic_write_barrier ();
94 sa
.sa_sigaction
= action
;
95 sigemptyset (&sa
.sa_mask
);
96 sa
.sa_flags
= SA_SIGINFO
;
97 if (sigaction (SIGUSR1
, &sa
, NULL
))
99 puts ("sigaction failed");
104 if (sem_init (&sem
, 0, 0))
106 puts ("sem_init failed");
110 val
.sival_ptr
= &sem
;
111 for (int i
= 0; i
< 10; ++i
)
113 if (pthread_sigqueue (th
[i
], SIGUSR1
, val
))
115 puts ("pthread_sigqueue failed");
120 for (int i
= 0; i
< 10; ++i
)
124 puts ("sem_wait failed");
129 tls7mod_action
= NULL
;
133 puts ("dlclose failed");
142 #define TEST_FUNCTION do_test ()
143 #include "../test-skeleton.c"