2004-11-04 Zoltan Varga <vargaz@freemail.hu>
[mono.git] / mono / interpreter / interp.c
index 73b14846b6f2961252bf95fb5dc75714c50fc3ba..893d736c90b7131fab3d48f099dece4376866a12 100644 (file)
@@ -669,13 +669,17 @@ ves_array_element_address (MonoInvocation *frame)
 }
 
 static void
-interp_walk_stack (MonoStackWalk func, gpointer user_data)
+interp_walk_stack (MonoStackWalk func, gboolean do_il_offset, gpointer user_data)
 {
        ThreadContext *context = TlsGetValue (thread_context_id);
-       MonoInvocation *frame = context->current_frame;
+       MonoInvocation *frame;
        int il_offset;
        MonoMethodHeader *hd;
 
+       if (!context) return;
+               
+       frame = context->current_frame;
+
        while (frame) {
                gboolean managed = FALSE;
                MonoMethod *method = frame->runtime_method->method;
@@ -760,6 +764,25 @@ interp_delegate_ctor (MonoDomain *domain, MonoObject *this, MonoObject *target,
        }
 }
 
+MonoDelegate*
+mono_interp_ftnptr_to_delegate (MonoClass *klass, gpointer ftn)
+{
+       MonoDelegate *d;
+       MonoJitInfo *ji;
+       MonoDomain *domain = mono_domain_get ();
+
+       d = (MonoDelegate*)mono_object_new (domain, klass);
+
+       ji = mono_jit_info_table_find (domain, ftn);
+       if (ji == NULL)
+               mono_raise_exception (mono_get_exception_argument ("", "Function pointer was not created by a Delegate."));
+
+       /* FIXME: discard the wrapper and call the original method */
+       interp_delegate_ctor (domain, (MonoObject*)d, NULL, mono_interp_get_runtime_method (ji->method));
+
+       return d;
+}
+
 /*
  * From the spec:
  * runtime specifies that the implementation of the method is automatically
@@ -1209,7 +1232,7 @@ do_icall (ThreadContext *context, int op, stackval *sp, gpointer ptr)
                context->env_frame = old_env_frame;
                context->current_env = old_env;
                context->managed_code = 1;
-               return;
+               return sp;
        }
 
        context->env_frame = context->current_frame;
@@ -4360,7 +4383,8 @@ mono_interp_init(const char *file)
        g_log_set_always_fatal (G_LOG_LEVEL_ERROR);
        g_log_set_fatal_mask (G_LOG_DOMAIN, G_LOG_LEVEL_ERROR);
 
-       g_thread_init (NULL);
+       if (!g_thread_supported ())
+               g_thread_init (NULL);
 
        thread_context_id = TlsAlloc ();
        TlsSetValue (thread_context_id, NULL);
@@ -4379,7 +4403,7 @@ mono_interp_init(const char *file)
        mono_runtime_install_cleanup (quit_function);
        abort_requested = mono_thread_interruption_request_flag ();
 
-       domain = mono_init (file);
+       domain = mono_init_from_assembly (file, file);
 #ifdef __hpux /* generates very big stack frames */
        mono_threads_set_default_stacksize(32*1024*1024);
 #endif
@@ -4391,6 +4415,7 @@ mono_interp_init(const char *file)
 
        mono_runtime_init (domain, NULL, NULL);
 
+       mono_thread_attach (domain);
        return domain;
 }
 
@@ -4408,6 +4433,8 @@ mono_main (int argc, char *argv [])
        if (argc < 2)
                usage ();
 
+       MONO_GC_PRE_INIT ();
+       
        for (i = 1; i < argc && argv [i][0] == '-'; i++){
                if (strcmp (argv [i], "--trace") == 0)
                        global_tracing = 1;