2 * Copyright (c) 1999 Apple Computer, 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 * NeXT 386 setjmp/longjmp
29 * Written by Bruce Martin, NeXT Inc. 4/9/92
33 * C library -- setjmp, longjmp
36 * will generate a "return(v)" from
39 * by restoring registers from the stack,
40 * The previous value of the signal mask is
45 #include <architecture/i386/asm_help.h>
57 #define JB_FPCONTROL 76
59 #define JB_SAVEMASK 84 // sigsetjmp/siglongjmp only
62 #define STACK_SSFLAGS 16 // offsetof(stack_t, ss_flags)
65 // %rdi is sigjmp_buf * jmpbuf;
66 // %esi is int savemask
67 movl %esi, JB_SAVEMASK(%rdi) // jmpbuf[_JBLEN] = savemask;
68 cmpl $0, %esi // if savemask != 0
69 jne _setjmp // setjmp(jmpbuf);
70 jmp L_do__setjmp // else _setjmp(jmpbuf);
73 pushq %rdi // Preserve the jmp_buf across the call
74 movl $1, %edi // how = SIG_BLOCK
75 xorq %rsi, %rsi // set = NULL
76 subq $16, %rsp // Allocate space for the return from sigprocmask + 8 to align stack
77 movq %rsp, %rdx // oset = allocated space
78 CALL_EXTERN(_sigprocmask)
79 popq %rax // Save the mask
80 addq $8, %rsp // Restore the stack to before we align it
81 movq (%rsp), %rdi // jmp_buf (struct sigcontext *). Leave pointer on the stack for _sigaltstack call)
82 movl %eax, JB_MASK(%rdi)
84 // Get current sigaltstack status (stack_t)
85 subq $32, %rsp // 24 bytes for a stack_t, + 8 for the jmp_buf pointer, + 8 is correctly aligned
86 movq %rsp, %rsi // oss
87 xorq %rdi, %rdi // ss == NULL
88 CALL_EXTERN(___sigaltstack) // __sigaltstack(NULL, oss)
89 movl STACK_SSFLAGS(%rsp), %eax // oss.ss_flags
90 movq 32(%rsp), %rdi // jmpbuf (will be first argument to subsequent call)
91 movl %eax, JB_ONSTACK(%rdi) // Store ss_flags in jmpbuf
92 addq $40, %rsp // restore %rsp
95 BRANCH_EXTERN(__setjmp)
98 // %rdi is sigjmp_buf * jmpbuf;
99 cmpl $0, JB_SAVEMASK(%rdi) // if jmpbuf[_JBLEN] != 0
100 jne _longjmp // longjmp(jmpbuf, var);
101 jmp L_do__longjmp // else _longjmp(jmpbuf, var);
104 // %rdi is address of jmp_buf (saved context)
105 pushq %rdi // Preserve the jmp_buf across the call
106 pushq %rsi // Preserve the value across the call
107 pushq JB_MASK(%rdi) // Put the mask on the stack
108 movq $3, %rdi // how = SIG_SETMASK
109 movq %rsp, %rsi // set = address where we stored the mask
110 xorq %rdx, %rdx // oset = NULL
111 CALL_EXTERN_AGAIN(_sigprocmask)
113 // Restore sigaltstack status
114 movq 16(%rsp), %rdi // Grab jmpbuf but leave it on the stack
115 movl JB_ONSTACK(%rdi), %edi // Pass old state to _sigunaltstack()
116 CALL_EXTERN(__sigunaltstack)
117 addq $8, %rsp // Restore stack
119 popq %rdi // Pass jmpbuf to _longjmp
122 BRANCH_EXTERN(__longjmp) // else