[WIP] [runtime] Convert WindowsIdentity.GetRoles () icall to coop. (mono/mono#15849)
authorZoltan Varga <vargaz@gmail.com>
Sat, 27 Jul 2019 06:27:24 +0000 (02:27 -0400)
committerGitHub <noreply@github.com>
Sat, 27 Jul 2019 06:27:24 +0000 (02:27 -0400)
* [runtime] Convert WindowsIdentity.GetRoles () icall to coop.

* [runtime] Replace some Buffer icalls with Unsafe methods.

* Fix the windows build.

Commit migrated from https://github.com/mono/mono/commit/9f253249364fa7cfd158647525850c393acc9ec3

src/mono/mono/metadata/icall-decl.h
src/mono/mono/metadata/icall-def.h
src/mono/mono/metadata/icall.c
src/mono/mono/metadata/mono-security-windows-uwp.c
src/mono/mono/metadata/mono-security-windows.c
src/mono/mono/metadata/mono-security.c
src/mono/mono/metadata/security.h

index b3cffed..b787c95 100644 (file)
@@ -165,7 +165,6 @@ ICALL_EXPORT gint64 ves_icall_System_Diagnostics_Process_GetProcessData (int, gi
 ICALL_EXPORT gint64 ves_icall_System_Diagnostics_Stopwatch_GetTimestamp (void);
 ICALL_EXPORT gint64 ves_icall_System_GC_GetTotalMemory (MonoBoolean forceCollection);
 ICALL_EXPORT gint64 ves_icall_System_Threading_Timer_GetTimeMonotonic (void);
-ICALL_EXPORT gint8 ves_icall_System_Buffer_GetByteInternal (MonoArray*, gint32);
 ICALL_EXPORT gpointer ves_icall_System_GCHandle_GetAddrOfPinnedObject (guint32 handle);
 ICALL_EXPORT int ves_icall_Interop_Sys_DoubleToString (double, char*, char*, int);
 ICALL_EXPORT int ves_icall_System_Environment_get_Platform (void);
@@ -178,7 +177,6 @@ ICALL_EXPORT void ves_icall_Mono_Runtime_RegisterReportingForNativeLib (const ch
 ICALL_EXPORT void ves_icall_System_Array_GetGenericValueImpl (MonoArray*, guint32, gpointer);
 ICALL_EXPORT void ves_icall_System_Array_SetGenericValueImpl (MonoArray*, guint32, gpointer);
 ICALL_EXPORT void ves_icall_System_Buffer_MemcpyInternal (gpointer dest, gconstpointer src, gint32 count);
-ICALL_EXPORT void ves_icall_System_Buffer_SetByteInternal (MonoArray*, gint32, gint8);
 ICALL_EXPORT void ves_icall_System_Environment_Exit (int);
 ICALL_EXPORT void ves_icall_System_GCHandle_FreeHandle (guint32 handle);
 ICALL_EXPORT void ves_icall_System_GC_InternalCollect (int generation);
index 08784df..f9dd021 100644 (file)
@@ -228,8 +228,6 @@ ICALL_TYPE(BUFFER, "System.Buffer", BUFFER_1)
 ICALL(BUFFER_1, "InternalBlockCopy", ves_icall_System_Buffer_BlockCopyInternal)
 NOHANDLES(ICALL(BUFFER_5, "InternalMemcpy", ves_icall_System_Buffer_MemcpyInternal))
 ICALL(BUFFER_2, "_ByteLength", ves_icall_System_Buffer_ByteLengthInternal)
-ICALL(BUFFER_3, "_GetByte", ves_icall_System_Buffer_GetByteInternal)
-ICALL(BUFFER_4, "_SetByte", ves_icall_System_Buffer_SetByteInternal)
 
 ICALL_TYPE(CLRCONFIG, "System.CLRConfig", CLRCONFIG_1)
 HANDLES(CLRCONFIG_1, "CheckThrowUnobservedTaskExceptions", ves_icall_System_CLRConfig_CheckThrowUnobservedTaskExceptions, MonoBoolean, 0, ())
@@ -936,7 +934,7 @@ ICALL_TYPE(WINID, "System.Security.Principal.WindowsIdentity", WINID_1)
 HANDLES(WINID_1, "GetCurrentToken", ves_icall_System_Security_Principal_WindowsIdentity_GetCurrentToken, gpointer, 0, ())
 HANDLES(WINID_2, "GetTokenName", ves_icall_System_Security_Principal_WindowsIdentity_GetTokenName, MonoString, 1, (gpointer))
 HANDLES(WINID_3, "GetUserToken", ves_icall_System_Security_Principal_WindowsIdentity_GetUserToken, gpointer, 1, (MonoString))
-ICALL(WINID_4, "_GetRoles", ves_icall_System_Security_Principal_WindowsIdentity_GetRoles)
+HANDLES(WINID_4, "_GetRoles", ves_icall_System_Security_Principal_WindowsIdentity_GetRoles, MonoArray, 1, (gpointer))
 
 ICALL_TYPE(WINIMP, "System.Security.Principal.WindowsImpersonationContext", WINIMP_1)
 HANDLES(WINIMP_1, "CloseToken", ves_icall_System_Security_Principal_WindowsImpersonationContext_CloseToken, MonoBoolean, 1, (gpointer))
index 5e0ee44..4edd598 100644 (file)
@@ -7131,18 +7131,6 @@ ves_icall_System_Buffer_ByteLengthInternal (MonoArray *array)
        return mono_array_get_byte_length (array);
 }
 
-gint8 
-ves_icall_System_Buffer_GetByteInternal (MonoArray *array, gint32 idx) 
-{
-       return mono_array_get_internal (array, gint8, idx);
-}
-
-void 
-ves_icall_System_Buffer_SetByteInternal (MonoArray *array, gint32 idx, gint8 value) 
-{
-       mono_array_set_internal (array, gint8, idx, value);
-}
-
 void
 ves_icall_System_Buffer_MemcpyInternal (gpointer dest, gconstpointer src, gint32 count)
 {
index d6e1751..5923fe0 100644 (file)
@@ -36,14 +36,11 @@ ves_icall_System_Security_Principal_WindowsIdentity_GetCurrentToken (MonoError *
        return mono_security_principal_windows_identity_get_current_token (error);
 }
 
-MonoArray*
-ves_icall_System_Security_Principal_WindowsIdentity_GetRoles (gpointer token)
+MonoArrayHandle
+ves_icall_System_Security_Principal_WindowsIdentity_GetRoles (gpointer token, MonoError *error)
 {
-       // FIXME This is now supported by UWP.
-       ERROR_DECL (error); // FIXMEcoop
        mono_security_win_not_supported ("GetTokenInformation", error);
-       mono_error_set_pending_exception (error); // FIXMEcoop
-       return NULL;
+       return NULL_HANDLE_ARRAY;
 }
 
 gpointer
index 3e6de3c..52348c5 100644 (file)
@@ -152,14 +152,14 @@ ves_icall_System_Security_Principal_WindowsIdentity_GetUserToken (MonoStringHand
 }
 
 #if G_HAVE_API_SUPPORT(HAVE_CLASSIC_WINAPI_SUPPORT)
-MonoArray*
-ves_icall_System_Security_Principal_WindowsIdentity_GetRoles (gpointer token)
+MonoArrayHandle
+ves_icall_System_Security_Principal_WindowsIdentity_GetRoles (gpointer token, MonoError *error)
 {
-       ERROR_DECL (error);
-       MonoArray *array = NULL;
+       MonoArrayHandle array;
+       MonoStringHandle str_h;
        MonoDomain *domain = mono_domain_get ();
-
        gint32 size = 0;
+       gboolean created = FALSE;
 
        GetTokenInformation (token, TokenGroups, NULL, size, (PDWORD)&size);
        if (size > 0) {
@@ -168,25 +168,27 @@ ves_icall_System_Security_Principal_WindowsIdentity_GetRoles (gpointer token)
                        int i=0;
                        int num = tg->GroupCount;
 
-                       array = mono_array_new_checked (domain, mono_get_string_class (), num, error);
-                       if (mono_error_set_pending_exception (error)) {
+                       array = mono_array_new_handle (domain, mono_get_string_class (), num, error);
+                       if (!is_ok (error)) {
                                g_free (tg);
-                               return NULL;
+                               return NULL_HANDLE_ARRAY;
                        }
+                       created = TRUE;
 
+                       str_h = MONO_HANDLE_NEW (MonoString, NULL);
                        for (i=0; i < num; i++) {
                                gint32 size = 0;
                                gunichar2 *uniname = GetSidName (NULL, tg->Groups [i].Sid, &size);
 
                                if (uniname) {
                                        MonoString *str = mono_string_new_utf16_checked (domain, uniname, size, error);
+                                       MONO_HANDLE_ASSIGN_RAW (str_h, str);
                                        if (!is_ok (error)) {
                                                g_free (uniname);
                                                g_free (tg);
-                                               mono_error_set_pending_exception (error);
-                                               return NULL;
+                                               return NULL_HANDLE_ARRAY;
                                        }
-                                       mono_array_setref_internal (array, i, str);
+                                       MONO_HANDLE_ARRAY_SETREF (array, i, str_h);
                                        g_free (uniname);
                                }
                        }
@@ -194,10 +196,10 @@ ves_icall_System_Security_Principal_WindowsIdentity_GetRoles (gpointer token)
                g_free (tg);
        }
 
-       if (!array) {
+       if (!created) {
                /* return empty array of string, i.e. string [0] */
-               array = mono_array_new_checked (domain, mono_get_string_class (), 0, error);
-               mono_error_set_pending_exception (error);
+               array = mono_array_new_handle (domain, mono_get_string_class (), 0, error);
+               return_val_if_nok (error, NULL_HANDLE_ARRAY);
        }
        return array;
 }
index 96a7ce3..9d187a0 100644 (file)
@@ -329,22 +329,15 @@ ves_icall_System_Security_Principal_WindowsIdentity_GetUserToken (MonoStringHand
 */
 
 #ifndef HOST_WIN32
-MonoArray*
-ves_icall_System_Security_Principal_WindowsIdentity_GetRoles (gpointer token)
+MonoArrayHandle
+ves_icall_System_Security_Principal_WindowsIdentity_GetRoles (gpointer token, MonoError *error)
 {
-       ERROR_DECL (error);
-       MonoArray *array = NULL;
        MonoDomain *domain = mono_domain_get ();
 
        /* POSIX-compliant systems should use IsMemberOfGroupId or IsMemberOfGroupName */
        g_warning ("WindowsIdentity._GetRoles should never be called on POSIX");
 
-       if (!array) {
-               /* return empty array of string, i.e. string [0] */
-               array = mono_array_new_checked (domain, mono_get_string_class (), 0, error);
-               mono_error_set_pending_exception (error);
-       }
-       return array;
+       return mono_array_new_handle (domain, mono_get_string_class (), 0, error);
 }
 #endif /* !HOST_WIN32 */
 
index 3204fec..85e16b3 100644 (file)
@@ -25,8 +25,4 @@
 gpointer
 mono_security_principal_windows_identity_get_current_token (MonoError *error);
 
-ICALL_EXPORT
-MonoArray*
-ves_icall_System_Security_Principal_WindowsIdentity_GetRoles (gpointer token);
-
 #endif /* _MONO_METADATA_SECURITY_H_ */