From: Aleksey Kliger Date: Mon, 1 May 2017 19:43:02 +0000 (-0400) Subject: [runtime] Use coop handles for some simple icalls X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=commitdiff_plain;h=419331f455e776b0440f41b69e4bfccf6b538111;p=mono.git [runtime] Use coop handles for some simple icalls - System.Text.EncodingHelper.InternalCodePage - System.Runtime.InteropServices.Marshal.PtrToStringAnsi(intptr) - Use coop handles for ves_icall_System_Configuration_DefaultConfig_get_machine_config_path - Use coop handles for ves_icall_System_Configuration_InternalConfigurationHost_get_bundled_app_config - Use coop handles for System.Web.Util.ICalls.GetMachineInstallDirectory --- diff --git a/mono/metadata/icall-def.h b/mono/metadata/icall-def.h index 61e342435cb..37e349224a4 100644 --- a/mono/metadata/icall-def.h +++ b/mono/metadata/icall-def.h @@ -172,11 +172,11 @@ ICALL(CLRCONFIG_1, "CheckThrowUnobservedTaskExceptions", ves_icall_System_CLRCon ICALL_TYPE(DEFAULTC, "System.Configuration.DefaultConfig", DEFAULTC_1) HANDLES(ICALL(DEFAULTC_1, "get_bundled_machine_config", ves_icall_System_Configuration_DefaultConfig_get_bundled_machine_config)) -ICALL(DEFAULTC_2, "get_machine_config_path", ves_icall_System_Configuration_DefaultConfig_get_machine_config_path) +HANDLES(ICALL(DEFAULTC_2, "get_machine_config_path", ves_icall_System_Configuration_DefaultConfig_get_machine_config_path)) /* Note that the below icall shares the same function as DefaultConfig uses */ ICALL_TYPE(INTCFGHOST, "System.Configuration.InternalConfigurationHost", INTCFGHOST_1) -ICALL(INTCFGHOST_1, "get_bundled_app_config", get_bundled_app_config) +HANDLES(ICALL(INTCFGHOST_1, "get_bundled_app_config", ves_icall_System_Configuration_InternalConfigurationHost_get_bundled_app_config)) HANDLES(ICALL(INTCFGHOST_2, "get_bundled_machine_config", ves_icall_System_Configuration_InternalConfigurationHost_get_bundled_machine_config)) ICALL_TYPE(CONSOLE, "System.ConsoleDriver", CONSOLE_1) @@ -267,7 +267,7 @@ ICALL(ENV_2, "GetCommandLineArgs", ves_icall_System_Environment_GetCommandLineAr ICALL(ENV_3, "GetEnvironmentVariableNames", ves_icall_System_Environment_GetEnvironmentVariableNames) ICALL(ENV_31, "GetIs64BitOperatingSystem", ves_icall_System_Environment_GetIs64BitOperatingSystem) ICALL(ENV_4, "GetLogicalDrivesInternal", ves_icall_System_Environment_GetLogicalDrives ) -ICALL(ENV_5, "GetMachineConfigPath", ves_icall_System_Configuration_DefaultConfig_get_machine_config_path) +HANDLES(ICALL(ENV_5, "GetMachineConfigPath", ves_icall_System_Configuration_DefaultConfig_get_machine_config_path)) HANDLES(ICALL(ENV_51, "GetNewLine", ves_icall_System_Environment_get_NewLine)) HANDLES(ICALL(ENV_6, "GetOSVersionString", ves_icall_System_Environment_GetOSVersionString)) ICALL(ENV_6a, "GetPageSize", mono_pagesize) @@ -700,7 +700,7 @@ ICALL(MARSHAL_48, "IsComObject", ves_icall_System_Runtime_InteropServices_Marsha ICALL(MARSHAL_12, "OffsetOf", ves_icall_System_Runtime_InteropServices_Marshal_OffsetOf) ICALL(MARSHAL_13, "Prelink", ves_icall_System_Runtime_InteropServices_Marshal_Prelink) ICALL(MARSHAL_14, "PrelinkAll", ves_icall_System_Runtime_InteropServices_Marshal_PrelinkAll) -ICALL(MARSHAL_15, "PtrToStringAnsi(intptr)", ves_icall_System_Runtime_InteropServices_Marshal_PtrToStringAnsi) +HANDLES(ICALL(MARSHAL_15, "PtrToStringAnsi(intptr)", ves_icall_System_Runtime_InteropServices_Marshal_PtrToStringAnsi)) ICALL(MARSHAL_16, "PtrToStringAnsi(intptr,int)", ves_icall_System_Runtime_InteropServices_Marshal_PtrToStringAnsi_len) ICALL(MARSHAL_17, "PtrToStringBSTR", ves_icall_System_Runtime_InteropServices_Marshal_PtrToStringBSTR) ICALL(MARSHAL_18, "PtrToStringUni(intptr)", ves_icall_System_Runtime_InteropServices_Marshal_PtrToStringUni) @@ -869,7 +869,7 @@ ICALL(STRING_10, "InternalIntern", ves_icall_System_String_InternalIntern) ICALL(STRING_11, "InternalIsInterned", ves_icall_System_String_InternalIsInterned) ICALL_TYPE(TENC, "System.Text.EncodingHelper", TENC_1) -ICALL(TENC_1, "InternalCodePage", ves_icall_System_Text_EncodingHelper_InternalCodePage) +HANDLES(ICALL(TENC_1, "InternalCodePage", ves_icall_System_Text_EncodingHelper_InternalCodePage)) ICALL_TYPE(UNORM, "System.Text.Normalization", UNORM_1) ICALL(UNORM_1, "load_normalization_resource", ves_icall_System_Text_Normalization_load_normalization_resource) @@ -1050,8 +1050,8 @@ ICALL(VALUET_1, "InternalEquals", ves_icall_System_ValueType_Equals) ICALL(VALUET_2, "InternalGetHashCode", ves_icall_System_ValueType_InternalGetHashCode) ICALL_TYPE(WEBIC, "System.Web.Util.ICalls", WEBIC_1) -ICALL(WEBIC_1, "GetMachineConfigPath", ves_icall_System_Configuration_DefaultConfig_get_machine_config_path) -ICALL(WEBIC_2, "GetMachineInstallDirectory", ves_icall_System_Web_Util_ICalls_get_machine_install_dir) +HANDLES(ICALL(WEBIC_1, "GetMachineConfigPath", ves_icall_System_Configuration_DefaultConfig_get_machine_config_path)) +HANDLES(ICALL(WEBIC_2, "GetMachineInstallDirectory", ves_icall_System_Web_Util_ICalls_get_machine_install_dir)) HANDLES(ICALL(WEBIC_3, "GetUnmanagedResourcesPtr", ves_icall_get_resources_ptr)) #ifndef DISABLE_COM diff --git a/mono/metadata/icall.c b/mono/metadata/icall.c index 2bbde0097c6..33376d73492 100644 --- a/mono/metadata/icall.c +++ b/mono/metadata/icall.c @@ -6822,9 +6822,10 @@ static const char *encodings [] = { * 1 at entry, and we can not compute a suitable code page number, * returns the code page as a string */ -ICALL_EXPORT MonoString* -ves_icall_System_Text_EncodingHelper_InternalCodePage (gint32 *int_code_page) +ICALL_EXPORT MonoStringHandle +ves_icall_System_Text_EncodingHelper_InternalCodePage (gint32 *int_code_page, MonoError *error) { + error_init (error); const char *cset; const char *p; char *c; @@ -6866,9 +6867,9 @@ ves_icall_System_Text_EncodingHelper_InternalCodePage (gint32 *int_code_page) g_free (codepage); if (want_name && *int_code_page == -1) - return mono_string_new (mono_domain_get (), cset); + return mono_string_new_handle (mono_domain_get (), cset, error); else - return NULL; + return MONO_HANDLE_CAST (MonoString, NULL_HANDLE); } ICALL_EXPORT MonoBoolean @@ -7096,53 +7097,54 @@ ves_icall_RuntimeMethodHandle_GetFunctionPointer (MonoMethod *method) return result; } -ICALL_EXPORT MonoString * -ves_icall_System_Configuration_DefaultConfig_get_machine_config_path (void) +ICALL_EXPORT MonoStringHandle +ves_icall_System_Configuration_DefaultConfig_get_machine_config_path (MonoError *error) { - MonoString *mcpath; + error_init (error); gchar *path; path = g_build_path (G_DIR_SEPARATOR_S, mono_get_config_dir (), "mono", mono_get_runtime_info ()->framework_version, "machine.config", NULL); mono_icall_make_platform_path (path); - mcpath = mono_string_new (mono_domain_get (), path); + MonoStringHandle mcpath = mono_string_new_handle (mono_domain_get (), path, error); g_free (path); - g_assert (mcpath); + mono_error_assert_ok (error); return mcpath; } -/* this is an icall */ -static MonoString * -get_bundled_app_config (void) +static MonoStringHandle +ves_icall_System_Configuration_InternalConfigurationHost_get_bundled_app_config (MonoError *error) { - MonoError error; + error_init (error); const gchar *app_config; MonoDomain *domain; - MonoString *file; gchar *config_file_name, *config_file_path; gsize len, config_file_path_length, config_ext_length; gchar *module; domain = mono_domain_get (); - file = domain->setup->configuration_file; - if (!file || file->length == 0) + MonoStringHandle file = MONO_HANDLE_NEW (MonoString, domain->setup->configuration_file); + if (MONO_HANDLE_IS_NULL (file) || MONO_HANDLE_GETVAL (file, length) == 0) return NULL; // Retrieve config file and remove the extension - config_file_name = mono_string_to_utf8_checked (file, &error); - if (mono_error_set_pending_exception (&error)) - return NULL; + config_file_name = mono_string_handle_to_utf8 (file, error); + return_val_if_nok (error, MONO_HANDLE_CAST (MonoString, NULL_HANDLE)); + config_file_path = mono_portability_find_file (config_file_name, TRUE); if (!config_file_path) config_file_path = config_file_name; config_file_path_length = strlen (config_file_path); config_ext_length = strlen (".config"); - if (config_file_path_length <= config_ext_length) - return NULL; + if (config_file_path_length <= config_ext_length) { + if (config_file_name != config_file_path) + g_free (config_file_name); + return MONO_HANDLE_CAST (MonoString, NULL_HANDLE); + } len = config_file_path_length - config_ext_length; module = (gchar *)g_malloc0 (len + 1); @@ -7156,9 +7158,9 @@ get_bundled_app_config (void) g_free (config_file_path); if (!app_config) - return NULL; + return MONO_HANDLE_CAST (MonoString, NULL_HANDLE); - return mono_string_new (mono_domain_get (), app_config); + return mono_string_new_handle (mono_domain_get (), app_config, error); } static MonoStringHandle @@ -7194,17 +7196,17 @@ ves_icall_System_Configuration_InternalConfigurationHost_get_bundled_machine_con } -ICALL_EXPORT MonoString * -ves_icall_System_Web_Util_ICalls_get_machine_install_dir (void) +ICALL_EXPORT MonoStringHandle +ves_icall_System_Web_Util_ICalls_get_machine_install_dir (MonoError *error) { - MonoString *ipath; + error_init (error); gchar *path; path = g_path_get_dirname (mono_get_config_dir ()); mono_icall_make_platform_path (path); - ipath = mono_string_new (mono_domain_get (), path); + MonoStringHandle ipath = mono_string_new_handle (mono_domain_get (), path, error); g_free (path); return ipath; diff --git a/mono/metadata/marshal.c b/mono/metadata/marshal.c index 9bcb521c068..41dded95f02 100644 --- a/mono/metadata/marshal.c +++ b/mono/metadata/marshal.c @@ -10930,13 +10930,14 @@ ves_icall_System_Runtime_InteropServices_Marshal_copy_from_unmanaged (gpointer s memcpy (dest_addr, src, length * element_size); } -MonoString * -ves_icall_System_Runtime_InteropServices_Marshal_PtrToStringAnsi (char *ptr) +MonoStringHandle +ves_icall_System_Runtime_InteropServices_Marshal_PtrToStringAnsi (char *ptr, MonoError *error) { + error_init (error); if (ptr == NULL) - return NULL; + return MONO_HANDLE_CAST (MonoString, NULL_HANDLE); else - return mono_string_new (mono_domain_get (), ptr); + return mono_string_new_handle (mono_domain_get (), ptr, error); } MonoString * diff --git a/mono/metadata/marshal.h b/mono/metadata/marshal.h index 2469701a84a..57018b828d4 100644 --- a/mono/metadata/marshal.h +++ b/mono/metadata/marshal.h @@ -436,8 +436,8 @@ void ves_icall_System_Runtime_InteropServices_Marshal_copy_from_unmanaged (gpointer src, gint32 start_index, MonoArray *dest, gint32 length); -MonoString * -ves_icall_System_Runtime_InteropServices_Marshal_PtrToStringAnsi (char *ptr); +MonoStringHandle +ves_icall_System_Runtime_InteropServices_Marshal_PtrToStringAnsi (char *ptr, MonoError *error); MonoString * ves_icall_System_Runtime_InteropServices_Marshal_PtrToStringAnsi_len (char *ptr, gint32 len);