]> git.ipfire.org Git - thirdparty/glibc.git/blob - sysdeps/unix/sysv/linux/i386/sigaction.c
Update.
[thirdparty/glibc.git] / sysdeps / unix / sysv / linux / i386 / sigaction.c
1 /* POSIX.1 `sigaction' call for Linux/i386.
2 Copyright (C) 1991, 1995, 1996, 1997, 1998 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public License as
7 published by the Free Software Foundation; either version 2 of the
8 License, or (at your option) any later version.
9
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 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public
16 License along with the GNU C Library; see the file COPYING.LIB. If not,
17 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. */
19
20 #include <sysdep.h>
21 #include <errno.h>
22 #include <stddef.h>
23 #include <signal.h>
24
25 /* The difference here is that the sigaction structure used in the
26 kernel is not the same as we use in the libc. Therefore we must
27 translate it here. */
28 #include <kernel_sigaction.h>
29
30
31 extern int __syscall_rt_sigaction (int, const struct kernel_sigaction *,
32 struct kernel_sigaction *, size_t);
33
34 /* The variable is shared between all wrappers around signal handling
35 functions which have RT equivalents. */
36 int __libc_missing_rt_sigs;
37
38
39 /* If ACT is not NULL, change the action for SIG to *ACT.
40 If OACT is not NULL, put the old action for SIG in *OACT. */
41 int
42 __sigaction (int sig, const struct sigaction *act, struct sigaction *oact)
43 {
44 struct old_kernel_sigaction k_newact, k_oldact;
45 int result;
46
47 /* First try the RT signals. */
48 if (!__libc_missing_rt_sigs)
49 {
50 struct kernel_sigaction kact, koact;
51 int saved_errno = errno;
52
53 if (act)
54 {
55 kact.k_sa_handler = act->sa_handler;
56 memcpy (&kact.sa_mask, &act->sa_mask, sizeof (sigset_t));
57 kact.sa_flags = act->sa_flags;
58
59 kact.sa_restorer = ((act->sa_flags & SA_NOMASK)
60 ? &&restore_nomask : &&restore);
61 }
62
63 /* XXX The size argument hopefully will have to be changed to the
64 real size of the user-level sigset_t. */
65 result = __syscall_rt_sigaction (sig, act ? &kact : NULL,
66 oact ? &koact : NULL, _NSIG / 8);
67
68 if (result >= 0 || errno != ENOSYS)
69 {
70 if (oact && result >= 0)
71 {
72 oact->sa_handler = koact.k_sa_handler;
73 memcpy (&oact->sa_mask, &koact.sa_mask, sizeof (sigset_t));
74 oact->sa_flags = koact.sa_flags;
75 oact->sa_restorer = koact.sa_restorer;
76 }
77 return result;
78 }
79
80 __set_errno (saved_errno);
81 __libc_missing_rt_sigs = 1;
82 }
83
84 if (act)
85 {
86 k_newact.k_sa_handler = act->sa_handler;
87 k_newact.sa_mask = act->sa_mask.__val[0];
88 k_newact.sa_flags = act->sa_flags;
89
90 k_newact.sa_restorer = ((act->sa_flags & SA_NOMASK)
91 ? &&restore_nomask : &&restore);
92 }
93
94 asm volatile ("pushl %%ebx\n"
95 "movl %2, %%ebx\n"
96 "int $0x80\n"
97 "popl %%ebx"
98 : "=a" (result)
99 : "0" (SYS_ify (sigaction)), "r" (sig),
100 "c" (act ? &k_newact : 0), "d" (oact ? &k_oldact : 0));
101
102 if (result < 0)
103 {
104 __set_errno (-result);
105 return -1;
106 }
107
108 if (oact)
109 {
110 oact->sa_handler = k_oldact.k_sa_handler;
111 oact->sa_mask.__val[0] = k_oldact.sa_mask;
112 oact->sa_flags = k_oldact.sa_flags;
113 oact->sa_restorer = k_oldact.sa_restorer;
114 }
115
116 return 0;
117
118 restore:
119 asm (
120 #ifdef PIC
121 " pushl %%ebx\n"
122 " call 0f\n"
123 "0: popl %%ebx\n"
124 " addl $_GLOBAL_OFFSET_TABLE_+[.-0b], %%ebx\n"
125 " addl $8, %%esp\n"
126 " call __sigsetmask@PLT\n"
127 " addl $8, %%esp\n"
128 " popl %%ebx\n"
129 #else
130 " addl $4, %%esp\n"
131 " call __sigsetmask\n"
132 " addl $4, %%esp\n"
133 #endif
134 " popl %%eax\n"
135 " popl %%ecx\n"
136 " popl %%edx\n"
137 " popf\n"
138 " ret"
139 : : );
140
141 restore_nomask:
142 asm (" addl $4, %%esp\n"
143 " popl %%eax\n"
144 " popl %%ecx\n"
145 " popl %%edx\n"
146 " popf\n"
147 " ret"
148 : : );
149
150 /* NOTREACHED */
151 return -1;
152 }
153
154 weak_alias (__sigaction, sigaction)