2 * Copyright (c) 1999, 2007 Apple Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
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
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.
21 * @APPLE_LICENSE_HEADER_END@
24 * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved
27 #define _XOPEN_SOURCE 600
33 #import <mach/thread_status.h>
34 #include <TargetConditionals.h>
36 extern int __sigreturn(ucontext_t
*, int);
39 * sigvec registers _sigtramp as the handler for any signal requiring
40 * user-mode intervention. All _sigtramp does is find the real handler,
41 * calls it, then sigreturn's.
43 * Note that the kernel saves/restores all of our register state.
46 /* On i386, i386/sys/_sigtramp.s defines this. There is no in_sigtramp on arm */
47 #if defined(__DYNAMIC__) && defined(__x86_64__)
48 __attribute__((visibility("hidden")))
49 int __in_sigtramp
= 0;
52 /* These defn should match the kernel one */
55 #if defined(__ppc__) || defined(__ppc64__)
57 #define UC_TRAD64_VEC 25
58 #define UC_FLAVOR_VEC 35
59 #define UC_FLAVOR64 40
60 #define UC_FLAVOR64_VEC 45
62 #define UC_DUAL_VEC 55
64 /* The following are valid mcontext sizes */
65 #define UC_FLAVOR_SIZE ((PPC_THREAD_STATE_COUNT + PPC_EXCEPTION_STATE_COUNT + PPC_FLOAT_STATE_COUNT) * sizeof(int))
67 #define UC_FLAVOR_VEC_SIZE ((PPC_THREAD_STATE_COUNT + PPC_EXCEPTION_STATE_COUNT + PPC_FLOAT_STATE_COUNT + PPC_VECTOR_STATE_COUNT) * sizeof(int))
69 #define UC_FLAVOR64_SIZE ((PPC_THREAD_STATE64_COUNT + PPC_EXCEPTION_STATE64_COUNT + PPC_FLOAT_STATE_COUNT) * sizeof(int))
71 #define UC_FLAVOR64_VEC_SIZE ((PPC_THREAD_STATE64_COUNT + PPC_EXCEPTION_STATE64_COUNT + PPC_FLOAT_STATE_COUNT + PPC_VECTOR_STATE_COUNT) * sizeof(int))
74 #define UC_SET_ALT_STACK 0x40000000
75 #define UC_RESET_ALT_STACK 0x80000000
78 * Reset the kernel's idea of the use of an alternate stack; this is used by
79 * both longjmp() and siglongjmp(). Nothing other than this reset is needed,
80 * since restoring the registers and other operations that would normally be
81 * done by sigreturn() are handled in user space, so we do not pass a user
82 * context (in PPC, a user context is not the same as a jmpbuf mcontext, due
83 * to having more than one set of registers, etc., for the various 32/64 etc.
87 _sigunaltstack(int set
)
89 /* sigreturn(uctx, ctxstyle); */
90 /* syscall (SYS_SIGRETURN, uctx, ctxstyle); */
91 __sigreturn (NULL
, (set
== SS_ONSTACK
) ? UC_SET_ALT_STACK
: UC_RESET_ALT_STACK
);
94 /* On these architectures, _sigtramp is implemented in assembly to
95 ensure it matches its DWARF unwind information. */
96 #if !defined (__i386__) && !defined (__x86_64__)
100 union __sigaction_u __sigaction_u
,
106 int ctxstyle
= UC_FLAVOR
;
108 if (sigstyle
== UC_TRAD
)
112 // <rdar://problem/22016014>
113 sa_sigaction(sig
, sinfo
, NULL
);
115 sa_sigaction(sig
, sinfo
, uctx
);
119 /* sigreturn(uctx, ctxstyle); */
120 /* syscall (SYS_SIGRETURN, uctx, ctxstyle); */
121 __sigreturn (uctx
, ctxstyle
);
124 #endif /* not ppc nor ppc64 nor i386 nor x86_64 */