Merge pull request #3059 from lateralusX/jlorenss/win-x64-dyncall-gsharedvt-support
[mono.git] / mono / mini / mini-s390x.c
index 368c3bc9882189148756cb07e5580ce93543f67b..3fe40d2cfc28fdd8a055b003ad58785d5cbd3427 100644 (file)
@@ -264,6 +264,8 @@ if (ins->inst_target_bb->native_offset) {                                   \
 #include <mono/metadata/appdomain.h>
 #include <mono/metadata/debug-helpers.h>
 #include <mono/metadata/profiler-private.h>
+#include <mono/utils/mono-error.h>
+#include <mono/utils/mono-error-internals.h>
 #include <mono/utils/mono-math.h>
 #include <mono/utils/mono-mmap.h>
 #include <mono/utils/mono-hwcap-s390x.h>
@@ -765,6 +767,20 @@ cvtMonoType(MonoTypeEnum t)
 /*                                                                 */
 /*------------------------------------------------------------------*/
 
+static void
+decodeParmString (MonoString *s)
+{
+       MonoError error;
+       char *str = mono_string_to_utf8_checked(s, &error);
+       if (is_ok (&error))  {
+               printf("[STRING:%p:%s], ", s, str);
+               g_free (str);
+       } else {
+               mono_error_cleanup (&error);
+               printf("[STRING:%p:], ", s);
+       }
+}
+
 static void 
 decodeParm(MonoType *type, void *curParm, int size)
 {
@@ -813,7 +829,7 @@ enum_parmtype:
                                MonoString *s = *((MonoString **) curParm);
                                if (s) {
                                        g_assert (((MonoObject *) s)->vtable->klass == mono_defaults.string_class);
-                                       printf("[STRING:%p:%s], ", s, mono_string_to_utf8(s));
+                                       decodeParmString (s);
                                } else {
                                        printf("[STRING:null], ");
                                }
@@ -828,8 +844,7 @@ enum_parmtype:
                                        klass = obj->vtable->klass;
                                        printf("%p [%p] ",obj,curParm);
                                        if (klass == mono_defaults.string_class) {
-                                               printf("[STRING:%p:%s]", 
-                                                      obj, mono_string_to_utf8 ((MonoString *) obj));
+                                               decodeParmString ((MonoString *)obj);
                                        } else if (klass == mono_defaults.int32_class) { 
                                                printf("[INT32:%p:%d]", 
                                                        obj, *(gint32 *)((char *)obj + sizeof (MonoObject)));
@@ -969,8 +984,8 @@ enter_method (MonoMethod *method, RegParm *rParm, char *sp)
                                if (obj->vtable) {
                                        klass = obj->vtable->klass;
                                        if (klass == mono_defaults.string_class) {
-                                               printf ("this:[STRING:%p:%s], ", 
-                                                       obj, mono_string_to_utf8 ((MonoString *)obj));
+                                               printf ("this:");
+                                               decodeParmString((MonoString *)obj);
                                        } else {
                                                printf ("this:%p[%s.%s], ", 
                                                        obj, klass->name_space, klass->name);
@@ -1126,7 +1141,7 @@ handle_enum:
 ;
                if (s) {
                        g_assert (((MonoObject *)s)->vtable->klass == mono_defaults.string_class);
-                       printf ("[STRING:%p:%s]", s, mono_string_to_utf8 (s));
+                       decodeParmString (s);
                } else 
                        printf ("[STRING:null], ");
                break;
@@ -2547,10 +2562,12 @@ mono_arch_emit_outarg_vt (MonoCompile *cfg, MonoInst *ins, MonoInst *src)
 
                mono_call_inst_add_outarg_reg (cfg, call, dreg, ainfo->reg, TRUE);
        } else {
+               MonoError error;
                MonoMethodHeader *header;
                int srcReg;
 
-               header = mono_method_get_header (cfg->method);
+               header = mono_method_get_header_checked (cfg->method, &error);
+               mono_error_assert_ok (&error); /* FIXME don't swallow the error */
                if ((cfg->flags & MONO_CFG_HAS_ALLOCA) || header->num_clauses)
                        srcReg = s390_r11;
                else
@@ -4602,7 +4619,7 @@ mono_arch_output_basic_block (MonoCompile *cfg, MonoBasicBlock *bb)
                        s390_tcdb (code, ins->sreg1, 0, s390_r13, 0);
                        s390_jz   (code, 0); CODEPTR(code, o);
                        mono_add_patch_info (cfg, code - cfg->native_code, 
-                                            MONO_PATCH_INFO_EXC, "ArithmeticException");
+                                            MONO_PATCH_INFO_EXC, "OverflowException");
                        s390_brasl (code, s390_r14,0);
                        PTRSLOT(code, o);
                }
@@ -5384,16 +5401,20 @@ mono_arch_register_lowlevel_calls (void)
 
 void
 mono_arch_patch_code (MonoCompile *cfg, MonoMethod *method, MonoDomain *domain, 
-                     guint8 *code, MonoJumpInfo *ji, gboolean run_cctors)
+                     guint8 *code, MonoJumpInfo *ji, gboolean run_cctors,
+                     MonoError *error)
 {
        MonoJumpInfo *patch_info;
 
+       mono_error_init (error);
+
        for (patch_info = ji; patch_info; patch_info = patch_info->next) {
                unsigned char *ip = patch_info->ip.i + code;
                gconstpointer target = NULL;
 
                target = mono_resolve_patch_target (method, domain, code, 
-                                                   patch_info, run_cctors);
+                                                                                       patch_info, run_cctors, error);
+               return_if_nok (error);
 
                switch (patch_info->type) {
                        case MONO_PATCH_INFO_IP:
@@ -5407,9 +5428,6 @@ mono_arch_patch_code (MonoCompile *cfg, MonoMethod *method, MonoDomain *domain,
                        case MONO_PATCH_INFO_INTERNAL_METHOD:
                        case MONO_PATCH_INFO_JIT_ICALL_ADDR:
                        case MONO_PATCH_INFO_RGCTX_FETCH:
-                       case MONO_PATCH_INFO_MONITOR_ENTER:
-                       case MONO_PATCH_INFO_MONITOR_ENTER_V4:
-                       case MONO_PATCH_INFO_MONITOR_EXIT:
                        case MONO_PATCH_INFO_ABS: {
                                S390_EMIT_CALL (ip, target);
                                continue;
@@ -6078,10 +6096,9 @@ mono_arch_emit_exceptions (MonoCompile *cfg)
                        /*-----------------------------------------------------*/
                        s390_patch_rel (ip + 2, (guint64) S390_RELATIVE(code,ip));
 
-                       exc_class = mono_class_from_name (mono_defaults.corlib, 
+                       exc_class = mono_class_load_from_name (mono_defaults.corlib,
                                                          "System", 
                                                          patch_info->data.name);
-                       g_assert (exc_class);
                        throw_ip = patch_info->ip.i;
 
                        for (iExc = 0; iExc < nThrows; ++iExc)