From c89cdd4f8559748a263b38163227973841dbcc76 Mon Sep 17 00:00:00 2001 From: Zoltan Varga Date: Tue, 13 Jan 2009 16:00:59 +0000 Subject: [PATCH] 2009-01-13 Zoltan Varga * 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 | 8 ++++++++ mono/metadata/marshal.c | 37 +++++++++------------------------- mono/metadata/method-builder.c | 10 +++++++++ mono/metadata/method-builder.h | 5 +++++ 4 files changed, 33 insertions(+), 27 deletions(-) diff --git a/mono/metadata/ChangeLog b/mono/metadata/ChangeLog index ea340939316..1180b3d0a61 100644 --- a/mono/metadata/ChangeLog +++ b/mono/metadata/ChangeLog @@ -1,3 +1,11 @@ +2009-01-13 Zoltan Varga + + * 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 diff --git a/mono/metadata/marshal.c b/mono/metadata/marshal.c index 6d321f9f6a4..20a488da1b7 100644 --- a/mono/metadata/marshal.c +++ b/mono/metadata/marshal.c @@ -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; } diff --git a/mono/metadata/method-builder.c b/mono/metadata/method-builder.c index 18410dd757a..4e85ec205b1 100644 --- a/mono/metadata/method-builder.c +++ b/mono/metadata/method-builder.c @@ -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; +} diff --git a/mono/metadata/method-builder.h b/mono/metadata/method-builder.h index 049a3290555..3334f8876bb 100644 --- a/mono/metadata/method-builder.h +++ b/mono/metadata/method-builder.h @@ -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__ */ -- 2.25.1