]> git.ipfire.org Git - thirdparty/glibc.git/blame - sysdeps/unix/sysv/linux/sigsuspend.c
(CFLAGS-tst-align.c): Add -mpreferred-stack-boundary=4.
[thirdparty/glibc.git] / sysdeps / unix / sysv / linux / sigsuspend.c
CommitLineData
a334319f
UD
1/* Copyright (C) 1996, 1997, 1998, 1999, 2000, 2002, 2003
2 Free Software Foundation, Inc.
84384f5b 3 This file is part of the GNU C Library.
1177c8ba 4
84384f5b 5 The GNU C Library is free software; you can redistribute it and/or
41bdb6e2
AJ
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
1177c8ba 9
84384f5b
UD
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
41bdb6e2 13 Lesser General Public License for more details.
1177c8ba 14
41bdb6e2
AJ
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, write to the Free
17 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
18 02111-1307 USA. */
1177c8ba 19
cbdee279 20#include <errno.h>
1177c8ba 21#include <signal.h>
1177c8ba
RM
22#include <unistd.h>
23
6ee8d334 24#include <sysdep-cancel.h>
0dee6738 25#include <sys/syscall.h>
4bbb61e4 26#include <bp-checks.h>
0dee6738 27
a334319f 28#include "kernel-features.h"
958f238f 29
cbdee279 30
6ee8d334 31#if !__ASSUME_REALTIME_SIGNALS
cbdee279 32/* The variable is shared between all wrappers around signal handling
7804eb37
UD
33 functions which have RT equivalents. The definition is in sigaction.c. */
34extern int __libc_missing_rt_sigs;
cbdee279 35
1177c8ba 36
6ee8d334
UD
37static int
38do_sigsuspend (const sigset_t *set)
1177c8ba 39{
958f238f 40# ifdef __NR_rt_sigsuspend
cbdee279 41 /* First try the RT signals. */
da2d1bc5 42 if (!__libc_missing_rt_sigs)
cbdee279
UD
43 {
44 /* XXX The size argument hopefully will have to be changed to the
45 real size of the user-level sigset_t. */
8fb3e007 46 int saved_errno = errno;
4bbb61e4
GM
47 int result = INLINE_SYSCALL (rt_sigsuspend, 2,
48 CHECK_SIGSET (set), _NSIG / 8);
cbdee279
UD
49 if (result >= 0 || errno != ENOSYS)
50 return result;
51
8fb3e007 52 __set_errno (saved_errno);
da2d1bc5 53 __libc_missing_rt_sigs = 1;
cbdee279 54 }
958f238f 55# endif
df4ef2ab 56
0dee6738 57 return INLINE_SYSCALL (sigsuspend, 3, 0, 0, set->__val[0]);
6ee8d334
UD
58}
59#endif
60
61/* Change the set of blocked signals to SET,
62 wait until a signal arrives, and restore the set of blocked signals. */
63int
64__sigsuspend (set)
65 const sigset_t *set;
66{
a334319f
UD
67#if __ASSUME_REALTIME_SIGNALS
68 if (SINGLE_THREAD_P)
69 return INLINE_SYSCALL (rt_sigsuspend, 2, CHECK_SIGSET (set), _NSIG / 8);
70
71 int oldtype = LIBC_CANCEL_ASYNC ();
72
73 int result = INLINE_SYSCALL (rt_sigsuspend, 2, CHECK_SIGSET (set),
74 _NSIG / 8);
75
76 LIBC_CANCEL_RESET (oldtype);
77
78 return result;
79#else
6ee8d334
UD
80 if (SINGLE_THREAD_P)
81 return do_sigsuspend (set);
82
83 int oldtype = LIBC_CANCEL_ASYNC ();
84
85 int result = do_sigsuspend (set);
86
87 LIBC_CANCEL_RESET (oldtype);
88
89 return result;
a334319f 90#endif
1177c8ba 91}
37ba7d66 92libc_hidden_def (__sigsuspend)
84384f5b 93weak_alias (__sigsuspend, sigsuspend)
e5e45b53 94strong_alias (__sigsuspend, __libc_sigsuspend)