]>
Commit | Line | Data |
---|---|---|
8e029c65 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 | #include <SYS.h> | |
47 | ||
48 | #define JB_RBX 0 | |
49 | #define JB_RBP 8 | |
50 | #define JB_RSP 16 | |
51 | #define JB_R12 24 | |
52 | #define JB_R13 32 | |
53 | #define JB_R14 40 | |
54 | #define JB_R15 48 | |
55 | #define JB_RIP 56 | |
56 | #define JB_RFLAGS 64 | |
57 | #define JB_MXCSR 72 | |
58 | #define JB_FPCONTROL 76 | |
59 | #define JB_MASK 80 | |
60 | #define JB_SAVEMASK 84 // sigsetjmp/siglongjmp only | |
61 | ||
62 | ||
63 | LEAF(_sigsetjmp, 0) | |
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); | |
70 | ||
71 | LEAF(_setjmp, 0) | |
72 | pushq %rdi // Preserve the jmp_buf across the call | |
73 | movl $1, %edi // how = SIG_BLOCK | |
74 | xorq %rsi, %rsi // set = NULL | |
224c7076 A |
75 | subq $16, %rsp // Allocate space for the return from sigprocmask + 8 to align stack |
76 | movq %rsp, %rdx // oset = allocated space | |
8e029c65 A |
77 | CALL_EXTERN(_sigprocmask) |
78 | popq %rax // Save the mask | |
224c7076 | 79 | addq $8, %rsp // Restore the stack to before we align it |
8e029c65 A |
80 | popq %rdi // jmp_buf (struct sigcontext *) |
81 | movq %rax, JB_MASK(%rdi) | |
82 | L_do__setjmp: | |
83 | BRANCH_EXTERN(__setjmp) | |
84 | ||
85 | LEAF(_siglongjmp, 0) | |
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); | |
90 | ||
91 | LEAF(_longjmp, 0) | |
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 | |
224c7076 A |
97 | movq %rsp, %rsi // set = address where we stored the mask |
98 | xorq %rdx, %rdx // oset = NULL | |
8e029c65 A |
99 | CALL_EXTERN_AGAIN(_sigprocmask) |
100 | addq $8, %rsp | |
101 | popq %rsi // Restore the value | |
102 | popq %rdi // Restore the jmp_buf | |
103 | L_do__longjmp: | |
104 | BRANCH_EXTERN(__longjmp) // else | |
105 | END(_longjmp) |