static gboolean no_exec = FALSE;
static int n_appctx_props;
-static gunichar2 **appctx_keys;
-static gunichar2 **appctx_values;
+static char **appctx_keys;
+static char **appctx_values;
+
+static MonovmRuntimeConfigArguments *runtime_config_arg;
+static MonovmRuntimeConfigArgumentsCleanup runtime_config_cleanup_fn;
+static gpointer runtime_config_user_data;
static const char *
mono_check_corlib_version_internal (void);
static void
add_assembly_to_alc (MonoAssemblyLoadContext *alc, MonoAssembly *ass);
+static const char *
+runtimeconfig_json_get_buffer (MonovmRuntimeConfigArguments *arg, MonoFileMap **file_map, gpointer *buf_handle);
+
+static void
+runtimeconfig_json_read_props (const char *ptr, const char **endp, int nprops, gunichar2 **dest_keys, gunichar2 **dest_values);
+
static MonoLoadFunc load_function = NULL;
/* Lazy class loading functions */
mono_runtime_register_appctx_properties (int nprops, const char **keys, const char **values)
{
n_appctx_props = nprops;
- appctx_keys = g_new0 (gunichar2*, nprops);
- appctx_values = g_new0 (gunichar2*, nprops);
+ appctx_keys = g_new0 (char *, n_appctx_props);
+ appctx_values = g_new0 (char *, n_appctx_props);
for (int i = 0; i < nprops; ++i) {
- appctx_keys [i] = g_utf8_to_utf16 (keys [i], strlen (keys [i]), NULL, NULL, NULL);
- appctx_values [i] = g_utf8_to_utf16 (values [i], strlen (values [i]), NULL, NULL, NULL);
+ appctx_keys [i] = g_strdup (keys [i]);
+ appctx_values [i] = g_strdup (values [i]);
}
}
+void
+mono_runtime_register_runtimeconfig_json_properties (MonovmRuntimeConfigArguments *arg, MonovmRuntimeConfigArgumentsCleanup cleanup_fn, void *user_data)
+{
+ runtime_config_arg = arg;
+ runtime_config_cleanup_fn = cleanup_fn;
+ runtime_config_user_data = user_data;
+}
+
static GENERATE_GET_CLASS_WITH_CACHE (appctx, "System", "AppContext")
/* Install properties into AppContext */
{
ERROR_DECL (error);
gpointer args [3];
+ int n_runtimeconfig_json_props = 0;
+ int n_combined_props;
+ gunichar2 **combined_keys;
+ gunichar2 **combined_values;
+ MonoFileMap *runtimeconfig_json_map = NULL;
+ gpointer runtimeconfig_json_map_handle = NULL;
+ const char *buffer_start = runtimeconfig_json_get_buffer (runtime_config_arg, &runtimeconfig_json_map, &runtimeconfig_json_map_handle);
+ const char *buffer = buffer_start;
MonoMethod *setup = mono_class_get_method_from_name_checked (mono_class_get_appctx_class (), "Setup", 3, 0, error);
g_assert (setup);
// FIXME: TRUSTED_PLATFORM_ASSEMBLIES is very large
+ // Combine and convert properties
+ if (buffer)
+ n_runtimeconfig_json_props = mono_metadata_decode_value (buffer, &buffer);
+
+ n_combined_props = n_appctx_props + n_runtimeconfig_json_props;
+ combined_keys = g_new0 (gunichar2 *, n_combined_props);
+ combined_values = g_new0 (gunichar2 *, n_combined_props);
+
+ for (int i = 0; i < n_appctx_props; ++i) {
+ combined_keys [i] = g_utf8_to_utf16 (appctx_keys [i], -1, NULL, NULL, NULL);
+ combined_values [i] = g_utf8_to_utf16 (appctx_values [i], -1, NULL, NULL, NULL);
+ }
+
+ runtimeconfig_json_read_props (buffer, &buffer, n_runtimeconfig_json_props, combined_keys + n_appctx_props, combined_values + n_appctx_props);
+
/* internal static unsafe void Setup(char** pNames, char** pValues, int count) */
- args [0] = appctx_keys;
- args [1] = appctx_values;
- args [2] = &n_appctx_props;
+ args [0] = combined_keys;
+ args [1] = combined_values;
+ args [2] = &n_combined_props;
mono_runtime_invoke_checked (setup, NULL, args, error);
mono_error_assert_ok (error);
+ if (runtimeconfig_json_map != NULL) {
+ mono_file_unmap ((gpointer)buffer_start, runtimeconfig_json_map_handle);
+ mono_file_map_close (runtimeconfig_json_map);
+ }
+
+ // Call user defined cleanup function
+ if (runtime_config_cleanup_fn)
+ (*runtime_config_cleanup_fn) (runtime_config_arg, runtime_config_user_data);
+
/* No longer needed */
+ for (int i = 0; i < n_combined_props; ++i) {
+ g_free (combined_keys [i]);
+ g_free (combined_values [i]);
+ }
+ g_free (combined_keys);
+ g_free (combined_values);
for (int i = 0; i < n_appctx_props; ++i) {
g_free (appctx_keys [i]);
g_free (appctx_values [i]);
}
g_free (appctx_keys);
g_free (appctx_values);
+
appctx_keys = NULL;
appctx_values = NULL;
+ if (runtime_config_arg) {
+ runtime_config_arg = NULL;
+ runtime_config_cleanup_fn = NULL;
+ runtime_config_user_data = NULL;
+ }
+}
+
+static const char *
+runtimeconfig_json_get_buffer (MonovmRuntimeConfigArguments *arg, MonoFileMap **file_map, gpointer *buf_handle)
+{
+ if (arg != NULL) {
+ switch (arg->kind) {
+ case 0: {
+ char *buffer = NULL;
+ guint64 file_len = 0;
+
+ *file_map = mono_file_map_open (arg->runtimeconfig.name.path);
+ g_assert (*file_map);
+ file_len = mono_file_map_size (*file_map);
+ g_assert (file_len > 0);
+ buffer = (char *)mono_file_map (file_len, MONO_MMAP_READ|MONO_MMAP_PRIVATE, mono_file_map_fd (*file_map), 0, buf_handle);
+ g_assert (buffer);
+ return buffer;
+ }
+ case 1: {
+ *file_map = NULL;
+ *buf_handle = NULL;
+ return arg->runtimeconfig.data.data;
+ }
+ default:
+ g_assert_not_reached ();
+ }
+ }
+
+ *file_map = NULL;
+ *buf_handle = NULL;
+ return NULL;
+}
+
+static void
+runtimeconfig_json_read_props (const char *ptr, const char **endp, int nprops, gunichar2 **dest_keys, gunichar2 **dest_values)
+{
+ for (int i = 0; i < nprops; ++i) {
+ int str_len;
+
+ str_len = mono_metadata_decode_value (ptr, &ptr);
+ dest_keys [i] = g_utf8_to_utf16 (ptr, str_len, NULL, NULL, NULL);
+ ptr += str_len;
+
+ str_len = mono_metadata_decode_value (ptr, &ptr);
+ dest_values [i] = g_utf8_to_utf16 (ptr, str_len, NULL, NULL, NULL);
+ ptr += str_len;
+ }
+
+ *endp = ptr;
}