2 * exceptions-ia64.c: exception support for IA64
5 * Zoltan Varga (vargaz@gmail.com)
7 * (C) 2001 Ximian, Inc.
14 #include <sys/ucontext.h>
16 #include <mono/arch/ia64/ia64-codegen.h>
17 #include <mono/metadata/appdomain.h>
18 #include <mono/metadata/tabledefs.h>
19 #include <mono/metadata/threads.h>
20 #include <mono/metadata/debug-helpers.h>
21 #include <mono/metadata/exception.h>
22 #include <mono/metadata/gc-internal.h>
23 #include <mono/metadata/mono-debug.h>
26 #include "mini-ia64.h"
28 #define ALIGN_TO(val,align) (((val) + ((align) - 1)) & ~((align) - 1))
30 #define NOT_IMPLEMENTED g_assert_not_reached ()
33 * mono_arch_get_restore_context:
35 * Returns a pointer to a method which restores a previously saved sigcontext.
38 mono_arch_get_restore_context (void)
40 static guint8 *start = NULL;
41 static gboolean inited = FALSE;
42 Ia64CodegenState code;
47 /* restore_contect (MonoContext *ctx) */
49 start = mono_global_codeman_reserve (256);
52 ia64_codegen_init (code, start);
53 ia64_break_i (code, 0);
54 ia64_codegen_close (code);
56 g_assert ((code.buf - start) <= 256);
58 mono_arch_flush_icache (start, code.buf - start);
64 * mono_arch_get_call_filter:
66 * Returns a pointer to a method which calls an exception filter. We
67 * also use this function to call finally handlers (we pass NULL as
68 * @exc object in this case).
71 mono_arch_get_call_filter (void)
74 static gboolean inited = FALSE;
77 Ia64CodegenState code;
85 start = mono_global_codeman_reserve (256);
87 /* call_filter (MonoContext *ctx, unsigned long eip) */
90 ia64_codegen_init (code, start);
91 ia64_break_i (code, 0);
92 ia64_codegen_close (code);
94 g_assert ((code.buf - start) <= 256);
96 mono_arch_flush_icache (start, code.buf - start);
102 throw_exception (MonoObject *exc, guint64 rip, guint64 rsp,
103 guint64 rbx, guint64 rbp, guint64 r12, guint64 r13,
104 guint64 r14, guint64 r15, guint64 rethrow)
106 static void (*restore_context) (MonoContext *);
109 if (!restore_context)
110 restore_context = mono_arch_get_restore_context ();
116 get_throw_trampoline (gboolean rethrow)
119 Ia64CodegenState code;
121 start = mono_global_codeman_reserve (64);
124 ia64_codegen_init (code, start);
125 ia64_break_i (code, 0);
126 ia64_codegen_close (code);
128 g_assert ((code.buf - start) <= 256);
130 mono_arch_flush_icache (start, code.buf - start);
136 * mono_arch_get_throw_exception:
138 * Returns a function pointer which can be used to raise
139 * exceptions. The returned function has the following
140 * signature: void (*func) (MonoException *exc);
144 mono_arch_get_throw_exception (void)
146 static guint8* start;
147 static gboolean inited = FALSE;
152 start = get_throw_trampoline (FALSE);
160 mono_arch_get_rethrow_exception (void)
162 static guint8* start;
163 static gboolean inited = FALSE;
168 start = get_throw_trampoline (TRUE);
176 mono_arch_get_throw_exception_by_name (void)
178 static gboolean inited = FALSE;
180 Ia64CodegenState code;
182 start = mono_global_codeman_reserve (64);
184 /* Not used on ia64 */
185 ia64_codegen_init (code, start);
186 ia64_break_i (code, 0);
187 ia64_codegen_close (code);
189 g_assert ((code.buf - start) <= 256);
191 mono_arch_flush_icache (start, code.buf - start);
197 * mono_arch_get_throw_corlib_exception:
199 * Returns a function pointer which can be used to raise
200 * corlib exceptions. The returned function has the following
201 * signature: void (*func) (guint32 ex_token, guint32 offset);
202 * Here, offset is the offset which needs to be substracted from the caller IP
203 * to get the IP of the throw. Passing the offset has the advantage that it
204 * needs no relocations in the caller.
207 mono_arch_get_throw_corlib_exception (void)
209 static guint8* start;
210 static gboolean inited = FALSE;
212 Ia64CodegenState code;
217 start = mono_global_codeman_reserve (64);
220 ia64_codegen_init (code, start);
221 ia64_break_i (code, 0);
222 ia64_codegen_close (code);
224 g_assert ((code.buf - start) <= 256);
226 mono_arch_flush_icache (start, code.buf - start);
231 /* mono_arch_find_jit_info:
233 * This function is used to gather information from @ctx. It return the
234 * MonoJitInfo of the corresponding function, unwinds one stack frame and
235 * stores the resulting context into @new_ctx. It also stores a string
236 * describing the stack location into @trace (if not NULL), and modifies
237 * the @lmf if necessary. @native_offset return the IP offset from the
238 * start of the function or -1 if that info is not available.
241 mono_arch_find_jit_info (MonoDomain *domain, MonoJitTlsData *jit_tls, MonoJitInfo *res, MonoJitInfo *prev_ji, MonoContext *ctx,
242 MonoContext *new_ctx, char **trace, MonoLMF **lmf, int *native_offset,
247 gpointer ip = MONO_CONTEXT_GET_IP (ctx);
254 * mono_arch_handle_exception:
256 * @ctx: saved processor state
257 * @obj: the exception object
260 mono_arch_handle_exception (void *sigctx, gpointer obj, gboolean test_only)
262 ucontext_t *ctx = (ucontext_t*)sigctx;
270 mono_arch_ip_from_context (void *sigctx)