Skip to content

Commit

Permalink
[mono] Add mono_get_bundled_assembly in preparation for bundled runti…
Browse files Browse the repository at this point in the history
…meconfig data
  • Loading branch information
mdh1418 committed Apr 3, 2023
1 parent a34c284 commit c1924b2
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 24 deletions.
63 changes: 40 additions & 23 deletions src/mono/mono/mini/aot-runtime.c
Original file line number Diff line number Diff line change
Expand Up @@ -2413,39 +2413,56 @@ mono_aot_register_module (gpointer *aot_info)
mono_aot_unlock ();
}

typedef struct BundleAssembly_ BundleAssembly;
static GHashTable *bundled_assemblies = NULL;

struct BundleAssembly_ {
MonoBundledAssembly assembly;
BundleAssembly *next;
};
static int bundles_added = 0;

static BundleAssembly *bundle_assembly_start;
static int bundle_assembly_count;
void
mono_add_bundled_assembly (const char *name, const unsigned char *data, unsigned int size)
{
if (!bundled_assemblies)
bundled_assemblies = g_hash_table_new (g_str_hash, g_str_equal);

MonoBundledAssembly *bundled_assembly = g_new0 (MonoBundledAssembly, 1);
bundled_assembly->name = g_strdup (name);
g_assert (bundled_assembly->name);
bundled_assembly->data = data;
bundled_assembly->size = size;
g_hash_table_insert (bundled_assemblies, (gpointer) name, bundled_assembly);
bundles_added++;
}

void
mono_add_bundled_assembly (const char* name, const unsigned char* data, unsigned int size)
mono_get_bundled_assembly (const char *name, const unsigned char **out_data, unsigned int *out_size)
{
*out_data = NULL;
*out_size = 0;
MonoBundledAssembly *bundled_assembly;

if (g_hash_table_lookup_extended (bundled_assemblies, name, NULL, (gpointer *)&bundled_assembly)) {
*out_data = bundled_assembly->data;
*out_size = bundled_assembly->size;
}
}

static void
populate_bundle (gpointer key, gpointer value, gpointer user_data)
{
BundleAssembly *entry = g_new0 (BundleAssembly, 1);
entry->assembly.name = g_strdup (name);
g_assert (entry->assembly.name);
entry->assembly.data = data;
entry->assembly.size = size;
entry->next = bundle_assembly_start;
bundle_assembly_start = entry;
++bundle_assembly_count;
MonoBundledAssembly *bundled_assembly = (MonoBundledAssembly *)value;
MonoBundledAssembly **bundle = (MonoBundledAssembly **)user_data;
g_assert (bundles_added > 0);
bundle [bundles_added-- - 1] = bundled_assembly;
}

void
mono_register_bundle (void)
{
MonoBundledAssembly **bundle = g_new0 (MonoBundledAssembly*, bundle_assembly_count + 1);
BundleAssembly *bundle_assembly = bundle_assembly_start;
for (int i = 0; i < bundle_assembly_count; ++i) {
g_assert (bundle_assembly);
bundle [i] = &bundle_assembly->assembly;
bundle_assembly = bundle_assembly->next;
}
if (!bundled_assemblies)
return;

MonoBundledAssembly **bundle = g_new0 (MonoBundledAssembly*, bundles_added + 1);
g_hash_table_foreach (bundled_assemblies, populate_bundle, bundle);

mono_register_bundled_assemblies ((const MonoBundledAssembly **)bundle);
}

Expand Down
3 changes: 2 additions & 1 deletion src/mono/mono/mini/aot-runtime.h
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,8 @@ typedef struct MonoAotFileInfo
/* Number of symbols in the MonoAotFileInfo structure */
#define MONO_AOT_FILE_INFO_NUM_SYMBOLS (((G_STRUCT_OFFSET (MonoAotFileInfo, MONO_AOT_FILE_INFO_LAST_SYMBOL) - G_STRUCT_OFFSET (MonoAotFileInfo, MONO_AOT_FILE_INFO_FIRST_SYMBOL)) / sizeof (gpointer)) + 1)

void mono_add_bundled_assembly (const char* name, const unsigned char* data, unsigned int size);
void mono_add_bundled_assembly (const char *name, const unsigned char *data, unsigned int size);
void mono_get_bundled_assembly (const char *name, const unsigned char **out_data, unsigned int *out_size);
void mono_register_bundle (void);
void mono_aot_init (void);
gpointer mono_aot_get_method (MonoMethod *method, MonoError *error);
Expand Down

0 comments on commit c1924b2

Please sign in to comment.