Mon Aug 5 19:30:04 CEST 2002 Paolo Molaro <lupus@ximian.com>
authorPaolo Molaro <lupus@oddwiz.org>
Mon, 5 Aug 2002 17:35:25 +0000 (17:35 -0000)
committerPaolo Molaro <lupus@oddwiz.org>
Mon, 5 Aug 2002 17:35:25 +0000 (17:35 -0000)
* assembly.c: fix mem corruption issue.
* image.h, image.c: added mono_image_get_resource () to access
managed resources.
* icall.c: implemented Assembly.EntryPoint property and some
Managed Resources related internalcalls.

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

mono/metadata/ChangeLog
mono/metadata/assembly.c
mono/metadata/icall.c
mono/metadata/image.c
mono/metadata/image.h

index 914ccb05087db85b1015caa3087a176390de7294..8f892a0bb348ce73c65cc4276c2e5ca39522e153 100644 (file)
@@ -1,4 +1,13 @@
 
+Mon Aug 5 19:30:04 CEST 2002 Paolo Molaro <lupus@ximian.com>
+
+       * assembly.c: fix mem corruption issue.
+       * image.h, image.c: added mono_image_get_resource () to access
+       managed resources.
+       * icall.c: implemented Assembly.EntryPoint property and some
+       Managed Resources related internalcalls.
+
+
 Mon Aug 5 18:18:03 CEST 2002 Paolo Molaro <lupus@ximian.com>
 
        * image.c, image.h: impemented mono_image_get_entry_point ().
index 9aa09a75b8f1611cb848fd0416cbda9a7881e85a..4a36e9ede8d806203c81225f6619994499399cb4 100644 (file)
@@ -285,7 +285,6 @@ mono_assembly_open (const char *filename, MonoImageOpenStatus *status)
                g_free (module_ref);
        }
 
-       g_free (base_dir);
        return ass;
 }
 
index 7d2be551c2698c5ee873e97fabfde459a7ddae4a..21aaf6289cc2e4ad0558a4c54ff91999d9bc1eb2 100644 (file)
@@ -1779,6 +1779,92 @@ ves_icall_System_Reflection_Assembly_get_code_base (MonoReflectionAssembly *asse
        return res;
 }
 
+static MonoReflectionMethod*
+ves_icall_System_Reflection_Assembly_get_EntryPoint (MonoReflectionAssembly *assembly) {
+       guint32 token = mono_image_get_entry_point (assembly->assembly->image);
+       if (!token)
+               return NULL;
+       return mono_method_get_object (mono_object_domain (assembly), mono_get_method (assembly->assembly->image, token, NULL));
+}
+
+static MonoArray*
+ves_icall_System_Reflection_Assembly_GetManifestResourceNames (MonoReflectionAssembly *assembly) {
+       MonoTableInfo *table = &assembly->assembly->image->tables [MONO_TABLE_MANIFESTRESOURCE];
+       MonoArray *result = mono_array_new (mono_object_domain (assembly), mono_defaults.string_class, table->rows);
+       int i;
+       const char *val;
+
+       for (i = 0; i < table->rows; ++i) {
+               val = mono_metadata_string_heap (assembly->assembly->image, mono_metadata_decode_row_col (table, i, MONO_MANIFEST_NAME));
+               mono_array_set (result, gpointer, i, mono_string_new (mono_object_domain (assembly), val));
+       }
+       return result;
+}
+
+/* move this in some file in mono/util/ */
+static char *
+g_concat_dir_and_file (const char *dir, const char *file)
+{
+       g_return_val_if_fail (dir != NULL, NULL);
+       g_return_val_if_fail (file != NULL, NULL);
+
+        /*
+        * If the directory name doesn't have a / on the end, we need
+        * to add one so we get a proper path to the file
+        */
+       if (dir [strlen(dir) - 1] != G_DIR_SEPARATOR)
+               return g_strconcat (dir, G_DIR_SEPARATOR_S, file, NULL);
+       else
+               return g_strconcat (dir, file, NULL);
+}
+
+static MonoObject*
+ves_icall_System_Reflection_Assembly_GetManifestResourceInternal (MonoReflectionAssembly *assembly, MonoString *name) {
+       char *n = mono_string_to_utf8 (name);
+       MonoTableInfo *table = &assembly->assembly->image->tables [MONO_TABLE_MANIFESTRESOURCE];
+       guint32 i;
+       guint32 cols [MONO_MANIFEST_SIZE];
+       const char *val;
+       MonoObject *result;
+
+       for (i = 0; i < table->rows; ++i) {
+               mono_metadata_decode_row (table, i, cols, MONO_MANIFEST_SIZE);
+               val = mono_metadata_string_heap (assembly->assembly->image, cols [MONO_MANIFEST_NAME]);
+               if (strcmp (val, n) == 0)
+                       break;
+       }
+       g_free (n);
+       if (i == table->rows)
+               return NULL;
+       /* FIXME */
+       if (!cols [MONO_MANIFEST_IMPLEMENTATION]) {
+               guint32 size;
+               MonoArray *data;
+               val = mono_image_get_resource (assembly->assembly->image, cols [MONO_MANIFEST_OFFSET], &size);
+               if (!val)
+                       return NULL;
+               data = mono_array_new (mono_object_domain (assembly), mono_defaults.byte_class, size);
+               memcpy (mono_array_addr (data, char, 0), val, size);
+               return (MonoObject*)data;
+       }
+       switch (cols [MONO_MANIFEST_IMPLEMENTATION] & IMPLEMENTATION_MASK) {
+       case IMPLEMENTATION_FILE:
+               i = cols [MONO_MANIFEST_IMPLEMENTATION] >> IMPLEMENTATION_BITS;
+               table = &assembly->assembly->image->tables [MONO_TABLE_FILE];
+               i = mono_metadata_decode_row_col (table, i - 1, MONO_FILE_NAME);
+               val = mono_metadata_string_heap (assembly->assembly->image, i);
+               n = g_concat_dir_and_file (assembly->assembly->basedir, val);
+               result = (MonoObject*)mono_string_new (mono_object_domain (assembly), n);
+               g_free (n);
+               return result;
+       case IMPLEMENTATION_ASSEMBLYREF:
+       case IMPLEMENTATION_EXP_TYPE:
+               /* FIXME */
+               break;
+       }
+       return NULL;
+}
+
 static MonoReflectionMethod*
 ves_icall_GetCurrentMethod (void) {
        MonoMethod *m = mono_method_get_last_managed ();
@@ -2589,6 +2675,9 @@ static gconstpointer icall_map [] = {
        "System.Reflection.Assembly::get_code_base", ves_icall_System_Reflection_Assembly_get_code_base,
        "System.Reflection.Assembly::GetExecutingAssembly", ves_icall_System_Reflection_Assembly_GetExecutingAssembly,
        "System.Reflection.Assembly::GetCallingAssembly", ves_icall_System_Reflection_Assembly_GetCallingAssembly,
+       "System.Reflection.Assembly::get_EntryPoint", ves_icall_System_Reflection_Assembly_get_EntryPoint,
+       "System.Reflection.Assembly::GetManifestResourceNames", ves_icall_System_Reflection_Assembly_GetManifestResourceNames,
+       "System.Reflection.Assembly::GetManifestResourceInternal", ves_icall_System_Reflection_Assembly_GetManifestResourceInternal,
 
        /*
         * System.MonoType.
index 91fcea9cb85df7ac2348b4246df45adacf3ac1c7..117ebae06d9783391a58d2ca8430c2b08a0febb6 100644 (file)
@@ -815,4 +815,23 @@ mono_image_get_entry_point (MonoImage *image)
        return ((MonoCLIImageInfo*)image->image_info)->cli_cli_header.ch_entry_point;
 }
 
+const char*
+mono_image_get_resource (MonoImage *image, guint32 offset, guint32 *size)
+{
+       MonoCLIImageInfo *iinfo = image->image_info;
+       MonoCLIHeader *ch = &iinfo->cli_cli_header;
+       const char* data;
+
+       if (!ch->ch_resources.rva || offset + 4 > ch->ch_resources.size)
+               return NULL;
+       
+       data = mono_cli_rva_map (iinfo, ch->ch_resources.rva);
+       if (!data)
+               return NULL;
+       data += offset;
+       if (size)
+               *size = read32 (data);
+       data += 4;
+       return data;
+}
 
index 650e2a63d03b400872f7d4adc9939c0c0feb49f3..f47cd3a94c32132c80ce8f05aaea7fd2056cc872 100644 (file)
@@ -141,6 +141,7 @@ int           mono_image_ensure_section_idx (MonoImage *image,
                                             int section);
 
 guint32       mono_image_get_entry_point    (MonoImage *image);
+const char   *mono_image_get_resource       (MonoImage *image, guint32 offset, guint32 *size);
 
 /* This actually returns a MonoPEResourceDataEntry *, but declaring it
  * causes an include file loop.