]>
git.saurik.com Git - apple/libplatform.git/blob - src/ucontext/generic/getmcontext.c
2 * Copyright (c) 2007, 2008, 2009 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 #define _XOPEN_SOURCE 600L
28 #if defined(__x86_64__) || defined(__i386__)
30 #include <sys/resource.h>
35 extern int __sigaltstack(const stack_t
* __restrict
, stack_t
* __restrict
);
38 extern int __in_sigtramp
;
39 #endif /* __DYNAMIC_ */
41 __attribute__((visibility("hidden")))
43 getmcontext(ucontext_t
*uctx
, void *sp
)
45 mcontext_t mctx
= (mcontext_t
)&uctx
->__mcontext_data
;
49 uctx
->uc_stack
.ss_sp
= sp
;
50 uctx
->uc_stack
.ss_flags
= 0;
52 if (0 == __sigaltstack(NULL
, &stack
)) {
53 if (stack
.ss_flags
& SS_ONSTACK
) {
54 uctx
->uc_stack
= stack
;
55 stacksize
= stack
.ss_size
;
61 if (0 == getrlimit(RLIMIT_STACK
, &rlim
))
62 stacksize
= rlim
.rlim_cur
;
65 uctx
->uc_stack
.ss_size
= stacksize
;
67 if (uctx
->uc_mcontext
!= mctx
) {
68 uctx
->uc_mcontext
= mctx
;
71 uctx
->uc_link
= (ucontext_t
*)(uintptr_t)__in_sigtramp
; /* non-zero if in signal handler */
72 #else /* !__DYNAMIC__ */
74 #endif /* __DYNAMIC__ */
78 sigprocmask(0, NULL
, &uctx
->uc_sigmask
);
85 getcontext(ucontext_t
*u
)