From 24d88154d1a372c37531152ef19558491c92e313 Mon Sep 17 00:00:00 2001 From: Jeremy Koritzinsky Date: Fri, 17 Jan 2020 10:46:57 -0800 Subject: [PATCH 1/4] Don't block non-blittable pointer types in P/Invokes. Don't block non-blittable pointer types in P/Invokes. If you're using pointers in interop you're already using unsafe code so we're going to assume you know what you're doing. C# won't let you form a pointer to a reference, so there's no risk of passing an object reference directly to native unless you're writing IL directly. Fixes dotnet/coreclr#27800 --- src/coreclr/src/vm/mlinfo.cpp | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/src/coreclr/src/vm/mlinfo.cpp b/src/coreclr/src/vm/mlinfo.cpp index efc9169ed307a..de086738a28f2 100644 --- a/src/coreclr/src/vm/mlinfo.cpp +++ b/src/coreclr/src/vm/mlinfo.cpp @@ -1612,13 +1612,6 @@ MarshalInfo::MarshalInfo(Module* pModule, // plus they are not marked as blittable. if (!th.IsEnum()) { - // It should be blittable - if (!th.IsBlittable()) - { - m_resID = IDS_EE_BADMARSHAL_PTRNONBLITTABLE; - IfFailGoto(E_FAIL, lFail); - } - // Check for Copy Constructor Modifier if (sigtmp.HasCustomModifier(pModule, "Microsoft.VisualC.NeedsCopyConstructorModifier", ELEMENT_TYPE_CMOD_REQD) || sigtmp.HasCustomModifier(pModule, "System.Runtime.CompilerServices.IsCopyConstructed", ELEMENT_TYPE_CMOD_REQD) ) @@ -1634,17 +1627,6 @@ MarshalInfo::MarshalInfo(Module* pModule, } } } - else - { - if (!(mtype2 != ELEMENT_TYPE_CLASS && - mtype2 != ELEMENT_TYPE_STRING && - mtype2 != ELEMENT_TYPE_OBJECT && - mtype2 != ELEMENT_TYPE_SZARRAY)) - { - m_resID = IDS_EE_BADMARSHAL_PTRSUBTYPE; - IfFailGoto(E_FAIL, lFail); - } - } } } From 00eda656b9f0091170892cf124d1f4409f7887c4 Mon Sep 17 00:00:00 2001 From: Jeremy Koritzinsky Date: Fri, 17 Jan 2020 13:44:48 -0800 Subject: [PATCH 2/4] Delete unused resources. --- src/coreclr/src/dlls/mscorrc/mscorrc.rc | 2 -- src/coreclr/src/dlls/mscorrc/resource.h | 2 -- 2 files changed, 4 deletions(-) diff --git a/src/coreclr/src/dlls/mscorrc/mscorrc.rc b/src/coreclr/src/dlls/mscorrc/mscorrc.rc index 327a5641741e6..d57f248412135 100644 --- a/src/coreclr/src/dlls/mscorrc/mscorrc.rc +++ b/src/coreclr/src/dlls/mscorrc/mscorrc.rc @@ -608,8 +608,6 @@ BEGIN IDS_EE_BADMARSHAL_SAFEHANDLEARRAY "Invalid managed/unmanaged type combination (Arrays of SafeHandles are not supported)." IDS_EE_BADMARSHAL_CRITICALHANDLEARRAY "Invalid managed/unmanaged type combination (Arrays of CriticalHandles are not supported)." IDS_EE_BADMARSHAL_SYSARRAY "Invalid managed/unmanaged type combination (System.Array must be paired with SafeArray or Interface)." - IDS_EE_BADMARSHAL_PTRSUBTYPE "Pointers cannot reference managed objects. Use ByRef instead." - IDS_EE_BADMARSHAL_PTRNONBLITTABLE "Pointers cannot reference marshaled structures. Use ByRef instead." IDS_EE_BADMARSHAL_RESTRICTION "This type can only be marshaled in restricted ways." IDS_EE_BADMARSHAL_ASANYRESTRICTION "AsAny cannot be used on return types, ByRef parameters, ArrayWithOffset, or parameters passed from unmanaged to managed." IDS_EE_BADMARSHAL_VBBYVALSTRRESTRICTION "VBByRefStr can only be used in combination with in/out, ByRef managed-to-unmanaged strings." diff --git a/src/coreclr/src/dlls/mscorrc/resource.h b/src/coreclr/src/dlls/mscorrc/resource.h index fe09f73fea484..363f6e7e492ed 100644 --- a/src/coreclr/src/dlls/mscorrc/resource.h +++ b/src/coreclr/src/dlls/mscorrc/resource.h @@ -164,8 +164,6 @@ #define IDS_EE_BADMARSHAL_BADMANAGED 0x1756 #define IDS_EE_SRC_OBJ_NOT_COMOBJECT 0x1757 #define IDS_EE_CANNOT_COERCE_COMOBJECT 0x1759 -#define IDS_EE_BADMARSHAL_PTRSUBTYPE 0x175b -#define IDS_EE_BADMARSHAL_PTRNONBLITTABLE 0x175c #define IDS_EE_BADMARSHAL_RESTRICTION 0x175d #define IDS_EE_BADMARSHAL_ASANYRESTRICTION 0x175f From e312a3a8659fa9bce7b759d8ba75f10cb8b56a05 Mon Sep 17 00:00:00 2001 From: Jeremy Koritzinsky Date: Fri, 17 Jan 2020 13:45:51 -0800 Subject: [PATCH 3/4] Apply fix to managed type system as well. --- .../TypeSystem/Interop/IL/MarshalHelpers.cs | 24 ++++--------------- 1 file changed, 4 insertions(+), 20 deletions(-) diff --git a/src/coreclr/src/tools/Common/TypeSystem/Interop/IL/MarshalHelpers.cs b/src/coreclr/src/tools/Common/TypeSystem/Interop/IL/MarshalHelpers.cs index 991422c369ee5..85d110e18f8d4 100644 --- a/src/coreclr/src/tools/Common/TypeSystem/Interop/IL/MarshalHelpers.cs +++ b/src/coreclr/src/tools/Common/TypeSystem/Interop/IL/MarshalHelpers.cs @@ -11,8 +11,8 @@ namespace Internal.TypeSystem.Interop { public static partial class MarshalHelpers { - internal static TypeDesc GetNativeTypeFromMarshallerKind(TypeDesc type, - MarshallerKind kind, + internal static TypeDesc GetNativeTypeFromMarshallerKind(TypeDesc type, + MarshallerKind kind, MarshallerKind elementMarshallerKind, #if !READYTORUN InteropStateManager interopStateManager, @@ -121,7 +121,7 @@ internal static TypeDesc GetNativeTypeFromMarshallerKind(TypeDesc type, #if !READYTORUN interopStateManager, #endif - marshalAs, + marshalAs, isArrayElement: true); return elementNativeType.MakePointerType(); @@ -196,7 +196,7 @@ internal static MarshallerKind GetMarshallerKind( // Determine MarshalerKind // // This mostly resembles desktop CLR and .NET Native code as we need to match their behavior - // + // if (type.IsPrimitive) { switch (type.Category) @@ -440,22 +440,6 @@ internal static MarshallerKind GetMarshallerKind( } else if (type.IsPointer) { -#if READYTORUN - TypeDesc parameterType = ((PointerType)type).ParameterType; - - if ((!parameterType.IsEnum - && !parameterType.IsPrimitive - && !MarshalUtils.IsBlittableType(parameterType)) - || parameterType.IsGCPointer) - { - // Pointers cannot reference marshaled structures. Use ByRef instead. - return MarshallerKind.Invalid; - } -#else - // Do not bother enforcing the above artificial restriction - // See https://github.com/dotnet/coreclr/issues/27800 -#endif - if (nativeType == NativeTypeKind.Default) return MarshallerKind.BlittableValue; else From 68b755324555af4f7a36c8bb1935848332b65d6d Mon Sep 17 00:00:00 2001 From: Jeremy Koritzinsky Date: Fri, 17 Jan 2020 14:27:33 -0800 Subject: [PATCH 4/4] Add positive test for nonblittable pointers. Remove negative tests that were in GenericTest. --- src/coreclr/tests/src/Interop/CMakeLists.txt | 1 + .../Generics/GenericsTest.NullableB.cs | 25 ----------------- .../Generics/GenericsTest.NullableC.cs | 25 ----------------- .../Generics/GenericsTest.NullableD.cs | 25 ----------------- .../Generics/GenericsTest.NullableF.cs | 26 ----------------- .../Generics/GenericsTest.NullableL.cs | 25 ----------------- .../Generics/GenericsTest.NullableU.cs | 25 ----------------- .../PInvoke/Generics/GenericsTest.Point1B.cs | 23 --------------- .../PInvoke/Generics/GenericsTest.Point1C.cs | 23 --------------- .../PInvoke/Generics/GenericsTest.Point2B.cs | 22 --------------- .../PInvoke/Generics/GenericsTest.Point2C.cs | 23 --------------- .../PInvoke/Generics/GenericsTest.Point3B.cs | 23 --------------- .../PInvoke/Generics/GenericsTest.Point3C.cs | 23 --------------- .../PInvoke/Generics/GenericsTest.Point4B.cs | 23 --------------- .../PInvoke/Generics/GenericsTest.Point4C.cs | 23 --------------- .../PInvoke/Primitives/Pointer/CMakeLists.txt | 6 ++++ .../Pointer/NonBlittablePointer.csproj | 14 ++++++++++ .../Pointer/NonBlittablePointerNative.cpp | 10 +++++++ .../Primitives/Pointer/PInvokePointerTest.cs | 28 ------------------- .../Pointer/PInvokePointerTest.csproj | 11 -------- .../PInvoke/Primitives/Pointer/Program.cs | 25 +++++++++++++++++ 21 files changed, 56 insertions(+), 373 deletions(-) create mode 100644 src/coreclr/tests/src/Interop/PInvoke/Primitives/Pointer/CMakeLists.txt create mode 100644 src/coreclr/tests/src/Interop/PInvoke/Primitives/Pointer/NonBlittablePointer.csproj create mode 100644 src/coreclr/tests/src/Interop/PInvoke/Primitives/Pointer/NonBlittablePointerNative.cpp delete mode 100644 src/coreclr/tests/src/Interop/PInvoke/Primitives/Pointer/PInvokePointerTest.cs delete mode 100644 src/coreclr/tests/src/Interop/PInvoke/Primitives/Pointer/PInvokePointerTest.csproj create mode 100644 src/coreclr/tests/src/Interop/PInvoke/Primitives/Pointer/Program.cs diff --git a/src/coreclr/tests/src/Interop/CMakeLists.txt b/src/coreclr/tests/src/Interop/CMakeLists.txt index f85eff4c8f5ef..d9a710cec930a 100644 --- a/src/coreclr/tests/src/Interop/CMakeLists.txt +++ b/src/coreclr/tests/src/Interop/CMakeLists.txt @@ -20,6 +20,7 @@ add_subdirectory(PInvoke/BestFitMapping/LPStr) add_subdirectory(PInvoke/Delegate) add_subdirectory(PInvoke/Primitives/Int) add_subdirectory(PInvoke/Primitives/RuntimeHandles) +add_subdirectory(PInvoke/Primitives/Pointer) add_subdirectory(PInvoke/SizeParamIndex/PInvoke/PassingByOut) add_subdirectory(PInvoke/SizeParamIndex/PInvoke/PassingByRef) add_subdirectory(PInvoke/SizeParamIndex/ReversePInvoke/PassingByOut) diff --git a/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.NullableB.cs b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.NullableB.cs index 61580bb4441cf..edff74a9914ac 100644 --- a/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.NullableB.cs +++ b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.NullableB.cs @@ -11,24 +11,15 @@ unsafe partial class GenericsNative [DllImport(nameof(GenericsNative))] public static extern bool? GetNullableB(bool hasValue, bool value); - [DllImport(nameof(GenericsNative))] - public static extern void GetNullableBOut(bool hasValue, bool value, bool?* pValue); - [DllImport(nameof(GenericsNative))] public static extern void GetNullableBOut(bool hasValue, bool value, out bool? pValue); - [DllImport(nameof(GenericsNative))] - public static extern bool?* GetNullableBPtr(bool hasValue, bool value); - [DllImport(nameof(GenericsNative), EntryPoint = "GetNullableBPtr")] public static extern ref readonly bool? GetNullableBRef(bool hasValue, bool value); [DllImport(nameof(GenericsNative))] public static extern bool? AddNullableB(bool? lhs, bool? rhs); - [DllImport(nameof(GenericsNative))] - public static extern bool? AddNullableBs(bool?* pValues, int count); - [DllImport(nameof(GenericsNative))] public static extern bool? AddNullableBs([MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] bool?[] pValues, int count); @@ -42,17 +33,8 @@ private static void TestNullableB() { Assert.Throws(() => GenericsNative.GetNullableB(true, false)); - Assert.Throws(() => { - bool? value2; - GenericsNative.GetNullableBOut(true, false, &value2); - }); - Assert.Throws(() => GenericsNative.GetNullableBOut(true, false, out bool? value3)); - Assert.Throws(() => GenericsNative.GetNullableBPtr(true, false)); - - Assert.Throws(() => GenericsNative.GetNullableBRef(true, false)); - Assert.Throws(() => GenericsNative.AddNullableB(default, default)); bool?[] values = new bool?[] { @@ -63,13 +45,6 @@ private static void TestNullableB() default }; - Assert.Throws(() => { - fixed (bool?* pValues = &values[0]) - { - GenericsNative.AddNullableBs(pValues, values.Length); - } - }); - Assert.Throws(() => GenericsNative.AddNullableBs(values, values.Length)); Assert.Throws(() => GenericsNative.AddNullableBs(in values[0], values.Length)); diff --git a/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.NullableC.cs b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.NullableC.cs index c2a33ef8918b3..73a5e8ea53515 100644 --- a/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.NullableC.cs +++ b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.NullableC.cs @@ -11,24 +11,15 @@ unsafe partial class GenericsNative [DllImport(nameof(GenericsNative))] public static extern char? GetNullableC(bool hasValue, char value); - [DllImport(nameof(GenericsNative))] - public static extern void GetNullableCOut(bool hasValue, char value, char?* pValue); - [DllImport(nameof(GenericsNative))] public static extern void GetNullableCOut(bool hasValue, char value, out char? pValue); - [DllImport(nameof(GenericsNative))] - public static extern char?* GetNullableCPtr(bool hasValue, char value); - [DllImport(nameof(GenericsNative), EntryPoint = "GetNullableCPtr")] public static extern ref readonly char? GetNullableCRef(bool hasValue, char value); [DllImport(nameof(GenericsNative))] public static extern char? AddNullableC(char? lhs, char? rhs); - [DllImport(nameof(GenericsNative))] - public static extern char? AddNullableCs(char?* pValues, int count); - [DllImport(nameof(GenericsNative))] public static extern char? AddNullableCs([MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] char?[] pValues, int count); @@ -42,17 +33,8 @@ private static void TestNullableC() { Assert.Throws(() => GenericsNative.GetNullableC(true, '1')); - Assert.Throws(() => { - char? value2; - GenericsNative.GetNullableCOut(true, '1', &value2); - }); - Assert.Throws(() => GenericsNative.GetNullableCOut(true, '1', out char? value3)); - Assert.Throws(() => GenericsNative.GetNullableCPtr(true, '1')); - - Assert.Throws(() => GenericsNative.GetNullableCRef(true, '1')); - Assert.Throws(() => GenericsNative.AddNullableC(default, default)); char?[] values = new char?[] { @@ -63,13 +45,6 @@ private static void TestNullableC() default }; - Assert.Throws(() => { - fixed (char?* pValues = &values[0]) - { - GenericsNative.AddNullableCs(pValues, values.Length); - } - }); - Assert.Throws(() => GenericsNative.AddNullableCs(values, values.Length)); Assert.Throws(() => GenericsNative.AddNullableCs(in values[0], values.Length)); diff --git a/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.NullableD.cs b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.NullableD.cs index 7bf829d4abd48..cc21ebd996b1b 100644 --- a/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.NullableD.cs +++ b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.NullableD.cs @@ -11,24 +11,15 @@ unsafe partial class GenericsNative [DllImport(nameof(GenericsNative))] public static extern double? GetNullableD(bool hasValue, double value); - [DllImport(nameof(GenericsNative))] - public static extern void GetNullableDOut(bool hasValue, double value, double?* pValue); - [DllImport(nameof(GenericsNative))] public static extern void GetNullableDOut(bool hasValue, double value, out double? pValue); - [DllImport(nameof(GenericsNative))] - public static extern double?* GetNullableDPtr(bool hasValue, double value); - [DllImport(nameof(GenericsNative), EntryPoint = "GetNullableDPtr")] public static extern ref readonly double? GetNullableDRef(bool hasValue, double value); [DllImport(nameof(GenericsNative))] public static extern double? AddNullableD(double? lhs, double? rhs); - [DllImport(nameof(GenericsNative))] - public static extern double? AddNullableDs(double?* pValues, int count); - [DllImport(nameof(GenericsNative))] public static extern double? AddNullableDs([MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] double?[] pValues, int count); @@ -42,17 +33,8 @@ private static void TestNullableD() { Assert.Throws(() => GenericsNative.GetNullableD(true, 1.0)); - Assert.Throws(() => { - double? value2; - GenericsNative.GetNullableDOut(true, 1.0, &value2); - }); - Assert.Throws(() => GenericsNative.GetNullableDOut(true, 1.0, out double? value3)); - Assert.Throws(() => GenericsNative.GetNullableDPtr(true, 1.0)); - - Assert.Throws(() => GenericsNative.GetNullableDRef(true, 1.0)); - Assert.Throws(() => GenericsNative.AddNullableD(default, default)); double?[] values = new double?[] { @@ -63,13 +45,6 @@ private static void TestNullableD() default }; - Assert.Throws(() => { - fixed (double?* pValues = &values[0]) - { - GenericsNative.AddNullableDs(pValues, values.Length); - } - }); - Assert.Throws(() => GenericsNative.AddNullableDs(values, values.Length)); Assert.Throws(() => GenericsNative.AddNullableDs(in values[0], values.Length)); diff --git a/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.NullableF.cs b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.NullableF.cs index c0f2f69b43f1d..9d3b6b15f4a94 100644 --- a/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.NullableF.cs +++ b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.NullableF.cs @@ -10,25 +10,15 @@ unsafe partial class GenericsNative { [DllImport(nameof(GenericsNative))] public static extern float? GetNullableF(bool hasValue, float value); - - [DllImport(nameof(GenericsNative))] - public static extern void GetNullableFOut(bool hasValue, float value, float?* pValue); - [DllImport(nameof(GenericsNative))] public static extern void GetNullableFOut(bool hasValue, float value, out float? pValue); - [DllImport(nameof(GenericsNative))] - public static extern float?* GetNullableFPtr(bool hasValue, float value); - [DllImport(nameof(GenericsNative), EntryPoint = "GetNullableFPtr")] public static extern ref readonly float? GetNullableFRef(bool hasValue, float value); [DllImport(nameof(GenericsNative))] public static extern float? AddNullableF(float? lhs, float? rhs); - [DllImport(nameof(GenericsNative))] - public static extern float? AddNullableFs(float?* pValues, int count); - [DllImport(nameof(GenericsNative))] public static extern float? AddNullableFs([MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] float?[] pValues, int count); @@ -42,17 +32,8 @@ private static void TestNullableF() { Assert.Throws(() => GenericsNative.GetNullableF(true, 1.0f)); - Assert.Throws(() => { - float? value2; - GenericsNative.GetNullableFOut(true, 1.0f, &value2); - }); - Assert.Throws(() => GenericsNative.GetNullableFOut(true, 1.0f, out float? value3)); - Assert.Throws(() => GenericsNative.GetNullableFPtr(true, 1.0f)); - - Assert.Throws(() => GenericsNative.GetNullableFRef(true, 1.0f)); - Assert.Throws(() => GenericsNative.AddNullableF(default, default)); float?[] values = new float?[] { @@ -63,13 +44,6 @@ private static void TestNullableF() default }; - Assert.Throws(() => { - fixed (float?* pValues = &values[0]) - { - GenericsNative.AddNullableFs(pValues, values.Length); - } - }); - Assert.Throws(() => GenericsNative.AddNullableFs(values, values.Length)); Assert.Throws(() => GenericsNative.AddNullableFs(in values[0], values.Length)); diff --git a/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.NullableL.cs b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.NullableL.cs index 21255d6854271..a85d2e4b80724 100644 --- a/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.NullableL.cs +++ b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.NullableL.cs @@ -11,24 +11,15 @@ unsafe partial class GenericsNative [DllImport(nameof(GenericsNative))] public static extern long? GetNullableL(bool hasValue, long value); - [DllImport(nameof(GenericsNative))] - public static extern void GetNullableLOut(bool hasValue, long value, long?* pValue); - [DllImport(nameof(GenericsNative))] public static extern void GetNullableLOut(bool hasValue, long value, out long? pValue); - [DllImport(nameof(GenericsNative))] - public static extern long?* GetNullableLPtr(bool hasValue, long value); - [DllImport(nameof(GenericsNative), EntryPoint = "GetNullableLPtr")] public static extern ref readonly long? GetNullableLRef(bool hasValue, long value); [DllImport(nameof(GenericsNative))] public static extern long? AddNullableL(long? lhs, long? rhs); - [DllImport(nameof(GenericsNative))] - public static extern long? AddNullableLs(long?* pValues, int count); - [DllImport(nameof(GenericsNative))] public static extern long? AddNullableLs([MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] long?[] pValues, int count); @@ -42,17 +33,8 @@ private static void TestNullableL() { Assert.Throws(() => GenericsNative.GetNullableL(true, 1L)); - Assert.Throws(() => { - long? value2; - GenericsNative.GetNullableLOut(true, 1L, &value2); - }); - Assert.Throws(() => GenericsNative.GetNullableLOut(true, 1L, out long? value3)); - Assert.Throws(() => GenericsNative.GetNullableLPtr(true, 1L)); - - Assert.Throws(() => GenericsNative.GetNullableLRef(true, 1L)); - Assert.Throws(() => GenericsNative.AddNullableL(default, default)); long?[] values = new long?[] { @@ -63,13 +45,6 @@ private static void TestNullableL() default }; - Assert.Throws(() => { - fixed (long?* pValues = &values[0]) - { - GenericsNative.AddNullableLs(pValues, values.Length); - } - }); - Assert.Throws(() => GenericsNative.AddNullableLs(values, values.Length)); Assert.Throws(() => GenericsNative.AddNullableLs(in values[0], values.Length)); diff --git a/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.NullableU.cs b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.NullableU.cs index cba3a458ebdd0..331b4544797f3 100644 --- a/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.NullableU.cs +++ b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.NullableU.cs @@ -11,24 +11,15 @@ unsafe partial class GenericsNative [DllImport(nameof(GenericsNative))] public static extern uint? GetNullableU(bool hasValue, uint value); - [DllImport(nameof(GenericsNative))] - public static extern void GetNullableUOut(bool hasValue, uint value, uint?* pValue); - [DllImport(nameof(GenericsNative))] public static extern void GetNullableUOut(bool hasValue, uint value, out uint? pValue); - [DllImport(nameof(GenericsNative))] - public static extern uint?* GetNullableUPtr(bool hasValue, uint value); - [DllImport(nameof(GenericsNative), EntryPoint = "GetNullableUPtr")] public static extern ref readonly uint? GetNullableURef(bool hasValue, uint value); [DllImport(nameof(GenericsNative))] public static extern uint? AddNullableU(uint? lhs, uint? rhs); - [DllImport(nameof(GenericsNative))] - public static extern uint? AddNullableUs(uint?* pValues, int count); - [DllImport(nameof(GenericsNative))] public static extern uint? AddNullableUs([MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] uint?[] pValues, int count); @@ -42,17 +33,8 @@ private static void TestNullableU() { Assert.Throws(() => GenericsNative.GetNullableU(true, 1u)); - Assert.Throws(() => { - uint? value2; - GenericsNative.GetNullableUOut(true, 1u, &value2); - }); - Assert.Throws(() => GenericsNative.GetNullableUOut(true, 1u, out uint? value3)); - Assert.Throws(() => GenericsNative.GetNullableUPtr(true, 1u)); - - Assert.Throws(() => GenericsNative.GetNullableURef(true, 1u)); - Assert.Throws(() => GenericsNative.AddNullableU(default, default)); uint?[] values = new uint?[] { @@ -63,13 +45,6 @@ private static void TestNullableU() default }; - Assert.Throws(() => { - fixed (uint?* pValues = &values[0]) - { - GenericsNative.AddNullableUs(pValues, values.Length); - } - }); - Assert.Throws(() => GenericsNative.AddNullableUs(values, values.Length)); Assert.Throws(() => GenericsNative.AddNullableUs(in values[0], values.Length)); diff --git a/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.Point1B.cs b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.Point1B.cs index 24a3ab743ae1f..6dea4b41b2d06 100644 --- a/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.Point1B.cs +++ b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.Point1B.cs @@ -11,24 +11,15 @@ unsafe partial class GenericsNative [DllImport(nameof(GenericsNative))] public static extern Point1 GetPoint1B(bool e00); - [DllImport(nameof(GenericsNative))] - public static extern void GetPoint1BOut(bool e00, Point1* value); - [DllImport(nameof(GenericsNative))] public static extern void GetPoint1BOut(bool e00, out Point1 value); - [DllImport(nameof(GenericsNative))] - public static extern Point1* GetPoint1BPtr(bool e00); - [DllImport(nameof(GenericsNative), EntryPoint = "GetPoint1BPtr")] public static extern ref readonly Point1 GetPoint1BRef(bool e00); [DllImport(nameof(GenericsNative))] public static extern Point1 AddPoint1B(Point1 lhs, Point1 rhs); - [DllImport(nameof(GenericsNative))] - public static extern Point1 AddPoint1Bs(Point1* pValues, int count); - [DllImport(nameof(GenericsNative))] public static extern Point1 AddPoint1Bs([MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] Point1[] pValues, int count); @@ -42,15 +33,8 @@ private static void TestPoint1B() { Assert.Throws(() => GenericsNative.GetPoint1B(true)); - Assert.Throws(() => { - GenericsNative.Point1 value2; - GenericsNative.GetPoint1BOut(true, &value2); - }); - Assert.Throws(() => GenericsNative.GetPoint1BOut(true, out GenericsNative.Point1 value3)); - Assert.Throws(() => GenericsNative.GetPoint1BPtr(true)); - Assert.Throws(() => GenericsNative.GetPoint1BRef(true)); Assert.Throws(() => GenericsNative.AddPoint1B(default, default)); @@ -63,13 +47,6 @@ private static void TestPoint1B() default }; - Assert.Throws(() => { - fixed (GenericsNative.Point1* pValues = &values[0]) - { - GenericsNative.AddPoint1Bs(pValues, values.Length); - } - }); - Assert.Throws(() => GenericsNative.AddPoint1Bs(values, values.Length)); Assert.Throws(() => GenericsNative.AddPoint1Bs(in values[0], values.Length)); diff --git a/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.Point1C.cs b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.Point1C.cs index 1f744d6809d9f..2161632885253 100644 --- a/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.Point1C.cs +++ b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.Point1C.cs @@ -11,24 +11,15 @@ unsafe partial class GenericsNative [DllImport(nameof(GenericsNative))] public static extern Point1 GetPoint1C(char e00); - [DllImport(nameof(GenericsNative))] - public static extern void GetPoint1COut(char e00, Point1* value); - [DllImport(nameof(GenericsNative))] public static extern void GetPoint1COut(char e00, out Point1 value); - [DllImport(nameof(GenericsNative))] - public static extern Point1* GetPoint1CPtr(char e00); - [DllImport(nameof(GenericsNative), EntryPoint = "GetPoint1CPtr")] public static extern ref readonly Point1 GetPoint1CRef(char e00); [DllImport(nameof(GenericsNative))] public static extern Point1 AddPoint1C(Point1 lhs, Point1 rhs); - [DllImport(nameof(GenericsNative))] - public static extern Point1 AddPoint1Cs(Point1* pValues, int count); - [DllImport(nameof(GenericsNative))] public static extern Point1 AddPoint1Cs([MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] Point1[] pValues, int count); @@ -42,15 +33,8 @@ private static void TestPoint1C() { Assert.Throws(() => GenericsNative.GetPoint1C('1')); - Assert.Throws(() => { - GenericsNative.Point1 value2; - GenericsNative.GetPoint1COut('1', &value2); - }); - Assert.Throws(() => GenericsNative.GetPoint1COut('1', out GenericsNative.Point1 value3)); - Assert.Throws(() => GenericsNative.GetPoint1CPtr('1')); - Assert.Throws(() => GenericsNative.GetPoint1CRef('1')); Assert.Throws(() => GenericsNative.AddPoint1C(default, default)); @@ -63,13 +47,6 @@ private static void TestPoint1C() default }; - Assert.Throws(() => { - fixed (GenericsNative.Point1* pValues = &values[0]) - { - GenericsNative.AddPoint1Cs(pValues, values.Length); - } - }); - Assert.Throws(() => GenericsNative.AddPoint1Cs(values, values.Length)); Assert.Throws(() => GenericsNative.AddPoint1Cs(in values[0], values.Length)); diff --git a/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.Point2B.cs b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.Point2B.cs index d484b992c2a5e..ce5747c9d043b 100644 --- a/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.Point2B.cs +++ b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.Point2B.cs @@ -11,24 +11,15 @@ unsafe partial class GenericsNative [DllImport(nameof(GenericsNative))] public static extern Point2 GetPoint2B(bool e00, bool e01); - [DllImport(nameof(GenericsNative))] - public static extern void GetPoint2BOut(bool e00, bool e01, Point2* value); - [DllImport(nameof(GenericsNative))] public static extern void GetPoint2BOut(bool e00, bool e01, out Point2 value); - [DllImport(nameof(GenericsNative))] - public static extern Point2* GetPoint2BPtr(bool e00, bool e01); - [DllImport(nameof(GenericsNative), EntryPoint = "GetPoint2BPtr")] public static extern ref readonly Point2 GetPoint2BRef(bool e00, bool e01); [DllImport(nameof(GenericsNative))] public static extern Point2 AddPoint2B(Point2 lhs, Point2 rhs); - [DllImport(nameof(GenericsNative))] - public static extern Point2 AddPoint2Bs(Point2* pValues, int count); - [DllImport(nameof(GenericsNative))] public static extern Point2 AddPoint2Bs([MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] Point2[] pValues, int count); @@ -42,15 +33,8 @@ private static void TestPoint2B() { Assert.Throws(() => GenericsNative.GetPoint2B(true, false)); - Assert.Throws(() => { - GenericsNative.Point2 value2; - GenericsNative.GetPoint2BOut(true, false, &value2); - }); - Assert.Throws(() => GenericsNative.GetPoint2BOut(true, false, out GenericsNative.Point2 value3)); - Assert.Throws(() => GenericsNative.GetPoint2BPtr(true, false)); - Assert.Throws(() => GenericsNative.GetPoint2BRef(true, false)); Assert.Throws(() => GenericsNative.AddPoint2B(default, default)); @@ -63,12 +47,6 @@ private static void TestPoint2B() default }; - Assert.Throws(() => { - fixed (GenericsNative.Point2* pValues = &values[0]) - { - GenericsNative.AddPoint2Bs(pValues, values.Length); - } - }); Assert.Throws(() => GenericsNative.AddPoint2Bs(values, values.Length)); diff --git a/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.Point2C.cs b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.Point2C.cs index 35bed8170adfa..b2a3338311eba 100644 --- a/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.Point2C.cs +++ b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.Point2C.cs @@ -11,24 +11,15 @@ unsafe partial class GenericsNative [DllImport(nameof(GenericsNative))] public static extern Point2 GetPoint2C(char e00, char e01); - [DllImport(nameof(GenericsNative))] - public static extern void GetPoint2COut(char e00, char e01, Point2* value); - [DllImport(nameof(GenericsNative))] public static extern void GetPoint2COut(char e00, char e01, out Point2 value); - [DllImport(nameof(GenericsNative))] - public static extern Point2* GetPoint2CPtr(char e00, char e01); - [DllImport(nameof(GenericsNative), EntryPoint = "GetPoint2CPtr")] public static extern ref readonly Point2 GetPoint2CRef(char e00, char e01); [DllImport(nameof(GenericsNative))] public static extern Point2 AddPoint2C(Point2 lhs, Point2 rhs); - [DllImport(nameof(GenericsNative))] - public static extern Point2 AddPoint2Cs(Point2* pValues, int count); - [DllImport(nameof(GenericsNative))] public static extern Point2 AddPoint2Cs([MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] Point2[] pValues, int count); @@ -42,15 +33,8 @@ private static void TestPoint2C() { Assert.Throws(() => GenericsNative.GetPoint2C('1', '2')); - Assert.Throws(() => { - GenericsNative.Point2 value2; - GenericsNative.GetPoint2COut('1', '2', &value2); - }); - Assert.Throws(() => GenericsNative.GetPoint2COut('1', '2', out GenericsNative.Point2 value3)); - Assert.Throws(() => GenericsNative.GetPoint2CPtr('1', '2')); - Assert.Throws(() => GenericsNative.GetPoint2CRef('1', '2')); Assert.Throws(() => GenericsNative.AddPoint2C(default, default)); @@ -63,13 +47,6 @@ private static void TestPoint2C() default }; - Assert.Throws(() => { - fixed (GenericsNative.Point2* pValues = &values[0]) - { - GenericsNative.AddPoint2Cs(pValues, values.Length); - } - }); - Assert.Throws(() => GenericsNative.AddPoint2Cs(values, values.Length)); Assert.Throws(() => GenericsNative.AddPoint2Cs(in values[0], values.Length)); diff --git a/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.Point3B.cs b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.Point3B.cs index 4cec3bea7088e..9903b3aac58ab 100644 --- a/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.Point3B.cs +++ b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.Point3B.cs @@ -11,24 +11,15 @@ unsafe partial class GenericsNative [DllImport(nameof(GenericsNative))] public static extern Point3 GetPoint3B(bool e00, bool e01, bool e02); - [DllImport(nameof(GenericsNative))] - public static extern void GetPoint3BOut(bool e00, bool e01, bool e02, Point3* value); - [DllImport(nameof(GenericsNative))] public static extern void GetPoint3BOut(bool e00, bool e01, bool e02, out Point3 value); - [DllImport(nameof(GenericsNative))] - public static extern Point3* GetPoint3BPtr(bool e00, bool e01, bool e02); - [DllImport(nameof(GenericsNative), EntryPoint = "GetPoint3BPtr")] public static extern ref readonly Point3 GetPoint3BRef(bool e00, bool e01, bool e02); [DllImport(nameof(GenericsNative))] public static extern Point3 AddPoint3B(Point3 lhs, Point3 rhs); - [DllImport(nameof(GenericsNative))] - public static extern Point3 AddPoint3Bs(Point3* pValues, int count); - [DllImport(nameof(GenericsNative))] public static extern Point3 AddPoint3Bs([MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] Point3[] pValues, int count); @@ -42,15 +33,8 @@ private static void TestPoint3B() { Assert.Throws(() => GenericsNative.GetPoint3B(true, false, true)); - Assert.Throws(() => { - GenericsNative.Point3 value2; - GenericsNative.GetPoint3BOut(true, false, true, &value2); - }); - Assert.Throws(() => GenericsNative.GetPoint3BOut(true, false, true, out GenericsNative.Point3 value3)); - Assert.Throws(() => GenericsNative.GetPoint3BPtr(true, false, true)); - Assert.Throws(() => GenericsNative.GetPoint3BRef(true, false, true)); Assert.Throws(() => GenericsNative.AddPoint3B(default, default)); @@ -63,13 +47,6 @@ private static void TestPoint3B() default }; - Assert.Throws(() => { - fixed (GenericsNative.Point3* pValues = &values[0]) - { - GenericsNative.AddPoint3Bs(pValues, values.Length); - } - }); - Assert.Throws(() => GenericsNative.AddPoint3Bs(values, values.Length)); Assert.Throws(() => GenericsNative.AddPoint3Bs(in values[0], values.Length)); diff --git a/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.Point3C.cs b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.Point3C.cs index f461443c41bc5..d823a6c717e2f 100644 --- a/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.Point3C.cs +++ b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.Point3C.cs @@ -11,24 +11,15 @@ unsafe partial class GenericsNative [DllImport(nameof(GenericsNative))] public static extern Point3 GetPoint3C(char e00, char e01, char e02); - [DllImport(nameof(GenericsNative))] - public static extern void GetPoint3COut(char e00, char e01, char e02, Point3* value); - [DllImport(nameof(GenericsNative))] public static extern void GetPoint3COut(char e00, char e01, char e02, out Point3 value); - [DllImport(nameof(GenericsNative))] - public static extern Point3* GetPoint3CPtr(char e00, char e01, char e02); - [DllImport(nameof(GenericsNative), EntryPoint = "GetPoint3CPtr")] public static extern ref readonly Point3 GetPoint3CRef(char e00, char e01, char e02); [DllImport(nameof(GenericsNative))] public static extern Point3 AddPoint3C(Point3 lhs, Point3 rhs); - [DllImport(nameof(GenericsNative))] - public static extern Point3 AddPoint3Cs(Point3* pValues, int count); - [DllImport(nameof(GenericsNative))] public static extern Point3 AddPoint3Cs([MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] Point3[] pValues, int count); @@ -42,15 +33,8 @@ private static void TestPoint3C() { Assert.Throws(() => GenericsNative.GetPoint3C('1', '2', '3')); - Assert.Throws(() => { - GenericsNative.Point3 value2; - GenericsNative.GetPoint3COut('1', '2', '3', &value2); - }); - Assert.Throws(() => GenericsNative.GetPoint3COut('1', '2', '3', out GenericsNative.Point3 value3)); - Assert.Throws(() => GenericsNative.GetPoint3CPtr('1', '2', '3')); - Assert.Throws(() => GenericsNative.GetPoint3CRef('1', '2', '3')); Assert.Throws(() => GenericsNative.AddPoint3C(default, default)); @@ -63,13 +47,6 @@ private static void TestPoint3C() default }; - Assert.Throws(() => { - fixed (GenericsNative.Point3* pValues = &values[0]) - { - GenericsNative.AddPoint3Cs(pValues, values.Length); - } - }); - Assert.Throws(() => GenericsNative.AddPoint3Cs(values, values.Length)); Assert.Throws(() => GenericsNative.AddPoint3Cs(in values[0], values.Length)); diff --git a/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.Point4B.cs b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.Point4B.cs index e66be24654f36..933689521f5cf 100644 --- a/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.Point4B.cs +++ b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.Point4B.cs @@ -11,24 +11,15 @@ unsafe partial class GenericsNative [DllImport(nameof(GenericsNative))] public static extern Point4 GetPoint4B(bool e00, bool e01, bool e02, bool e03); - [DllImport(nameof(GenericsNative))] - public static extern void GetPoint4BOut(bool e00, bool e01, bool e02, bool e03, Point4* value); - [DllImport(nameof(GenericsNative))] public static extern void GetPoint4BOut(bool e00, bool e01, bool e02, bool e03, out Point4 value); - [DllImport(nameof(GenericsNative))] - public static extern Point4* GetPoint4BPtr(bool e00, bool e01, bool e02, bool e03); - [DllImport(nameof(GenericsNative), EntryPoint = "GetPoint4BPtr")] public static extern ref readonly Point4 GetPoint4BRef(bool e00, bool e01, bool e02, bool e03); [DllImport(nameof(GenericsNative))] public static extern Point4 AddPoint4B(Point4 lhs, Point4 rhs); - [DllImport(nameof(GenericsNative))] - public static extern Point4 AddPoint4Bs(Point4* pValues, int count); - [DllImport(nameof(GenericsNative))] public static extern Point4 AddPoint4Bs([MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] Point4[] pValues, int count); @@ -42,15 +33,8 @@ private static void TestPoint4B() { Assert.Throws(() => GenericsNative.GetPoint4B(true, false, true, false)); - Assert.Throws(() => { - GenericsNative.Point4 value2; - GenericsNative.GetPoint4BOut(true, false, true, false, &value2); - }); - Assert.Throws(() => GenericsNative.GetPoint4BOut(true, false, true, false, out GenericsNative.Point4 value3)); - Assert.Throws(() => GenericsNative.GetPoint4BPtr(true, false, true, false)); - Assert.Throws(() => GenericsNative.GetPoint4BRef(true, false, true, false)); Assert.Throws(() => GenericsNative.AddPoint4B(default, default)); @@ -63,13 +47,6 @@ private static void TestPoint4B() default }; - Assert.Throws(() => { - fixed (GenericsNative.Point4* pValues = &values[0]) - { - GenericsNative.AddPoint4Bs(pValues, values.Length); - } - }); - Assert.Throws(() => GenericsNative.AddPoint4Bs(values, values.Length)); Assert.Throws(() => GenericsNative.AddPoint4Bs(in values[0], values.Length)); diff --git a/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.Point4C.cs b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.Point4C.cs index 7c9d297c8ec0f..4d014536eb285 100644 --- a/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.Point4C.cs +++ b/src/coreclr/tests/src/Interop/PInvoke/Generics/GenericsTest.Point4C.cs @@ -11,24 +11,15 @@ unsafe partial class GenericsNative [DllImport(nameof(GenericsNative))] public static extern Point4 GetPoint4C(char e00, char e01, char e02, char e03); - [DllImport(nameof(GenericsNative))] - public static extern void GetPoint4COut(char e00, char e01, char e02, char e03, Point4* value); - [DllImport(nameof(GenericsNative))] public static extern void GetPoint4COut(char e00, char e01, char e02, char e03, out Point4 value); - [DllImport(nameof(GenericsNative))] - public static extern Point4* GetPoint4CPtr(char e00, char e01, char e02, char e03); - [DllImport(nameof(GenericsNative), EntryPoint = "GetPoint4CPtr")] public static extern ref readonly Point4 GetPoint4CRef(char e00, char e01, char e02, char e03); [DllImport(nameof(GenericsNative))] public static extern Point4 AddPoint4C(Point4 lhs, Point4 rhs); - [DllImport(nameof(GenericsNative))] - public static extern Point4 AddPoint4Cs(Point4* pValues, int count); - [DllImport(nameof(GenericsNative))] public static extern Point4 AddPoint4Cs([MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] Point4[] pValues, int count); @@ -42,15 +33,8 @@ private static void TestPoint4C() { Assert.Throws(() => GenericsNative.GetPoint4C('1', '2', '3', '4')); - Assert.Throws(() => { - GenericsNative.Point4 value2; - GenericsNative.GetPoint4COut('1', '2', '3', '4', &value2); - }); - Assert.Throws(() => GenericsNative.GetPoint4COut('1', '2', '3', '4', out GenericsNative.Point4 value3)); - Assert.Throws(() => GenericsNative.GetPoint4CPtr('1', '2', '3', '4')); - Assert.Throws(() => GenericsNative.GetPoint4CRef('1', '2', '3', '4')); Assert.Throws(() => GenericsNative.AddPoint4C(default, default)); @@ -63,13 +47,6 @@ private static void TestPoint4C() default }; - Assert.Throws(() => { - fixed (GenericsNative.Point4* pValues = &values[0]) - { - GenericsNative.AddPoint4Cs(pValues, values.Length); - } - }); - Assert.Throws(() => GenericsNative.AddPoint4Cs(values, values.Length)); Assert.Throws(() => GenericsNative.AddPoint4Cs(in values[0], values.Length)); diff --git a/src/coreclr/tests/src/Interop/PInvoke/Primitives/Pointer/CMakeLists.txt b/src/coreclr/tests/src/Interop/PInvoke/Primitives/Pointer/CMakeLists.txt new file mode 100644 index 0000000000000..ca190ec6735d3 --- /dev/null +++ b/src/coreclr/tests/src/Interop/PInvoke/Primitives/Pointer/CMakeLists.txt @@ -0,0 +1,6 @@ +include ("${CLR_INTEROP_TEST_ROOT}/Interop.cmake") +set(SOURCES + NonBlittablePointerNative.cpp +) +add_library (NonBlittablePointerNative SHARED ${SOURCES}) +install (TARGETS NonBlittablePointerNative DESTINATION bin) diff --git a/src/coreclr/tests/src/Interop/PInvoke/Primitives/Pointer/NonBlittablePointer.csproj b/src/coreclr/tests/src/Interop/PInvoke/Primitives/Pointer/NonBlittablePointer.csproj new file mode 100644 index 0000000000000..e2e28689c1011 --- /dev/null +++ b/src/coreclr/tests/src/Interop/PInvoke/Primitives/Pointer/NonBlittablePointer.csproj @@ -0,0 +1,14 @@ + + + + Exe + true + + + + + + + + + diff --git a/src/coreclr/tests/src/Interop/PInvoke/Primitives/Pointer/NonBlittablePointerNative.cpp b/src/coreclr/tests/src/Interop/PInvoke/Primitives/Pointer/NonBlittablePointerNative.cpp new file mode 100644 index 0000000000000..b4b9075728674 --- /dev/null +++ b/src/coreclr/tests/src/Interop/PInvoke/Primitives/Pointer/NonBlittablePointerNative.cpp @@ -0,0 +1,10 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +#include + +extern "C" DLL_EXPORT void STDMETHODCALLTYPE Negate(bool* ptr) +{ + *ptr = !*ptr; +} diff --git a/src/coreclr/tests/src/Interop/PInvoke/Primitives/Pointer/PInvokePointerTest.cs b/src/coreclr/tests/src/Interop/PInvoke/Primitives/Pointer/PInvokePointerTest.cs deleted file mode 100644 index 1080e0b506a94..0000000000000 --- a/src/coreclr/tests/src/Interop/PInvoke/Primitives/Pointer/PInvokePointerTest.cs +++ /dev/null @@ -1,28 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -using System; -using System.Runtime.InteropServices; -using TestLibrary; - -unsafe class Program -{ - [StructLayout(LayoutKind.Sequential)] - struct NonBlittable - { - bool _nonBlittable; - } - - // the "string unused" parameter is just so that we don't hit https://github.com/dotnet/coreclr/issues/27408 that - // makes this p/invoke actually work. - [DllImport("Unused")] - private static extern void PointerToNonBlittableType(NonBlittable* pNonBlittable, string unused); - - static int Main() - { - Assert.Throws(() => PointerToNonBlittableType(null, null)); - - return 100; - } -} diff --git a/src/coreclr/tests/src/Interop/PInvoke/Primitives/Pointer/PInvokePointerTest.csproj b/src/coreclr/tests/src/Interop/PInvoke/Primitives/Pointer/PInvokePointerTest.csproj deleted file mode 100644 index 5bab1ec9f38bd..0000000000000 --- a/src/coreclr/tests/src/Interop/PInvoke/Primitives/Pointer/PInvokePointerTest.csproj +++ /dev/null @@ -1,11 +0,0 @@ - - - Exe - $(DefineConstants);STATIC - true - - - - - - diff --git a/src/coreclr/tests/src/Interop/PInvoke/Primitives/Pointer/Program.cs b/src/coreclr/tests/src/Interop/PInvoke/Primitives/Pointer/Program.cs new file mode 100644 index 0000000000000..d0d1d80ef95ae --- /dev/null +++ b/src/coreclr/tests/src/Interop/PInvoke/Primitives/Pointer/Program.cs @@ -0,0 +1,25 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Runtime.InteropServices; + +namespace NonBlittablePointer +{ + static class NonBlittablePointerNative + { + [DllImport(nameof(NonBlittablePointerNative))] + public static unsafe extern void Negate(bool* ptr); + } + + class Program + { + static unsafe int Main(string[] args) + { + bool value = true; + NonBlittablePointerNative.Negate(&value); + return value == false ? 100 : 101; + } + } +}