]> git.saurik.com Git - apple/libplatform.git/blob - src/setjmp/generic/sigtramp.c
libplatform-177.200.16.tar.gz
[apple/libplatform.git] / src / setjmp / generic / sigtramp.c
1 /*
2 * Copyright (c) 1999, 2007 Apple Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
11 * file.
12 *
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23 /*
24 * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved
25 */
26
27 #define _XOPEN_SOURCE 600
28
29 #import <sys/types.h>
30 #import <signal.h>
31 #import <unistd.h>
32 #import <ucontext.h>
33 #import <mach/thread_status.h>
34 #include <TargetConditionals.h>
35 #import <os/internal.h>
36
37 extern int __sigreturn(ucontext_t *, int, uintptr_t);
38
39 /*
40 * sigvec registers _sigtramp as the handler for any signal requiring
41 * user-mode intervention. All _sigtramp does is find the real handler,
42 * calls it, then sigreturn's.
43 *
44 * Note that the kernel saves/restores all of our register state.
45 */
46
47 /* On i386, i386/sys/_sigtramp.s defines this. There is no in_sigtramp on arm */
48 #if defined(__DYNAMIC__) && defined(__x86_64__)
49 OS_NOEXPORT
50 int __in_sigtramp = 0;
51 #endif
52
53 /* These defn should match the kernel one */
54 #define UC_TRAD 1
55 #define UC_FLAVOR 30
56
57 #define UC_SET_ALT_STACK 0x40000000
58 #define UC_RESET_ALT_STACK 0x80000000
59
60 /*
61 * Reset the kernel's idea of the use of an alternate stack; this is used by
62 * both longjmp() and siglongjmp(). Nothing other than this reset is needed,
63 * since restoring the registers and other operations that would normally be
64 * done by sigreturn() are handled in user space, so we do not pass a user
65 * context (in PPC, a user context is not the same as a jmpbuf mcontext, due
66 * to having more than one set of registers, etc., for the various 32/64 etc.
67 * contexts)..
68 */
69 OS_NOEXPORT
70 void
71 _sigunaltstack(int set)
72 {
73 /* sigreturn(uctx, ctxstyle); */
74 /* syscall (SYS_SIGRETURN, uctx, ctxstyle); */
75 __sigreturn (NULL, (set == SS_ONSTACK) ? UC_SET_ALT_STACK : UC_RESET_ALT_STACK, 0);
76 }
77
78 /* On these architectures, _sigtramp is implemented in assembly to
79 ensure it matches its DWARF unwind information. */
80 #if !defined (__i386__) && !defined (__x86_64__)
81 OS_NOEXPORT
82 void
83 _sigtramp(
84 union __sigaction_u __sigaction_u,
85 int sigstyle,
86 int sig,
87 siginfo_t *sinfo,
88 ucontext_t *uctx,
89 uintptr_t token
90 ) {
91 int ctxstyle = UC_FLAVOR;
92
93 if (sigstyle == UC_TRAD)
94 sa_handler(sig);
95 else {
96 #if TARGET_OS_WATCH
97 // <rdar://problem/22016014>
98 sa_sigaction(sig, sinfo, NULL);
99 #else
100 sa_sigaction(sig, sinfo, uctx);
101 #endif
102 }
103
104 /* sigreturn(uctx, ctxstyle); */
105 /* syscall (SYS_SIGRETURN, uctx, ctxstyle); */
106 __sigreturn (uctx, ctxstyle, token);
107 __builtin_trap(); /* __sigreturn returning is a fatal error */
108 }
109
110 #endif /* not ppc nor ppc64 nor i386 nor x86_64 */