diff options
author | Jay Krell <jaykrell@microsoft.com> | 2018-12-13 01:40:47 +0300 |
---|---|---|
committer | Aleksey Kliger (λgeek) <akliger@gmail.com> | 2018-12-14 23:22:22 +0300 |
commit | 1503ca49525e0846bd21e454dae1c5ae2e3afcb0 (patch) | |
tree | 8331b87c2a9973778be07b152c38cf8787316d73 | |
parent | d8faa8e8819b9f7b5a060bb972609e792808293e (diff) |
Cache MonoMethod in ves_icall_System_Security_SecureString_EncryptInternal / ves_icall_System_Security_SecureString_DecryptInternal.
-rw-r--r-- | mono/metadata/mono-security.c | 41 |
1 files changed, 22 insertions, 19 deletions
diff --git a/mono/metadata/mono-security.c b/mono/metadata/mono-security.c index fcf33f60727..65f5d1c8589 100644 --- a/mono/metadata/mono-security.c +++ b/mono/metadata/mono-security.c @@ -595,41 +595,44 @@ ves_icall_System_Security_Policy_Evidence_IsAuthenticodePresent (MonoReflectionA /* System.Security.SecureString related internal calls */ static MonoImage *system_security_assembly; +static MonoMethod *mono_method_securestring_decrypt; +static MonoMethod *mono_method_securestring_encrypt; static void -mono_invoke_protected_memory_method (MonoArrayHandle data, MonoObjectHandle scope, gboolean encrypt, MonoError *error) +mono_invoke_protected_memory_method (MonoArrayHandle data, MonoObjectHandle scope, + const char *method_name, MonoMethod **method, MonoError *error) { - if (system_security_assembly == NULL) { - system_security_assembly = mono_image_loaded ("System.Security"); - if (!system_security_assembly) { - MonoAssemblyOpenRequest req; - mono_assembly_request_prepare (&req.request, sizeof (req), MONO_ASMCTX_DEFAULT); - MonoAssembly *sa = mono_assembly_request_open ("System.Security.dll", &req, NULL); - g_assert (sa); - system_security_assembly = mono_assembly_get_image_internal (sa); + if (!*method) { + if (system_security_assembly == NULL) { + system_security_assembly = mono_image_loaded ("System.Security"); + if (!system_security_assembly) { + MonoAssemblyOpenRequest req; + mono_assembly_request_prepare (&req.request, sizeof (req), MONO_ASMCTX_DEFAULT); + MonoAssembly *sa = mono_assembly_request_open ("System.Security.dll", &req, NULL); + g_assert (sa); + system_security_assembly = mono_assembly_get_image_internal (sa); + } } + MonoClass *klass = mono_class_load_from_name (system_security_assembly, + "System.Security.Cryptography", "ProtectedMemory"); + *method = mono_class_get_method_from_name_checked (klass, method_name, 2, 0, error); + mono_error_assert_ok (error); + g_assert (*method); } - - MonoClass *klass = mono_class_load_from_name (system_security_assembly, - "System.Security.Cryptography", "ProtectedMemory"); - MonoMethod *method = mono_class_get_method_from_name_checked (klass, encrypt ? "Protect" : "Unprotect", 2, 0, error); - mono_error_assert_ok (error); - g_assert (method); void *params [ ] = { MONO_HANDLE_RAW (data), MONO_HANDLE_RAW (scope) // MemoryProtectionScope.SameProcess }; - mono_runtime_invoke_handle_void (method, NULL_HANDLE, params, error); + mono_runtime_invoke_handle_void (*method, NULL_HANDLE, params, error); } - void ves_icall_System_Security_SecureString_DecryptInternal (MonoArrayHandle data, MonoObjectHandle scope, MonoError *error) { - mono_invoke_protected_memory_method (data, scope, FALSE, error); + mono_invoke_protected_memory_method (data, scope, "Unprotect", &mono_method_securestring_decrypt, error); } void ves_icall_System_Security_SecureString_EncryptInternal (MonoArrayHandle data, MonoObjectHandle scope, MonoError *error) { - mono_invoke_protected_memory_method (data, scope, TRUE, error); + mono_invoke_protected_memory_method (data, scope, "Protect", &mono_method_securestring_encrypt, error); } |