Allow mscorlib to be loaded from disk when using NACL.
authorElijah Taylor <elijahtaylor@google.com>
Tue, 17 Aug 2010 05:29:44 +0000 (07:29 +0200)
committerZoltan Varga <vargaz@gmail.com>
Tue, 17 Aug 2010 05:30:37 +0000 (07:30 +0200)
mono/metadata/assembly.c

index 26f743f7cdb41ab2df875ac55533e8103b88bd32..4bb632cbb90be7dfb752e477a0684ea0cdf2f429 100644 (file)
@@ -127,6 +127,27 @@ static const AssemblyVersionMap framework_assemblies [] = {
 static GList *loaded_assemblies = NULL;
 static MonoAssembly *corlib;
 
+#if defined(__native_client__)
+
+/* On Native Client, allow mscorlib to be loaded from memory  */
+/* instead of loaded off disk.  If these are not set, default */
+/* mscorlib loading will take place                           */
+
+/* NOTE: If mscorlib data is passed to mono in this way then */
+/* it needs to remain allocated during the use of mono.      */
+
+static void *corlibData = NULL;
+static size_t corlibSize = 0;
+
+void
+mono_set_corlib_data (void *data, size_t size)
+{
+  corlibData = data;
+  corlibSize = size;
+}
+
+#endif
+
 /* This protects loaded_assemblies and image->references */
 #define mono_assemblies_lock() EnterCriticalSection (&assemblies_mutex)
 #define mono_assemblies_unlock() LeaveCriticalSection (&assemblies_mutex)
@@ -2515,7 +2536,6 @@ mono_assembly_load_from_gac (MonoAssemblyName *aname,  gchar *filename, MonoImag
        return result;
 }
 
-
 MonoAssembly*
 mono_assembly_load_corlib (const MonoRuntimeInfo *runtime, MonoImageOpenStatus *status)
 {
@@ -2525,6 +2545,22 @@ mono_assembly_load_corlib (const MonoRuntimeInfo *runtime, MonoImageOpenStatus *
                /* g_print ("corlib already loaded\n"); */
                return corlib;
        }
+
+#if defined(__native_client__)
+       if (corlibData != NULL && corlibSize != 0) {
+               int status = 0;
+               /* First "FALSE" instructs mono not to make a copy. */
+               /* Second "FALSE" says this is not just a ref.      */
+               MonoImage* image = mono_image_open_from_data_full (corlibData, corlibSize, FALSE, &status, FALSE);
+               if (image == NULL || status != 0)
+                       g_print("mono_image_open_from_data_full failed: %d\n", status);
+               corlib = mono_assembly_load_from_full (image, "mscorlib", &status, FALSE);
+               if (corlib == NULL || status != 0)
+                       g_print ("mono_assembly_load_from_full failed: %d\n", status);
+               if (corlib)
+                       return corlib;
+       }
+#endif
        
        if (assemblies_path) {
                corlib = load_in_path ("mscorlib.dll", (const char**)assemblies_path, status, FALSE);