Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[reflection] Add GC Unsafe transitions on embedding API functions #52769

Merged
merged 1 commit into from
May 18, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 45 additions & 11 deletions src/mono/mono/metadata/reflection.c
Original file line number Diff line number Diff line change
Expand Up @@ -242,10 +242,13 @@ mono_assembly_get_object_handle (MonoAssembly *assembly, MonoError *error)
MonoReflectionModule*
mono_module_get_object (MonoDomain *domain, MonoImage *image)
{
MonoReflectionModuleHandle result;
HANDLE_FUNCTION_ENTER ();
MONO_ENTER_GC_UNSAFE;
ERROR_DECL (error);
MonoReflectionModuleHandle result = mono_module_get_object_handle (image, error);
result = mono_module_get_object_handle (image, error);
mono_error_cleanup (error);
MONO_EXIT_GC_UNSAFE;
HANDLE_FUNCTION_RETURN_OBJ (result);
}

Expand Down Expand Up @@ -308,10 +311,13 @@ mono_module_get_object_handle (MonoImage *image, MonoError *error)
MonoReflectionModule*
mono_module_file_get_object (MonoDomain *domain, MonoImage *image, int table_index)
{
MonoReflectionModuleHandle result;
HANDLE_FUNCTION_ENTER ();
MONO_ENTER_GC_UNSAFE;
ERROR_DECL (error);
MonoReflectionModuleHandle result = mono_module_file_get_object_handle (image, table_index, error);
result = mono_module_file_get_object_handle (image, table_index, error);
mono_error_cleanup (error);
MONO_EXIT_GC_UNSAFE;
HANDLE_FUNCTION_RETURN_OBJ (result);
}

Expand Down Expand Up @@ -692,10 +698,13 @@ mono_method_clear_object (MonoMethod *method)
MonoReflectionField*
mono_field_get_object (MonoDomain *domain, MonoClass *klass, MonoClassField *field)
{
MonoReflectionFieldHandle result;
HANDLE_FUNCTION_ENTER ();
MONO_ENTER_GC_UNSAFE;
ERROR_DECL (error);
MonoReflectionFieldHandle result = mono_field_get_object_handle (klass, field, error);
result = mono_field_get_object_handle (klass, field, error);
mono_error_cleanup (error);
MONO_EXIT_GC_UNSAFE;
HANDLE_FUNCTION_RETURN_OBJ (result);
}

Expand Down Expand Up @@ -770,10 +779,13 @@ mono_field_get_object_checked (MonoClass *klass, MonoClassField *field, MonoErro
MonoReflectionProperty*
mono_property_get_object (MonoDomain *domain, MonoClass *klass, MonoProperty *property)
{
MonoReflectionPropertyHandle result;
HANDLE_FUNCTION_ENTER ();
MONO_ENTER_GC_UNSAFE;
ERROR_DECL (error);
MonoReflectionPropertyHandle result = mono_property_get_object_handle (klass, property, error);
result = mono_property_get_object_handle (klass, property, error);
mono_error_cleanup (error);
MONO_EXIT_GC_UNSAFE;
HANDLE_FUNCTION_RETURN_OBJ (result);
}

Expand Down Expand Up @@ -834,10 +846,13 @@ mono_property_get_object_checked (MonoClass *klass, MonoProperty *property, Mono
MonoReflectionEvent*
mono_event_get_object (MonoDomain *domain, MonoClass *klass, MonoEvent *event)
{
MonoReflectionEventHandle result;
HANDLE_FUNCTION_ENTER ();
MONO_ENTER_GC_UNSAFE;
ERROR_DECL (error);
MonoReflectionEventHandle result = mono_event_get_object_handle (klass, event, error);
result = mono_event_get_object_handle (klass, event, error);
mono_error_cleanup (error);
MONO_EXIT_GC_UNSAFE;
HANDLE_FUNCTION_RETURN_OBJ (result);
}

Expand Down Expand Up @@ -1134,10 +1149,13 @@ mono_param_get_objects_internal (MonoMethod *method, MonoClass *refclass, MonoEr
MonoArray*
mono_param_get_objects (MonoDomain *domain, MonoMethod *method)
{
MonoArrayHandle result;
HANDLE_FUNCTION_ENTER ();
MONO_ENTER_GC_UNSAFE;
ERROR_DECL (error);
MonoArrayHandle result = mono_param_get_objects_internal (method, NULL, error);
result = mono_param_get_objects_internal (method, NULL, error);
mono_error_assert_ok (error);
MONO_EXIT_GC_UNSAFE;
HANDLE_FUNCTION_RETURN_OBJ (result);
}

Expand Down Expand Up @@ -1202,10 +1220,13 @@ add_exception_handling_clause_to_array (MonoMethodHeader *header, int idx, MonoA
MonoReflectionMethodBody*
mono_method_body_get_object (MonoDomain *domain, MonoMethod *method)
{
MonoReflectionMethodBodyHandle result;
HANDLE_FUNCTION_ENTER ();
MONO_ENTER_GC_UNSAFE;
ERROR_DECL (error);
MonoReflectionMethodBodyHandle result = mono_method_body_get_object_handle (method, error);
result = mono_method_body_get_object_handle (method, error);
mono_error_cleanup (error);
MONO_EXIT_GC_UNSAFE;
HANDLE_FUNCTION_RETURN_OBJ (result);
}

Expand Down Expand Up @@ -1902,9 +1923,12 @@ mono_identifier_unescape_info (MonoTypeNameParse *info)
int
mono_reflection_parse_type (char *name, MonoTypeNameParse *info)
{
gboolean result;
MONO_ENTER_GC_UNSAFE;
ERROR_DECL (error);
gboolean result = mono_reflection_parse_type_checked (name, info, error);
result = mono_reflection_parse_type_checked (name, info, error);
mono_error_cleanup (error);
MONO_EXIT_GC_UNSAFE;
return result ? 1 : 0;
}

Expand Down Expand Up @@ -2133,9 +2157,12 @@ mono_reflection_get_type_internal (MonoAssemblyLoadContext *alc, MonoImage *root
MonoType*
mono_reflection_get_type (MonoImage* image, MonoTypeNameParse *info, gboolean ignorecase, gboolean *type_resolve)
{
MonoType *result;
MONO_ENTER_GC_UNSAFE;
ERROR_DECL (error);
MonoType *result = mono_reflection_get_type_with_rootimage (mono_alc_get_default (), image, image, info, ignorecase, TRUE, type_resolve, error);
result = mono_reflection_get_type_with_rootimage (mono_alc_get_default (), image, image, info, ignorecase, TRUE, type_resolve, error);
mono_error_cleanup (error);
MONO_EXIT_GC_UNSAFE;
return result;
}

Expand Down Expand Up @@ -2333,13 +2360,16 @@ mono_reflection_free_type_info (MonoTypeNameParse *info)
MonoType*
mono_reflection_type_from_name (char *name, MonoImage *image)
{
MonoType *result;
MONO_ENTER_GC_UNSAFE;
ERROR_DECL (error);

MonoAssemblyLoadContext *alc = mono_alc_get_default ();

MonoType * const result = mono_reflection_type_from_name_checked (name, alc, image, error);
result = mono_reflection_type_from_name_checked (name, alc, image, error);

mono_error_cleanup (error);
MONO_EXIT_GC_UNSAFE;
return result;
}

Expand Down Expand Up @@ -2385,11 +2415,15 @@ mono_reflection_type_from_name_checked (char *name, MonoAssemblyLoadContext *alc
guint32
mono_reflection_get_token (MonoObject *obj_raw)
{
guint32 result;
HANDLE_FUNCTION_ENTER ();
MONO_ENTER_GC_UNSAFE;
MONO_HANDLE_DCL (MonoObject, obj);
ERROR_DECL (error);
guint32 result = mono_reflection_get_token_checked (obj, error);
result = mono_reflection_get_token_checked (obj, error);
mono_error_assert_ok (error);

MONO_EXIT_GC_UNSAFE;
HANDLE_FUNCTION_RETURN_VAL (result);
}

Expand Down