2010-02-02 Zoltan Varga <vargaz@gmail.com>
[mono.git] / mono / mini / exceptions-x86.c
index 7b22122f7559a1abac887af7dd3c4534195e1624..732614236cae0d1ddb0dcb0a2057b2cfecd1d4fb 100644 (file)
@@ -460,8 +460,16 @@ get_throw_exception (const char *name, gboolean rethrow, gboolean llvm, gboolean
 
        start = code = mono_global_codeman_reserve (128);
 
-       /* The + 4 aligns the stack on apple */
-       stack_size = 128 + 4;
+       stack_size = 128;
+
+       /* 
+        * On apple, the stack is misaligned by the pushing of the return address.
+        */
+       if (!llvm && corlib)
+               /* On OSX, we don't generate alignment code to save space */
+               stack_size += 4;
+       else
+               stack_size += MONO_ARCH_FRAME_ALIGNMENT - 4;
 
        /*
         * The stack looks like this:
@@ -492,12 +500,20 @@ get_throw_exception (const char *name, gboolean rethrow, gboolean llvm, gboolean
                /* LLVM doesn't push the arguments */
                stack_offset = stack_size + 4;
        } else {
-               if (corlib)
+               if (corlib) {
                        /* Two arguments */
                        stack_offset = stack_size + 4 + 8;
-               else
+#ifdef __APPLE__
+                       /* We don't generate stack alignment code on osx to save space */
+#endif
+               } else {
                        /* One argument */
                        stack_offset = stack_size + 4 + 4;
+#ifdef __APPLE__
+                       /* Pop the alignment added by OP_THROW too */
+                       stack_offset += MONO_ARCH_FRAME_ALIGNMENT - 4;
+#endif
+               }
        }
        /* Save ESP */
        x86_lea_membase (code, X86_EAX, X86_ESP, stack_offset);
@@ -555,35 +571,6 @@ mono_arch_get_rethrow_exception (void)
        return get_throw_exception ("rethrow_exception_trampoline", TRUE, FALSE, FALSE);
 }
 
-/**
- * mono_arch_get_throw_exception_by_name:
- *
- * Returns a function pointer which can be used to raise 
- * corlib exceptions. The returned function has the following 
- * signature: void (*func) (gpointer ip, char *exc_name); 
- * For example to raise an arithmetic exception you can use:
- *
- * x86_push_imm (code, "ArithmeticException"); 
- * x86_push_imm (code, <IP>)
- * x86_jump_code (code, arch_get_throw_exception_by_name ()); 
- *
- */
-gpointer 
-mono_arch_get_throw_exception_by_name (void)
-{
-       guint8* start;
-       guint8 *code;
-
-       start = code = mono_global_codeman_reserve (32);
-
-       /* Not used */
-       x86_breakpoint (code);
-
-       mono_arch_flush_icache (start, code - start);
-
-       return start;
-}
-
 /**
  * mono_arch_get_throw_corlib_exception:
  *