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

[Mono] UnsafeAccessorAttribute non-generic support for field #88626

Merged
merged 35 commits into from
Jul 14, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
bc9d6ed
Detect an UnsafeAccessorAttribute for method with interpreter
fanyang-mono Jul 5, 2023
1643710
Change field to property
fanyang-mono Jul 6, 2023
b0def6c
Get Kind from typed_args
fanyang-mono Jul 6, 2023
0c51e8a
define MonoUnsafeAccessorKind enum
lambdageek Jul 6, 2023
94ce7d2
Add the frontend for JIT
fanyang-mono Jul 6, 2023
a49a8e0
Add mono_marshal_get_unsafe_accessor_wrapper and WRAPPER_SUBTYPE_UNSA…
lambdageek Jul 7, 2023
4701689
[interp] get the unsafe accessor wrapper
lambdageek Jul 7, 2023
495ce38
fix: skip visibility in unsafe accessor wrappers
lambdageek Jul 7, 2023
35c4d45
fix: decode the length and copy the name from UnsafeAccessorAttribute
lambdageek Jul 7, 2023
0c8f4da
[mini] compile wrapper
lambdageek Jul 10, 2023
8d039e6
[aot] Emit unsafe accessor wrappers to the AOT image
lambdageek Jul 10, 2023
080559a
Add the method to emit wrapper for field
fanyang-mono Jul 10, 2023
2ec266b
Fix typo
fanyang-mono Jul 10, 2023
8571969
Remove assertion for interpreter
fanyang-mono Jul 10, 2023
b7e35c6
Fix format and replace assertion with proper exception
fanyang-mono Jul 10, 2023
449aa6f
Free the memory and throw proper NotImplementedException
fanyang-mono Jul 10, 2023
da84576
Enable StaticField and Field tests
fanyang-mono Jul 10, 2023
23a4d9a
Remove unused variables
fanyang-mono Jul 11, 2023
342c8d4
Only allow static method
fanyang-mono Jul 11, 2023
375d460
Return immediately once hit an exception
fanyang-mono Jul 11, 2023
9222fd2
Free cinfo at the right location
fanyang-mono Jul 11, 2023
ab2e8c5
Disable test, cause Constructor kind is not supported yet.
fanyang-mono Jul 11, 2023
2f8031a
Stop inlining UnsafeAccessor wrapper for interpreter
fanyang-mono Jul 11, 2023
10e43de
Merge branch 'main' into unsafeAccessor
fanyang-mono Jul 12, 2023
4d874c3
Revert inlining change
fanyang-mono Jul 12, 2023
ade7c78
Update exception message
fanyang-mono Jul 12, 2023
58822ca
Fix loading static field and add static status check and a test
fanyang-mono Jul 13, 2023
3686590
Add another test and address feedback
fanyang-mono Jul 13, 2023
8afb00a
Update src/tests/baseservices/compilerservices/UnsafeAccessors/Unsafe…
fanyang-mono Jul 13, 2023
a3f9e77
Update src/tests/baseservices/compilerservices/UnsafeAccessors/Unsafe…
fanyang-mono Jul 13, 2023
9f6b532
Update src/tests/baseservices/compilerservices/UnsafeAccessors/Unsafe…
fanyang-mono Jul 13, 2023
0c15ccd
Update src/tests/baseservices/compilerservices/UnsafeAccessors/Unsafe…
fanyang-mono Jul 13, 2023
f21b78e
Update src/tests/baseservices/compilerservices/UnsafeAccessors/Unsafe…
fanyang-mono Jul 13, 2023
781f512
Address more review feedback
fanyang-mono Jul 13, 2023
17febef
Fix function call to field
fanyang-mono Jul 13, 2023
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
13 changes: 9 additions & 4 deletions src/mono/mono/metadata/marshal-lightweight.c
Original file line number Diff line number Diff line change
Expand Up @@ -2343,16 +2343,21 @@ emit_unsafe_accessor_field_wrapper (MonoMethodBuilder *mb, MonoMethod *accessor_
return;
}

mono_mb_emit_ldarg (mb, 0);

MonoClassField *target_field = mono_class_get_field_from_name_full (target_class, member_name, NULL);
if (target_field == NULL || target_field->type->type != ret_type->type) {
if (target_field == NULL || !mono_metadata_type_equal_full (target_field->type, m_class_get_byval_arg (mono_class_from_mono_type_internal (ret_type)), TRUE)) {
mono_mb_emit_exception_full (mb, "System", "MissingFieldException",
g_strdup_printf("No '%s' in '%s'. Or the type of '%s' doesn't match", member_name, m_class_get_name (target_class), member_name));
return;
}
gboolean is_field_static = !!(target_field->type->attrs & FIELD_ATTRIBUTE_STATIC);
if ((kind == MONO_UNSAFE_ACCESSOR_FIELD && is_field_static) || (kind == MONO_UNSAFE_ACCESSOR_STATIC_FIELD && !is_field_static)) {
mono_mb_emit_exception_full (mb, "System", "MissingFieldException", g_strdup_printf("The status of static of field '%s' in '%s' doesn't match", member_name, m_class_get_name (target_class)));
fanyang-mono marked this conversation as resolved.
Show resolved Hide resolved
return;
}

mono_mb_emit_op (mb, CEE_LDFLDA, target_field);
if (kind == MONO_UNSAFE_ACCESSOR_FIELD)
mono_mb_emit_ldarg (mb, 0);
mono_mb_emit_op (mb, kind == MONO_UNSAFE_ACCESSOR_FIELD ? CEE_LDFLDA : CEE_LDSFLDA, target_field);
mono_mb_emit_byte (mb, CEE_RET);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,9 @@ public static void Verify_InvalidTargetUnsafeAccessor()
AssertExtensions.ThrowsMissingMemberException<MissingFieldException>(
isNativeAot ? null : DoesNotExist,
() => FieldNotFound(null));
AssertExtensions.ThrowsMissingMemberException<MissingFieldException>(
isNativeAot ? null : DoesNotExist,
fanyang-mono marked this conversation as resolved.
Show resolved Hide resolved
() => FieldNotFoundStaticStatus(null));
AssertExtensions.ThrowsMissingMemberException<MissingFieldException>(
isNativeAot ? null : DoesNotExist,
() => StaticFieldNotFound(null));
Expand All @@ -406,6 +409,9 @@ public static void Verify_InvalidTargetUnsafeAccessor()
[UnsafeAccessor(UnsafeAccessorKind.Field, Name=DoesNotExist)]
extern static ref string FieldNotFound(UserDataClass d);

[UnsafeAccessor(UnsafeAccessorKind.Field, Name=UserDataClass.StaticFieldName)]
extern static ref string FieldNotFoundStaticStatus(UserDataClass d);
fanyang-mono marked this conversation as resolved.
Show resolved Hide resolved

[UnsafeAccessor(UnsafeAccessorKind.StaticField, Name=DoesNotExist)]
extern static ref string StaticFieldNotFound(UserDataClass d);

Expand Down
Loading