Standardized Mainsoft ConstraintCollection tests.
[mono.git] / mono / mini / mini-exceptions.c
index 17dfb5ad9a66e968ac9b0e1bf4ab9f45f80eca7f..36946b60f45c45fedbbdd907abfff0e66c6cf9d1 100644 (file)
@@ -61,23 +61,27 @@ mono_find_jit_info (MonoDomain *domain, MonoJitTlsData *jit_tls, MonoJitInfo *re
 
        if (managed2 || ji->method->wrapper_type) {
                char *source_location, *tmpaddr, *fname;
-               gint32 address, iloffset;
+               gint32 offset, iloffset;
 
-               address = (char *)ip - (char *)ji->code_start;
+               if (!managed2)
+                       /* ctx->ip points into native code */
+                       offset = (char*)MONO_CONTEXT_GET_IP (new_ctx) - (char*)ji->code_start;
+               else
+                       offset = (char *)ip - (char *)ji->code_start;
 
                if (native_offset)
-                       *native_offset = address;
+                       *native_offset = offset;
 
                if (managed)
                        if (!ji->method->wrapper_type)
                                *managed = TRUE;
 
                if (trace) {
-                       source_location = mono_debug_source_location_from_address (ji->method, address, NULL, domain);
-                       iloffset = mono_debug_il_offset_from_address (ji->method, address, domain);
+                       source_location = mono_debug_source_location_from_address (ji->method, offset, NULL, domain);
+                       iloffset = mono_debug_il_offset_from_address (ji->method, offset, domain);
 
                        if (iloffset < 0)
-                               tmpaddr = g_strdup_printf ("<0x%05x>", address);
+                               tmpaddr = g_strdup_printf ("<0x%05x>", offset);
                        else
                                tmpaddr = g_strdup_printf ("[0x%05x]", iloffset);
                
@@ -193,7 +197,16 @@ ves_icall_get_trace (MonoException *exc, gint32 skip, MonoBoolean need_file_info
 
                g_assert (ji != NULL);
 
-               sf->method = mono_method_get_object (domain, ji->method, NULL);
+               if (ji->method->wrapper_type) {
+                       char *s;
+
+                       sf->method = NULL;
+                       s = mono_method_full_name (ji->method, TRUE);
+                       sf->internal_method_name = mono_string_new (domain, s);
+                       g_free (s);
+               }
+               else
+                       sf->method = mono_method_get_object (domain, ji->method, NULL);
                sf->native_offset = (char *)ip - (char *)ji->code_start;
 
                sf->il_offset = mono_debug_il_offset_from_address (ji->method, sf->native_offset, domain);
@@ -270,11 +283,20 @@ mono_jit_walk_stack (MonoStackWalk func, gboolean do_il_offset, gpointer user_da
 
        MonoContext ctx, new_ctx;
 
+#ifdef _MSC_VER
+       unsigned int stackptr, retaddr;
+       __asm mov stackptr, ebp;
+       __asm mov eax, DWORD PTR [ebp + 4];
+       __asm mov retaddr, eax;
+       MONO_CONTEXT_SET_IP (&ctx, retaddr);
+       /* FIXME: NOT WORKING -- THIS IS __builtin_frame_address (0) NOT (1) */
+       MONO_CONTEXT_SET_BP (&ctx, stackptr);
+#else
        mono_arch_flush_register_windows ();
 
        MONO_CONTEXT_SET_IP (&ctx, __builtin_return_address (0));
        MONO_CONTEXT_SET_BP (&ctx, __builtin_frame_address (1));
-
+#endif
        while (MONO_CONTEXT_GET_BP (&ctx) < jit_tls->end_of_stack) {
                
                ji = mono_find_jit_info (domain, jit_tls, &rji, NULL, &ctx, &new_ctx, NULL, &lmf, &native_offset, &managed);
@@ -303,11 +325,18 @@ ves_icall_get_frame_info (gint32 skip, MonoBoolean need_file_info,
        MonoLMF *lmf = jit_tls->lmf;
        MonoJitInfo *ji, rji;
        MonoContext ctx, new_ctx;
+       gssize stackptr;
 
        mono_arch_flush_register_windows ();
 
+#ifdef _MSC_VER
+       __asm mov stackptr, ebp;
+#else
+       stackptr = (gssize)__builtin_frame_address (0);
+#endif
+
        MONO_CONTEXT_SET_IP (&ctx, ves_icall_get_frame_info);
-       MONO_CONTEXT_SET_BP (&ctx, __builtin_frame_address (0));
+       MONO_CONTEXT_SET_BP (&ctx, stackptr);
 
        skip++;
 
@@ -397,7 +426,16 @@ ves_icall_System_Security_SecurityFrame_GetSecurityFrame (gint32 skip)
        MonoFrameSecurityInfo si;
        MonoContext ctx;
 
+#ifdef _MSC_VER
+       /* seems that MSC doesn't like having __asm in macros */
+       unsigned int stackptr;
+       mono_arch_flush_register_windows ();
+       __asm mov stackptr, ebp;
+       MONO_CONTEXT_SET_IP (&ctx, ves_icall_System_Security_SecurityFrame_GetSecurityFrame);
+       MONO_CONTEXT_SET_BP (&ctx, stackptr);
+#else
        MONO_INIT_CONTEXT_FROM_FUNC (&ctx, ves_icall_System_Security_SecurityFrame_GetSecurityFrame);
+#endif
 
        si.skips = skip;
        si.frame = NULL;
@@ -409,9 +447,26 @@ ves_icall_System_Security_SecurityFrame_GetSecurityFrame (gint32 skip)
 
 typedef struct {
        guint32 skips;
-       GList *stack;
+       MonoArray *stack;
+       guint32 count;
+       guint32 maximum;
 } MonoSecurityStack;
 
+static void
+grow_array (MonoSecurityStack *stack)
+{
+       MonoDomain *domain = mono_domain_get ();
+       guint32 newsize = (stack->maximum << 1);
+       MonoArray *newstack = mono_array_new (domain, mono_defaults.runtimesecurityframe_class, newsize);
+       int i;
+       for (i=0; i < stack->maximum; i++) {
+               gpointer frame = mono_array_get (stack->stack, gpointer, i);
+               mono_array_set (newstack, gpointer, i, frame);
+       }
+       stack->maximum = newsize;
+       stack->stack = newstack;
+}
+
 static gboolean
 callback_get_stack_frames_security_info (MonoDomain *domain, MonoContext *ctx, MonoJitInfo *ji, gpointer data)
 {
@@ -431,7 +486,10 @@ callback_get_stack_frames_security_info (MonoDomain *domain, MonoContext *ctx, M
                return FALSE;
        }
 
-       ss->stack = g_list_prepend (ss->stack, mono_declsec_create_frame (domain, ji));
+       if (ss->count == ss->maximum)
+               grow_array (ss);
+       
+       mono_array_set (ss->stack, gpointer, ss->count++, mono_declsec_create_frame (domain, ji));
 
        /* continue down the stack */
        return FALSE;
@@ -472,19 +530,25 @@ ves_icall_System_Security_SecurityFrame_GetSecurityStack (gint32 skip)
        MonoJitTlsData *jit_tls = TlsGetValue (mono_jit_tls_id);
        MonoSecurityStack ss;
        MonoContext ctx;
-       MonoArray *stack;
 
+#ifdef _MSC_VER
+       /* seems that MSC doesn't like having __asm in macros */
+       unsigned int stackptr;
+       mono_arch_flush_register_windows ();
+       __asm mov stackptr, ebp;
+       MONO_CONTEXT_SET_IP (&ctx, ves_icall_System_Security_SecurityFrame_GetSecurityStack);
+       MONO_CONTEXT_SET_BP (&ctx, stackptr);
+#else
        MONO_INIT_CONTEXT_FROM_FUNC (&ctx, ves_icall_System_Security_SecurityFrame_GetSecurityStack);
+#endif
 
        ss.skips = skip;
-       ss.stack = NULL;
+       ss.count = 0;
+       ss.maximum = MONO_CAS_INITIAL_STACK_SIZE;
+       ss.stack = mono_array_new (domain, mono_defaults.runtimesecurityframe_class, ss.maximum);
        mono_walk_stack (domain, jit_tls, &ctx, callback_get_stack_frames_security_info, (gpointer)&ss);
-
-       stack = glist_to_array (ss.stack, mono_defaults.runtimesecurityframe_class);
-       if (ss.stack)
-               g_list_free (ss.stack);
-
-       return stack;
+       /* g_warning ("STACK RESULT: %d out of %d", ss.count, ss.maximum); */
+       return ss.stack;
 }
 
 #ifndef CUSTOM_EXCEPTION_HANDLING
@@ -544,6 +608,7 @@ mono_handle_exception (MonoContext *ctx, gpointer obj, gpointer original_ip, gbo
         */
        if (obj == domain->stack_overflow_ex) {
                obj = mono_get_exception_stack_overflow ();
+               stack_overflow = TRUE;
        }
        else if (obj == domain->null_reference_ex) {
                obj = mono_get_exception_null_reference ();
@@ -556,9 +621,6 @@ mono_handle_exception (MonoContext *ctx, gpointer obj, gpointer original_ip, gbo
                mono_ex = NULL;
        }
 
-       if (obj == domain->stack_overflow_ex)
-               stack_overflow = TRUE;
-
        if (!call_filter)
                call_filter = mono_arch_get_call_filter ();
 
@@ -649,7 +711,7 @@ mono_handle_exception (MonoContext *ctx, gpointer obj, gpointer original_ip, gbo
                                                /* catch block */
 
                                                if ((ei->flags == MONO_EXCEPTION_CLAUSE_NONE) || (ei->flags == MONO_EXCEPTION_CLAUSE_FILTER)) {
-                                                       /* store the exception object int cfg->excvar */
+                                                       /* store the exception object in cfg->excvar */
                                                        g_assert (ei->exvar_offset);
                                                        *((gpointer *)((char *)MONO_CONTEXT_GET_BP (ctx) + ei->exvar_offset)) = obj;
                                                }
@@ -712,8 +774,8 @@ mono_handle_exception (MonoContext *ctx, gpointer obj, gpointer original_ip, gbo
                                        /* Switch back to normal stack */
                                        if (stack_overflow)
                                                /* Free up some stack space */
-                                               MONO_CONTEXT_SET_SP (&initial_ctx, (guint32)(MONO_CONTEXT_GET_SP (&initial_ctx)) + (64 * 1024));
-                                       MONO_CONTEXT_SET_IP (&initial_ctx, (unsigned int)jit_tls->abort_func);
+                                               MONO_CONTEXT_SET_SP (&initial_ctx, (gssize)(MONO_CONTEXT_GET_SP (&initial_ctx)) + (64 * 1024));
+                                       MONO_CONTEXT_SET_IP (&initial_ctx, (gssize)jit_tls->abort_func);
                                        restore_context (&initial_ctx);
                                }
                                else