Merge pull request #4118 from petertiedemann/fix-bug-48516
[mono.git] / mono / mini / exceptions-arm64.c
1 /*
2  * exceptions-arm64.c: exception support for ARM64
3  *
4  * Copyright 2013 Xamarin Inc
5  *
6  * Based on exceptions-arm.c:
7  *
8  * Authors:
9  *   Dietmar Maurer (dietmar@ximian.com)
10  *   Paolo Molaro (lupus@ximian.com)
11  *
12  * (C) 2001 Ximian, Inc.
13  * Licensed under the MIT license. See LICENSE file in the project root for full license information.
14  */
15
16 #include "mini.h"
17
18 #include <mono/arch/arm64/arm64-codegen.h>
19 #include <mono/metadata/abi-details.h>
20
21 #define ALIGN_TO(val,align) ((((guint64)val) + ((align) - 1)) & ~((align) - 1))
22
23 #ifndef DISABLE_JIT
24
25 gpointer
26 mono_arch_get_restore_context (MonoTrampInfo **info, gboolean aot)
27 {
28         guint8 *start, *code;
29         MonoJumpInfo *ji = NULL;
30         GSList *unwind_ops = NULL;
31         int i, ctx_reg, size;
32         guint8 *labels [16];
33
34         size = 256;
35         code = start = mono_global_codeman_reserve (size);
36
37         arm_movx (code, ARMREG_IP0, ARMREG_R0);
38         ctx_reg = ARMREG_IP0;
39
40         /* Restore fregs */
41         arm_ldrx (code, ARMREG_IP1, ctx_reg, MONO_STRUCT_OFFSET (MonoContext, has_fregs));
42         labels [0] = code;
43         arm_cbzx (code, ARMREG_IP1, 0);
44         for (i = 0; i < 32; ++i)
45                 arm_ldrfpx (code, i, ctx_reg, MONO_STRUCT_OFFSET (MonoContext, fregs) + (i * 8));
46         mono_arm_patch (labels [0], code, MONO_R_ARM64_CBZ);
47         /* Restore gregs */
48         // FIXME: Restore less registers
49         // FIXME: fp should be restored later
50         code = mono_arm_emit_load_regarray (code, 0xffffffff & ~(1 << ctx_reg) & ~(1 << ARMREG_SP), ctx_reg, MONO_STRUCT_OFFSET (MonoContext, regs));
51         /* ip0/ip1 doesn't need to be restored */
52         /* ip1 = pc */
53         arm_ldrx (code, ARMREG_IP1, ctx_reg, MONO_STRUCT_OFFSET (MonoContext, pc));
54         /* ip0 = sp */
55         arm_ldrx (code, ARMREG_IP0, ctx_reg, MONO_STRUCT_OFFSET (MonoContext, regs) + (ARMREG_SP * 8));
56         /* Restore sp, ctx is no longer valid */
57         arm_movspx (code, ARMREG_SP, ARMREG_IP0); 
58         /* Branch to pc */
59         arm_brx (code, ARMREG_IP1);
60         /* Not reached */
61         arm_brk (code, 0);
62
63         g_assert ((code - start) < size);
64         mono_arch_flush_icache (start, code - start);
65         mono_profiler_code_buffer_new (start, code - start, MONO_PROFILER_CODE_BUFFER_EXCEPTION_HANDLING, NULL);
66
67         if (info)
68                 *info = mono_tramp_info_create ("restore_context", start, code - start, ji, unwind_ops);
69
70         return start;
71 }
72
73 gpointer
74 mono_arch_get_call_filter (MonoTrampInfo **info, gboolean aot)
75 {
76         guint8 *code;
77         guint8* start;
78         int i, size, offset, gregs_offset, fregs_offset, ctx_offset, num_fregs, frame_size;
79         MonoJumpInfo *ji = NULL;
80         GSList *unwind_ops = NULL;
81         guint8 *labels [16];
82
83         size = 512;
84         start = code = mono_global_codeman_reserve (size);
85
86         /* Compute stack frame size and offsets */
87         offset = 0;
88         /* frame block */
89         offset += 2 * 8;
90         /* gregs */
91         gregs_offset = offset;
92         offset += 32 * 8;
93         /* fregs */
94         num_fregs = 8;
95         fregs_offset = offset;
96         offset += num_fregs * 8;
97         ctx_offset = offset;
98         ctx_offset += 8;
99         frame_size = ALIGN_TO (offset, MONO_ARCH_FRAME_ALIGNMENT);
100
101         /*
102          * We are being called from C code, ctx is in r0, the address to call is in r1.
103          * We need to save state, restore ctx, make the call, then restore the previous state,
104          * returning the value returned by the call.
105          */
106
107         /* Setup a frame */
108         arm_stpx_pre (code, ARMREG_FP, ARMREG_LR, ARMREG_SP, -frame_size);
109         arm_movspx (code, ARMREG_FP, ARMREG_SP);
110
111         /* Save ctx */
112         arm_strx (code, ARMREG_R0, ARMREG_FP, ctx_offset);
113         /* Save gregs */
114         code = mono_arm_emit_store_regarray (code, MONO_ARCH_CALLEE_SAVED_REGS | (1 << ARMREG_FP), ARMREG_FP, gregs_offset);
115         /* Save fregs */
116         for (i = 0; i < num_fregs; ++i)
117                 arm_strfpx (code, ARMREG_D8 + i, ARMREG_FP, fregs_offset + (i * 8));
118
119         /* Load regs from ctx */
120         code = mono_arm_emit_load_regarray (code, MONO_ARCH_CALLEE_SAVED_REGS, ARMREG_R0, MONO_STRUCT_OFFSET (MonoContext, regs));
121         /* Load fregs */
122         arm_ldrx (code, ARMREG_IP0, ARMREG_R0, MONO_STRUCT_OFFSET (MonoContext, has_fregs));
123         labels [0] = code;
124         arm_cbzx (code, ARMREG_IP0, 0);
125         for (i = 0; i < num_fregs; ++i)
126                 arm_ldrfpx (code, ARMREG_D8 + i, ARMREG_R0, MONO_STRUCT_OFFSET (MonoContext, fregs) + (i * 8));
127         mono_arm_patch (labels [0], code, MONO_R_ARM64_CBZ);
128         /* Load fp */
129         arm_ldrx (code, ARMREG_FP, ARMREG_R0, MONO_STRUCT_OFFSET (MonoContext, regs) + (ARMREG_FP * 8));
130
131         /* Make the call */
132         arm_blrx (code, ARMREG_R1);
133         /* For filters, the result is in R0 */
134
135         /* Restore fp */
136         arm_ldrx (code, ARMREG_FP, ARMREG_SP, gregs_offset + (ARMREG_FP * 8));
137         /* Load ctx */
138         arm_ldrx (code, ARMREG_IP0, ARMREG_FP, ctx_offset);
139         /* Save registers back to ctx */
140         /* This isn't strictly neccessary since we don't allocate variables used in eh clauses to registers */
141         code = mono_arm_emit_store_regarray (code, MONO_ARCH_CALLEE_SAVED_REGS, ARMREG_IP0, MONO_STRUCT_OFFSET (MonoContext, regs));
142
143         /* Restore regs */
144         code = mono_arm_emit_load_regarray (code, MONO_ARCH_CALLEE_SAVED_REGS, ARMREG_FP, gregs_offset);
145         /* Restore fregs */
146         for (i = 0; i < num_fregs; ++i)
147                 arm_ldrfpx (code, ARMREG_D8 + i, ARMREG_FP, fregs_offset + (i * 8));
148         /* Destroy frame */
149         code = mono_arm_emit_destroy_frame (code, frame_size, (1 << ARMREG_IP0));
150         arm_retx (code, ARMREG_LR);
151
152         g_assert ((code - start) < size);
153         mono_arch_flush_icache (start, code - start);
154         mono_profiler_code_buffer_new (start, code - start, MONO_PROFILER_CODE_BUFFER_EXCEPTION_HANDLING, NULL);
155
156         if (info)
157                 *info = mono_tramp_info_create ("call_filter", start, code - start, ji, unwind_ops);
158
159         return start;
160 }
161
162 static gpointer 
163 get_throw_trampoline (int size, gboolean corlib, gboolean rethrow, gboolean llvm, gboolean resume_unwind, const char *tramp_name, MonoTrampInfo **info, gboolean aot)
164 {
165         guint8 *start, *code;
166         MonoJumpInfo *ji = NULL;
167         GSList *unwind_ops = NULL;
168         int i, offset, gregs_offset, fregs_offset, frame_size, num_fregs;
169
170         code = start = mono_global_codeman_reserve (size);
171
172         /* We are being called by JITted code, the exception object/type token is in R0 */
173
174         /* Compute stack frame size and offsets */
175         offset = 0;
176         /* frame block */
177         offset += 2 * 8;
178         /* gregs */
179         gregs_offset = offset;
180         offset += 32 * 8;
181         /* fregs */
182         num_fregs = 8;
183         fregs_offset = offset;
184         offset += num_fregs * 8;
185         frame_size = ALIGN_TO (offset, MONO_ARCH_FRAME_ALIGNMENT);
186
187         /* Setup a frame */
188         arm_stpx_pre (code, ARMREG_FP, ARMREG_LR, ARMREG_SP, -frame_size);
189         arm_movspx (code, ARMREG_FP, ARMREG_SP);
190
191         /* Save gregs */
192         code = mono_arm_emit_store_regarray (code, 0xffffffff, ARMREG_FP, gregs_offset);
193         if (corlib && !llvm)
194                 /* The real LR is in R1 */
195                 arm_strx (code, ARMREG_R1, ARMREG_FP, gregs_offset + (ARMREG_LR * 8));
196         /* Save fp/sp */
197         arm_ldrx (code, ARMREG_IP0, ARMREG_FP, 0);
198         arm_strx (code, ARMREG_IP0, ARMREG_FP, gregs_offset + (ARMREG_FP * 8));
199         arm_addx_imm (code, ARMREG_IP0, ARMREG_FP, frame_size);
200         arm_strx (code, ARMREG_IP0, ARMREG_FP, gregs_offset + (ARMREG_SP * 8)); 
201         /* Save fregs */
202         for (i = 0; i < num_fregs; ++i)
203                 arm_strfpx (code, ARMREG_D8 + i, ARMREG_FP, fregs_offset + (i * 8));
204
205         /* Call the C trampoline function */
206         /* Arg1 =  exception object/type token */
207         arm_movx (code, ARMREG_R0, ARMREG_R0);
208         /* Arg2 = caller ip */
209         if (corlib) {
210                 if (llvm)
211                         arm_ldrx (code, ARMREG_R1, ARMREG_FP, gregs_offset + (ARMREG_LR * 8));
212                 else
213                         arm_movx (code, ARMREG_R1, ARMREG_R1);
214         } else {
215                 arm_ldrx (code, ARMREG_R1, ARMREG_FP, 8);
216         }
217         /* Arg 3 = gregs */
218         arm_addx_imm (code, ARMREG_R2, ARMREG_FP, gregs_offset);
219         /* Arg 4 = fregs */
220         arm_addx_imm (code, ARMREG_R3, ARMREG_FP, fregs_offset);
221         /* Arg 5 = corlib */
222         arm_movzx (code, ARMREG_R4, corlib ? 1 : 0, 0);
223         /* Arg 6 = rethrow */
224         arm_movzx (code, ARMREG_R5, rethrow ? 1 : 0, 0);
225         /* Call the function */
226         if (aot) {
227                 const char *icall_name;
228
229                 if (resume_unwind)
230                         icall_name = "mono_arm_resume_unwind";
231                 else
232                         icall_name = "mono_arm_throw_exception";
233
234                 code = mono_arm_emit_aotconst (&ji, code, start, ARMREG_LR, MONO_PATCH_INFO_JIT_ICALL_ADDR, icall_name);
235         } else {
236                 gpointer icall_func;
237
238                 if (resume_unwind)
239                         icall_func = mono_arm_resume_unwind;
240                 else
241                         icall_func = mono_arm_throw_exception;
242
243                 code = mono_arm_emit_imm64 (code, ARMREG_LR, (guint64)icall_func);
244         }
245         arm_blrx (code, ARMREG_LR);
246         /* This shouldn't return */
247         arm_brk (code, 0x0);
248
249         g_assert ((code - start) < size);
250         mono_arch_flush_icache (start, code - start);
251         mono_profiler_code_buffer_new (start, code - start, MONO_PROFILER_CODE_BUFFER_EXCEPTION_HANDLING, NULL);
252
253         if (info)
254                 *info = mono_tramp_info_create (tramp_name, start, code - start, ji, unwind_ops);
255
256         return start;
257 }
258
259 gpointer 
260 mono_arch_get_throw_exception (MonoTrampInfo **info, gboolean aot)
261 {
262         return get_throw_trampoline (256, FALSE, FALSE, FALSE, FALSE, "throw_exception", info, aot);
263 }
264
265 gpointer
266 mono_arch_get_rethrow_exception (MonoTrampInfo **info, gboolean aot)
267 {
268         return get_throw_trampoline (256, FALSE, TRUE, FALSE, FALSE, "rethrow_exception", info, aot);
269 }
270
271 gpointer 
272 mono_arch_get_throw_corlib_exception (MonoTrampInfo **info, gboolean aot)
273 {
274         return get_throw_trampoline (256, TRUE, FALSE, FALSE, FALSE, "throw_corlib_exception", info, aot);
275 }
276
277 GSList*
278 mono_arm_get_exception_trampolines (gboolean aot)
279 {
280         MonoTrampInfo *info;
281         GSList *tramps = NULL;
282
283         /* LLVM uses the normal trampolines, but with a different name */
284         get_throw_trampoline (256, TRUE, FALSE, FALSE, FALSE, "llvm_throw_corlib_exception_trampoline", &info, aot);
285         tramps = g_slist_prepend (tramps, info);
286         
287         get_throw_trampoline (256, TRUE, FALSE, TRUE, FALSE, "llvm_throw_corlib_exception_abs_trampoline", &info, aot);
288         tramps = g_slist_prepend (tramps, info);
289
290         get_throw_trampoline (256, FALSE, FALSE, FALSE, TRUE, "llvm_resume_unwind_trampoline", &info, aot);
291         tramps = g_slist_prepend (tramps, info);
292
293         return tramps;
294 }
295
296 #else /* DISABLE_JIT */
297
298 gpointer
299 mono_arch_get_restore_context (MonoTrampInfo **info, gboolean aot)
300 {
301         g_assert_not_reached ();
302         return NULL;
303 }
304
305 gpointer
306 mono_arch_get_call_filter (MonoTrampInfo **info, gboolean aot)
307 {
308         g_assert_not_reached ();
309         return NULL;
310 }
311
312 gpointer 
313 mono_arch_get_throw_exception (MonoTrampInfo **info, gboolean aot)
314 {
315         g_assert_not_reached ();
316         return NULL;
317 }
318
319 gpointer
320 mono_arch_get_rethrow_exception (MonoTrampInfo **info, gboolean aot)
321 {
322         g_assert_not_reached ();
323         return NULL;
324 }
325
326 gpointer 
327 mono_arch_get_throw_corlib_exception (MonoTrampInfo **info, gboolean aot)
328 {
329         g_assert_not_reached ();
330         return NULL;
331 }       
332
333 GSList*
334 mono_arm_get_exception_trampolines (gboolean aot)
335 {
336         g_assert_not_reached ();
337         return NULL;
338 }
339
340 #endif /* !DISABLE_JIT */
341
342 void
343 mono_arch_exceptions_init (void)
344 {
345         guint8 *tramp;
346         GSList *tramps, *l;
347
348         if (mono_aot_only) {
349                 tramp = mono_aot_get_trampoline ("llvm_throw_corlib_exception_trampoline");
350                 mono_register_jit_icall (tramp, "llvm_throw_corlib_exception_trampoline", NULL, TRUE);
351                 tramp = mono_aot_get_trampoline ("llvm_throw_corlib_exception_abs_trampoline");
352                 mono_register_jit_icall (tramp, "llvm_throw_corlib_exception_abs_trampoline", NULL, TRUE);
353                 tramp = mono_aot_get_trampoline ("llvm_resume_unwind_trampoline");
354                 mono_register_jit_icall (tramp, "llvm_resume_unwind_trampoline", NULL, TRUE);
355         } else {
356                 tramps = mono_arm_get_exception_trampolines (FALSE);
357                 for (l = tramps; l; l = l->next) {
358                         MonoTrampInfo *info = l->data;
359
360                         mono_register_jit_icall (info->code, g_strdup (info->name), NULL, TRUE);
361                         mono_tramp_info_register (info, NULL);
362                 }
363                 g_slist_free (tramps);
364         }
365 }
366
367 /*
368  * mono_arm_throw_exception:
369  *
370  *   This function is called by the exception trampolines.
371  * FP_REGS points to the 8 callee saved fp regs.
372  */
373 void
374 mono_arm_throw_exception (gpointer arg, mgreg_t pc, mgreg_t *int_regs, gdouble *fp_regs, gboolean corlib, gboolean rethrow)
375 {
376         MonoError error;
377         MonoContext ctx;
378         MonoObject *exc = NULL;
379         guint32 ex_token_index, ex_token;
380
381         if (!corlib)
382                 exc = arg;
383         else {
384                 ex_token_index = (guint64)arg;
385                 ex_token = MONO_TOKEN_TYPE_DEF | ex_token_index;
386                 exc = (MonoObject*)mono_exception_from_token (mono_defaults.corlib, ex_token);
387         }
388
389         /* Adjust pc so it points into the call instruction */
390         pc -= 4;
391
392         /* Initialize a ctx based on the arguments */
393         memset (&ctx, 0, sizeof (MonoContext));
394         memcpy (&(ctx.regs [0]), int_regs, sizeof (mgreg_t) * 32);
395         memcpy (&(ctx.fregs [ARMREG_D8]), fp_regs, sizeof (double) * 8);
396         ctx.has_fregs = 1;
397         ctx.pc = pc;
398
399         if (mono_object_isinst_checked (exc, mono_defaults.exception_class, &error)) {
400                 MonoException *mono_ex = (MonoException*)exc;
401                 if (!rethrow) {
402                         mono_ex->stack_trace = NULL;
403                         mono_ex->trace_ips = NULL;
404                 }
405         }
406         mono_error_assert_ok (&error);
407
408         mono_handle_exception (&ctx, exc);
409
410         mono_restore_context (&ctx);
411 }
412
413 void
414 mono_arm_resume_unwind (gpointer arg, mgreg_t pc, mgreg_t *int_regs, gdouble *fp_regs, gboolean corlib, gboolean rethrow)
415 {
416         MonoContext ctx;
417
418         /* Adjust pc so it points into the call instruction */
419         pc -= 4;
420
421         /* Initialize a ctx based on the arguments */
422         memset (&ctx, 0, sizeof (MonoContext));
423         memcpy (&(ctx.regs [0]), int_regs, sizeof (mgreg_t) * 32);
424         memcpy (&(ctx.fregs [ARMREG_D8]), fp_regs, sizeof (double) * 8);
425         ctx.has_fregs = 1;
426         ctx.pc = pc;
427
428         mono_resume_unwind (&ctx);
429 }
430
431 /* 
432  * mono_arch_unwind_frame:
433  *
434  * See exceptions-amd64.c for docs;
435  */
436 gboolean
437 mono_arch_unwind_frame (MonoDomain *domain, MonoJitTlsData *jit_tls, 
438                                                          MonoJitInfo *ji, MonoContext *ctx, 
439                                                          MonoContext *new_ctx, MonoLMF **lmf,
440                                                          mgreg_t **save_locations,
441                                                          StackFrameInfo *frame)
442 {
443         gpointer ip = MONO_CONTEXT_GET_IP (ctx);
444
445         memset (frame, 0, sizeof (StackFrameInfo));
446         frame->ji = ji;
447
448         *new_ctx = *ctx;
449
450         if (ji != NULL) {
451                 mgreg_t regs [MONO_MAX_IREGS + 8 + 1];
452                 guint8 *cfa;
453                 guint32 unwind_info_len;
454                 guint8 *unwind_info;
455
456                 frame->type = FRAME_TYPE_MANAGED;
457
458                 unwind_info = mono_jinfo_get_unwind_info (ji, &unwind_info_len);
459
460                 memcpy (regs, &new_ctx->regs, sizeof (mgreg_t) * 32);
461                 /* v8..v15 are callee saved */
462                 memcpy (regs + MONO_MAX_IREGS, &(new_ctx->fregs [8]), sizeof (mgreg_t) * 8);
463
464                 mono_unwind_frame (unwind_info, unwind_info_len, ji->code_start, 
465                                                    (guint8*)ji->code_start + ji->code_size,
466                                                    ip, NULL, regs, MONO_MAX_IREGS + 8,
467                                                    save_locations, MONO_MAX_IREGS, &cfa);
468
469                 memcpy (&new_ctx->regs, regs, sizeof (mgreg_t) * 32);
470                 memcpy (&(new_ctx->fregs [8]), regs + MONO_MAX_IREGS, sizeof (mgreg_t) * 8);
471
472                 new_ctx->pc = regs [ARMREG_LR];
473                 new_ctx->regs [ARMREG_SP] = (mgreg_t)cfa;
474
475                 if (*lmf && (*lmf)->gregs [MONO_ARCH_LMF_REG_SP] && (MONO_CONTEXT_GET_SP (ctx) >= (gpointer)(*lmf)->gregs [MONO_ARCH_LMF_REG_SP])) {
476                         /* remove any unused lmf */
477                         *lmf = (gpointer)(((gsize)(*lmf)->previous_lmf) & ~3);
478                 }
479
480                 /* we substract 1, so that the IP points into the call instruction */
481                 new_ctx->pc--;
482
483                 return TRUE;
484         } else if (*lmf) {
485                 if (((gsize)(*lmf)->previous_lmf) & 2) {
486                         /* 
487                          * This LMF entry is created by the soft debug code to mark transitions to
488                          * managed code done during invokes.
489                          */
490                         MonoLMFExt *ext = (MonoLMFExt*)(*lmf);
491
492                         g_assert (ext->debugger_invoke);
493
494                         memcpy (new_ctx, &ext->ctx, sizeof (MonoContext));
495
496                         *lmf = (gpointer)(((gsize)(*lmf)->previous_lmf) & ~3);
497
498                         frame->type = FRAME_TYPE_DEBUGGER_INVOKE;
499
500                         return TRUE;
501                 }
502
503                 frame->type = FRAME_TYPE_MANAGED_TO_NATIVE;
504
505                 ji = mini_jit_info_table_find (domain, (gpointer)(*lmf)->pc, NULL);
506                 if (!ji)
507                         return FALSE;
508
509                 g_assert (MONO_ARCH_LMF_REGS == ((0x3ff << 19) | (1 << ARMREG_FP) | (1 << ARMREG_SP)));
510                 memcpy (&new_ctx->regs [ARMREG_R19], &(*lmf)->gregs [0], sizeof (mgreg_t) * 10);
511                 new_ctx->regs [ARMREG_FP] = (*lmf)->gregs [MONO_ARCH_LMF_REG_FP];
512                 new_ctx->regs [ARMREG_SP] = (*lmf)->gregs [MONO_ARCH_LMF_REG_SP];
513                 new_ctx->pc = (*lmf)->pc;
514
515                 /* we substract 1, so that the IP points into the call instruction */
516                 new_ctx->pc--;
517
518                 *lmf = (gpointer)(((gsize)(*lmf)->previous_lmf) & ~3);
519
520                 return TRUE;
521         }
522
523         return FALSE;
524 }
525
526 /*
527  * handle_exception:
528  *
529  *   Called by resuming from a signal handler.
530  */
531 static void
532 handle_signal_exception (gpointer obj)
533 {
534         MonoJitTlsData *jit_tls = mono_tls_get_jit_tls ();
535         MonoContext ctx;
536
537         memcpy (&ctx, &jit_tls->ex_ctx, sizeof (MonoContext));
538
539         mono_handle_exception (&ctx, obj);
540
541         mono_restore_context (&ctx);
542 }
543
544 /*
545  * This is the function called from the signal handler
546  */
547 gboolean
548 mono_arch_handle_exception (void *ctx, gpointer obj)
549 {
550 #if defined(MONO_CROSS_COMPILE)
551         g_assert_not_reached ();
552 #else
553         MonoJitTlsData *jit_tls;
554         void *sigctx = ctx;
555
556         /*
557          * Resume into the normal stack and handle the exception there.
558          */
559         jit_tls = mono_tls_get_jit_tls ();
560
561         /* Pass the ctx parameter in TLS */
562         mono_sigctx_to_monoctx (sigctx, &jit_tls->ex_ctx);
563         /* The others in registers */
564         UCONTEXT_REG_R0 (sigctx) = (gsize)obj;
565
566         UCONTEXT_REG_PC (sigctx) = (gsize)handle_signal_exception;
567         UCONTEXT_REG_SP (sigctx) = UCONTEXT_REG_SP (sigctx) - MONO_ARCH_REDZONE_SIZE;
568 #endif
569
570         return TRUE;
571 }
572
573 gpointer
574 mono_arch_ip_from_context (void *sigctx)
575 {
576 #ifdef MONO_CROSS_COMPILE
577         g_assert_not_reached ();
578         return NULL;
579 #else
580         return (gpointer)UCONTEXT_REG_PC (sigctx);
581 #endif
582 }
583
584 void
585 mono_arch_setup_async_callback (MonoContext *ctx, void (*async_cb)(void *fun), gpointer user_data)
586 {
587         mgreg_t sp = (mgreg_t)MONO_CONTEXT_GET_SP (ctx);
588
589         // FIXME:
590         g_assert (!user_data);
591
592         /* Allocate a stack frame */
593         sp -= 32;
594         MONO_CONTEXT_SET_SP (ctx, sp);
595
596         mono_arch_setup_resume_sighandler_ctx (ctx, async_cb);
597 }
598
599 /*
600  * mono_arch_setup_resume_sighandler_ctx:
601  *
602  *   Setup CTX so execution continues at FUNC.
603  */
604 void
605 mono_arch_setup_resume_sighandler_ctx (MonoContext *ctx, gpointer func)
606 {
607         MONO_CONTEXT_SET_IP (ctx,func);
608 }