Changed mono_win_chained_exception_needs_run to be a JIT TLS variable.
[mono.git] / mono / mini / exceptions-x86.c
index 7badd246e8977d2b6598e4fb3ef550cd96897ad4..0505633d1bcf17a15931be28beff90f6e43d4f5d 100644 (file)
@@ -47,7 +47,6 @@ static MonoW32ExceptionHandler segv_handler;
 
 LPTOP_LEVEL_EXCEPTION_FILTER mono_old_win_toplevel_exception_filter;
 gpointer mono_win_vectored_exception_handle;
-extern gboolean mono_win_chained_exception_needs_run;
 extern int (*gUnhandledExceptionHandler)(EXCEPTION_POINTERS*);
 
 #ifndef PROCESS_CALLBACK_FILTER_ENABLED
@@ -196,8 +195,9 @@ LONG CALLBACK seh_vectored_exception_handler(EXCEPTION_POINTERS* ep)
        CONTEXT* ctx;
        struct sigcontext* sctx;
        LONG res;
+       MonoJitTlsData *jit_tls = mono_native_tls_get_value (mono_jit_tls_id);
 
-       mono_win_chained_exception_needs_run = FALSE;
+       jit_tls->mono_win_chained_exception_needs_run = FALSE;
        res = EXCEPTION_CONTINUE_EXECUTION;
 
        er = ep->ExceptionRecord;
@@ -237,7 +237,7 @@ LONG CALLBACK seh_vectored_exception_handler(EXCEPTION_POINTERS* ep)
                break;
        }
 
-       if (mono_win_chained_exception_needs_run) {
+       if (jit_tls->mono_win_chained_exception_needs_run) {
                /* Don't copy context back if we chained exception
                * as the handler may have modfied the EXCEPTION_POINTERS
                * directly. We don't pass sigcontext to chained handlers.
@@ -343,8 +343,6 @@ mono_arch_get_restore_context (MonoTrampInfo **info, gboolean aot)
 
        /* load ESP into EBP */
        x86_mov_reg_membase (code, X86_EBP, X86_EAX,  G_STRUCT_OFFSET (MonoContext, esp), 4);
-       /* Align it, it can be unaligned if it was captured asynchronously */
-       x86_alu_reg_imm (code, X86_AND, X86_EBP, ~(MONO_ARCH_LOCALLOC_ALIGNMENT - 1));
        /* load return address into ECX */
        x86_mov_reg_membase (code, X86_ECX, X86_EAX,  G_STRUCT_OFFSET (MonoContext, eip), 4);
        /* save the return addr to the restored stack - 4 */
@@ -803,10 +801,7 @@ mono_arch_find_jit_info (MonoDomain *domain, MonoJitTlsData *jit_tls,
 
                frame->type = FRAME_TYPE_MANAGED;
 
-               if (ji->from_aot)
-                       unwind_info = mono_aot_get_unwind_info (ji, &unwind_info_len);
-               else
-                       unwind_info = mono_get_cached_unwind_info (ji->used_regs, &unwind_info_len);
+               unwind_info = mono_jinfo_get_unwind_info (ji, &unwind_info_len);
 
                regs [X86_EAX] = new_ctx->eax;
                regs [X86_EBX] = new_ctx->ebx;
@@ -854,14 +849,26 @@ mono_arch_find_jit_info (MonoDomain *domain, MonoJitTlsData *jit_tls,
                                *lmf = (gpointer)(((gsize)(*lmf)->previous_lmf) & ~3);
                }
 
+#ifndef MONO_X86_NO_PUSHES
                /* Pop arguments off the stack */
-               /* 
-                * FIXME: LLVM doesn't push these, we can't use ji->from_llvm as it describes
-                * the callee.
-                */
-#ifndef ENABLE_LLVM
-               if (ji->has_arch_eh_info)
-                       new_ctx->esp += mono_jit_info_get_arch_eh_info (ji)->stack_size;
+               if (ji->has_arch_eh_info) {
+                       int stack_size;
+
+                       stack_size = mono_jit_info_get_arch_eh_info (ji)->stack_size;
+
+                       if (stack_size) {
+#ifdef ENABLE_LLVM
+                               MonoJitInfo *caller_ji;
+
+                               caller_ji = mini_jit_info_table_find (domain, (char*)new_ctx->eip, NULL);
+                               /* LLVM doesn't push the arguments */
+                               if (caller_ji && !caller_ji->from_llvm)
+                                       new_ctx->esp += stack_size;
+#else
+                                       new_ctx->esp += stack_size;
+#endif
+                       }
+               }
 #endif
 
                return TRUE;