Thu Oct 26 00:11:13 1995 Roland McGrath <roland@churchy.gnu.ai.mit.edu>
[platform/upstream/linaro-glibc.git] / sysdeps / unix / sysv / linux / i386 / sigaction.c
1 /* POSIX.1 `sigaction' call for Linux/i386.
2 Copyright (C) 1991, 1995 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
17 not, write to the Free Software Foundation, Inc., 675 Mass Ave,
18 Cambridge, MA 02139, USA.  */
19
20 #include <sysdep.h>
21 #include <errno.h>
22 #include <stddef.h>
23 #include <signal.h>
24
25
26 /* If ACT is not NULL, change the action for SIG to *ACT.
27    If OACT is not NULL, put the old action for SIG in *OACT.  */
28 int
29 __sigaction (int sig, const struct sigaction *act, struct sigaction *oact)
30 {
31   struct sigaction newact;
32   int result;
33
34   if (new)
35     {
36       newact = *new;
37       new = &newact;
38       new->sa_restorer = ((new->sa_flags & SA_NOMASK)
39                           ? &&restore_nomask : &&restore);
40     }
41
42   asm volatile ("pushl %%ebx\n"
43                 "movl %1, %%ebx\n"
44                 "int $0x80\n"
45                 "popl %%ebx"
46                 : "=a" (result)
47                 : "0" (SYS_ify (sigaction)), "g" (sig), "c" (new), "d" (old));
48
49   if (result < 0)
50     {
51       errno = -result;
52       return -1;
53     }
54   return 0;
55
56  restore:
57   asm (
58 #ifdef  PIC
59        "        pushl %ebx\n"
60        "        call 0f\n"
61        "0:      popl %ebx\n"
62        "        addl $_GLOBAL_OFFSET_TABLE_+[.-0b],%ebx\n"
63        "        addl $8, %%esp\n"
64        "        call __sigsetmask@PLT\n"
65        "        addl $8, %%esp\n"
66        "        popl %ebx\n"
67 #else
68        "        addl $4, %%esp\n"
69        "        call __sigsetmask\n"
70        "        addl $4, %%esp\n"
71 #endif
72        "popl %eax\n"
73        "popl %ecx\n"
74        "popl %edx\n"
75        "popf\n"
76        "ret");
77  restore_nomask:
78   asm ("addl $4, %esp\n"
79        "popl %eax\n"
80        "popl %ecx\n"
81        "popl %edx\n"
82        "popf\n"
83        "ret");
84 }
85
86 weak_alias (__sigaction, sigaction)