]> git.saurik.com Git - apple/libc.git/blame - sys/sigaction.c
Libc-320.tar.gz
[apple/libc.git] / sys / sigaction.c
CommitLineData
e9ce8d39
A
1/*
2 * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
734aad71 6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
e9ce8d39 7 *
734aad71
A
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
e9ce8d39
A
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
734aad71
A
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.
e9ce8d39
A
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>
9385eb3d 32#include <unistd.h>
e9ce8d39
A
33#include <signal.h>
34#include <sys/signal.h>
35#include <errno.h>
36
37/*
38 * Intercept the sigaction syscall and use our signal trampoline
39 * as the signal handler instead. The code here is derived
40 * from sigvec in sys/kern_sig.c.
41 */
42
e9ce8d39
A
43#if defined(__DYNAMIC__)
44extern int __in_sigtramp;
45#endif
46
47static int
48sigaction__ (sig, nsv, osv, bind)
49 int sig;
50 register struct sigaction *nsv, *osv;
51 int bind;
52{
e9ce8d39 53 extern void _sigtramp();
5b2abdfb
A
54 struct __sigaction sa;
55 struct __sigaction *sap;
e9ce8d39
A
56
57 if (sig <= 0 || sig >= NSIG || sig == SIGKILL || sig == SIGSTOP) {
58 errno = EINVAL;
59 return (-1);
60 }
5b2abdfb 61 sap = (struct __sigaction *)0;
e9ce8d39 62 if (nsv) {
5b2abdfb
A
63 sa.sa_handler = nsv->sa_handler;
64 sa.sa_tramp = _sigtramp;
65 sa.sa_mask = nsv->sa_mask;
66 sa.sa_flags = nsv->sa_flags;
67 sap = &sa;
e9ce8d39 68 if (nsv->sa_handler != (void (*)())SIG_DFL && nsv->sa_handler != (void (*)())SIG_IGN) {
e9ce8d39
A
69#ifdef __DYNAMIC__
70 if (bind && (__in_sigtramp == 0)) // XXX
5b2abdfb 71 _dyld_bind_fully_image_containing_address(nsv->sa_handler);
e9ce8d39
A
72#endif
73 }
74 }
5b2abdfb 75 if (syscall (SYS_sigaction, sig, sap, osv) < 0) {
e9ce8d39
A
76 return (-1);
77 }
e9ce8d39
A
78 return (0);
79}
80
81
82int
83sigaction (sig, nsv, osv)
84 int sig;
85 register const struct sigaction *nsv;
86 register struct sigaction *osv;
87{
88 return sigaction__(sig, nsv, osv, 1);
89}
90
91// XXX
92#ifdef __DYNAMIC__
93
94int
95_sigaction_nobind (sig, nsv, osv)
96 int sig;
97 register const struct sigaction *nsv;
98 register struct sigaction *osv;
99{
100 return sigaction__(sig, nsv, osv, 0);
101}
102#endif
103