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>
58 #define JB_FPCONTROL 76
60 #define JB_SAVEMASK 84 // sigsetjmp/siglongjmp only
64 // %rdi is sigjmp_buf * jmpbuf;
65 // %esi is int savemask
66 movl %esi, JB_SAVEMASK(%rdi) // jmpbuf[_JBLEN] = savemask;
67 cmpl $0, %esi // if savemask != 0
68 jne _setjmp // setjmp(jmpbuf);
69 jmp L_do__setjmp // else _setjmp(jmpbuf);
72 pushq %rdi // Preserve the jmp_buf across the call
73 movl $1, %edi // how = SIG_BLOCK
74 xorq %rsi, %rsi // set = NULL
75 subq $16, %rsp // Allocate space for the return from sigprocmask + 8 to align stack
76 movq %rsp, %rdx // oset = allocated space
77 CALL_EXTERN(_sigprocmask)
78 popq %rax // Save the mask
79 addq $8, %rsp // Restore the stack to before we align it
80 popq %rdi // jmp_buf (struct sigcontext *)
81 movq %rax, JB_MASK(%rdi)
83 BRANCH_EXTERN(__setjmp)
86 // %rdi is sigjmp_buf * jmpbuf;
87 cmpl $0, JB_SAVEMASK(%rdi) // if jmpbuf[_JBLEN] != 0
88 jne _longjmp // longjmp(jmpbuf, var);
89 jmp L_do__longjmp // else _longjmp(jmpbuf, var);
92 // %rdi is address of jmp_buf (saved context)
93 pushq %rdi // Preserve the jmp_buf across the call
94 pushq %rsi // Preserve the value across the call
95 pushq JB_MASK(%rdi) // Put the mask on the stack
96 movq $3, %rdi // how = SIG_SETMASK
97 movq %rsp, %rsi // set = address where we stored the mask
98 xorq %rdx, %rdx // oset = NULL
99 CALL_EXTERN_AGAIN(_sigprocmask)
101 popq %rsi // Restore the value
102 popq %rdi // Restore the jmp_buf
104 BRANCH_EXTERN(__longjmp) // else