128 | | |
129 | | #define CONTEXT_STATE (((struct ucontext64 *)context)->uc_mcontext64->ss) |
130 | | |
131 | | #define CONTEXT_PC (CONTEXT_STATE.srr0) |
132 | | #define CONTEXT_EXCEPTION_POINTER (CONTEXT_STATE.r29) |
133 | | #define CONTEXT_YOUNG_LIMIT (CONTEXT_STATE.r30) |
134 | | #define CONTEXT_YOUNG_PTR (CONTEXT_STATE.r31) |
135 | | #define CONTEXT_FAULTING_ADDRESS ((char *) info->si_addr) |
136 | | #define CONTEXT_SP (CONTEXT_STATE.r1) |
137 | | |
138 | | #else |
139 | | |
140 | | #include <sys/utsname.h> |
141 | | |
142 | | #define DECLARE_SIGNAL_HANDLER(name) \ |
143 | | static void name(int sig, siginfo_t * info, void * context) |
144 | | |
145 | | #define SET_SIGACT(sigact,name) \ |
146 | | sigact.sa_handler = (void (*)(int)) (name); \ |
147 | | sigact.sa_flags = SA_SIGINFO |
148 | | |
149 | | typedef unsigned long context_reg; |
150 | | |
151 | | #define CONTEXT_PC (*context_gpr_p(context, -2)) |
152 | | #define CONTEXT_EXCEPTION_POINTER (*context_gpr_p(context, 29)) |
153 | | #define CONTEXT_YOUNG_LIMIT (*context_gpr_p(context, 30)) |
154 | | #define CONTEXT_YOUNG_PTR (*context_gpr_p(context, 31)) |
155 | | #define CONTEXT_FAULTING_ADDRESS ((char *) info->si_addr) |
156 | | #define CONTEXT_SP (*context_gpr_p(context, 1)) |
157 | | |
158 | | static int ctx_version = 0; |
159 | | static void init_ctx (void) |
160 | | { |
161 | | struct utsname name; |
162 | | if (uname (&name) == 0){ |
163 | | if (name.release[1] == '.' && name.release[0] <= '5'){ |
164 | | ctx_version = 1; |
165 | | }else{ |
166 | | ctx_version = 2; |
167 | | } |
168 | | }else{ |
169 | | caml_fatal_error ("cannot determine SIGCONTEXT format"); |
170 | | } |
171 | | } |
172 | | |
173 | | #ifdef DARWIN_VERSION_6 |
174 | | #include <sys/ucontext.h> |
175 | | static unsigned long *context_gpr_p (void *ctx, int regno) |
176 | | { |
177 | | unsigned long *regs; |
178 | | if (ctx_version == 0) init_ctx (); |
179 | | if (ctx_version == 1){ |
180 | | /* old-style context (10.0 and 10.1) */ |
181 | | regs = (unsigned long *)(((struct sigcontext *)ctx)->sc_regs); |
182 | | }else{ |
183 | | Assert (ctx_version == 2); |
184 | | /* new-style context (10.2) */ |
185 | | regs = (unsigned long *)&(((struct ucontext *)ctx)->uc_mcontext->ss); |
186 | | } |
187 | | return &(regs[2 + regno]); |
188 | | } |
| 125 | |
| 126 | #ifdef __LP64__ |
| 127 | #define SET_SIGACT(sigact,name) \ |
| 128 | sigact.sa_sigaction = (name); \ |
| 129 | sigact.sa_flags = SA_SIGINFO | SA_64REGSET |
| 130 | |
| 131 | typedef unsigned long long context_reg; |
| 132 | |
| 133 | #define CONTEXT_MCONTEXT (((ucontext64_t *)context)->uc_mcontext64) |
190 | | #define SA_SIGINFO 0x0040 |
191 | | struct ucontext { |
192 | | int uc_onstack; |
193 | | sigset_t uc_sigmask; |
194 | | struct sigaltstack uc_stack; |
195 | | struct ucontext *uc_link; |
196 | | size_t uc_mcsize; |
197 | | unsigned long *uc_mcontext; |
198 | | }; |
199 | | static unsigned long *context_gpr_p (void *ctx, int regno) |
200 | | { |
201 | | unsigned long *regs; |
202 | | if (ctx_version == 0) init_ctx (); |
203 | | if (ctx_version == 1){ |
204 | | /* old-style context (10.0 and 10.1) */ |
205 | | regs = (unsigned long *)(((struct sigcontext *)ctx)->sc_regs); |
206 | | }else{ |
207 | | Assert (ctx_version == 2); |
208 | | /* new-style context (10.2) */ |
209 | | regs = (unsigned long *)((struct ucontext *)ctx)->uc_mcontext + 8; |
210 | | } |
211 | | return &(regs[2 + regno]); |
212 | | } |
| 135 | #define SET_SIGACT(sigact,name) \ |
| 136 | sigact.sa_sigaction = (name); \ |
| 137 | sigact.sa_flags = SA_SIGINFO |
| 138 | |
| 139 | typedef unsigned long context_reg; |
| 140 | |
| 141 | #define CONTEXT_MCONTEXT (((ucontext_t *)context)->uc_mcontext) |
214 | | |
215 | | #endif |
| 143 | |
| 144 | #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5 |
| 145 | #define CONTEXT_STATE (CONTEXT_MCONTEXT->ss) |
| 146 | #define CONTEXT_PC (CONTEXT_STATE.srr0) |
| 147 | #define CONTEXT_EXCEPTION_POINTER (CONTEXT_STATE.r29) |
| 148 | #define CONTEXT_YOUNG_LIMIT (CONTEXT_STATE.r30) |
| 149 | #define CONTEXT_YOUNG_PTR (CONTEXT_STATE.r31) |
| 150 | #define CONTEXT_SP (CONTEXT_STATE.r1) |
| 151 | #else |
| 152 | #define CONTEXT_STATE (CONTEXT_MCONTEXT->__ss) |
| 153 | #define CONTEXT_PC (CONTEXT_STATE.__srr0) |
| 154 | #define CONTEXT_EXCEPTION_POINTER (CONTEXT_STATE.__r29) |
| 155 | #define CONTEXT_YOUNG_LIMIT (CONTEXT_STATE.__r30) |
| 156 | #define CONTEXT_YOUNG_PTR (CONTEXT_STATE.__r31) |
| 157 | #define CONTEXT_SP (CONTEXT_STATE.__r1) |
| 158 | #endif |
| 159 | |
| 160 | #define CONTEXT_FAULTING_ADDRESS ((char *) info->si_addr) |