+
+static void
+handler_block_trampoline_helper (gpointer *ptr)
+{
+ MonoJitTlsData *jit_tls = mono_native_tls_get_value (mono_jit_tls_id);
+ *ptr = jit_tls->handler_block_return_address;
+}
+
+gpointer
+mono_arch_create_handler_block_trampoline (void)
+{
+ guint8 *tramp = mono_get_trampoline_code (MONO_TRAMPOLINE_HANDLER_BLOCK_GUARD);
+ guint8 *code, *buf;
+ int tramp_size = 64;
+ code = buf = mono_global_codeman_reserve (tramp_size);
+
+ /*
+ This trampoline restore the call chain of the handler block then jumps into the code that deals with it.
+ */
+
+ if (mono_get_jit_tls_offset () != -1) {
+ code = mono_x86_emit_tls_get (code, X86_EAX, mono_get_jit_tls_offset ());
+ x86_mov_reg_membase (code, X86_EAX, X86_EAX, G_STRUCT_OFFSET (MonoJitTlsData, handler_block_return_address), 4);
+ /*simulate a call*/
+ /*Fix stack alignment*/
+ x86_alu_reg_imm (code, X86_SUB, X86_ESP, 0x8);
+ x86_push_reg (code, X86_EAX);
+ x86_jump_code (code, tramp);
+ } else {
+ /*Slow path uses a c helper*/
+ x86_alu_reg_imm (code, X86_SUB, X86_ESP, 0x8);
+ x86_push_reg (code, X86_ESP);
+ x86_push_imm (code, tramp);
+ x86_jump_code (code, handler_block_trampoline_helper);
+ }
+
+ nacl_global_codeman_validate (&buf, tramp_size, &code);
+
+ mono_arch_flush_icache (buf, code - buf);
+ g_assert (code - buf <= tramp_size);
+
+ if (mono_jit_map_is_enabled ())
+ mono_emit_jit_tramp (buf, code - buf, "handler_block_trampoline");
+
+ return buf;
+}
+
+guint8*
+mono_arch_get_call_target (guint8 *code)
+{
+ if (code [-5] == 0xe8) {
+ guint32 disp = *(guint32*)(code - 4);
+ guint8 *target = code + disp;
+
+ return target;
+ } else {
+ return NULL;
+ }
+}
+
+guint32
+mono_arch_get_plt_info_offset (guint8 *plt_entry, mgreg_t *regs, guint8 *code)
+{
+ return *(guint32*)(plt_entry + NACL_SIZE (6, 12));
+}
+
+/*
+ * mono_arch_get_gsharedvt_arg_trampoline:
+ *
+ * Return a trampoline which passes ARG to the gsharedvt in/out trampoline ADDR.
+ */
+gpointer
+mono_arch_get_gsharedvt_arg_trampoline (MonoDomain *domain, gpointer arg, gpointer addr)
+{
+ guint8 *code, *start;
+ int buf_len;
+
+ buf_len = 10;
+
+ start = code = mono_domain_code_reserve (domain, buf_len);
+
+ x86_mov_reg_imm (code, X86_EAX, arg);
+ x86_jump_code (code, addr);
+ g_assert ((code - start) <= buf_len);
+
+ nacl_domain_code_validate (domain, &start, buf_len, &code);
+ mono_arch_flush_icache (start, code - start);
+
+ return start;
+}
+
+#if defined(MONOTOUCH) || defined(MONO_EXTENSIONS)
+
+#include "../../../mono-extensions/mono/mini/tramp-x86-gsharedvt.c"
+
+#else
+
+gpointer
+mono_arch_get_gsharedvt_trampoline (MonoTrampInfo **info, gboolean aot)
+{
+ if (info)
+ *info = NULL;
+ return NULL;
+}
+
+#endif /* !MONOTOUCH */