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>
48 // The FP control word is actually two bytes, but there's no harm in
49 // using four bytes for it and keeping the struct aligned.
68 #define JB_SAVEMASK 72 // sigsetjmp/siglongjmp only
71 movl 4(%esp), %eax // sigjmp_buf * jmpbuf;
72 movl 8(%esp), %ecx // int savemask;
73 movl %ecx, JB_SAVEMASK(%eax) // jmpbuf[_JBLEN] = savemask;
74 cmpl $0, %ecx // if savemask != 0
75 jne _setjmp // setjmp(jmpbuf);
76 jmp L_do__setjmp // else _setjmp(jmpbuf);
79 subl $16, %esp // make space for return from sigprocmask
80 // + 12 to align stack
82 pushl $0 // set = NULL
83 pushl $1 // how = SIG_BLOCK
84 CALL_EXTERN(_sigprocmask)
85 movl 12(%esp),%eax // save the mask
86 addl $28, %esp // restore original esp
87 movl 4(%esp), %ecx // jmp_buf (struct sigcontext *)
88 movl %eax, JB_MASK(%ecx)
90 subl $20, %esp // temporary struct sigaltstack + 8 to
93 pushl $0 // ss == NULL
94 CALL_EXTERN(_sigaltstack) // get alternate signal stack info
95 movl 16(%esp), %eax // oss->ss_flags
96 addl $28, %esp // Restore %esp
97 movl %eax, JB_ONSTACK(%ecx)
100 BRANCH_EXTERN(__setjmp)
103 movl 4(%esp), %eax // sigjmp_buf * jmpbuf;
104 cmpl $0, JB_SAVEMASK(%eax) // if jmpbuf[_JBLEN] != 0
105 jne _longjmp // longjmp(jmpbuf, var);
106 jmp L_do__longjmp // else _longjmp(jmpbuf, var);
109 movl 4(%esp), %ecx // address of jmp_buf (saved context)
110 movl JB_MASK(%ecx),%eax // get the mask
111 subl $12, %esp // Make sure the stack is 16-byte
112 // aligned when we call sigprocmask
113 pushl %eax // store the mask
114 movl %esp, %edx // save the address where we stored the mask
115 pushl $0 // oset = NULL
117 pushl $3 // how = SIG_SETMASK
118 CALL_EXTERN_AGAIN(_sigprocmask)
119 addl $28, %esp // restore original esp
121 movl 4(%esp), %ecx // address of jmp_buf
122 movl JB_ONSTACK(%ecx), %eax // ss_flags
125 CALL_EXTERN(__sigunaltstack)
129 BRANCH_EXTERN(__longjmp) // else