summaryrefslogtreecommitdiff
path: root/src/mscorlib/src/System/Runtime/InteropServices/Marshal.cs
diff options
context:
space:
mode:
authorJiyoung Yun <jy910.yun@samsung.com>2016-12-27 16:46:08 +0900
committerJiyoung Yun <jy910.yun@samsung.com>2016-12-27 16:46:08 +0900
commitdb20f3f1bb8595633a7e16c8900fd401a453a6b5 (patch)
treee5435159cd1bf0519276363a6fe1663d1721bed3 /src/mscorlib/src/System/Runtime/InteropServices/Marshal.cs
parent4b4aad7217d3292650e77eec2cf4c198ea9c3b4b (diff)
downloadcoreclr-db20f3f1bb8595633a7e16c8900fd401a453a6b5.tar.gz
coreclr-db20f3f1bb8595633a7e16c8900fd401a453a6b5.tar.bz2
coreclr-db20f3f1bb8595633a7e16c8900fd401a453a6b5.zip
Imported Upstream version 1.0.0.9127upstream/1.0.0.9127
Diffstat (limited to 'src/mscorlib/src/System/Runtime/InteropServices/Marshal.cs')
-rw-r--r--src/mscorlib/src/System/Runtime/InteropServices/Marshal.cs622
1 files changed, 96 insertions, 526 deletions
diff --git a/src/mscorlib/src/System/Runtime/InteropServices/Marshal.cs b/src/mscorlib/src/System/Runtime/InteropServices/Marshal.cs
index 86e88306f0..3a79650bd9 100644
--- a/src/mscorlib/src/System/Runtime/InteropServices/Marshal.cs
+++ b/src/mscorlib/src/System/Runtime/InteropServices/Marshal.cs
@@ -29,6 +29,7 @@ namespace System.Runtime.InteropServices
using System.Runtime.Versioning;
using Win32Native = Microsoft.Win32.Win32Native;
using Microsoft.Win32.SafeHandles;
+ using System.Diagnostics;
using System.Diagnostics.Contracts;
using System.Runtime.InteropServices.ComTypes;
@@ -45,9 +46,6 @@ namespace System.Runtime.InteropServices
// declaration on the class.
//========================================================================
- #if FEATURE_CORECLR
- [System.Security.SecurityCritical] // auto-generated
- #endif
public static partial class Marshal
{
//====================================================================
@@ -117,7 +115,6 @@ namespace System.Runtime.InteropServices
[MethodImplAttribute(MethodImplOptions.InternalCall)]
private static extern int GetSystemMaxDBCSCharSize();
- [System.Security.SecurityCritical] // auto-generated_required
unsafe public static String PtrToStringAnsi(IntPtr ptr)
{
if (IntPtr.Zero == ptr) {
@@ -137,36 +134,32 @@ namespace System.Runtime.InteropServices
}
}
- [System.Security.SecurityCritical] // auto-generated_required
unsafe public static String PtrToStringAnsi(IntPtr ptr, int len)
{
if (ptr == IntPtr.Zero)
- throw new ArgumentNullException("ptr");
+ throw new ArgumentNullException(nameof(ptr));
if (len < 0)
- throw new ArgumentException("len");
+ throw new ArgumentException(null, nameof(len));
return new String((sbyte *)ptr, 0, len);
}
- [System.Security.SecurityCritical] // auto-generated_required
unsafe public static String PtrToStringUni(IntPtr ptr, int len)
{
if (ptr == IntPtr.Zero)
- throw new ArgumentNullException("ptr");
+ throw new ArgumentNullException(nameof(ptr));
if (len < 0)
- throw new ArgumentException("len");
+ throw new ArgumentException(null, nameof(len));
return new String((char *)ptr, 0, len);
}
- [System.Security.SecurityCritical] // auto-generated_required
public static String PtrToStringAuto(IntPtr ptr, int len)
{
// Ansi platforms are no longer supported
return PtrToStringUni(ptr, len);
}
- [System.Security.SecurityCritical] // auto-generated_required
unsafe public static String PtrToStringUni(IntPtr ptr)
{
if (IntPtr.Zero == ptr) {
@@ -180,26 +173,23 @@ namespace System.Runtime.InteropServices
}
}
- [System.Security.SecurityCritical] // auto-generated_required
public static String PtrToStringAuto(IntPtr ptr)
{
// Ansi platforms are no longer supported
return PtrToStringUni(ptr);
}
- [System.Security.SecurityCritical] // auto-generated_required
unsafe public static String PtrToStringUTF8(IntPtr ptr)
{
int nbBytes = System.StubHelpers.StubHelpers.strlen((sbyte*)ptr.ToPointer());
return PtrToStringUTF8(ptr, nbBytes);
}
- [System.Security.SecurityCritical] // auto-generated_required
unsafe public static String PtrToStringUTF8(IntPtr ptr,int byteLen)
{
if (byteLen < 0)
{
- throw new ArgumentException("byteLen");
+ throw new ArgumentException(null, nameof(byteLen));
}
else if (IntPtr.Zero == ptr)
{
@@ -227,7 +217,7 @@ namespace System.Runtime.InteropServices
public static int SizeOf(Object structure)
{
if (structure == null)
- throw new ArgumentNullException("structure");
+ throw new ArgumentNullException(nameof(structure));
// we never had a check for generics here
Contract.EndContractBlock();
@@ -243,11 +233,11 @@ namespace System.Runtime.InteropServices
public static int SizeOf(Type t)
{
if (t == null)
- throw new ArgumentNullException("t");
+ throw new ArgumentNullException(nameof(t));
if (!(t is RuntimeType))
- throw new ArgumentException(Environment.GetResourceString("Argument_MustBeRuntimeType"), "t");
+ throw new ArgumentException(Environment.GetResourceString("Argument_MustBeRuntimeType"), nameof(t));
if (t.IsGenericType)
- throw new ArgumentException(Environment.GetResourceString("Argument_NeedNonGenericType"), "t");
+ throw new ArgumentException(Environment.GetResourceString("Argument_NeedNonGenericType"), nameof(t));
Contract.EndContractBlock();
return SizeOfHelper(t, true);
@@ -290,9 +280,6 @@ namespace System.Runtime.InteropServices
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
private static extern uint AlignedSizeOfType(Type type);
-#if !FEATURE_CORECLR // Marshal is critical in CoreCLR, so SafeCritical members trigger Annotator violations
- [System.Security.SecuritySafeCritical]
-#endif // !FEATURE_CORECLR
[MethodImplAttribute(MethodImplOptions.InternalCall)]
internal static extern int SizeOfHelper(Type t, bool throwIfNotMarshalable);
@@ -302,15 +289,15 @@ namespace System.Runtime.InteropServices
public static IntPtr OffsetOf(Type t, String fieldName)
{
if (t == null)
- throw new ArgumentNullException("t");
+ throw new ArgumentNullException(nameof(t));
Contract.EndContractBlock();
FieldInfo f = t.GetField(fieldName, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
if (f == null)
- throw new ArgumentException(Environment.GetResourceString("Argument_OffsetOfFieldNotFound", t.FullName), "fieldName");
+ throw new ArgumentException(Environment.GetResourceString("Argument_OffsetOfFieldNotFound", t.FullName), nameof(fieldName));
RtFieldInfo rtField = f as RtFieldInfo;
if (rtField == null)
- throw new ArgumentException(Environment.GetResourceString("Argument_MustBeRuntimeFieldInfo"), "fieldName");
+ throw new ArgumentException(Environment.GetResourceString("Argument_MustBeRuntimeFieldInfo"), nameof(fieldName));
return OffsetOfHelper(rtField);
}
@@ -330,11 +317,9 @@ namespace System.Runtime.InteropServices
// an array that is not pinned or in the fixed heap can cause
// unexpected results !
//====================================================================
- [System.Security.SecurityCritical] // auto-generated_required
[MethodImplAttribute(MethodImplOptions.InternalCall)]
public static extern IntPtr UnsafeAddrOfPinnedArrayElement(Array arr, int index);
- [System.Security.SecurityCritical]
public static IntPtr UnsafeAddrOfPinnedArrayElement<T>(T[] arr, int index)
{
return UnsafeAddrOfPinnedArrayElement((Array)arr, index);
@@ -343,42 +328,34 @@ namespace System.Runtime.InteropServices
//====================================================================
// Copy blocks from CLR arrays to native memory.
//====================================================================
- [System.Security.SecurityCritical] // auto-generated_required
public static void Copy(int[] source, int startIndex, IntPtr destination, int length)
{
CopyToNative(source, startIndex, destination, length);
}
- [System.Security.SecurityCritical] // auto-generated_required
public static void Copy(char[] source, int startIndex, IntPtr destination, int length)
{
CopyToNative(source, startIndex, destination, length);
}
- [System.Security.SecurityCritical] // auto-generated_required
public static void Copy(short[] source, int startIndex, IntPtr destination, int length)
{
CopyToNative(source, startIndex, destination, length);
}
- [System.Security.SecurityCritical] // auto-generated_required
public static void Copy(long[] source, int startIndex, IntPtr destination, int length)
{
CopyToNative(source, startIndex, destination, length);
}
- [System.Security.SecurityCritical] // auto-generated_required
public static void Copy(float[] source, int startIndex, IntPtr destination, int length)
{
CopyToNative(source, startIndex, destination, length);
}
- [System.Security.SecurityCritical] // auto-generated_required
public static void Copy(double[] source, int startIndex, IntPtr destination, int length)
{
CopyToNative(source, startIndex, destination, length);
}
- [System.Security.SecurityCritical] // auto-generated_required
public static void Copy(byte[] source, int startIndex, IntPtr destination, int length)
{
CopyToNative(source, startIndex, destination, length);
}
- [System.Security.SecurityCritical] // auto-generated_required
public static void Copy(IntPtr[] source, int startIndex, IntPtr destination, int length)
{
CopyToNative(source, startIndex, destination, length);
@@ -389,42 +366,34 @@ namespace System.Runtime.InteropServices
//====================================================================
// Copy blocks from native memory to CLR arrays
//====================================================================
- [System.Security.SecurityCritical] // auto-generated_required
public static void Copy(IntPtr source, int[] destination, int startIndex, int length)
{
CopyToManaged(source, destination, startIndex, length);
}
- [System.Security.SecurityCritical] // auto-generated_required
public static void Copy(IntPtr source, char[] destination, int startIndex, int length)
{
CopyToManaged(source, destination, startIndex, length);
}
- [System.Security.SecurityCritical] // auto-generated_required
public static void Copy(IntPtr source, short[] destination, int startIndex, int length)
{
CopyToManaged(source, destination, startIndex, length);
}
- [System.Security.SecurityCritical] // auto-generated_required
public static void Copy(IntPtr source, long[] destination, int startIndex, int length)
{
CopyToManaged(source, destination, startIndex, length);
}
- [System.Security.SecurityCritical] // auto-generated_required
public static void Copy(IntPtr source, float[] destination, int startIndex, int length)
{
CopyToManaged(source, destination, startIndex, length);
}
- [System.Security.SecurityCritical] // auto-generated_required
public static void Copy(IntPtr source, double[] destination, int startIndex, int length)
{
CopyToManaged(source, destination, startIndex, length);
}
- [System.Security.SecurityCritical] // auto-generated_required
public static void Copy(IntPtr source, byte[] destination, int startIndex, int length)
{
CopyToManaged(source, destination, startIndex, length);
}
- [System.Security.SecurityCritical] // auto-generated_required
public static void Copy(IntPtr source, IntPtr[] destination, int startIndex, int length)
{
CopyToManaged(source, destination, startIndex, length);
@@ -435,19 +404,11 @@ namespace System.Runtime.InteropServices
//====================================================================
// Read from memory
//====================================================================
- [System.Security.SecurityCritical] // auto-generated
-#if !FEATURE_CORECLR
- [DllImport(Win32Native.SHIM, EntryPoint="ND_RU1")]
- [SuppressUnmanagedCodeSecurity]
- public static extern byte ReadByte([MarshalAs(UnmanagedType.AsAny), In] Object ptr, int ofs);
-#else
public static byte ReadByte([MarshalAs(UnmanagedType.AsAny), In] Object ptr, int ofs)
{
throw new PlatformNotSupportedException();
- }
-#endif // !FEATURE_CORECLR
+ }
- [System.Security.SecurityCritical] // auto-generated_required
public static unsafe byte ReadByte(IntPtr ptr, int ofs)
{
try
@@ -462,25 +423,16 @@ namespace System.Runtime.InteropServices
}
}
- [System.Security.SecurityCritical] // auto-generated_required
public static byte ReadByte(IntPtr ptr)
{
return ReadByte(ptr,0);
}
-
- [System.Security.SecurityCritical] // auto-generated
-#if !FEATURE_CORECLR
- [DllImport(Win32Native.SHIM, EntryPoint="ND_RI2")]
- [SuppressUnmanagedCodeSecurity]
- public static extern short ReadInt16([MarshalAs(UnmanagedType.AsAny),In] Object ptr, int ofs);
-#else
+
public static short ReadInt16([MarshalAs(UnmanagedType.AsAny),In] Object ptr, int ofs)
{
throw new PlatformNotSupportedException();
- }
-#endif // !FEATURE_CORECLR
+ }
- [System.Security.SecurityCritical] // auto-generated_required
public static unsafe short ReadInt16(IntPtr ptr, int ofs)
{
try
@@ -508,25 +460,16 @@ namespace System.Runtime.InteropServices
}
}
- [System.Security.SecurityCritical] // auto-generated_required
public static short ReadInt16(IntPtr ptr)
{
return ReadInt16(ptr, 0);
}
-
- [System.Security.SecurityCritical] // auto-generated
-#if !FEATURE_CORECLR
- [DllImport(Win32Native.SHIM, EntryPoint="ND_RI4"), ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
- [SuppressUnmanagedCodeSecurity]
- public static extern int ReadInt32([MarshalAs(UnmanagedType.AsAny),In] Object ptr, int ofs);
-#else
+
public static int ReadInt32([MarshalAs(UnmanagedType.AsAny),In] Object ptr, int ofs)
{
throw new PlatformNotSupportedException();
}
-#endif // !FEATURE_CORECLR
- [System.Security.SecurityCritical] // auto-generated_required
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
public static unsafe int ReadInt32(IntPtr ptr, int ofs)
{
@@ -557,14 +500,12 @@ namespace System.Runtime.InteropServices
}
}
- [System.Security.SecurityCritical] // auto-generated_required
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
public static int ReadInt32(IntPtr ptr)
{
return ReadInt32(ptr,0);
}
- [System.Security.SecurityCritical] // auto-generated_required
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
public static IntPtr ReadIntPtr([MarshalAs(UnmanagedType.AsAny),In] Object ptr, int ofs)
{
@@ -575,7 +516,6 @@ namespace System.Runtime.InteropServices
#endif
}
- [System.Security.SecurityCritical] // auto-generated_required
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
public static IntPtr ReadIntPtr(IntPtr ptr, int ofs)
{
@@ -586,7 +526,6 @@ namespace System.Runtime.InteropServices
#endif
}
- [System.Security.SecurityCritical] // auto-generated_required
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
public static IntPtr ReadIntPtr(IntPtr ptr)
{
@@ -597,19 +536,11 @@ namespace System.Runtime.InteropServices
#endif
}
- [System.Security.SecurityCritical] // auto-generated
-#if !FEATURE_CORECLR
- [DllImport(Win32Native.SHIM, EntryPoint="ND_RI8"), ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
- [SuppressUnmanagedCodeSecurity]
- public static extern long ReadInt64([MarshalAs(UnmanagedType.AsAny),In] Object ptr, int ofs);
-#else
public static long ReadInt64([MarshalAs(UnmanagedType.AsAny),In] Object ptr, int ofs)
{
throw new PlatformNotSupportedException();
}
-#endif // !FEATURE_CORECLR
- [System.Security.SecurityCritical] // auto-generated_required
public static unsafe long ReadInt64(IntPtr ptr, int ofs)
{
try
@@ -643,7 +574,6 @@ namespace System.Runtime.InteropServices
}
}
- [System.Security.SecurityCritical] // auto-generated_required
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
public static long ReadInt64(IntPtr ptr)
{
@@ -654,7 +584,6 @@ namespace System.Runtime.InteropServices
//====================================================================
// Write to memory
//====================================================================
- [System.Security.SecurityCritical] // auto-generated_required
public static unsafe void WriteByte(IntPtr ptr, int ofs, byte val)
{
try
@@ -669,25 +598,16 @@ namespace System.Runtime.InteropServices
}
}
- [System.Security.SecurityCritical] // auto-generated
-#if !FEATURE_CORECLR
- [DllImport(Win32Native.SHIM, EntryPoint="ND_WU1")]
- [SuppressUnmanagedCodeSecurity]
- public static extern void WriteByte([MarshalAs(UnmanagedType.AsAny),In,Out] Object ptr, int ofs, byte val);
-#else
public static void WriteByte([MarshalAs(UnmanagedType.AsAny),In,Out] Object ptr, int ofs, byte val)
{
throw new PlatformNotSupportedException();
}
-#endif // !FEATURE_CORECLR
- [System.Security.SecurityCritical] // auto-generated_required
public static void WriteByte(IntPtr ptr, byte val)
{
WriteByte(ptr, 0, val);
}
- [System.Security.SecurityCritical] // auto-generated_required
public static unsafe void WriteInt16(IntPtr ptr, int ofs, short val)
{
try
@@ -712,44 +632,32 @@ namespace System.Runtime.InteropServices
throw new AccessViolationException();
}
}
-
- [System.Security.SecurityCritical] // auto-generated
-#if !FEATURE_CORECLR
- [DllImport(Win32Native.SHIM, EntryPoint="ND_WI2")]
- [SuppressUnmanagedCodeSecurity]
- public static extern void WriteInt16([MarshalAs(UnmanagedType.AsAny),In,Out] Object ptr, int ofs, short val);
-#else
+
public static void WriteInt16([MarshalAs(UnmanagedType.AsAny),In,Out] Object ptr, int ofs, short val)
{
throw new PlatformNotSupportedException();
}
-#endif // !FEATURE_CORECLR
-
- [System.Security.SecurityCritical] // auto-generated_required
+
public static void WriteInt16(IntPtr ptr, short val)
{
WriteInt16(ptr, 0, val);
}
- [System.Security.SecurityCritical] // auto-generated_required
public static void WriteInt16(IntPtr ptr, int ofs, char val)
{
WriteInt16(ptr, ofs, (short)val);
}
- [System.Security.SecurityCritical] // auto-generated_required
public static void WriteInt16([In,Out]Object ptr, int ofs, char val)
{
WriteInt16(ptr, ofs, (short)val);
}
- [System.Security.SecurityCritical] // auto-generated_required
public static void WriteInt16(IntPtr ptr, char val)
{
WriteInt16(ptr, 0, (short)val);
}
- [System.Security.SecurityCritical] // auto-generated_required
public static unsafe void WriteInt32(IntPtr ptr, int ofs, int val)
{
try
@@ -776,26 +684,17 @@ namespace System.Runtime.InteropServices
throw new AccessViolationException();
}
}
-
- [System.Security.SecurityCritical] // auto-generated
-#if !FEATURE_CORECLR
- [DllImport(Win32Native.SHIM, EntryPoint="ND_WI4")]
- [SuppressUnmanagedCodeSecurity]
- public static extern void WriteInt32([MarshalAs(UnmanagedType.AsAny),In,Out] Object ptr, int ofs, int val);
-#else
+
public static void WriteInt32([MarshalAs(UnmanagedType.AsAny),In,Out] Object ptr, int ofs, int val)
{
throw new PlatformNotSupportedException();
}
-#endif // !FEATURE_CORECLR
- [System.Security.SecurityCritical] // auto-generated_required
public static void WriteInt32(IntPtr ptr, int val)
{
WriteInt32(ptr,0,val);
}
- [System.Security.SecurityCritical] // auto-generated_required
public static void WriteIntPtr(IntPtr ptr, int ofs, IntPtr val)
{
#if BIT64
@@ -805,7 +704,6 @@ namespace System.Runtime.InteropServices
#endif
}
- [System.Security.SecurityCritical] // auto-generated_required
public static void WriteIntPtr([MarshalAs(UnmanagedType.AsAny),In,Out] Object ptr, int ofs, IntPtr val)
{
#if BIT64
@@ -815,7 +713,6 @@ namespace System.Runtime.InteropServices
#endif
}
- [System.Security.SecurityCritical] // auto-generated_required
public static void WriteIntPtr(IntPtr ptr, IntPtr val)
{
#if BIT64
@@ -825,7 +722,6 @@ namespace System.Runtime.InteropServices
#endif
}
- [System.Security.SecurityCritical] // auto-generated_required
public static unsafe void WriteInt64(IntPtr ptr, int ofs, long val)
{
try
@@ -856,20 +752,12 @@ namespace System.Runtime.InteropServices
throw new AccessViolationException();
}
}
-
- [System.Security.SecurityCritical] // auto-generated
-#if !FEATURE_CORECLR
- [DllImport(Win32Native.SHIM, EntryPoint="ND_WI8")]
- [SuppressUnmanagedCodeSecurity]
- public static extern void WriteInt64([MarshalAs(UnmanagedType.AsAny),In,Out] Object ptr, int ofs, long val);
-#else
+
public static void WriteInt64([MarshalAs(UnmanagedType.AsAny),In,Out] Object ptr, int ofs, long val)
{
throw new PlatformNotSupportedException();
}
-#endif // !FEATURE_CORECLR
- [System.Security.SecurityCritical] // auto-generated_required
public static void WriteInt64(IntPtr ptr, long val)
{
WriteInt64(ptr, 0, val);
@@ -879,7 +767,6 @@ namespace System.Runtime.InteropServices
//====================================================================
// GetLastWin32Error
//====================================================================
- [System.Security.SecurityCritical] // auto-generated_required
[MethodImplAttribute(MethodImplOptions.InternalCall)]
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
public static extern int GetLastWin32Error();
@@ -896,7 +783,6 @@ namespace System.Runtime.InteropServices
//====================================================================
// GetHRForLastWin32Error
//====================================================================
- [System.Security.SecurityCritical] // auto-generated_required
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
public static int GetHRForLastWin32Error()
{
@@ -911,11 +797,10 @@ namespace System.Runtime.InteropServices
//====================================================================
// Prelink
//====================================================================
- [System.Security.SecurityCritical] // auto-generated_required
public static void Prelink(MethodInfo m)
{
if (m == null)
- throw new ArgumentNullException("m");
+ throw new ArgumentNullException(nameof(m));
Contract.EndContractBlock();
RuntimeMethodInfo rmi = m as RuntimeMethodInfo;
@@ -927,14 +812,12 @@ namespace System.Runtime.InteropServices
}
[DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode), SuppressUnmanagedCodeSecurity]
- [SecurityCritical]
private static extern void InternalPrelink(IRuntimeMethodInfo m);
- [System.Security.SecurityCritical] // auto-generated_required
public static void PrelinkAll(Type c)
{
if (c == null)
- throw new ArgumentNullException("c");
+ throw new ArgumentNullException(nameof(c));
Contract.EndContractBlock();
MethodInfo[] mi = c.GetMethods();
@@ -950,11 +833,10 @@ namespace System.Runtime.InteropServices
//====================================================================
// NumParamBytes
//====================================================================
- [System.Security.SecurityCritical] // auto-generated_required
public static int NumParamBytes(MethodInfo m)
{
if (m == null)
- throw new ArgumentNullException("m");
+ throw new ArgumentNullException(nameof(m));
Contract.EndContractBlock();
RuntimeMethodInfo rmi = m as RuntimeMethodInfo;
@@ -965,7 +847,6 @@ namespace System.Runtime.InteropServices
}
[DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode), SuppressUnmanagedCodeSecurity]
- [SecurityCritical]
private static extern int InternalNumParamBytes(IRuntimeMethodInfo m);
//====================================================================
@@ -973,12 +854,10 @@ namespace System.Runtime.InteropServices
// These are mostly interesting for Structured exception handling,
// but need to be exposed for all exceptions (not just SEHException).
//====================================================================
- [System.Security.SecurityCritical] // auto-generated_required
[MethodImplAttribute(MethodImplOptions.InternalCall)]
[System.Runtime.InteropServices.ComVisible(true)]
public static extern /* struct _EXCEPTION_POINTERS* */ IntPtr GetExceptionPointers();
- [System.Security.SecurityCritical] // auto-generated_required
[MethodImplAttribute(MethodImplOptions.InternalCall)]
public static extern int GetExceptionCode();
@@ -988,12 +867,10 @@ namespace System.Runtime.InteropServices
// If the structure contains pointers to allocated blocks and
// "fDeleteOld" is true, this routine will call DestroyStructure() first.
//====================================================================
- [System.Security.SecurityCritical] // auto-generated_required
[MethodImplAttribute(MethodImplOptions.InternalCall), ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
[System.Runtime.InteropServices.ComVisible(true)]
public static extern void StructureToPtr(Object structure, IntPtr ptr, bool fDeleteOld);
- [System.Security.SecurityCritical]
public static void StructureToPtr<T>(T structure, IntPtr ptr, bool fDeleteOld)
{
StructureToPtr((object)structure, ptr, fDeleteOld);
@@ -1002,14 +879,12 @@ namespace System.Runtime.InteropServices
//====================================================================
// Marshals data from a native memory block to a preallocated structure class.
//====================================================================
- [System.Security.SecurityCritical] // auto-generated_required
[System.Runtime.InteropServices.ComVisible(true)]
public static void PtrToStructure(IntPtr ptr, Object structure)
{
PtrToStructureHelper(ptr, structure, false);
}
- [System.Security.SecurityCritical]
public static void PtrToStructure<T>(IntPtr ptr, T structure)
{
PtrToStructure(ptr, (object)structure);
@@ -1019,7 +894,6 @@ namespace System.Runtime.InteropServices
// Creates a new instance of "structuretype" and marshals data from a
// native memory block to it.
//====================================================================
- [System.Security.SecurityCritical] // auto-generated_required
[System.Runtime.InteropServices.ComVisible(true)]
[MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var has to be marked non-inlineable
public static Object PtrToStructure(IntPtr ptr, Type structureType)
@@ -1027,15 +901,15 @@ namespace System.Runtime.InteropServices
if (ptr == IntPtr.Zero) return null;
if (structureType == null)
- throw new ArgumentNullException("structureType");
+ throw new ArgumentNullException(nameof(structureType));
if (structureType.IsGenericType)
- throw new ArgumentException(Environment.GetResourceString("Argument_NeedNonGenericType"), "structureType");
+ throw new ArgumentException(Environment.GetResourceString("Argument_NeedNonGenericType"), nameof(structureType));
RuntimeType rt = structureType.UnderlyingSystemType as RuntimeType;
if (rt == null)
- throw new ArgumentException(Environment.GetResourceString("Arg_MustBeType"), "type");
+ throw new ArgumentException(Environment.GetResourceString("Arg_MustBeType"), nameof(structureType));
StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
@@ -1044,7 +918,6 @@ namespace System.Runtime.InteropServices
return structure;
}
- [System.Security.SecurityCritical]
public static T PtrToStructure<T>(IntPtr ptr)
{
return (T)PtrToStructure(ptr, typeof(T));
@@ -1061,27 +934,25 @@ namespace System.Runtime.InteropServices
// Freeds all substructures pointed to by the native memory block.
// "structureclass" is used to provide layout information.
//====================================================================
- [System.Security.SecurityCritical] // auto-generated_required
[MethodImplAttribute(MethodImplOptions.InternalCall)]
[System.Runtime.InteropServices.ComVisible(true)]
public static extern void DestroyStructure(IntPtr ptr, Type structuretype);
- [System.Security.SecurityCritical]
public static void DestroyStructure<T>(IntPtr ptr)
{
DestroyStructure(ptr, typeof(T));
}
+#if FEATURE_COMINTEROP
//====================================================================
// Returns the HInstance for this module. Returns -1 if the module
// doesn't have an HInstance. In Memory (Dynamic) Modules won't have
// an HInstance.
//====================================================================
- [System.Security.SecurityCritical] // auto-generated_required
public static IntPtr GetHINSTANCE(Module m)
{
if (m == null)
- throw new ArgumentNullException("m");
+ throw new ArgumentNullException(nameof(m));
Contract.EndContractBlock();
RuntimeModule rtModule = m as RuntimeModule;
@@ -1093,26 +964,24 @@ namespace System.Runtime.InteropServices
}
if (rtModule == null)
- throw new ArgumentNullException("m",Environment.GetResourceString("Argument_MustBeRuntimeModule"));
+ throw new ArgumentNullException(nameof(m),Environment.GetResourceString("Argument_MustBeRuntimeModule"));
return GetHINSTANCE(rtModule.GetNativeHandle());
}
- [System.Security.SecurityCritical] // auto-generated_required
[SuppressUnmanagedCodeSecurity]
[DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode), SuppressUnmanagedCodeSecurity]
private extern static IntPtr GetHINSTANCE(RuntimeModule m);
+#endif // FEATURE_COMINTEROP
//====================================================================
// Throws a CLR exception based on the HRESULT.
//====================================================================
- [System.Security.SecurityCritical] // auto-generated_required
public static void ThrowExceptionForHR(int errorCode)
{
if (errorCode < 0)
ThrowExceptionForHRInternal(errorCode, IntPtr.Zero);
}
- [System.Security.SecurityCritical] // auto-generated_required
public static void ThrowExceptionForHR(int errorCode, IntPtr errorInfo)
{
if (errorCode < 0)
@@ -1126,7 +995,6 @@ namespace System.Runtime.InteropServices
//====================================================================
// Converts the HRESULT to a CLR exception.
//====================================================================
- [System.Security.SecurityCritical] // auto-generated_required
public static Exception GetExceptionForHR(int errorCode)
{
if (errorCode < 0)
@@ -1134,7 +1002,6 @@ namespace System.Runtime.InteropServices
else
return null;
}
- [System.Security.SecurityCritical] // auto-generated_required
public static Exception GetExceptionForHR(int errorCode, IntPtr errorInfo)
{
if (errorCode < 0)
@@ -1151,7 +1018,6 @@ namespace System.Runtime.InteropServices
// This method is intended for compiler code generators rather
// than applications.
//====================================================================
- [System.Security.SecurityCritical] // auto-generated_required
[ObsoleteAttribute("The GetUnmanagedThunkForManagedMethodPtr method has been deprecated and will be removed in a future release.", false)]
[MethodImplAttribute(MethodImplOptions.InternalCall)]
public static extern IntPtr GetUnmanagedThunkForManagedMethodPtr(IntPtr pfnMethodToWrap, IntPtr pbSignature, int cbSignature);
@@ -1160,7 +1026,6 @@ namespace System.Runtime.InteropServices
// This method is intended for compiler code generators rather
// than applications.
//====================================================================
- [System.Security.SecurityCritical] // auto-generated_required
[ObsoleteAttribute("The GetManagedThunkForUnmanagedMethodPtr method has been deprecated and will be removed in a future release.", false)]
[MethodImplAttribute(MethodImplOptions.InternalCall)]
public static extern IntPtr GetManagedThunkForUnmanagedMethodPtr(IntPtr pfnMethodToWrap, IntPtr pbSignature, int cbSignature);
@@ -1171,12 +1036,11 @@ namespace System.Runtime.InteropServices
// activity. A fiber cookie can be redeemed for its managed Thread
// object by calling the following service.
//====================================================================
- [System.Security.SecurityCritical] // auto-generated_required
[ObsoleteAttribute("The GetThreadFromFiberCookie method has been deprecated. Use the hosting API to perform this operation.", false)]
public static Thread GetThreadFromFiberCookie(int cookie)
{
if (cookie == 0)
- throw new ArgumentException(Environment.GetResourceString("Argument_ArgumentZero"), "cookie");
+ throw new ArgumentException(Environment.GetResourceString("Argument_ArgumentZero"), nameof(cookie));
Contract.EndContractBlock();
return InternalGetThreadFromFiberCookie(cookie);
@@ -1189,7 +1053,6 @@ namespace System.Runtime.InteropServices
//====================================================================
// Memory allocation and deallocation.
//====================================================================
- [System.Security.SecurityCritical] // auto-generated_required
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
public static IntPtr AllocHGlobal(IntPtr cb)
{
@@ -1214,14 +1077,12 @@ namespace System.Runtime.InteropServices
return pNewMem;
}
- [System.Security.SecurityCritical] // auto-generated_required
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
public static IntPtr AllocHGlobal(int cb)
{
return AllocHGlobal((IntPtr)cb);
}
- [System.Security.SecurityCritical] // auto-generated_required
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
public static void FreeHGlobal(IntPtr hglobal)
{
@@ -1232,7 +1093,6 @@ namespace System.Runtime.InteropServices
}
}
- [System.Security.SecurityCritical] // auto-generated_required
public static IntPtr ReAllocHGlobal(IntPtr pv, IntPtr cb)
{
IntPtr pNewMem = Win32Native.LocalReAlloc(pv, cb, LMEM_MOVEABLE);
@@ -1246,7 +1106,6 @@ namespace System.Runtime.InteropServices
//====================================================================
// String convertions.
//====================================================================
- [System.Security.SecurityCritical] // auto-generated_required
unsafe public static IntPtr StringToHGlobalAnsi(String s)
{
if (s == null)
@@ -1259,7 +1118,7 @@ namespace System.Runtime.InteropServices
// Overflow checking
if (nb < s.Length)
- throw new ArgumentOutOfRangeException("s");
+ throw new ArgumentOutOfRangeException(nameof(s));
UIntPtr len = new UIntPtr((uint)nb);
IntPtr hglobal = Win32Native.LocalAlloc_NoSafeHandle(LMEM_FIXED, len);
@@ -1276,7 +1135,6 @@ namespace System.Runtime.InteropServices
}
}
- [System.Security.SecurityCritical] // auto-generated_required
unsafe public static IntPtr StringToHGlobalUni(String s)
{
if (s == null)
@@ -1289,7 +1147,7 @@ namespace System.Runtime.InteropServices
// Overflow checking
if (nb < s.Length)
- throw new ArgumentOutOfRangeException("s");
+ throw new ArgumentOutOfRangeException(nameof(s));
UIntPtr len = new UIntPtr((uint)nb);
IntPtr hglobal = Win32Native.LocalAlloc_NoSafeHandle(LMEM_FIXED, len);
@@ -1309,7 +1167,6 @@ namespace System.Runtime.InteropServices
}
}
- [System.Security.SecurityCritical] // auto-generated_required
public static IntPtr StringToHGlobalAuto(String s)
{
// Ansi platforms are no longer supported
@@ -1322,7 +1179,6 @@ namespace System.Runtime.InteropServices
// Converts the CLR exception to an HRESULT. This function also sets
// up an IErrorInfo for the exception.
//====================================================================
- [System.Security.SecurityCritical] // auto-generated_required
[MethodImplAttribute(MethodImplOptions.InternalCall)]
public static extern int GetHRForException(Exception e);
@@ -1332,7 +1188,6 @@ namespace System.Runtime.InteropServices
// This function is only used in WinRT and converts ObjectDisposedException
// to RO_E_CLOSED
//====================================================================
- [System.Security.SecurityCritical] // auto-generated_required
[MethodImplAttribute(MethodImplOptions.InternalCall)]
internal static extern int GetHRForException_WinRT(Exception e);
@@ -1341,7 +1196,6 @@ namespace System.Runtime.InteropServices
//====================================================================
// Given a managed object that wraps a UCOMITypeLib, return its name
//====================================================================
- [System.Security.SecurityCritical] // auto-generated_required
[Obsolete("Use System.Runtime.InteropServices.Marshal.GetTypeLibName(ITypeLib pTLB) instead. http://go.microsoft.com/fwlink/?linkid=14202&ID=0000011.", false)]
public static String GetTypeLibName(UCOMITypeLib pTLB)
{
@@ -1352,11 +1206,10 @@ namespace System.Runtime.InteropServices
//====================================================================
// Given a managed object that wraps an ITypeLib, return its name
//====================================================================
- [System.Security.SecurityCritical] // auto-generated_required
public static String GetTypeLibName(ITypeLib typelib)
{
if (typelib == null)
- throw new ArgumentNullException("typelib");
+ throw new ArgumentNullException(nameof(typelib));
Contract.EndContractBlock();
String strTypeLibName = null;
@@ -1373,11 +1226,10 @@ namespace System.Runtime.InteropServices
// Internal version of GetTypeLibName
// Support GUID_ManagedName which aligns with TlbImp
//====================================================================
- [System.Security.SecurityCritical] // auto-generated_required
internal static String GetTypeLibNameInternal(ITypeLib typelib)
{
if (typelib == null)
- throw new ArgumentNullException("typelib");
+ throw new ArgumentNullException(nameof(typelib));
Contract.EndContractBlock();
// Try GUID_ManagedName first
@@ -1415,7 +1267,6 @@ namespace System.Runtime.InteropServices
//====================================================================
// Given an managed object that wraps an UCOMITypeLib, return its guid
//====================================================================
- [System.Security.SecurityCritical] // auto-generated_required
[Obsolete("Use System.Runtime.InteropServices.Marshal.GetTypeLibGuid(ITypeLib pTLB) instead. http://go.microsoft.com/fwlink/?linkid=14202&ID=0000011.", false)]
public static Guid GetTypeLibGuid(UCOMITypeLib pTLB)
{
@@ -1425,7 +1276,6 @@ namespace System.Runtime.InteropServices
//====================================================================
// Given an managed object that wraps an ITypeLib, return its guid
//====================================================================
- [System.Security.SecurityCritical] // auto-generated_required
public static Guid GetTypeLibGuid(ITypeLib typelib)
{
Guid result = new Guid ();
@@ -1439,7 +1289,6 @@ namespace System.Runtime.InteropServices
//====================================================================
// Given a managed object that wraps a UCOMITypeLib, return its lcid
//====================================================================
- [System.Security.SecurityCritical] // auto-generated_required
[Obsolete("Use System.Runtime.InteropServices.Marshal.GetTypeLibLcid(ITypeLib pTLB) instead. http://go.microsoft.com/fwlink/?linkid=14202&ID=0000011.", false)]
public static int GetTypeLibLcid(UCOMITypeLib pTLB)
{
@@ -1449,7 +1298,6 @@ namespace System.Runtime.InteropServices
//====================================================================
// Given a managed object that wraps an ITypeLib, return its lcid
//====================================================================
- [System.Security.SecurityCritical] // auto-generated_required
[MethodImplAttribute(MethodImplOptions.InternalCall)]
public static extern int GetTypeLibLcid(ITypeLib typelib);
@@ -1463,7 +1311,6 @@ namespace System.Runtime.InteropServices
//====================================================================
// Given a managed object that wraps an ITypeInfo, return its guid.
//====================================================================
- [System.Security.SecurityCritical] // auto-generated
internal static Guid GetTypeInfoGuid(ITypeInfo typeInfo)
{
Guid result = new Guid ();
@@ -1478,16 +1325,15 @@ namespace System.Runtime.InteropServices
// Given a assembly, return the TLBID that will be generated for the
// typelib exported from the assembly.
//====================================================================
- [System.Security.SecurityCritical] // auto-generated_required
public static Guid GetTypeLibGuidForAssembly(Assembly asm)
{
if (asm == null)
- throw new ArgumentNullException("asm");
+ throw new ArgumentNullException(nameof(asm));
Contract.EndContractBlock();
RuntimeAssembly rtAssembly = asm as RuntimeAssembly;
if (rtAssembly == null)
- throw new ArgumentException(Environment.GetResourceString("Argument_MustBeRuntimeAssembly"), "asm");
+ throw new ArgumentException(Environment.GetResourceString("Argument_MustBeRuntimeAssembly"), nameof(asm));
Guid result = new Guid();
FCallGetTypeLibGuidForAssembly(ref result, rtAssembly);
@@ -1504,16 +1350,15 @@ namespace System.Runtime.InteropServices
[MethodImplAttribute(MethodImplOptions.InternalCall)]
private static extern void _GetTypeLibVersionForAssembly(RuntimeAssembly inputAssembly, out int majorVersion, out int minorVersion);
- [System.Security.SecurityCritical] // auto-generated_required
public static void GetTypeLibVersionForAssembly(Assembly inputAssembly, out int majorVersion, out int minorVersion)
{
if (inputAssembly == null)
- throw new ArgumentNullException("inputAssembly");
+ throw new ArgumentNullException(nameof(inputAssembly));
Contract.EndContractBlock();
RuntimeAssembly rtAssembly = inputAssembly as RuntimeAssembly;
if (rtAssembly == null)
- throw new ArgumentException(Environment.GetResourceString("Argument_MustBeRuntimeAssembly"), "inputAssembly");
+ throw new ArgumentException(Environment.GetResourceString("Argument_MustBeRuntimeAssembly"), nameof(inputAssembly));
_GetTypeLibVersionForAssembly(rtAssembly, out majorVersion, out minorVersion);
}
@@ -1521,7 +1366,6 @@ namespace System.Runtime.InteropServices
//====================================================================
// Given a managed object that wraps an UCOMITypeInfo, return its name
//====================================================================
- [System.Security.SecurityCritical] // auto-generated_required
[Obsolete("Use System.Runtime.InteropServices.Marshal.GetTypeInfoName(ITypeInfo pTLB) instead. http://go.microsoft.com/fwlink/?linkid=14202&ID=0000011.", false)]
public static String GetTypeInfoName(UCOMITypeInfo pTI)
{
@@ -1531,11 +1375,10 @@ namespace System.Runtime.InteropServices
//====================================================================
// Given a managed object that wraps an ITypeInfo, return its name
//====================================================================
- [System.Security.SecurityCritical] // auto-generated_required
public static String GetTypeInfoName(ITypeInfo typeInfo)
{
if (typeInfo == null)
- throw new ArgumentNullException("typeInfo");
+ throw new ArgumentNullException(nameof(typeInfo));
Contract.EndContractBlock();
String strTypeLibName = null;
@@ -1552,11 +1395,10 @@ namespace System.Runtime.InteropServices
// Internal version of GetTypeInfoName
// Support GUID_ManagedName which aligns with TlbImp
//====================================================================
- [System.Security.SecurityCritical] // auto-generated_required
internal static String GetTypeInfoNameInternal(ITypeInfo typeInfo, out bool hasManagedName)
{
if (typeInfo == null)
- throw new ArgumentNullException("typeInfo");
+ throw new ArgumentNullException(nameof(typeInfo));
Contract.EndContractBlock();
// Try ManagedNameGuid first
@@ -1590,7 +1432,6 @@ namespace System.Runtime.InteropServices
// Get the corresponding managed name as converted by TlbImp
// Used to get the type using GetType() from imported assemblies
//====================================================================
- [System.Security.SecurityCritical] // auto-generated_required
internal static String GetManagedTypeInfoNameInternal(ITypeLib typeLib, ITypeInfo typeInfo)
{
bool hasManagedName;
@@ -1609,95 +1450,8 @@ namespace System.Runtime.InteropServices
[MethodImplAttribute(MethodImplOptions.InternalCall)]
private static extern Type GetLoadedTypeForGUID(ref Guid guid);
-#if !FEATURE_CORECLR // current implementation requires reflection only load
- //====================================================================
- // map ITypeInfo* to Type
- //====================================================================
- [System.Security.SecurityCritical] // auto-generated_required
- public static Type GetTypeForITypeInfo(IntPtr /* ITypeInfo* */ piTypeInfo)
- {
- ITypeInfo pTI = null;
- ITypeLib pTLB = null;
- Type TypeObj = null;
- Assembly AsmBldr = null;
- TypeLibConverter TlbConverter = null;
- int Index = 0;
- Guid clsid;
-
- // If the input ITypeInfo is NULL then return NULL.
- if (piTypeInfo == IntPtr.Zero)
- return null;
-
- // Wrap the ITypeInfo in a CLR object.
- pTI = (ITypeInfo)GetObjectForIUnknown(piTypeInfo);
-
- // Check to see if a class exists with the specified GUID.
-
- clsid = GetTypeInfoGuid(pTI);
- TypeObj = GetLoadedTypeForGUID(ref clsid);
-
- // If we managed to find the type based on the GUID then return it.
- if (TypeObj != null)
- return TypeObj;
-
- // There is no type with the specified GUID in the app domain so lets
- // try and convert the containing typelib.
- try
- {
- pTI.GetContainingTypeLib(out pTLB, out Index);
- }
- catch(COMException)
- {
- pTLB = null;
- }
-
- // Check to see if we managed to get a containing typelib.
- if (pTLB != null)
- {
- // Get the assembly name from the typelib.
- AssemblyName AsmName = TypeLibConverter.GetAssemblyNameFromTypelib(pTLB, null, null, null, null, AssemblyNameFlags.None);
- String AsmNameString = AsmName.FullName;
-
- // Check to see if the assembly that will contain the type already exists.
- Assembly[] aAssemblies = Thread.GetDomain().GetAssemblies();
- int NumAssemblies = aAssemblies.Length;
- for (int i = 0; i < NumAssemblies; i++)
- {
- if (String.Compare(aAssemblies[i].FullName,
- AsmNameString,StringComparison.Ordinal) == 0)
- AsmBldr = aAssemblies[i];
- }
-
- // If we haven't imported the assembly yet then import it.
- if (AsmBldr == null)
- {
- TlbConverter = new TypeLibConverter();
- AsmBldr = TlbConverter.ConvertTypeLibToAssembly(pTLB,
- GetTypeLibName(pTLB) + ".dll", 0, new ImporterCallback(), null, null, null, null);
- }
-
- // Load the type object from the imported typelib.
- // Call GetManagedTypeInfoNameInternal to align with TlbImp behavior
- TypeObj = AsmBldr.GetType(GetManagedTypeInfoNameInternal(pTLB, pTI), true, false);
- if (TypeObj != null && !TypeObj.IsVisible)
- TypeObj = null;
- }
- else
- {
- // If the ITypeInfo does not have a containing typelib then simply
- // return Object as the type.
- TypeObj = typeof(Object);
- }
-
- return TypeObj;
- }
-#endif // #if !FEATURE_CORECLR
-
// This method is identical to Type.GetTypeFromCLSID. Since it's interop specific, we expose it
// on Marshal for more consistent API surface.
-#if !FEATURE_CORECLR
- [System.Security.SecuritySafeCritical]
-#endif //!FEATURE_CORECLR
public static Type GetTypeFromCLSID(Guid clsid)
{
return RuntimeType.GetTypeFromCLSIDImpl(clsid, null, false);
@@ -1706,7 +1460,6 @@ namespace System.Runtime.InteropServices
//====================================================================
// map Type to ITypeInfo*
//====================================================================
- [System.Security.SecurityCritical] // auto-generated_required
[MethodImplAttribute(MethodImplOptions.InternalCall)]
public static extern IntPtr /* ITypeInfo* */ GetITypeInfoForType(Type t);
@@ -1715,13 +1468,11 @@ namespace System.Runtime.InteropServices
// is the one where the RCW was first seen. Will return null
// otherwise.
//====================================================================
- [System.Security.SecurityCritical] // auto-generated_required
public static IntPtr /* IUnknown* */ GetIUnknownForObject(Object o)
{
return GetIUnknownForObjectNative(o, false);
}
- [System.Security.SecurityCritical] // auto-generated_required
public static IntPtr /* IUnknown* */ GetIUnknownForObjectInContext(Object o)
{
return GetIUnknownForObjectNative(o, true);
@@ -1737,22 +1488,22 @@ namespace System.Runtime.InteropServices
//====================================================================
[MethodImplAttribute(MethodImplOptions.InternalCall)]
internal static extern IntPtr /* IUnknown* */ GetRawIUnknownForComObjectNoAddRef(Object o);
+#endif // FEATURE_COMINTEROP
//====================================================================
// return the IDispatch* for an Object
//====================================================================
- [System.Security.SecurityCritical] // auto-generated_required
public static IntPtr /* IDispatch */ GetIDispatchForObject(Object o)
{
- return GetIDispatchForObjectNative(o, false);
+ throw new PlatformNotSupportedException();
}
-
+
+#if FEATURE_COMINTEROP
//====================================================================
// return the IDispatch* for an Object if the current context
// is the one where the RCW was first seen. Will return null
// otherwise.
//====================================================================
- [System.Security.SecurityCritical] // auto-generated_required
public static IntPtr /* IUnknown* */ GetIDispatchForObjectInContext(Object o)
{
return GetIDispatchForObjectNative(o, true);
@@ -1765,13 +1516,11 @@ namespace System.Runtime.InteropServices
// return the IUnknown* representing the interface for the Object
// Object o should support Type T
//====================================================================
- [System.Security.SecurityCritical] // auto-generated_required
public static IntPtr /* IUnknown* */ GetComInterfaceForObject(Object o, Type T)
{
return GetComInterfaceForObjectNative(o, T, false, true);
}
- [System.Security.SecurityCritical]
public static IntPtr GetComInterfaceForObject<T, TInterface>(T o)
{
return GetComInterfaceForObject(o, typeof(TInterface));
@@ -1782,7 +1531,6 @@ namespace System.Runtime.InteropServices
// Object o should support Type T, it refer the value of mode to
// invoke customized QueryInterface or not
//====================================================================
- [System.Security.SecurityCritical] // auto-generated_required
public static IntPtr /* IUnknown* */ GetComInterfaceForObject(Object o, Type T, CustomQueryInterfaceMode mode)
{
bool bEnableCustomizedQueryInterface = ((mode == CustomQueryInterfaceMode.Allow) ? true : false);
@@ -1795,7 +1543,6 @@ namespace System.Runtime.InteropServices
// is the one where the RCW was first seen. Will return null
// otherwise.
//====================================================================
- [System.Security.SecurityCritical] // auto-generated_required
public static IntPtr /* IUnknown* */ GetComInterfaceForObjectInContext(Object o, Type t)
{
return GetComInterfaceForObjectNative(o, t, true, true);
@@ -1807,7 +1554,6 @@ namespace System.Runtime.InteropServices
//====================================================================
// return an Object for IUnknown
//====================================================================
- [System.Security.SecurityCritical] // auto-generated_required
[MethodImplAttribute(MethodImplOptions.InternalCall)]
public static extern Object GetObjectForIUnknown(IntPtr /* IUnknown* */ pUnk);
@@ -1818,7 +1564,6 @@ namespace System.Runtime.InteropServices
// where you want to be able to call ReleaseComObject on a RCW
// and not worry about other active uses of said RCW.
//====================================================================
- [System.Security.SecurityCritical] // auto-generated_required
[MethodImplAttribute(MethodImplOptions.InternalCall)]
public static extern Object GetUniqueObjectForIUnknown(IntPtr unknown);
@@ -1828,40 +1573,31 @@ namespace System.Runtime.InteropServices
// Type T should be either a COM imported Type or a sub-type of COM
// imported Type
//====================================================================
- [System.Security.SecurityCritical] // auto-generated_required
[MethodImplAttribute(MethodImplOptions.InternalCall)]
public static extern Object GetTypedObjectForIUnknown(IntPtr /* IUnknown* */ pUnk, Type t);
- [System.Security.SecurityCritical] // auto-generated_required
[MethodImplAttribute(MethodImplOptions.InternalCall)]
public static extern IntPtr CreateAggregatedObject(IntPtr pOuter, Object o);
- [System.Security.SecurityCritical]
public static IntPtr CreateAggregatedObject<T>(IntPtr pOuter, T o)
{
return CreateAggregatedObject(pOuter, (object)o);
}
- [System.Security.SecurityCritical] // auto-generated_required
[MethodImplAttribute(MethodImplOptions.InternalCall)]
public static extern void CleanupUnusedObjectsInCurrentContext();
- [System.Security.SecurityCritical]
[MethodImplAttribute(MethodImplOptions.InternalCall)]
public static extern bool AreComObjectsAvailableForCleanup();
//====================================================================
// check if the object is classic COM component
//====================================================================
-#if !FEATURE_CORECLR // with FEATURE_CORECLR, the whole type is SecurityCritical
- [System.Security.SecuritySafeCritical]
-#endif
[MethodImplAttribute(MethodImplOptions.InternalCall)]
public static extern bool IsComObject(Object o);
#endif // FEATURE_COMINTEROP
- [System.Security.SecurityCritical] // auto-generated_required
public static IntPtr AllocCoTaskMem(int cb)
{
IntPtr pNewMem = Win32Native.CoTaskMemAlloc(new UIntPtr((uint)cb));
@@ -1872,7 +1608,6 @@ namespace System.Runtime.InteropServices
return pNewMem;
}
- [System.Security.SecurityCritical] // auto-generated_required
unsafe public static IntPtr StringToCoTaskMemUni(String s)
{
if (s == null)
@@ -1885,7 +1620,7 @@ namespace System.Runtime.InteropServices
// Overflow checking
if (nb < s.Length)
- throw new ArgumentOutOfRangeException("s");
+ throw new ArgumentOutOfRangeException(nameof(s));
IntPtr hglobal = Win32Native.CoTaskMemAlloc(new UIntPtr((uint)nb));
@@ -1904,7 +1639,6 @@ namespace System.Runtime.InteropServices
}
}
- [System.Security.SecurityCritical] // auto-generated_required
unsafe public static IntPtr StringToCoTaskMemUTF8(String s)
{
const int MAX_UTF8_CHAR_SIZE = 3;
@@ -1918,7 +1652,7 @@ namespace System.Runtime.InteropServices
// Overflow checking
if (nb < s.Length)
- throw new ArgumentOutOfRangeException("s");
+ throw new ArgumentOutOfRangeException(nameof(s));
IntPtr pMem = Win32Native.CoTaskMemAlloc(new UIntPtr((uint)nb +1));
@@ -1936,14 +1670,12 @@ namespace System.Runtime.InteropServices
}
}
- [System.Security.SecurityCritical] // auto-generated_required
public static IntPtr StringToCoTaskMemAuto(String s)
{
// Ansi platforms are no longer supported
return StringToCoTaskMemUni(s);
}
- [System.Security.SecurityCritical] // auto-generated_required
unsafe public static IntPtr StringToCoTaskMemAnsi(String s)
{
if (s == null)
@@ -1956,7 +1688,7 @@ namespace System.Runtime.InteropServices
// Overflow checking
if (nb < s.Length)
- throw new ArgumentOutOfRangeException("s");
+ throw new ArgumentOutOfRangeException(nameof(s));
IntPtr hglobal = Win32Native.CoTaskMemAlloc(new UIntPtr((uint)nb));
@@ -1972,7 +1704,6 @@ namespace System.Runtime.InteropServices
}
}
- [System.Security.SecurityCritical] // auto-generated_required
public static void FreeCoTaskMem(IntPtr ptr)
{
if (IsNotWin32Atom(ptr)) {
@@ -1980,7 +1711,6 @@ namespace System.Runtime.InteropServices
}
}
- [System.Security.SecurityCritical] // auto-generated_required
public static IntPtr ReAllocCoTaskMem(IntPtr pv, int cb)
{
IntPtr pNewMem = Win32Native.CoTaskMemRealloc(pv, new UIntPtr((uint)cb));
@@ -1994,7 +1724,6 @@ namespace System.Runtime.InteropServices
//====================================================================
// BSTR allocation and dealocation.
//====================================================================
- [System.Security.SecurityCritical] // auto-generated_required
public static void FreeBSTR(IntPtr ptr)
{
if (IsNotWin32Atom(ptr))
@@ -2003,7 +1732,6 @@ namespace System.Runtime.InteropServices
}
}
- [System.Security.SecurityCritical] // auto-generated_required
public static IntPtr StringToBSTR(String s)
{
if (s == null)
@@ -2011,7 +1739,7 @@ namespace System.Runtime.InteropServices
// Overflow checking
if (s.Length + 1 < s.Length)
- throw new ArgumentOutOfRangeException("s");
+ throw new ArgumentOutOfRangeException(nameof(s));
IntPtr bstr = Win32Native.SysAllocStringLen(s, s.Length);
if (bstr == IntPtr.Zero)
@@ -2020,7 +1748,6 @@ namespace System.Runtime.InteropServices
return bstr;
}
- [System.Security.SecurityCritical] // auto-generated_required
public static String PtrToStringBSTR(IntPtr ptr)
{
return PtrToStringUni(ptr, (int)Win32Native.SysStringLen(ptr));
@@ -2031,7 +1758,6 @@ namespace System.Runtime.InteropServices
// release the COM component and if the reference hits 0 zombie this object
// further usage of this Object might throw an exception
//====================================================================
- [System.Security.SecurityCritical] // auto-generated_required
public static int ReleaseComObject(Object o)
{
__ComObject co = null;
@@ -2043,7 +1769,7 @@ namespace System.Runtime.InteropServices
}
catch (InvalidCastException)
{
- throw new ArgumentException(Environment.GetResourceString("Argument_ObjNotComObject"), "o");
+ throw new ArgumentException(Environment.GetResourceString("Argument_ObjNotComObject"), nameof(o));
}
return co.ReleaseSelf();
@@ -2057,11 +1783,10 @@ namespace System.Runtime.InteropServices
// release the COM component and zombie this object
// further usage of this Object might throw an exception
//====================================================================
- [System.Security.SecurityCritical] // auto-generated_required
public static Int32 FinalReleaseComObject(Object o)
{
if (o == null)
- throw new ArgumentNullException("o");
+ throw new ArgumentNullException(nameof(o));
Contract.EndContractBlock();
__ComObject co = null;
@@ -2073,7 +1798,7 @@ namespace System.Runtime.InteropServices
}
catch (InvalidCastException)
{
- throw new ArgumentException(Environment.GetResourceString("Argument_ObjNotComObject"), "o");
+ throw new ArgumentException(Environment.GetResourceString("Argument_ObjNotComObject"), nameof(o));
}
co.FinalReleaseSelf();
@@ -2083,39 +1808,14 @@ namespace System.Runtime.InteropServices
[MethodImplAttribute(MethodImplOptions.InternalCall)]
internal static extern void InternalFinalReleaseComObject(Object o);
+#endif // FEATURE_COMINTEROP
//====================================================================
// This method retrieves data from the COM object.
//====================================================================
- [System.Security.SecurityCritical] // auto-generated_required
public static Object GetComObjectData(Object obj, Object key)
{
- // Validate that the arguments aren't null.
- if (obj == null)
- throw new ArgumentNullException("obj");
- if (key == null)
- throw new ArgumentNullException("key");
- Contract.EndContractBlock();
-
- __ComObject comObj = null;
-
- // Make sure the obj is an __ComObject.
- try
- {
- comObj = (__ComObject)obj;
- }
- catch (InvalidCastException)
- {
- throw new ArgumentException(Environment.GetResourceString("Argument_ObjNotComObject"), "obj");
- }
-
- if (obj.GetType().IsWindowsRuntimeObject)
- {
- throw new ArgumentException(Environment.GetResourceString("Argument_ObjIsWinRTObject"), "obj");
- }
-
- // Retrieve the data from the __ComObject.
- return comObj.GetData(key);
+ throw new PlatformNotSupportedException();
}
//====================================================================
@@ -2124,55 +1824,29 @@ namespace System.Runtime.InteropServices
// true if the data has been added, false if the data could not be
// added because there already was data for the specified key.
//====================================================================
- [System.Security.SecurityCritical] // auto-generated_required
public static bool SetComObjectData(Object obj, Object key, Object data)
{
- // Validate that the arguments aren't null. The data can validly be null.
- if (obj == null)
- throw new ArgumentNullException("obj");
- if (key == null)
- throw new ArgumentNullException("key");
- Contract.EndContractBlock();
-
- __ComObject comObj = null;
-
- // Make sure the obj is an __ComObject.
- try
- {
- comObj = (__ComObject)obj;
- }
- catch (InvalidCastException)
- {
- throw new ArgumentException(Environment.GetResourceString("Argument_ObjNotComObject"), "obj");
- }
-
- if (obj.GetType().IsWindowsRuntimeObject)
- {
- throw new ArgumentException(Environment.GetResourceString("Argument_ObjIsWinRTObject"), "obj");
- }
-
- // Retrieve the data from the __ComObject.
- return comObj.SetData(key, data);
+ throw new PlatformNotSupportedException();
}
+#if FEATURE_COMINTEROP
//====================================================================
// This method takes the given COM object and wraps it in an object
// of the specified type. The type must be derived from __ComObject.
//====================================================================
- [System.Security.SecurityCritical] // auto-generated_required
public static Object CreateWrapperOfType(Object o, Type t)
{
// Validate the arguments.
if (t == null)
- throw new ArgumentNullException("t");
+ throw new ArgumentNullException(nameof(t));
if (!t.IsCOMObject)
- throw new ArgumentException(Environment.GetResourceString("Argument_TypeNotComObject"), "t");
+ throw new ArgumentException(Environment.GetResourceString("Argument_TypeNotComObject"), nameof(t));
if (t.IsGenericType)
- throw new ArgumentException(Environment.GetResourceString("Argument_NeedNonGenericType"), "t");
+ throw new ArgumentException(Environment.GetResourceString("Argument_NeedNonGenericType"), nameof(t));
Contract.EndContractBlock();
if (t.IsWindowsRuntimeObject)
- throw new ArgumentException(Environment.GetResourceString("Argument_TypeIsWinRTType"), "t");
+ throw new ArgumentException(Environment.GetResourceString("Argument_TypeIsWinRTType"), nameof(t));
// Check for the null case.
if (o == null)
@@ -2180,9 +1854,9 @@ namespace System.Runtime.InteropServices
// Make sure the object is a COM object.
if (!o.GetType().IsCOMObject)
- throw new ArgumentException(Environment.GetResourceString("Argument_ObjNotComObject"), "o");
+ throw new ArgumentException(Environment.GetResourceString("Argument_ObjNotComObject"), nameof(o));
if (o.GetType().IsWindowsRuntimeObject)
- throw new ArgumentException(Environment.GetResourceString("Argument_ObjIsWinRTObject"), "o");
+ throw new ArgumentException(Environment.GetResourceString("Argument_ObjIsWinRTObject"), nameof(o));
// Check to see if the type of the object is the requested type.
if (o.GetType() == t)
@@ -2206,7 +1880,6 @@ namespace System.Runtime.InteropServices
return Wrapper;
}
- [System.Security.SecurityCritical]
public static TWrapper CreateWrapperOfType<T, TWrapper>(T o)
{
return (TWrapper)CreateWrapperOfType(o, typeof(TWrapper));
@@ -2215,7 +1888,6 @@ namespace System.Runtime.InteropServices
//====================================================================
// Helper method called from CreateWrapperOfType.
//====================================================================
- [System.Security.SecurityCritical] // auto-generated_required
[MethodImplAttribute(MethodImplOptions.InternalCall)]
private static extern Object InternalCreateWrapperOfType(Object o, Type t);
@@ -2223,7 +1895,6 @@ namespace System.Runtime.InteropServices
// There may be a thread-based cache of COM components. This service can
// force the aggressive release of the current thread's cache.
//====================================================================
- [System.Security.SecurityCritical] // auto-generated_required
[Obsolete("This API did not perform any operation and will be removed in future versions of the CLR.", false)]
public static void ReleaseThreadCache()
{
@@ -2232,50 +1903,40 @@ namespace System.Runtime.InteropServices
//====================================================================
// check if the type is visible from COM.
//====================================================================
- [System.Security.SecuritySafeCritical]
[MethodImplAttribute(MethodImplOptions.InternalCall)]
public static extern bool IsTypeVisibleFromCom(Type t);
//====================================================================
// IUnknown Helpers
//====================================================================
- [System.Security.SecurityCritical] // auto-generated_required
[MethodImplAttribute(MethodImplOptions.InternalCall)]
public static extern int /* HRESULT */ QueryInterface(IntPtr /* IUnknown */ pUnk, ref Guid iid, out IntPtr ppv);
- [System.Security.SecurityCritical] // auto-generated_required
[MethodImplAttribute(MethodImplOptions.InternalCall)]
public static extern int /* ULONG */ AddRef(IntPtr /* IUnknown */ pUnk );
- [System.Security.SecurityCritical] // auto-generated_required
[MethodImplAttribute(MethodImplOptions.InternalCall)]
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
public static extern int /* ULONG */ Release(IntPtr /* IUnknown */ pUnk );
- [System.Security.SecurityCritical] // auto-generated_required
[MethodImplAttribute(MethodImplOptions.InternalCall)]
public static extern void GetNativeVariantForObject(Object obj, /* VARIANT * */ IntPtr pDstNativeVariant);
- [System.Security.SecurityCritical]
public static void GetNativeVariantForObject<T>(T obj, IntPtr pDstNativeVariant)
{
GetNativeVariantForObject((object)obj, pDstNativeVariant);
}
- [System.Security.SecurityCritical] // auto-generated_required
[MethodImplAttribute(MethodImplOptions.InternalCall)]
public static extern Object GetObjectForNativeVariant(/* VARIANT * */ IntPtr pSrcNativeVariant );
- [System.Security.SecurityCritical]
public static T GetObjectForNativeVariant<T>(IntPtr pSrcNativeVariant)
{
return (T)GetObjectForNativeVariant(pSrcNativeVariant);
}
- [System.Security.SecurityCritical] // auto-generated_required
[MethodImplAttribute(MethodImplOptions.InternalCall)]
public static extern Object[] GetObjectsForNativeVariants(/* VARIANT * */ IntPtr aSrcNativeVariant, int cVars );
- [System.Security.SecurityCritical]
public static T[] GetObjectsForNativeVariants<T>(IntPtr aSrcNativeVariant, int cVars)
{
object[] objects = GetObjectsForNativeVariants(aSrcNativeVariant, cVars);
@@ -2294,14 +1955,12 @@ namespace System.Runtime.InteropServices
/// <para>Returns the first valid COM slot that GetMethodInfoForSlot will work on
/// This will be 3 for IUnknown based interfaces and 7 for IDispatch based interfaces. </para>
/// </summary>
- [System.Security.SecurityCritical] // auto-generated_required
[MethodImplAttribute(MethodImplOptions.InternalCall)]
public static extern int GetStartComSlot(Type t);
/// <summary>
/// <para>Returns the last valid COM slot that GetMethodInfoForSlot will work on. </para>
/// </summary>
- [System.Security.SecurityCritical] // auto-generated_required
[MethodImplAttribute(MethodImplOptions.InternalCall)]
public static extern int GetEndComSlot(Type t);
@@ -2312,7 +1971,6 @@ namespace System.Runtime.InteropServices
/// For classes, the lookup is done on the default interface that will be
/// exposed for the class. </para>
/// </summary>
- [System.Security.SecurityCritical] // auto-generated_required
[MethodImplAttribute(MethodImplOptions.InternalCall)]
public static extern MemberInfo GetMethodInfoForComSlot(Type t, int slot, ref ComMemberType memberType);
@@ -2320,19 +1978,18 @@ namespace System.Runtime.InteropServices
/// <para>Returns the COM slot for a memeber info, taking into account whether
/// the exposed interface is IUnknown based or IDispatch based</para>
/// </summary>
- [System.Security.SecurityCritical] // auto-generated_required
public static int GetComSlotForMethodInfo(MemberInfo m)
{
if (m== null)
- throw new ArgumentNullException("m");
+ throw new ArgumentNullException(nameof(m));
if (!(m is RuntimeMethodInfo))
- throw new ArgumentException(Environment.GetResourceString("Argument_MustBeRuntimeMethodInfo"), "m");
+ throw new ArgumentException(Environment.GetResourceString("Argument_MustBeRuntimeMethodInfo"), nameof(m));
if (!m.DeclaringType.IsInterface)
- throw new ArgumentException(Environment.GetResourceString("Argument_MustBeInterfaceMethod"), "m");
+ throw new ArgumentException(Environment.GetResourceString("Argument_MustBeInterfaceMethod"), nameof(m));
if (m.DeclaringType.IsGenericType)
- throw new ArgumentException(Environment.GetResourceString("Argument_NeedNonGenericType"), "m");
+ throw new ArgumentException(Environment.GetResourceString("Argument_NeedNonGenericType"), nameof(m));
Contract.EndContractBlock();
return InternalGetComSlotForMethodInfo((IRuntimeMethodInfo)m);
@@ -2340,6 +1997,7 @@ namespace System.Runtime.InteropServices
[MethodImplAttribute(MethodImplOptions.InternalCall)]
private static extern int InternalGetComSlotForMethodInfo(IRuntimeMethodInfo m);
+#endif // FEATURE_COMINTEROP
//====================================================================
// This method generates a GUID for the specified type. If the type
@@ -2347,38 +2005,27 @@ namespace System.Runtime.InteropServices
// guid GUID is generated based on the fully qualified name of the
// type.
//====================================================================
- [System.Security.SecurityCritical] // auto-generated_required
public static Guid GenerateGuidForType(Type type)
{
- Guid result = new Guid ();
- FCallGenerateGuidForType (ref result, type);
- return result;
+ return type.GUID;
}
- // The full assembly name is used to compute the GUID, so this should be SxS-safe
- [MethodImplAttribute(MethodImplOptions.InternalCall)]
- private static extern void FCallGenerateGuidForType(ref Guid result, Type type);
-
//====================================================================
// 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.
//====================================================================
- [System.Security.SecurityCritical] // auto-generated_required
public static String GenerateProgIdForType(Type type)
{
if (type == null)
- throw new ArgumentNullException("type");
+ throw new ArgumentNullException(nameof(type));
if (type.IsImport)
- throw new ArgumentException(Environment.GetResourceString("Argument_TypeMustNotBeComImport"), "type");
+ throw new ArgumentException(Environment.GetResourceString("Argument_TypeMustNotBeComImport"), nameof(type));
if (type.IsGenericType)
- throw new ArgumentException(Environment.GetResourceString("Argument_NeedNonGenericType"), "type");
+ throw new ArgumentException(Environment.GetResourceString("Argument_NeedNonGenericType"), nameof(type));
Contract.EndContractBlock();
- if (!RegistrationServices.TypeRequiresRegistrationHelper(type))
- throw new ArgumentException(Environment.GetResourceString("Argument_TypeMustBeComCreatable"), "type");
-
IList<CustomAttributeData> cas = CustomAttributeData.GetCustomAttributes(type);
for (int i = 0; i < cas.Count; i ++)
{
@@ -2386,10 +2033,10 @@ namespace System.Runtime.InteropServices
{
// Retrieve the PROGID string from the ProgIdAttribute.
IList<CustomAttributeTypedArgument> caConstructorArgs = cas[i].ConstructorArguments;
- Contract.Assert(caConstructorArgs.Count == 1, "caConstructorArgs.Count == 1");
+ Debug.Assert(caConstructorArgs.Count == 1, "caConstructorArgs.Count == 1");
CustomAttributeTypedArgument progIdConstructorArg = caConstructorArgs[0];
- Contract.Assert(progIdConstructorArg.ArgumentType == typeof(String), "progIdConstructorArg.ArgumentType == typeof(String)");
+ Debug.Assert(progIdConstructorArg.ArgumentType == typeof(String), "progIdConstructorArg.ArgumentType == typeof(String)");
String strProgId = (String)progIdConstructorArg.Value;
@@ -2404,10 +2051,10 @@ namespace System.Runtime.InteropServices
return type.FullName;
}
+#if FEATURE_COMINTEROP
//====================================================================
// This method binds to the specified moniker.
//====================================================================
- [System.Security.SecurityCritical] // auto-generated_required
public static Object BindToMoniker(String monikerName)
{
Object obj = null;
@@ -2425,7 +2072,6 @@ namespace System.Runtime.InteropServices
//====================================================================
// This method gets the currently running object.
//====================================================================
- [System.Security.SecurityCritical] // auto-generated_required
public static Object GetActiveObject(String progID)
{
Object obj = null;
@@ -2449,32 +2095,26 @@ namespace System.Runtime.InteropServices
[DllImport(Microsoft.Win32.Win32Native.OLE32, PreserveSig = false)]
[SuppressUnmanagedCodeSecurity]
- [System.Security.SecurityCritical] // auto-generated
private static extern void CLSIDFromProgIDEx([MarshalAs(UnmanagedType.LPWStr)] String progId, out Guid clsid);
[DllImport(Microsoft.Win32.Win32Native.OLE32, PreserveSig = false)]
[SuppressUnmanagedCodeSecurity]
- [System.Security.SecurityCritical] // auto-generated
private static extern void CLSIDFromProgID([MarshalAs(UnmanagedType.LPWStr)] String progId, out Guid clsid);
[DllImport(Microsoft.Win32.Win32Native.OLE32, PreserveSig = false)]
[SuppressUnmanagedCodeSecurity]
- [System.Security.SecurityCritical] // auto-generated
private static extern void CreateBindCtx(UInt32 reserved, out IBindCtx ppbc);
[DllImport(Microsoft.Win32.Win32Native.OLE32, PreserveSig = false)]
[SuppressUnmanagedCodeSecurity]
- [System.Security.SecurityCritical] // auto-generated
private static extern void MkParseDisplayName(IBindCtx pbc, [MarshalAs(UnmanagedType.LPWStr)] String szUserName, out UInt32 pchEaten, out IMoniker ppmk);
[DllImport(Microsoft.Win32.Win32Native.OLE32, PreserveSig = false)]
[SuppressUnmanagedCodeSecurity]
- [System.Security.SecurityCritical] // auto-generated
private static extern void BindMoniker(IMoniker pmk, UInt32 grfOpt, ref Guid iidResult, [MarshalAs(UnmanagedType.Interface)] out Object ppvResult);
[DllImport(Microsoft.Win32.Win32Native.OLEAUT32, PreserveSig = false)]
[SuppressUnmanagedCodeSecurity]
- [System.Security.SecurityCritical] // auto-generated
private static extern void GetActiveObject(ref Guid rclsid, IntPtr reserved, [MarshalAs(UnmanagedType.Interface)] out Object ppunk);
//========================================================================
@@ -2489,7 +2129,6 @@ namespace System.Runtime.InteropServices
//========================================================================
// Private method called from EE upon use of license/ICF2 marshaling.
//========================================================================
- [SecurityCritical]
private static IntPtr LoadLicenseManager()
{
Assembly sys = Assembly.Load("System, Version="+ ThisAssembly.Version +
@@ -2500,16 +2139,13 @@ namespace System.Runtime.InteropServices
return t.TypeHandle.Value;
}
- [System.Security.SecurityCritical] // auto-generated_required
[MethodImplAttribute(MethodImplOptions.InternalCall)]
public static extern void ChangeWrapperHandleStrength(Object otp, bool fIsWeak);
- [System.Security.SecurityCritical]
[MethodImplAttribute(MethodImplOptions.InternalCall)]
internal static extern void InitializeWrapperForWinRT(object o, ref IntPtr pUnk);
#if FEATURE_COMINTEROP_WINRT_MANAGED_ACTIVATION
- [System.Security.SecurityCritical]
[MethodImplAttribute(MethodImplOptions.InternalCall)]
internal static extern void InitializeManagedWinRTFactoryObject(object o, RuntimeType runtimeClassType);
#endif
@@ -2517,7 +2153,6 @@ namespace System.Runtime.InteropServices
//========================================================================
// Create activation factory and wraps it with a unique RCW
//========================================================================
- [System.Security.SecurityCritical]
[MethodImplAttribute(MethodImplOptions.InternalCall)]
internal static extern object GetNativeActivationFactory(Type type);
@@ -2525,11 +2160,9 @@ namespace System.Runtime.InteropServices
// Methods allowing retrieval of the IIDs exposed by an underlying WinRT
// object, as specified by the object's IInspectable::GetIids()
//========================================================================
- [System.Security.SecurityCritical]
[DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode), SuppressUnmanagedCodeSecurity]
private static extern void _GetInspectableIids(ObjectHandleOnStack obj, ObjectHandleOnStack guids);
- [System.Security.SecurityCritical]
internal static System.Guid[] GetInspectableIids(object obj)
{
System.Guid[] result = null;
@@ -2547,14 +2180,12 @@ namespace System.Runtime.InteropServices
// Methods allowing retrieval of the cached WinRT type corresponding to
// the specified GUID
//========================================================================
- [System.Security.SecurityCritical]
[DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode), SuppressUnmanagedCodeSecurity]
private static extern void _GetCachedWinRTTypeByIid(
ObjectHandleOnStack appDomainObj,
System.Guid iid,
out IntPtr rthHandle);
- [System.Security.SecurityCritical]
internal static System.Type GetCachedWinRTTypeByIid(
System.AppDomain ad,
System.Guid iid)
@@ -2572,14 +2203,12 @@ namespace System.Runtime.InteropServices
// Methods allowing retrieval of the WinRT types cached in the specified
// app domain
//========================================================================
- [System.Security.SecurityCritical]
[DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode), SuppressUnmanagedCodeSecurity]
private static extern void _GetCachedWinRTTypes(
ObjectHandleOnStack appDomainObj,
ref int epoch,
ObjectHandleOnStack winrtTypes);
- [System.Security.SecurityCritical]
internal static System.Type[] GetCachedWinRTTypes(
System.AppDomain ad,
ref int epoch)
@@ -2599,7 +2228,6 @@ namespace System.Runtime.InteropServices
return result;
}
- [System.Security.SecurityCritical]
internal static System.Type[] GetCachedWinRTTypes(
System.AppDomain ad)
{
@@ -2610,31 +2238,29 @@ namespace System.Runtime.InteropServices
#endif // FEATURE_COMINTEROP
- [System.Security.SecurityCritical] // auto-generated_required
public static Delegate GetDelegateForFunctionPointer(IntPtr ptr, Type t)
{
// Validate the parameters
if (ptr == IntPtr.Zero)
- throw new ArgumentNullException("ptr");
+ throw new ArgumentNullException(nameof(ptr));
if (t == null)
- throw new ArgumentNullException("t");
+ throw new ArgumentNullException(nameof(t));
Contract.EndContractBlock();
if ((t as RuntimeType) == null)
- throw new ArgumentException(Environment.GetResourceString("Argument_MustBeRuntimeType"), "t");
+ throw new ArgumentException(Environment.GetResourceString("Argument_MustBeRuntimeType"), nameof(t));
if (t.IsGenericType)
- throw new ArgumentException(Environment.GetResourceString("Argument_NeedNonGenericType"), "t");
+ throw new ArgumentException(Environment.GetResourceString("Argument_NeedNonGenericType"), nameof(t));
Type c = t.BaseType;
if (c == null || (c != typeof(Delegate) && c != typeof(MulticastDelegate)))
- throw new ArgumentException(Environment.GetResourceString("Arg_MustBeDelegate"), "t");
+ throw new ArgumentException(Environment.GetResourceString("Arg_MustBeDelegate"), nameof(t));
return GetDelegateForFunctionPointerInternal(ptr, t);
}
- [System.Security.SecurityCritical]
public static TDelegate GetDelegateForFunctionPointer<TDelegate>(IntPtr ptr)
{
return (TDelegate)(object)GetDelegateForFunctionPointer(ptr, typeof(TDelegate));
@@ -2643,17 +2269,15 @@ namespace System.Runtime.InteropServices
[MethodImplAttribute(MethodImplOptions.InternalCall)]
internal static extern Delegate GetDelegateForFunctionPointerInternal(IntPtr ptr, Type t);
- [System.Security.SecurityCritical] // auto-generated_required
public static IntPtr GetFunctionPointerForDelegate(Delegate d)
{
if (d == null)
- throw new ArgumentNullException("d");
+ throw new ArgumentNullException(nameof(d));
Contract.EndContractBlock();
return GetFunctionPointerForDelegateInternal(d);
}
- [System.Security.SecurityCritical]
public static IntPtr GetFunctionPointerForDelegate<TDelegate>(TDelegate d)
{
return GetFunctionPointerForDelegate((Delegate)(object)d);
@@ -2662,47 +2286,39 @@ namespace System.Runtime.InteropServices
[MethodImplAttribute(MethodImplOptions.InternalCall)]
internal static extern IntPtr GetFunctionPointerForDelegateInternal(Delegate d);
-#if FEATURE_LEGACYSURFACE
-
-#if FEATURE_COMINTEROP
- [System.Security.SecurityCritical] // auto-generated_required
public static IntPtr SecureStringToBSTR(SecureString s) {
if( s == null) {
- throw new ArgumentNullException("s");
+ throw new ArgumentNullException(nameof(s));
}
Contract.EndContractBlock();
- return s.ToBSTR();
- }
+#if FEATURE_COMINTEROP
+ return s.MarshalToBSTR();
+#else
+ throw new PlatformNotSupportedException();
#endif
+ }
- [System.Security.SecurityCritical] // auto-generated_required
public static IntPtr SecureStringToCoTaskMemAnsi(SecureString s) {
if( s == null) {
- throw new ArgumentNullException("s");
+ throw new ArgumentNullException(nameof(s));
}
Contract.EndContractBlock();
- return s.ToAnsiStr(false);
+ return s.MarshalToString(globalAlloc: false, unicode: false);
}
- [System.Security.SecurityCritical] // auto-generated_required
public static IntPtr SecureStringToCoTaskMemUnicode(SecureString s)
{
- if (s == null)
- {
- throw new ArgumentNullException("s");
+ if( s == null) {
+ throw new ArgumentNullException(nameof(s));
}
Contract.EndContractBlock();
- return s.ToUniStr(false);
+ return s.MarshalToString(globalAlloc: false, unicode: true);
}
-#endif // FEATURE_LEGACYSURFACE
-
-
#if FEATURE_COMINTEROP
- [System.Security.SecurityCritical] // auto-generated_required
public static void ZeroFreeBSTR(IntPtr s)
{
Win32Native.ZeroMemory(s, (UIntPtr)(Win32Native.SysStringLen(s) * 2));
@@ -2710,97 +2326,51 @@ namespace System.Runtime.InteropServices
}
#endif
- [System.Security.SecurityCritical] // auto-generated_required
public static void ZeroFreeCoTaskMemAnsi(IntPtr s)
{
Win32Native.ZeroMemory(s, (UIntPtr)(Win32Native.lstrlenA(s)));
FreeCoTaskMem(s);
}
- [System.Security.SecurityCritical] // auto-generated_required
public static void ZeroFreeCoTaskMemUnicode(IntPtr s)
{
Win32Native.ZeroMemory(s, (UIntPtr)(Win32Native.lstrlenW(s) * 2));
FreeCoTaskMem(s);
}
- [System.Security.SecurityCritical] // auto-generated_required
unsafe public static void ZeroFreeCoTaskMemUTF8(IntPtr s)
{
Win32Native.ZeroMemory(s, (UIntPtr)System.StubHelpers.StubHelpers.strlen((sbyte*)s));
FreeCoTaskMem(s);
}
-#if FEATURE_LEGACYSURFACE
- [System.Security.SecurityCritical] // auto-generated_required
public static IntPtr SecureStringToGlobalAllocAnsi(SecureString s) {
if( s == null) {
- throw new ArgumentNullException("s");
+ throw new ArgumentNullException(nameof(s));
}
Contract.EndContractBlock();
- return s.ToAnsiStr(true);
+ return s.MarshalToString(globalAlloc: true, unicode: false);
}
- [System.Security.SecurityCritical] // auto-generated_required
public static IntPtr SecureStringToGlobalAllocUnicode(SecureString s) {
if( s == null) {
- throw new ArgumentNullException("s");
+ throw new ArgumentNullException(nameof(s));
}
Contract.EndContractBlock();
- return s.ToUniStr(true);
+ return s.MarshalToString(globalAlloc: true, unicode: true);;
}
-#endif // FEATURE_LEGACYSURFACE
- [System.Security.SecurityCritical] // auto-generated_required
public static void ZeroFreeGlobalAllocAnsi(IntPtr s) {
Win32Native.ZeroMemory(s, (UIntPtr)(Win32Native.lstrlenA(s)));
FreeHGlobal(s);
}
- [System.Security.SecurityCritical] // auto-generated_required
public static void ZeroFreeGlobalAllocUnicode(IntPtr s) {
Win32Native.ZeroMemory(s, (UIntPtr)(Win32Native.lstrlenW(s) * 2));
FreeHGlobal(s);
}
}
-
-#if FEATURE_COMINTEROP && !FEATURE_CORECLR // current implementation requires reflection only load
- //========================================================================
- // Typelib importer callback implementation.
- //========================================================================
- internal class ImporterCallback : ITypeLibImporterNotifySink
- {
- public void ReportEvent(ImporterEventKind EventKind, int EventCode, String EventMsg)
- {
- }
-
- [System.Security.SecuritySafeCritical] // overrides transparent public member
- public Assembly ResolveRef(Object TypeLib)
- {
- try
- {
- // Create the TypeLibConverter.
- ITypeLibConverter TLBConv = new TypeLibConverter();
-
- // Convert the typelib.
- return TLBConv.ConvertTypeLibToAssembly(TypeLib,
- Marshal.GetTypeLibName((ITypeLib)TypeLib) + ".dll",
- 0,
- new ImporterCallback(),
- null,
- null,
- null,
- null);
- }
- catch(Exception)
-// catch
- {
- return null;
- }
- }
- }
-#endif // FEATURE_COMINTEROP && !FEATURE_CORECLR
}