From: Zoltan Varga Date: Wed, 27 Jan 2016 21:01:41 +0000 (-0500) Subject: [jit] Convert some of the error handling to use cfg->error instead of cfg->exception_... X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=commitdiff_plain;h=bb015846ad009e29179f2c1537f078d2d42d9362;p=mono.git [jit] Convert some of the error handling to use cfg->error instead of cfg->exception_type. --- diff --git a/mono/mini/decompose.c b/mono/mini/decompose.c index ea53056e695..d8c46e88c0d 100644 --- a/mono/mini/decompose.c +++ b/mono/mini/decompose.c @@ -439,8 +439,7 @@ mono_decompose_opcode (MonoCompile *cfg, MonoInst *ins) case OP_FCONV_TO_OVF_U8_UN: case OP_FCONV_TO_OVF_I_UN: case OP_FCONV_TO_OVF_U_UN: - cfg->exception_type = MONO_EXCEPTION_INVALID_PROGRAM; - cfg->exception_message = g_strdup_printf ("float conv.ovf.un opcodes not supported."); + mono_cfg_set_exception_invalid_program (cfg, g_strdup_printf ("float conv.ovf.un opcodes not supported.")); break; case OP_IDIV: diff --git a/mono/mini/method-to-ir.c b/mono/mini/method-to-ir.c index 85cf2aca184..2ff04067b88 100644 --- a/mono/mini/method-to-ir.c +++ b/mono/mini/method-to-ir.c @@ -108,7 +108,8 @@ } \ } while (0) #define OUT_OF_MEMORY_FAILURE do { \ - mono_cfg_set_exception (cfg, MONO_EXCEPTION_OUT_OF_MEMORY); \ + mono_cfg_set_exception (cfg, MONO_EXCEPTION_MONO_ERROR); \ + mono_error_set_out_of_memory (&cfg->error, ""); \ goto exception_exit; \ } while (0) #define DISABLE_AOT(cfg) do { \ @@ -373,8 +374,8 @@ method_access_failure (MonoCompile *cfg, MonoMethod *method, MonoMethod *cil_met { char *method_fname = mono_method_full_name (method, TRUE); char *cil_method_fname = mono_method_full_name (cil_method, TRUE); - mono_cfg_set_exception (cfg, MONO_EXCEPTION_METHOD_ACCESS); - cfg->exception_message = g_strdup_printf ("Method `%s' is inaccessible from method `%s'\n", cil_method_fname, method_fname); + mono_cfg_set_exception (cfg, MONO_EXCEPTION_MONO_ERROR); + mono_error_set_generic_error (&cfg->error, "System", "MethodAccessException", "Method `%s' is inaccessible from method `%s'\n", cil_method_fname, method_fname); g_free (method_fname); g_free (cil_method_fname); } @@ -384,8 +385,8 @@ field_access_failure (MonoCompile *cfg, MonoMethod *method, MonoClassField *fiel { char *method_fname = mono_method_full_name (method, TRUE); char *field_fname = mono_field_full_name (field); - mono_cfg_set_exception (cfg, MONO_EXCEPTION_FIELD_ACCESS); - cfg->exception_message = g_strdup_printf ("Field `%s' is inaccessible from method `%s'\n", field_fname, method_fname); + mono_cfg_set_exception (cfg, MONO_EXCEPTION_MONO_ERROR); + mono_error_set_generic_error (&cfg->error, "System", "FieldAccessException", "Field `%s' is inaccessible from method `%s'\n", field_fname, method_fname); g_free (method_fname); g_free (field_fname); } @@ -7601,21 +7602,12 @@ set_exception_type_from_invalid_il (MonoCompile *cfg, MonoMethod *method, unsign method_code = g_strdup ("method body is empty."); else method_code = mono_disasm_code_one (NULL, method, ip, NULL); - mono_cfg_set_exception (cfg, MONO_EXCEPTION_INVALID_PROGRAM); - cfg->exception_message = g_strdup_printf ("Invalid IL code in %s: %s\n", method_fname, method_code); + mono_cfg_set_exception_invalid_program (cfg, g_strdup_printf ("Invalid IL code in %s: %s\n", method_fname, method_code)); g_free (method_fname); g_free (method_code); cfg->headers_to_free = g_slist_prepend_mempool (cfg->mempool, cfg->headers_to_free, header); } -static void -set_exception_object (MonoCompile *cfg, MonoException *exception) -{ - mono_cfg_set_exception (cfg, MONO_EXCEPTION_OBJECT_SUPPLIED); - MONO_GC_REGISTER_ROOT_SINGLE (cfg->exception_ptr, MONO_ROOT_SOURCE_JIT, "jit exception"); - cfg->exception_ptr = exception; -} - static void emit_stloc_ir (MonoCompile *cfg, MonoInst **sp, MonoMethodHeader *header, int n) { @@ -8165,8 +8157,7 @@ mono_method_to_ir (MonoCompile *cfg, MonoMethod *method, MonoBasicBlock *start_b if ((error = mono_loader_get_last_error ())) { mono_cfg_set_exception (cfg, error->exception_type); } else { - mono_cfg_set_exception (cfg, MONO_EXCEPTION_INVALID_PROGRAM); - cfg->exception_message = g_strdup_printf ("Missing or incorrect header for method %s", cfg->method->name); + mono_cfg_set_exception_invalid_program (cfg, g_strdup_printf ("Missing or incorrect header for method %s", cfg->method->name)); } goto exception_exit; } @@ -11649,7 +11640,9 @@ mono_method_to_ir (MonoCompile *cfg, MonoMethod *method, MonoBasicBlock *start_b INLINE_FAILURE ("class init"); ex = mono_runtime_class_init_full (vtable, FALSE); if (ex) { - set_exception_object (cfg, ex); + mono_cfg_set_exception (cfg, MONO_EXCEPTION_MONO_ERROR); + mono_error_set_exception_instance (&cfg->error, ex); + g_assert_not_reached (); goto exception_exit; } } @@ -13636,8 +13629,7 @@ mono_method_to_ir (MonoCompile *cfg, MonoMethod *method, MonoBasicBlock *start_b /* Method is too large */ mname = mono_method_full_name (method, TRUE); - mono_cfg_set_exception (cfg, MONO_EXCEPTION_INVALID_PROGRAM); - cfg->exception_message = g_strdup_printf ("Method %s is too complex.", mname); + mono_cfg_set_exception_invalid_program (cfg, g_strdup_printf ("Method %s is too complex.", mname)); g_free (mname); } diff --git a/mono/mini/mini-amd64.c b/mono/mini/mini-amd64.c index a97493988ce..d37ad6818bf 100644 --- a/mono/mini/mini-amd64.c +++ b/mono/mini/mini-amd64.c @@ -1958,8 +1958,7 @@ mono_arch_allocate_vars (MonoCompile *cfg) offsets = mono_allocate_stack_slots (cfg, cfg->arch.omit_fp ? FALSE: TRUE, &locals_stack_size, &locals_stack_align); if (locals_stack_size > MONO_ARCH_MAX_FRAME_SIZE) { char *mname = mono_method_full_name (cfg->method, TRUE); - cfg->exception_type = MONO_EXCEPTION_INVALID_PROGRAM; - cfg->exception_message = g_strdup_printf ("Method %s stack is too big.", mname); + mono_cfg_set_exception_invalid_program (cfg, g_strdup_printf ("Method %s stack is too big.", mname)); g_free (mname); return; } @@ -2475,8 +2474,7 @@ mono_arch_emit_call (MonoCompile *cfg, MonoCallInst *call) if (size >= 10000) { /* Avoid asserts in emit_memcpy () */ - cfg->exception_type = MONO_EXCEPTION_INVALID_PROGRAM; - cfg->exception_message = g_strdup_printf ("Passing an argument of size '%d'.", size); + mono_cfg_set_exception_invalid_program (cfg, g_strdup_printf ("Passing an argument of size '%d'.", size)); /* Continue normally */ } diff --git a/mono/mini/mini-x86.c b/mono/mini/mini-x86.c index dfea009165d..03e2eca5272 100644 --- a/mono/mini/mini-x86.c +++ b/mono/mini/mini-x86.c @@ -1096,8 +1096,7 @@ mono_arch_allocate_vars (MonoCompile *cfg) offsets = mono_allocate_stack_slots (cfg, TRUE, &locals_stack_size, &locals_stack_align); if (locals_stack_size > MONO_ARCH_MAX_FRAME_SIZE) { char *mname = mono_method_full_name (cfg->method, TRUE); - cfg->exception_type = MONO_EXCEPTION_INVALID_PROGRAM; - cfg->exception_message = g_strdup_printf ("Method %s stack is too big.", mname); + mono_cfg_set_exception_invalid_program (cfg, g_strdup_printf ("Method %s stack is too big.", mname)); g_free (mname); return; } diff --git a/mono/mini/mini.c b/mono/mini/mini.c index 7a490f01304..ba5577ef60a 100644 --- a/mono/mini/mini.c +++ b/mono/mini/mini.c @@ -1256,8 +1256,17 @@ mini_method_verify (MonoCompile *cfg, MonoMethod *method, gboolean fail_compile) if (info->info.status == MONO_VERIFY_NOT_VERIFIABLE && (!is_fulltrust || info->exception_type == MONO_EXCEPTION_METHOD_ACCESS || info->exception_type == MONO_EXCEPTION_FIELD_ACCESS)) { if (fail_compile) { char *method_name = mono_method_full_name (method, TRUE); - cfg->exception_type = info->exception_type; - cfg->exception_message = g_strdup_printf ("Error verifying %s: %s", method_name, info->info.message); + + if (info->exception_type == MONO_EXCEPTION_METHOD_ACCESS || info->exception_type == MONO_EXCEPTION_FIELD_ACCESS) { + if (info->exception_type == MONO_EXCEPTION_METHOD_ACCESS) + mono_error_set_generic_error (&cfg->error, "System", "MethodAccessException", "Error verifying %s: %s", method_name, info->info.message); + else + mono_error_set_generic_error (&cfg->error, "System", "FieldAccessException", "Error verifying %s: %s", method_name, info->info.message); + cfg->exception_type = MONO_EXCEPTION_MONO_ERROR; + } else { + cfg->exception_type = info->exception_type; + cfg->exception_message = g_strdup_printf ("Error verifying %s: %s", method_name, info->info.message); + } g_free (method_name); } mono_free_verify_list (res); @@ -3477,8 +3486,7 @@ mini_method_compile (MonoMethod *method, guint32 opts, MonoDomain *domain, JitFl if ((error = mono_loader_get_last_error ())) { cfg->exception_type = error->exception_type; } else { - cfg->exception_type = MONO_EXCEPTION_INVALID_PROGRAM; - cfg->exception_message = g_strdup_printf ("Missing or incorrect header for method %s", cfg->method->name); + mono_cfg_set_exception_invalid_program (cfg, g_strdup_printf ("Missing or incorrect header for method %s", cfg->method->name)); } if (MONO_METHOD_COMPILE_END_ENABLED ()) MONO_PROBE_METHOD_COMPILE_END (method, FALSE); @@ -4135,6 +4143,14 @@ mono_cfg_set_exception (MonoCompile *cfg, int type) cfg->exception_type = type; } +/* Assumes ownership of the MSG argument */ +void +mono_cfg_set_exception_invalid_program (MonoCompile *cfg, char *msg) +{ + mono_cfg_set_exception (cfg, MONO_EXCEPTION_MONO_ERROR); + mono_error_set_generic_error (&cfg->error, "System", "InvalidProgramException", msg); +} + #endif /* DISABLE_JIT */ static MonoJitInfo* @@ -4335,28 +4351,9 @@ mono_jit_compile_method_inner (MonoMethod *method, MonoDomain *target_domain, in } break; } - case MONO_EXCEPTION_INVALID_PROGRAM: - ex = mono_exception_from_name_msg (mono_defaults.corlib, "System", "InvalidProgramException", cfg->exception_message); - break; case MONO_EXCEPTION_UNVERIFIABLE_IL: ex = mono_exception_from_name_msg (mono_defaults.corlib, "System.Security", "VerificationException", cfg->exception_message); break; - case MONO_EXCEPTION_METHOD_ACCESS: - ex = mono_exception_from_name_msg (mono_defaults.corlib, "System", "MethodAccessException", cfg->exception_message); - break; - case MONO_EXCEPTION_FIELD_ACCESS: - ex = mono_exception_from_name_msg (mono_defaults.corlib, "System", "FieldAccessException", cfg->exception_message); - break; - case MONO_EXCEPTION_OBJECT_SUPPLIED: { - MonoException *exp = (MonoException *)cfg->exception_ptr; - MONO_GC_UNREGISTER_ROOT (cfg->exception_ptr); - - ex = exp; - break; - } - case MONO_EXCEPTION_OUT_OF_MEMORY: - ex = mono_domain_get ()->out_of_memory_ex; - break; case MONO_EXCEPTION_MONO_ERROR: g_assert (!mono_error_ok (&cfg->error)); ex = mono_error_convert_to_exception (&cfg->error); diff --git a/mono/mini/mini.h b/mono/mini/mini.h index 5cf8fb55038..592d2945d2f 100644 --- a/mono/mini/mini.h +++ b/mono/mini/mini.h @@ -3005,6 +3005,7 @@ guint mono_type_to_regmove (MonoCompile *cfg, MonoType *type) MONO_LLVM_INTERNAL void mono_cfg_add_try_hole (MonoCompile *cfg, MonoExceptionClause *clause, guint8 *start, MonoBasicBlock *bb); void mono_cfg_set_exception (MonoCompile *cfg, int type); +void mono_cfg_set_exception_invalid_program (MonoCompile *cfg, char *msg); gboolean mini_type_is_reference (MonoType *type); gboolean mini_type_is_vtype (MonoType *t) MONO_LLVM_INTERNAL;