From 96d90cdffc5187c965f3363b25131fd2a889bd07 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Aleksey=20Kliger=20=28=CE=BBgeek=29?= Date: Thu, 19 Mar 2020 19:00:09 -0400 Subject: [PATCH] [mono] Enter GC Unsafe mode in some string allocation functions (#33754) All these functions are MONO_RT_EXTERNAL_ONLY and they all allocate managed objects. Fixes a coop state machine assertion if an embedder calls the function and it needs to take the GC lock to do a collection. --- src/mono/mono/metadata/object.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/mono/mono/metadata/object.c b/src/mono/mono/metadata/object.c index 5fbaeaf..8d28bb6 100644 --- a/src/mono/mono/metadata/object.c +++ b/src/mono/mono/metadata/object.c @@ -6607,13 +6607,12 @@ mono_string_empty_handle (MonoDomain *domain) MonoString * mono_string_new_utf16 (MonoDomain *domain, const mono_unichar2 *text, gint32 len) { - MONO_REQ_GC_UNSAFE_MODE; - - ERROR_DECL (error); MonoString *res = NULL; + MONO_ENTER_GC_UNSAFE; + ERROR_DECL (error); res = mono_string_new_utf16_checked (domain, text, len, error); mono_error_cleanup (error); - + MONO_EXIT_GC_UNSAFE; return res; } @@ -6710,10 +6709,12 @@ mono_string_new_utf32 (MonoDomain *domain, const mono_unichar4 *text, gint32 len MonoString * mono_string_new_size (MonoDomain *domain, gint32 len) { + MonoString *str; + MONO_ENTER_GC_UNSAFE; ERROR_DECL (error); - MonoString *str = mono_string_new_size_checked (domain, len, error); + str = mono_string_new_size_checked (domain, len, error); mono_error_cleanup (error); - + MONO_EXIT_GC_UNSAFE; return str; } @@ -7546,9 +7547,12 @@ mono_string_intern (MonoString *str_raw) MonoString* mono_ldstr (MonoDomain *domain, MonoImage *image, guint32 idx) { + MonoString *result; + MONO_ENTER_GC_UNSAFE; ERROR_DECL (error); - MonoString *result = mono_ldstr_checked (domain, image, idx, error); + result = mono_ldstr_checked (domain, image, idx, error); mono_error_cleanup (error); + MONO_EXIT_GC_UNSAFE; return result; } -- 2.7.4