Standardized Mainsoft ConstraintCollection tests.
[mono.git] / mono / mini / mini-exceptions.c
index 90cfa0a1f8bf5bdd18ab0a1fda28752f965aa762..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);
                
@@ -321,14 +325,14 @@ ves_icall_get_frame_info (gint32 skip, MonoBoolean need_file_info,
        MonoLMF *lmf = jit_tls->lmf;
        MonoJitInfo *ji, rji;
        MonoContext ctx, new_ctx;
-       unsigned int stackptr;
+       gssize stackptr;
 
        mono_arch_flush_register_windows ();
 
 #ifdef _MSC_VER
        __asm mov stackptr, ebp;
 #else
-       stackptr = (unsigned int) __builtin_frame_address (0);
+       stackptr = (gssize)__builtin_frame_address (0);
 #endif
 
        MONO_CONTEXT_SET_IP (&ctx, ves_icall_get_frame_info);
@@ -443,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)
 {
@@ -465,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;
@@ -506,7 +530,6 @@ 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 */
@@ -520,14 +543,12 @@ ves_icall_System_Security_SecurityFrame_GetSecurityStack (gint32 skip)
 #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