Test case for bug#325444.
[mono.git] / mono / mini / aot-runtime.c
index 538533ec59d232ba68a551cd98a02cf9120630eb..6da4f6e00f4e1c85c51a40cec484839c6ab2d9a2 100644 (file)
@@ -10,7 +10,9 @@
 
 #include "config.h"
 #include <sys/types.h>
+#ifdef HAVE_UNISTD_H
 #include <unistd.h>
+#endif
 #include <fcntl.h>
 #include <string.h>
 #ifndef PLATFORM_WIN32
@@ -44,6 +46,7 @@
 #include <mono/metadata/assembly.h>
 #include <mono/metadata/metadata-internals.h>
 #include <mono/metadata/marshal.h>
+#include <mono/metadata/gc-internal.h>
 #include <mono/utils/mono-logger.h>
 #include "mono/utils/mono-compiler.h"
 
@@ -235,9 +238,12 @@ decode_klass_info (MonoAotModule *module, guint8 *buf, guint8 **endbuf)
        image = load_image (module, image_index);
        if (!image)
                return NULL;
-       if (mono_metadata_token_code (token) == 0) {
+       if (mono_metadata_token_table (token) == 0) {
                klass = mono_class_get (image, MONO_TOKEN_TYPE_DEF + token);
+       } else if (mono_metadata_token_table (token) == MONO_TABLE_TYPESPEC) {
+               klass = mono_class_get (image, token);
        } else {
+               g_assert (mono_metadata_token_table (token) == MONO_TABLE_TYPEDEF);
                token = MONO_TOKEN_TYPE_DEF + decode_value (buf, &buf);
                rank = decode_value (buf, &buf);
                if (token == MONO_TOKEN_TYPE_DEF) {
@@ -289,6 +295,12 @@ decode_method_ref (MonoAotModule *module, guint32 *token, guint8 *buf, guint8 **
        image_index = value >> 24;
        *token = MONO_TOKEN_METHOD_DEF | (value & 0xffffff);
 
+       if (image_index == 255) {
+               /* Methodspec */
+               image_index = decode_value (buf, &buf);
+               *token = decode_value (buf, &buf);
+       }
+
        image = load_image (module, image_index);
        if (!image)
                return NULL;
@@ -659,6 +671,9 @@ decode_cached_class_info (MonoAotModule *module, MonoCachedClassInfo *info, guin
        guint32 flags;
 
        info->vtable_size = decode_value (buf, &buf);
+       if (info->vtable_size == -1)
+               /* Generic type */
+               return FALSE;
        flags = decode_value (buf, &buf);
        info->ghcimpl = (flags >> 0) & 0x1;
        info->has_finalize = (flags >> 1) & 0x1;
@@ -1096,18 +1111,14 @@ decode_patch_info (MonoAotModule *aot_module, MonoMemPool *mp, MonoJumpInfo *ji,
        case MONO_PATCH_INFO_METHOD:
        case MONO_PATCH_INFO_METHODCONST:
        case MONO_PATCH_INFO_METHOD_JUMP: {
-               guint32 image_index, token, value;
+               guint32 token;
 
-               value = decode_value (p, &p);
-               image_index = value >> 24;
-               token = MONO_TOKEN_METHOD_DEF | (value & 0xffffff);
-
-               image = load_image (aot_module, image_index);
+               image = decode_method_ref (aot_module, &token, p, &p);
                if (!image)
                        goto cleanup;
 
 #ifdef MONO_ARCH_HAVE_CREATE_TRAMPOLINE_FROM_TOKEN
-               if (ji->type == MONO_PATCH_INFO_METHOD) {
+               if ((ji->type == MONO_PATCH_INFO_METHOD) && (mono_metadata_token_table (token) == MONO_TABLE_METHOD)) {
                        ji->data.target = mono_create_jit_trampoline_from_token (image, token);
                        ji->type = MONO_PATCH_INFO_ABS;
                }
@@ -1182,6 +1193,13 @@ decode_patch_info (MonoAotModule *aot_module, MonoMemPool *mp, MonoJumpInfo *ji,
                                g_assert_not_reached ();
                        break;
                }
+               case MONO_WRAPPER_ALLOC: {
+                       int atype = decode_value (p, &p);
+
+                       ji->type = MONO_PATCH_INFO_METHOD;
+                       ji->data.method = mono_gc_get_managed_allocator_by_type (atype);
+                       break;
+               }
                case MONO_WRAPPER_STELEMREF:
                        ji->type = MONO_PATCH_INFO_METHOD;
                        ji->data.method = mono_marshal_get_stelemref ();
@@ -1888,7 +1906,7 @@ mono_aot_handle_pagefault (void *ptr)
 }
 
 /*
- * aot_dyn_resolve:
+ * mono_aot_plt_resolve:
  *
  *   This function is called by the entries in the PLT to resolve the actual method that
  * needs to be called. It returns a trampoline to the method and patches the PLT entry.
@@ -2088,4 +2106,10 @@ mono_aot_get_plt_entry (guint8 *code)
        return NULL;
 }
 
+gpointer
+mono_aot_plt_resolve (gpointer aot_module, guint32 plt_info_offset, guint8 *code)
+{
+       return NULL;
+}
+
 #endif