2009-01-13 Zoltan Varga <vargaz@gmail.com>
authorZoltan Varga <vargaz@gmail.com>
Tue, 13 Jan 2009 16:00:59 +0000 (16:00 -0000)
committerZoltan Varga <vargaz@gmail.com>
Tue, 13 Jan 2009 16:00:59 +0000 (16:00 -0000)
* marshal.c: Avoid setting the exception clauses after a method has been entered
into the wrapper caches. Fixes #465700.

* method-builder.c (mono_mb_set_clauses): New function to set the clauses of the
method builder.
(mono_mb_create_method): Set the clauses from the method builder.

svn path=/trunk/mono/; revision=123201

mono/metadata/ChangeLog
mono/metadata/marshal.c
mono/metadata/method-builder.c
mono/metadata/method-builder.h

index ea34093931606070c47b4e0c1e3fff73a7451279..1180b3d0a619c47b6e03da65395913fb10b46ef5 100644 (file)
@@ -1,3 +1,11 @@
+2009-01-13  Zoltan Varga  <vargaz@gmail.com>
+
+       * marshal.c: Avoid setting the exception clauses after a method has been entered 
+       into the wrapper caches. Fixes #465700.
+
+       * method-builder.c (mono_mb_set_clauses): New function to set the clauses of the
+       method builder.
+       (mono_mb_create_method): Set the clauses from the method builder.
 
 2009-01-13 Gonzalo Paniagua Javier <gonzalo@novell.com>
 
index 6d321f9f6a4b48e498b439ab808c203111c97696..20a488da1b758fb87446f8cf07f54d8310ad91ac 100644 (file)
@@ -3832,7 +3832,6 @@ mono_marshal_get_xappdomain_dispatch (MonoMethod *method, int *marshal_types, in
        MonoClass *ret_class = NULL;
        int loc_array=0, loc_return=0, loc_serialized_exc=0;
        MonoExceptionClause *main_clause;
-       MonoMethodHeader *header;
        int pos, pos_leave;
        gboolean copy_return;
 
@@ -4069,13 +4068,11 @@ mono_marshal_get_xappdomain_dispatch (MonoMethod *method, int *marshal_types, in
 
        mono_mb_emit_byte (mb, CEE_RET);
 
+       mono_mb_set_clauses (mb, 1, main_clause);
+
        res = mono_remoting_mb_create_and_cache (method, mb, csig, csig->param_count + 16);
        mono_mb_free (mb);
 
-       header = ((MonoMethodNormal *)res)->header;
-       header->num_clauses = 1;
-       header->clauses = main_clause;
-
        return res;
 }
 
@@ -4841,7 +4838,6 @@ mono_marshal_get_runtime_invoke (MonoMethod *method)
 {
        MonoMethodSignature *sig, *csig, *callsig;
        MonoExceptionClause *clause;
-       MonoMethodHeader *header;
        MonoMethodBuilder *mb;
        GHashTable *cache = NULL;
        MonoClass *target_klass;
@@ -5179,6 +5175,8 @@ handle_enum:
 
        clause->handler_len = mono_mb_get_pos (mb) - clause->handler_offset;
 
+       mono_mb_set_clauses (mb, 1, clause);
+
        /* return result */
        mono_mb_patch_branch (mb, pos);
        mono_mb_emit_ldloc (mb, 0);
@@ -5215,10 +5213,6 @@ handle_enum:
 
        mono_mb_free (mb);
 
-       header = ((MonoMethodNormal *)res)->header;
-       header->num_clauses = 1;
-       header->clauses = clause;
-
        return res;     
 }
 
@@ -9821,7 +9815,6 @@ mono_marshal_get_synchronized_wrapper (MonoMethod *method)
        static MonoMethod *enter_method, *exit_method, *gettypefromhandle_method;
        MonoMethodSignature *sig;
        MonoExceptionClause *clause;
-       MonoMethodHeader *header;
        MonoMethodBuilder *mb;
        MonoMethod *res;
        GHashTable *cache;
@@ -9942,14 +9935,12 @@ mono_marshal_get_synchronized_wrapper (MonoMethod *method)
                mono_mb_emit_ldloc (mb, ret_local);
        mono_mb_emit_byte (mb, CEE_RET);
 
+       mono_mb_set_clauses (mb, 1, clause);
+
        res = mono_mb_create_and_cache (cache, method,
                                                                        mb, sig, sig->param_count + 16);
        mono_mb_free (mb);
 
-       header = ((MonoMethodNormal *)res)->header;
-       header->num_clauses = 1;
-       header->clauses = clause;
-
        return res;     
 }
 
@@ -12338,7 +12329,6 @@ cominterop_get_managed_wrapper_adjusted (MonoMethod *method)
        MonoMarshalSpec **mspecs;
        MonoMethodSignature *sig, *sig_native;
        MonoExceptionClause *main_clause = NULL;
-       MonoMethodHeader *header;
        int pos_leave;
        int hr = 0;
        int i;
@@ -12413,6 +12403,8 @@ cominterop_get_managed_wrapper_adjusted (MonoMethod *method)
                main_clause->handler_len = mono_mb_get_pos (mb) - main_clause->handler_offset;
                /* end catch */
 
+               mono_mb_set_clauses (mb, 1, main_clause);
+
                mono_mb_patch_branch (mb, pos_leave);
 
                mono_mb_emit_ldloc (mb, hr);
@@ -12433,12 +12425,6 @@ cominterop_get_managed_wrapper_adjusted (MonoMethod *method)
                        mono_metadata_free_marshal_spec (mspecs [i]);
        g_free (mspecs);
 
-       if (!preserve_sig) {
-               header = ((MonoMethodNormal *)res)->header;
-               header->num_clauses = 1;
-               header->clauses = main_clause;
-       }
-
        return res;
 }
 
@@ -12672,7 +12658,6 @@ mono_marshal_get_thunk_invoke_wrapper (MonoMethod *method)
        MonoMethodBuilder *mb;
        MonoMethodSignature *sig, *csig;
        MonoExceptionClause *clause;
-       MonoMethodHeader *header;
        MonoImage *image;
        MonoClass *klass;
        GHashTable *cache;
@@ -12791,6 +12776,8 @@ mono_marshal_get_thunk_invoke_wrapper (MonoMethod *method)
 
        clause->handler_len = mono_mb_get_pos (mb) - clause->handler_offset;
 
+       mono_mb_set_clauses (mb, 1, clause);
+
        mono_mb_patch_branch (mb, pos_leave);
        /* end-try */
 
@@ -12807,9 +12794,5 @@ mono_marshal_get_thunk_invoke_wrapper (MonoMethod *method)
        res = mono_mb_create_and_cache (cache, method, mb, csig, param_count + 16);
        mono_mb_free (mb);
 
-       header = ((MonoMethodNormal *)res)->header;
-       header->num_clauses = 1;
-       header->clauses = clause;
-
        return res;
 }
index 18410dd757a008f624ed4ea8fbfec5941d384fb0..4e85ec205b1986c707780637df39aa42583bdd6f 100644 (file)
@@ -187,6 +187,9 @@ mono_mb_create_method (MonoMethodBuilder *mb, MonoMethodSignature *signature, in
        header->num_locals = mb->locals;
        header->init_locals = TRUE;
 
+       header->num_clauses = mb->num_clauses;
+       header->clauses = mb->clauses;
+
        mw = (MonoMethodWrapper*) mb->method;
        i = g_list_length (mw->method_data);
        if (i) {
@@ -518,3 +521,10 @@ mono_mb_emit_add_to_local (MonoMethodBuilder *mb, guint16 local, gint32 incr)
        mono_mb_emit_byte (mb, CEE_ADD);
        mono_mb_emit_stloc (mb, local); 
 }
+
+void
+mono_mb_set_clauses (MonoMethodBuilder *mb, int num_clauses, MonoExceptionClause *clauses)
+{
+       mb->num_clauses = num_clauses;
+       mb->clauses = clauses;
+}
index 049a32905557a8639569f05de862169cb8f72977..3334f8876bbcc9da67b453f95640ca7b7ceebc63 100644 (file)
@@ -28,6 +28,8 @@ typedef struct _MonoMethodBuilder {
        gboolean no_dup_name;
        guint32 code_size, pos;
        unsigned char *code;
+       int num_clauses;
+       MonoExceptionClause *clauses;
 } MonoMethodBuilder;
 
 MonoMethodBuilder *
@@ -135,6 +137,9 @@ mono_mb_emit_op (MonoMethodBuilder *mb, guint8 op, gpointer data) MONO_INTERNAL;
 void
 mono_mb_emit_ldstr (MonoMethodBuilder *mb, char *str) MONO_INTERNAL;
 
+void
+mono_mb_set_clauses (MonoMethodBuilder *mb, int num_clauses, MonoExceptionClause *clauses) MONO_INTERNAL;
+
 G_END_DECLS
 
 #endif /* __MONO_METHOD_BUILDER_H__ */