[aot] Add hooks which can be used by embedders to load the aot data for aot images...
authorZoltan Varga <vargaz@gmail.com>
Mon, 21 Dec 2015 22:06:53 +0000 (17:06 -0500)
committerZoltan Varga <vargaz@gmail.com>
Mon, 21 Dec 2015 22:06:56 +0000 (17:06 -0500)
mono/mini/aot-runtime.c
mono/mini/mini.h

index 1e28aaef20c63e0f99339103744e7ad0d70dcc13..8586cf50eeac1141e2c768948a651882101f3ca0 100644 (file)
@@ -211,6 +211,11 @@ static mono_mutex_t aot_page_mutex;
 
 static MonoAotModule *mscorlib_aot_module;
 
+/* Embedding API hooks to load the AOT data for AOT images compiled with MONO_AOT_FILE_FLAG_SEPARATE_DATA */
+static MonoLoadAotDataFunc aot_data_load_func;
+static MonoFreeAotDataFunc aot_data_free_func;
+static gpointer aot_data_func_user_data;
+
 static void
 init_plt (MonoAotModule *info);
 
@@ -1661,6 +1666,14 @@ find_symbol (MonoDl *module, gpointer *globals, const char *name, gpointer *valu
        }
 }
 
+void
+mono_install_load_aot_data_hook (MonoLoadAotDataFunc load_func, MonoFreeAotDataFunc free_func, gpointer user_data)
+{
+       aot_data_load_func = load_func;
+       aot_data_free_func = free_func;
+       aot_data_func_user_data = user_data;
+}
+
 /* Load the separate aot data file for ASSEMBLY */
 static guint8*
 open_aot_data (MonoAssembly *assembly, MonoAotFileInfo *info, void **ret_handle)
@@ -1669,13 +1682,19 @@ open_aot_data (MonoAssembly *assembly, MonoAotFileInfo *info, void **ret_handle)
        char *filename;
        guint8 *data;
 
+       if (aot_data_load_func) {
+               data = aot_data_load_func (assembly, info->datafile_size, aot_data_func_user_data, ret_handle);
+               g_assert (data);
+               return data;
+       }
+
        /*
         * Use <assembly name>.aotdata as the default implementation if no callback is given
         */
        filename = g_strdup_printf ("%s.aotdata", assembly->image->name);
        map = mono_file_map_open (filename);
        g_assert (map);
-       data = mono_file_map (info->datafile_size, MONO_MMAP_READ|MONO_MMAP_PRIVATE, mono_file_map_fd (map), 0, ret_handle);
+       data = mono_file_map (info->datafile_size, MONO_MMAP_READ, mono_file_map_fd (map), 0, ret_handle);
        g_assert (data);
 
        return data;
index 9a7916000a08d6671231e2daf48986d31771b761..8c6913add30ba37c4dc5f6df75c05297c5c28da9 100644 (file)
@@ -2430,6 +2430,16 @@ void     mono_aot_init_gshared_method_rgctx  (gpointer aot_module, guint32 metho
 /* This is an exported function */
 MONO_API void     mono_aot_register_module           (gpointer *aot_info);
 
+/* These are used to load the AOT data for aot images compiled with MONO_AOT_FILE_FLAG_SEPARATE_DATA */
+/*
+ * Return the AOT data for ASSEMBLY. SIZE is the size of the data. OUT_HANDLE should be set to a handle which is later
+ * passed to the free function.
+ */
+typedef unsigned char* (*MonoLoadAotDataFunc)          (MonoAssembly *assembly, int size, gpointer user_data, void **out_handle);
+/* Not yet used */
+typedef void  (*MonoFreeAotDataFunc)          (MonoAssembly *assembly, int size, gpointer user_data, void *handle);
+MONO_API void mono_install_load_aot_data_hook (MonoLoadAotDataFunc load_func, MonoFreeAotDataFunc free_func, gpointer user_data);
+
 void     mono_xdebug_init                   (const char *xdebug_opts);
 void     mono_save_xdebug_info              (MonoCompile *cfg);
 void     mono_save_trampoline_xdebug_info   (MonoTrampInfo *info);