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