Implement System.Runtime.CompilerServices.DisabledRuntimeMarshallingAttribute on CoreCLR-family of runtimes/type systems#63320
Conversation
…ribute is applied.
…n bugs are present. Fix a bug that was uncovered when the tests were refactored.
|
Note regarding the This serves as a reminder for when your PR is modifying a ref *.cs file and adding/modifying public APIs, to please make sure the API implementation in the src *.cs file is documented with triple slash comments, so the PR reviewers can sign off that change. |
|
I had a few open questions for reviewers:
As there is no current alternative for varargs support today, I wanted to raise the question so we can decide whether or not we need to explicitly block it.
Since
|
Is the plan to eventually apply this on all of our assemblies produced from dotnet/runtime? If so, is that tracked separately? |
|
As we will be updating the spec for user-defined value type marshalling with DllImportGenerator to require this attribute, we will update the assemblies defined in dotnet/runtime to have this attribute applied as part of that change. |
AaronRobinsonMSFT
left a comment
There was a problem hiding this comment.
This is a great start. Now that we are moving toward reconciling blittable and unmanaged, we should also update the BOTR.
Great question. I consider it part of the marshalling logic. I think it should apply. I would however like to see how C++/CLI plays with this attribute. I'm not sure how far one would get with C++/CLI if it were applied in general.
I'd prefer this to be disabled.
I think disabling this is appropriate. |
|
|
||
| private MethodIL EmitIL() | ||
| { | ||
| if (_targetMethod.HasCustomAttribute("System.Runtime.InteropServices", "LCIDConversionAttribute")) |
Will the analyzer be available for a better developer experience? |
@jkoritzinsky Could you add the new tests to issues.targets to disable them on Mono for now. |
elinor-fung
left a comment
There was a problem hiding this comment.
I would be pro blocking/disabling ArgIterator/varargs/auto-layout when runtime marshalling is disabled.
MichalStrehovsky
left a comment
There was a problem hiding this comment.
Crossgen2/NativeAOT changes look good! Thank you!
|
|
||
| if (m_type_is_byref(t)) { | ||
| if (emit_exception) | ||
| get_marshal_cb ()->emit_marshal_directive_exception (m, argnum, "Cannot marshal managed references when the built-in marshalling system is disabled."); |
There was a problem hiding this comment.
Should such error messages include the assembly name?
There was a problem hiding this comment.
Since the P/Invoke method will be included in the stack trace, I don't think we need to include the assembly name here.
|
@vargaz could you review mono changes? |
| /// - LCIDConversionAttribute support is disabled. | ||
| /// </remarks> | ||
| [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] | ||
| public sealed class DisableRuntimeMarshallingAttribute : Attribute |
There was a problem hiding this comment.
Have you tried to mark CoreLib with this and see what breaks? Should we add it to CoreLib as part to this PR?
There was a problem hiding this comment.
I haven't tried applying this attribute to CoreLib yet. It looks like we have a few regular DllImports that are waiting on the next phase of work after this attribute gets in (described in #63765) to handle cases where we pass System.Guids to and from native code. Once we put this PR in, we can update the DllImportGenerator based on #63765, convert the rest of the DllImports over to the generated ones, and apply this attribute.
I might throw up another PR next week based on this one that applies the attribute just to see all that breaks.
|
Marking as blocking as a lot of the planned work for the Interop team (the rest of DllImportGenerator productization) requires this PR. |
| using System.Runtime.InteropServices; | ||
| using Xunit; | ||
|
|
||
| public unsafe class DisabledRuntimeMarshallingNative |
There was a problem hiding this comment.
For after this PR: thoughts on pulling out the common parts between this and the one under Native_Default or having one file with ifdefs?
There was a problem hiding this comment.
Maybe... Depends on how much would actually be common between the two.
|
The mono changes look ok, it could use a bit of cleanup later but nothing that would hold up this PR imho. |
…en deciding if runtime marshalling is enabled for a varargs P/Invoke call.
Implement support for the new
System.Runtime.CompilerServices.DisabledRuntimeMarshallingAttributein the CoreCLR, R2R, and NativeAOT type systems/runtimes.This feature (as discussed in API review), disables all runtime marshalling for P/Invokes, interop delegate types, and function pointer invocations defined within the assembly where the attribute is applied.
This also disables usage of
SetLastError=true,PreserveSig=falseandLCIDConversionAttributeon P/Invokes. Usage of any of these settings while using[assembly:DisabledRuntimeMarshalling]will result in aMarshalDirectiveException.This PR also has a few minor fixes for NativeAOT:
MarshalDirectiveExceptioninstead of aSystem.Exceptionwhen a parameter/field/return-value that cannot be marshalled is encountered to be consistent with CoreCLR.This PR includes basic support in Mono. Further integration with Mono's componentization is tracked in #61685.
Fixes #60639