Small cleanup on runtime shutdown to move more code to the same spot and reduce dupli...
[mono.git] / mono / mini / tramp-x86.c
index 90b76fdbbe903619a9962f341b95ec6367553a30..83cdee58228d06aa7ebb79d80c97424309c4b58a 100644 (file)
@@ -125,7 +125,7 @@ mono_arch_patch_callsite (guint8 *method_start, guint8 *orig_code, guint8 *addr)
         */
        code -= 6;
        orig_code -= 6;
-       if ((code [1] == 0xe8)) {
+       if (code [1] == 0xe8) {
                if (can_write) {
                        InterlockedExchange ((gint32*)(orig_code + 2), (guint)addr - ((guint)orig_code + 1) - 5);
 
@@ -577,7 +577,7 @@ mono_arch_create_specific_trampoline (gpointer arg1, MonoTrampolineType tramp_ty
        x86_jump_code (buf, tramp);
        g_assert ((buf - code) <= TRAMPOLINE_SIZE);
 
-       nacl_domain_code_validate (domain, &code, kNaClAlignment, &buf);
+       nacl_domain_code_validate (domain, &code, NACL_SIZE (4, kNaClAlignment), &buf);
 
        mono_arch_flush_icache (code, buf - code);
 
@@ -688,6 +688,48 @@ mono_arch_create_rgctx_lazy_fetch_trampoline (guint32 slot, MonoTrampInfo **info
        return buf;
 }
 
+/*
+ * mono_arch_create_general_rgctx_lazy_fetch_trampoline:
+ *
+ *   This is a general variant of the rgctx fetch trampolines. It receives a pointer to gpointer[2] in the rgctx reg. The first entry contains the slot, the second
+ * the trampoline to call if the slot is not filled.
+ */
+gpointer
+mono_arch_create_general_rgctx_lazy_fetch_trampoline (MonoTrampInfo **info, gboolean aot)
+{
+       guint8 *code, *buf;
+       int tramp_size;
+       MonoJumpInfo *ji = NULL;
+       GSList *unwind_ops = NULL;
+
+       g_assert (aot);
+
+       unwind_ops = mono_arch_get_cie_program ();
+
+       tramp_size = 64;
+
+       code = buf = mono_global_codeman_reserve (tramp_size);
+
+       // FIXME: Currently, we always go to the slow path.
+       
+       /* Load trampoline addr */
+       x86_mov_reg_membase (code, X86_EAX, MONO_ARCH_RGCTX_REG, 4, 4);
+       /* Load mrgctx/vtable */
+       x86_mov_reg_membase (code, MONO_ARCH_VTABLE_REG, X86_ESP, 4, 4);
+
+       x86_jump_reg (code, X86_EAX);
+
+       nacl_global_codeman_validate (&buf, tramp_size, &code);
+       mono_arch_flush_icache (buf, code - buf);
+
+       g_assert (code - buf <= tramp_size);
+
+       if (info)
+               *info = mono_tramp_info_create ("rgctx_fetch_trampoline_general", buf, code - buf, ji, unwind_ops);
+
+       return buf;
+}
+
 gpointer
 mono_arch_create_generic_class_init_trampoline (MonoTrampInfo **info, gboolean aot)
 {
@@ -783,7 +825,7 @@ mono_arch_create_monitor_enter_trampoline (MonoTrampInfo **info, gboolean aot)
        owner_offset = MONO_THREADS_SYNC_MEMBER_OFFSET (owner_offset);
        nest_offset = MONO_THREADS_SYNC_MEMBER_OFFSET (nest_offset);
 
-       tramp_size = NACL_SIZE (64, 128);
+       tramp_size = NACL_SIZE (96, 128);
 
        code = buf = mono_global_codeman_reserve (tramp_size);
 
@@ -1040,7 +1082,7 @@ mono_arch_invalidate_method (MonoJitInfo *ji, void *func, gpointer func_arg)
 static void
 handler_block_trampoline_helper (gpointer *ptr)
 {
-       MonoJitTlsData *jit_tls = TlsGetValue (mono_jit_tls_id);
+       MonoJitTlsData *jit_tls = mono_native_tls_get_value (mono_jit_tls_id);
        *ptr = jit_tls->handler_block_return_address;
 }
 
@@ -1101,3 +1143,44 @@ 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 */