Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[mono][tasks] Extract EmitWasmBundle into generic EmitBundle task and enable bundling in mono self-contained library #84191

Merged
merged 115 commits into from
Jun 20, 2023
Merged
Show file tree
Hide file tree
Changes from 113 commits
Commits
Show all changes
115 commits
Select commit Hold shift + click to select a range
1d4e246
[tasks] Move EmitWasmBundle out of wasm specific task
mdh1418 Mar 31, 2023
2955cdb
[tasks] Make EmitBundle more generic
mdh1418 Mar 31, 2023
2d25efc
[tasks] Generate EmitBundle task and replace invocations of old task
mdh1418 Mar 31, 2023
d8d97e8
Extend preloading assemblies with mono_assembly_open
mdh1418 Mar 31, 2023
eb5e396
[LibraryBuilder] Integrate bundling
mdh1418 Mar 31, 2023
a34c284
Refactor LibraryBuilder targets to isolate Bundling
mdh1418 Apr 3, 2023
c1924b2
[mono] Add mono_get_bundled_assembly in preparation for bundled runti…
mdh1418 Apr 3, 2023
9084234
[mono][librarymode] Bundle runtimeconfig.bin
mdh1418 Apr 3, 2023
382a93d
Address feedback
mdh1418 Apr 5, 2023
d4d4193
Consolidate runtimeconfig functions
mdh1418 Apr 6, 2023
e70e61a
[LibraryBuilder] Enable bundling by default
mdh1418 Apr 6, 2023
ecf5ffc
Merge branch 'main' into mono_library_mode_bundling
lewing Apr 12, 2023
fda389a
Merge remote-tracking branch 'upstream/main' into HEAD
mdh1418 Apr 12, 2023
791c743
Handle pdb bundling
mdh1418 Apr 11, 2023
d98c0a5
Default EmitBundle callback function to mono_add_bundled_resource
mdh1418 Apr 11, 2023
6fc54b1
Combine bundled resource types into generic bundled data
mdh1418 Apr 12, 2023
d7c09d0
Add api to free memory dynamically allocated for the bundled resource…
mdh1418 Apr 12, 2023
d1b5f02
Prepend enum and entries with mono
mdh1418 Apr 12, 2023
c0c443c
Move bundling api into separate source and header
mdh1418 Apr 12, 2023
7683ed1
Fix source file name
mdh1418 Apr 18, 2023
b1f3240
Prefix struct with Mono
mdh1418 Apr 18, 2023
ddf6691
Integrate new bundling api into mono debug
mdh1418 Apr 18, 2023
130aff3
Fix types in autoinit
mdh1418 Apr 18, 2023
b8177d0
[mono] Base bundling apis around preallocation of MonoBundled*Resourc…
mdh1418 Apr 22, 2023
60aa110
[mono] Clean up bundled assembly and satellite assembly search
mdh1418 Apr 22, 2023
ba241b5
[mono] Incorporate new bundling APIs into bundled resource retrievals
mdh1418 Apr 22, 2023
cfa60e5
[EmitBundle][task] Add templates for bundled source files
mdh1418 Apr 21, 2023
6fe9912
[EmitBundle] Enable consolidation of bundled resource symbols
mdh1418 Apr 21, 2023
077c020
[EmitBundle] Generate bundled source file to preallocate MonoBundled*…
mdh1418 Apr 21, 2023
1e7ad1c
[EmitBundle] Output symbol to resource type map for populating functi…
mdh1418 Apr 21, 2023
c5eb985
[LibraryBuilder] Generate source file to add preallocated MonoBundled…
mdh1418 Apr 22, 2023
d28ee4b
[LibraryBuilder] Incorporate EmitBundle templates into targets flow
mdh1418 Apr 22, 2023
a796bfb
[EmitBundle] Move bundle registration back into EmitBundle
mdh1418 Apr 24, 2023
364a119
Update invocations of EmitBundle task
mdh1418 Apr 24, 2023
7e48dc6
Merge remote-tracking branch 'upstream/main' into mono_library_mode_b…
mdh1418 Apr 24, 2023
46bd211
Address feedback
mdh1418 May 3, 2023
ddade81
[mono] Prefer C99 compliant types for partially exposed APIs
mdh1418 May 3, 2023
7c0081f
Address various fixups
mdh1418 May 4, 2023
39b5107
Combine preallocation registration and rename to templates
mdh1418 May 4, 2023
69af44c
Prefer symbol data over symfile
mdh1418 May 4, 2023
c3401df
Differentiate resource name and symbol
mdh1418 May 4, 2023
239c649
Update invocations of EmitBundle
mdh1418 May 4, 2023
ae088f2
Add inlined resource getters
mdh1418 May 4, 2023
233025a
Add unique id field for each MonoBundledResource
mdh1418 May 5, 2023
7f4258a
Include culture information for satellite resources
mdh1418 May 5, 2023
a632a73
Generate preallocation and registration source file iff BundleFile pr…
mdh1418 May 5, 2023
429fe75
Generate output itemgroup detailing resource data
mdh1418 May 5, 2023
5aeaef4
Leverage new bundling api from old bundling api and deprecate
mdh1418 May 7, 2023
ccd783b
[mono][debug] Migrate symbol data registration to new bundling api
mdh1418 May 10, 2023
3cf95fc
Remove symbol data from MonoBundleSatelliteAssemblyResource
mdh1418 May 9, 2023
5d265db
Directly determine resource type
mdh1418 May 9, 2023
3206aab
Update bundled header and switch to non internal types
mdh1418 May 10, 2023
a8c5d88
Update Autoinitialization logic to leverage bundled runtimeconfig sym…
mdh1418 May 10, 2023
fbe022e
Integrate header into bundled source
mdh1418 May 10, 2023
3390e90
Add functions to free allocated MonoBundledResources
mdh1418 May 11, 2023
e16e467
Fixup Leverage new bundling api from old bundling api and deprecate
mdh1418 May 11, 2023
684b667
Fixup Address various fixups
mdh1418 May 11, 2023
50fd4ba
Remove unnecessary includes
mdh1418 May 11, 2023
236539a
Fix trailing commas in structs and extra lines in generated files
mdh1418 May 11, 2023
df96a6d
Move specific bundled resource getters into source file
mdh1418 May 11, 2023
befa5d6
Various cleanups
mdh1418 May 11, 2023
c3bb50a
Cleanup logic surrounding EmitBundle task invocations
mdh1418 May 11, 2023
a060748
Rename output metadata to DataLenSymbol and DataLenSymbolValue
mdh1418 May 11, 2023
aff9c60
Simplify bundled resource hashtable insertion
mdh1418 May 12, 2023
c1e9ec1
Cleanup variable instantiation
mdh1418 May 13, 2023
aeaf879
Fixup mono-debug
mdh1418 May 13, 2023
a6b9245
Cleanup header
mdh1418 May 13, 2023
6c7d33d
fixup wasi
mdh1418 May 13, 2023
dfba3f4
fixup template format
mdh1418 May 13, 2023
e8aa970
Add flexibility to auto initialize runtime without bundled runtimeconfig
mdh1418 May 13, 2023
d191d59
Various fixups
mdh1418 May 13, 2023
afaf91a
Use g_free for memory allocated through glib apis
mdh1418 May 15, 2023
3eff6b9
Move condition end tag into LibraryBuilder to avoid empty line and cl…
mdh1418 May 15, 2023
7d3bebd
Add bundled resource getters to access data values without MonoBundle…
mdh1418 May 15, 2023
187855f
Emit one object file for single resource data source file mode
mdh1418 May 16, 2023
7cf6edd
Rename resource size symbol
mdh1418 May 16, 2023
8a78222
Use public friendly API in file linking towards runtime
mdh1418 May 16, 2023
f5ec428
Cleanup types populated through bundled resource getters
mdh1418 May 16, 2023
f309569
Move extern block completely to LibraryBuilder side
mdh1418 May 16, 2023
5001622
Update EmitBundle task invocations to use BundleRegistrationFunctionName
mdh1418 May 16, 2023
0b3b30d
Refactor EmitBundle to account for timezone duplicate resource contents
mdh1418 May 17, 2023
1803ede
Merge remote-tracking branch 'upstream/main' into mono_library_mode_b…
mdh1418 May 17, 2023
2af674d
wip
mdh1418 May 19, 2023
4541530
wip
mdh1418 May 23, 2023
204cae7
WIP
mdh1418 May 24, 2023
a77c39c
[mono] Alias assemblies with known extension in bundled resources has…
mdh1418 May 25, 2023
ec2570d
[tasks] Calculate destination files within EmitBundle task itself
mdh1418 May 25, 2023
4ba29ad
Update invocations of EmitBundle to grab DestinationFiles from output
mdh1418 May 25, 2023
9e5e42f
Guard webcil specific logic
mdh1418 May 25, 2023
d0fafb6
Include OutputDirectory path into output destinationFiles
mdh1418 May 25, 2023
5dad711
Fix debugger tests and memory leak
mdh1418 May 25, 2023
51637a3
Various fixups and Documentation
mdh1418 May 25, 2023
0e33442
Try adding resources with known assembly extensions as dll
mdh1418 May 25, 2023
37b1c82
Revert to custom hash and equal without WEBCIL guard
mdh1418 May 26, 2023
88f90d4
Consolidate file and bundledResource variables
mdh1418 May 30, 2023
e4c6ef6
Add culture metadata to SatelliteAssembly resources
mdh1418 May 30, 2023
dbe7c21
Truncate Encoding for readability
mdh1418 May 30, 2023
8705c97
Enable custom hash for bundling resources on wasm
mdh1418 May 30, 2023
4071c10
Leverage new bundling api for wasm wasi drivers
mdh1418 Jun 1, 2023
a573583
Add helper to dynamically add bundled assembly and satellite_assembly…
mdh1418 Jun 1, 2023
7d1a6bd
Limit when bundled resources can be added and freed
mdh1418 Jun 1, 2023
58eeb95
Restrict MonoBundledResource getters
mdh1418 Jun 1, 2023
4e568b1
Restrict exposure of underlying MonoBundledAssemblyResource modification
mdh1418 Jun 1, 2023
b755fc7
WIP
mdh1418 Jun 2, 2023
e34aff7
Free function chaining.
lateralusX Jun 2, 2023
854c5ec
Fix crash when output parameters are NULL.
lateralusX Jun 2, 2023
4379c37
Fix WASM/WASI build errors.
lateralusX Jun 2, 2023
59ba150
Align bundled resources registration struct
mdh1418 Jun 5, 2023
102c47d
Merge remote-tracking branch 'upstream/main' into mono_library_mode_b…
mdh1418 Jun 5, 2023
560491a
[task] Check PE metadata to determine resource type
mdh1418 Jun 6, 2023
5e41b81
Cleanup Satellite Assembly bundling
mdh1418 Jun 6, 2023
18afeda
Address Feedback
mdh1418 Jun 8, 2023
c2c69ab
Split MonoBundledAssemblyResource getter
mdh1418 Jun 9, 2023
45d2f8b
Addressing more feedback
mdh1418 Jun 13, 2023
b377ff4
Validate OutputDirectory
mdh1418 Jun 13, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 14 additions & 4 deletions src/mono/mono/component/mini-wasm-debugger.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <mono/metadata/mono-debug.h>
#include <mono/metadata/assembly.h>
#include <mono/metadata/assembly-internals.h>
#include <mono/metadata/bundled-resources-internals.h>
#include <mono/metadata/metadata.h>
#include <mono/metadata/metadata-internals.h>
#include <mono/metadata/mono-endian.h>
Expand Down Expand Up @@ -198,7 +199,14 @@ assembly_loaded (MonoProfiler *prof, MonoAssembly *assembly)
return;
}

if (mono_wasm_assembly_already_added(assembly->aname.name))
gboolean already_loaded = mono_bundled_resources_get_assembly_resource_values (assembly->aname.name, NULL, NULL);
pavelsavara marked this conversation as resolved.
Show resolved Hide resolved
if (!already_loaded && !g_str_has_suffix (assembly->aname.name, ".dll")) {
char *assembly_name_with_extension = g_strdup_printf ("%s.dll", assembly->aname.name);
already_loaded = mono_bundled_resources_get_assembly_resource_values (assembly_name_with_extension, NULL, NULL);
g_free (assembly_name_with_extension);
}

if (already_loaded)
return;

if (mono_has_pdb_checksum ((char *) assembly_image->raw_data, assembly_image->raw_data_len)) { //if it's a release assembly we don't need to send to DebuggerProxy
Expand Down Expand Up @@ -435,10 +443,12 @@ mono_wasm_send_dbg_command (int id, MdbgProtCommandSet command_set, int command,
}
else
{
const unsigned char* assembly_bytes = NULL;
unsigned int assembly_size = 0;
int symfile_size = 0;
const unsigned char* assembly_bytes = mono_wasm_get_assembly_bytes (assembly_name, &assembly_size);
const unsigned char* pdb_bytes = mono_get_symfile_bytes_from_bundle (assembly_name, &symfile_size);
mono_bundled_resources_get_assembly_resource_values (assembly_name, &assembly_bytes, &assembly_size);
const unsigned char* pdb_bytes = NULL;
unsigned int symfile_size = 0;
mono_bundled_resources_get_assembly_resource_symbol_values (assembly_name, &pdb_bytes, &symfile_size);
m_dbgprot_buffer_init (&buf, assembly_size + symfile_size);
m_dbgprot_buffer_add_byte_array (&buf, (uint8_t *) assembly_bytes, assembly_size);
m_dbgprot_buffer_add_byte_array (&buf, (uint8_t *) pdb_bytes, symfile_size);
Expand Down
2 changes: 2 additions & 0 deletions src/mono/mono/metadata/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ set(metadata_common_sources
appdomain-icalls.h
assembly.c
assembly-internals.h
bundled-resources.c
bundled-resources-internals.h
cil-coff.h
class.c
class-getters.h
Expand Down
111 changes: 47 additions & 64 deletions src/mono/mono/metadata/assembly.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include <stdlib.h>
#include <mono/metadata/assembly.h>
#include "assembly-internals.h"
#include <mono/metadata/bundled-resources-internals.h>
#include <mono/metadata/image.h>
#include "image-internals.h"
#include "object-internals.h"
Expand Down Expand Up @@ -81,11 +82,6 @@ mono_assemblies_unlock (void)
mono_os_mutex_unlock (&assemblies_mutex);
}

/* If defined, points to the bundled assembly information */
static const MonoBundledAssembly **bundles;

static const MonoBundledSatelliteAssembly **satellite_bundles;

/* Class lazy loading functions */
static GENERATE_TRY_GET_CLASS_WITH_CACHE (debuggable_attribute, "System.Diagnostics", "DebuggableAttribute")

Expand Down Expand Up @@ -711,7 +707,8 @@ mono_assembly_get_assemblyref (MonoImage *image, int index, MonoAssemblyName *an
static MonoAssembly *
search_bundle_for_assembly (MonoAssemblyLoadContext *alc, MonoAssemblyName *aname)
{
if (bundles == NULL && satellite_bundles == NULL)
if (!mono_bundled_resources_contains_assemblies () &&
!mono_bundled_resources_contains_satellite_assemblies ())
return NULL;

MonoImageOpenStatus status;
Expand Down Expand Up @@ -794,15 +791,15 @@ netcore_load_reference (MonoAssemblyName *aname, MonoAssemblyLoadContext *alc, M
}
}

if (bundles != NULL && !is_satellite) {
if (mono_bundled_resources_contains_assemblies () && !is_satellite) {
reference = search_bundle_for_assembly (mono_alc_get_default (), aname);
if (reference) {
mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_ASSEMBLY, "Assembly found in the bundle: '%s'.", aname->name);
goto leave;
}
}

if (satellite_bundles != NULL && is_satellite) {
if (mono_bundled_resources_contains_satellite_assemblies () && is_satellite) {
// Satellite assembly byname requests should be loaded in the same ALC as their parent assembly
size_t name_len = strlen (aname->name);
char *parent_name = NULL;
Expand Down Expand Up @@ -1451,47 +1448,19 @@ absolute_dir (const gchar *filename)
return res;
}

static gboolean
bundled_assembly_match (const char *bundled_name, const char *name)
{
#ifndef ENABLE_WEBCIL
return strcmp (bundled_name, name) == 0;
#else
if (strcmp (bundled_name, name) == 0)
return TRUE;
/* if they want a .dll and we have the matching .webcil, return it */
if (g_str_has_suffix (bundled_name, ".webcil") && g_str_has_suffix (name, ".dll")) {
size_t bprefix = strlen (bundled_name) - strlen (".webcil");
size_t nprefix = strlen (name) - strlen (".dll");
if (bprefix == nprefix && strncmp (bundled_name, name, bprefix) == 0)
return TRUE;
}
/* if they want a .dll and we have the matching .wasm webcil-in-wasm, return it */
if (g_str_has_suffix (bundled_name, MONO_WEBCIL_IN_WASM_EXTENSION) && g_str_has_suffix (name, ".dll")) {
size_t bprefix = strlen (bundled_name) - strlen (MONO_WEBCIL_IN_WASM_EXTENSION);
size_t nprefix = strlen (name) - strlen (".dll");
if (bprefix == nprefix && strncmp (bundled_name, name, bprefix) == 0)
return TRUE;
}
return FALSE;
#endif
}

static MonoImage *
open_from_bundle_internal (MonoAssemblyLoadContext *alc, const char *filename, MonoImageOpenStatus *status, gboolean is_satellite)
open_from_bundle_internal (MonoAssemblyLoadContext *alc, const char *filename, MonoImageOpenStatus *status)
{
if (!bundles)
lateralusX marked this conversation as resolved.
Show resolved Hide resolved
if (!mono_bundled_resources_contains_assemblies ())
return NULL;

MonoImage *image = NULL;
char *name = is_satellite ? g_strdup (filename) : g_path_get_basename (filename);
for (int i = 0; !image && bundles [i]; ++i) {
if (bundled_assembly_match (bundles[i]->name, name)) {
// Since bundled images don't exist on disk, don't give them a legit filename
image = mono_image_open_from_data_internal (alc, (char*)bundles [i]->data, bundles [i]->size, FALSE, status, FALSE, name, NULL);
break;
}
}
char *name = g_path_get_basename (filename);

const uint8_t *data = NULL;
uint32_t size = 0;
if (mono_bundled_resources_get_assembly_resource_values (name, &data, &size))
image = mono_image_open_from_data_internal (alc, (char *)data, size, FALSE, status, FALSE, name, NULL);

g_free (name);
return image;
Expand All @@ -1500,22 +1469,18 @@ open_from_bundle_internal (MonoAssemblyLoadContext *alc, const char *filename, M
static MonoImage *
open_from_satellite_bundle (MonoAssemblyLoadContext *alc, const char *filename, MonoImageOpenStatus *status, const char *culture)
{
if (!satellite_bundles)
lateralusX marked this conversation as resolved.
Show resolved Hide resolved
if (!mono_bundled_resources_contains_satellite_assemblies ())
return NULL;

MonoImage *image = NULL;
char *name = g_strdup (filename);
char *bundle_name = g_strconcat (culture, "/", filename, (const char *)NULL);

for (int i = 0; !image && satellite_bundles [i]; ++i) {
if (bundled_assembly_match (satellite_bundles[i]->name, name) && strcmp (satellite_bundles [i]->culture, culture) == 0) {
char *bundle_name = g_strconcat (culture, "/", name, (const char *)NULL);
image = mono_image_open_from_data_internal (alc, (char *)satellite_bundles [i]->data, satellite_bundles [i]->size, FALSE, status, FALSE, bundle_name, NULL);
g_free (bundle_name);
break;
}
}
const uint8_t *data = NULL;
uint32_t size = 0;
if (mono_bundled_resources_get_satellite_assembly_resource_values (bundle_name, &data, &size))
image = mono_image_open_from_data_internal (alc, (char *)data, size, FALSE, status, FALSE, bundle_name, NULL);

g_free (name);
g_free (bundle_name);
return image;
}

Expand All @@ -1525,7 +1490,7 @@ open_from_satellite_bundle (MonoAssemblyLoadContext *alc, const char *filename,
* \param status return status code
*
* This routine tries to open the assembly specified by \p filename from the
* defined bundles, if found, returns the MonoImage for it, if not found
* bundles hashtable in bundled-resources.c, if found, returns the MonoImage for it, if not found
* returns NULL
*/
MonoImage *
Expand All @@ -1537,12 +1502,10 @@ mono_assembly_open_from_bundle (MonoAssemblyLoadContext *alc, const char *filena
*/
MonoImage *image = NULL;
MONO_ENTER_GC_UNSAFE;
gboolean is_satellite = culture && culture [0] != 0;

if (is_satellite)
if (culture && culture [0] != 0)
image = open_from_satellite_bundle (alc, filename, status, culture);
else
image = open_from_bundle_internal (alc, filename, status, FALSE);
image = open_from_bundle_internal (alc, filename, status);

if (image) {
mono_image_addref (image);
Expand Down Expand Up @@ -1620,7 +1583,7 @@ mono_assembly_request_open (const char *filename, const MonoAssemblyOpenRequest

// If VM built with mkbundle
loaded_from_bundle = FALSE;
if (bundles != NULL || satellite_bundles != NULL) {
if (mono_bundled_resources_contains_assemblies ()) {
/* We don't know the culture of the filename we're loading here, so this call is not culture aware. */
image = mono_assembly_open_from_bundle (load_req.alc, fname, status, NULL);
loaded_from_bundle = image != NULL;
Expand Down Expand Up @@ -3172,11 +3135,16 @@ mono_assembly_get_name_internal (MonoAssembly *assembly)

/**
* mono_register_bundled_assemblies:
* Dynamically allocates MonoBundledAssemblyResources to leverage
* preferred bundling api mono_bundled_resources_add.
*/
void
mono_register_bundled_assemblies (const MonoBundledAssembly **assemblies)
{
bundles = assemblies;
for (int i = 0; assemblies [i]; ++i) {
const MonoBundledAssembly *assembly = assemblies [i];
mono_bundled_resources_add_assembly_resource (assembly->name, assembly->name, (const uint8_t *)assembly->data, (uint32_t)assembly->size, NULL, NULL);
}
}

/**
Expand All @@ -3187,19 +3155,34 @@ mono_create_new_bundled_satellite_assembly (const char *name, const char *cultur
{
MonoBundledSatelliteAssembly *satellite_assembly = g_new0 (MonoBundledSatelliteAssembly, 1);
satellite_assembly->name = strdup (name);
g_assert (satellite_assembly->name);
satellite_assembly->culture = strdup (culture);
g_assert (satellite_assembly->culture);
satellite_assembly->data = data;
satellite_assembly->size = size;
return satellite_assembly;
}

static void
mono_free_bundled_satellite_assembly_func (void *resource, void *free_data)
{
g_free (free_data);
}

/**
* mono_register_bundled_satellite_assemblies:
* Dynamically allocates MonoBundledSatelliteAssemblyResources to leverage
* preferred bundling api mono_bundled_resources_add.
*/
void
mono_register_bundled_satellite_assemblies (const MonoBundledSatelliteAssembly **assemblies)
mono_register_bundled_satellite_assemblies (const MonoBundledSatelliteAssembly **satellite_assemblies)
{
satellite_bundles = assemblies;
for (int i = 0; satellite_assemblies [i]; ++i) {
const MonoBundledSatelliteAssembly *satellite_assembly = satellite_assemblies [i];
char *id = g_strconcat (satellite_assembly->culture, "/", satellite_assembly->name, (const char*)NULL);
g_assert (id);
mono_bundled_resources_add_satellite_assembly_resource (id, satellite_assembly->name, satellite_assembly->culture, (const uint8_t *)satellite_assembly->data, (uint32_t)satellite_assembly->size, mono_free_bundled_satellite_assembly_func, id);
}
}

/**
Expand Down
103 changes: 103 additions & 0 deletions src/mono/mono/metadata/bundled-resources-internals.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
// Licensed to the .NET Foundation under one or more agreements.
mdh1418 marked this conversation as resolved.
Show resolved Hide resolved
// The .NET Foundation licenses this file to you under the MIT license.
//

#ifndef __MONO_METADATA_BUNDLED_RESOURCES_INTERNALS_H__
#define __MONO_METADATA_BUNDLED_RESOURCES_INTERNALS_H__

#include <stdbool.h>
#include <stdint.h>

typedef enum {
MONO_BUNDLED_DATA,
MONO_BUNDLED_ASSEMBLY,
MONO_BUNDLED_SATELLITE_ASSEMBLY,
MONO_BUNDLED_RESOURCE_COUNT
} MonoBundledResourceType;

typedef void (*free_bundled_resource_func)(void *, void*);

typedef struct _MonoBundledResource {
MonoBundledResourceType type;
const char *id;
free_bundled_resource_func free_func;
void *free_data;
} MonoBundledResource;

typedef struct _MonoBundledData {
const char *name;
const uint8_t *data;
uint32_t size;
} MonoBundledData;

typedef struct _MonoBundledDataResource {
MonoBundledResource resource;
MonoBundledData data;
} MonoBundledDataResource;

typedef struct _MonoBundledSymbolData {
const uint8_t *data;
uint32_t size;
} MonoBundledSymbolData;

typedef struct _MonoBundledAssemblyData {
const char *name;
const uint8_t *data;
uint32_t size;
} MonoBundledAssemblyData;

typedef struct _MonoBundledAssemblyResource {
MonoBundledResource resource;
MonoBundledAssemblyData assembly;
MonoBundledSymbolData symbol_data;
} MonoBundledAssemblyResource;

typedef struct _MonoBundledSatelliteAssemblyData {
const char *name;
const char *culture;
const uint8_t *data;
uint32_t size;
} MonoBundledSatelliteAssemblyData;

typedef struct _MonoBundledSatelliteAssemblyResource {
MonoBundledResource resource;
MonoBundledSatelliteAssemblyData satellite_assembly;
} MonoBundledSatelliteAssemblyResource;

void
mono_bundled_resources_free (void);
mdh1418 marked this conversation as resolved.
Show resolved Hide resolved

void
mono_bundled_resources_add (MonoBundledResource **resources_to_bundle, uint32_t len);

bool
mono_bundled_resources_get_assembly_resource_values (const char *id, const uint8_t **data_out, uint32_t *size_out);

bool
mono_bundled_resources_get_assembly_resource_symbol_values (const char *id, const uint8_t **symbol_data_out, uint32_t *symbol_size_out);

bool
mono_bundled_resources_get_satellite_assembly_resource_values (const char *id, const uint8_t **data_out, uint32_t *size_out);

bool
mono_bundled_resources_get_data_resource_values (const char *id, const uint8_t **data_out, uint32_t *size_out);

void
mono_bundled_resources_add_assembly_resource (const char *id, const char *name, const uint8_t *data, uint32_t size, free_bundled_resource_func free_func, void *free_data);

void
mono_bundled_resources_add_assembly_symbol_resource (const char *id, const uint8_t *data, uint32_t size, free_bundled_resource_func free_func, void *free_data);

void
mono_bundled_resources_add_satellite_assembly_resource (const char *id, const char *name, const char *culture, const uint8_t *data, uint32_t size, free_bundled_resource_func free_func, void *free_data);

void
mono_bundled_resources_add_data_resource (const char *id, const char *name, const uint8_t *data, uint32_t size, free_bundled_resource_func free_func, void *free_data);

bool
mono_bundled_resources_contains_assemblies (void);

bool
mono_bundled_resources_contains_satellite_assemblies (void);

#endif /* __MONO_METADATA_BUNDLED_RESOURCES_INTERNALS_H__ */