From: Zoltan Varga Date: Tue, 4 Aug 2020 22:18:21 +0000 (-0400) Subject: [wasm] Make mono_wasm_get_obj_type () GC safe by doing all object access before calli... X-Git-Tag: submit/tizen/20210909.063632~6225 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=7d3b804b6078a647835bfaf697369109855093b5;p=platform%2Fupstream%2Fdotnet%2Fruntime.git [wasm] Make mono_wasm_get_obj_type () GC safe by doing all object access before calling into the runtime. (#40312) Part of the fix for https://github.com/dotnet/runtime/issues/40132. --- diff --git a/src/mono/wasm/runtime/driver.c b/src/mono/wasm/runtime/driver.c index fec7260..0400c39 100644 --- a/src/mono/wasm/runtime/driver.c +++ b/src/mono/wasm/runtime/driver.c @@ -587,6 +587,11 @@ mono_wasm_get_obj_type (MonoObject *obj) if (!obj) return 0; + /* Process obj before calling into the runtime, class_from_name () can invoke managed code */ + MonoClass *klass = mono_object_get_class (obj); + MonoType *type = mono_class_get_type (klass); + obj = NULL; + if (!datetime_class) datetime_class = mono_class_from_name (mono_get_corlib(), "System", "DateTime"); if (!datetimeoffset_class) @@ -598,9 +603,6 @@ mono_wasm_get_obj_type (MonoObject *obj) if (!safehandle_class) safehandle_class = mono_class_from_name (mono_get_corlib(), "System.Runtime.InteropServices", "SafeHandle"); - MonoClass *klass = mono_object_get_class (obj); - MonoType *type = mono_class_get_type (klass); - switch (mono_type_get_type (type)) { // case MONO_TYPE_CHAR: prob should be done not as a number? case MONO_TYPE_BOOLEAN: