]> 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 sigaction *,
32 struct 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 sigaction nact, *nactp;
51
52 if (act)
53 {
54 nact.sa_handler = act->sa_handler;
55 memcpy (&nact.sa_mask, &act->sa_mask, sizeof (sigset_t));
56 nact.sa_flags = act->sa_flags;
57
58 nact.sa_restorer = ((act->sa_flags & SA_NOMASK)
59 ? &&restore_nomask : &&restore);
60 nactp = &nact;
61 }
62 else
63 nactp = NULL;
64
65 /* XXX The size argument hopefully will have to be changed to the
66 real size of the user-level sigset_t. */
67 result = __syscall_rt_sigaction (sig, nactp, oact, _NSIG / 8);
68
69 if (result >= 0 || errno != ENOSYS)
70 return result;
71
72 __libc_missing_rt_sigs = 1;
73 }
74
75 if (act)
76 {
77 k_newact.k_sa_handler = act->sa_handler;
78 k_newact.sa_mask = act->sa_mask.__val[0];
79 k_newact.sa_flags = act->sa_flags;
80
81 k_newact.sa_restorer = ((act->sa_flags & SA_NOMASK)
82 ? &&restore_nomask : &&restore);
83 }
84
85 asm volatile ("pushl %%ebx\n"
86 "movl %2, %%ebx\n"
87 "int $0x80\n"
88 "popl %%ebx"
89 : "=a" (result)
90 : "0" (SYS_ify (sigaction)), "r" (sig),
91 "c" (act ? &k_newact : 0), "d" (oact ? &k_oldact : 0));
92
93 if (result < 0)
94 {
95 __set_errno (-result);
96 return -1;
97 }
98
99 if (oact)
100 {
101 oact->sa_handler = k_oldact.k_sa_handler;
102 oact->sa_mask.__val[0] = k_oldact.sa_mask;
103 oact->sa_flags = k_oldact.sa_flags;
104 oact->sa_restorer = k_oldact.sa_restorer;
105 }
106
107 return 0;
108
109 restore:
110 asm (
111 #ifdef PIC
112 " pushl %%ebx\n"
113 " call 0f\n"
114 "0: popl %%ebx\n"
115 " addl $_GLOBAL_OFFSET_TABLE_+[.-0b], %%ebx\n"
116 " addl $8, %%esp\n"
117 " call __sigsetmask@PLT\n"
118 " addl $8, %%esp\n"
119 " popl %%ebx\n"
120 #else
121 " addl $4, %%esp\n"
122 " call __sigsetmask\n"
123 " addl $4, %%esp\n"
124 #endif
125 " popl %%eax\n"
126 " popl %%ecx\n"
127 " popl %%edx\n"
128 " popf\n"
129 " ret"
130 : : );
131
132 restore_nomask:
133 asm (" addl $4, %%esp\n"
134 " popl %%eax\n"
135 " popl %%ecx\n"
136 " popl %%edx\n"
137 " popf\n"
138 " ret"
139 : : );
140
141 /* NOTREACHED */
142 return -1;
143 }
144
145 weak_alias (__sigaction, sigaction)