[sdb] Keep the exception object alive during debugger suspensions. Fixes #12494.
[mono.git] / mono / mini / mini-x86.c
index fe3dcca1319c8a384a9891b35bf9e0667d1d930e..4809ae935bd8d98854070c2abf7c463bea840056 100644 (file)
@@ -74,8 +74,6 @@ mono_breakpoint_info [MONO_BREAKPOINT_ARRAY_SIZE];
 
 
 #ifdef __native_client_codegen__
-const guint kNaClAlignment = kNaClAlignmentX86;
-const guint kNaClAlignmentMask = kNaClAlignmentMaskX86;
 
 /* Default alignment for Native Client is 32-byte. */
 gint8 nacl_align_byte = -32; /* signed version of 0xe0 */
@@ -711,7 +709,12 @@ static const guchar cpuid_impl [] = {
        0x89, 0x02,                             /* mov    %eax,(%edx) */
        0x5b,                                   /* pop    %ebx */
        0xc9,                                   /* leave   */
-       0x59, 0x83, 0xe1, 0xe0, 0xff, 0xe1      /* naclret */
+       0x59, 0x83, 0xe1, 0xe0, 0xff, 0xe1,     /* naclret */
+       0xf4, 0xf4, 0xf4, 0xf4, 0xf4, 0xf4,     /* padding, to provide bundle aligned version */
+       0xf4, 0xf4, 0xf4, 0xf4, 0xf4, 0xf4,
+       0xf4, 0xf4, 0xf4, 0xf4, 0xf4, 0xf4,
+       0xf4, 0xf4, 0xf4, 0xf4, 0xf4, 0xf4,
+       0xf4
 };
 #endif
 
@@ -2810,6 +2813,10 @@ mono_arch_output_basic_block (MonoCompile *cfg, MonoBasicBlock *bb)
                        break;
                case OP_IDIV:
                case OP_IREM:
+#if defined( __native_client_codegen__ )
+                       x86_alu_reg_imm (code, X86_CMP, ins->sreg2, 0);
+                       EMIT_COND_SYSTEM_EXCEPTION (X86_CC_EQ, TRUE, "DivideByZeroException");
+#endif
                        /* 
                         * The code is the same for div/rem, the allocator will allocate dreg
                         * to RAX/RDX as appropriate.
@@ -2827,6 +2834,10 @@ mono_arch_output_basic_block (MonoCompile *cfg, MonoBasicBlock *bb)
                        break;
                case OP_IDIV_UN:
                case OP_IREM_UN:
+#if defined( __native_client_codegen__ )
+                       x86_alu_reg_imm (code, X86_CMP, ins->sreg2, 0);
+                       EMIT_COND_SYSTEM_EXCEPTION (X86_CC_EQ, TRUE, "DivideByZeroException");
+#endif
                        if (ins->sreg2 == X86_EDX) {
                                x86_push_reg (code, ins->sreg2);
                                x86_alu_reg_reg (code, X86_XOR, X86_EDX, X86_EDX);
@@ -2838,6 +2849,13 @@ mono_arch_output_basic_block (MonoCompile *cfg, MonoBasicBlock *bb)
                        }
                        break;
                case OP_DIV_IMM:
+#if defined( __native_client_codegen__ )
+                       if (ins->inst_imm == 0) {
+                               mono_add_patch_info (cfg, code - cfg->native_code, MONO_PATCH_INFO_EXC, "DivideByZeroException");
+                               x86_jump32 (code, 0);
+                               break;
+                       }
+#endif
                        x86_mov_reg_imm (code, ins->sreg2, ins->inst_imm);
                        x86_cdq (code);
                        x86_div_reg (code, ins->sreg2, TRUE);
@@ -5073,6 +5091,7 @@ mono_arch_emit_prolog (MonoCompile *cfg)
        code = cfg->native_code = g_malloc (cfg->code_size);
 #elif defined(__native_client_codegen__)
        /* native_code_alloc is not 32-byte aligned, native_code is. */
+       cfg->code_size = NACL_BUNDLE_ALIGN_UP (cfg->code_size);
        cfg->native_code_alloc = g_malloc (cfg->code_size + kNaClAlignment);
 
        /* Align native_code to next nearest kNaclAlignment byte. */
@@ -5786,6 +5805,7 @@ mono_arch_build_imt_thunk (MonoVTable *vtable, MonoDomain *domain, MonoIMTCheckI
 #if defined(__native_client__) && defined(__native_client_codegen__)
        /* In Native Client, we don't re-use thunks, allocate from the */
        /* normal code manager paths. */
+       size = NACL_BUNDLE_ALIGN_UP (size);
        code = mono_domain_code_reserve (domain, size);
 #else
        if (fail_tramp)