From ae9192f96febdb5ceea3b73d6aa226d601006371 Mon Sep 17 00:00:00 2001 From: Jay Krell Date: Thu, 5 Dec 2019 10:10:29 -0800 Subject: [PATCH] [netcore] Remove approx. 10 icalls. (#18018) * [netcore] Remove ves_icall_System_Runtime_InteropServices_Marshal_PtrToStringUni and _len icalls. They are implemented in C#. The C# is equivalent to the C, and could be used for classic runtime, except for the treatment of large/negative lengths. * Remove a few more icalls. Instead of ifdef and leaving them uncompiled when compiling netcore, declare them and put asserts in them. --- mono/eglib/glib.h | 8 +++++++ mono/metadata/icall-def-netcore.h | 10 -------- mono/metadata/icall.c | 5 ++++ mono/metadata/marshal-windows.c | 5 ++++ mono/metadata/marshal.c | 48 +++++++++++++++++++++++++++++++++++++++ 5 files changed, 66 insertions(+), 10 deletions(-) diff --git a/mono/eglib/glib.h b/mono/eglib/glib.h index 898360eb2f0..29bb96be47a 100644 --- a/mono/eglib/glib.h +++ b/mono/eglib/glib.h @@ -948,6 +948,14 @@ GUnicodeBreakType g_unichar_break_type (gunichar c); #define g_assert_not_reached() G_STMT_START { mono_assertion_message_unreachable (__FILE__, __LINE__); eg_unreachable(); } G_STMT_END +#if ENABLE_NETCORE +#define g_assert_netcore() /* nothing */ +#define g_assert_not_netcore() g_assert (!"This function should only be called on mono-notnetcore.") +#else +#define g_assert_netcore() g_assert (!"This function should only be called on mono-netcore.") +#define g_assert_not_netcore() /* nothing */ +#endif + /* f is format -- like printf and scanf * Where you might have said: * if (!(expr)) diff --git a/mono/metadata/icall-def-netcore.h b/mono/metadata/icall-def-netcore.h index 39637bed325..4a4bab5fb43 100644 --- a/mono/metadata/icall-def-netcore.h +++ b/mono/metadata/icall-def-netcore.h @@ -339,7 +339,6 @@ HANDLES(GCH_4, "InternalSet", ves_icall_System_GCHandle_InternalSet, void, 2, (g ICALL_TYPE(MARSHAL, "System.Runtime.InteropServices.Marshal", MARSHAL_2) HANDLES(MARSHAL_2, "AllocCoTaskMem", ves_icall_System_Runtime_InteropServices_Marshal_AllocCoTaskMem, gpointer, 1, (int)) -HANDLES(MARSHAL_51,"AllocCoTaskMemSize(uintptr)", ves_icall_System_Runtime_InteropServices_Marshal_AllocCoTaskMemSize, gpointer, 1, (gsize)) HANDLES(MARSHAL_3, "AllocHGlobal", ves_icall_System_Runtime_InteropServices_Marshal_AllocHGlobal, gpointer, 1, (gsize)) NOHANDLES(ICALL(MARSHAL_50, "BufferToBSTR", ves_icall_System_Runtime_InteropServices_Marshal_BufferToBSTR)) HANDLES(MARSHAL_4, "DestroyStructure", ves_icall_System_Runtime_InteropServices_Marshal_DestroyStructure, void, 2, (gpointer, MonoReflectionType)) @@ -351,24 +350,15 @@ HANDLES(MARSHAL_10, "GetFunctionPointerForDelegateInternal", ves_icall_System_Ru NOHANDLES(ICALL(MARSHAL_11, "GetLastWin32Error", ves_icall_System_Runtime_InteropServices_Marshal_GetLastWin32Error)) HANDLES(MARSHAL_48a, "IsPinnableType", ves_icall_System_Runtime_InteropServices_Marshal_IsPinnableType, MonoBoolean, 1, (MonoReflectionType)) HANDLES(MARSHAL_12, "OffsetOf", ves_icall_System_Runtime_InteropServices_Marshal_OffsetOf, int, 2, (MonoReflectionType, MonoString)) -HANDLES(MARSHAL_14, "PrelinkAll", ves_icall_System_Runtime_InteropServices_Marshal_PrelinkAll, void, 1, (MonoReflectionType)) HANDLES(MARSHAL_13, "PrelinkInternal", ves_icall_System_Runtime_InteropServices_Marshal_Prelink, void, 1, (MonoReflectionMethod)) -HANDLES(MARSHAL_15, "PtrToStringAnsi(intptr)", ves_icall_System_Runtime_InteropServices_Marshal_PtrToStringAnsi, MonoString, 1, (const_char_ptr)) -HANDLES(MARSHAL_16, "PtrToStringAnsi(intptr,int)", ves_icall_System_Runtime_InteropServices_Marshal_PtrToStringAnsi_len, MonoString, 2, (const_char_ptr, gint32)) HANDLES(MARSHAL_17, "PtrToStringBSTR", ves_icall_System_Runtime_InteropServices_Marshal_PtrToStringBSTR, MonoString, 1, (mono_bstr_const)) -HANDLES(MARSHAL_18, "PtrToStringUni(intptr)", ves_icall_System_Runtime_InteropServices_Marshal_PtrToStringUni, MonoString, 1, (const_gunichar2_ptr)) -HANDLES(MARSHAL_19, "PtrToStringUni(intptr,int)", ves_icall_System_Runtime_InteropServices_Marshal_PtrToStringUni_len, MonoString, 2, (const_gunichar2_ptr, gint32)) HANDLES(MARSHAL_20, "PtrToStructureInternal", ves_icall_System_Runtime_InteropServices_Marshal_PtrToStructureInternal, void, 3, (gconstpointer, MonoObject, MonoBoolean)) HANDLES(MARSHAL_43, "ReAllocCoTaskMem", ves_icall_System_Runtime_InteropServices_Marshal_ReAllocCoTaskMem, gpointer, 2, (gpointer, int)) HANDLES(MARSHAL_23, "ReAllocHGlobal", ves_icall_System_Runtime_InteropServices_Marshal_ReAllocHGlobal, gpointer, 2, (gpointer, gsize)) NOHANDLES(ICALL(MARSHAL_29a, "SetLastWin32Error", ves_icall_System_Runtime_InteropServices_Marshal_SetLastWin32Error)) HANDLES(MARSHAL_30, "SizeOf", ves_icall_System_Runtime_InteropServices_Marshal_SizeOf, guint32, 1, (MonoReflectionType)) HANDLES(MARSHAL_31, "SizeOfHelper", ves_icall_System_Runtime_InteropServices_Marshal_SizeOfHelper, guint32, 2, (MonoReflectionType, MonoBoolean)) -HANDLES(MARSHAL_32, "StringToHGlobalAnsi", ves_icall_System_Runtime_InteropServices_Marshal_StringToHGlobalAnsi, char_ptr, 2, (const_gunichar2_ptr, int)) -HANDLES(MARSHAL_33, "StringToHGlobalUni", ves_icall_System_Runtime_InteropServices_Marshal_StringToHGlobalUni, gunichar2_ptr, 2, (const_gunichar2_ptr, int)) HANDLES(MARSHAL_34, "StructureToPtr", ves_icall_System_Runtime_InteropServices_Marshal_StructureToPtr, void, 3, (MonoObject, gpointer, MonoBoolean)) -HANDLES(MARSHAL_41, "copy_from_unmanaged_fixed", ves_icall_System_Runtime_InteropServices_Marshal_copy_from_unmanaged, void, 5, (gconstpointer, gint32, MonoArray, gint32, gpointer)) -HANDLES(MARSHAL_42, "copy_to_unmanaged_fixed", ves_icall_System_Runtime_InteropServices_Marshal_copy_to_unmanaged, void, 5, (MonoArray, gint32, gpointer, gint32, gconstpointer)) ICALL_TYPE(NATIVEL, "System.Runtime.InteropServices.NativeLibrary", NATIVEL_1) HANDLES(NATIVEL_1, "FreeLib", ves_icall_System_Runtime_InteropServices_NativeLibrary_FreeLib, void, 1, (gpointer)) diff --git a/mono/metadata/icall.c b/mono/metadata/icall.c index 9e80cb861ae..2954d65415d 100644 --- a/mono/metadata/icall.c +++ b/mono/metadata/icall.c @@ -8590,8 +8590,13 @@ ves_icall_System_Runtime_InteropServices_Marshal_Prelink (MonoReflectionMethodHa } void +ves_icall_System_Runtime_InteropServices_Marshal_PrelinkAll (MonoReflectionTypeHandle type, MonoError *error); + +void ves_icall_System_Runtime_InteropServices_Marshal_PrelinkAll (MonoReflectionTypeHandle type, MonoError *error) { + g_assert_not_netcore (); + error_init (error); MonoClass *klass = mono_class_from_mono_type_internal (MONO_HANDLE_GETVAL (type, type)); MonoMethod* m; diff --git a/mono/metadata/marshal-windows.c b/mono/metadata/marshal-windows.c index ed42392af6a..70c340245a8 100644 --- a/mono/metadata/marshal-windows.c +++ b/mono/metadata/marshal-windows.c @@ -57,8 +57,13 @@ mono_marshal_realloc_co_task_mem (gpointer ptr, size_t size) } char* +ves_icall_System_Runtime_InteropServices_Marshal_StringToHGlobalAnsi (const gunichar2 *s, int length, MonoError *error); + +char* ves_icall_System_Runtime_InteropServices_Marshal_StringToHGlobalAnsi (const gunichar2 *s, int length, MonoError *error) { + g_assert_not_netcore (); + // FIXME pass mono_utf16_to_utf8 an allocator to avoid double alloc/copy. char* tres = mono_utf16_to_utf8 (s, length, error); diff --git a/mono/metadata/marshal.c b/mono/metadata/marshal.c index 59a0c2eb9d2..8b18779d3df 100644 --- a/mono/metadata/marshal.c +++ b/mono/metadata/marshal.c @@ -5149,8 +5149,14 @@ copy_managed_common (MonoArrayHandle managed, gconstpointer native, gint32 start void ves_icall_System_Runtime_InteropServices_Marshal_copy_to_unmanaged (MonoArrayHandle src, gint32 start_index, + gpointer dest, gint32 length, gconstpointer managed_source_addr, MonoError *error); + +void +ves_icall_System_Runtime_InteropServices_Marshal_copy_to_unmanaged (MonoArrayHandle src, gint32 start_index, gpointer dest, gint32 length, gconstpointer managed_source_addr, MonoError *error) { + g_assert_not_netcore (); + guint32 gchandle = 0; gsize const bytes = copy_managed_common (src, dest, start_index, length, (gpointer*)&managed_source_addr, &gchandle, error); if (bytes) @@ -5160,8 +5166,14 @@ ves_icall_System_Runtime_InteropServices_Marshal_copy_to_unmanaged (MonoArrayHan void ves_icall_System_Runtime_InteropServices_Marshal_copy_from_unmanaged (gconstpointer src, gint32 start_index, + MonoArrayHandle dest, gint32 length, gpointer managed_dest_addr, MonoError *error); + +void +ves_icall_System_Runtime_InteropServices_Marshal_copy_from_unmanaged (gconstpointer src, gint32 start_index, MonoArrayHandle dest, gint32 length, gpointer managed_dest_addr, MonoError *error) { + g_assert_not_netcore (); + guint32 gchandle = 0; gsize const bytes = copy_managed_common (dest, src, start_index, length, &managed_dest_addr, &gchandle, error); if (bytes) @@ -5170,16 +5182,26 @@ ves_icall_System_Runtime_InteropServices_Marshal_copy_from_unmanaged (gconstpoin } MonoStringHandle +ves_icall_System_Runtime_InteropServices_Marshal_PtrToStringAnsi (const char *ptr, MonoError *error); + +MonoStringHandle ves_icall_System_Runtime_InteropServices_Marshal_PtrToStringAnsi (const char *ptr, MonoError *error) { + g_assert_not_netcore (); + if (!ptr) return NULL_HANDLE_STRING; return mono_string_new_handle (mono_domain_get (), ptr, error); } MonoStringHandle +ves_icall_System_Runtime_InteropServices_Marshal_PtrToStringAnsi_len (const char *ptr, gint32 len, MonoError *error); + +MonoStringHandle ves_icall_System_Runtime_InteropServices_Marshal_PtrToStringAnsi_len (const char *ptr, gint32 len, MonoError *error) { + g_assert_not_netcore (); + if (!ptr) { mono_error_set_argument_null (error, "ptr", ""); return NULL_HANDLE_STRING; @@ -5188,8 +5210,13 @@ ves_icall_System_Runtime_InteropServices_Marshal_PtrToStringAnsi_len (const char } MonoStringHandle +ves_icall_System_Runtime_InteropServices_Marshal_PtrToStringUni (const gunichar2 *ptr, MonoError *error); + +MonoStringHandle ves_icall_System_Runtime_InteropServices_Marshal_PtrToStringUni (const gunichar2 *ptr, MonoError *error) { + g_assert_not_netcore (); + gsize len = 0; const gunichar2 *t = ptr; @@ -5206,8 +5233,13 @@ ves_icall_System_Runtime_InteropServices_Marshal_PtrToStringUni (const gunichar2 } MonoStringHandle +ves_icall_System_Runtime_InteropServices_Marshal_PtrToStringUni_len (const gunichar2 *ptr, gint32 len, MonoError *error); + +MonoStringHandle ves_icall_System_Runtime_InteropServices_Marshal_PtrToStringUni_len (const gunichar2 *ptr, gint32 len, MonoError *error) { + g_assert_not_netcore (); + if (!ptr) { mono_error_set_argument_null (error, "ptr", ""); return NULL_HANDLE_STRING; @@ -5435,9 +5467,15 @@ ves_icall_System_Runtime_InteropServices_Marshal_OffsetOf (MonoReflectionTypeHan } #ifndef HOST_WIN32 + +char* +ves_icall_System_Runtime_InteropServices_Marshal_StringToHGlobalAnsi (const gunichar2 *s, int length, MonoError *error); + char* ves_icall_System_Runtime_InteropServices_Marshal_StringToHGlobalAnsi (const gunichar2 *s, int length, MonoError *error) { + g_assert_not_netcore (); + return mono_utf16_to_utf8 (s, length, error); } @@ -5452,8 +5490,13 @@ mono_marshal_alloc_hglobal (size_t size, MonoError *error) #endif /* !HOST_WIN32 */ gunichar2* +ves_icall_System_Runtime_InteropServices_Marshal_StringToHGlobalUni (const gunichar2 *s, int length, MonoError *error); + +gunichar2* ves_icall_System_Runtime_InteropServices_Marshal_StringToHGlobalUni (const gunichar2 *s, int length, MonoError *error) { + g_assert_not_netcore (); + if (!s) return NULL; @@ -5603,8 +5646,13 @@ ves_icall_System_Runtime_InteropServices_Marshal_AllocCoTaskMem (int size, MonoE } void* +ves_icall_System_Runtime_InteropServices_Marshal_AllocCoTaskMemSize (gsize size, MonoError *error); + +void* ves_icall_System_Runtime_InteropServices_Marshal_AllocCoTaskMemSize (gsize size, MonoError *error) { + g_assert_not_netcore (); + void *res = mono_marshal_alloc_co_task_mem (size); if (!res) -- 2.11.4.GIT