Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices')
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/AllowReversePInvokeCallsAttribute.cs16
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ArrayWithOffset.cs74
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/BStrWrapper.cs22
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/BestFitMappingAttribute.cs19
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/COMException.cs74
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/CallingConvention.cs16
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/CharSet.cs21
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ClassInterfaceAttribute.cs21
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ClassInterfaceType.cs13
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/CoClassAttribute.cs17
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/CollectionsMarshal.cs21
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComDefaultInterfaceAttribute.cs17
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComEventInterfaceAttribute.cs19
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComEventsHelpers.NoCom.cs21
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComImportAttribute.cs11
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComInterfaceType.cs14
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComMemberType.cs13
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComSourceInterfacesAttribute.cs37
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComTypes/IBindCtx.cs33
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComTypes/IConnectionPoint.cs18
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComTypes/IConnectionPointContainer.cs15
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComTypes/IEnumConnectionPoints.cs19
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComTypes/IEnumConnections.cs27
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComTypes/IEnumMoniker.cs19
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComTypes/IEnumString.cs19
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComTypes/IEnumVARIANT.cs23
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComTypes/IMoniker.cs49
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComTypes/IPersistFile.cs23
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComTypes/IRunningObjectTable.cs23
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComTypes/IStream.cs43
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComTypes/ITypeComp.cs36
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComTypes/ITypeInfo.cs303
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComTypes/ITypeInfo2.cs51
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComTypes/ITypeLib.cs54
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComTypes/ITypeLib2.cs31
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComVisibleAttribute.cs17
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/CriticalHandle.cs211
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/CurrencyWrapper.cs25
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/CustomQueryInterfaceMode.cs12
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/CustomQueryInterfaceResult.cs14
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/DefaultCharSetAttribute.cs17
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/DefaultDllImportSearchPathsAttribute.cs17
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/DefaultParameterValueAttribute.cs23
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/DispIdAttribute.cs17
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/DispatchWrapper.cs26
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/DllImportAttribute.cs26
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/DllImportSearchPath.cs18
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ErrorWrapper.cs29
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ExternalException.cs81
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/FieldOffsetAttribute.cs17
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/GCHandle.cs195
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/GCHandleType.cs18
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/GuidAttribute.cs17
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/HandleRef.cs29
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ICustomAdapter.cs13
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ICustomFactory.cs11
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ICustomMarshaler.cs20
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ICustomQueryInterface.cs12
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/InAttribute.cs14
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/InterfaceTypeAttribute.cs21
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/InvalidComObjectException.cs41
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/InvalidOleVariantTypeException.cs40
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/LCIDConversionAttribute.cs17
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/LayoutKind.cs14
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/Marshal.NoCom.cs204
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/Marshal.Unix.cs66
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/Marshal.Windows.cs131
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/Marshal.cs978
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/MarshalAsAttribute.cs39
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/MarshalDirectiveException.cs44
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/MemoryMarshal.cs535
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/NativeCallableAttribute.cs29
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/NativeLibrary.cs248
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/OptionalAttribute.cs14
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/OutAttribute.cs14
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/PreserveSigAttribute.cs14
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ProgIdAttribute.cs17
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/SEHException.cs47
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/SafeArrayRankMismatchException.cs39
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/SafeArrayTypeMismatchException.cs39
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/SafeBuffer.cs393
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/SafeHandle.cs253
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/StructLayoutAttribute.cs26
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/SuppressGCTransitionAttribute.cs65
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/TypeIdentifierAttribute.cs20
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/UnknownWrapper.cs17
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/UnmanagedFunctionPointerAttribute.cs27
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/UnmanagedType.cs48
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/VarEnum.cs54
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/VariantWrapper.cs17
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/WindowsRuntime/EventRegistrationToken.cs34
91 files changed, 0 insertions, 5656 deletions
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/AllowReversePInvokeCallsAttribute.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/AllowReversePInvokeCallsAttribute.cs
deleted file mode 100644
index cb640a7a8c8..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/AllowReversePInvokeCallsAttribute.cs
+++ /dev/null
@@ -1,16 +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.
-
-namespace System.Runtime.InteropServices
-{
- // To be used on methods that sink reverse P/Invoke calls.
- // This attribute was a Silverlight security measure, currently ignored.
- [AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = false)]
- public sealed class AllowReversePInvokeCallsAttribute : Attribute
- {
- public AllowReversePInvokeCallsAttribute()
- {
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ArrayWithOffset.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ArrayWithOffset.cs
deleted file mode 100644
index ca1567c514f..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ArrayWithOffset.cs
+++ /dev/null
@@ -1,74 +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.Runtime.CompilerServices;
-
-#pragma warning disable SA1121 // explicitly using type aliases instead of built-in types
-#if BIT64
-using nuint = System.UInt64;
-#else
-using nuint = System.UInt32;
-#endif
-
-namespace System.Runtime.InteropServices
-{
- public struct ArrayWithOffset
- {
- private readonly object? m_array;
- private readonly int m_offset;
- private readonly int m_count;
-
- // From MAX_SIZE_FOR_INTEROP in mlinfo.h
- private const int MaxSizeForInterop = 0x7ffffff0;
-
- public ArrayWithOffset(object? array, int offset)
- {
- int totalSize = 0;
- if (array != null)
- {
- if (!(array is Array arrayObj) || (arrayObj.Rank != 1) || !Marshal.IsPinnable(arrayObj))
- {
- throw new ArgumentException(SR.ArgumentException_NotIsomorphic);
- }
-
- nuint nativeTotalSize = (nuint)arrayObj.LongLength * (nuint)arrayObj.GetElementSize();
- if (nativeTotalSize > MaxSizeForInterop)
- {
- throw new ArgumentException(SR.Argument_StructArrayTooLarge);
- }
-
- totalSize = (int)nativeTotalSize;
- }
-
- if ((uint)offset > (uint)totalSize)
- {
- throw new IndexOutOfRangeException(SR.IndexOutOfRange_ArrayWithOffset);
- }
-
- m_array = array;
- m_offset = offset;
- m_count = totalSize - offset;
- }
-
- public object? GetArray() => m_array;
-
- public int GetOffset() => m_offset;
-
- public override int GetHashCode() => m_count + m_offset;
-
- public override bool Equals(object? obj)
- {
- return obj is ArrayWithOffset && Equals((ArrayWithOffset)obj);
- }
-
- public bool Equals(ArrayWithOffset obj)
- {
- return obj.m_array == m_array && obj.m_offset == m_offset && obj.m_count == m_count;
- }
-
- public static bool operator ==(ArrayWithOffset a, ArrayWithOffset b) => a.Equals(b);
-
- public static bool operator !=(ArrayWithOffset a, ArrayWithOffset b) => !(a == b);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/BStrWrapper.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/BStrWrapper.cs
deleted file mode 100644
index 9329b0513cf..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/BStrWrapper.cs
+++ /dev/null
@@ -1,22 +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.
-
-namespace System.Runtime.InteropServices
-{
- // Wrapper that is converted to a variant with VT_BSTR.
- public sealed class BStrWrapper
- {
- public BStrWrapper(string? value)
- {
- WrappedObject = value;
- }
-
- public BStrWrapper(object? value)
- {
- WrappedObject = (string?)value;
- }
-
- public string? WrappedObject { get; }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/BestFitMappingAttribute.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/BestFitMappingAttribute.cs
deleted file mode 100644
index 4ebee1538ca..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/BestFitMappingAttribute.cs
+++ /dev/null
@@ -1,19 +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.
-
-namespace System.Runtime.InteropServices
-{
- [AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Interface | AttributeTargets.Class | AttributeTargets.Struct, Inherited = false)]
- public sealed class BestFitMappingAttribute : Attribute
- {
- public BestFitMappingAttribute(bool BestFitMapping)
- {
- this.BestFitMapping = BestFitMapping;
- }
-
- public bool BestFitMapping { get; }
-
- public bool ThrowOnUnmappableChar;
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/COMException.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/COMException.cs
deleted file mode 100644
index 6b22d026313..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/COMException.cs
+++ /dev/null
@@ -1,74 +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.Runtime.Serialization;
-using System.Globalization;
-using System.Text;
-
-namespace System.Runtime.InteropServices
-{
- // Exception for COM Interop errors where we don't recognize the HResult.
- /// <summary>
- /// Exception class for all errors from COM Interop where we don't
- /// recognize the HResult.
- /// </summary>
- [Serializable]
- [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public class COMException : ExternalException
- {
- public COMException()
- : base(SR.Arg_COMException)
- {
- HResult = HResults.E_FAIL;
- }
-
- public COMException(string? message)
- : base(message)
- {
- HResult = HResults.E_FAIL;
- }
-
- public COMException(string? message, Exception? inner)
- : base(message, inner)
- {
- HResult = HResults.E_FAIL;
- }
-
- public COMException(string? message, int errorCode)
- : base(message)
- {
- HResult = errorCode;
- }
-
- protected COMException(SerializationInfo info, StreamingContext context) : base(info, context)
- {
- }
-
- public override string ToString()
- {
- StringBuilder s = new StringBuilder();
-
- string className = GetType().ToString();
- s.Append(className).Append(" (0x").Append(HResult.ToString("X8", CultureInfo.InvariantCulture)).Append(')');
-
- string message = Message;
- if (!string.IsNullOrEmpty(message))
- {
- s.Append(": ").Append(message);
- }
-
- Exception? innerException = InnerException;
- if (innerException != null)
- {
- s.Append(Environment.NewLineConst + InnerExceptionPrefix).Append(innerException.ToString());
- }
-
- string? stackTrace = StackTrace;
- if (stackTrace != null)
- s.AppendLine().Append(stackTrace);
-
- return s.ToString();
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/CallingConvention.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/CallingConvention.cs
deleted file mode 100644
index 3b18fdee3a8..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/CallingConvention.cs
+++ /dev/null
@@ -1,16 +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.
-
-namespace System.Runtime.InteropServices
-{
- // Used for the CallingConvention named argument to the DllImport and NativeCallable attribute
- public enum CallingConvention
- {
- Winapi = 1,
- Cdecl = 2,
- StdCall = 3,
- ThisCall = 4,
- FastCall = 5,
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/CharSet.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/CharSet.cs
deleted file mode 100644
index 955ec8eb2f7..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/CharSet.cs
+++ /dev/null
@@ -1,21 +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.
-
-namespace System.Runtime.InteropServices
-{
- // Use this in P/Invoke function prototypes to specify
- // which character set to use when marshalling Strings.
- // Using Ansi will marshal the strings as 1 byte char*'s.
- // Using Unicode will marshal the strings as 2 byte wchar*'s.
- // Generally you probably want to use Auto, which does the
- // right thing 99% of the time.
-
- public enum CharSet
- {
- None = 1, // User didn't specify how to marshal strings.
- Ansi = 2, // Strings should be marshalled as ANSI 1 byte chars.
- Unicode = 3, // Strings should be marshalled as Unicode 2 byte chars.
- Auto = 4, // Marshal Strings in the right way for the target system.
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ClassInterfaceAttribute.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ClassInterfaceAttribute.cs
deleted file mode 100644
index 59d79ff4438..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ClassInterfaceAttribute.cs
+++ /dev/null
@@ -1,21 +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.
-
-namespace System.Runtime.InteropServices
-{
- [AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Class, Inherited = false)]
- public sealed class ClassInterfaceAttribute : Attribute
- {
- public ClassInterfaceAttribute(ClassInterfaceType classInterfaceType)
- {
- Value = classInterfaceType;
- }
- public ClassInterfaceAttribute(short classInterfaceType)
- {
- Value = (ClassInterfaceType)classInterfaceType;
- }
-
- public ClassInterfaceType Value { get; }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ClassInterfaceType.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ClassInterfaceType.cs
deleted file mode 100644
index ef1fe841940..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ClassInterfaceType.cs
+++ /dev/null
@@ -1,13 +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.
-
-namespace System.Runtime.InteropServices
-{
- public enum ClassInterfaceType
- {
- None = 0,
- AutoDispatch = 1,
- AutoDual = 2
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/CoClassAttribute.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/CoClassAttribute.cs
deleted file mode 100644
index 4be6622c3da..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/CoClassAttribute.cs
+++ /dev/null
@@ -1,17 +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.
-
-namespace System.Runtime.InteropServices
-{
- [AttributeUsage(AttributeTargets.Interface, Inherited = false)]
- public sealed class CoClassAttribute : Attribute
- {
- public CoClassAttribute(Type coClass)
- {
- CoClass = coClass;
- }
-
- public Type CoClass { get; }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/CollectionsMarshal.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/CollectionsMarshal.cs
deleted file mode 100644
index 8b38858d084..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/CollectionsMarshal.cs
+++ /dev/null
@@ -1,21 +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.Collections.Generic;
-
-namespace System.Runtime.InteropServices
-{
- /// <summary>
- /// An unsafe class that provides a set of methods to access the underlying data representations of collections.
- /// </summary>
- public static class CollectionsMarshal
- {
- /// <summary>
- /// Get a <see cref="Span{T}"/> view over a <see cref="List{T}"/>'s data.
- /// Items should not be added or removed from the <see cref="List{T}"/> while the <see cref="Span{T}"/> is in use.
- /// </summary>
- public static Span<T> AsSpan<T>(List<T>? list)
- => list is null ? default : new Span<T>(list._items, 0, list._size);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComDefaultInterfaceAttribute.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComDefaultInterfaceAttribute.cs
deleted file mode 100644
index 1b84f5f561a..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComDefaultInterfaceAttribute.cs
+++ /dev/null
@@ -1,17 +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.
-
-namespace System.Runtime.InteropServices
-{
- [AttributeUsage(AttributeTargets.Class, Inherited = false)]
- public sealed class ComDefaultInterfaceAttribute : Attribute
- {
- public ComDefaultInterfaceAttribute(Type defaultInterface)
- {
- Value = defaultInterface;
- }
-
- public Type Value { get; }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComEventInterfaceAttribute.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComEventInterfaceAttribute.cs
deleted file mode 100644
index d4ccc702e05..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComEventInterfaceAttribute.cs
+++ /dev/null
@@ -1,19 +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.
-
-namespace System.Runtime.InteropServices
-{
- [AttributeUsage(AttributeTargets.Interface, Inherited = false)]
- public sealed class ComEventInterfaceAttribute : Attribute
- {
- public ComEventInterfaceAttribute(Type SourceInterface, Type EventProvider)
- {
- this.SourceInterface = SourceInterface;
- this.EventProvider = EventProvider;
- }
-
- public Type SourceInterface { get; }
- public Type EventProvider { get; }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComEventsHelpers.NoCom.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComEventsHelpers.NoCom.cs
deleted file mode 100644
index 7b29d6f9ad0..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComEventsHelpers.NoCom.cs
+++ /dev/null
@@ -1,21 +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.Runtime.InteropServices.ComTypes;
-
-namespace System.Runtime.InteropServices
-{
- public static class ComEventsHelper
- {
- public static void Combine(object rcw, Guid iid, int dispid, Delegate d)
- {
- throw new PlatformNotSupportedException(SR.PlatformNotSupported_ComInterop);
- }
-
- public static Delegate Remove(object rcw, Guid iid, int dispid, Delegate d)
- {
- throw new PlatformNotSupportedException(SR.PlatformNotSupported_ComInterop);
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComImportAttribute.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComImportAttribute.cs
deleted file mode 100644
index a290bf4510d..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComImportAttribute.cs
+++ /dev/null
@@ -1,11 +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.
-
-namespace System.Runtime.InteropServices
-{
- [AttributeUsage(AttributeTargets.Class | AttributeTargets.Interface, Inherited = false)]
- public sealed class ComImportAttribute : Attribute
- {
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComInterfaceType.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComInterfaceType.cs
deleted file mode 100644
index 03b8ae534ad..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComInterfaceType.cs
+++ /dev/null
@@ -1,14 +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.
-
-namespace System.Runtime.InteropServices
-{
- public enum ComInterfaceType
- {
- InterfaceIsDual = 0,
- InterfaceIsIUnknown = 1,
- InterfaceIsIDispatch = 2,
- InterfaceIsIInspectable = 3,
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComMemberType.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComMemberType.cs
deleted file mode 100644
index 4be75b03b9f..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComMemberType.cs
+++ /dev/null
@@ -1,13 +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.
-
-namespace System.Runtime.InteropServices
-{
- public enum ComMemberType
- {
- Method = 0,
- PropGet = 1,
- PropSet = 2
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComSourceInterfacesAttribute.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComSourceInterfacesAttribute.cs
deleted file mode 100644
index a62871a3997..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComSourceInterfacesAttribute.cs
+++ /dev/null
@@ -1,37 +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.
-
-namespace System.Runtime.InteropServices
-{
- [AttributeUsage(AttributeTargets.Class, Inherited = true)]
- public sealed class ComSourceInterfacesAttribute : Attribute
- {
- public ComSourceInterfacesAttribute(string sourceInterfaces)
- {
- Value = sourceInterfaces;
- }
-
- public ComSourceInterfacesAttribute(Type sourceInterface)
- {
- Value = sourceInterface.FullName!;
- }
-
- public ComSourceInterfacesAttribute(Type sourceInterface1, Type sourceInterface2)
- {
- Value = sourceInterface1.FullName + "\0" + sourceInterface2.FullName;
- }
-
- public ComSourceInterfacesAttribute(Type sourceInterface1, Type sourceInterface2, Type sourceInterface3)
- {
- Value = sourceInterface1.FullName + "\0" + sourceInterface2.FullName + "\0" + sourceInterface3.FullName;
- }
-
- public ComSourceInterfacesAttribute(Type sourceInterface1, Type sourceInterface2, Type sourceInterface3, Type sourceInterface4)
- {
- Value = sourceInterface1.FullName + "\0" + sourceInterface2.FullName + "\0" + sourceInterface3.FullName + "\0" + sourceInterface4.FullName;
- }
-
- public string Value { get; }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComTypes/IBindCtx.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComTypes/IBindCtx.cs
deleted file mode 100644
index 0ad56c23bd9..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComTypes/IBindCtx.cs
+++ /dev/null
@@ -1,33 +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.
-
-namespace System.Runtime.InteropServices.ComTypes
-{
- [StructLayout(LayoutKind.Sequential)]
- public struct BIND_OPTS
- {
- public int cbStruct;
- public int grfFlags;
- public int grfMode;
- public int dwTickCountDeadline;
- }
-
- [Guid("0000000e-0000-0000-C000-000000000046")]
- [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
- [ComImport]
- public interface IBindCtx
- {
- void RegisterObjectBound([MarshalAs(UnmanagedType.Interface)] object punk);
- void RevokeObjectBound([MarshalAs(UnmanagedType.Interface)] object punk);
- void ReleaseBoundObjects();
- void SetBindOptions([In] ref BIND_OPTS pbindopts);
- void GetBindOptions(ref BIND_OPTS pbindopts);
- void GetRunningObjectTable(out IRunningObjectTable? pprot);
- void RegisterObjectParam([MarshalAs(UnmanagedType.LPWStr)] string pszKey, [MarshalAs(UnmanagedType.Interface)] object punk);
- void GetObjectParam([MarshalAs(UnmanagedType.LPWStr)] string pszKey, [MarshalAs(UnmanagedType.Interface)] out object? ppunk);
- void EnumObjectParam(out IEnumString? ppenum);
- [PreserveSig]
- int RevokeObjectParam([MarshalAs(UnmanagedType.LPWStr)] string pszKey);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComTypes/IConnectionPoint.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComTypes/IConnectionPoint.cs
deleted file mode 100644
index b2ce1928a13..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComTypes/IConnectionPoint.cs
+++ /dev/null
@@ -1,18 +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.
-
-namespace System.Runtime.InteropServices.ComTypes
-{
- [Guid("B196B286-BAB4-101A-B69C-00AA00341D07")]
- [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
- [ComImport]
- public interface IConnectionPoint
- {
- void GetConnectionInterface(out Guid pIID);
- void GetConnectionPointContainer(out IConnectionPointContainer ppCPC);
- void Advise([MarshalAs(UnmanagedType.Interface)] object pUnkSink, out int pdwCookie);
- void Unadvise(int dwCookie);
- void EnumConnections(out IEnumConnections ppEnum);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComTypes/IConnectionPointContainer.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComTypes/IConnectionPointContainer.cs
deleted file mode 100644
index 4dd08658a0d..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComTypes/IConnectionPointContainer.cs
+++ /dev/null
@@ -1,15 +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.
-
-namespace System.Runtime.InteropServices.ComTypes
-{
- [Guid("B196B284-BAB4-101A-B69C-00AA00341D07")]
- [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
- [ComImport]
- public interface IConnectionPointContainer
- {
- void EnumConnectionPoints(out IEnumConnectionPoints ppEnum);
- void FindConnectionPoint([In] ref Guid riid, out IConnectionPoint? ppCP);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComTypes/IEnumConnectionPoints.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComTypes/IEnumConnectionPoints.cs
deleted file mode 100644
index 99df6ac60e4..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComTypes/IEnumConnectionPoints.cs
+++ /dev/null
@@ -1,19 +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.
-
-namespace System.Runtime.InteropServices.ComTypes
-{
- [Guid("B196B285-BAB4-101A-B69C-00AA00341D07")]
- [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
- [ComImport]
- public interface IEnumConnectionPoints
- {
- [PreserveSig]
- int Next(int celt, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 0), Out] IConnectionPoint[] rgelt, IntPtr pceltFetched);
- [PreserveSig]
- int Skip(int celt);
- void Reset();
- void Clone(out IEnumConnectionPoints ppenum);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComTypes/IEnumConnections.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComTypes/IEnumConnections.cs
deleted file mode 100644
index 951685beff7..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComTypes/IEnumConnections.cs
+++ /dev/null
@@ -1,27 +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.
-
-namespace System.Runtime.InteropServices.ComTypes
-{
- [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
- public struct CONNECTDATA
- {
- [MarshalAs(UnmanagedType.Interface)]
- public object pUnk;
- public int dwCookie;
- }
-
- [Guid("B196B287-BAB4-101A-B69C-00AA00341D07")]
- [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
- [ComImport]
- public interface IEnumConnections
- {
- [PreserveSig]
- int Next(int celt, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 0), Out] CONNECTDATA[] rgelt, IntPtr pceltFetched);
- [PreserveSig]
- int Skip(int celt);
- void Reset();
- void Clone(out IEnumConnections ppenum);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComTypes/IEnumMoniker.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComTypes/IEnumMoniker.cs
deleted file mode 100644
index 9a63ba0a11a..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComTypes/IEnumMoniker.cs
+++ /dev/null
@@ -1,19 +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.
-
-namespace System.Runtime.InteropServices.ComTypes
-{
- [Guid("00000102-0000-0000-C000-000000000046")]
- [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
- [ComImport]
- public interface IEnumMoniker
- {
- [PreserveSig]
- int Next(int celt, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 0), Out] IMoniker[] rgelt, IntPtr pceltFetched);
- [PreserveSig]
- int Skip(int celt);
- void Reset();
- void Clone(out IEnumMoniker ppenum);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComTypes/IEnumString.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComTypes/IEnumString.cs
deleted file mode 100644
index 57fc59121f0..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComTypes/IEnumString.cs
+++ /dev/null
@@ -1,19 +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.
-
-namespace System.Runtime.InteropServices.ComTypes
-{
- [Guid("00000101-0000-0000-C000-000000000046")]
- [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
- [ComImport]
- public interface IEnumString
- {
- [PreserveSig]
- int Next(int celt, [MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.LPWStr, SizeParamIndex = 0), Out] string[] rgelt, IntPtr pceltFetched);
- [PreserveSig]
- int Skip(int celt);
- void Reset();
- void Clone(out IEnumString ppenum);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComTypes/IEnumVARIANT.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComTypes/IEnumVARIANT.cs
deleted file mode 100644
index bb6688ee2c7..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComTypes/IEnumVARIANT.cs
+++ /dev/null
@@ -1,23 +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.
-
-namespace System.Runtime.InteropServices.ComTypes
-{
- [Guid("00020404-0000-0000-C000-000000000046")]
- [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
- [ComImport]
- public interface IEnumVARIANT
- {
- [PreserveSig]
- int Next(int celt, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 0), Out] object?[] rgVar, IntPtr pceltFetched);
-
- [PreserveSig]
- int Skip(int celt);
-
- [PreserveSig]
- int Reset();
-
- IEnumVARIANT Clone();
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComTypes/IMoniker.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComTypes/IMoniker.cs
deleted file mode 100644
index f2d5242294d..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComTypes/IMoniker.cs
+++ /dev/null
@@ -1,49 +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.
-
-namespace System.Runtime.InteropServices.ComTypes
-{
- [StructLayout(LayoutKind.Sequential)]
- public struct FILETIME
- {
- public int dwLowDateTime;
- public int dwHighDateTime;
- }
-
- [Guid("0000000f-0000-0000-C000-000000000046")]
- [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
- [ComImport]
- public interface IMoniker
- {
- // IPersist portion
- void GetClassID(out Guid pClassID);
-
- // IPersistStream portion
- [PreserveSig]
- int IsDirty();
- void Load(IStream pStm);
- void Save(IStream pStm, [MarshalAs(UnmanagedType.Bool)] bool fClearDirty);
- void GetSizeMax(out long pcbSize);
-
- // IMoniker portion
- void BindToObject(IBindCtx pbc, IMoniker? pmkToLeft, [In] ref Guid riidResult, [MarshalAs(UnmanagedType.Interface)] out object ppvResult);
- void BindToStorage(IBindCtx pbc, IMoniker? pmkToLeft, [In] ref Guid riid, [MarshalAs(UnmanagedType.Interface)] out object ppvObj);
- void Reduce(IBindCtx pbc, int dwReduceHowFar, ref IMoniker? ppmkToLeft, out IMoniker? ppmkReduced);
- void ComposeWith(IMoniker pmkRight, [MarshalAs(UnmanagedType.Bool)] bool fOnlyIfNotGeneric, out IMoniker? ppmkComposite);
- void Enum([MarshalAs(UnmanagedType.Bool)] bool fForward, out IEnumMoniker? ppenumMoniker);
- [PreserveSig]
- int IsEqual(IMoniker pmkOtherMoniker);
- void Hash(out int pdwHash);
- [PreserveSig]
- int IsRunning(IBindCtx pbc, IMoniker? pmkToLeft, IMoniker? pmkNewlyRunning);
- void GetTimeOfLastChange(IBindCtx pbc, IMoniker? pmkToLeft, out FILETIME pFileTime);
- void Inverse(out IMoniker ppmk);
- void CommonPrefixWith(IMoniker pmkOther, out IMoniker? ppmkPrefix);
- void RelativePathTo(IMoniker pmkOther, out IMoniker? ppmkRelPath);
- void GetDisplayName(IBindCtx pbc, IMoniker? pmkToLeft, [MarshalAs(UnmanagedType.LPWStr)] out string ppszDisplayName);
- void ParseDisplayName(IBindCtx pbc, IMoniker pmkToLeft, [MarshalAs(UnmanagedType.LPWStr)] string pszDisplayName, out int pchEaten, out IMoniker ppmkOut);
- [PreserveSig]
- int IsSystemMoniker(out int pdwMksys);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComTypes/IPersistFile.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComTypes/IPersistFile.cs
deleted file mode 100644
index 4ae9d127ea9..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComTypes/IPersistFile.cs
+++ /dev/null
@@ -1,23 +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.
-
-namespace System.Runtime.InteropServices.ComTypes
-{
- [Guid("0000010b-0000-0000-C000-000000000046")]
- [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
- [ComImport]
- public interface IPersistFile
- {
- // IPersist portion
- void GetClassID(out Guid pClassID);
-
- // IPersistFile portion
- [PreserveSig]
- int IsDirty();
- void Load([MarshalAs(UnmanagedType.LPWStr)] string pszFileName, int dwMode);
- void Save([MarshalAs(UnmanagedType.LPWStr)] string? pszFileName, [MarshalAs(UnmanagedType.Bool)] bool fRemember);
- void SaveCompleted([MarshalAs(UnmanagedType.LPWStr)] string pszFileName);
- void GetCurFile([MarshalAs(UnmanagedType.LPWStr)] out string ppszFileName);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComTypes/IRunningObjectTable.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComTypes/IRunningObjectTable.cs
deleted file mode 100644
index 1884fcc99b5..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComTypes/IRunningObjectTable.cs
+++ /dev/null
@@ -1,23 +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.
-
-namespace System.Runtime.InteropServices.ComTypes
-{
- [Guid("00000010-0000-0000-C000-000000000046")]
- [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
- [ComImport]
- public interface IRunningObjectTable
- {
- int Register(int grfFlags, [MarshalAs(UnmanagedType.Interface)] object punkObject, IMoniker pmkObjectName);
- void Revoke(int dwRegister);
- [PreserveSig]
- int IsRunning(IMoniker pmkObjectName);
- [PreserveSig]
- int GetObject(IMoniker pmkObjectName, [MarshalAs(UnmanagedType.Interface)] out object ppunkObject);
- void NoteChangeTime(int dwRegister, ref FILETIME pfiletime);
- [PreserveSig]
- int GetTimeOfLastChange(IMoniker pmkObjectName, out FILETIME pfiletime);
- void EnumRunning(out IEnumMoniker ppenumMoniker);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComTypes/IStream.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComTypes/IStream.cs
deleted file mode 100644
index 09b284041e7..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComTypes/IStream.cs
+++ /dev/null
@@ -1,43 +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.
-
-namespace System.Runtime.InteropServices.ComTypes
-{
- [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
- public struct STATSTG
- {
- public string pwcsName;
- public int type;
- public long cbSize;
- public FILETIME mtime;
- public FILETIME ctime;
- public FILETIME atime;
- public int grfMode;
- public int grfLocksSupported;
- public Guid clsid;
- public int grfStateBits;
- public int reserved;
- }
-
- [Guid("0000000c-0000-0000-C000-000000000046")]
- [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
- [ComImport]
- public interface IStream
- {
- // ISequentialStream portion
- void Read([MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1), Out] byte[] pv, int cb, IntPtr pcbRead);
- void Write([MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] byte[] pv, int cb, IntPtr pcbWritten);
-
- // IStream portion
- void Seek(long dlibMove, int dwOrigin, IntPtr plibNewPosition);
- void SetSize(long libNewSize);
- void CopyTo(IStream pstm, long cb, IntPtr pcbRead, IntPtr pcbWritten);
- void Commit(int grfCommitFlags);
- void Revert();
- void LockRegion(long libOffset, long cb, int dwLockType);
- void UnlockRegion(long libOffset, long cb, int dwLockType);
- void Stat(out STATSTG pstatstg, int grfStatFlag);
- void Clone(out IStream ppstm);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComTypes/ITypeComp.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComTypes/ITypeComp.cs
deleted file mode 100644
index 7e637936151..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComTypes/ITypeComp.cs
+++ /dev/null
@@ -1,36 +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.
-
-namespace System.Runtime.InteropServices.ComTypes
-{
- public enum DESCKIND
- {
- DESCKIND_NONE = 0,
- DESCKIND_FUNCDESC = DESCKIND_NONE + 1,
- DESCKIND_VARDESC = DESCKIND_FUNCDESC + 1,
- DESCKIND_TYPECOMP = DESCKIND_VARDESC + 1,
- DESCKIND_IMPLICITAPPOBJ = DESCKIND_TYPECOMP + 1,
- DESCKIND_MAX = DESCKIND_IMPLICITAPPOBJ + 1
- }
-
- [StructLayout(LayoutKind.Explicit, CharSet = CharSet.Unicode)]
- public struct BINDPTR
- {
- [FieldOffset(0)]
- public IntPtr lpfuncdesc;
- [FieldOffset(0)]
- public IntPtr lpvardesc;
- [FieldOffset(0)]
- public IntPtr lptcomp;
- }
-
- [Guid("00020403-0000-0000-C000-000000000046")]
- [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
- [ComImport]
- public interface ITypeComp
- {
- void Bind([MarshalAs(UnmanagedType.LPWStr)] string szName, int lHashVal, short wFlags, out ITypeInfo ppTInfo, out DESCKIND pDescKind, out BINDPTR pBindPtr);
- void BindType([MarshalAs(UnmanagedType.LPWStr)] string szName, int lHashVal, out ITypeInfo ppTInfo, out ITypeComp ppTComp);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComTypes/ITypeInfo.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComTypes/ITypeInfo.cs
deleted file mode 100644
index 0b00fdceab8..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComTypes/ITypeInfo.cs
+++ /dev/null
@@ -1,303 +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.
-
-namespace System.Runtime.InteropServices.ComTypes
-{
- public enum TYPEKIND
- {
- TKIND_ENUM = 0,
- TKIND_RECORD = TKIND_ENUM + 1,
- TKIND_MODULE = TKIND_RECORD + 1,
- TKIND_INTERFACE = TKIND_MODULE + 1,
- TKIND_DISPATCH = TKIND_INTERFACE + 1,
- TKIND_COCLASS = TKIND_DISPATCH + 1,
- TKIND_ALIAS = TKIND_COCLASS + 1,
- TKIND_UNION = TKIND_ALIAS + 1,
- TKIND_MAX = TKIND_UNION + 1
- }
-
- [Flags]
- public enum TYPEFLAGS : short
- {
- TYPEFLAG_FAPPOBJECT = 0x1,
- TYPEFLAG_FCANCREATE = 0x2,
- TYPEFLAG_FLICENSED = 0x4,
- TYPEFLAG_FPREDECLID = 0x8,
- TYPEFLAG_FHIDDEN = 0x10,
- TYPEFLAG_FCONTROL = 0x20,
- TYPEFLAG_FDUAL = 0x40,
- TYPEFLAG_FNONEXTENSIBLE = 0x80,
- TYPEFLAG_FOLEAUTOMATION = 0x100,
- TYPEFLAG_FRESTRICTED = 0x200,
- TYPEFLAG_FAGGREGATABLE = 0x400,
- TYPEFLAG_FREPLACEABLE = 0x800,
- TYPEFLAG_FDISPATCHABLE = 0x1000,
- TYPEFLAG_FREVERSEBIND = 0x2000,
- TYPEFLAG_FPROXY = 0x4000
- }
-
- [Flags]
- public enum IMPLTYPEFLAGS
- {
- IMPLTYPEFLAG_FDEFAULT = 0x1,
- IMPLTYPEFLAG_FSOURCE = 0x2,
- IMPLTYPEFLAG_FRESTRICTED = 0x4,
- IMPLTYPEFLAG_FDEFAULTVTABLE = 0x8,
- }
-
- [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
- public struct TYPEATTR
- {
- // Constant used with the memid fields.
- public const int MEMBER_ID_NIL = unchecked((int)0xFFFFFFFF);
-
- // Actual fields of the TypeAttr struct.
- public Guid guid;
- public int lcid;
- public int dwReserved;
- public int memidConstructor;
- public int memidDestructor;
- public IntPtr lpstrSchema;
- public int cbSizeInstance;
- public TYPEKIND typekind;
- public short cFuncs;
- public short cVars;
- public short cImplTypes;
- public short cbSizeVft;
- public short cbAlignment;
- public TYPEFLAGS wTypeFlags;
- public short wMajorVerNum;
- public short wMinorVerNum;
- public TYPEDESC tdescAlias;
- public IDLDESC idldescType;
- }
-
- [StructLayout(LayoutKind.Sequential)]
- public struct FUNCDESC
- {
- public int memid; // MEMBERID memid;
- public IntPtr lprgscode; // /* [size_is(cScodes)] */ SCODE RPC_FAR *lprgscode;
- public IntPtr lprgelemdescParam; // /* [size_is(cParams)] */ ELEMDESC __RPC_FAR *lprgelemdescParam;
- public FUNCKIND funckind; // FUNCKIND funckind;
- public INVOKEKIND invkind; // INVOKEKIND invkind;
- public CALLCONV callconv; // CALLCONV callconv;
- public short cParams; // short cParams;
- public short cParamsOpt; // short cParamsOpt;
- public short oVft; // short oVft;
- public short cScodes; // short cScodes;
- public ELEMDESC elemdescFunc; // ELEMDESC elemdescFunc;
- public short wFuncFlags; // WORD wFuncFlags;
- }
-
- [Flags]
- public enum IDLFLAG : short
- {
- IDLFLAG_NONE = PARAMFLAG.PARAMFLAG_NONE,
- IDLFLAG_FIN = PARAMFLAG.PARAMFLAG_FIN,
- IDLFLAG_FOUT = PARAMFLAG.PARAMFLAG_FOUT,
- IDLFLAG_FLCID = PARAMFLAG.PARAMFLAG_FLCID,
- IDLFLAG_FRETVAL = PARAMFLAG.PARAMFLAG_FRETVAL
- }
-
- [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
- public struct IDLDESC
- {
- public IntPtr dwReserved;
- public IDLFLAG wIDLFlags;
- }
-
- [Flags]
- public enum PARAMFLAG : short
- {
- PARAMFLAG_NONE = 0,
- PARAMFLAG_FIN = 0x1,
- PARAMFLAG_FOUT = 0x2,
- PARAMFLAG_FLCID = 0x4,
- PARAMFLAG_FRETVAL = 0x8,
- PARAMFLAG_FOPT = 0x10,
- PARAMFLAG_FHASDEFAULT = 0x20,
- PARAMFLAG_FHASCUSTDATA = 0x40
- }
-
- [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
- public struct PARAMDESC
- {
- public IntPtr lpVarValue;
- public PARAMFLAG wParamFlags;
- }
-
- [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
- public struct TYPEDESC
- {
- public IntPtr lpValue;
- public short vt;
- }
-
- [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
- public struct ELEMDESC
- {
- public TYPEDESC tdesc;
-
- [StructLayout(LayoutKind.Explicit, CharSet = CharSet.Unicode)]
- public struct DESCUNION
- {
- [FieldOffset(0)]
- public IDLDESC idldesc;
- [FieldOffset(0)]
- public PARAMDESC paramdesc;
- }
- public DESCUNION desc;
- }
-
- public enum VARKIND : int
- {
- VAR_PERINSTANCE = 0x0,
- VAR_STATIC = 0x1,
- VAR_CONST = 0x2,
- VAR_DISPATCH = 0x3
- }
-
- [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
-
- public struct VARDESC
- {
- public int memid;
- public string lpstrSchema;
-
- [StructLayout(LayoutKind.Explicit, CharSet = CharSet.Unicode)]
- public struct DESCUNION
- {
- [FieldOffset(0)]
- public int oInst;
- [FieldOffset(0)]
- public IntPtr lpvarValue;
- }
-
- public DESCUNION desc;
-
- public ELEMDESC elemdescVar;
- public short wVarFlags;
- public VARKIND varkind;
- }
-
- [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
- public struct DISPPARAMS
- {
- public IntPtr rgvarg;
- public IntPtr rgdispidNamedArgs;
- public int cArgs;
- public int cNamedArgs;
- }
-
- [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
- public struct EXCEPINFO
- {
- public short wCode;
- public short wReserved;
- [MarshalAs(UnmanagedType.BStr)] public string bstrSource;
- [MarshalAs(UnmanagedType.BStr)] public string bstrDescription;
- [MarshalAs(UnmanagedType.BStr)] public string bstrHelpFile;
- public int dwHelpContext;
- public IntPtr pvReserved;
- public IntPtr pfnDeferredFillIn;
- public int scode;
- }
-
- public enum FUNCKIND : int
- {
- FUNC_VIRTUAL = 0,
- FUNC_PUREVIRTUAL = 1,
- FUNC_NONVIRTUAL = 2,
- FUNC_STATIC = 3,
- FUNC_DISPATCH = 4
- }
-
- [Flags]
- public enum INVOKEKIND : int
- {
- INVOKE_FUNC = 0x1,
- INVOKE_PROPERTYGET = 0x2,
- INVOKE_PROPERTYPUT = 0x4,
- INVOKE_PROPERTYPUTREF = 0x8
- }
-
- public enum CALLCONV : int
- {
- CC_CDECL = 1,
- CC_MSCPASCAL = 2,
- CC_PASCAL = CC_MSCPASCAL,
- CC_MACPASCAL = 3,
- CC_STDCALL = 4,
- CC_RESERVED = 5,
- CC_SYSCALL = 6,
- CC_MPWCDECL = 7,
- CC_MPWPASCAL = 8,
- CC_MAX = 9
- }
-
- [Flags]
- public enum FUNCFLAGS : short
- {
- FUNCFLAG_FRESTRICTED = 0x1,
- FUNCFLAG_FSOURCE = 0x2,
- FUNCFLAG_FBINDABLE = 0x4,
- FUNCFLAG_FREQUESTEDIT = 0x8,
- FUNCFLAG_FDISPLAYBIND = 0x10,
- FUNCFLAG_FDEFAULTBIND = 0x20,
- FUNCFLAG_FHIDDEN = 0x40,
- FUNCFLAG_FUSESGETLASTERROR = 0x80,
- FUNCFLAG_FDEFAULTCOLLELEM = 0x100,
- FUNCFLAG_FUIDEFAULT = 0x200,
- FUNCFLAG_FNONBROWSABLE = 0x400,
- FUNCFLAG_FREPLACEABLE = 0x800,
- FUNCFLAG_FIMMEDIATEBIND = 0x1000
- }
-
- [Flags]
- public enum VARFLAGS : short
- {
- VARFLAG_FREADONLY = 0x1,
- VARFLAG_FSOURCE = 0x2,
- VARFLAG_FBINDABLE = 0x4,
- VARFLAG_FREQUESTEDIT = 0x8,
- VARFLAG_FDISPLAYBIND = 0x10,
- VARFLAG_FDEFAULTBIND = 0x20,
- VARFLAG_FHIDDEN = 0x40,
- VARFLAG_FRESTRICTED = 0x80,
- VARFLAG_FDEFAULTCOLLELEM = 0x100,
- VARFLAG_FUIDEFAULT = 0x200,
- VARFLAG_FNONBROWSABLE = 0x400,
- VARFLAG_FREPLACEABLE = 0x800,
- VARFLAG_FIMMEDIATEBIND = 0x1000
- }
-
- [Guid("00020401-0000-0000-C000-000000000046")]
- [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
- [ComImport]
- public interface ITypeInfo
- {
- void GetTypeAttr(out IntPtr ppTypeAttr);
- void GetTypeComp(out ITypeComp ppTComp);
- void GetFuncDesc(int index, out IntPtr ppFuncDesc);
- void GetVarDesc(int index, out IntPtr ppVarDesc);
- void GetNames(int memid, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 2), Out] string[] rgBstrNames, int cMaxNames, out int pcNames);
- void GetRefTypeOfImplType(int index, out int href);
- void GetImplTypeFlags(int index, out IMPLTYPEFLAGS pImplTypeFlags);
- void GetIDsOfNames([MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.LPWStr, SizeParamIndex = 1), In] string[] rgszNames, int cNames, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1), Out] int[] pMemId);
- void Invoke([MarshalAs(UnmanagedType.IUnknown)] object pvInstance, int memid, short wFlags, ref DISPPARAMS pDispParams, IntPtr pVarResult, IntPtr pExcepInfo, out int puArgErr);
- void GetDocumentation(int index, out string strName, out string strDocString, out int dwHelpContext, out string strHelpFile);
- void GetDllEntry(int memid, INVOKEKIND invKind, IntPtr pBstrDllName, IntPtr pBstrName, IntPtr pwOrdinal);
- void GetRefTypeInfo(int hRef, out ITypeInfo ppTI);
- void AddressOfMember(int memid, INVOKEKIND invKind, out IntPtr ppv);
- void CreateInstance([MarshalAs(UnmanagedType.IUnknown)] object? pUnkOuter, [In] ref Guid riid, [MarshalAs(UnmanagedType.IUnknown), Out] out object ppvObj);
- void GetMops(int memid, out string? pBstrMops);
- void GetContainingTypeLib(out ITypeLib ppTLB, out int pIndex);
- [PreserveSig]
- void ReleaseTypeAttr(IntPtr pTypeAttr);
- [PreserveSig]
- void ReleaseFuncDesc(IntPtr pFuncDesc);
- [PreserveSig]
- void ReleaseVarDesc(IntPtr pVarDesc);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComTypes/ITypeInfo2.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComTypes/ITypeInfo2.cs
deleted file mode 100644
index e322f8a4f86..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComTypes/ITypeInfo2.cs
+++ /dev/null
@@ -1,51 +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.
-
-namespace System.Runtime.InteropServices.ComTypes
-{
- [Guid("00020412-0000-0000-C000-000000000046")]
- [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
- [ComImport]
- public interface ITypeInfo2 : ITypeInfo
- {
- new void GetTypeAttr(out IntPtr ppTypeAttr);
- new void GetTypeComp(out ITypeComp ppTComp);
- new void GetFuncDesc(int index, out IntPtr ppFuncDesc);
- new void GetVarDesc(int index, out IntPtr ppVarDesc);
- new void GetNames(int memid, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 2), Out] string[] rgBstrNames, int cMaxNames, out int pcNames);
- new void GetRefTypeOfImplType(int index, out int href);
- new void GetImplTypeFlags(int index, out IMPLTYPEFLAGS pImplTypeFlags);
- new void GetIDsOfNames([MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.LPWStr, SizeParamIndex = 1), In] string[] rgszNames, int cNames, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1), Out] int[] pMemId);
- new void Invoke([MarshalAs(UnmanagedType.IUnknown)] object pvInstance, int memid, short wFlags, ref DISPPARAMS pDispParams, IntPtr pVarResult, IntPtr pExcepInfo, out int puArgErr);
- new void GetDocumentation(int index, out string strName, out string strDocString, out int dwHelpContext, out string strHelpFile);
- new void GetDllEntry(int memid, INVOKEKIND invKind, IntPtr pBstrDllName, IntPtr pBstrName, IntPtr pwOrdinal);
- new void GetRefTypeInfo(int hRef, out ITypeInfo ppTI);
- new void AddressOfMember(int memid, INVOKEKIND invKind, out IntPtr ppv);
- new void CreateInstance([MarshalAs(UnmanagedType.IUnknown)] object? pUnkOuter, [In] ref Guid riid, [MarshalAs(UnmanagedType.IUnknown), Out] out object ppvObj);
- new void GetMops(int memid, out string? pBstrMops);
- new void GetContainingTypeLib(out ITypeLib ppTLB, out int pIndex);
- [PreserveSig]
- new void ReleaseTypeAttr(IntPtr pTypeAttr);
- [PreserveSig]
- new void ReleaseFuncDesc(IntPtr pFuncDesc);
- [PreserveSig]
- new void ReleaseVarDesc(IntPtr pVarDesc);
- void GetTypeKind(out TYPEKIND pTypeKind);
- void GetTypeFlags(out int pTypeFlags);
- void GetFuncIndexOfMemId(int memid, INVOKEKIND invKind, out int pFuncIndex);
- void GetVarIndexOfMemId(int memid, out int pVarIndex);
- void GetCustData(ref Guid guid, out object pVarVal);
- void GetFuncCustData(int index, ref Guid guid, out object pVarVal);
- void GetParamCustData(int indexFunc, int indexParam, ref Guid guid, out object pVarVal);
- void GetVarCustData(int index, ref Guid guid, out object pVarVal);
- void GetImplTypeCustData(int index, ref Guid guid, out object pVarVal);
- [LCIDConversion(1)]
- void GetDocumentation2(int memid, out string pbstrHelpString, out int pdwHelpStringContext, out string pbstrHelpStringDll);
- void GetAllCustData(IntPtr pCustData);
- void GetAllFuncCustData(int index, IntPtr pCustData);
- void GetAllParamCustData(int indexFunc, int indexParam, IntPtr pCustData);
- void GetAllVarCustData(int index, IntPtr pCustData);
- void GetAllImplTypeCustData(int index, IntPtr pCustData);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComTypes/ITypeLib.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComTypes/ITypeLib.cs
deleted file mode 100644
index 6cab58e117d..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComTypes/ITypeLib.cs
+++ /dev/null
@@ -1,54 +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.
-
-namespace System.Runtime.InteropServices.ComTypes
-{
- public enum SYSKIND
- {
- SYS_WIN16 = 0,
- SYS_WIN32 = SYS_WIN16 + 1,
- SYS_MAC = SYS_WIN32 + 1,
- SYS_WIN64 = SYS_MAC + 1
- }
-
- [Flags]
- public enum LIBFLAGS : short
- {
- LIBFLAG_FRESTRICTED = 0x1,
- LIBFLAG_FCONTROL = 0x2,
- LIBFLAG_FHIDDEN = 0x4,
- LIBFLAG_FHASDISKIMAGE = 0x8
- }
-
- [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
- public struct TYPELIBATTR
- {
- public Guid guid;
- public int lcid;
- public SYSKIND syskind;
- public short wMajorVerNum;
- public short wMinorVerNum;
- public LIBFLAGS wLibFlags;
- }
-
- [Guid("00020402-0000-0000-C000-000000000046")]
- [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
- [ComImport]
- public interface ITypeLib
- {
- [PreserveSig]
- int GetTypeInfoCount();
- void GetTypeInfo(int index, out ITypeInfo ppTI);
- void GetTypeInfoType(int index, out TYPEKIND pTKind);
- void GetTypeInfoOfGuid(ref Guid guid, out ITypeInfo ppTInfo);
- void GetLibAttr(out IntPtr ppTLibAttr);
- void GetTypeComp(out ITypeComp ppTComp);
- void GetDocumentation(int index, out string strName, out string strDocString, out int dwHelpContext, out string strHelpFile);
- [return: MarshalAs(UnmanagedType.Bool)]
- bool IsName([MarshalAs(UnmanagedType.LPWStr)] string szNameBuf, int lHashVal);
- void FindName([MarshalAs(UnmanagedType.LPWStr)] string szNameBuf, int lHashVal, [MarshalAs(UnmanagedType.LPArray), Out] ITypeInfo[] ppTInfo, [MarshalAs(UnmanagedType.LPArray), Out] int[] rgMemId, ref short pcFound);
- [PreserveSig]
- void ReleaseTLibAttr(IntPtr pTLibAttr);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComTypes/ITypeLib2.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComTypes/ITypeLib2.cs
deleted file mode 100644
index 61703d1cfe3..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComTypes/ITypeLib2.cs
+++ /dev/null
@@ -1,31 +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.
-
-namespace System.Runtime.InteropServices.ComTypes
-{
- [Guid("00020411-0000-0000-C000-000000000046")]
- [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
- [ComImport]
- public interface ITypeLib2 : ITypeLib
- {
- [PreserveSig]
- new int GetTypeInfoCount();
- new void GetTypeInfo(int index, out ITypeInfo ppTI);
- new void GetTypeInfoType(int index, out TYPEKIND pTKind);
- new void GetTypeInfoOfGuid(ref Guid guid, out ITypeInfo ppTInfo);
- new void GetLibAttr(out IntPtr ppTLibAttr);
- new void GetTypeComp(out ITypeComp ppTComp);
- new void GetDocumentation(int index, out string strName, out string strDocString, out int dwHelpContext, out string strHelpFile);
- [return: MarshalAs(UnmanagedType.Bool)]
- new bool IsName([MarshalAs(UnmanagedType.LPWStr)] string szNameBuf, int lHashVal);
- new void FindName([MarshalAs(UnmanagedType.LPWStr)] string szNameBuf, int lHashVal, [MarshalAs(UnmanagedType.LPArray), Out] ITypeInfo[] ppTInfo, [MarshalAs(UnmanagedType.LPArray), Out] int[] rgMemId, ref short pcFound);
- [PreserveSig]
- new void ReleaseTLibAttr(IntPtr pTLibAttr);
- void GetCustData(ref Guid guid, out object pVarVal);
- [LCIDConversion(1)]
- void GetDocumentation2(int index, out string pbstrHelpString, out int pdwHelpStringContext, out string pbstrHelpStringDll);
- void GetLibStatistics(IntPtr pcUniqueNames, out int pcchUniqueNames);
- void GetAllCustData(IntPtr pCustData);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComVisibleAttribute.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComVisibleAttribute.cs
deleted file mode 100644
index 84b9505a5a4..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComVisibleAttribute.cs
+++ /dev/null
@@ -1,17 +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.
-
-namespace System.Runtime.InteropServices
-{
- [AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Interface | AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Delegate | AttributeTargets.Enum | AttributeTargets.Field | AttributeTargets.Method | AttributeTargets.Property, Inherited = false)]
- public sealed class ComVisibleAttribute : Attribute
- {
- public ComVisibleAttribute(bool visibility)
- {
- Value = visibility;
- }
-
- public bool Value { get; }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/CriticalHandle.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/CriticalHandle.cs
deleted file mode 100644
index fc6a27d18ca..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/CriticalHandle.cs
+++ /dev/null
@@ -1,211 +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.
-
-/*============================================================
-**
-**
-**
-** A specially designed handle wrapper to ensure we never leak
-** an OS handle. The runtime treats this class specially during
-** P/Invoke marshaling and finalization. Users should write
-** subclasses of CriticalHandle for each distinct handle type.
-** This class is similar to SafeHandle, but lacks the ref counting
-** behavior on marshaling that prevents handle recycling errors
-** or security holes. This lowers the overhead of using the handle
-** considerably, but leaves the onus on the caller to protect
-** themselves from any recycling effects.
-**
-** **** NOTE ****
-**
-** Since there are no ref counts tracking handle usage there is
-** no thread safety either. Your application must ensure that
-** usages of the handle do not cross with attempts to close the
-** handle (or tolerate such crossings). Normal GC mechanics will
-** prevent finalization until the handle class isn't used any more,
-** but explicit Close or Dispose operations may be initiated at any
-** time.
-**
-** Similarly, multiple calls to Close or Dispose on different
-** threads at the same time may cause the ReleaseHandle method to be
-** called more than once.
-**
-** In general (and as might be inferred from the lack of handle
-** recycle protection) you should be very cautious about exposing
-** CriticalHandle instances directly or indirectly to untrusted users.
-** At a minimum you should restrict their ability to queue multiple
-** operations against a single handle at the same time or block their
-** access to Close and Dispose unless you are very comfortable with the
-** semantics of passing an invalid (or possibly invalidated and
-** reallocated) to the unamanged routines you marshal your handle to
-** (and the effects of closing such a handle while those calls are in
-** progress). The runtime cannot protect you from undefined program
-** behvior that might result from such scenarios. You have been warned.
-**
-**
-===========================================================*/
-
-using System.Runtime.ConstrainedExecution;
-
-/*
- Problems addressed by the CriticalHandle class:
- 1) Critical finalization - ensure we never leak OS resources in SQL. Done
- without running truly arbitrary & unbounded amounts of managed code.
- 2) Reduced graph promotion - during finalization, keep object graph small
- 3) GC.KeepAlive behavior - P/Invoke vs. finalizer thread race condition (HandleRef)
- 4) Enforcement of the above via the type system - Don't use IntPtr anymore.
-
- Subclasses of CriticalHandle will implement the ReleaseHandle
- abstract method used to execute any code required to free the
- handle. This method will be prepared as a constrained execution
- region at instance construction time (along with all the methods in
- its statically determinable call graph). This implies that we won't
- get any inconvenient jit allocation errors or rude thread abort
- interrupts while releasing the handle but the user must still write
- careful code to avoid injecting fault paths of their own (see the
- CER spec for more details). In particular, any sub-methods you call
- should be decorated with a reliability contract of the appropriate
- level. In most cases this should be:
- ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)
-
- Subclasses must also implement the IsInvalid property so that the
- infrastructure can tell when critical finalization is actually required.
- Again, this method is prepared ahead of time. It's envisioned that direct
- subclasses of CriticalHandle will provide an IsInvalid implementation that suits
- the general type of handle they support (null is invalid, -1 is invalid etc.)
- and then these classes will be further derived for specific handle types.
-
- Most classes using CriticalHandle should not provide a finalizer. If they do
- need to do so (ie, for flushing out file buffers, needing to write some data
- back into memory, etc), then they can provide a finalizer that will be
- guaranteed to run before the CriticalHandle's critical finalizer.
-
- Subclasses are expected to be written as follows:
-
- internal sealed MyCriticalHandleSubclass : CriticalHandle {
- // Called by P/Invoke when returning CriticalHandles
- private MyCriticalHandleSubclass() : base(IntPtr.Zero)
- {
- }
-
- // Do not provide a finalizer - CriticalHandle's critical finalizer will
- // call ReleaseHandle for you.
-
- public override bool IsInvalid {
- get { return handle == IntPtr.Zero; }
- }
-
- [DllImport(Interop.Libraries.Kernel32), ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
- private static extern bool CloseHandle(IntPtr handle);
-
- override protected bool ReleaseHandle()
- {
- return CloseHandle(handle);
- }
- }
-
- Then elsewhere to create one of these CriticalHandles, define a method
- with the following type of signature (CreateFile follows this model).
- Note that when returning a CriticalHandle like this, P/Invoke will call your
- classes default constructor.
-
- [DllImport(Interop.Libraries.Kernel32)]
- private static extern MyCriticalHandleSubclass CreateHandle(int someState);
-
- */
-
-namespace System.Runtime.InteropServices
-{
- // This class should not be serializable - it's a handle
- public abstract partial class CriticalHandle : CriticalFinalizerObject, IDisposable
- {
- // ! Do not add or rearrange fields as the EE depends on this layout.
- //------------------------------------------------------------------
- protected IntPtr handle; // This must be protected so derived classes can use out params.
- private bool _isClosed; // Set by SetHandleAsInvalid or Close/Dispose/finalization.
-
- // Creates a CriticalHandle class. Users must then set the Handle property or allow P/Invoke marshaling to set it implicitly.
- protected CriticalHandle(IntPtr invalidHandleValue)
- {
- handle = invalidHandleValue;
- }
-
- ~CriticalHandle()
- {
- Dispose(false);
- }
-
- private void Cleanup()
- {
- if (IsClosed)
- return;
- _isClosed = true;
-
- if (IsInvalid)
- return;
-
- // Save last error from P/Invoke in case the implementation of
- // ReleaseHandle trashes it (important because this ReleaseHandle could
- // occur implicitly as part of unmarshaling another P/Invoke).
- int lastError = Marshal.GetLastWin32Error();
-
- ReleaseHandle();
-
- Marshal.SetLastWin32Error(lastError);
- GC.SuppressFinalize(this);
- }
-
- protected void SetHandle(IntPtr handle)
- {
- this.handle = handle;
- }
-
- // Returns whether the handle has been explicitly marked as closed
- // (Close/Dispose) or invalid (SetHandleAsInvalid).
- public bool IsClosed => _isClosed;
-
- // Returns whether the handle looks like an invalid value (i.e. matches one
- // of the handle's designated illegal values). CriticalHandle itself doesn't
- // know what an invalid handle looks like, so this method is abstract and
- // must be provided by a derived type.
- public abstract bool IsInvalid
- {
- get;
- }
-
- public void Close()
- {
- Dispose(true);
- }
-
- public void Dispose()
- {
- Dispose(true);
- }
-
- protected virtual void Dispose(bool disposing)
- {
- Cleanup();
- }
-
- // This should only be called for cases when you know for a fact that
- // your handle is invalid and you want to record that information.
- // An example is calling a syscall and getting back ERROR_INVALID_HANDLE.
- // This method will normally leak handles!
- public void SetHandleAsInvalid()
- {
- _isClosed = true;
- GC.SuppressFinalize(this);
- }
-
- // Implement this abstract method in your derived class to specify how to
- // free the handle. Be careful not write any code that's subject to faults
- // in this method (the runtime will prepare the infrastructure for you so
- // that no jit allocations etc. will occur, but don't allocate memory unless
- // you can deal with the failure and still free the handle).
- // The boolean returned should be true for success and false if a
- // catastrophic error occurred and you wish to trigger a diagnostic for
- // debugging purposes.
- protected abstract bool ReleaseHandle();
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/CurrencyWrapper.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/CurrencyWrapper.cs
deleted file mode 100644
index 373f9bb9c5e..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/CurrencyWrapper.cs
+++ /dev/null
@@ -1,25 +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.
-
-namespace System.Runtime.InteropServices
-{
- // Wrapper that is converted to a variant with VT_CURRENCY.
- public sealed class CurrencyWrapper
- {
- public CurrencyWrapper(decimal obj)
- {
- WrappedObject = obj;
- }
-
- public CurrencyWrapper(object obj)
- {
- if (!(obj is decimal))
- throw new ArgumentException(SR.Arg_MustBeDecimal, nameof(obj));
-
- WrappedObject = (decimal)obj;
- }
-
- public decimal WrappedObject { get; }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/CustomQueryInterfaceMode.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/CustomQueryInterfaceMode.cs
deleted file mode 100644
index 7b5eddacf4c..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/CustomQueryInterfaceMode.cs
+++ /dev/null
@@ -1,12 +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.
-
-namespace System.Runtime.InteropServices
-{
- public enum CustomQueryInterfaceMode
- {
- Ignore = 0,
- Allow = 1,
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/CustomQueryInterfaceResult.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/CustomQueryInterfaceResult.cs
deleted file mode 100644
index 1e1d3fd7ead..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/CustomQueryInterfaceResult.cs
+++ /dev/null
@@ -1,14 +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.
-
-namespace System.Runtime.InteropServices
-{
- // The enum of the return value of IQuerable.GetInterface
- public enum CustomQueryInterfaceResult
- {
- Handled = 0,
- NotHandled = 1,
- Failed = 2,
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/DefaultCharSetAttribute.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/DefaultCharSetAttribute.cs
deleted file mode 100644
index 7a486f7017b..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/DefaultCharSetAttribute.cs
+++ /dev/null
@@ -1,17 +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.
-
-namespace System.Runtime.InteropServices
-{
- [AttributeUsage(AttributeTargets.Module, Inherited = false)]
- public sealed class DefaultCharSetAttribute : Attribute
- {
- public DefaultCharSetAttribute(CharSet charSet)
- {
- CharSet = charSet;
- }
-
- public CharSet CharSet { get; }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/DefaultDllImportSearchPathsAttribute.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/DefaultDllImportSearchPathsAttribute.cs
deleted file mode 100644
index 1ff27fbbd55..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/DefaultDllImportSearchPathsAttribute.cs
+++ /dev/null
@@ -1,17 +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.
-
-namespace System.Runtime.InteropServices
-{
- [AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Method, AllowMultiple = false)]
- public sealed class DefaultDllImportSearchPathsAttribute : Attribute
- {
- public DefaultDllImportSearchPathsAttribute(DllImportSearchPath paths)
- {
- Paths = paths;
- }
-
- public DllImportSearchPath Paths { get; }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/DefaultParameterValueAttribute.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/DefaultParameterValueAttribute.cs
deleted file mode 100644
index ed709f16d1c..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/DefaultParameterValueAttribute.cs
+++ /dev/null
@@ -1,23 +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.
-
-namespace System.Runtime.InteropServices
-{
- //
- // The DefaultParameterValueAttribute is used in C# to set
- // the default value for parameters when calling methods
- // from other languages. This is particularly useful for
- // methods defined in COM interop interfaces.
- //
- [AttributeUsage(AttributeTargets.Parameter)]
- public sealed class DefaultParameterValueAttribute : Attribute
- {
- public DefaultParameterValueAttribute(object? value)
- {
- Value = value;
- }
-
- public object? Value { get; }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/DispIdAttribute.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/DispIdAttribute.cs
deleted file mode 100644
index 1f147280c5c..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/DispIdAttribute.cs
+++ /dev/null
@@ -1,17 +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.
-
-namespace System.Runtime.InteropServices
-{
- [AttributeUsage(AttributeTargets.Method | AttributeTargets.Field | AttributeTargets.Property | AttributeTargets.Event, Inherited = false)]
- public sealed class DispIdAttribute : Attribute
- {
- public DispIdAttribute(int dispId)
- {
- Value = dispId;
- }
-
- public int Value { get; }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/DispatchWrapper.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/DispatchWrapper.cs
deleted file mode 100644
index 3bb1507203c..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/DispatchWrapper.cs
+++ /dev/null
@@ -1,26 +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.
-
-namespace System.Runtime.InteropServices
-{
- // Wrapper that is converted to a variant with VT_DISPATCH
- public sealed class DispatchWrapper
- {
- public DispatchWrapper(object? obj)
- {
- if (obj != null)
- {
- // Make sure this guy has an IDispatch
- IntPtr pdisp = Marshal.GetIDispatchForObject(obj);
-
- // If we got here without throwing an exception, the QI for IDispatch succeeded.
- Marshal.Release(pdisp);
-
- WrappedObject = obj;
- }
- }
-
- public object? WrappedObject { get; }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/DllImportAttribute.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/DllImportAttribute.cs
deleted file mode 100644
index 11e3deb21c3..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/DllImportAttribute.cs
+++ /dev/null
@@ -1,26 +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.
-
-namespace System.Runtime.InteropServices
-{
- [AttributeUsage(AttributeTargets.Method, Inherited = false)]
- public sealed class DllImportAttribute : Attribute
- {
- public DllImportAttribute(string dllName)
- {
- Value = dllName;
- }
-
- public string Value { get; }
-
- public string? EntryPoint;
- public CharSet CharSet;
- public bool SetLastError;
- public bool ExactSpelling;
- public CallingConvention CallingConvention;
- public bool BestFitMapping;
- public bool PreserveSig;
- public bool ThrowOnUnmappableChar;
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/DllImportSearchPath.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/DllImportSearchPath.cs
deleted file mode 100644
index 8dbdb40be96..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/DllImportSearchPath.cs
+++ /dev/null
@@ -1,18 +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.
-
-namespace System.Runtime.InteropServices
-{
- [Flags]
- public enum DllImportSearchPath
- {
- UseDllDirectoryForDependencies = 0x100,
- ApplicationDirectory = 0x200,
- UserDirectories = 0x400,
- System32 = 0x800,
- SafeDirectories = 0x1000,
- AssemblyDirectory = 0x2,
- LegacyBehavior = 0x0
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ErrorWrapper.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ErrorWrapper.cs
deleted file mode 100644
index d25f0231a44..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ErrorWrapper.cs
+++ /dev/null
@@ -1,29 +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.
-
-namespace System.Runtime.InteropServices
-{
- // Wrapper that is converted to a variant with VT_ERROR.
- public sealed class ErrorWrapper
- {
- public ErrorWrapper(int errorCode)
- {
- ErrorCode = errorCode;
- }
-
- public ErrorWrapper(object errorCode)
- {
- if (!(errorCode is int))
- throw new ArgumentException(SR.Arg_MustBeInt32, nameof(errorCode));
- ErrorCode = (int)errorCode;
- }
-
- public ErrorWrapper(Exception e)
- {
- ErrorCode = Marshal.GetHRForException(e);
- }
-
- public int ErrorCode { get; }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ExternalException.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ExternalException.cs
deleted file mode 100644
index b9bc042986e..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ExternalException.cs
+++ /dev/null
@@ -1,81 +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.
-
-/*=============================================================================
-**
-**
-**
-** Purpose: Exception base class for all errors from Interop or Structured
-** Exception Handling code.
-**
-**
-=============================================================================*/
-
-using System.Globalization;
-using System.Runtime.Serialization;
-
-namespace System.Runtime.InteropServices
-{
- // Base exception for COM Interop errors &; Structured Exception Handler
- // exceptions.
- [Serializable]
- [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public class ExternalException : SystemException
- {
- public ExternalException()
- : base(SR.Arg_ExternalException)
- {
- HResult = HResults.E_FAIL;
- }
-
- public ExternalException(string? message)
- : base(message)
- {
- HResult = HResults.E_FAIL;
- }
-
- public ExternalException(string? message, Exception? inner)
- : base(message, inner)
- {
- HResult = HResults.E_FAIL;
- }
-
- public ExternalException(string? message, int errorCode)
- : base(message)
- {
- HResult = errorCode;
- }
-
- protected ExternalException(SerializationInfo info, StreamingContext context)
- : base(info, context)
- {
- }
-
- public virtual int ErrorCode => HResult;
-
- public override string ToString()
- {
- string message = Message;
- string className = GetType().ToString();
-
- string s = className + " (0x" + HResult.ToString("X8", CultureInfo.InvariantCulture) + ")";
-
- if (!string.IsNullOrEmpty(message))
- {
- s += ": " + message;
- }
-
- Exception? innerException = InnerException;
- if (innerException != null)
- {
- s += Environment.NewLineConst + InnerExceptionPrefix + innerException.ToString();
- }
-
- if (StackTrace != null)
- s += Environment.NewLineConst + StackTrace;
-
- return s;
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/FieldOffsetAttribute.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/FieldOffsetAttribute.cs
deleted file mode 100644
index 27e1097749f..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/FieldOffsetAttribute.cs
+++ /dev/null
@@ -1,17 +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.
-
-namespace System.Runtime.InteropServices
-{
- [AttributeUsage(AttributeTargets.Field, Inherited = false)]
- public sealed class FieldOffsetAttribute : Attribute
- {
- public FieldOffsetAttribute(int offset)
- {
- Value = offset;
- }
-
- public int Value { get; }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/GCHandle.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/GCHandle.cs
deleted file mode 100644
index b39bc98ef37..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/GCHandle.cs
+++ /dev/null
@@ -1,195 +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.Diagnostics;
-using System.Runtime.CompilerServices;
-using System.Threading;
-using Internal.Runtime.CompilerServices;
-
-#pragma warning disable SA1121 // explicitly using type aliases instead of built-in types
-#if BIT64
-using nint = System.Int64;
-#else
-using nint = System.Int32;
-#endif
-
-namespace System.Runtime.InteropServices
-{
- /// <summary>
- /// Represents an opaque, GC handle to a managed object. A GC handle is used when an
- /// object reference must be reachable from unmanaged memory.
- /// </summary>
- /// <remarks>
- /// There are 4 kinds of roots:
- /// Normal: Keeps the object from being collected.
- /// Weak: Allows object to be collected and handle contents will be zeroed.
- /// Weak references are zeroed before the finalizer runs, so if the
- /// object is resurrected in the finalizer the weak reference is still zeroed.
- /// WeakTrackResurrection: Same as Weak, but stays until after object is really gone.
- /// Pinned - same as Normal, but allows the address of the actual object to be taken.
- /// </remarks>
- [StructLayout(LayoutKind.Sequential)]
- public partial struct GCHandle
- {
- // The actual integer handle value that the EE uses internally.
- private IntPtr _handle;
-
- // Allocate a handle storing the object and the type.
- private GCHandle(object? value, GCHandleType type)
- {
- // Make sure the type parameter is within the valid range for the enum.
- if ((uint)type > (uint)GCHandleType.Pinned) // IMPORTANT: This must be kept in sync with the GCHandleType enum.
- {
- throw new ArgumentOutOfRangeException(nameof(type), SR.ArgumentOutOfRange_Enum);
- }
-
- if (type == GCHandleType.Pinned && !Marshal.IsPinnable(value))
- {
- throw new ArgumentException(SR.ArgumentException_NotIsomorphic, nameof(value));
- }
-
- IntPtr handle = InternalAlloc(value, type);
-
- if (type == GCHandleType.Pinned)
- {
- // Record if the handle is pinned.
- handle = (IntPtr)((nint)handle | 1);
- }
-
- _handle = handle;
- }
-
- // Used in the conversion functions below.
- private GCHandle(IntPtr handle) => _handle = handle;
-
- /// <summary>Creates a new GC handle for an object.</summary>
- /// <param name="value">The object that the GC handle is created for.</param>
- /// <returns>A new GC handle that protects the object.</returns>
- public static GCHandle Alloc(object? value) => new GCHandle(value, GCHandleType.Normal);
-
- /// <summary>Creates a new GC handle for an object.</summary>
- /// <param name="value">The object that the GC handle is created for.</param>
- /// <param name="type">The type of GC handle to create.</param>
- /// <returns>A new GC handle that protects the object.</returns>
- public static GCHandle Alloc(object? value, GCHandleType type) => new GCHandle(value, type);
-
- /// <summary>Frees a GC handle.</summary>
- public void Free()
- {
- // Free the handle if it hasn't already been freed.
- IntPtr handle = Interlocked.Exchange(ref _handle, IntPtr.Zero);
- ThrowIfInvalid(handle);
- InternalFree(GetHandleValue(handle));
- }
-
- // Target property - allows getting / updating of the handle's referent.
- public object? Target
- {
- get
- {
- IntPtr handle = _handle;
- ThrowIfInvalid(handle);
-
- return InternalGet(GetHandleValue(handle));
- }
- set
- {
- IntPtr handle = _handle;
- ThrowIfInvalid(handle);
-
- if (IsPinned(handle) && !Marshal.IsPinnable(value))
- {
- throw new ArgumentException(SR.ArgumentException_NotIsomorphic, nameof(value));
- }
-
- InternalSet(GetHandleValue(handle), value);
- }
- }
-
- /// <summary>
- /// Retrieve the address of an object in a Pinned handle. This throws
- /// an exception if the handle is any type other than Pinned.
- /// </summary>
- public IntPtr AddrOfPinnedObject()
- {
- // Check if the handle was not a pinned handle.
- // You can only get the address of pinned handles.
- IntPtr handle = _handle;
- ThrowIfInvalid(handle);
-
- if (!IsPinned(handle))
- {
- ThrowHelper.ThrowInvalidOperationException_HandleIsNotPinned();
- }
-
- // Get the address.
-
- object target = InternalGet(GetHandleValue(handle));
- if (target is null)
- {
- return default;
- }
-
- unsafe
- {
- if (RuntimeHelpers.ObjectHasComponentSize(target))
- {
- if (target.GetType() == typeof(string))
- {
- return (IntPtr)Unsafe.AsPointer(ref Unsafe.As<string>(target).GetRawStringData());
- }
-
- Debug.Assert(target is Array);
- return (IntPtr)Unsafe.AsPointer(ref Unsafe.As<Array>(target).GetRawArrayData());
- }
-
- return (IntPtr)Unsafe.AsPointer(ref target.GetRawData());
- }
- }
-
- /// <summary>Determine whether this handle has been allocated or not.</summary>
- public bool IsAllocated => _handle != IntPtr.Zero;
-
- /// <summary>
- /// Used to create a GCHandle from an int. This is intended to
- /// be used with the reverse conversion.
- /// </summary>
- public static explicit operator GCHandle(IntPtr value) => FromIntPtr(value);
-
- public static GCHandle FromIntPtr(IntPtr value)
- {
- ThrowIfInvalid(value);
- return new GCHandle(value);
- }
-
- /// <summary>Used to get the internal integer representation of the handle out.</summary>
- public static explicit operator IntPtr(GCHandle value) => ToIntPtr(value);
-
- public static IntPtr ToIntPtr(GCHandle value) => value._handle;
-
- public override int GetHashCode() => _handle.GetHashCode();
-
- public override bool Equals(object? o) => o is GCHandle && _handle == ((GCHandle)o)._handle;
-
- public static bool operator ==(GCHandle a, GCHandle b) => a._handle == b._handle;
-
- public static bool operator !=(GCHandle a, GCHandle b) => a._handle != b._handle;
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- private static IntPtr GetHandleValue(IntPtr handle) => new IntPtr((nint)handle & ~(nint)1); // Remove Pin flag
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- private static bool IsPinned(IntPtr handle) => ((nint)handle & 1) != 0; // Check Pin flag
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- private static void ThrowIfInvalid(IntPtr handle)
- {
- // Check if the handle was never initialized or was freed.
- if (handle == IntPtr.Zero)
- {
- ThrowHelper.ThrowInvalidOperationException_HandleIsNotInitialized();
- }
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/GCHandleType.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/GCHandleType.cs
deleted file mode 100644
index 68da96830ae..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/GCHandleType.cs
+++ /dev/null
@@ -1,18 +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.
-
-namespace System.Runtime.InteropServices
-{
- // These are the types of handles used by the EE.
- // IMPORTANT: These must match the definitions in ObjectHandle.h in the EE.
- // IMPORTANT: If new values are added to the enum the GCHandle.MaxHandleType
- // constant must be updated.
- public enum GCHandleType
- {
- Weak = 0,
- WeakTrackResurrection = 1,
- Normal = 2,
- Pinned = 3
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/GuidAttribute.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/GuidAttribute.cs
deleted file mode 100644
index cf60b9bf70a..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/GuidAttribute.cs
+++ /dev/null
@@ -1,17 +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.
-
-namespace System.Runtime.InteropServices
-{
- [AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Interface | AttributeTargets.Class | AttributeTargets.Enum | AttributeTargets.Struct | AttributeTargets.Delegate, Inherited = false)]
- public sealed class GuidAttribute : Attribute
- {
- public GuidAttribute(string guid)
- {
- Value = guid;
- }
-
- public string Value { get; }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/HandleRef.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/HandleRef.cs
deleted file mode 100644
index 075d78f2416..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/HandleRef.cs
+++ /dev/null
@@ -1,29 +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.
-
-namespace System.Runtime.InteropServices
-{
- public readonly struct HandleRef
- {
- // ! Do not add or rearrange fields as the EE depends on this layout.
- //------------------------------------------------------------------
- private readonly object? _wrapper;
- private readonly IntPtr _handle;
- //------------------------------------------------------------------
-
- public HandleRef(object? wrapper, IntPtr handle)
- {
- _wrapper = wrapper;
- _handle = handle;
- }
-
- public object? Wrapper => _wrapper;
-
- public IntPtr Handle => _handle;
-
- public static explicit operator IntPtr(HandleRef value) => value._handle;
-
- public static IntPtr ToIntPtr(HandleRef value) => value._handle;
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ICustomAdapter.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ICustomAdapter.cs
deleted file mode 100644
index 6dd90e2dace..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ICustomAdapter.cs
+++ /dev/null
@@ -1,13 +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.
-
-namespace System.Runtime.InteropServices
-{
- // This the base interface that custom adapters can chose to implement when they want to expose the underlying object.
- public interface ICustomAdapter
- {
- [return: MarshalAs(UnmanagedType.IUnknown)]
- object GetUnderlyingObject();
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ICustomFactory.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ICustomFactory.cs
deleted file mode 100644
index 799db6a2d3a..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ICustomFactory.cs
+++ /dev/null
@@ -1,11 +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.
-
-namespace System.Runtime.InteropServices
-{
- public interface ICustomFactory
- {
- MarshalByRefObject CreateInstance(Type serverType);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ICustomMarshaler.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ICustomMarshaler.cs
deleted file mode 100644
index cf442d4fde1..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ICustomMarshaler.cs
+++ /dev/null
@@ -1,20 +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.
-
-namespace System.Runtime.InteropServices
-{
- // This the base interface that must be implemented by all custom marshalers.
- public interface ICustomMarshaler
- {
- object MarshalNativeToManaged(IntPtr pNativeData);
-
- IntPtr MarshalManagedToNative(object ManagedObj);
-
- void CleanUpNativeData(IntPtr pNativeData);
-
- void CleanUpManagedData(object ManagedObj);
-
- int GetNativeDataSize();
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ICustomQueryInterface.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ICustomQueryInterface.cs
deleted file mode 100644
index a91fd7f5fbb..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ICustomQueryInterface.cs
+++ /dev/null
@@ -1,12 +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.
-
-namespace System.Runtime.InteropServices
-{
- // This the interface that be implemented by class that want to customize the behavior of QueryInterface.
- public interface ICustomQueryInterface
- {
- CustomQueryInterfaceResult GetInterface([In]ref Guid iid, out IntPtr ppv);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/InAttribute.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/InAttribute.cs
deleted file mode 100644
index 39f5a958bc8..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/InAttribute.cs
+++ /dev/null
@@ -1,14 +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.
-
-namespace System.Runtime.InteropServices
-{
- [AttributeUsage(AttributeTargets.Parameter, Inherited = false)]
- public sealed class InAttribute : Attribute
- {
- public InAttribute()
- {
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/InterfaceTypeAttribute.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/InterfaceTypeAttribute.cs
deleted file mode 100644
index 695faa79378..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/InterfaceTypeAttribute.cs
+++ /dev/null
@@ -1,21 +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.
-
-namespace System.Runtime.InteropServices
-{
- [AttributeUsage(AttributeTargets.Interface, Inherited = false)]
- public sealed class InterfaceTypeAttribute : Attribute
- {
- public InterfaceTypeAttribute(ComInterfaceType interfaceType)
- {
- Value = interfaceType;
- }
- public InterfaceTypeAttribute(short interfaceType)
- {
- Value = (ComInterfaceType)interfaceType;
- }
-
- public ComInterfaceType Value { get; }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/InvalidComObjectException.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/InvalidComObjectException.cs
deleted file mode 100644
index 5bc16e54b74..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/InvalidComObjectException.cs
+++ /dev/null
@@ -1,41 +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.Runtime.Serialization;
-
-namespace System.Runtime.InteropServices
-{
- /// <summary>
- /// The exception thrown when an invalid COM object is used. This happens
- /// when a the __ComObject type is used directly without having a backing
- /// class factory.
- /// </summary>
- [Serializable]
- [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public class InvalidComObjectException : SystemException
- {
- public InvalidComObjectException()
- : base(SR.Arg_InvalidComObjectException)
- {
- HResult = HResults.COR_E_INVALIDCOMOBJECT;
- }
-
- public InvalidComObjectException(string? message)
- : base(message)
- {
- HResult = HResults.COR_E_INVALIDCOMOBJECT;
- }
-
- public InvalidComObjectException(string? message, Exception? inner)
- : base(message, inner)
- {
- HResult = HResults.COR_E_INVALIDCOMOBJECT;
- }
-
- protected InvalidComObjectException(SerializationInfo info, StreamingContext context)
- : base(info, context)
- {
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/InvalidOleVariantTypeException.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/InvalidOleVariantTypeException.cs
deleted file mode 100644
index e5aedb000f9..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/InvalidOleVariantTypeException.cs
+++ /dev/null
@@ -1,40 +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.Runtime.Serialization;
-
-namespace System.Runtime.InteropServices
-{
- /// <summary>
- /// Exception thrown when the type of an OLE variant that was passed into the
- /// runtime is invalid.
- /// </summary>
- [Serializable]
- [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public class InvalidOleVariantTypeException : SystemException
- {
- public InvalidOleVariantTypeException()
- : base(SR.Arg_InvalidOleVariantTypeException)
- {
- HResult = HResults.COR_E_INVALIDOLEVARIANTTYPE;
- }
-
- public InvalidOleVariantTypeException(string? message)
- : base(message)
- {
- HResult = HResults.COR_E_INVALIDOLEVARIANTTYPE;
- }
-
- public InvalidOleVariantTypeException(string? message, Exception? inner)
- : base(message, inner)
- {
- HResult = HResults.COR_E_INVALIDOLEVARIANTTYPE;
- }
-
- protected InvalidOleVariantTypeException(SerializationInfo info, StreamingContext context)
- : base(info, context)
- {
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/LCIDConversionAttribute.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/LCIDConversionAttribute.cs
deleted file mode 100644
index 75f8fcfc914..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/LCIDConversionAttribute.cs
+++ /dev/null
@@ -1,17 +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.
-
-namespace System.Runtime.InteropServices
-{
- [AttributeUsage(AttributeTargets.Method, Inherited = false)]
- public sealed class LCIDConversionAttribute : Attribute
- {
- public LCIDConversionAttribute(int lcid)
- {
- Value = lcid;
- }
-
- public int Value { get; }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/LayoutKind.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/LayoutKind.cs
deleted file mode 100644
index dbd7ec62d54..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/LayoutKind.cs
+++ /dev/null
@@ -1,14 +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.
-
-namespace System.Runtime.InteropServices
-{
- // Used in the StructLayoutAttribute class
- public enum LayoutKind
- {
- Sequential = 0,
- Explicit = 2,
- Auto = 3,
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/Marshal.NoCom.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/Marshal.NoCom.cs
deleted file mode 100644
index b3101344516..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/Marshal.NoCom.cs
+++ /dev/null
@@ -1,204 +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.Diagnostics.CodeAnalysis;
-using System.Reflection;
-using System.Runtime.InteropServices.ComTypes;
-
-namespace System.Runtime.InteropServices
-{
- public static partial class Marshal
- {
- public static int GetHRForException(Exception? e)
- {
- return e?.HResult ?? 0;
- }
-
- public static int AddRef(IntPtr pUnk)
- {
- throw new PlatformNotSupportedException(SR.PlatformNotSupported_ComInterop);
- }
-
- public static bool AreComObjectsAvailableForCleanup() => false;
-
- public static IntPtr CreateAggregatedObject(IntPtr pOuter, object o)
- {
- throw new PlatformNotSupportedException(SR.PlatformNotSupported_ComInterop);
- }
-
- public static object BindToMoniker(string monikerName)
- {
- throw new PlatformNotSupportedException(SR.PlatformNotSupported_ComInterop);
- }
-
- public static void CleanupUnusedObjectsInCurrentContext()
- {
- }
-
- public static IntPtr CreateAggregatedObject<T>(IntPtr pOuter, T o) where T : notnull
- {
- throw new PlatformNotSupportedException(SR.PlatformNotSupported_ComInterop);
- }
-
- public static object? CreateWrapperOfType(object? o, Type t)
- {
- throw new PlatformNotSupportedException(SR.PlatformNotSupported_ComInterop);
- }
-
- public static TWrapper CreateWrapperOfType<T, TWrapper>([AllowNull] T o)
- {
- throw new PlatformNotSupportedException(SR.PlatformNotSupported_ComInterop);
- }
-
- public static void ChangeWrapperHandleStrength(object otp, bool fIsWeak)
- {
- throw new PlatformNotSupportedException(SR.PlatformNotSupported_ComInterop);
- }
-
- public static int FinalReleaseComObject(object o)
- {
- throw new PlatformNotSupportedException(SR.PlatformNotSupported_ComInterop);
- }
-
- public static IntPtr GetComInterfaceForObject(object o, Type T)
- {
- throw new PlatformNotSupportedException(SR.PlatformNotSupported_ComInterop);
- }
-
- public static IntPtr GetComInterfaceForObject(object o, Type T, CustomQueryInterfaceMode mode)
- {
- throw new PlatformNotSupportedException(SR.PlatformNotSupported_ComInterop);
- }
-
- public static IntPtr GetComInterfaceForObject<T, TInterface>([DisallowNull] T o)
- {
- throw new PlatformNotSupportedException(SR.PlatformNotSupported_ComInterop);
- }
-
- public static object? GetComObjectData(object obj, object key)
- {
- throw new PlatformNotSupportedException(SR.PlatformNotSupported_ComInterop);
- }
-
- public static IntPtr GetHINSTANCE(Module m)
- {
- if (m is null)
- {
- throw new ArgumentNullException(nameof(m));
- }
-
- return (IntPtr)(-1);
- }
-
- public static IntPtr GetIUnknownForObject(object o)
- {
- throw new PlatformNotSupportedException(SR.PlatformNotSupported_ComInterop);
- }
-
- public static void GetNativeVariantForObject(object? obj, IntPtr pDstNativeVariant)
- {
- throw new PlatformNotSupportedException(SR.PlatformNotSupported_ComInterop);
- }
-
- public static void GetNativeVariantForObject<T>([AllowNull] T obj, IntPtr pDstNativeVariant)
- {
- throw new PlatformNotSupportedException(SR.PlatformNotSupported_ComInterop);
- }
-
- public static object GetTypedObjectForIUnknown(IntPtr pUnk, Type t)
- {
- throw new PlatformNotSupportedException(SR.PlatformNotSupported_ComInterop);
- }
-
- public static object GetObjectForIUnknown(IntPtr pUnk)
- {
- throw new PlatformNotSupportedException(SR.PlatformNotSupported_ComInterop);
- }
-
- public static object? GetObjectForNativeVariant(IntPtr pSrcNativeVariant)
- {
- throw new PlatformNotSupportedException(SR.PlatformNotSupported_ComInterop);
- }
-
- [return: MaybeNull]
- public static T GetObjectForNativeVariant<T>(IntPtr pSrcNativeVariant)
- {
- throw new PlatformNotSupportedException(SR.PlatformNotSupported_ComInterop);
- }
-
- public static object?[] GetObjectsForNativeVariants(IntPtr aSrcNativeVariant, int cVars)
- {
- throw new PlatformNotSupportedException(SR.PlatformNotSupported_ComInterop);
- }
-
- public static T[] GetObjectsForNativeVariants<T>(IntPtr aSrcNativeVariant, int cVars)
- {
- throw new PlatformNotSupportedException(SR.PlatformNotSupported_ComInterop);
- }
-
- public static int GetStartComSlot(Type t)
- {
- throw new PlatformNotSupportedException(SR.PlatformNotSupported_ComInterop);
- }
-
- public static int GetEndComSlot(Type t)
- {
- throw new PlatformNotSupportedException(SR.PlatformNotSupported_ComInterop);
- }
-
- public static Type GetTypeFromCLSID(Guid clsid)
- {
- throw new PlatformNotSupportedException(SR.PlatformNotSupported_ComInterop);
- }
-
- public static string GetTypeInfoName(ITypeInfo typeInfo)
- {
- throw new PlatformNotSupportedException(SR.PlatformNotSupported_ComInterop);
- }
-
- public static object GetUniqueObjectForIUnknown(IntPtr unknown)
- {
- throw new PlatformNotSupportedException(SR.PlatformNotSupported_ComInterop);
- }
-
- public static bool IsComObject(object o)
- {
- if (o is null)
- {
- throw new ArgumentNullException(nameof(o));
- }
-
- return false;
- }
-
- public static bool IsTypeVisibleFromCom(Type t)
- {
- if (t is null)
- {
- throw new ArgumentNullException(nameof(t));
- }
- return false;
- }
-
- public static int QueryInterface(IntPtr pUnk, ref Guid iid, out IntPtr ppv)
- {
- throw new PlatformNotSupportedException(SR.PlatformNotSupported_ComInterop);
- }
-
- public static int Release(IntPtr pUnk)
- {
- throw new PlatformNotSupportedException(SR.PlatformNotSupported_ComInterop);
- }
-
- public static int ReleaseComObject(object o)
- {
- throw new PlatformNotSupportedException(SR.PlatformNotSupported_ComInterop);
- }
-
- public static bool SetComObjectData(object obj, object key, object? data)
- {
- throw new PlatformNotSupportedException(SR.PlatformNotSupported_ComInterop);
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/Marshal.Unix.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/Marshal.Unix.cs
deleted file mode 100644
index 63c790501e7..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/Marshal.Unix.cs
+++ /dev/null
@@ -1,66 +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.Diagnostics;
-using System.Text;
-
-namespace System.Runtime.InteropServices
-{
- public static partial class Marshal
- {
- public static string? PtrToStringAuto(IntPtr ptr, int len)
- {
- return PtrToStringUTF8(ptr, len);
- }
-
- public static string? PtrToStringAuto(IntPtr ptr)
- {
- return PtrToStringUTF8(ptr);
- }
-
- public static IntPtr StringToHGlobalAuto(string? s)
- {
- return StringToHGlobalUTF8(s);
- }
-
- public static IntPtr StringToCoTaskMemAuto(string? s)
- {
- return StringToCoTaskMemUTF8(s);
- }
-
- private static int GetSystemMaxDBCSCharSize() => 3;
-
- private static bool IsNullOrWin32Atom(IntPtr ptr) => ptr == IntPtr.Zero;
-
- internal static unsafe int StringToAnsiString(string s, byte* buffer, int bufferLength, bool bestFit = false, bool throwOnUnmappableChar = false)
- {
- Debug.Assert(bufferLength >= (s.Length + 1) * SystemMaxDBCSCharSize, "Insufficient buffer length passed to StringToAnsiString");
-
- int convertedBytes;
-
- fixed (char* pChar = s)
- {
- convertedBytes = Encoding.UTF8.GetBytes(pChar, s.Length, buffer, bufferLength);
- }
-
- buffer[convertedBytes] = 0;
-
- return convertedBytes;
- }
-
- // Returns number of bytes required to convert given string to Ansi string. The return value includes null terminator.
- internal static unsafe int GetAnsiStringByteCount(ReadOnlySpan<char> chars)
- {
- int byteLength = Encoding.UTF8.GetByteCount(chars);
- return checked(byteLength + 1);
- }
-
- // Converts given string to Ansi string. The destination buffer must be large enough to hold the converted value, including null terminator.
- internal static unsafe void GetAnsiStringBytes(ReadOnlySpan<char> chars, Span<byte> bytes)
- {
- int actualByteLength = Encoding.UTF8.GetBytes(chars, bytes);
- bytes[actualByteLength] = 0;
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/Marshal.Windows.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/Marshal.Windows.cs
deleted file mode 100644
index 9889030d882..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/Marshal.Windows.cs
+++ /dev/null
@@ -1,131 +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.Diagnostics;
-
-namespace System.Runtime.InteropServices
-{
- public static partial class Marshal
- {
- public static string? PtrToStringAuto(IntPtr ptr, int len)
- {
- return PtrToStringUni(ptr, len);
- }
-
- public static string? PtrToStringAuto(IntPtr ptr)
- {
- return PtrToStringUni(ptr);
- }
-
- public static IntPtr StringToHGlobalAuto(string? s)
- {
- return StringToHGlobalUni(s);
- }
-
- public static IntPtr StringToCoTaskMemAuto(string? s)
- {
- return StringToCoTaskMemUni(s);
- }
-
- private static unsafe int GetSystemMaxDBCSCharSize()
- {
- Interop.Kernel32.CPINFO cpInfo = default;
-
- if (Interop.Kernel32.GetCPInfo(Interop.Kernel32.CP_ACP, &cpInfo) == Interop.BOOL.FALSE)
- return 2;
-
- return cpInfo.MaxCharSize;
- }
-
- // Win32 has the concept of Atoms, where a pointer can either be a pointer
- // or an int. If it's less than 64K, this is guaranteed to NOT be a
- // pointer since the bottom 64K bytes are reserved in a process' page table.
- // We should be careful about deallocating this stuff.
- private static bool IsNullOrWin32Atom(IntPtr ptr)
- {
- const long HIWORDMASK = unchecked((long)0xffffffffffff0000L);
-
- long lPtr = (long)ptr;
- return 0 == (lPtr & HIWORDMASK);
- }
-
- internal static unsafe int StringToAnsiString(string s, byte* buffer, int bufferLength, bool bestFit = false, bool throwOnUnmappableChar = false)
- {
- Debug.Assert(bufferLength >= (s.Length + 1) * SystemMaxDBCSCharSize, "Insufficient buffer length passed to StringToAnsiString");
-
- int nb;
-
- uint flags = bestFit ? 0 : Interop.Kernel32.WC_NO_BEST_FIT_CHARS;
- uint defaultCharUsed = 0;
-
- fixed (char* pwzChar = s)
- {
- nb = Interop.Kernel32.WideCharToMultiByte(
- Interop.Kernel32.CP_ACP,
- flags,
- pwzChar,
- s.Length,
- buffer,
- bufferLength,
- IntPtr.Zero,
- throwOnUnmappableChar ? new IntPtr(&defaultCharUsed) : IntPtr.Zero);
- }
-
- if (defaultCharUsed != 0)
- {
- throw new ArgumentException(SR.Interop_Marshal_Unmappable_Char);
- }
-
- buffer[nb] = 0;
- return nb;
- }
-
- // Returns number of bytes required to convert given string to Ansi string. The return value includes null terminator.
- internal static unsafe int GetAnsiStringByteCount(ReadOnlySpan<char> chars)
- {
- int byteLength;
-
- if (chars.Length == 0)
- {
- byteLength = 0;
- }
- else
- {
- fixed (char* pChars = chars)
- {
- byteLength = Interop.Kernel32.WideCharToMultiByte(
- Interop.Kernel32.CP_ACP, Interop.Kernel32.WC_NO_BEST_FIT_CHARS, pChars, chars.Length, null, 0, IntPtr.Zero, IntPtr.Zero);
- if (byteLength <= 0)
- throw new ArgumentException();
- }
- }
-
- return checked(byteLength + 1);
- }
-
- // Converts given string to Ansi string. The destination buffer must be large enough to hold the converted value, including null terminator.
- internal static unsafe void GetAnsiStringBytes(ReadOnlySpan<char> chars, Span<byte> bytes)
- {
- int byteLength;
-
- if (chars.Length == 0)
- {
- byteLength = 0;
- }
- else
- {
- fixed (char* pChars = chars)
- fixed (byte* pBytes = bytes)
- {
- byteLength = Interop.Kernel32.WideCharToMultiByte(
- Interop.Kernel32.CP_ACP, Interop.Kernel32.WC_NO_BEST_FIT_CHARS, pChars, chars.Length, pBytes, bytes.Length, IntPtr.Zero, IntPtr.Zero);
- if (byteLength <= 0)
- throw new ArgumentException();
- }
- }
-
- bytes[byteLength] = 0;
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/Marshal.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/Marshal.cs
deleted file mode 100644
index 4eaef53ec42..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/Marshal.cs
+++ /dev/null
@@ -1,978 +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.Security;
-using System.Reflection;
-using System.Runtime.CompilerServices;
-using System.Text;
-
-using Internal.Runtime.CompilerServices;
-using System.Diagnostics.CodeAnalysis;
-
-#pragma warning disable SA1121 // explicitly using type aliases instead of built-in types
-#if BIT64
-using nuint = System.UInt64;
-#else
-using nuint = System.UInt32;
-#endif
-
-namespace System.Runtime.InteropServices
-{
- /// <summary>
- /// This class contains methods that are mainly used to marshal between unmanaged
- /// and managed types.
- /// </summary>
- public static partial class Marshal
- {
- /// <summary>
- /// The default character size for the system. This is always 2 because
- /// the framework only runs on UTF-16 systems.
- /// </summary>
- public static readonly int SystemDefaultCharSize = 2;
-
- /// <summary>
- /// The max DBCS character size for the system.
- /// </summary>
- public static readonly int SystemMaxDBCSCharSize = GetSystemMaxDBCSCharSize();
-
- public static IntPtr AllocHGlobal(int cb) => AllocHGlobal((IntPtr)cb);
-
- public static unsafe string? PtrToStringAnsi(IntPtr ptr)
- {
- if (IsNullOrWin32Atom(ptr))
- {
- return null;
- }
-
- return new string((sbyte*)ptr);
- }
-
- public static unsafe string PtrToStringAnsi(IntPtr ptr, int len)
- {
- if (ptr == IntPtr.Zero)
- {
- throw new ArgumentNullException(nameof(ptr));
- }
- if (len < 0)
- {
- throw new ArgumentOutOfRangeException(nameof(len), len, SR.ArgumentOutOfRange_NeedNonNegNum);
- }
-
- return new string((sbyte*)ptr, 0, len);
- }
-
- public static unsafe string? PtrToStringUni(IntPtr ptr)
- {
- if (IsNullOrWin32Atom(ptr))
- {
- return null;
- }
-
- return new string((char*)ptr);
- }
-
- public static unsafe string PtrToStringUni(IntPtr ptr, int len)
- {
- if (ptr == IntPtr.Zero)
- {
- throw new ArgumentNullException(nameof(ptr));
- }
- if (len < 0)
- {
- throw new ArgumentOutOfRangeException(nameof(len), len, SR.ArgumentOutOfRange_NeedNonNegNum);
- }
-
- return new string((char*)ptr, 0, len);
- }
-
- public static unsafe string? PtrToStringUTF8(IntPtr ptr)
- {
- if (IsNullOrWin32Atom(ptr))
- {
- return null;
- }
-
- int nbBytes = string.strlen((byte*)ptr);
- return string.CreateStringFromEncoding((byte*)ptr, nbBytes, Encoding.UTF8);
- }
-
- public static unsafe string PtrToStringUTF8(IntPtr ptr, int byteLen)
- {
- if (ptr == IntPtr.Zero)
- {
- throw new ArgumentNullException(nameof(ptr));
- }
- if (byteLen < 0)
- {
- throw new ArgumentOutOfRangeException(nameof(byteLen), byteLen, SR.ArgumentOutOfRange_NeedNonNegNum);
- }
-
- return string.CreateStringFromEncoding((byte*)ptr, byteLen, Encoding.UTF8);
- }
-
- public static int SizeOf(object structure)
- {
- if (structure is null)
- {
- throw new ArgumentNullException(nameof(structure));
- }
-
- return SizeOfHelper(structure.GetType(), throwIfNotMarshalable: true);
- }
-
- public static int SizeOf<T>(T structure)
- {
- if (structure is null)
- {
- throw new ArgumentNullException(nameof(structure));
- }
-
- return SizeOfHelper(structure.GetType(), throwIfNotMarshalable: true);
- }
-
- public static int SizeOf(Type t)
- {
- if (t is null)
- {
- throw new ArgumentNullException(nameof(t));
- }
- if (!t.IsRuntimeImplemented())
- {
- throw new ArgumentException(SR.Argument_MustBeRuntimeType, nameof(t));
- }
- if (t.IsGenericType)
- {
- throw new ArgumentException(SR.Argument_NeedNonGenericType, nameof(t));
- }
-
- return SizeOfHelper(t, throwIfNotMarshalable: true);
- }
-
- public static int SizeOf<T>() => SizeOf(typeof(T));
-
- /// <summary>
- /// IMPORTANT NOTICE: This method does not do any verification on the array.
- /// It must be used with EXTREME CAUTION since passing in invalid index or
- /// an array that is not pinned can cause unexpected results.
- /// </summary>
- public static unsafe IntPtr UnsafeAddrOfPinnedArrayElement(Array arr, int index)
- {
- if (arr is null)
- throw new ArgumentNullException(nameof(arr));
-
- void* pRawData = Unsafe.AsPointer(ref arr.GetRawArrayData());
- return (IntPtr)((byte*)pRawData + (uint)index * (nuint)arr.GetElementSize());
- }
-
- public static unsafe IntPtr UnsafeAddrOfPinnedArrayElement<T>(T[] arr, int index)
- {
- if (arr is null)
- throw new ArgumentNullException(nameof(arr));
-
- void* pRawData = Unsafe.AsPointer(ref arr.GetRawSzArrayData());
- return (IntPtr)((byte*)pRawData + (uint)index * (nuint)Unsafe.SizeOf<T>());
- }
-
- public static IntPtr OffsetOf<T>(string fieldName) => OffsetOf(typeof(T), fieldName);
-
- public static void Copy(int[] source, int startIndex, IntPtr destination, int length)
- {
- CopyToNative(source, startIndex, destination, length);
- }
-
- public static void Copy(char[] source, int startIndex, IntPtr destination, int length)
- {
- CopyToNative(source, startIndex, destination, length);
- }
-
- public static void Copy(short[] source, int startIndex, IntPtr destination, int length)
- {
- CopyToNative(source, startIndex, destination, length);
- }
-
- public static void Copy(long[] source, int startIndex, IntPtr destination, int length)
- {
- CopyToNative(source, startIndex, destination, length);
- }
-
- public static void Copy(float[] source, int startIndex, IntPtr destination, int length)
- {
- CopyToNative(source, startIndex, destination, length);
- }
-
- public static void Copy(double[] source, int startIndex, IntPtr destination, int length)
- {
- CopyToNative(source, startIndex, destination, length);
- }
-
- public static void Copy(byte[] source, int startIndex, IntPtr destination, int length)
- {
- CopyToNative(source, startIndex, destination, length);
- }
-
- public static void Copy(IntPtr[] source, int startIndex, IntPtr destination, int length)
- {
- CopyToNative(source, startIndex, destination, length);
- }
-
- private static unsafe void CopyToNative<T>(T[] source, int startIndex, IntPtr destination, int length)
- {
- if (source is null)
- throw new ArgumentNullException(nameof(source));
- if (destination == IntPtr.Zero)
- throw new ArgumentNullException(nameof(destination));
-
- // The rest of the argument validation is done by CopyTo
-
- new Span<T>(source, startIndex, length).CopyTo(new Span<T>((void*)destination, length));
- }
-
- public static void Copy(IntPtr source, int[] destination, int startIndex, int length)
- {
- CopyToManaged(source, destination, startIndex, length);
- }
-
- public static void Copy(IntPtr source, char[] destination, int startIndex, int length)
- {
- CopyToManaged(source, destination, startIndex, length);
- }
-
- public static void Copy(IntPtr source, short[] destination, int startIndex, int length)
- {
- CopyToManaged(source, destination, startIndex, length);
- }
-
- public static void Copy(IntPtr source, long[] destination, int startIndex, int length)
- {
- CopyToManaged(source, destination, startIndex, length);
- }
-
- public static void Copy(IntPtr source, float[] destination, int startIndex, int length)
- {
- CopyToManaged(source, destination, startIndex, length);
- }
-
- public static void Copy(IntPtr source, double[] destination, int startIndex, int length)
- {
- CopyToManaged(source, destination, startIndex, length);
- }
-
- public static void Copy(IntPtr source, byte[] destination, int startIndex, int length)
- {
- CopyToManaged(source, destination, startIndex, length);
- }
-
- public static void Copy(IntPtr source, IntPtr[] destination, int startIndex, int length)
- {
- CopyToManaged(source, destination, startIndex, length);
- }
-
- private static unsafe void CopyToManaged<T>(IntPtr source, T[] destination, int startIndex, int length)
- {
- if (source == IntPtr.Zero)
- throw new ArgumentNullException(nameof(source));
- if (destination is null)
- throw new ArgumentNullException(nameof(destination));
- if (startIndex < 0)
- throw new ArgumentOutOfRangeException(nameof(startIndex), SR.ArgumentOutOfRange_StartIndex);
- if (length < 0)
- throw new ArgumentOutOfRangeException(nameof(length), SR.ArgumentOutOfRange_NeedNonNegNum);
-
- // The rest of the argument validation is done by CopyTo
-
- new Span<T>((void*)source, length).CopyTo(new Span<T>(destination, startIndex, length));
- }
-
- public static unsafe byte ReadByte(IntPtr ptr, int ofs)
- {
- try
- {
- byte* addr = (byte*)ptr + ofs;
- return *addr;
- }
- catch (NullReferenceException)
- {
- // this method is documented to throw AccessViolationException on any AV
- throw new AccessViolationException();
- }
- }
-
- public static byte ReadByte(IntPtr ptr) => ReadByte(ptr, 0);
-
- public static unsafe short ReadInt16(IntPtr ptr, int ofs)
- {
- try
- {
- byte* addr = (byte*)ptr + ofs;
- if ((unchecked((int)addr) & 0x1) == 0)
- {
- // aligned read
- return *((short*)addr);
- }
- else
- {
- return Unsafe.ReadUnaligned<short>(addr);
- }
- }
- catch (NullReferenceException)
- {
- // this method is documented to throw AccessViolationException on any AV
- throw new AccessViolationException();
- }
- }
-
- public static short ReadInt16(IntPtr ptr) => ReadInt16(ptr, 0);
-
- public static unsafe int ReadInt32(IntPtr ptr, int ofs)
- {
- try
- {
- byte* addr = (byte*)ptr + ofs;
- if ((unchecked((int)addr) & 0x3) == 0)
- {
- // aligned read
- return *((int*)addr);
- }
- else
- {
- return Unsafe.ReadUnaligned<int>(addr);
- }
- }
- catch (NullReferenceException)
- {
- // this method is documented to throw AccessViolationException on any AV
- throw new AccessViolationException();
- }
- }
-
- public static int ReadInt32(IntPtr ptr) => ReadInt32(ptr, 0);
-
- public static IntPtr ReadIntPtr(object ptr, int ofs)
- {
-#if BIT64
- return (IntPtr)ReadInt64(ptr, ofs);
-#else // 32
- return (IntPtr)ReadInt32(ptr, ofs);
-#endif
- }
-
- public static IntPtr ReadIntPtr(IntPtr ptr, int ofs)
- {
-#if BIT64
- return (IntPtr)ReadInt64(ptr, ofs);
-#else // 32
- return (IntPtr)ReadInt32(ptr, ofs);
-#endif
- }
-
- public static IntPtr ReadIntPtr(IntPtr ptr) => ReadIntPtr(ptr, 0);
-
- public static unsafe long ReadInt64(IntPtr ptr, int ofs)
- {
- try
- {
- byte* addr = (byte*)ptr + ofs;
- if ((unchecked((int)addr) & 0x7) == 0)
- {
- // aligned read
- return *((long*)addr);
- }
- else
- {
- return Unsafe.ReadUnaligned<long>(addr);
- }
- }
- catch (NullReferenceException)
- {
- // this method is documented to throw AccessViolationException on any AV
- throw new AccessViolationException();
- }
- }
-
- public static long ReadInt64(IntPtr ptr) => ReadInt64(ptr, 0);
-
- public static unsafe void WriteByte(IntPtr ptr, int ofs, byte val)
- {
- try
- {
- byte* addr = (byte*)ptr + ofs;
- *addr = val;
- }
- catch (NullReferenceException)
- {
- // this method is documented to throw AccessViolationException on any AV
- throw new AccessViolationException();
- }
- }
-
- public static void WriteByte(IntPtr ptr, byte val) => WriteByte(ptr, 0, val);
-
- public static unsafe void WriteInt16(IntPtr ptr, int ofs, short val)
- {
- try
- {
- byte* addr = (byte*)ptr + ofs;
- if ((unchecked((int)addr) & 0x1) == 0)
- {
- // aligned write
- *((short*)addr) = val;
- }
- else
- {
- Unsafe.WriteUnaligned(addr, val);
- }
- }
- catch (NullReferenceException)
- {
- // this method is documented to throw AccessViolationException on any AV
- throw new AccessViolationException();
- }
- }
-
- public static void WriteInt16(IntPtr ptr, short val) => WriteInt16(ptr, 0, val);
-
- public static void WriteInt16(IntPtr ptr, int ofs, char val) => WriteInt16(ptr, ofs, (short)val);
-
- public static void WriteInt16([In, Out]object ptr, int ofs, char val) => WriteInt16(ptr, ofs, (short)val);
-
- public static void WriteInt16(IntPtr ptr, char val) => WriteInt16(ptr, 0, (short)val);
-
- public static unsafe void WriteInt32(IntPtr ptr, int ofs, int val)
- {
- try
- {
- byte* addr = (byte*)ptr + ofs;
- if ((unchecked((int)addr) & 0x3) == 0)
- {
- // aligned write
- *((int*)addr) = val;
- }
- else
- {
- Unsafe.WriteUnaligned(addr, val);
- }
- }
- catch (NullReferenceException)
- {
- // this method is documented to throw AccessViolationException on any AV
- throw new AccessViolationException();
- }
- }
-
- public static void WriteInt32(IntPtr ptr, int val) => WriteInt32(ptr, 0, val);
-
- public static void WriteIntPtr(IntPtr ptr, int ofs, IntPtr val)
- {
-#if BIT64
- WriteInt64(ptr, ofs, (long)val);
-#else // 32
- WriteInt32(ptr, ofs, (int)val);
-#endif
- }
-
- public static void WriteIntPtr(object ptr, int ofs, IntPtr val)
- {
-#if BIT64
- WriteInt64(ptr, ofs, (long)val);
-#else // 32
- WriteInt32(ptr, ofs, (int)val);
-#endif
- }
-
- public static void WriteIntPtr(IntPtr ptr, IntPtr val) => WriteIntPtr(ptr, 0, val);
-
- public static unsafe void WriteInt64(IntPtr ptr, int ofs, long val)
- {
- try
- {
- byte* addr = (byte*)ptr + ofs;
- if ((unchecked((int)addr) & 0x7) == 0)
- {
- // aligned write
- *((long*)addr) = val;
- }
- else
- {
- Unsafe.WriteUnaligned(addr, val);
- }
- }
- catch (NullReferenceException)
- {
- // this method is documented to throw AccessViolationException on any AV
- throw new AccessViolationException();
- }
- }
-
- public static void WriteInt64(IntPtr ptr, long val) => WriteInt64(ptr, 0, val);
-
- public static void Prelink(MethodInfo m)
- {
- if (m is null)
- {
- throw new ArgumentNullException(nameof(m));
- }
-
- PrelinkCore(m);
- }
-
- public static void PrelinkAll(Type c)
- {
- if (c is null)
- {
- throw new ArgumentNullException(nameof(c));
- }
-
- MethodInfo[] mi = c.GetMethods();
-
- for (int i = 0; i < mi.Length; i++)
- {
- Prelink(mi[i]);
- }
- }
-
- public static void StructureToPtr<T>([DisallowNull] T structure, IntPtr ptr, bool fDeleteOld)
- {
- StructureToPtr((object)structure!, ptr, fDeleteOld);
- }
-
- /// <summary>
- /// Creates a new instance of "structuretype" and marshals data from a
- /// native memory block to it.
- /// </summary>
- public static object? PtrToStructure(IntPtr ptr, Type structureType)
- {
- if (ptr == IntPtr.Zero)
- {
- return null;
- }
-
- if (structureType is null)
- {
- throw new ArgumentNullException(nameof(structureType));
- }
- if (structureType.IsGenericType)
- {
- throw new ArgumentException(SR.Argument_NeedNonGenericType, nameof(structureType));
- }
- if (!structureType.IsRuntimeImplemented())
- {
- throw new ArgumentException(SR.Argument_MustBeRuntimeType, nameof(structureType));
- }
-
- return PtrToStructureHelper(ptr, structureType);
- }
-
- /// <summary>
- /// Marshals data from a native memory block to a preallocated structure class.
- /// </summary>
- public static void PtrToStructure(IntPtr ptr, object structure)
- {
- PtrToStructureHelper(ptr, structure, allowValueClasses: false);
- }
-
- public static void PtrToStructure<T>(IntPtr ptr, [DisallowNull] T structure)
- {
- PtrToStructure(ptr, (object)structure!);
- }
-
- [return: MaybeNull]
- public static T PtrToStructure<T>(IntPtr ptr) => (T)PtrToStructure(ptr, typeof(T))!;
-
- public static void DestroyStructure<T>(IntPtr ptr) => DestroyStructure(ptr, typeof(T));
-
- /// <summary>
- /// Converts the HRESULT to a CLR exception.
- /// </summary>
- public static Exception? GetExceptionForHR(int errorCode) => GetExceptionForHR(errorCode, IntPtr.Zero);
-
- public static Exception? GetExceptionForHR(int errorCode, IntPtr errorInfo)
- {
- if (errorCode >= 0)
- {
- return null;
- }
-
- return GetExceptionForHRInternal(errorCode, errorInfo);
- }
-
- /// <summary>
- /// Throws a CLR exception based on the HRESULT.
- /// </summary>
- public static void ThrowExceptionForHR(int errorCode)
- {
- if (errorCode < 0)
- {
- throw GetExceptionForHR(errorCode, IntPtr.Zero)!;
- }
- }
-
- public static void ThrowExceptionForHR(int errorCode, IntPtr errorInfo)
- {
- if (errorCode < 0)
- {
- throw GetExceptionForHR(errorCode, errorInfo)!;
- }
- }
-
- public static IntPtr SecureStringToBSTR(SecureString s)
- {
- if (s is null)
- {
- throw new ArgumentNullException(nameof(s));
- }
-
- return s.MarshalToBSTR();
- }
-
- public static IntPtr SecureStringToCoTaskMemAnsi(SecureString s)
- {
- if (s is null)
- {
- throw new ArgumentNullException(nameof(s));
- }
-
- return s.MarshalToString(globalAlloc: false, unicode: false);
- }
-
- public static IntPtr SecureStringToCoTaskMemUnicode(SecureString s)
- {
- if (s is null)
- {
- throw new ArgumentNullException(nameof(s));
- }
-
- return s.MarshalToString(globalAlloc: false, unicode: true);
- }
-
- public static IntPtr SecureStringToGlobalAllocAnsi(SecureString s)
- {
- if (s is null)
- {
- throw new ArgumentNullException(nameof(s));
- }
-
- return s.MarshalToString(globalAlloc: true, unicode: false);
- }
-
- public static IntPtr SecureStringToGlobalAllocUnicode(SecureString s)
- {
- if (s is null)
- {
- throw new ArgumentNullException(nameof(s));
- }
-
- return s.MarshalToString(globalAlloc: true, unicode: true);
- }
-
- public static unsafe IntPtr StringToHGlobalAnsi(string? s)
- {
- if (s is null)
- {
- return IntPtr.Zero;
- }
-
- long lnb = (s.Length + 1) * (long)SystemMaxDBCSCharSize;
- int nb = (int)lnb;
-
- // Overflow checking
- if (nb != lnb)
- {
- throw new ArgumentOutOfRangeException(nameof(s));
- }
-
- IntPtr hglobal = AllocHGlobal((IntPtr)nb);
-
- StringToAnsiString(s, (byte*)hglobal, nb);
- return hglobal;
- }
-
- public static unsafe IntPtr StringToHGlobalUni(string? s)
- {
- if (s is null)
- {
- return IntPtr.Zero;
- }
-
- int nb = (s.Length + 1) * 2;
-
- // Overflow checking
- if (nb < s.Length)
- {
- throw new ArgumentOutOfRangeException(nameof(s));
- }
-
- IntPtr hglobal = AllocHGlobal((IntPtr)nb);
-
- fixed (char* firstChar = s)
- {
- string.wstrcpy((char*)hglobal, firstChar, s.Length + 1);
- }
- return hglobal;
- }
-
- private static unsafe IntPtr StringToHGlobalUTF8(string? s)
- {
- if (s is null)
- {
- return IntPtr.Zero;
- }
-
- int nb = Encoding.UTF8.GetMaxByteCount(s.Length);
-
- IntPtr pMem = AllocHGlobal(nb + 1);
-
- int nbWritten;
- byte* pbMem = (byte*)pMem;
-
- fixed (char* firstChar = s)
- {
- nbWritten = Encoding.UTF8.GetBytes(firstChar, s.Length, pbMem, nb);
- }
-
- pbMem[nbWritten] = 0;
-
- return pMem;
- }
-
- public static unsafe IntPtr StringToCoTaskMemUni(string? s)
- {
- if (s is null)
- {
- return IntPtr.Zero;
- }
-
- int nb = (s.Length + 1) * 2;
-
- // Overflow checking
- if (nb < s.Length)
- {
- throw new ArgumentOutOfRangeException(nameof(s));
- }
-
- IntPtr hglobal = AllocCoTaskMem(nb);
-
- fixed (char* firstChar = s)
- {
- string.wstrcpy((char*)hglobal, firstChar, s.Length + 1);
- }
- return hglobal;
- }
-
- public static unsafe IntPtr StringToCoTaskMemUTF8(string? s)
- {
- if (s is null)
- {
- return IntPtr.Zero;
- }
-
- int nb = Encoding.UTF8.GetMaxByteCount(s.Length);
-
- IntPtr pMem = AllocCoTaskMem(nb + 1);
-
- int nbWritten;
- byte* pbMem = (byte*)pMem;
-
- fixed (char* firstChar = s)
- {
- nbWritten = Encoding.UTF8.GetBytes(firstChar, s.Length, pbMem, nb);
- }
-
- pbMem[nbWritten] = 0;
-
- return pMem;
- }
-
- public static unsafe IntPtr StringToCoTaskMemAnsi(string? s)
- {
- if (s is null)
- {
- return IntPtr.Zero;
- }
-
- long lnb = (s.Length + 1) * (long)SystemMaxDBCSCharSize;
- int nb = (int)lnb;
-
- // Overflow checking
- if (nb != lnb)
- {
- throw new ArgumentOutOfRangeException(nameof(s));
- }
-
- IntPtr hglobal = AllocCoTaskMem(nb);
-
- StringToAnsiString(s, (byte*)hglobal, nb);
- return hglobal;
- }
-
- /// <summary>
- /// Generates a GUID for the specified type. If the type has a GUID in the
- /// metadata then it is returned otherwise a stable guid is generated based
- /// on the fully qualified name of the type.
- /// </summary>
- public static Guid GenerateGuidForType(Type type)
- {
- if (type is null)
- {
- throw new ArgumentNullException(nameof(type));
- }
- if (!type.IsRuntimeImplemented())
- {
- throw new ArgumentException(SR.Argument_MustBeRuntimeType, nameof(type));
- }
-
- return type.GUID;
- }
-
- /// <summary>
- /// This method generates a PROGID for the specified type. If the type has
- /// a PROGID in the metadata then it is returned otherwise a stable PROGID
- /// is generated based on the fully qualified name of the type.
- /// </summary>
- public static string? GenerateProgIdForType(Type type)
- {
- if (type is null)
- {
- throw new ArgumentNullException(nameof(type));
- }
- if (type.IsImport)
- {
- throw new ArgumentException(SR.Argument_TypeMustNotBeComImport, nameof(type));
- }
- if (type.IsGenericType)
- {
- throw new ArgumentException(SR.Argument_NeedNonGenericType, nameof(type));
- }
-
- ProgIdAttribute? progIdAttribute = type.GetCustomAttribute<ProgIdAttribute>();
- if (progIdAttribute != null)
- {
- return progIdAttribute.Value ?? string.Empty;
- }
-
- // If there is no prog ID attribute then use the full name of the type as the prog id.
- return type.FullName;
- }
-
- public static Delegate GetDelegateForFunctionPointer(IntPtr ptr, Type t)
- {
- if (ptr == IntPtr.Zero)
- {
- throw new ArgumentNullException(nameof(ptr));
- }
- if (t is null)
- {
- throw new ArgumentNullException(nameof(t));
- }
- if (!t.IsRuntimeImplemented())
- {
- throw new ArgumentException(SR.Argument_MustBeRuntimeType, nameof(t));
- }
- if (t.IsGenericType)
- {
- throw new ArgumentException(SR.Argument_NeedNonGenericType, nameof(t));
- }
-
- Type? c = t.BaseType;
- if (c != typeof(Delegate) && c != typeof(MulticastDelegate))
- {
- throw new ArgumentException(SR.Arg_MustBeDelegate, nameof(t));
- }
-
- return GetDelegateForFunctionPointerInternal(ptr, t);
- }
-
- public static TDelegate GetDelegateForFunctionPointer<TDelegate>(IntPtr ptr)
- {
- return (TDelegate)(object)GetDelegateForFunctionPointer(ptr, typeof(TDelegate));
- }
-
- public static IntPtr GetFunctionPointerForDelegate(Delegate d)
- {
- if (d is null)
- {
- throw new ArgumentNullException(nameof(d));
- }
-
- return GetFunctionPointerForDelegateInternal(d);
- }
-
- public static IntPtr GetFunctionPointerForDelegate<TDelegate>(TDelegate d) where TDelegate : notnull
- {
- return GetFunctionPointerForDelegate((Delegate)(object)d);
- }
-
- public static int GetHRForLastWin32Error()
- {
- int dwLastError = GetLastWin32Error();
- if ((dwLastError & 0x80000000) == 0x80000000)
- {
- return dwLastError;
- }
-
- return (dwLastError & 0x0000FFFF) | unchecked((int)0x80070000);
- }
-
- public static IntPtr /* IDispatch */ GetIDispatchForObject(object o) => throw new PlatformNotSupportedException();
-
- public static unsafe void ZeroFreeBSTR(IntPtr s)
- {
- if (s == IntPtr.Zero)
- {
- return;
- }
- Buffer.ZeroMemory((byte*)s, SysStringByteLen(s));
- FreeBSTR(s);
- }
-
- public static unsafe void ZeroFreeCoTaskMemAnsi(IntPtr s)
- {
- ZeroFreeCoTaskMemUTF8(s);
- }
-
- public static unsafe void ZeroFreeCoTaskMemUnicode(IntPtr s)
- {
- if (s == IntPtr.Zero)
- {
- return;
- }
- Buffer.ZeroMemory((byte*)s, (nuint)string.wcslen((char*)s) * sizeof(char));
- FreeCoTaskMem(s);
- }
-
- public static unsafe void ZeroFreeCoTaskMemUTF8(IntPtr s)
- {
- if (s == IntPtr.Zero)
- {
- return;
- }
- Buffer.ZeroMemory((byte*)s, (nuint)string.strlen((byte*)s));
- FreeCoTaskMem(s);
- }
-
- public static unsafe void ZeroFreeGlobalAllocAnsi(IntPtr s)
- {
- if (s == IntPtr.Zero)
- {
- return;
- }
- Buffer.ZeroMemory((byte*)s, (nuint)string.strlen((byte*)s));
- FreeHGlobal(s);
- }
-
- public static unsafe void ZeroFreeGlobalAllocUnicode(IntPtr s)
- {
- if (s == IntPtr.Zero)
- {
- return;
- }
- Buffer.ZeroMemory((byte*)s, (nuint)string.wcslen((char*)s) * sizeof(char));
- FreeHGlobal(s);
- }
-
- internal static unsafe uint SysStringByteLen(IntPtr s)
- {
- return *(((uint*)s) - 1);
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/MarshalAsAttribute.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/MarshalAsAttribute.cs
deleted file mode 100644
index ae142a4323d..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/MarshalAsAttribute.cs
+++ /dev/null
@@ -1,39 +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.
-
-namespace System.Runtime.InteropServices
-{
- [AttributeUsage(AttributeTargets.Parameter | AttributeTargets.Field | AttributeTargets.ReturnValue, Inherited = false)]
- public sealed partial class MarshalAsAttribute : Attribute
- {
- public MarshalAsAttribute(UnmanagedType unmanagedType)
- {
- Value = unmanagedType;
- }
- public MarshalAsAttribute(short unmanagedType)
- {
- Value = (UnmanagedType)unmanagedType;
- }
-
- public UnmanagedType Value { get; }
-
- // Fields used with SubType = SafeArray.
- public VarEnum SafeArraySubType;
- public Type? SafeArrayUserDefinedSubType;
-
- // Field used with iid_is attribute (interface pointers).
- public int IidParameterIndex;
-
- // Fields used with SubType = ByValArray and LPArray.
- // Array size = parameter(PI) * PM + C
- public UnmanagedType ArraySubType;
- public short SizeParamIndex; // param index PI
- public int SizeConst; // constant C
-
- // Fields used with SubType = CustomMarshaler
- public string? MarshalType; // Name of marshaler class
- public Type? MarshalTypeRef; // Type of marshaler class
- public string? MarshalCookie; // cookie to pass to marshaler
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/MarshalDirectiveException.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/MarshalDirectiveException.cs
deleted file mode 100644
index 1baae38e965..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/MarshalDirectiveException.cs
+++ /dev/null
@@ -1,44 +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.
-
-/*=============================================================================
-**
-**
-** Purpose: This exception is thrown when the marshaller encounters a signature
-** that has an invalid MarshalAs CA for a given argument or is not
-** supported.
-**
-=============================================================================*/
-
-using System.Runtime.Serialization;
-
-namespace System.Runtime.InteropServices
-{
- [Serializable]
- [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public class MarshalDirectiveException : SystemException
- {
- public MarshalDirectiveException()
- : base(SR.Arg_MarshalDirectiveException)
- {
- HResult = HResults.COR_E_MARSHALDIRECTIVE;
- }
-
- public MarshalDirectiveException(string? message)
- : base(message)
- {
- HResult = HResults.COR_E_MARSHALDIRECTIVE;
- }
-
- public MarshalDirectiveException(string? message, Exception? inner)
- : base(message, inner)
- {
- HResult = HResults.COR_E_MARSHALDIRECTIVE;
- }
-
- protected MarshalDirectiveException(SerializationInfo info, StreamingContext context) : base(info, context)
- {
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/MemoryMarshal.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/MemoryMarshal.cs
deleted file mode 100644
index a61e0220885..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/MemoryMarshal.cs
+++ /dev/null
@@ -1,535 +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.Buffers;
-using System.Runtime.CompilerServices;
-using System.Collections.Generic;
-using System.Diagnostics;
-
-using Internal.Runtime.CompilerServices;
-using System.Diagnostics.CodeAnalysis;
-
-namespace System.Runtime.InteropServices
-{
- /// <summary>
- /// Provides a collection of methods for interoperating with <see cref="Memory{T}"/>, <see cref="ReadOnlyMemory{T}"/>,
- /// <see cref="Span{T}"/>, and <see cref="ReadOnlySpan{T}"/>.
- /// </summary>
- public static class MemoryMarshal
- {
- /// <summary>
- /// Casts a Span of one primitive type <typeparamref name="T"/> to Span of bytes.
- /// That type may not contain pointers or references. This is checked at runtime in order to preserve type safety.
- /// </summary>
- /// <param name="span">The source slice, of type <typeparamref name="T"/>.</param>
- /// <exception cref="System.ArgumentException">
- /// Thrown when <typeparamref name="T"/> contains pointers.
- /// </exception>
- /// <exception cref="System.OverflowException">
- /// Thrown if the Length property of the new Span would exceed int.MaxValue.
- /// </exception>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static Span<byte> AsBytes<T>(Span<T> span)
- where T : struct
- {
- if (RuntimeHelpers.IsReferenceOrContainsReferences<T>())
- ThrowHelper.ThrowInvalidTypeWithPointersNotSupported(typeof(T));
-
- return new Span<byte>(
- ref Unsafe.As<T, byte>(ref GetReference(span)),
- checked(span.Length * Unsafe.SizeOf<T>()));
- }
-
- /// <summary>
- /// Casts a ReadOnlySpan of one primitive type <typeparamref name="T"/> to ReadOnlySpan of bytes.
- /// That type may not contain pointers or references. This is checked at runtime in order to preserve type safety.
- /// </summary>
- /// <param name="span">The source slice, of type <typeparamref name="T"/>.</param>
- /// <exception cref="System.ArgumentException">
- /// Thrown when <typeparamref name="T"/> contains pointers.
- /// </exception>
- /// <exception cref="System.OverflowException">
- /// Thrown if the Length property of the new Span would exceed int.MaxValue.
- /// </exception>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static ReadOnlySpan<byte> AsBytes<T>(ReadOnlySpan<T> span)
- where T : struct
- {
- if (RuntimeHelpers.IsReferenceOrContainsReferences<T>())
- ThrowHelper.ThrowInvalidTypeWithPointersNotSupported(typeof(T));
-
- return new ReadOnlySpan<byte>(
- ref Unsafe.As<T, byte>(ref GetReference(span)),
- checked(span.Length * Unsafe.SizeOf<T>()));
- }
-
- /// <summary>Creates a <see cref="Memory{T}"/> from a <see cref="ReadOnlyMemory{T}"/>.</summary>
- /// <param name="memory">The <see cref="ReadOnlyMemory{T}"/>.</param>
- /// <returns>A <see cref="Memory{T}"/> representing the same memory as the <see cref="ReadOnlyMemory{T}"/>, but writable.</returns>
- /// <remarks>
- /// <see cref="AsMemory{T}(ReadOnlyMemory{T})"/> must be used with extreme caution. <see cref="ReadOnlyMemory{T}"/> is used
- /// to represent immutable data and other memory that is not meant to be written to; <see cref="Memory{T}"/> instances created
- /// by <see cref="AsMemory{T}(ReadOnlyMemory{T})"/> should not be written to. The method exists to enable variables typed
- /// as <see cref="Memory{T}"/> but only used for reading to store a <see cref="ReadOnlyMemory{T}"/>.
- /// </remarks>
- public static Memory<T> AsMemory<T>(ReadOnlyMemory<T> memory) =>
- Unsafe.As<ReadOnlyMemory<T>, Memory<T>>(ref memory);
-
- /// <summary>
- /// Returns a reference to the 0th element of the Span. If the Span is empty, returns a reference to the location where the 0th element
- /// would have been stored. Such a reference may or may not be null. It can be used for pinning but must never be dereferenced.
- /// </summary>
- public static ref T GetReference<T>(Span<T> span) => ref span._pointer.Value;
-
- /// <summary>
- /// Returns a reference to the 0th element of the ReadOnlySpan. If the ReadOnlySpan is empty, returns a reference to the location where the 0th element
- /// would have been stored. Such a reference may or may not be null. It can be used for pinning but must never be dereferenced.
- /// </summary>
- public static ref T GetReference<T>(ReadOnlySpan<T> span) => ref span._pointer.Value;
-
- /// <summary>
- /// Returns a reference to the 0th element of the Span. If the Span is empty, returns a reference to fake non-null pointer. Such a reference can be used
- /// for pinning but must never be dereferenced. This is useful for interop with methods that do not accept null pointers for zero-sized buffers.
- /// </summary>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- internal static unsafe ref T GetNonNullPinnableReference<T>(Span<T> span) => ref (span.Length != 0) ? ref span._pointer.Value : ref Unsafe.AsRef<T>((void*)1);
-
- /// <summary>
- /// Returns a reference to the 0th element of the ReadOnlySpan. If the ReadOnlySpan is empty, returns a reference to fake non-null pointer. Such a reference
- /// can be used for pinning but must never be dereferenced. This is useful for interop with methods that do not accept null pointers for zero-sized buffers.
- /// </summary>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- internal static unsafe ref T GetNonNullPinnableReference<T>(ReadOnlySpan<T> span) => ref (span.Length != 0) ? ref span._pointer.Value : ref Unsafe.AsRef<T>((void*)1);
-
- /// <summary>
- /// Casts a Span of one primitive type <typeparamref name="TFrom"/> to another primitive type <typeparamref name="TTo"/>.
- /// These types may not contain pointers or references. This is checked at runtime in order to preserve type safety.
- /// </summary>
- /// <remarks>
- /// Supported only for platforms that support misaligned memory access or when the memory block is aligned by other means.
- /// </remarks>
- /// <param name="span">The source slice, of type <typeparamref name="TFrom"/>.</param>
- /// <exception cref="System.ArgumentException">
- /// Thrown when <typeparamref name="TFrom"/> or <typeparamref name="TTo"/> contains pointers.
- /// </exception>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static Span<TTo> Cast<TFrom, TTo>(Span<TFrom> span)
- where TFrom : struct
- where TTo : struct
- {
- if (RuntimeHelpers.IsReferenceOrContainsReferences<TFrom>())
- ThrowHelper.ThrowInvalidTypeWithPointersNotSupported(typeof(TFrom));
- if (RuntimeHelpers.IsReferenceOrContainsReferences<TTo>())
- ThrowHelper.ThrowInvalidTypeWithPointersNotSupported(typeof(TTo));
-
- // Use unsigned integers - unsigned division by constant (especially by power of 2)
- // and checked casts are faster and smaller.
- uint fromSize = (uint)Unsafe.SizeOf<TFrom>();
- uint toSize = (uint)Unsafe.SizeOf<TTo>();
- uint fromLength = (uint)span.Length;
- int toLength;
- if (fromSize == toSize)
- {
- // Special case for same size types - `(ulong)fromLength * (ulong)fromSize / (ulong)toSize`
- // should be optimized to just `length` but the JIT doesn't do that today.
- toLength = (int)fromLength;
- }
- else if (fromSize == 1)
- {
- // Special case for byte sized TFrom - `(ulong)fromLength * (ulong)fromSize / (ulong)toSize`
- // becomes `(ulong)fromLength / (ulong)toSize` but the JIT can't narrow it down to `int`
- // and can't eliminate the checked cast. This also avoids a 32 bit specific issue,
- // the JIT can't eliminate long multiply by 1.
- toLength = (int)(fromLength / toSize);
- }
- else
- {
- // Ensure that casts are done in such a way that the JIT is able to "see"
- // the uint->ulong casts and the multiply together so that on 32 bit targets
- // 32x32to64 multiplication is used.
- ulong toLengthUInt64 = (ulong)fromLength * (ulong)fromSize / (ulong)toSize;
- toLength = checked((int)toLengthUInt64);
- }
-
- return new Span<TTo>(
- ref Unsafe.As<TFrom, TTo>(ref span._pointer.Value),
- toLength);
- }
-
- /// <summary>
- /// Casts a ReadOnlySpan of one primitive type <typeparamref name="TFrom"/> to another primitive type <typeparamref name="TTo"/>.
- /// These types may not contain pointers or references. This is checked at runtime in order to preserve type safety.
- /// </summary>
- /// <remarks>
- /// Supported only for platforms that support misaligned memory access or when the memory block is aligned by other means.
- /// </remarks>
- /// <param name="span">The source slice, of type <typeparamref name="TFrom"/>.</param>
- /// <exception cref="System.ArgumentException">
- /// Thrown when <typeparamref name="TFrom"/> or <typeparamref name="TTo"/> contains pointers.
- /// </exception>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static ReadOnlySpan<TTo> Cast<TFrom, TTo>(ReadOnlySpan<TFrom> span)
- where TFrom : struct
- where TTo : struct
- {
- if (RuntimeHelpers.IsReferenceOrContainsReferences<TFrom>())
- ThrowHelper.ThrowInvalidTypeWithPointersNotSupported(typeof(TFrom));
- if (RuntimeHelpers.IsReferenceOrContainsReferences<TTo>())
- ThrowHelper.ThrowInvalidTypeWithPointersNotSupported(typeof(TTo));
-
- // Use unsigned integers - unsigned division by constant (especially by power of 2)
- // and checked casts are faster and smaller.
- uint fromSize = (uint)Unsafe.SizeOf<TFrom>();
- uint toSize = (uint)Unsafe.SizeOf<TTo>();
- uint fromLength = (uint)span.Length;
- int toLength;
- if (fromSize == toSize)
- {
- // Special case for same size types - `(ulong)fromLength * (ulong)fromSize / (ulong)toSize`
- // should be optimized to just `length` but the JIT doesn't do that today.
- toLength = (int)fromLength;
- }
- else if (fromSize == 1)
- {
- // Special case for byte sized TFrom - `(ulong)fromLength * (ulong)fromSize / (ulong)toSize`
- // becomes `(ulong)fromLength / (ulong)toSize` but the JIT can't narrow it down to `int`
- // and can't eliminate the checked cast. This also avoids a 32 bit specific issue,
- // the JIT can't eliminate long multiply by 1.
- toLength = (int)(fromLength / toSize);
- }
- else
- {
- // Ensure that casts are done in such a way that the JIT is able to "see"
- // the uint->ulong casts and the multiply together so that on 32 bit targets
- // 32x32to64 multiplication is used.
- ulong toLengthUInt64 = (ulong)fromLength * (ulong)fromSize / (ulong)toSize;
- toLength = checked((int)toLengthUInt64);
- }
-
- return new ReadOnlySpan<TTo>(
- ref Unsafe.As<TFrom, TTo>(ref MemoryMarshal.GetReference(span)),
- toLength);
- }
-
- /// <summary>
- /// Create a new span over a portion of a regular managed object. This can be useful
- /// if part of a managed object represents a "fixed array." This is dangerous because the
- /// <paramref name="length"/> is not checked.
- /// </summary>
- /// <param name="reference">A reference to data.</param>
- /// <param name="length">The number of <typeparamref name="T"/> elements the memory contains.</param>
- /// <returns>The lifetime of the returned span will not be validated for safety by span-aware languages.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static Span<T> CreateSpan<T>(ref T reference, int length) => new Span<T>(ref reference, length);
-
- /// <summary>
- /// Create a new read-only span over a portion of a regular managed object. This can be useful
- /// if part of a managed object represents a "fixed array." This is dangerous because the
- /// <paramref name="length"/> is not checked.
- /// </summary>
- /// <param name="reference">A reference to data.</param>
- /// <param name="length">The number of <typeparamref name="T"/> elements the memory contains.</param>
- /// <returns>The lifetime of the returned span will not be validated for safety by span-aware languages.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static ReadOnlySpan<T> CreateReadOnlySpan<T>(ref T reference, int length) => new ReadOnlySpan<T>(ref reference, length);
-
- /// <summary>
- /// Get an array segment from the underlying memory.
- /// If unable to get the array segment, return false with a default array segment.
- /// </summary>
- public static bool TryGetArray<T>(ReadOnlyMemory<T> memory, out ArraySegment<T> segment)
- {
- object? obj = memory.GetObjectStartLength(out int index, out int length);
-
- // As an optimization, we skip the "is string?" check below if typeof(T) is not char,
- // as Memory<T> / ROM<T> can't possibly contain a string instance in this case.
-
- if (obj != null && !(
- (typeof(T) == typeof(char) && obj.GetType() == typeof(string))
-#if FEATURE_UTF8STRING
- || ((typeof(T) == typeof(byte) || typeof(T) == typeof(Char8)) && obj.GetType() == typeof(Utf8String))
-#endif // FEATURE_UTF8STRING
- ))
- {
- if (RuntimeHelpers.ObjectHasComponentSize(obj))
- {
- // The object has a component size, which means it's variable-length, but we already
- // checked above that it's not a string. The only remaining option is that it's a T[]
- // or a U[] which is blittable to a T[] (e.g., int[] and uint[]).
-
- // The array may be prepinned, so remove the high bit from the start index in the line below.
- // The ArraySegment<T> ctor will perform bounds checking on index & length.
-
- segment = new ArraySegment<T>(Unsafe.As<T[]>(obj), index & ReadOnlyMemory<T>.RemoveFlagsBitMask, length);
- return true;
- }
- else
- {
- // The object isn't null, and it's not variable-length, so the only remaining option
- // is MemoryManager<T>. The ArraySegment<T> ctor will perform bounds checking on index & length.
-
- Debug.Assert(obj is MemoryManager<T>);
- if (Unsafe.As<MemoryManager<T>>(obj).TryGetArray(out ArraySegment<T> tempArraySegment))
- {
- segment = new ArraySegment<T>(tempArraySegment.Array!, tempArraySegment.Offset + index, length);
- return true;
- }
- }
- }
-
- // If we got to this point, the object is null, or it's a string, or it's a MemoryManager<T>
- // which isn't backed by an array. We'll quickly homogenize all zero-length Memory<T> instances
- // to an empty array for the purposes of reporting back to our caller.
-
- if (length == 0)
- {
- segment = ArraySegment<T>.Empty;
- return true;
- }
-
- // Otherwise, there's *some* data, but it's not convertible to T[].
-
- segment = default;
- return false;
- }
-
- /// <summary>
- /// Gets an <see cref="MemoryManager{T}"/> from the underlying read-only memory.
- /// If unable to get the <typeparamref name="TManager"/> type, returns false.
- /// </summary>
- /// <typeparam name="T">The element type of the <paramref name="memory" />.</typeparam>
- /// <typeparam name="TManager">The type of <see cref="MemoryManager{T}"/> to try and retrive.</typeparam>
- /// <param name="memory">The memory to get the manager for.</param>
- /// <param name="manager">The returned manager of the <see cref="ReadOnlyMemory{T}"/>.</param>
- /// <returns>A <see cref="bool"/> indicating if it was successful.</returns>
- public static bool TryGetMemoryManager<T, TManager>(ReadOnlyMemory<T> memory, [NotNullWhen(true)] out TManager? manager)
- where TManager : MemoryManager<T>
- {
- TManager? localManager; // Use register for null comparison rather than byref
- manager = localManager = memory.GetObjectStartLength(out _, out _) as TManager;
- return localManager != null;
- }
-
- /// <summary>
- /// Gets an <see cref="MemoryManager{T}"/> and <paramref name="start" />, <paramref name="length" /> from the underlying read-only memory.
- /// If unable to get the <typeparamref name="TManager"/> type, returns false.
- /// </summary>
- /// <typeparam name="T">The element type of the <paramref name="memory" />.</typeparam>
- /// <typeparam name="TManager">The type of <see cref="MemoryManager{T}"/> to try and retrive.</typeparam>
- /// <param name="memory">The memory to get the manager for.</param>
- /// <param name="manager">The returned manager of the <see cref="ReadOnlyMemory{T}"/>.</param>
- /// <param name="start">The offset from the start of the <paramref name="manager" /> that the <paramref name="memory" /> represents.</param>
- /// <param name="length">The length of the <paramref name="manager" /> that the <paramref name="memory" /> represents.</param>
- /// <returns>A <see cref="bool"/> indicating if it was successful.</returns>
- public static bool TryGetMemoryManager<T, TManager>(ReadOnlyMemory<T> memory, [NotNullWhen(true)] out TManager? manager, out int start, out int length)
- where TManager : MemoryManager<T>
- {
- TManager? localManager; // Use register for null comparison rather than byref
- manager = localManager = memory.GetObjectStartLength(out start, out length) as TManager;
-
- Debug.Assert(length >= 0);
-
- if (localManager == null)
- {
- start = default;
- length = default;
- return false;
- }
- return true;
- }
-
- /// <summary>
- /// Creates an <see cref="IEnumerable{T}"/> view of the given <paramref name="memory" /> to allow
- /// the <paramref name="memory" /> to be used in existing APIs that take an <see cref="IEnumerable{T}"/>.
- /// </summary>
- /// <typeparam name="T">The element type of the <paramref name="memory" />.</typeparam>
- /// <param name="memory">The ReadOnlyMemory to view as an <see cref="IEnumerable{T}"/></param>
- /// <returns>An <see cref="IEnumerable{T}"/> view of the given <paramref name="memory" /></returns>
- public static IEnumerable<T> ToEnumerable<T>(ReadOnlyMemory<T> memory)
- {
- for (int i = 0; i < memory.Length; i++)
- yield return memory.Span[i];
- }
-
- /// <summary>Attempts to get the underlying <see cref="string"/> from a <see cref="ReadOnlyMemory{T}"/>.</summary>
- /// <param name="memory">The memory that may be wrapping a <see cref="string"/> object.</param>
- /// <param name="text">The string.</param>
- /// <param name="start">The starting location in <paramref name="text"/>.</param>
- /// <param name="length">The number of items in <paramref name="text"/>.</param>
- /// <returns></returns>
- public static bool TryGetString(ReadOnlyMemory<char> memory, [NotNullWhen(true)] out string? text, out int start, out int length)
- {
- if (memory.GetObjectStartLength(out int offset, out int count) is string s)
- {
- Debug.Assert(offset >= 0);
- Debug.Assert(count >= 0);
- text = s;
- start = offset;
- length = count;
- return true;
- }
- else
- {
- text = null;
- start = 0;
- length = 0;
- return false;
- }
- }
-
- /// <summary>
- /// Reads a structure of type T out of a read-only span of bytes.
- /// </summary>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static T Read<T>(ReadOnlySpan<byte> source)
- where T : struct
- {
- if (RuntimeHelpers.IsReferenceOrContainsReferences<T>())
- {
- ThrowHelper.ThrowInvalidTypeWithPointersNotSupported(typeof(T));
- }
- if (Unsafe.SizeOf<T>() > source.Length)
- {
- ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.length);
- }
- return Unsafe.ReadUnaligned<T>(ref GetReference(source));
- }
-
- /// <summary>
- /// Reads a structure of type T out of a span of bytes.
- /// <returns>If the span is too small to contain the type T, return false.</returns>
- /// </summary>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static bool TryRead<T>(ReadOnlySpan<byte> source, out T value)
- where T : struct
- {
- if (RuntimeHelpers.IsReferenceOrContainsReferences<T>())
- {
- ThrowHelper.ThrowInvalidTypeWithPointersNotSupported(typeof(T));
- }
- if (Unsafe.SizeOf<T>() > (uint)source.Length)
- {
- value = default;
- return false;
- }
- value = Unsafe.ReadUnaligned<T>(ref GetReference(source));
- return true;
- }
-
- /// <summary>
- /// Writes a structure of type T into a span of bytes.
- /// </summary>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static void Write<T>(Span<byte> destination, ref T value)
- where T : struct
- {
- if (RuntimeHelpers.IsReferenceOrContainsReferences<T>())
- {
- ThrowHelper.ThrowInvalidTypeWithPointersNotSupported(typeof(T));
- }
- if ((uint)Unsafe.SizeOf<T>() > (uint)destination.Length)
- {
- ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.length);
- }
- Unsafe.WriteUnaligned<T>(ref GetReference(destination), value);
- }
-
- /// <summary>
- /// Writes a structure of type T into a span of bytes.
- /// <returns>If the span is too small to contain the type T, return false.</returns>
- /// </summary>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static bool TryWrite<T>(Span<byte> destination, ref T value)
- where T : struct
- {
- if (RuntimeHelpers.IsReferenceOrContainsReferences<T>())
- {
- ThrowHelper.ThrowInvalidTypeWithPointersNotSupported(typeof(T));
- }
- if (Unsafe.SizeOf<T>() > (uint)destination.Length)
- {
- return false;
- }
- Unsafe.WriteUnaligned<T>(ref GetReference(destination), value);
- return true;
- }
-
- /// <summary>
- /// Re-interprets a span of bytes as a reference to structure of type T.
- /// The type may not contain pointers or references. This is checked at runtime in order to preserve type safety.
- /// </summary>
- /// <remarks>
- /// Supported only for platforms that support misaligned memory access or when the memory block is aligned by other means.
- /// </remarks>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static ref T AsRef<T>(Span<byte> span)
- where T : struct
- {
- if (RuntimeHelpers.IsReferenceOrContainsReferences<T>())
- {
- ThrowHelper.ThrowInvalidTypeWithPointersNotSupported(typeof(T));
- }
- if (Unsafe.SizeOf<T>() > (uint)span.Length)
- {
- ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.length);
- }
- return ref Unsafe.As<byte, T>(ref GetReference(span));
- }
-
- /// <summary>
- /// Re-interprets a span of bytes as a reference to structure of type T.
- /// The type may not contain pointers or references. This is checked at runtime in order to preserve type safety.
- /// </summary>
- /// <remarks>
- /// Supported only for platforms that support misaligned memory access or when the memory block is aligned by other means.
- /// </remarks>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static ref readonly T AsRef<T>(ReadOnlySpan<byte> span)
- where T : struct
- {
- if (RuntimeHelpers.IsReferenceOrContainsReferences<T>())
- {
- ThrowHelper.ThrowInvalidTypeWithPointersNotSupported(typeof(T));
- }
- if (Unsafe.SizeOf<T>() > (uint)span.Length)
- {
- ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.length);
- }
- return ref Unsafe.As<byte, T>(ref GetReference(span));
- }
-
- /// <summary>
- /// Creates a new memory over the portion of the pre-pinned target array beginning
- /// at 'start' index and ending at 'end' index (exclusive).
- /// </summary>
- /// <param name="array">The pre-pinned target array.</param>
- /// <param name="start">The index at which to begin the memory.</param>
- /// <param name="length">The number of items in the memory.</param>
- /// <remarks>This method should only be called on an array that is already pinned and
- /// that array should not be unpinned while the returned Memory<typeparamref name="T"/> is still in use.
- /// Calling this method on an unpinned array could result in memory corruption.</remarks>
- /// <remarks>Returns default when <paramref name="array"/> is null.</remarks>
- /// <exception cref="System.ArrayTypeMismatchException">Thrown when <paramref name="array"/> is covariant and array's type is not exactly T[].</exception>
- /// <exception cref="System.ArgumentOutOfRangeException">
- /// Thrown when the specified <paramref name="start"/> or end index is not in the range (&lt;0 or &gt;=Length).
- /// </exception>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static Memory<T> CreateFromPinnedArray<T>(T[]? array, int start, int length)
- {
- if (array == null)
- {
- if (start != 0 || length != 0)
- ThrowHelper.ThrowArgumentOutOfRangeException();
- return default;
- }
- if (default(T)! == null && array.GetType() != typeof(T[])) // TODO-NULLABLE: default(T) == null warning (https://github.com/dotnet/roslyn/issues/34757)
- ThrowHelper.ThrowArrayTypeMismatchException();
- if ((uint)start > (uint)array.Length || (uint)length > (uint)(array.Length - start))
- ThrowHelper.ThrowArgumentOutOfRangeException();
-
- // Before using _index, check if _index < 0, then 'and' it with RemoveFlagsBitMask
- return new Memory<T>((object)array, start | (1 << 31), length);
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/NativeCallableAttribute.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/NativeCallableAttribute.cs
deleted file mode 100644
index 5fa60f460f8..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/NativeCallableAttribute.cs
+++ /dev/null
@@ -1,29 +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.
-
-namespace System.Runtime.InteropServices
-{
- /// <summary>
- /// Any method marked with NativeCallableAttribute can be directly called from
- /// native code. The function token can be loaded to a local variable using LDFTN
- /// and passed as a callback to native method.
- /// </summary>
- [AttributeUsage(AttributeTargets.Method)]
- public sealed class NativeCallableAttribute : Attribute
- {
- public NativeCallableAttribute()
- {
- }
-
- /// <summary>
- /// Optional. If omitted, compiler will choose one for you.
- /// </summary>
- public CallingConvention CallingConvention;
-
- /// <summary>
- /// Optional. If omitted, then the method is native callable, but no EAT is emitted.
- /// </summary>
- public string? EntryPoint;
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/NativeLibrary.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/NativeLibrary.cs
deleted file mode 100644
index 9bd65fe57b1..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/NativeLibrary.cs
+++ /dev/null
@@ -1,248 +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.Reflection;
-using System.Runtime.CompilerServices;
-using System.Threading;
-
-namespace System.Runtime.InteropServices
-{
- /// <summary>
- /// A delegate used to resolve native libraries via callback.
- /// </summary>
- /// <param name="libraryName">The native library to resolve</param>
- /// <param name="assembly">The assembly requesting the resolution</param>
- /// <param name="searchPath">
- /// The DllImportSearchPathsAttribute on the PInvoke, if any.
- /// Otherwise, the DllImportSearchPathsAttribute on the assembly, if any.
- /// Otherwise null.
- /// </param>
- /// <returns>The handle for the loaded native library on success, null on failure</returns>
- public delegate IntPtr DllImportResolver(string libraryName,
- Assembly assembly,
- DllImportSearchPath? searchPath);
-
- /// <summary>
- /// APIs for managing Native Libraries
- /// </summary>
- public static partial class NativeLibrary
- {
- /// <summary>
- /// NativeLibrary Loader: Simple API
- /// This method is a wrapper around OS loader, using "default" flags.
- /// </summary>
- /// <param name="libraryPath">The name of the native library to be loaded</param>
- /// <returns>The handle for the loaded native library</returns>
- /// <exception cref="System.ArgumentNullException">If libraryPath is null</exception>
- /// <exception cref="System.DllNotFoundException ">If the library can't be found.</exception>
- /// <exception cref="System.BadImageFormatException">If the library is not valid.</exception>
- public static IntPtr Load(string libraryPath)
- {
- if (libraryPath == null)
- throw new ArgumentNullException(nameof(libraryPath));
-
- return LoadFromPath(libraryPath, throwOnError: true);
- }
-
- /// <summary>
- /// NativeLibrary Loader: Simple API that doesn't throw
- /// </summary>
- /// <param name="libraryPath">The name of the native library to be loaded</param>
- /// <param name="handle">The out-parameter for the loaded native library handle</param>
- /// <returns>True on successful load, false otherwise</returns>
- /// <exception cref="System.ArgumentNullException">If libraryPath is null</exception>
- public static bool TryLoad(string libraryPath, out IntPtr handle)
- {
- if (libraryPath == null)
- throw new ArgumentNullException(nameof(libraryPath));
-
- handle = LoadFromPath(libraryPath, throwOnError: false);
- return handle != IntPtr.Zero;
- }
-
- /// <summary>
- /// NativeLibrary Loader: High-level API
- /// Given a library name, this function searches specific paths based on the
- /// runtime configuration, input parameters, and attributes of the calling assembly.
- /// If DllImportSearchPath parameter is non-null, the flags in this enumeration are used.
- /// Otherwise, the flags specified by the DefaultDllImportSearchPaths attribute on the
- /// calling assembly (if any) are used.
- /// This LoadLibrary() method does not invoke the managed call-backs for native library resolution:
- /// * The per-assembly registered callback
- /// * AssemblyLoadContext.LoadUnmanagedDll()
- /// * AssemblyLoadContext.ResolvingUnmanagedDllEvent
- /// </summary>
- /// <param name="libraryName">The name of the native library to be loaded</param>
- /// <param name="assembly">The assembly loading the native library</param>
- /// <param name="searchPath">The search path</param>
- /// <returns>The handle for the loaded library</returns>
- /// <exception cref="System.ArgumentNullException">If libraryPath or assembly is null</exception>
- /// <exception cref="System.ArgumentException">If assembly is not a RuntimeAssembly</exception>
- /// <exception cref="System.DllNotFoundException ">If the library can't be found.</exception>
- /// <exception cref="System.BadImageFormatException">If the library is not valid.</exception>
- public static IntPtr Load(string libraryName, Assembly assembly, DllImportSearchPath? searchPath)
- {
- if (libraryName == null)
- throw new ArgumentNullException(nameof(libraryName));
- if (assembly == null)
- throw new ArgumentNullException(nameof(assembly));
- if (!assembly.IsRuntimeImplemented())
- throw new ArgumentException(SR.Argument_MustBeRuntimeAssembly);
-
- return LoadLibraryByName(libraryName,
- assembly,
- searchPath,
- throwOnError: true);
- }
-
- /// <summary>
- /// NativeLibrary Loader: High-level API that doesn't throw.
- /// </summary>
- /// <param name="libraryName">The name of the native library to be loaded</param>
- /// <param name="searchPath">The search path</param>
- /// <param name="assembly">The assembly loading the native library</param>
- /// <param name="handle">The out-parameter for the loaded native library handle</param>
- /// <returns>True on successful load, false otherwise</returns>
- /// <exception cref="System.ArgumentNullException">If libraryPath or assembly is null</exception>
- /// <exception cref="System.ArgumentException">If assembly is not a RuntimeAssembly</exception>
- public static bool TryLoad(string libraryName, Assembly assembly, DllImportSearchPath? searchPath, out IntPtr handle)
- {
- if (libraryName == null)
- throw new ArgumentNullException(nameof(libraryName));
- if (assembly == null)
- throw new ArgumentNullException(nameof(assembly));
- if (!assembly.IsRuntimeImplemented())
- throw new ArgumentException(SR.Argument_MustBeRuntimeAssembly);
-
- handle = LoadLibraryByName(libraryName,
- assembly,
- searchPath,
- throwOnError: false);
- return handle != IntPtr.Zero;
- }
-
- /// <summary>
- /// Free a loaded library
- /// Given a library handle, free it.
- /// No action if the input handle is null.
- /// </summary>
- /// <param name="handle">The native library handle to be freed</param>
- public static void Free(IntPtr handle)
- {
- if (handle == IntPtr.Zero)
- return;
- FreeLib(handle);
- }
-
- /// <summary>
- /// Get the address of an exported Symbol
- /// This is a simple wrapper around OS calls, and does not perform any name mangling.
- /// </summary>
- /// <param name="handle">The native library handle</param>
- /// <param name="name">The name of the exported symbol</param>
- /// <returns>The address of the symbol</returns>
- /// <exception cref="System.ArgumentNullException">If handle or name is null</exception>
- /// <exception cref="System.EntryPointNotFoundException">If the symbol is not found</exception>
- public static IntPtr GetExport(IntPtr handle, string name)
- {
- if (handle == IntPtr.Zero)
- throw new ArgumentNullException(nameof(handle));
- if (name == null)
- throw new ArgumentNullException(nameof(name));
-
- return GetSymbol(handle, name, throwOnError: true);
- }
-
- /// <summary>
- /// Get the address of an exported Symbol, but do not throw
- /// </summary>
- /// <param name="handle">The native library handle</param>
- /// <param name="name">The name of the exported symbol</param>
- /// <param name="address"> The out-parameter for the symbol address, if it exists</param>
- /// <returns>True on success, false otherwise</returns>
- /// <exception cref="System.ArgumentNullException">If handle or name is null</exception>
- public static bool TryGetExport(IntPtr handle, string name, out IntPtr address)
- {
- if (handle == IntPtr.Zero)
- throw new ArgumentNullException(nameof(handle));
- if (name == null)
- throw new ArgumentNullException(nameof(name));
-
- address = GetSymbol(handle, name, throwOnError: false);
- return address != IntPtr.Zero;
- }
-
- /// <summary>
- /// Map from assembly to native-library resolver.
- /// Interop specific fields and properties are generally not added to Assembly class.
- /// Therefore, this table uses weak assembly pointers to indirectly achieve
- /// similar behavior.
- /// </summary>
- private static ConditionalWeakTable<Assembly, DllImportResolver>? s_nativeDllResolveMap;
-
- /// <summary>
- /// Set a callback for resolving native library imports from an assembly.
- /// This per-assembly resolver is the first attempt to resolve native library loads
- /// initiated by this assembly.
- ///
- /// Only one resolver can be registered per assembly.
- /// Trying to register a second resolver fails with InvalidOperationException.
- /// </summary>
- /// <param name="assembly">The assembly for which the resolver is registered</param>
- /// <param name="resolver">The resolver callback to register</param>
- /// <exception cref="System.ArgumentNullException">If assembly or resolver is null</exception>
- /// <exception cref="System.ArgumentException">If a resolver is already set for this assembly</exception>
- public static void SetDllImportResolver(Assembly assembly, DllImportResolver resolver)
- {
- if (assembly == null)
- throw new ArgumentNullException(nameof(assembly));
- if (resolver == null)
- throw new ArgumentNullException(nameof(resolver));
- if (!assembly.IsRuntimeImplemented())
- throw new ArgumentException(SR.Argument_MustBeRuntimeAssembly);
-
- if (s_nativeDllResolveMap == null)
- {
- Interlocked.CompareExchange(ref s_nativeDllResolveMap,
- new ConditionalWeakTable<Assembly, DllImportResolver>(), null);
- }
-
- try
- {
- s_nativeDllResolveMap.Add(assembly, resolver);
- }
- catch (ArgumentException)
- {
- // ConditionalWealTable throws ArgumentException if the Key already exists
- throw new InvalidOperationException(SR.InvalidOperation_CannotRegisterSecondResolver);
- }
- }
-
- /// <summary>
- /// The helper function that calls the per-assembly native-library resolver
- /// if one is registered for this assembly.
- /// </summary>
- /// <param name="libraryName">The native library to load</param>
- /// <param name="assembly">The assembly trying load the native library</param>
- /// <param name="hasDllImportSearchPathFlags">If the pInvoke has DefaultDllImportSearchPathAttribute</param>
- /// <param name="dllImportSearchPathFlags">If hasdllImportSearchPathFlags is true, the flags in
- /// DefaultDllImportSearchPathAttribute; meaningless otherwise </param>
- /// <returns>The handle for the loaded library on success. Null on failure.</returns>
- internal static IntPtr LoadLibraryCallbackStub(string libraryName, Assembly assembly,
- bool hasDllImportSearchPathFlags, uint dllImportSearchPathFlags)
- {
- if (s_nativeDllResolveMap == null)
- {
- return IntPtr.Zero;
- }
-
- if (!s_nativeDllResolveMap.TryGetValue(assembly, out DllImportResolver? resolver))
- {
- return IntPtr.Zero;
- }
-
- return resolver(libraryName, assembly, hasDllImportSearchPathFlags ? (DllImportSearchPath?)dllImportSearchPathFlags : null);
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/OptionalAttribute.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/OptionalAttribute.cs
deleted file mode 100644
index 5ac75d7b3e9..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/OptionalAttribute.cs
+++ /dev/null
@@ -1,14 +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.
-
-namespace System.Runtime.InteropServices
-{
- [AttributeUsage(AttributeTargets.Parameter, Inherited = false)]
- public sealed class OptionalAttribute : Attribute
- {
- public OptionalAttribute()
- {
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/OutAttribute.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/OutAttribute.cs
deleted file mode 100644
index 338ceac91e1..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/OutAttribute.cs
+++ /dev/null
@@ -1,14 +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.
-
-namespace System.Runtime.InteropServices
-{
- [AttributeUsage(AttributeTargets.Parameter, Inherited = false)]
- public sealed class OutAttribute : Attribute
- {
- public OutAttribute()
- {
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/PreserveSigAttribute.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/PreserveSigAttribute.cs
deleted file mode 100644
index 464e1abcbeb..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/PreserveSigAttribute.cs
+++ /dev/null
@@ -1,14 +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.
-
-namespace System.Runtime.InteropServices
-{
- [AttributeUsage(AttributeTargets.Method, Inherited = false)]
- public sealed class PreserveSigAttribute : Attribute
- {
- public PreserveSigAttribute()
- {
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ProgIdAttribute.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ProgIdAttribute.cs
deleted file mode 100644
index bc4bd18bb1b..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ProgIdAttribute.cs
+++ /dev/null
@@ -1,17 +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.
-
-namespace System.Runtime.InteropServices
-{
- [AttributeUsage(AttributeTargets.Class, Inherited = false)]
- public sealed class ProgIdAttribute : Attribute
- {
- public ProgIdAttribute(string progId)
- {
- Value = progId;
- }
-
- public string Value { get; }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/SEHException.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/SEHException.cs
deleted file mode 100644
index 0f44e3e99ec..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/SEHException.cs
+++ /dev/null
@@ -1,47 +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.Runtime.Serialization;
-
-namespace System.Runtime.InteropServices
-{
- /// <summary>
- /// Exception for Structured Exception Handler exceptions.
- /// </summary>
- [Serializable]
- [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public class SEHException : ExternalException
- {
- public SEHException()
- {
- HResult = HResults.E_FAIL;
- }
-
- public SEHException(string? message)
- : base(message)
- {
- HResult = HResults.E_FAIL;
- }
-
- public SEHException(string? message, Exception? inner)
- : base(message, inner)
- {
- HResult = HResults.E_FAIL;
- }
-
- protected SEHException(SerializationInfo info, StreamingContext context) : base(info, context)
- {
- }
-
- // Exceptions can be resumable, meaning a filtered exception
- // handler can correct the problem that caused the exception,
- // and the code will continue from the point that threw the
- // exception.
- //
- // Resumable exceptions aren't implemented in this version,
- // but this method exists and always returns false.
- //
- public virtual bool CanResume() => false;
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/SafeArrayRankMismatchException.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/SafeArrayRankMismatchException.cs
deleted file mode 100644
index 1bd3fdd9f3d..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/SafeArrayRankMismatchException.cs
+++ /dev/null
@@ -1,39 +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.Runtime.Serialization;
-
-namespace System.Runtime.InteropServices
-{
- /// <summary>
- /// The exception is thrown when the runtime rank of a safe array is different
- /// than the array rank specified in the metadata.
- /// </summary>
- [Serializable]
- [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public class SafeArrayRankMismatchException : SystemException
- {
- public SafeArrayRankMismatchException()
- : base(SR.Arg_SafeArrayRankMismatchException)
- {
- HResult = HResults.COR_E_SAFEARRAYRANKMISMATCH;
- }
-
- public SafeArrayRankMismatchException(string? message)
- : base(message)
- {
- HResult = HResults.COR_E_SAFEARRAYRANKMISMATCH;
- }
-
- public SafeArrayRankMismatchException(string? message, Exception? inner)
- : base(message, inner)
- {
- HResult = HResults.COR_E_SAFEARRAYRANKMISMATCH;
- }
-
- protected SafeArrayRankMismatchException(SerializationInfo info, StreamingContext context) : base(info, context)
- {
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/SafeArrayTypeMismatchException.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/SafeArrayTypeMismatchException.cs
deleted file mode 100644
index 2cb1fc475ae..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/SafeArrayTypeMismatchException.cs
+++ /dev/null
@@ -1,39 +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.Runtime.Serialization;
-
-namespace System.Runtime.InteropServices
-{
- /// <summary>
- /// The exception is thrown when the runtime type of an array is different
- /// than the safe array sub type specified in the metadata.
- /// </summary>
- [Serializable]
- [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public class SafeArrayTypeMismatchException : SystemException
- {
- public SafeArrayTypeMismatchException()
- : base(SR.Arg_SafeArrayTypeMismatchException)
- {
- HResult = HResults.COR_E_SAFEARRAYTYPEMISMATCH;
- }
-
- public SafeArrayTypeMismatchException(string? message)
- : base(message)
- {
- HResult = HResults.COR_E_SAFEARRAYTYPEMISMATCH;
- }
-
- public SafeArrayTypeMismatchException(string? message, Exception? inner)
- : base(message, inner)
- {
- HResult = HResults.COR_E_SAFEARRAYTYPEMISMATCH;
- }
-
- protected SafeArrayTypeMismatchException(SerializationInfo info, StreamingContext context) : base(info, context)
- {
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/SafeBuffer.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/SafeBuffer.cs
deleted file mode 100644
index 19e021c6b37..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/SafeBuffer.cs
+++ /dev/null
@@ -1,393 +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.
-
-/*============================================================
-**
-** Purpose: Unsafe code that uses pointers should use
-** SafePointer to fix subtle lifetime problems with the
-** underlying resource.
-**
-===========================================================*/
-
-// Design points:
-// *) Avoid handle-recycling problems (including ones triggered via
-// resurrection attacks) for all accesses via pointers. This requires tying
-// together the lifetime of the unmanaged resource with the code that reads
-// from that resource, in a package that uses synchronization to enforce
-// the correct semantics during finalization. We're using SafeHandle's
-// ref count as a gate on whether the pointer can be dereferenced because that
-// controls the lifetime of the resource.
-//
-// *) Keep the penalties for using this class small, both in terms of space
-// and time. Having multiple threads reading from a memory mapped file
-// will already require 2 additional interlocked operations. If we add in
-// a "current position" concept, that requires additional space in memory and
-// synchronization. Since the position in memory is often (but not always)
-// something that can be stored on the stack, we can save some memory by
-// excluding it from this object. However, avoiding the need for
-// synchronization is a more significant win. This design allows multiple
-// threads to read and write memory simultaneously without locks (as long as
-// you don't write to a region of memory that overlaps with what another
-// thread is accessing).
-//
-// *) Space-wise, we use the following memory, including SafeHandle's fields:
-// Object Header MT* handle int bool bool <2 pad bytes> length
-// On 32 bit platforms: 24 bytes. On 64 bit platforms: 40 bytes.
-// (We can safe 4 bytes on x86 only by shrinking SafeHandle)
-//
-// *) Wrapping a SafeHandle would have been a nice solution, but without an
-// ordering between critical finalizable objects, it would have required
-// changes to each SafeHandle subclass to opt in to being usable from a
-// SafeBuffer (or some clever exposure of SafeHandle's state fields and a
-// way of forcing ReleaseHandle to run even after the SafeHandle has been
-// finalized with a ref count > 1). We can use less memory and create fewer
-// objects by simply inserting a SafeBuffer into the class hierarchy.
-//
-// *) In an ideal world, we could get marshaling support for SafeBuffer that
-// would allow us to annotate a P/Invoke declaration, saying this parameter
-// specifies the length of the buffer, and the units of that length are X.
-// P/Invoke would then pass that size parameter to SafeBuffer.
-// [DllImport(...)]
-// static extern SafeMemoryHandle AllocCharBuffer(int numChars);
-// If we could put an attribute on the SafeMemoryHandle saying numChars is
-// the element length, and it must be multiplied by 2 to get to the byte
-// length, we can simplify the usage model for SafeBuffer.
-//
-// *) This class could benefit from a constraint saying T is a value type
-// containing no GC references.
-
-// Implementation notes:
-// *) The Initialize method must be called before you use any instance of
-// a SafeBuffer. To avoid race conditions when storing SafeBuffers in statics,
-// you either need to take a lock when publishing the SafeBuffer, or you
-// need to create a local, initialize the SafeBuffer, then assign to the
-// static variable (perhaps using Interlocked.CompareExchange). Of course,
-// assignments in a static class constructor are under a lock implicitly.
-
-using System.Runtime.CompilerServices;
-using Internal.Runtime.CompilerServices;
-using Microsoft.Win32.SafeHandles;
-
-namespace System.Runtime.InteropServices
-{
- public abstract unsafe class SafeBuffer : SafeHandleZeroOrMinusOneIsInvalid
- {
- // Steal UIntPtr.MaxValue as our uninitialized value.
- private static readonly UIntPtr Uninitialized = (UIntPtr.Size == 4) ?
- ((UIntPtr)uint.MaxValue) : ((UIntPtr)ulong.MaxValue);
-
- private UIntPtr _numBytes;
-
- protected SafeBuffer(bool ownsHandle) : base(ownsHandle)
- {
- _numBytes = Uninitialized;
- }
-
- /// <summary>
- /// Specifies the size of the region of memory, in bytes. Must be
- /// called before using the SafeBuffer.
- /// </summary>
- /// <param name="numBytes">Number of valid bytes in memory.</param>
- [CLSCompliant(false)]
- public void Initialize(ulong numBytes)
- {
- if (IntPtr.Size == 4 && numBytes > uint.MaxValue)
- throw new ArgumentOutOfRangeException(nameof(numBytes), SR.ArgumentOutOfRange_AddressSpace);
-
- if (numBytes >= (ulong)Uninitialized)
- throw new ArgumentOutOfRangeException(nameof(numBytes), SR.ArgumentOutOfRange_UIntPtrMax);
-
- _numBytes = (UIntPtr)numBytes;
- }
-
- /// <summary>
- /// Specifies the size of the region in memory, as the number of
- /// elements in an array. Must be called before using the SafeBuffer.
- /// </summary>
- [CLSCompliant(false)]
- public void Initialize(uint numElements, uint sizeOfEachElement)
- {
- Initialize((ulong)numElements * sizeOfEachElement);
- }
-
- /// <summary>
- /// Specifies the size of the region in memory, as the number of
- /// elements in an array. Must be called before using the SafeBuffer.
- /// </summary>
- [CLSCompliant(false)]
- public void Initialize<T>(uint numElements) where T : struct
- {
- Initialize(numElements, AlignedSizeOf<T>());
- }
-
- // Callers should ensure that they check whether the pointer ref param
- // is null when AcquirePointer returns. If it is not null, they must
- // call ReleasePointer. This method calls DangerousAddRef
- // & exposes the pointer. Unlike Read, it does not alter the "current
- // position" of the pointer. Here's how to use it:
- //
- // byte* pointer = null;
- // try {
- // safeBuffer.AcquirePointer(ref pointer);
- // // Use pointer here, with your own bounds checking
- // }
- // finally {
- // if (pointer != null)
- // safeBuffer.ReleasePointer();
- // }
- //
- // Note: If you cast this byte* to a T*, you have to worry about
- // whether your pointer is aligned. Additionally, you must take
- // responsibility for all bounds checking with this pointer.
- /// <summary>
- /// Obtain the pointer from a SafeBuffer for a block of code,
- /// with the express responsibility for bounds checking and calling
- /// ReleasePointer later to ensure the pointer can be freed later.
- /// This method either completes successfully or throws an exception
- /// and returns with pointer set to null.
- /// </summary>
- /// <param name="pointer">A byte*, passed by reference, to receive
- /// the pointer from within the SafeBuffer. You must set
- /// pointer to null before calling this method.</param>
- [CLSCompliant(false)]
- public void AcquirePointer(ref byte* pointer)
- {
- if (_numBytes == Uninitialized)
- throw NotInitialized();
-
- pointer = null;
-
- bool junk = false;
- DangerousAddRef(ref junk);
- pointer = (byte*)handle;
- }
-
- public void ReleasePointer()
- {
- if (_numBytes == Uninitialized)
- throw NotInitialized();
-
- DangerousRelease();
- }
-
- /// <summary>
- /// Read a value type from memory at the given offset. This is
- /// equivalent to: return *(T*)(bytePtr + byteOffset);
- /// </summary>
- /// <typeparam name="T">The value type to read</typeparam>
- /// <param name="byteOffset">Where to start reading from memory. You
- /// may have to consider alignment.</param>
- /// <returns>An instance of T read from memory.</returns>
- [CLSCompliant(false)]
- public T Read<T>(ulong byteOffset) where T : struct
- {
- if (_numBytes == Uninitialized)
- throw NotInitialized();
-
- uint sizeofT = SizeOf<T>();
- byte* ptr = (byte*)handle + byteOffset;
- SpaceCheck(ptr, sizeofT);
-
- // return *(T*) (_ptr + byteOffset);
- T value = default;
- bool mustCallRelease = false;
- try
- {
- DangerousAddRef(ref mustCallRelease);
-
- fixed (byte* pStructure = &Unsafe.As<T, byte>(ref value))
- Buffer.Memmove(pStructure, ptr, sizeofT);
- }
- finally
- {
- if (mustCallRelease)
- DangerousRelease();
- }
- return value;
- }
-
- [CLSCompliant(false)]
- public void ReadArray<T>(ulong byteOffset, T[] array, int index, int count)
- where T : struct
- {
- if (array == null)
- throw new ArgumentNullException(nameof(array), SR.ArgumentNull_Buffer);
- if (index < 0)
- throw new ArgumentOutOfRangeException(nameof(index), SR.ArgumentOutOfRange_NeedNonNegNum);
- if (count < 0)
- throw new ArgumentOutOfRangeException(nameof(count), SR.ArgumentOutOfRange_NeedNonNegNum);
- if (array.Length - index < count)
- throw new ArgumentException(SR.Argument_InvalidOffLen);
-
- if (_numBytes == Uninitialized)
- throw NotInitialized();
-
- uint sizeofT = SizeOf<T>();
- uint alignedSizeofT = AlignedSizeOf<T>();
- byte* ptr = (byte*)handle + byteOffset;
- SpaceCheck(ptr, checked((ulong)(alignedSizeofT * count)));
-
- bool mustCallRelease = false;
- try
- {
- DangerousAddRef(ref mustCallRelease);
-
- if (count > 0)
- {
- fixed (byte* pStructure = &Unsafe.As<T, byte>(ref array[index]))
- {
- for (int i = 0; i < count; i++)
- Buffer.Memmove(pStructure + sizeofT * i, ptr + alignedSizeofT * i, sizeofT);
- }
- }
- }
- finally
- {
- if (mustCallRelease)
- DangerousRelease();
- }
- }
-
- /// <summary>
- /// Write a value type to memory at the given offset. This is
- /// equivalent to: *(T*)(bytePtr + byteOffset) = value;
- /// </summary>
- /// <typeparam name="T">The type of the value type to write to memory.</typeparam>
- /// <param name="byteOffset">The location in memory to write to. You
- /// may have to consider alignment.</param>
- /// <param name="value">The value type to write to memory.</param>
- [CLSCompliant(false)]
- public void Write<T>(ulong byteOffset, T value) where T : struct
- {
- if (_numBytes == Uninitialized)
- throw NotInitialized();
-
- uint sizeofT = SizeOf<T>();
- byte* ptr = (byte*)handle + byteOffset;
- SpaceCheck(ptr, sizeofT);
-
- // *((T*) (_ptr + byteOffset)) = value;
- bool mustCallRelease = false;
- try
- {
- DangerousAddRef(ref mustCallRelease);
-
- fixed (byte* pStructure = &Unsafe.As<T, byte>(ref value))
- Buffer.Memmove(ptr, pStructure, sizeofT);
- }
- finally
- {
- if (mustCallRelease)
- DangerousRelease();
- }
- }
-
- [CLSCompliant(false)]
- public void WriteArray<T>(ulong byteOffset, T[] array, int index, int count)
- where T : struct
- {
- if (array == null)
- throw new ArgumentNullException(nameof(array), SR.ArgumentNull_Buffer);
- if (index < 0)
- throw new ArgumentOutOfRangeException(nameof(index), SR.ArgumentOutOfRange_NeedNonNegNum);
- if (count < 0)
- throw new ArgumentOutOfRangeException(nameof(count), SR.ArgumentOutOfRange_NeedNonNegNum);
- if (array.Length - index < count)
- throw new ArgumentException(SR.Argument_InvalidOffLen);
-
- if (_numBytes == Uninitialized)
- throw NotInitialized();
-
- uint sizeofT = SizeOf<T>();
- uint alignedSizeofT = AlignedSizeOf<T>();
- byte* ptr = (byte*)handle + byteOffset;
- SpaceCheck(ptr, checked((ulong)(alignedSizeofT * count)));
-
- bool mustCallRelease = false;
- try
- {
- DangerousAddRef(ref mustCallRelease);
-
- if (count > 0)
- {
- {
- fixed (byte* pStructure = &Unsafe.As<T, byte>(ref array[index]))
- {
- for (int i = 0; i < count; i++)
- Buffer.Memmove(ptr + alignedSizeofT * i, pStructure + sizeofT * i, sizeofT);
- }
- }
- }
- }
- finally
- {
- if (mustCallRelease)
- DangerousRelease();
- }
- }
-
- /// <summary>
- /// Returns the number of bytes in the memory region.
- /// </summary>
- [CLSCompliant(false)]
- public ulong ByteLength
- {
- get
- {
- if (_numBytes == Uninitialized)
- throw NotInitialized();
-
- return (ulong)_numBytes;
- }
- }
-
- /* No indexer. The perf would be misleadingly bad. People should use
- * AcquirePointer and ReleasePointer instead. */
-
- private void SpaceCheck(byte* ptr, ulong sizeInBytes)
- {
- if ((ulong)_numBytes < sizeInBytes)
- NotEnoughRoom();
- if ((ulong)(ptr - (byte*)handle) > ((ulong)_numBytes) - sizeInBytes)
- NotEnoughRoom();
- }
-
- private static void NotEnoughRoom()
- {
- throw new ArgumentException(SR.Arg_BufferTooSmall);
- }
-
- private static InvalidOperationException NotInitialized()
- {
- return new InvalidOperationException(SR.InvalidOperation_MustCallInitialize);
- }
-
- /// <summary>
- /// Returns the size that SafeBuffer (and hence, UnmanagedMemoryAccessor) reserves in the unmanaged buffer for each element of an array of T. This is not the same
- /// value that sizeof(T) returns! Since the primary use case is to parse memory mapped files, we cannot change this algorithm as this defines a de-facto serialization format.
- /// Throws if T contains GC references.
- /// </summary>
- internal static uint AlignedSizeOf<T>() where T : struct
- {
- uint size = SizeOf<T>();
- if (size == 1 || size == 2)
- {
- return size;
- }
-
- return (uint)((size + 3) & (~3));
- }
-
- /// <summary>
- /// Returns same value as sizeof(T) but throws if T contains GC references.
- /// </summary>
- internal static uint SizeOf<T>() where T : struct
- {
- if (RuntimeHelpers.IsReferenceOrContainsReferences<T>())
- throw new ArgumentException(SR.Argument_NeedStructWithNoRefs);
-
- return (uint)Unsafe.SizeOf<T>();
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/SafeHandle.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/SafeHandle.cs
deleted file mode 100644
index 053a70f1566..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/SafeHandle.cs
+++ /dev/null
@@ -1,253 +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.Diagnostics;
-using System.Runtime.ConstrainedExecution;
-using System.Threading;
-
-namespace System.Runtime.InteropServices
-{
- // This implementation does not employ critical execution regions and thus cannot
- // reliably guarantee handle release in the face of thread aborts.
-
- /// <summary>Represents a wrapper class for operating system handles.</summary>
- public abstract partial class SafeHandle : CriticalFinalizerObject, IDisposable
- {
- // IMPORTANT:
- // - Do not add or rearrange fields as the EE depends on this layout,
- // as well as on the values of the StateBits flags.
- // - The EE may also perform the same operations using equivalent native
- // code, so this managed code must not assume it is the only code
- // manipulating _state.
-
- /// <summary>Specifies the handle to be wrapped.</summary>
- protected IntPtr handle;
- /// <summary>Combined ref count and closed/disposed flags (so we can atomically modify them).</summary>
- private volatile int _state;
- /// <summary>Whether we can release this handle.</summary>
- private readonly bool _ownsHandle;
- /// <summary>Whether constructor completed.</summary>
- private volatile bool _fullyInitialized;
-
- /// <summary>Bitmasks for the <see cref="_state"/> field.</summary>
- /// <remarks>
- /// The state field ends up looking like this:
- ///
- /// 31 2 1 0
- /// +-----------------------------------------------------------+---+---+
- /// | Ref count | D | C |
- /// +-----------------------------------------------------------+---+---+
- ///
- /// Where D = 1 means a Dispose has been performed and C = 1 means the
- /// underlying handle has been (or will be shortly) released.
- /// </remarks>
- private static class StateBits
- {
- public const int Closed = 0b01;
- public const int Disposed = 0b10;
- public const int RefCount = unchecked(~0b11); // 2 bits reserved for closed/disposed; ref count gets 30 bits
- public const int RefCountOne = 1 << 2;
- }
-
- /// <summary>Creates a SafeHandle class.</summary>
- protected SafeHandle(IntPtr invalidHandleValue, bool ownsHandle)
- {
- handle = invalidHandleValue;
- _state = StateBits.RefCountOne; // Ref count 1 and not closed or disposed.
- _ownsHandle = ownsHandle;
-
- if (!ownsHandle)
- {
- GC.SuppressFinalize(this);
- }
-
- _fullyInitialized = true;
- }
-
-#if !CORERT // CoreRT doesn't correctly support CriticalFinalizerObject
- ~SafeHandle()
- {
- if (_fullyInitialized)
- {
- Dispose(disposing: false);
- }
- }
-#endif
-
- protected void SetHandle(IntPtr handle) => this.handle = handle;
-
- public IntPtr DangerousGetHandle() => handle;
-
- public bool IsClosed => (_state & StateBits.Closed) == StateBits.Closed;
-
- public abstract bool IsInvalid { get; }
-
- public void Close() => Dispose();
-
- public void Dispose()
- {
- Dispose(disposing: true);
- GC.SuppressFinalize(this);
- }
-
- protected virtual void Dispose(bool disposing)
- {
- Debug.Assert(_fullyInitialized);
- InternalRelease(disposeOrFinalizeOperation: true);
- }
-
- public void SetHandleAsInvalid()
- {
- Debug.Assert(_fullyInitialized);
-
- // Attempt to set closed state (low order bit of the _state field).
- // Might have to attempt these repeatedly, if the operation suffers
- // interference from an AddRef or Release.
- int oldState, newState;
- do
- {
- oldState = _state;
- newState = oldState | StateBits.Closed;
- } while (Interlocked.CompareExchange(ref _state, newState, oldState) != oldState);
-
- GC.SuppressFinalize(this);
- }
-
- protected abstract bool ReleaseHandle();
-
- public void DangerousAddRef(ref bool success)
- {
- // To prevent handle recycling security attacks we must enforce the
- // following invariant: we cannot successfully AddRef a handle on which
- // we've committed to the process of releasing.
-
- // We ensure this by never AddRef'ing a handle that is marked closed and
- // never marking a handle as closed while the ref count is non-zero. For
- // this to be thread safe we must perform inspection/updates of the two
- // values as a single atomic operation. We achieve this by storing them both
- // in a single aligned int and modifying the entire state via interlocked
- // compare exchange operations.
-
- // Additionally we have to deal with the problem of the Dispose operation.
- // We must assume that this operation is directly exposed to untrusted
- // callers and that malicious callers will try and use what is basically a
- // Release call to decrement the ref count to zero and free the handle while
- // it's still in use (the other way a handle recycling attack can be
- // mounted). We combat this by allowing only one Dispose to operate against
- // a given safe handle (which balances the creation operation given that
- // Dispose suppresses finalization). We record the fact that a Dispose has
- // been requested in the same state field as the ref count and closed state.
-
- Debug.Assert(_fullyInitialized);
-
- // Might have to perform the following steps multiple times due to
- // interference from other AddRef's and Release's.
- int oldState, newState;
- do
- {
- // First step is to read the current handle state. We use this as a
- // basis to decide whether an AddRef is legal and, if so, to propose an
- // update predicated on the initial state (a conditional write).
- // Check for closed state.
- oldState = _state;
- if ((oldState & StateBits.Closed) != 0)
- {
- throw new ObjectDisposedException(nameof(SafeHandle), SR.ObjectDisposed_SafeHandleClosed);
- }
-
- // Not closed, let's propose an update (to the ref count, just add
- // StateBits.RefCountOne to the state to effectively add 1 to the ref count).
- // Continue doing this until the update succeeds (because nobody
- // modifies the state field between the read and write operations) or
- // the state moves to closed.
- newState = oldState + StateBits.RefCountOne;
- } while (Interlocked.CompareExchange(ref _state, newState, oldState) != oldState);
-
- // If we got here we managed to update the ref count while the state
- // remained non closed. So we're done.
- success = true;
- }
-
- public void DangerousRelease() => InternalRelease(disposeOrFinalizeOperation: false);
-
- private void InternalRelease(bool disposeOrFinalizeOperation)
- {
- Debug.Assert(_fullyInitialized || disposeOrFinalizeOperation);
-
- // See AddRef above for the design of the synchronization here. Basically we
- // will try to decrement the current ref count and, if that would take us to
- // zero refs, set the closed state on the handle as well.
- bool performRelease = false;
-
- // Might have to perform the following steps multiple times due to
- // interference from other AddRef's and Release's.
- int oldState, newState;
- do
- {
- // First step is to read the current handle state. We use this cached
- // value to predicate any modification we might decide to make to the
- // state).
- oldState = _state;
-
- // If this is a Dispose operation we have additional requirements (to
- // ensure that Dispose happens at most once as the comments in AddRef
- // detail). We must check that the dispose bit is not set in the old
- // state and, in the case of successful state update, leave the disposed
- // bit set. Silently do nothing if Dispose has already been called.
- if (disposeOrFinalizeOperation && ((oldState & StateBits.Disposed) != 0))
- {
- return;
- }
-
- // We should never see a ref count of zero (that would imply we have
- // unbalanced AddRef and Releases). (We might see a closed state before
- // hitting zero though -- that can happen if SetHandleAsInvalid is
- // used).
- if ((oldState & StateBits.RefCount) == 0)
- {
- throw new ObjectDisposedException(nameof(SafeHandle), SR.ObjectDisposed_SafeHandleClosed);
- }
-
- // If we're proposing a decrement to zero and the handle is not closed
- // and we own the handle then we need to release the handle upon a
- // successful state update. If so we need to check whether the handle is
- // currently invalid by asking the SafeHandle subclass. We must do this before
- // transitioning the handle to closed, however, since setting the closed
- // state will cause IsInvalid to always return true.
- performRelease = ((oldState & (StateBits.RefCount | StateBits.Closed)) == StateBits.RefCountOne) &&
- _ownsHandle &&
- !IsInvalid;
-
- // Attempt the update to the new state, fail and retry if the initial
- // state has been modified in the meantime. Decrement the ref count by
- // substracting StateBits.RefCountOne from the state then OR in the bits for
- // Dispose (if that's the reason for the Release) and closed (if the
- // initial ref count was 1).
- newState = oldState - StateBits.RefCountOne;
- if ((oldState & StateBits.RefCount) == StateBits.RefCountOne)
- {
- newState |= StateBits.Closed;
- }
- if (disposeOrFinalizeOperation)
- {
- newState |= StateBits.Disposed;
- }
- } while (Interlocked.CompareExchange(ref _state, newState, oldState) != oldState);
-
- // If we get here we successfully decremented the ref count. Additionally we
- // may have decremented it to zero and set the handle state as closed. In
- // this case (providng we own the handle) we will call the ReleaseHandle
- // method on the SafeHandle subclass.
- if (performRelease)
- {
- // Save last error from P/Invoke in case the implementation of ReleaseHandle
- // trashes it (important because this ReleaseHandle could occur implicitly
- // as part of unmarshaling another P/Invoke).
- int lastError = Marshal.GetLastWin32Error();
- ReleaseHandle();
- Marshal.SetLastWin32Error(lastError);
- }
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/StructLayoutAttribute.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/StructLayoutAttribute.cs
deleted file mode 100644
index c4cce9956e1..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/StructLayoutAttribute.cs
+++ /dev/null
@@ -1,26 +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.
-
-namespace System.Runtime.InteropServices
-{
- [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct, Inherited = false)]
- public sealed class StructLayoutAttribute : Attribute
- {
- public StructLayoutAttribute(LayoutKind layoutKind)
- {
- Value = layoutKind;
- }
-
- public StructLayoutAttribute(short layoutKind)
- {
- Value = (LayoutKind)layoutKind;
- }
-
- public LayoutKind Value { get; }
-
- public int Pack;
- public int Size;
- public CharSet CharSet;
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/SuppressGCTransitionAttribute.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/SuppressGCTransitionAttribute.cs
deleted file mode 100644
index 21f1695192c..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/SuppressGCTransitionAttribute.cs
+++ /dev/null
@@ -1,65 +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.
-
-namespace System.Runtime.InteropServices
-{
- /// <summary>
- /// An attribute used to indicate a GC transition should be skipped when making an unmanaged function call.
- /// </summary>
- /// <example>
- /// Example of a valid use case. The Win32 `GetTickCount()` function is a small performance related function
- /// that reads some global memory and returns the value. In this case, the GC transition overhead is significantly
- /// more than the memory read.
- /// <code>
- /// using System;
- /// using System.Runtime.InteropServices;
- /// class Program
- /// {
- /// [DllImport("Kernel32")]
- /// [SuppressGCTransition]
- /// static extern int GetTickCount();
- /// static void Main()
- /// {
- /// Console.WriteLine($"{GetTickCount()}");
- /// }
- /// }
- /// </code>
- /// </example>
- /// <remarks>
- /// This attribute is ignored if applied to a method without the <see cref="System.Runtime.InteropServices.DllImportAttribute"/>.
- ///
- /// Forgoing this transition can yield benefits when the cost of the transition is more than the execution time
- /// of the unmanaged function. However, avoiding this transition removes some of the guarantees the runtime
- /// provides through a normal P/Invoke. When exiting the managed runtime to enter an unmanaged function the
- /// GC must transition from Cooperative mode into Preemptive mode. Full details on these modes can be found at
- /// https://github.com/dotnet/coreclr/blob/master/Documentation/coding-guidelines/clr-code-guide.md#2.1.8.
- /// Suppressing the GC transition is an advanced scenario and should not be done without fully understanding
- /// potential consequences.
- ///
- /// One of these consequences is an impact to Mixed-mode debugging (https://docs.microsoft.com/visualstudio/debugger/how-to-debug-in-mixed-mode).
- /// During Mixed-mode debugging, it is not possible to step into or set breakpoints in a P/Invoke that
- /// has been marked with this attribute. A workaround is to switch to native debugging and set a breakpoint in the native function.
- /// In general, usage of this attribute is not recommended if debugging the P/Invoke is important, for example
- /// stepping through the native code or diagnosing an exception thrown from the native code.
- ///
- /// The P/Invoke method that this attribute is applied to must have all of the following properties:
- /// * Native function always executes for a trivial amount of time (less than 1 microsecond).
- /// * Native function does not perform a blocking syscall (e.g. any type of I/O).
- /// * Native function does not call back into the runtime (e.g. Reverse P/Invoke).
- /// * Native function does not throw exceptions.
- /// * Native function does not manipulate locks or other concurrency primitives.
- ///
- /// Consequences of invalid uses of this attribute:
- /// * GC starvation.
- /// * Immediate runtime termination.
- /// * Data corruption.
- /// </remarks>
- [AttributeUsage(AttributeTargets.Method, Inherited = false)]
- public sealed class SuppressGCTransitionAttribute : Attribute
- {
- public SuppressGCTransitionAttribute()
- {
- }
- }
-} \ No newline at end of file
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/TypeIdentifierAttribute.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/TypeIdentifierAttribute.cs
deleted file mode 100644
index 73069f36549..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/TypeIdentifierAttribute.cs
+++ /dev/null
@@ -1,20 +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.
-
-namespace System.Runtime.InteropServices
-{
- [AttributeUsage(AttributeTargets.Interface | AttributeTargets.Enum | AttributeTargets.Struct | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
- public sealed class TypeIdentifierAttribute : Attribute
- {
- public TypeIdentifierAttribute() { }
- public TypeIdentifierAttribute(string? scope, string? identifier)
- {
- Scope = scope;
- Identifier = identifier;
- }
-
- public string? Scope { get; }
- public string? Identifier { get; }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/UnknownWrapper.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/UnknownWrapper.cs
deleted file mode 100644
index 3581ca93a51..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/UnknownWrapper.cs
+++ /dev/null
@@ -1,17 +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.
-
-namespace System.Runtime.InteropServices
-{
- // Wrapper that is converted to a variant with VT_UNKNOWN.
- public sealed class UnknownWrapper
- {
- public UnknownWrapper(object? obj)
- {
- WrappedObject = obj;
- }
-
- public object? WrappedObject { get; }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/UnmanagedFunctionPointerAttribute.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/UnmanagedFunctionPointerAttribute.cs
deleted file mode 100644
index c4f96903ee2..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/UnmanagedFunctionPointerAttribute.cs
+++ /dev/null
@@ -1,27 +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.
-
-namespace System.Runtime.InteropServices
-{
- [AttributeUsage(AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
- public sealed class UnmanagedFunctionPointerAttribute : Attribute
- {
- public UnmanagedFunctionPointerAttribute()
- {
- CallingConvention = CallingConvention.Winapi;
- }
-
- public UnmanagedFunctionPointerAttribute(CallingConvention callingConvention)
- {
- CallingConvention = callingConvention;
- }
-
- public CallingConvention CallingConvention { get; }
-
- public bool BestFitMapping;
- public bool SetLastError;
- public bool ThrowOnUnmappableChar;
- public CharSet CharSet;
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/UnmanagedType.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/UnmanagedType.cs
deleted file mode 100644
index 4deca7fe0cf..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/UnmanagedType.cs
+++ /dev/null
@@ -1,48 +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.
-
-namespace System.Runtime.InteropServices
-{
- public enum UnmanagedType
- {
- Bool = 0x2, // 4 byte boolean value (true != 0, false == 0)
- I1 = 0x3, // 1 byte signed value
- U1 = 0x4, // 1 byte unsigned value
- I2 = 0x5, // 2 byte signed value
- U2 = 0x6, // 2 byte unsigned value
- I4 = 0x7, // 4 byte signed value
- U4 = 0x8, // 4 byte unsigned value
- I8 = 0x9, // 8 byte signed value
- U8 = 0xa, // 8 byte unsigned value
- R4 = 0xb, // 4 byte floating point
- R8 = 0xc, // 8 byte floating point
- Currency = 0xf, // A currency
- BStr = 0x13, // OLE Unicode BSTR
- LPStr = 0x14, // Ptr to SBCS string
- LPWStr = 0x15, // Ptr to Unicode string
- LPTStr = 0x16, // Ptr to OS preferred (SBCS/Unicode) string
- ByValTStr = 0x17, // OS preferred (SBCS/Unicode) inline string (only valid in structs)
- IUnknown = 0x19, // COM IUnknown pointer.
- IDispatch = 0x1a, // COM IDispatch pointer
- Struct = 0x1b, // Structure
- Interface = 0x1c, // COM interface
- SafeArray = 0x1d, // OLE SafeArray
- ByValArray = 0x1e, // Array of fixed size (only valid in structs)
- SysInt = 0x1f, // Hardware natural sized signed integer
- SysUInt = 0x20,
- VBByRefStr = 0x22,
- AnsiBStr = 0x23, // OLE BSTR containing SBCS characters
- TBStr = 0x24, // Ptr to OS preferred (SBCS/Unicode) BSTR
- VariantBool = 0x25, // OLE defined BOOLEAN (2 bytes, true == -1, false == 0)
- FunctionPtr = 0x26, // Function pointer
- AsAny = 0x28, // Paired with Object type and does runtime marshalling determination
- LPArray = 0x2a, // C style array
- LPStruct = 0x2b, // Pointer to a structure
- CustomMarshaler = 0x2c,
- Error = 0x2d,
- IInspectable = 0x2e,
- HString = 0x2f, // Windows Runtime HSTRING
- LPUTF8Str = 0x30, // UTF8 string
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/VarEnum.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/VarEnum.cs
deleted file mode 100644
index 495aeca6d1f..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/VarEnum.cs
+++ /dev/null
@@ -1,54 +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.
-
-namespace System.Runtime.InteropServices
-{
- public enum VarEnum
- {
- VT_EMPTY = 0,
- VT_NULL = 1,
- VT_I2 = 2,
- VT_I4 = 3,
- VT_R4 = 4,
- VT_R8 = 5,
- VT_CY = 6,
- VT_DATE = 7,
- VT_BSTR = 8,
- VT_DISPATCH = 9,
- VT_ERROR = 10,
- VT_BOOL = 11,
- VT_VARIANT = 12,
- VT_UNKNOWN = 13,
- VT_DECIMAL = 14,
- VT_I1 = 16,
- VT_UI1 = 17,
- VT_UI2 = 18,
- VT_UI4 = 19,
- VT_I8 = 20,
- VT_UI8 = 21,
- VT_INT = 22,
- VT_UINT = 23,
- VT_VOID = 24,
- VT_HRESULT = 25,
- VT_PTR = 26,
- VT_SAFEARRAY = 27,
- VT_CARRAY = 28,
- VT_USERDEFINED = 29,
- VT_LPSTR = 30,
- VT_LPWSTR = 31,
- VT_RECORD = 36,
- VT_FILETIME = 64,
- VT_BLOB = 65,
- VT_STREAM = 66,
- VT_STORAGE = 67,
- VT_STREAMED_OBJECT = 68,
- VT_STORED_OBJECT = 69,
- VT_BLOB_OBJECT = 70,
- VT_CF = 71,
- VT_CLSID = 72,
- VT_VECTOR = 0x1000,
- VT_ARRAY = 0x2000,
- VT_BYREF = 0x4000
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/VariantWrapper.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/VariantWrapper.cs
deleted file mode 100644
index 74054d5dc9e..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/VariantWrapper.cs
+++ /dev/null
@@ -1,17 +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.
-
-namespace System.Runtime.InteropServices
-{
- // Wrapper that is converted to a variant with VT_BYREF | VT_VARIANT.
- public sealed class VariantWrapper
- {
- public VariantWrapper(object? obj)
- {
- WrappedObject = obj;
- }
-
- public object? WrappedObject { get; }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/WindowsRuntime/EventRegistrationToken.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/WindowsRuntime/EventRegistrationToken.cs
deleted file mode 100644
index 15b4a8302e1..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/WindowsRuntime/EventRegistrationToken.cs
+++ /dev/null
@@ -1,34 +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.
-
-namespace System.Runtime.InteropServices.WindowsRuntime
-{
- // Event registration tokens are 64 bit opaque structures returned from WinRT style event adders, in order
- // to signify a registration of a particular delegate to an event. The token's only real use is to
- // unregister the same delgate from the event at a later time.
- public struct EventRegistrationToken : IEquatable<EventRegistrationToken>
- {
- private readonly ulong _value;
-
- [CLSCompliant(false)]
- public EventRegistrationToken(ulong value) => _value = value;
-
- [CLSCompliant(false)]
- public ulong Value => _value;
-
- public static bool operator ==(EventRegistrationToken left, EventRegistrationToken right) =>
- left.Equals(right);
-
- public static bool operator !=(EventRegistrationToken left, EventRegistrationToken right) =>
- !left.Equals(right);
-
- public override bool Equals(object? obj) =>
- obj is EventRegistrationToken &&
- ((EventRegistrationToken)obj)._value == _value;
-
- public override int GetHashCode() => _value.GetHashCode();
-
- public bool Equals(EventRegistrationToken other) => other._value == _value;
- }
-}