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>
35 #import <os/internal.h>
37 extern int __sigreturn(ucontext_t
*, int, uintptr_t);
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.
44 * Note that the kernel saves/restores all of our register state.
47 /* On i386, i386/sys/_sigtramp.s defines this. There is no in_sigtramp on arm */
48 #if defined(__DYNAMIC__) && defined(__x86_64__)
50 int __in_sigtramp
= 0;
53 /* These defn should match the kernel one */
57 #define UC_SET_ALT_STACK 0x40000000
58 #define UC_RESET_ALT_STACK 0x80000000
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.
71 _sigunaltstack(int set
)
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);
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__)
84 union __sigaction_u __sigaction_u
,
91 int ctxstyle
= UC_FLAVOR
;
93 if (sigstyle
== UC_TRAD
)
97 // <rdar://problem/22016014>
98 sa_sigaction(sig
, sinfo
, NULL
);
100 sa_sigaction(sig
, sinfo
, uctx
);
104 /* sigreturn(uctx, ctxstyle); */
105 /* syscall (SYS_SIGRETURN, uctx, ctxstyle); */
106 __sigreturn (uctx
, ctxstyle
, token
);
107 __builtin_trap(); /* __sigreturn returning is a fatal error */
110 #endif /* not ppc nor ppc64 nor i386 nor x86_64 */