1 /* ABI compatibility for obsolete sigvec function from 4.2BSD.
2 Copyright (C) 1991-2022 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
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.
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
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <https://www.gnu.org/licenses/>. */
19 #include <shlib-compat.h>
21 #if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_21)
28 /* These are the struct sigvec and SV_* bit definitions that
29 used to be in <signal.h>. The whole interface now exists
30 solely for ABI compatibility, so it can just be here. */
33 __sighandler_t sv_handler
; /* Signal handler. */
34 int sv_mask
; /* Mask of signals to be blocked. */
36 int sv_flags
; /* Flags (see below). */
38 # define SV_ONSTACK (1 << 0)/* Take the signal on the signal stack. */
39 # define SV_INTERRUPT (1 << 1)/* Do not restart system calls. */
40 # define SV_RESETHAND (1 << 2)/* Reset handler to SIG_DFL on receipt. */
43 /* Include macros to convert between `sigset_t' and old-style mask. */
44 # include <sigset-cvt-mask.h>
47 /* When sigaction lacks the extension bit for it,
48 we use a wrapper handler to support SV_RESETHAND. */
49 struct sigvec_wrapper_data
51 __sighandler_t sw_handler
;
55 static void sigvec_wrapper_handler (int sig
) __THROW
;
57 static struct sigvec_wrapper_data sigvec_wrapper_data
[NSIG
];
61 /* If VEC is non-NULL, set the handler for SIG to the `sv_handler' member
62 of VEC. The signals in `sv_mask' will be blocked while the handler runs.
63 If the SV_RESETHAND bit is set in `sv_flags', the handler for SIG will be
64 reset to SIG_DFL before `sv_handler' is entered. If OVEC is non-NULL,
65 it is filled in with the old information for SIG. */
68 const struct sigvec
*vec
,
74 if (vec
== NULL
|| !(vec
->sv_flags
& SV_RESETHAND
))
77 struct sigaction
new, *n
;
83 __sighandler_t handler
;
85 unsigned int sv_flags
;
86 unsigned int sa_flags
;
88 handler
= vec
->sv_handler
;
90 sv_flags
= vec
->sv_flags
;
92 if (sv_flags
& SV_ONSTACK
)
95 sa_flags
|= SA_ONSTACK
;
102 if (!(sv_flags
& SV_INTERRUPT
))
103 sa_flags
|= SA_RESTART
;
106 if (sv_flags
& SV_RESETHAND
)
107 sa_flags
|= SA_RESETHAND
;
110 new.sa_handler
= handler
;
111 if (sigset_set_old_mask (&new.sa_mask
, mask
) < 0)
113 new.sa_flags
= sa_flags
;
116 if (__sigaction (sig
, n
, &old
) < 0)
119 # ifndef SA_RESETHAND
122 __sighandler_t handler
;
124 struct sigvec_wrapper_data
*data
;
125 struct sigaction wrapper
;
127 handler
= vec
->sv_handler
;
128 mask
= (unsigned int)vec
->sv_mask
;
129 data
= &sigvec_wrapper_data
[sig
];
130 wrapper
.sa_handler
= sigvec_wrapper_handler
;
131 /* FIXME: should we set wrapper.sa_mask, wrapper.sa_flags?? */
132 data
->sw_handler
= handler
;
133 data
->sw_mask
= mask
;
135 if (__sigaction (sig
, &wrapper
, &old
) < 0)
142 __sighandler_t handler
;
143 unsigned int sv_flags
;
144 unsigned int sa_flags
;
147 handler
= old
.sa_handler
;
149 sa_flags
= old
.sa_flags
;
150 # ifndef SA_RESETHAND
151 if (handler
== sigvec_wrapper_handler
)
153 handler
= sigvec_wrapper_data
[sig
].sw_handler
;
154 /* should we use data->sw_mask?? */
155 sv_flags
|= SV_RESETHAND
;
158 if (sa_flags
& SA_RESETHAND
)
159 sv_flags
|= SV_RESETHAND
;
161 mask
= sigset_get_old_mask (&old
.sa_mask
);
163 if (sa_flags
& SA_ONSTACK
)
164 sv_flags
|= SV_ONSTACK
;
167 if (!(sa_flags
& SA_RESTART
))
169 sv_flags
|= SV_INTERRUPT
;
170 ovec
->sv_handler
= handler
;
171 ovec
->sv_mask
= (int)mask
;
172 ovec
->sv_flags
= (int)sv_flags
;
178 compat_symbol (libc
, __sigvec
, sigvec
, GLIBC_2_0
);
180 # ifndef SA_RESETHAND
182 sigvec_wrapper_handler (int sig
)
184 struct sigvec_wrapper_data
*data
;
185 struct sigaction act
;
187 __sighandler_t handler
;
189 data
= &sigvec_wrapper_data
[sig
];
190 act
.sa_handler
= SIG_DFL
;
192 sigset_set_old_mask (&act
.sa_mask
, data
->sw_mask
);
193 handler
= data
->sw_handler
;
195 (void) __sigaction (sig
, &act
, (struct sigaction
*) NULL
);
200 # endif /* No SA_RESETHAND. */
202 #endif /* SHLIB_COMPAT */