1 |
1325 |
phoenix |
/* Copyright (C) 1997, 1998, 1999, 2000 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 Library General Public License as
|
6 |
|
|
published by the Free Software Foundation; either version 2 of the
|
7 |
|
|
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 |
|
|
Library General Public License for more details.
|
13 |
|
|
|
14 |
|
|
You should have received a copy of the GNU Library General Public
|
15 |
|
|
License along with the GNU C Library; see the file COPYING.LIB. If not,
|
16 |
|
|
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
17 |
|
|
Boston, MA 02111-1307, USA.
|
18 |
|
|
|
19 |
|
|
Totally hacked up for uClibc by Erik Andersen <andersen@codepoet.org>
|
20 |
|
|
*/
|
21 |
|
|
|
22 |
|
|
#include <errno.h>
|
23 |
|
|
#include <signal.h>
|
24 |
|
|
#include <string.h>
|
25 |
|
|
#include <sys/syscall.h>
|
26 |
|
|
#include <bits/kernel_sigaction.h>
|
27 |
|
|
|
28 |
|
|
#define SA_RESTORER 0x04000000
|
29 |
|
|
extern void __default_sa_restorer(void);
|
30 |
|
|
extern void __default_rt_sa_restorer(void);
|
31 |
|
|
|
32 |
|
|
#if defined __NR_rt_sigaction
|
33 |
|
|
|
34 |
|
|
/* If ACT is not NULL, change the action for SIG to *ACT.
|
35 |
|
|
If OACT is not NULL, put the old action for SIG in *OACT. */
|
36 |
|
|
int __libc_sigaction (int sig, const struct sigaction *act, struct sigaction *oact)
|
37 |
|
|
{
|
38 |
|
|
int result;
|
39 |
|
|
struct kernel_sigaction kact, koact;
|
40 |
|
|
|
41 |
|
|
if (act) {
|
42 |
|
|
kact.k_sa_handler = act->sa_handler;
|
43 |
|
|
memcpy (&kact.sa_mask, &act->sa_mask, sizeof (kact.sa_mask));
|
44 |
|
|
kact.sa_flags = act->sa_flags;
|
45 |
|
|
# ifdef HAVE_SA_RESTORER
|
46 |
|
|
if (kact.sa_flags & (SA_RESTORER | SA_ONSTACK)) {
|
47 |
|
|
kact.sa_restorer = act->sa_restorer;
|
48 |
|
|
} else {
|
49 |
|
|
if (kact.sa_flags & SA_SIGINFO) {
|
50 |
|
|
kact.sa_restorer = __default_rt_sa_restorer;
|
51 |
|
|
} else {
|
52 |
|
|
kact.sa_restorer = __default_sa_restorer;
|
53 |
|
|
kact.sa_flags |= SA_RESTORER;
|
54 |
|
|
}
|
55 |
|
|
}
|
56 |
|
|
# endif
|
57 |
|
|
}
|
58 |
|
|
|
59 |
|
|
/* XXX The size argument hopefully will have to be changed to the
|
60 |
|
|
real size of the user-level sigset_t. */
|
61 |
|
|
result = __syscall_rt_sigaction(sig, act ? __ptrvalue (&kact) : NULL,
|
62 |
|
|
oact ? __ptrvalue (&koact) : NULL, _NSIG / 8);
|
63 |
|
|
|
64 |
|
|
if (oact && result >= 0) {
|
65 |
|
|
oact->sa_handler = koact.k_sa_handler;
|
66 |
|
|
memcpy (&oact->sa_mask, &koact.sa_mask, sizeof (oact->sa_mask));
|
67 |
|
|
oact->sa_flags = koact.sa_flags;
|
68 |
|
|
# ifdef HAVE_SA_RESTORER
|
69 |
|
|
oact->sa_restorer = koact.sa_restorer;
|
70 |
|
|
# endif
|
71 |
|
|
}
|
72 |
|
|
return result;
|
73 |
|
|
}
|
74 |
|
|
|
75 |
|
|
|
76 |
|
|
#else
|
77 |
|
|
|
78 |
|
|
/* If ACT is not NULL, change the action for SIG to *ACT.
|
79 |
|
|
If OACT is not NULL, put the old action for SIG in *OACT. */
|
80 |
|
|
int __libc_sigaction (int sig, const struct sigaction *act, struct sigaction *oact)
|
81 |
|
|
{
|
82 |
|
|
int result;
|
83 |
|
|
struct old_kernel_sigaction kact, koact;
|
84 |
|
|
|
85 |
|
|
if (act) {
|
86 |
|
|
kact.k_sa_handler = act->sa_handler;
|
87 |
|
|
kact.sa_mask = act->sa_mask.__val[0];
|
88 |
|
|
kact.sa_flags = act->sa_flags;
|
89 |
|
|
# ifdef HAVE_SA_RESTORER
|
90 |
|
|
/* See the comments above for why we test SA_ONSTACK. */
|
91 |
|
|
if (kact.sa_flags & (SA_RESTORER | SA_ONSTACK)) {
|
92 |
|
|
kact.sa_restorer = act->sa_restorer;
|
93 |
|
|
} else {
|
94 |
|
|
kact.sa_restorer = __default_sa_restorer;
|
95 |
|
|
kact.sa_flags |= SA_RESTORER;
|
96 |
|
|
}
|
97 |
|
|
# endif
|
98 |
|
|
}
|
99 |
|
|
result = __syscall_sigaction(sig, act ? __ptrvalue (&kact) : NULL,
|
100 |
|
|
oact ? __ptrvalue (&koact) : NULL);
|
101 |
|
|
|
102 |
|
|
if (oact && result >= 0) {
|
103 |
|
|
oact->sa_handler = koact.k_sa_handler;
|
104 |
|
|
oact->sa_mask.__val[0] = koact.sa_mask;
|
105 |
|
|
oact->sa_flags = koact.sa_flags;
|
106 |
|
|
# ifdef HAVE_SA_RESTORER
|
107 |
|
|
oact->sa_restorer = koact.sa_restorer;
|
108 |
|
|
# endif
|
109 |
|
|
}
|
110 |
|
|
return result;
|
111 |
|
|
}
|
112 |
|
|
|
113 |
|
|
#endif
|
114 |
|
|
|
115 |
|
|
weak_alias(__libc_sigaction, sigaction)
|
116 |
|
|
|