Imported Upstream version 5.14.0.93

Former-commit-id: dda284b8de49fb65cd1a403db6a592e6c68a5e8c
This commit is contained in:
Xamarin Public Jenkins (auto-signing)
2018-05-23 09:42:45 +00:00
parent fb453ffa72
commit 300ff421ef
63 changed files with 880 additions and 65 deletions

View File

@ -4,7 +4,7 @@ include ../../build/rules.make
PROGRAM = mkbundle.exe
OTHER_RES = template.c template_z.c template_main.c
OTHER_RES = template.c template_z.c template_main.c template_common.inc bundle-mono-api.inc
RESOURCE_FILES = $(OTHER_RES)
@ -17,7 +17,7 @@ EXTRA_DISTFILES = $(RESOURCE_FILES)
include ../../build/executable.make
mkbundle.exe: $(RESOURCE_FILES)
$(the_lib): $(RESOURCE_FILES)
test-simple: simple.exe
mono --debug $(the_lib) --simple simple.exe -o foo && ./foo

View File

@ -0,0 +1,40 @@
/* -*- C -*- */
/*
* The structure below should contain pointers to all the Mono runtime functions used throughout ANY
* of the generated C code. The reason for this is to avoid symbol load failures when the generated
* bundle is used by a third party which embeds Mono and loads it dynamically (like
* Xamarin.Android). Third parties should provide their own version of the structure - compatible
* with this one. This is done this way so that we don't have to make the API here public in any way
* or form and thus maintain freedom to break it as we see needed.
*
* Whenever ANY change to this structure is made, the `init_default_mono_api_struct` and
* `validate_api_struct` functions found in `template_common.inc` MUST be updated.
*
* The `mkbundle_log_error` must be provided by the embedding third party in order to implement a
* logging method specific to that third party (e.g. Xamarin.Android cannot use `fprintf` since it
* won't show up in the logcat).
*/
typedef struct BundleMonoAPI
{
void (*mono_register_bundled_assemblies) (const MonoBundledAssembly **assemblies);
void (*mono_register_config_for_assembly) (const char* assembly_name, const char* config_xml);
void (*mono_jit_set_aot_mode) (int mode);
void (*mono_aot_register_module) (void* aot_info);
void (*mono_config_parse_memory) (const char *buffer);
void (*mono_register_machine_config) (const char *config_xml);
} BundleMonoAPI;
#ifdef USE_DEFAULT_MONO_API_STRUCT
#include <stdio.h>
#include <stdarg.h>
static void
mkbundle_log_error (const char *format, ...)
{
va_list ap;
va_start (ap, format);
vfprintf (stderr, format, ap);
va_end (ap);
}
#endif // USE_DEFAULT_MONO_API_STRUCT

View File

@ -103,7 +103,8 @@ class MakeBundle {
""
};
static string target_server = "https://download.mono-project.com/runtimes/raw/";
static string mono_api_struct_file;
static int Main (string [] args)
{
List<string> sources = new List<string> ();
@ -453,6 +454,13 @@ class MakeBundle {
aot_compile = true;
static_link = true;
break;
case "--mono-api-struct-path":
if (i+1 == top) {
Console.WriteLine ("Usage: --mono-api-struct-path <path/to/file>");
return 1;
}
mono_api_struct_file = args [++i];
break;
default:
sources.Add (args [i]);
break;
@ -841,8 +849,6 @@ typedef struct {
const unsigned char *data;
const unsigned int size;
} MonoBundledAssembly;
void mono_register_bundled_assemblies (const MonoBundledAssembly **assemblies);
void mono_register_config_for_assembly (const char* assembly_name, const char* config_xml);
");
// These values are part of the public API, so they are expected not to change
@ -859,6 +865,20 @@ void mono_register_config_for_assembly (const char* assembly_name, cons
tc.WriteLine ("#include <mono/jit/jit.h>\n");
}
Stream template_stream;
if (String.IsNullOrEmpty (mono_api_struct_file)) {
tc.WriteLine ("#define USE_DEFAULT_MONO_API_STRUCT");
template_stream = typeof (MakeBundle).Assembly.GetManifestResourceStream ("bundle-mono-api.inc");
} else {
template_stream = File.OpenRead (mono_api_struct_file);
}
StreamReader s;
using (s = new StreamReader (template_stream)) {
tc.Write (s.ReadToEnd ());
}
template_stream.Dispose ();
if (compress) {
tc.WriteLine ("typedef struct _compressed_data {");
tc.WriteLine ("\tMonoBundledAssembly assembly;");
@ -1008,6 +1028,12 @@ void mono_register_config_for_assembly (const char* assembly_name, cons
}
tc.WriteLine ("\tNULL\n};\n");
// This must go before any attempt to access `mono_api`
using (template_stream = System.Reflection.Assembly.GetAssembly (typeof(MakeBundle)).GetManifestResourceStream ("template_common.inc")) {
using (s = new StreamReader (template_stream)) {
tc.Write (s.ReadToEnd ());
}
}
// AOT baked in plus loader
foreach (string asm in aot_names){
@ -1016,7 +1042,7 @@ void mono_register_config_for_assembly (const char* assembly_name, cons
tc.WriteLine ("\nstatic void install_aot_modules (void) {\n");
foreach (string asm in aot_names){
tc.WriteLine ("\tmono_aot_register_module (mono_aot_module_{0}_info);\n", asm);
tc.WriteLine ("\tmono_api.mono_aot_register_module (mono_aot_module_{0}_info);\n", asm);
}
string enum_aot_mode;
@ -1033,7 +1059,7 @@ void mono_register_config_for_assembly (const char* assembly_name, cons
default:
throw new Exception ("Unsupported AOT mode");
}
tc.WriteLine ("\tmono_jit_set_aot_mode ({0});", enum_aot_mode);
tc.WriteLine ("\tmono_api.mono_jit_set_aot_mode ({0});", enum_aot_mode);
tc.WriteLine ("\n}\n");
@ -1048,12 +1074,12 @@ void mono_register_config_for_assembly (const char* assembly_name, cons
tc.WriteLine ("\nstatic void install_dll_config_files (void) {\n");
foreach (string[] ass in config_names){
tc.WriteLine ("\tmono_register_config_for_assembly (\"{0}\", assembly_config_{1});\n", ass [0], ass [1]);
tc.WriteLine ("\tmono_api.mono_register_config_for_assembly (\"{0}\", assembly_config_{1});\n", ass [0], ass [1]);
}
if (config_file != null)
tc.WriteLine ("\tmono_config_parse_memory (&system_config);\n");
tc.WriteLine ("\tmono_api.mono_config_parse_memory (&system_config);\n");
if (machine_config_file != null)
tc.WriteLine ("\tmono_register_machine_config (&machine_config);\n");
tc.WriteLine ("\tmono_api.mono_register_machine_config (&machine_config);\n");
tc.WriteLine ("}\n");
if (config_dir != null)
@ -1061,16 +1087,16 @@ void mono_register_config_for_assembly (const char* assembly_name, cons
else
tc.WriteLine ("static const char *config_dir = NULL;");
Stream template_stream;
if (compress) {
template_stream = System.Reflection.Assembly.GetAssembly (typeof(MakeBundle)).GetManifestResourceStream ("template_z.c");
} else {
template_stream = System.Reflection.Assembly.GetAssembly (typeof(MakeBundle)).GetManifestResourceStream ("template.c");
}
StreamReader s = new StreamReader (template_stream);
string template = s.ReadToEnd ();
tc.Write (template);
using (s = new StreamReader (template_stream)) {
tc.Write (s.ReadToEnd ());
}
template_stream.Dispose ();
if (!nomain && custom_main == null) {
Stream template_main_stream = System.Reflection.Assembly.GetAssembly (typeof(MakeBundle)).GetManifestResourceStream ("template_main.c");

View File

@ -1,7 +1,7 @@
void mono_mkbundle_init ()
{
install_dll_config_files ();
mono_register_bundled_assemblies(bundled);
mono_api.mono_register_bundled_assemblies(bundled);
install_aot_modules ();
}

View File

@ -0,0 +1,61 @@
/* -*- C -*- */
#include <stdlib.h>
static BundleMonoAPI mono_api;
void initialize_mono_api (const BundleMonoAPI *info)
{
if (info == NULL) {
mkbundle_log_error ("mkbundle: missing Mono API info\n");
exit (1);
}
mono_api.mono_register_bundled_assemblies = info->mono_register_bundled_assemblies;
mono_api.mono_register_config_for_assembly = info->mono_register_config_for_assembly;
mono_api.mono_jit_set_aot_mode = info->mono_jit_set_aot_mode;
mono_api.mono_aot_register_module = info->mono_aot_register_module;
mono_api.mono_config_parse_memory = info->mono_config_parse_memory;
mono_api.mono_register_machine_config = info->mono_register_machine_config;
}
static int
validate_api_pointer (const char *name, void *ptr)
{
if (ptr != NULL)
return 0;
mkbundle_log_error ("mkbundle: Mono API pointer '%s' missing\n", name);
return 1;
}
static void
validate_api_struct ()
{
int missing = 0;
missing += validate_api_pointer ("mono_register_bundled_assemblies", mono_api.mono_register_bundled_assemblies);
missing += validate_api_pointer ("mono_register_config_for_assembly", mono_api.mono_register_config_for_assembly);
missing += validate_api_pointer ("mono_jit_set_aot_mode", mono_api.mono_jit_set_aot_mode);
missing += validate_api_pointer ("mono_aot_register_module", mono_api.mono_aot_register_module);
missing += validate_api_pointer ("mono_config_parse_memory", mono_api.mono_config_parse_memory);
missing += validate_api_pointer ("mono_register_machine_config", mono_api.mono_register_machine_config);
if (missing <= 0)
return;
mkbundle_log_error ("mkbundle: bundle not initialized properly, %d Mono API pointers are missing\n", missing);
exit (1);
}
static void
init_default_mono_api_struct ()
{
#ifdef USE_DEFAULT_MONO_API_STRUCT
mono_api.mono_register_bundled_assemblies = mono_register_bundled_assemblies;
mono_api.mono_register_config_for_assembly = mono_register_config_for_assembly;
mono_api.mono_jit_set_aot_mode = mono_jit_set_aot_mode;
mono_api.mono_aot_register_module = mono_aot_register_module;
mono_api.mono_config_parse_memory = mono_config_parse_memory;
mono_api.mono_register_machine_config = mono_register_machine_config;
#endif // USE_DEFAULT_MONO_API_STRUCT
}

View File

@ -48,6 +48,8 @@ void mono_mkbundle_init ()
Bytef *buffer;
int nbundles;
init_default_mono_api_struct ();
validate_api_struct ();
install_dll_config_files ();
ptr = (CompressedAssembly **) compressed;
@ -56,6 +58,12 @@ void mono_mkbundle_init ()
nbundles++;
bundled = (MonoBundledAssembly **) malloc (sizeof (MonoBundledAssembly *) * (nbundles + 1));
if (bundled == NULL) {
// May fail...
mkbundle_log_error ("mkbundle: out of memory");
exit (1);
}
bundled_ptr = bundled;
ptr = (CompressedAssembly **) compressed;
while (*ptr != NULL) {
@ -81,5 +89,5 @@ void mono_mkbundle_init ()
ptr++;
}
*bundled_ptr = NULL;
mono_register_bundled_assemblies((const MonoBundledAssembly **) bundled);
mono_api.mono_register_bundled_assemblies((const MonoBundledAssembly **) bundled);
}