]> git.saurik.com Git - apple/libc.git/blob - sys/sigaction.c
2737a914adbf069bed8713d01a2a0f845bc683e8
[apple/libc.git] / sys / sigaction.c
1 /*
2 * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
7 *
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * file.
14 *
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
22 *
23 * @APPLE_LICENSE_HEADER_END@
24 */
25 /*
26 * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved
27 *
28 * @(#)sigaction.c 1.0
29 */
30
31 #include <sys/syscall.h>
32 #include <signal.h>
33 #include <sys/signal.h>
34 #include <errno.h>
35
36 /*
37 * Intercept the sigaction syscall and use our signal trampoline
38 * as the signal handler instead. The code here is derived
39 * from sigvec in sys/kern_sig.c.
40 */
41
42 #if defined(__DYNAMIC__)
43 extern int __in_sigtramp;
44 #endif
45
46 static int
47 sigaction__ (sig, nsv, osv, bind)
48 int sig;
49 register struct sigaction *nsv, *osv;
50 int bind;
51 {
52 struct sigaction vec;
53 void (*prevsig)();
54 extern void _sigtramp();
55 struct __sigaction sa;
56 struct __sigaction *sap;
57
58 if (sig <= 0 || sig >= NSIG || sig == SIGKILL || sig == SIGSTOP) {
59 errno = EINVAL;
60 return (-1);
61 }
62 sap = (struct __sigaction *)0;
63 if (nsv) {
64 sa.sa_handler = nsv->sa_handler;
65 sa.sa_tramp = _sigtramp;
66 sa.sa_mask = nsv->sa_mask;
67 sa.sa_flags = nsv->sa_flags;
68 sap = &sa;
69 if (nsv->sa_handler != (void (*)())SIG_DFL && nsv->sa_handler != (void (*)())SIG_IGN) {
70 #ifdef __DYNAMIC__
71 if (bind && (__in_sigtramp == 0)) // XXX
72 _dyld_bind_fully_image_containing_address(nsv->sa_handler);
73 #endif
74 }
75 }
76 if (syscall (SYS_sigaction, sig, sap, osv) < 0) {
77 return (-1);
78 }
79 return (0);
80 }
81
82
83 int
84 sigaction (sig, nsv, osv)
85 int sig;
86 register const struct sigaction *nsv;
87 register struct sigaction *osv;
88 {
89 return sigaction__(sig, nsv, osv, 1);
90 }
91
92 // XXX
93 #ifdef __DYNAMIC__
94
95 int
96 _sigaction_nobind (sig, nsv, osv)
97 int sig;
98 register const struct sigaction *nsv;
99 register struct sigaction *osv;
100 {
101 return sigaction__(sig, nsv, osv, 0);
102 }
103 #endif
104