Don't use System.Environment.Exit to finish a sdb session on iOS.
[mono.git] / mono / mini / mini-x86.c
index 9e88e026d8ffd90dae21281360dd57a21f6ac06d..f562ea7f5ad924c8a10714f185c3227ccc5e1020 100644 (file)
@@ -582,7 +582,7 @@ get_call_info (MonoGenericSharingContext *gsctx, MonoMemPool *mp, MonoMethodSign
  * FIXME: The metadata calls might not be signal safe.
  */
 int
-mono_arch_get_argument_info (MonoMethodSignature *csig, int param_count, MonoJitArgumentInfo *arg_info)
+mono_arch_get_argument_info (MonoGenericSharingContext *gsctx, MonoMethodSignature *csig, int param_count, MonoJitArgumentInfo *arg_info)
 {
        int len, k, args_size = 0;
        int size, pad;
@@ -595,7 +595,7 @@ mono_arch_get_argument_info (MonoMethodSignature *csig, int param_count, MonoJit
        cinfo = (CallInfo*)g_newa (guint8*, len);
        memset (cinfo, 0, len);
 
-       cinfo = get_call_info_internal (NULL, cinfo, csig);
+       cinfo = get_call_info_internal (gsctx, cinfo, csig);
 
        arg_info [0].offset = offset;
 
@@ -801,6 +801,10 @@ mono_arch_init (void)
 void
 mono_arch_cleanup (void)
 {
+       if (ss_trigger_page)
+               mono_vfree (ss_trigger_page, mono_pagesize ());
+       if (bp_trigger_page)
+               mono_vfree (bp_trigger_page, mono_pagesize ());
        DeleteCriticalSection (&mini_arch_mutex);
 }
 
@@ -808,7 +812,7 @@ mono_arch_cleanup (void)
  * This function returns the optimizations supported on this cpu.
  */
 guint32
-mono_arch_cpu_optimizazions (guint32 *exclude_mask)
+mono_arch_cpu_optimizations (guint32 *exclude_mask)
 {
 #if !defined(__native_client__)
        int eax, ebx, ecx, edx;
@@ -1481,7 +1485,7 @@ mono_arch_emit_call (MonoCompile *cfg, MonoCallInst *call)
        /* Arguments are pushed in the reverse order */
        for (i = n - 1; i >= 0; i --) {
                ArgInfo *ainfo = cinfo->args + i;
-               MonoType *t;
+               MonoType *orig_type, *t;
                int argsize;
 
                if (cinfo->vtype_retaddr && cinfo->vret_arg_index == 1 && i == 0) {
@@ -1499,6 +1503,7 @@ mono_arch_emit_call (MonoCompile *cfg, MonoCallInst *call)
                        t = sig->params [i - sig->hasthis];
                else
                        t = &mono_defaults.int_class->byval_arg;
+               orig_type = t;
                t = mini_type_get_underlying_type (cfg->generic_sharing_context, t);
 
                MONO_INST_NEW (cfg, arg, OP_X86_PUSH);
@@ -1532,7 +1537,7 @@ mono_arch_emit_call (MonoCompile *cfg, MonoCallInst *call)
 
                                MONO_ADD_INS (cfg->cbb, arg);
                                sp_offset += size;
-                               emit_gc_param_slot_def (cfg, sp_offset, t);
+                               emit_gc_param_slot_def (cfg, sp_offset, orig_type);
                        }
                } else {
                        argsize = 4;
@@ -1571,11 +1576,16 @@ mono_arch_emit_call (MonoCompile *cfg, MonoCallInst *call)
                        if (cfg->compute_gc_maps) {
                                if (argsize == 4) {
                                        /* FIXME: The == STACK_OBJ check might be fragile ? */
-                                       if (sig->hasthis && i == 0 && call->args [i]->type == STACK_OBJ)
+                                       if (sig->hasthis && i == 0 && call->args [i]->type == STACK_OBJ) {
                                                /* this */
-                                               emit_gc_param_slot_def (cfg, sp_offset, &mono_defaults.object_class->byval_arg);
-                                       else
-                                               emit_gc_param_slot_def (cfg, sp_offset, t);
+                                               if (call->need_unbox_trampoline)
+                                                       /* The unbox trampoline transforms this into a managed pointer */
+                                                       emit_gc_param_slot_def (cfg, sp_offset, &mono_defaults.int_class->this_arg);
+                                               else
+                                                       emit_gc_param_slot_def (cfg, sp_offset, &mono_defaults.object_class->byval_arg);
+                                       } else {
+                                               emit_gc_param_slot_def (cfg, sp_offset, orig_type);
+                                       }
                                } else {
                                        /* i8/r8 */
                                        for (j = 0; j < argsize; j += 4)
@@ -1623,6 +1633,7 @@ mono_arch_emit_call (MonoCompile *cfg, MonoCallInst *call)
        }
 
        call->stack_usage = cinfo->stack_usage;
+       call->stack_align_amount = cinfo->stack_align_amount;
        cfg->arch.param_area_size = MAX (cfg->arch.param_area_size, sp_offset);
 }
 
@@ -2281,11 +2292,12 @@ mono_x86_have_tls_get (void)
 #ifdef __APPLE__
        static gboolean have_tls_get = FALSE;
        static gboolean inited = FALSE;
+       guint32 *ins;
 
        if (inited)
                return have_tls_get;
 
-       guint32 *ins = (guint32*)pthread_getspecific;
+       ins = (guint32*)pthread_getspecific;
        /*
         * We're looking for these two instructions:
         *
@@ -3174,7 +3186,7 @@ mono_arch_output_basic_block (MonoCompile *cfg, MonoBasicBlock *bb)
                        }
 
                        /* Copy arguments on the stack to our argument area */
-                       for (i = 0; i < call->stack_usage; i += 4) {
+                       for (i = 0; i < call->stack_usage - call->stack_align_amount; i += 4) {
                                x86_mov_reg_membase (code, X86_EAX, X86_ESP, i, 4);
                                x86_mov_membase_reg (code, X86_EBP, 8 + i, X86_EAX, 4);
                        }
@@ -5049,52 +5061,6 @@ mono_arch_emit_prolog (MonoCompile *cfg)
        alloc_size = cfg->stack_offset;
        pos = 0;
 
-       if (method->wrapper_type == MONO_WRAPPER_NATIVE_TO_MANAGED) {
-               /* Might need to attach the thread to the JIT  or change the domain for the callback */
-               if (appdomain_tls_offset != -1 && lmf_tls_offset != -1) {
-                       guint8 *buf, *no_domain_branch;
-
-                       code = mono_x86_emit_tls_get (code, X86_EAX, appdomain_tls_offset);
-                       x86_alu_reg_imm (code, X86_CMP, X86_EAX, GPOINTER_TO_UINT (cfg->domain));
-                       no_domain_branch = code;
-                       x86_branch8 (code, X86_CC_NE, 0, 0);
-                       code = mono_x86_emit_tls_get ( code, X86_EAX, lmf_tls_offset);
-                       x86_test_reg_reg (code, X86_EAX, X86_EAX);
-                       buf = code;
-                       x86_branch8 (code, X86_CC_NE, 0, 0);
-                       x86_patch (no_domain_branch, code);
-
-                       x86_alu_reg_imm (code, X86_SUB, X86_ESP, 4);
-                       x86_push_imm (code, cfg->domain);
-                       code = emit_call (cfg, code, MONO_PATCH_INFO_INTERNAL_METHOD, (gpointer)"mono_jit_thread_attach");
-                       x86_alu_reg_imm (code, X86_ADD, X86_ESP, 8);
-                       x86_patch (buf, code);
-#ifdef TARGET_WIN32
-                       /* The TLS key actually contains a pointer to the MonoJitTlsData structure */
-                       /* FIXME: Add a separate key for LMF to avoid this */
-                       x86_alu_reg_imm (code, X86_ADD, X86_EAX, G_STRUCT_OFFSET (MonoJitTlsData, lmf));
-#endif
-               }
-               else {
-                       x86_alu_reg_imm (code, X86_SUB, X86_ESP, 4);
-                       if (cfg->compile_aot) {
-                               /* 
-                                * This goes before the saving of callee saved regs, so save the got reg
-                                * ourselves.
-                                */
-                               x86_push_reg (code, MONO_ARCH_GOT_REG);
-                               code = mono_arch_emit_load_got_addr (cfg->native_code, code, cfg, NULL);
-                               x86_push_imm (code, 0);
-                       } else {
-                               x86_push_imm (code, cfg->domain);
-                       }
-                       code = emit_call (cfg, code, MONO_PATCH_INFO_INTERNAL_METHOD, (gpointer)"mono_jit_thread_attach");
-                       x86_alu_reg_imm (code, X86_ADD, X86_ESP, 8);
-                       if (cfg->compile_aot)
-                               x86_pop_reg (code, MONO_ARCH_GOT_REG);
-               }
-       }
-
        if (method->save_lmf) {
                pos += sizeof (MonoLMF);
 
@@ -5482,7 +5448,7 @@ mono_arch_emit_epilog (MonoCompile *cfg)
        if (CALLCONV_IS_STDCALL (sig)) {
                MonoJitArgumentInfo *arg_info = alloca (sizeof (MonoJitArgumentInfo) * (sig->param_count + 1));
 
-               stack_to_pop = mono_arch_get_argument_info (sig, sig->param_count, arg_info);
+               stack_to_pop = mono_arch_get_argument_info (cfg->generic_sharing_context, sig, sig->param_count, arg_info);
        } else if (MONO_TYPE_ISSTRUCT (mono_method_signature (cfg->method)->ret) && (cinfo->ret.storage == ArgOnStack))
                stack_to_pop = 4;
        else