]>
Commit | Line | Data |
---|---|---|
ada7c492 A |
1 | /* |
2 | * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. | |
3 | * | |
4 | * @APPLE_LICENSE_HEADER_START@ | |
5 | * | |
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 | |
11 | * file. | |
12 | * | |
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. | |
20 | * | |
21 | * @APPLE_LICENSE_HEADER_END@ | |
22 | */ | |
23 | /* | |
24 | * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved | |
25 | */ | |
26 | /* | |
27 | * NeXT 386 setjmp/longjmp | |
28 | * | |
29 | * Written by Bruce Martin, NeXT Inc. 4/9/92 | |
30 | */ | |
31 | ||
32 | /* | |
33 | * C library -- setjmp, longjmp | |
34 | * | |
35 | * longjmp(a,v) | |
36 | * will generate a "return(v)" from | |
37 | * the last call to | |
38 | * setjmp(a) | |
39 | * by restoring registers from the stack, | |
40 | * The previous value of the signal mask is | |
41 | * restored. | |
42 | * | |
43 | */ | |
44 | ||
45 | #include <architecture/i386/asm_help.h> | |
46 | ||
47 | #define JB_RBX 0 | |
48 | #define JB_RBP 8 | |
49 | #define JB_RSP 16 | |
50 | #define JB_R12 24 | |
51 | #define JB_R13 32 | |
52 | #define JB_R14 40 | |
53 | #define JB_R15 48 | |
54 | #define JB_RIP 56 | |
55 | #define JB_RFLAGS 64 | |
56 | #define JB_MXCSR 72 | |
57 | #define JB_FPCONTROL 76 | |
58 | #define JB_MASK 80 | |
59 | #define JB_SAVEMASK 84 // sigsetjmp/siglongjmp only | |
60 | #define JB_ONSTACK 88 | |
61 | ||
62 | #define STACK_SSFLAGS 16 // offsetof(stack_t, ss_flags) | |
63 | ||
64 | LEAF(_sigsetjmp, 0) | |
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); | |
71 | ||
72 | LEAF(_setjmp, 0) | |
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) | |
83 | ||
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 | |
93 | ||
94 | L_do__setjmp: | |
95 | BRANCH_EXTERN(__setjmp) | |
96 | ||
97 | LEAF(_siglongjmp, 0) | |
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); | |
102 | ||
103 | LEAF(_longjmp, 0) | |
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) | |
112 | ||
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 | |
118 | popq %rsi | |
119 | popq %rdi // Pass jmpbuf to _longjmp | |
120 | ||
121 | L_do__longjmp: | |
122 | BRANCH_EXTERN(__longjmp) // else | |
123 | END(_longjmp) |