1 |
207 |
jeremybenn |
/* POSIX.1 `sigaction' call for Linux/i386.
|
2 |
|
|
Copyright (C) 1991, 95, 96, 97, 98, 99, 2000 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 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.
|
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 |
|
|
Lesser General Public License for more details.
|
14 |
|
|
|
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. */
|
19 |
|
|
|
20 |
|
|
#include <errno.h>
|
21 |
|
|
#include <stddef.h>
|
22 |
|
|
#include <signal.h>
|
23 |
|
|
#include <string.h>
|
24 |
|
|
|
25 |
|
|
#include <machine/syscall.h>
|
26 |
|
|
|
27 |
|
|
/* The difference here is that the sigaction structure used in the
|
28 |
|
|
kernel is not the same as we use in the libc. Therefore we must
|
29 |
|
|
translate it here. */
|
30 |
|
|
#include <kernel_sigaction.h>
|
31 |
|
|
|
32 |
|
|
/* We do not globally define the SA_RESTORER flag so do it here. */
|
33 |
|
|
#define SA_RESTORER 0x04000000
|
34 |
|
|
|
35 |
|
|
#define __NR___rt_sigaction __NR_rt_sigaction
|
36 |
|
|
|
37 |
|
|
static _syscall4(int,__rt_sigaction,int,sig,const struct kernel_sigaction *,act,
|
38 |
|
|
struct kernel_sigaction *,oact,size_t,size)
|
39 |
|
|
|
40 |
|
|
static void restore_rt (void) asm ("__restore_rt");
|
41 |
|
|
static void restore (void) asm ("__restore");
|
42 |
|
|
|
43 |
|
|
/* If ACT is not NULL, change the action for SIG to *ACT.
|
44 |
|
|
If OACT is not NULL, put the old action for SIG in *OACT. */
|
45 |
|
|
int
|
46 |
|
|
__libc_sigaction (int sig, const struct sigaction *act, struct sigaction *oact)
|
47 |
|
|
{
|
48 |
|
|
int result;
|
49 |
|
|
struct kernel_sigaction kact, koact;
|
50 |
|
|
|
51 |
|
|
if (act)
|
52 |
|
|
{
|
53 |
|
|
kact.k_sa_handler = act->sa_handler;
|
54 |
|
|
memcpy (&kact.sa_mask, &act->sa_mask, sizeof (sigset_t));
|
55 |
|
|
kact.sa_flags = act->sa_flags | SA_RESTORER;
|
56 |
|
|
|
57 |
|
|
kact.sa_restorer = ((act->sa_flags & SA_SIGINFO)
|
58 |
|
|
? &restore_rt : &restore);
|
59 |
|
|
}
|
60 |
|
|
|
61 |
|
|
/* XXX The size argument hopefully will have to be changed to the
|
62 |
|
|
real size of the user-level sigset_t. */
|
63 |
|
|
result = __rt_sigaction(sig, act ? (&kact) : NULL,
|
64 |
|
|
oact ? (&koact) : NULL, _NSIG / 8);
|
65 |
|
|
|
66 |
|
|
if (oact && result >= 0)
|
67 |
|
|
{
|
68 |
|
|
oact->sa_handler = koact.k_sa_handler;
|
69 |
|
|
memcpy (&oact->sa_mask, &koact.sa_mask, sizeof (sigset_t));
|
70 |
|
|
oact->sa_flags = koact.sa_flags;
|
71 |
|
|
oact->sa_restorer = koact.sa_restorer;
|
72 |
|
|
}
|
73 |
|
|
return result;
|
74 |
|
|
}
|
75 |
|
|
|
76 |
|
|
weak_alias (__libc_sigaction, __sigaction)
|
77 |
|
|
weak_alias (__libc_sigaction, sigaction)
|
78 |
|
|
|
79 |
|
|
/* NOTE: Please think twice before making any changes to the bits of
|
80 |
|
|
code below. GDB needs some intimate knowledge about it to
|
81 |
|
|
recognize them as signal trampolines, and make backtraces through
|
82 |
|
|
signal handlers work right. Important are both the names
|
83 |
|
|
(__restore and __restore_rt) and the exact instruction sequence.
|
84 |
|
|
If you ever feel the need to make any changes, please notify the
|
85 |
|
|
appropriate GDB maintainer. */
|
86 |
|
|
|
87 |
|
|
#define RESTORE(name, syscall) RESTORE2 (name, syscall)
|
88 |
|
|
#define RESTORE2(name, syscall) \
|
89 |
|
|
asm \
|
90 |
|
|
( \
|
91 |
|
|
".text\n" \
|
92 |
|
|
" .align 16\n" \
|
93 |
|
|
"__" #name ":\n" \
|
94 |
|
|
" movl $" #syscall ", %eax\n" \
|
95 |
|
|
" int $0x80" \
|
96 |
|
|
);
|
97 |
|
|
|
98 |
|
|
/* The return code for realtime-signals. */
|
99 |
|
|
RESTORE (restore_rt, __NR_rt_sigreturn)
|
100 |
|
|
|
101 |
|
|
/* For the boring old signals. */
|
102 |
|
|
# undef RESTORE2
|
103 |
|
|
# define RESTORE2(name, syscall) \
|
104 |
|
|
asm \
|
105 |
|
|
( \
|
106 |
|
|
".text\n" \
|
107 |
|
|
" .align 8\n" \
|
108 |
|
|
"__" #name ":\n" \
|
109 |
|
|
" popl %eax\n" \
|
110 |
|
|
" movl $" #syscall ", %eax\n" \
|
111 |
|
|
" int $0x80" \
|
112 |
|
|
);
|
113 |
|
|
|
114 |
|
|
RESTORE (restore, __NR_sigreturn)
|