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

Implement System.Runtime.CompilerServices.DisabledRuntimeMarshallingAttribute on CoreCLR-family of runtimes/type systems #63320

Merged
merged 64 commits into from
Jan 21, 2022
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
95c08cf
Add the DisableRuntimeMarshallingAttribute to the build.
jkoritzinsky Dec 15, 2021
225dea7
Add initial test suite
jkoritzinsky Dec 17, 2021
7c85f02
Implement support in IL stubs for the "disabled runtime marshalling" …
jkoritzinsky Dec 28, 2021
132dc67
Add testing for inlining IL stubs.
jkoritzinsky Dec 28, 2021
70f2fab
Block SetLastError and LCID support when DisableRuntimeMarshallingAtt…
jkoritzinsky Dec 28, 2021
ae4f309
Bump NativeAOT-only R2R version header (missed previously)
jkoritzinsky Jan 3, 2022
8681adf
Implement support in crossgen2 and NativeAOT
jkoritzinsky Jan 3, 2022
7700998
Clean up the test tree and update the tests to fail more reliably whe…
jkoritzinsky Jan 3, 2022
20094a2
Fix NativeAOT and clean up crossgen2
jkoritzinsky Jan 3, 2022
f9f070f
Add a test for NoPreserveSig with DisableRuntimeMarshalling
jkoritzinsky Jan 4, 2022
e0ee72e
Merge branch 'main' of github.com:dotnet/runtime into disableruntimem…
jkoritzinsky Jan 4, 2022
694f5fb
Assign hr in SUCCEEDED macro.
jkoritzinsky Jan 4, 2022
9ca4274
PR feedback.
jkoritzinsky Jan 4, 2022
e84d87d
Block varargs in disabled marshalling mode.
jkoritzinsky Jan 4, 2022
a4a8c99
Fix typo
jkoritzinsky Jan 4, 2022
a0953a2
Block types that have a field that is auto-layout somewhere in their …
jkoritzinsky Jan 5, 2022
118e21c
Fix typo
jkoritzinsky Jan 5, 2022
57c5553
Revert the AutoLayoutOrHasAutoLayoutFIeld check in the "marshalling e…
jkoritzinsky Jan 5, 2022
8c7efa3
Only set scope when it isn't null (it's null for some cases).
jkoritzinsky Jan 5, 2022
ce914dc
Fix narrowing conversion failure.
jkoritzinsky Jan 5, 2022
e72845f
First pass simple implementation in Mono
jkoritzinsky Jan 5, 2022
bcfa307
Fix assert to still work for the built-in marshalling system
jkoritzinsky Jan 6, 2022
abf48cb
S_FALSE is a thing
jkoritzinsky Jan 6, 2022
517833f
Fix type load failures caused by eager type handle loading.
jkoritzinsky Jan 6, 2022
8eee013
Get MethodILScope from the calling method when available (this covers…
jkoritzinsky Jan 6, 2022
9d58b3f
Add const modifier.
jkoritzinsky Jan 6, 2022
9bb7a62
Try 2 to fix const modifiers
jkoritzinsky Jan 6, 2022
887e20a
Fix compilation of NativeAOT jitinterface
jkoritzinsky Jan 6, 2022
a8671be
Fix type lookup in Mono
jkoritzinsky Jan 6, 2022
e1d26fc
Merge branch 'disableruntimemarshalling' of github.com:jkoritzinsky/r…
jkoritzinsky Jan 6, 2022
f928557
Use try_get model for getting the attribute type in the case of failu…
jkoritzinsky Jan 6, 2022
754ffaf
Handle void and generic instantiations
jkoritzinsky Jan 6, 2022
149ba9f
Update auto-layout check to check recursively in layout.
jkoritzinsky Jan 6, 2022
82c0086
Enhance test suite with more tests for UnmanagedCallersOnly, generics…
jkoritzinsky Jan 6, 2022
d759243
Fix IL and a few typos
jkoritzinsky Jan 7, 2022
4218e1d
Set a value in the padding for easier debugging.
jkoritzinsky Jan 7, 2022
54dc419
Create sig->marshalling_disabled to track when marshalling is disable…
jkoritzinsky Jan 7, 2022
5ae53f8
Fix running test suite on Mono + Mini JIT
jkoritzinsky Jan 8, 2022
41a4474
Fix recursive type load failure by only checking the "has auto-layout…
jkoritzinsky Jan 10, 2022
adb46bc
Fix mono windows build.
jkoritzinsky Jan 10, 2022
1b26307
Feedback from Michal.
jkoritzinsky Jan 10, 2022
5c70dc2
Fix bug in EcmaAssembly.HasAssemblyCustomAttribute
jkoritzinsky Jan 10, 2022
b8588dc
Make the runtime flavor check in the wrapper generator case-invariant
jkoritzinsky Jan 10, 2022
f2d91ff
Use helper method since various different platforms/configurations th…
jkoritzinsky Jan 10, 2022
f2f773d
Fix AutoLayout test refactor and use a dummy value for the padding fi…
jkoritzinsky Jan 10, 2022
46c12bb
Add an explicit test for using enums as they're a little weird and ne…
jkoritzinsky Jan 10, 2022
4c49207
Fix build-time test filtering in xunit wrapper generator.
jkoritzinsky Jan 11, 2022
a660f12
Fix some x86-specific issues
jkoritzinsky Jan 11, 2022
f0c86ec
Merge branch 'disableruntimemarshalling' of E:/home/jekoritz/runtime …
jkoritzinsky Jan 11, 2022
57c482b
Add a nice big comment block.
jkoritzinsky Jan 11, 2022
d0e12db
Fix x86
jkoritzinsky Jan 11, 2022
7524223
Refactor tests so we can skip one on Mono since Char->char lossy conv…
jkoritzinsky Jan 11, 2022
b62fd52
Disable test in issues.targets until an alternative solution is reached.
jkoritzinsky Jan 11, 2022
e3b7686
Add another SkipOnMono attribute in the "Enabled" test suite.
jkoritzinsky Jan 11, 2022
2ecd865
Merge branch 'disableruntimemarshalling' of github.com:jkoritzinsky/r…
jkoritzinsky Jan 11, 2022
7b0f9b2
Apply UnmangedFunctionPointerAttribute to help hint to the Mono LLVM …
jkoritzinsky Jan 11, 2022
3122f76
Unify on "runtime marshalling" terminology
jkoritzinsky Jan 13, 2022
0d1f54e
Clean up unused usings.
jkoritzinsky Jan 13, 2022
6a08e87
Address Jan's feedback except for applying the attribute to CoreLib.
jkoritzinsky Jan 15, 2022
9e0fc41
PR feedback.
jkoritzinsky Jan 20, 2022
0896e44
Mono throws an InvalidProgramException for varargs
jkoritzinsky Jan 20, 2022
3609c82
Fix copy-paste issue.
jkoritzinsky Jan 20, 2022
74b0f61
Make sure we use the P/Invoke's Module and not the caller's module wh…
jkoritzinsky Jan 21, 2022
f496d66
Handle how LLVM AOT reports the failure to handle varargs (EEE)
jkoritzinsky Jan 21, 2022
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
4 changes: 4 additions & 0 deletions src/coreclr/dlls/mscorrc/mscorrc.rc
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,9 @@ BEGIN
IDS_EE_NDIRECT_GETPROCADDR_WIN_DLL "Unable to find an entry point named '%1' in DLL."
IDS_EE_NDIRECT_GETPROCADDR_UNIX_SO "Unable to find an entry point named '%1' in shared library."
IDS_EE_NDIRECT_GETPROCADDRESS_NONAME "A library name must be specified in a DllImport attribute applied to non-IJW methods."
IDS_EE_NDIRECT_DISABLEDMARSHAL_SETLASTERROR "Setting SetLastError=true is not supported when runtime marshalling is disabled."
jkoritzinsky marked this conversation as resolved.
Show resolved Hide resolved
IDS_EE_NDIRECT_DISABLEDMARSHAL_LCID "The LCIDConversionAttribute is not supported when runtime marshalling is disabled."
IDS_EE_NDIRECT_DISABLEDMARSHAL_PRESERVESIG "Setting PreserveSig to false for a P/Invoke is not supported when runtime marshalling is disabled."
IDS_EE_CLASS_CONSTRAINTS_VIOLATION "GenericArguments[%1], '%2', on '%3' violates the constraint of type parameter '%4'."
IDS_EE_METHOD_CONSTRAINTS_VIOLATION "Method %1.%2: type argument '%3' violates the constraint of type parameter '%4'."
IDS_EE_NOSYNCHRONIZED "Synchronized attribute cannot be used with this method type."
Expand Down Expand Up @@ -297,6 +300,7 @@ BEGIN
IDS_EE_BADMARSHAL_GENERICS_RESTRICTION "Non-blittable generic types cannot be marshaled."
IDS_EE_BADMARSHAL_AUTOLAYOUT "Structures marked with [StructLayout(LayoutKind.Auto)] cannot be marshaled."
IDS_EE_BADMARSHAL_STRING_OUT "Cannot marshal a string by-value with the [Out] attribute."
IDS_EE_BADMARSHAL_MARSHAL_DISABLED "Cannot marshal managed types when the built-in marshaling system is disabled."
jkoritzinsky marked this conversation as resolved.
Show resolved Hide resolved

IDS_EE_BADMARSHALPARAM_STRINGBUILDER "Invalid managed/unmanaged type combination (StringBuilders must be paired with LPStr, LPWStr, or LPTStr)."
IDS_EE_BADMARSHALPARAM_NO_LPTSTR "Invalid managed/unmanaged type combination (Strings cannot be paired with LPTStr for parameters and return types of methods in interfaces exposed to COM)."
Expand Down
4 changes: 4 additions & 0 deletions src/coreclr/dlls/mscorrc/resource.h
Original file line number Diff line number Diff line change
Expand Up @@ -588,3 +588,7 @@
#define IDS_EE_BADMARSHAL_DELEGATE_TLB_INTERFACE 0x2649
#define IDS_EE_THREAD_APARTMENT_NOT_SUPPORTED 0x264A
#define IDS_EE_NO_IINSPECTABLE 0x264B
#define IDS_EE_BADMARSHAL_MARSHAL_DISABLED 0x264C
#define IDS_EE_NDIRECT_DISABLEDMARSHAL_SETLASTERROR 0x264D
#define IDS_EE_NDIRECT_DISABLEDMARSHAL_LCID 0x264E
#define IDS_EE_NDIRECT_DISABLEDMARSHAL_PRESERVESIG 0x264F
2 changes: 1 addition & 1 deletion src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3747,7 +3747,7 @@ private uint getJitFlags(ref CORJIT_FLAGS flags, uint sizeInBytes)

#if READYTORUN
// TODO: enable this check in full AOT
if (Marshaller.IsMarshallingRequired(this.MethodBeingCompiled.Signature, Array.Empty<ParameterMetadata>())) // Only blittable arguments
if (Marshaller.IsMarshallingRequired(this.MethodBeingCompiled.Signature, Array.Empty<ParameterMetadata>(), ((MetadataType)this.MethodBeingCompiled.OwningType).Module)) // Only blittable arguments
{
ThrowHelper.ThrowInvalidProgramException(ExceptionStringID.InvalidProgramNonBlittableTypes, this.MethodBeingCompiled);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@ public partial class CalliMarshallingMethodThunk : ILStubMethod
private MethodSignature _signature;

public CalliMarshallingMethodThunk(MethodSignature targetSignature, TypeDesc owningType,
InteropStateManager interopStateManager)
InteropStateManager interopStateManager,
bool useRuntimeMarshalling)
{
_targetSignature = targetSignature;
_owningType = owningType;
_interopStateManager = interopStateManager;
UseRuntimeMarshalling = useRuntimeMarshalling;
}

public MethodSignature TargetSignature
Expand Down Expand Up @@ -87,6 +89,8 @@ public override string DiagnosticName
}
}

public bool UseRuntimeMarshalling { get; }

public override PInvokeMetadata GetPInvokeMethodMetadata()
{
// Return PInvokeAttributes.PreserveSig to circumvent marshalling required checks
Expand Down
86 changes: 61 additions & 25 deletions src/coreclr/tools/Common/TypeSystem/IL/Stubs/PInvokeILEmitter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace Internal.IL.Stubs
{
/// <summary>
/// Provides method bodies for PInvoke methods
///
///
/// This by no means intends to provide full PInvoke support. The intended use of this is to
jkoritzinsky marked this conversation as resolved.
Show resolved Hide resolved
/// a) prevent calls getting generated to targets that require a full marshaller
/// (this compiler doesn't provide that), and b) offer a hand in some very simple marshalling
Expand Down Expand Up @@ -55,23 +55,27 @@ private static Marshaller[] InitializeMarshallers(MethodDesc targetMethod, Inter
{
MarshalDirection direction = MarshalDirection.Forward;
MethodSignature methodSig;
bool runtimeMarshallingEnabled;
switch (targetMethod)
{
case DelegateMarshallingMethodThunk delegateMethod:
methodSig = delegateMethod.DelegateSignature;
direction = delegateMethod.Direction;
runtimeMarshallingEnabled = MarshalHelpers.IsRuntimeMarshallingEnabled(delegateMethod.DelegateType.Module);
break;
case CalliMarshallingMethodThunk calliMethod:
methodSig = calliMethod.TargetSignature;
runtimeMarshallingEnabled = calliMethod.UseRuntimeMarshalling;
break;
default:
methodSig = targetMethod.Signature;
runtimeMarshallingEnabled = MarshalHelpers.IsRuntimeMarshallingEnabled(((EcmaMethod)targetMethod).Module);
jkoritzinsky marked this conversation as resolved.
Show resolved Hide resolved
break;
}
int indexOffset = 0;
if (!methodSig.IsStatic && direction == MarshalDirection.Forward)
{
// For instance methods(eg. Forward delegate marshalling thunk), first argument is
// For instance methods(eg. Forward delegate marshalling thunk), first argument is
// the instance
indexOffset = 1;
}
Expand All @@ -88,7 +92,7 @@ private static Marshaller[] InitializeMarshallers(MethodDesc targetMethod, Inter
// if we don't have metadata for the parameter, create a dummy one
parameterMetadata = new ParameterMetadata(i, ParameterMetadataAttributes.None, null);
}
else
else
{
Debug.Assert(i == parameterMetadataArray[parameterIndex].Index);
parameterMetadata = parameterMetadataArray[parameterIndex++];
Expand All @@ -104,7 +108,7 @@ private static Marshaller[] InitializeMarshallers(MethodDesc targetMethod, Inter
{
// PreserveSig = false can only show up an regular forward PInvokes
Debug.Assert(direction == MarshalDirection.Forward);

parameterType = methodSig.Context.GetByRefType(parameterType);
isHRSwappedRetVal = true;
}
Expand All @@ -114,20 +118,36 @@ private static Marshaller[] InitializeMarshallers(MethodDesc targetMethod, Inter
parameterType = methodSig[i - 1];
}

marshallers[i] = Marshaller.CreateMarshaller(parameterType,
parameterIndex,
methodSig.GetEmbeddedSignatureData(),
MarshallerType.Argument,
parameterMetadata.MarshalAsDescriptor,
direction,
marshallers,
interopStateManager,
indexOffset + parameterMetadata.Index,
flags,
parameterMetadata.In,
isHRSwappedRetVal ? true : parameterMetadata.Out,
isHRSwappedRetVal ? false : parameterMetadata.Return
);
if (runtimeMarshallingEnabled)
{
marshallers[i] = Marshaller.CreateMarshaller(parameterType,
parameterIndex,
methodSig.GetEmbeddedSignatureData(),
MarshallerType.Argument,
parameterMetadata.MarshalAsDescriptor,
direction,
marshallers,
interopStateManager,
indexOffset + parameterMetadata.Index,
flags,
parameterMetadata.In,
isHRSwappedRetVal ? true : parameterMetadata.Out,
isHRSwappedRetVal ? false : parameterMetadata.Return
);
}
else
{
marshallers[i] = Marshaller.CreateDisabledRuntimeMarshallingMarshaller(
jkoritzinsky marked this conversation as resolved.
Show resolved Hide resolved
parameterType,
parameterIndex,
MarshallerType.Argument,
direction,
marshallers,
interopStateManager,
indexOffset + parameterMetadata.Index,
flags,
parameterMetadata.Return);
}
}

return marshallers;
Expand All @@ -146,10 +166,10 @@ private void EmitDelegateCall(DelegateMarshallingMethodThunk delegateMethod, PIn
if (delegateMethod.Kind == DelegateMarshallingMethodThunkKind.ReverseOpenStatic)
{
//
// For Open static delegates call
// For Open static delegates call
// InteropHelpers.GetCurrentCalleeOpenStaticDelegateFunctionPointer()
// which returns a function pointer. Just call the function pointer and we are done.
//
//
TypeDesc[] parameters = new TypeDesc[_marshallers.Length - 1];
for (int i = 1; i < _marshallers.Length; i++)
{
Expand Down Expand Up @@ -193,7 +213,7 @@ private void EmitDelegateCall(DelegateMarshallingMethodThunk delegateMethod, PIn
else if (delegateMethod.Kind == DelegateMarshallingMethodThunkKind
.ForwardNativeFunctionWrapper)
{
// if the SetLastError flag is set in UnmanagedFunctionPointerAttribute, clear the error code before doing P/Invoke
// if the SetLastError flag is set in UnmanagedFunctionPointerAttribute, clear the error code before doing P/Invoke
if (_flags.SetLastError)
{
callsiteSetupCodeStream.Emit(ILOpcode.call, emitter.NewToken(
Expand Down Expand Up @@ -225,7 +245,7 @@ private void EmitDelegateCall(DelegateMarshallingMethodThunk delegateMethod, PIn
MethodSignatureFlags unmanagedCallingConvention = _flags.UnmanagedCallingConvention;
if (unmanagedCallingConvention == MethodSignatureFlags.None)
unmanagedCallingConvention = MethodSignatureFlags.UnmanagedCallingConvention;

MethodSignature nativeSig = new MethodSignature(
MethodSignatureFlags.Static | unmanagedCallingConvention, 0, nativeReturnType, nativeParameterTypes);

Expand Down Expand Up @@ -257,9 +277,17 @@ private void EmitPInvokeCall(PInvokeILCodeStreams ilCodeStreams)
TypeDesc nativeReturnType = _flags.PreserveSig ? _marshallers[0].NativeParameterType : context.GetWellKnownType(WellKnownType.Int32);
TypeDesc[] nativeParameterTypes = new TypeDesc[isHRSwappedRetVal ? _marshallers.Length : _marshallers.Length - 1];

// if the SetLastError flag is set in DllImport, clear the error code before doing P/Invoke
bool runtimeMarshallingEnabled = _targetMethod is not EcmaMethod ecmaMethod
jkoritzinsky marked this conversation as resolved.
Show resolved Hide resolved
|| MarshalHelpers.IsRuntimeMarshallingEnabled(ecmaMethod.Module);

// if the SetLastError flag is set in DllImport, clear the error code before doing P/Invoke
if (_flags.SetLastError)
{
if (!runtimeMarshallingEnabled)
{
// When runtime marshalling is disabled, we don't support SetLastError
throw new NotSupportedException();
}
callsiteSetupCodeStream.Emit(ILOpcode.call, emitter.NewToken(
InteropTypes.GetPInvokeMarshal(context).GetKnownMethod("ClearLastError", null)));
}
Expand All @@ -271,6 +299,11 @@ private void EmitPInvokeCall(PInvokeILCodeStreams ilCodeStreams)

if (isHRSwappedRetVal)
{
if (!runtimeMarshallingEnabled)
{
// When runtime marshalling is disabled, we don't support HResult-return-swapping
throw new NotSupportedException();
}
nativeParameterTypes[_marshallers.Length - 1] = _marshallers[0].NativeParameterType;
}

Expand Down Expand Up @@ -364,6 +397,9 @@ private void EmitCalli(PInvokeILCodeStreams ilCodeStreams, CalliMarshallingMetho

private MethodIL EmitIL()
{
if (_targetMethod.HasCustomAttribute("System.Runtime.InteropServices", "LCIDConversionAttribute"))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

throw new NotSupportedException();

PInvokeILCodeStreams pInvokeILCodeStreams = new PInvokeILCodeStreams();
ILEmitter emitter = pInvokeILCodeStreams.Emitter;
ILCodeStream marshallingCodestream = pInvokeILCodeStreams.MarshallingCodeStream;
Expand Down Expand Up @@ -417,8 +453,8 @@ private MethodIL EmitIL()
return new PInvokeILStubMethodIL((ILStubMethodIL)emitter.Link(_targetMethod), IsStubRequired());
}

public static MethodIL EmitIL(MethodDesc method,
PInvokeILEmitterConfiguration pinvokeILEmitterConfiguration,
public static MethodIL EmitIL(MethodDesc method,
PInvokeILEmitterConfiguration pinvokeILEmitterConfiguration,
InteropStateManager interopStateManager)
{
try
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public static MethodIL EmitExceptionBody(string message, MethodDesc method)
TypeSystemContext context = method.Context;
MethodSignature ctorSignature = new MethodSignature(0, 0, context.GetWellKnownType(WellKnownType.Void),
new TypeDesc[] { context.GetWellKnownType(WellKnownType.String) });
MethodDesc exceptionCtor = method.Context.GetWellKnownType(WellKnownType.Exception).GetKnownMethod(".ctor", ctorSignature);
MethodDesc exceptionCtor = InteropTypes.GetMarshalDirectiveException(context).GetKnownMethod(".ctor", ctorSignature);

ILCodeStream codeStream = emitter.NewCodeStream();
codeStream.Emit(ILOpcode.ldstr, emitter.NewToken(message));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Internal.IL;
using Debug = System.Diagnostics.Debug;
using Internal.IL.Stubs;
using Internal.TypeSystem.Ecma;

namespace Internal.TypeSystem.Interop
{
Expand Down Expand Up @@ -844,6 +845,28 @@ private static MarshallerKind GetArrayElementMarshallerKind(
}
}

internal static MarshallerKind GetRuntimeDisabledMarshallingMarshallerKind(
TypeDesc type)
{
if (type.Category == TypeFlags.Void)
{
return MarshallerKind.VoidReturn;
}
if (type.IsPrimitive)
{
return MarshallerKind.BlittableValue;
}
else if (type.IsPointer || type.IsFunctionPointer)
{
return MarshallerKind.BlittableValue;
}
else if (type.IsValueType && !((DefType)type).ContainsGCPointers)
{
return MarshallerKind.BlittableValue;
}
return MarshallerKind.Invalid;
}

internal static bool ShouldCheckForPendingException(TargetDetails target, PInvokeMetadata metadata)
{
if (!target.IsOSX)
Expand All @@ -861,5 +884,10 @@ internal static bool ShouldCheckForPendingException(TargetDetails target, PInvok
return metadata.Module.Equals(ObjectiveCLibrary)
&& metadata.Name.StartsWith(ObjectiveCMsgSend);
}

public static bool IsRuntimeMarshallingEnabled(ModuleDesc module)
{
return module.Assembly is not EcmaAssembly assembly || assembly.HasAssemblyCustomAttribute("System.Runtime.CompilerServices", "DisableRuntimeMarshallingAttribute");
jkoritzinsky marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
52 changes: 52 additions & 0 deletions src/coreclr/tools/Common/TypeSystem/Interop/IL/Marshaller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,58 @@ public static Marshaller CreateMarshaller(TypeDesc parameterType,

return marshaller;
}

/// <summary>
/// Create a marshaller
/// </summary>
/// <param name="parameterType">type of the parameter to marshal</param>
/// <returns>The created Marshaller</returns>
public static Marshaller CreateDisabledRuntimeMarshallingMarshaller(TypeDesc parameterType,
int? parameterIndex,
MarshallerType marshallerType,
MarshalDirection direction,
Marshaller[] marshallers,
#if !READYTORUN
InteropStateManager interopStateManager,
#endif
int index,
PInvokeFlags flags,
bool isReturn)
{
bool isAnsi = flags.CharSet switch
jkoritzinsky marked this conversation as resolved.
Show resolved Hide resolved
{
CharSet.Ansi => true,
CharSet.Unicode => false,
CharSet.Auto => !parameterType.Context.Target.IsWindows,
_ => true
};

MarshallerKind marshallerKind = MarshalHelpers.GetRuntimeDisabledMarshallingMarshallerKind(parameterType);

TypeSystemContext context = parameterType.Context;
// Create the marshaller based on MarshallerKind
Marshaller marshaller = CreateMarshaller(marshallerKind);
marshaller.Context = context;
#if !READYTORUN
marshaller.InteropStateManager = interopStateManager;
jkotas marked this conversation as resolved.
Show resolved Hide resolved
#endif
marshaller.MarshallerKind = marshallerKind;
marshaller.MarshallerType = marshallerType;
marshaller.ElementMarshallerKind = MarshallerKind.Unknown;
marshaller.ManagedParameterType = parameterType;
marshaller.ManagedType = parameterType.IsByRef ? parameterType.GetParameterType() : parameterType;
jkotas marked this conversation as resolved.
Show resolved Hide resolved
marshaller.Return = isReturn;
marshaller.IsManagedByRef = parameterType.IsByRef;
marshaller.IsNativeByRef = marshaller.IsManagedByRef;
marshaller.MarshalDirection = direction;
marshaller.MarshalAsDescriptor = null;
marshaller.Marshallers = marshallers;
marshaller.Index = index;
marshaller.PInvokeFlags = flags;
marshaller.In = true;
marshaller.Out = marshaller.IsManagedByRef;
return marshaller;
}
#endregion


Expand Down
Loading