[wasm] Make mono_wasm_get_obj_type () GC safe by doing all object access before calli...
authorZoltan Varga <vargaz@gmail.com>
Tue, 4 Aug 2020 22:18:21 +0000 (18:18 -0400)
committerGitHub <noreply@github.com>
Tue, 4 Aug 2020 22:18:21 +0000 (18:18 -0400)
Part of the fix for https://github.com/dotnet/runtime/issues/40132.

src/mono/wasm/runtime/driver.c

index fec7260..0400c39 100644 (file)
@@ -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: