]> git.ipfire.org Git - thirdparty/glibc.git/blame - sysdeps/unix/sysv/linux/sigwait.c
powerpc: Remove unintended __longjmp symbol from ABI
[thirdparty/glibc.git] / sysdeps / unix / sysv / linux / sigwait.c
CommitLineData
f7a9f785 1/* Copyright (C) 1997-2016 Free Software Foundation, Inc.
76e34a5d
UD
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
59ba27a6
PE
15 License along with the GNU C Library; if not, see
16 <http://www.gnu.org/licenses/>. */
76e34a5d
UD
17
18#include <errno.h>
19#include <signal.h>
20#define __need_NULL
21#include <stddef.h>
6080ecdf 22#include <string.h>
76e34a5d 23
08192659 24#include <nptl/pthreadP.h>
6ee8d334 25#include <sysdep-cancel.h>
76e34a5d 26#include <sys/syscall.h>
76e34a5d
UD
27
28#ifdef __NR_rt_sigtimedwait
76e34a5d
UD
29
30/* Return any pending signal or wait for one for the given time. */
6ee8d334
UD
31static int
32do_sigwait (const sigset_t *set, int *sig)
76e34a5d 33{
76e34a5d
UD
34 int ret;
35
aa3cee21
UD
36#ifdef SIGCANCEL
37 sigset_t tmpset;
53b4fed6
UD
38 if (set != NULL
39 && (__builtin_expect (__sigismember (set, SIGCANCEL), 0)
40# ifdef SIGSETXID
41 || __builtin_expect (__sigismember (set, SIGSETXID), 0)
42# endif
43 ))
aa3cee21
UD
44 {
45 /* Create a temporary mask without the bit for SIGCANCEL set. */
46 // We are not copying more than we have to.
47 memcpy (&tmpset, set, _NSIG / 8);
48 __sigdelset (&tmpset, SIGCANCEL);
53b4fed6
UD
49# ifdef SIGSETXID
50 __sigdelset (&tmpset, SIGSETXID);
51# endif
aa3cee21
UD
52 set = &tmpset;
53 }
54#endif
55
76e34a5d
UD
56 /* XXX The size argument hopefully will have to be changed to the
57 real size of the user-level sigset_t. */
f4447671 58#ifdef INTERNAL_SYSCALL
6aca81bb 59 INTERNAL_SYSCALL_DECL (err);
4978fb0c 60 do
32a45bea 61 ret = INTERNAL_SYSCALL (rt_sigtimedwait, err, 4, set,
4978fb0c
UD
62 NULL, NULL, _NSIG / 8);
63 while (INTERNAL_SYSCALL_ERROR_P (ret, err)
64 && INTERNAL_SYSCALL_ERRNO (ret, err) == EINTR);
6aca81bb 65 if (! INTERNAL_SYSCALL_ERROR_P (ret, err))
f4447671
UD
66 {
67 *sig = ret;
68 ret = 0;
69 }
70 else
6aca81bb 71 ret = INTERNAL_SYSCALL_ERRNO (ret, err);
f4447671 72#else
4978fb0c 73 do
32a45bea 74 ret = INLINE_SYSCALL (rt_sigtimedwait, 4, set, NULL, NULL, _NSIG / 8);
4978fb0c 75 while (ret == -1 && errno == EINTR);
8a815198
UD
76 if (ret != -1)
77 {
78 *sig = ret;
79 ret = 0;
80 }
81 else
82 ret = errno;
f4447671 83#endif
76e34a5d
UD
84
85 return ret;
86}
6ee8d334
UD
87
88int
14bb4e57 89__sigwait (const sigset_t *set, int *sig)
6ee8d334
UD
90{
91 if (SINGLE_THREAD_P)
92 return do_sigwait (set, sig);
93
94 int oldtype = LIBC_CANCEL_ASYNC ();
95
96 int result = do_sigwait (set, sig);
97
98 LIBC_CANCEL_RESET (oldtype);
99
100 return result;
101}
6166815d 102libc_hidden_def (__sigwait)
76e34a5d
UD
103weak_alias (__sigwait, sigwait)
104#else
105# include <sysdeps/posix/sigwait.c>
106#endif
e5e45b53 107strong_alias (__sigwait, __libc_sigwait)