summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJan Kotas <jkotas@microsoft.com>2017-11-21 11:20:00 -0800
committerGitHub <noreply@github.com>2017-11-21 11:20:00 -0800
commit60222780cde77346bff1eb8979846769c223f833 (patch)
tree4185790997bcb331ca9701fad7d30a891897a6d8 /src
parent87fb7de212e7448638579d65c2f5574aa333bddd (diff)
downloadcoreclr-60222780cde77346bff1eb8979846769c223f833.tar.gz
coreclr-60222780cde77346bff1eb8979846769c223f833.tar.bz2
coreclr-60222780cde77346bff1eb8979846769c223f833.zip
Move SafeBuffer and a few other files to shared CoreLib partition (#15141)
Diffstat (limited to 'src')
-rw-r--r--src/mscorlib/System.Private.CoreLib.csproj10
-rw-r--r--src/mscorlib/shared/System.Private.CoreLib.Shared.projitems7
-rw-r--r--src/mscorlib/shared/System/Runtime/ExceptionServices/ExceptionNotification.cs18
-rw-r--r--src/mscorlib/shared/System/Runtime/InteropServices/MarshalDirectiveException.cs (renamed from src/mscorlib/src/System/Runtime/InteropServices/MarshalDirectiveException.cs)0
-rw-r--r--src/mscorlib/shared/System/Runtime/InteropServices/SafeBuffer.cs (renamed from src/mscorlib/src/System/Runtime/InteropServices/SafeBuffer.cs)164
-rw-r--r--src/mscorlib/shared/System/Text/Normalization.Unix.cs (renamed from src/mscorlib/src/System/Text/Normalization.Unix.cs)0
-rw-r--r--src/mscorlib/shared/System/Threading/Tasks/TaskCompletionSource.cs (renamed from src/mscorlib/src/System/Threading/Tasks/TaskCompletionSource.cs)0
-rw-r--r--src/mscorlib/src/System/Runtime/ExceptionServices/ExceptionDispatchInfo.cs (renamed from src/mscorlib/src/System/Runtime/ExceptionServices/ExceptionServicesCommon.cs)0
-rw-r--r--src/mscorlib/src/System/Runtime/ExceptionServices/ExceptionNotification.cs37
-rw-r--r--src/mscorlib/src/System/Runtime/InteropServices/ITypeLibConverter.cs26
-rw-r--r--src/vm/ecalllist.h8
-rw-r--r--src/vm/nativeoverlapped.h3
-rw-r--r--src/vm/object.h52
-rw-r--r--src/vm/safehandle.cpp57
14 files changed, 98 insertions, 284 deletions
diff --git a/src/mscorlib/System.Private.CoreLib.csproj b/src/mscorlib/System.Private.CoreLib.csproj
index e39b73e5f8..9dd49af077 100644
--- a/src/mscorlib/System.Private.CoreLib.csproj
+++ b/src/mscorlib/System.Private.CoreLib.csproj
@@ -153,12 +153,10 @@
<Compile Include="$(BclSourcesRoot)\System\Runtime\InteropServices\ICustomMarshaler.cs" />
<Compile Include="$(BclSourcesRoot)\System\Runtime\InteropServices\InvalidOleVariantTypeException.cs" />
<Compile Include="$(BclSourcesRoot)\System\Runtime\InteropServices\Marshal.cs" />
- <Compile Include="$(BclSourcesRoot)\System\Runtime\InteropServices\MarshalDirectiveException.cs" />
<Compile Include="$(BclSourcesRoot)\System\Runtime\InteropServices\PInvokeMap.cs" />
<Compile Include="$(BclSourcesRoot)\System\Runtime\InteropServices\PInvokeMarshal.cs" />
<Compile Include="$(BclSourcesRoot)\System\Runtime\InteropServices\RuntimeEnvironment.cs" />
<Compile Include="$(BclSourcesRoot)\System\Runtime\InteropServices\SEHException.cs" />
- <Compile Include="$(BclSourcesRoot)\System\Runtime\InteropServices\SafeBuffer.cs" />
<Compile Include="$(BclSourcesRoot)\System\Runtime\InteropServices\SafeHandle.cs" />
<Compile Include="$(BclSourcesRoot)\System\Runtime\InteropServices\BStrWrapper.cs" />
<Compile Include="$(BclSourcesRoot)\System\Runtime\InteropServices\CurrencyWrapper.cs" />
@@ -176,9 +174,6 @@
<Compile Condition="'$(FeatureCominterop)' == 'true'" Include="$(BclSourcesRoot)\System\Runtime\InteropServices\DispatchWrapper.cs" />
<Compile Include="$(BclSourcesRoot)\System\Runtime\InteropServices\ICustomFactory.cs" />
</ItemGroup>
- <ItemGroup Condition="'$(FeatureClassicCominterop)' == 'true'">
- <Compile Include="$(BclSourcesRoot)\System\Runtime\InteropServices\ITypeLibConverter.cs" />
- </ItemGroup>
<ItemGroup>
<Compile Include="$(BclSourcesRoot)\System\Runtime\InteropServices\Expando\IExpando.cs" />
</ItemGroup>
@@ -499,7 +494,6 @@
<Compile Include="$(BclSourcesRoot)\System\Threading\Tasks\TaskFactory.cs" />
<Compile Include="$(BclSourcesRoot)\System\Threading\Tasks\TaskScheduler.cs" />
<Compile Include="$(BclSourcesRoot)\System\Threading\Tasks\ThreadPoolTaskScheduler.cs" />
- <Compile Include="$(BclSourcesRoot)\System\Threading\Tasks\TaskCompletionSource.cs" />
<Compile Include="$(BclSourcesRoot)\System\Threading\Tasks\AsyncCausalityTracer.cs" />
<Compile Include="$(BclSourcesRoot)\System\Threading\Tasks\ConcurrentExclusiveSchedulerPair.cs" />
<Compile Include="$(BclSourcesRoot)\System\Threading\Tasks\ProducerConsumerQueues.cs" />
@@ -546,8 +540,7 @@
<Compile Include="$(BclSourcesRoot)\System\Diagnostics\SymbolStore\Token.cs" />
</ItemGroup>
<ItemGroup>
- <Compile Include="$(BclSourcesRoot)\System\Runtime\ExceptionServices\ExceptionServicesCommon.cs" />
- <Compile Include="$(BclSourcesRoot)\System\Runtime\ExceptionServices\ExceptionNotification.cs" />
+ <Compile Include="$(BclSourcesRoot)\System\Runtime\ExceptionServices\ExceptionDispatchInfo.cs" />
</ItemGroup>
<ItemGroup>
<Compile Include="$(BclSourcesRoot)\System\Runtime\Loader\AssemblyLoadContext.cs" />
@@ -607,7 +600,6 @@
<Compile Include="$(BclSourcesRoot)\System\IO\TextReader.cs" />
<Compile Include="$(BclSourcesRoot)\System\IO\StreamReader.cs" />
<Compile Include="$(BclSourcesRoot)\System\Runtime\Versioning\CompatibilitySwitch.cs" />
- <Compile Include="$(BclSourcesRoot)\System\Text\Normalization.Unix.cs" />
<Compile Include="$(BclSourcesRoot)\System\Threading\ClrThreadPoolBoundHandle.Unix.cs" />
<Compile Include="$(BclSourcesRoot)\System\TimeZoneInfo.Unix.cs" />
</ItemGroup>
diff --git a/src/mscorlib/shared/System.Private.CoreLib.Shared.projitems b/src/mscorlib/shared/System.Private.CoreLib.Shared.projitems
index ab7dc93b4e..f1eeb04164 100644
--- a/src/mscorlib/shared/System.Private.CoreLib.Shared.projitems
+++ b/src/mscorlib/shared/System.Private.CoreLib.Shared.projitems
@@ -400,6 +400,7 @@
<Compile Include="$(MSBuildThisFileDirectory)System\Runtime\ConstrainedExecution\Cer.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Runtime\ConstrainedExecution\Consistency.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Runtime\ConstrainedExecution\ReliabilityContractAttribute.cs" />
+ <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\ExceptionServices\ExceptionNotification.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Runtime\ExceptionServices\HandleProcessCorruptedStateExceptionsAttribute.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\BestFitMappingAttribute.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\CallingConvention.cs" />
@@ -414,10 +415,12 @@
<Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\InAttribute.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\LayoutKind.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\MarshalAsAttribute.cs" />
+ <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\MarshalDirectiveException.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\MemoryMarshal.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\OptionalAttribute.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\OutAttribute.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\PreserveSigAttribute.cs" />
+ <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\SafeBuffer.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\StringBuffer.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\StructLayoutAttribute.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\UnmanagedFunctionPointerAttribute.cs" />
@@ -512,6 +515,7 @@
<Compile Include="$(MSBuildThisFileDirectory)System\Threading\SpinWait.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Threading\SynchronizationLockException.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Threading\Tasks\TaskCanceledException.cs" />
+ <Compile Include="$(MSBuildThisFileDirectory)System\Threading\Tasks\TaskCompletionSource.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Threading\Tasks\TaskExtensions.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Threading\Tasks\TaskToApm.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Threading\Tasks\TaskSchedulerException.cs" />
@@ -704,13 +708,14 @@
<Compile Include="$(MSBuildThisFileDirectory)System\Globalization\CultureData.Unix.cs" Condition="'$(EnableDummyGlobalizationImplementation)' != 'true'" />
<Compile Include="$(MSBuildThisFileDirectory)System\Globalization\HijriCalendar.Unix.cs" Condition="'$(EnableDummyGlobalizationImplementation)' != 'true'" />
<Compile Include="$(MSBuildThisFileDirectory)System\Globalization\IdnMapping.Unix.cs" Condition="'$(EnableDummyGlobalizationImplementation)' != 'true'" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Globalization\LocaleData.Unix.cs" Condition="'$(EnableDummyGlobalizationImplementation)' != 'true'" />
<Compile Include="$(MSBuildThisFileDirectory)System\Globalization\JapaneseCalendar.Unix.cs" Condition="'$(EnableDummyGlobalizationImplementation)' != 'true'" />
+ <Compile Include="$(MSBuildThisFileDirectory)System\Globalization\LocaleData.Unix.cs" Condition="'$(EnableDummyGlobalizationImplementation)' != 'true'" />
<Compile Include="$(MSBuildThisFileDirectory)System\IO\FileStream.OSX.cs" Condition="'$(TargetsOSX)' == 'true'" />
<Compile Include="$(MSBuildThisFileDirectory)System\IO\FileStream.Linux.cs" Condition="'$(TargetsOSX)' != 'true'" />
<Compile Include="$(MSBuildThisFileDirectory)System\IO\FileStream.Unix.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\IO\Path.Unix.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\IO\PathInternal.Unix.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Security\SecureString.Unix.cs" />
+ <Compile Include="$(MSBuildThisFileDirectory)System\Text\Normalization.Unix.cs" Condition="'$(EnableDummyGlobalizationImplementation)' != 'true'" />
</ItemGroup>
</Project>
diff --git a/src/mscorlib/shared/System/Runtime/ExceptionServices/ExceptionNotification.cs b/src/mscorlib/shared/System/Runtime/ExceptionServices/ExceptionNotification.cs
new file mode 100644
index 0000000000..605588d657
--- /dev/null
+++ b/src/mscorlib/shared/System/Runtime/ExceptionServices/ExceptionNotification.cs
@@ -0,0 +1,18 @@
+// 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.ExceptionServices
+{
+ // Definition of the argument-type passed to the FirstChanceException event handler
+ public class FirstChanceExceptionEventArgs : EventArgs
+ {
+ public FirstChanceExceptionEventArgs(Exception exception)
+ {
+ Exception = exception;
+ }
+
+ // Returns the exception object pertaining to the first chance exception
+ public Exception Exception { get; }
+ }
+}
diff --git a/src/mscorlib/src/System/Runtime/InteropServices/MarshalDirectiveException.cs b/src/mscorlib/shared/System/Runtime/InteropServices/MarshalDirectiveException.cs
index 1d0d59fab6..1d0d59fab6 100644
--- a/src/mscorlib/src/System/Runtime/InteropServices/MarshalDirectiveException.cs
+++ b/src/mscorlib/shared/System/Runtime/InteropServices/MarshalDirectiveException.cs
diff --git a/src/mscorlib/src/System/Runtime/InteropServices/SafeBuffer.cs b/src/mscorlib/shared/System/Runtime/InteropServices/SafeBuffer.cs
index 0447ea51f7..4632b2a344 100644
--- a/src/mscorlib/src/System/Runtime/InteropServices/SafeBuffer.cs
+++ b/src/mscorlib/shared/System/Runtime/InteropServices/SafeBuffer.cs
@@ -4,16 +4,16 @@
/*============================================================
**
-** Purpose: Unsafe code that uses pointers should use
-** SafePointer to fix subtle lifetime problems with the
+** 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
+// *) 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
+// 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
@@ -24,23 +24,23 @@
// 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
+// 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
+// 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
+// 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.
//
@@ -65,14 +65,10 @@
// static variable (perhaps using Interlocked.CompareExchange). Of course,
// assignments in a static class constructor are under a lock implicitly.
-
using System;
-using System.Runtime.InteropServices;
+using System.Diagnostics;
using System.Runtime.CompilerServices;
-using System.Runtime.ConstrainedExecution;
-using System.Runtime.Versioning;
using Microsoft.Win32.SafeHandles;
-using System.Diagnostics;
namespace System.Runtime.InteropServices
{
@@ -90,7 +86,7 @@ namespace System.Runtime.InteropServices
}
/// <summary>
- /// Specifies the size of the region of memory, in bytes. Must be
+ /// 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>
@@ -107,7 +103,7 @@ namespace System.Runtime.InteropServices
}
/// <summary>
- /// Specifies the size of the region in memory, as the number of
+ /// 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)]
@@ -123,7 +119,7 @@ namespace System.Runtime.InteropServices
}
/// <summary>
- /// Specifies the size of the region in memory, as the number of
+ /// 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)]
@@ -133,13 +129,12 @@ namespace System.Runtime.InteropServices
}
// 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 in a CER. This method calls DangerousAddRef
- // & exposes the pointer. Unlike Read, it does not alter the "current
+ // 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;
- // RuntimeHelpers.PrepareConstrainedRegions();
// try {
// safeBuffer.AcquirePointer(ref pointer);
// // Use pointer here, with your own bounds checking
@@ -149,15 +144,15 @@ namespace System.Runtime.InteropServices
// safeBuffer.ReleasePointer();
// }
//
- // Note: If you cast this byte* to a T*, you have to worry about
+ // 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 within a CER to ensure the pointer can be
- /// freed later. This method either completes successfully or
- /// throws an exception and returns with pointer set to null.
+ /// 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
@@ -169,7 +164,6 @@ namespace System.Runtime.InteropServices
throw NotInitialized();
pointer = null;
- RuntimeHelpers.PrepareConstrainedRegions();
bool junk = false;
DangerousAddRef(ref junk);
@@ -189,7 +183,7 @@ namespace System.Runtime.InteropServices
/// 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
+ /// <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)]
@@ -203,14 +197,14 @@ namespace System.Runtime.InteropServices
SpaceCheck(ptr, sizeofT);
// return *(T*) (_ptr + byteOffset);
- T value;
+ T value = default(T);
bool mustCallRelease = false;
- RuntimeHelpers.PrepareConstrainedRegions();
try
{
DangerousAddRef(ref mustCallRelease);
- GenericPtrToStructure<T>(ptr, out value, sizeofT);
+ fixed (byte* pStructure = &Unsafe.As<T, byte>(ref value))
+ Buffer.Memmove(pStructure, ptr, sizeofT);
}
finally
{
@@ -242,13 +236,21 @@ namespace System.Runtime.InteropServices
SpaceCheck(ptr, checked((ulong)(alignedSizeofT * count)));
bool mustCallRelease = false;
- RuntimeHelpers.PrepareConstrainedRegions();
try
{
DangerousAddRef(ref mustCallRelease);
- for (int i = 0; i < count; i++)
- unsafe { GenericPtrToStructure<T>(ptr + alignedSizeofT * i, out array[i + index], sizeofT); }
+ if (count > 0)
+ {
+ unsafe
+ {
+ 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
{
@@ -262,7 +264,7 @@ namespace System.Runtime.InteropServices
/// 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
+ /// <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)]
@@ -277,11 +279,12 @@ namespace System.Runtime.InteropServices
// *((T*) (_ptr + byteOffset)) = value;
bool mustCallRelease = false;
- RuntimeHelpers.PrepareConstrainedRegions();
try
{
DangerousAddRef(ref mustCallRelease);
- GenericStructureToPtr(ref value, ptr, sizeofT);
+
+ fixed (byte* pStructure = &Unsafe.As<T, byte>(ref value))
+ Buffer.Memmove(ptr, pStructure, sizeofT);
}
finally
{
@@ -312,12 +315,21 @@ namespace System.Runtime.InteropServices
SpaceCheck(ptr, checked((ulong)(alignedSizeofT * count)));
bool mustCallRelease = false;
- RuntimeHelpers.PrepareConstrainedRegions();
try
{
DangerousAddRef(ref mustCallRelease);
- for (int i = 0; i < count; i++)
- unsafe { GenericStructureToPtr(ref array[i + index], ptr + alignedSizeofT * i, sizeofT); }
+
+ if (count > 0)
+ {
+ unsafe
+ {
+ 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
{
@@ -326,7 +338,6 @@ namespace System.Runtime.InteropServices
}
}
-
/// <summary>
/// Returns the number of bytes in the memory region.
/// </summary>
@@ -342,7 +353,7 @@ namespace System.Runtime.InteropServices
}
}
- /* No indexer. The perf would be misleadingly bad. People should use
+ /* No indexer. The perf would be misleadingly bad. People should use
* AcquirePointer and ReleasePointer instead. */
private void SpaceCheck(byte* ptr, ulong sizeInBytes)
@@ -363,62 +374,31 @@ namespace System.Runtime.InteropServices
return new InvalidOperationException(SR.InvalidOperation_MustCallInitialize);
}
- // FCALL limitations mean we can't have generic FCALL methods. However, we can pass
- // TypedReferences to FCALL methods.
- internal static void GenericPtrToStructure<T>(byte* ptr, out T structure, uint sizeofT) where T : struct
- {
- structure = default(T); // Dummy assignment to silence the compiler
- PtrToStructureNative(ptr, __makeref(structure), sizeofT);
- }
-
- [MethodImpl(MethodImplOptions.InternalCall)]
- private static extern void PtrToStructureNative(byte* ptr, /*out T*/ TypedReference structure, uint sizeofT);
-
- internal static void GenericStructureToPtr<T>(ref T structure, byte* ptr, uint sizeofT) where T : struct
- {
- StructureToPtrNative(__makeref(structure), ptr, sizeofT);
- }
-
- [MethodImpl(MethodImplOptions.InternalCall)]
- private static extern void StructureToPtrNative(/*ref T*/ TypedReference structure, byte* ptr, uint sizeofT);
-
- /// <summary>
- /// Returns the aligned size of an instance of a value type.
- /// </summary>
- /// <typeparam name="T">Provide a value type to figure out its size</typeparam>
- /// <returns>The aligned size of T in bytes.</returns>
- internal static uint SizeOf<T>() where T : struct
- {
- return SizeOfType(typeof(T));
- }
-
/// <summary>
- /// Returns the aligned size of an instance of a value type.
+ /// 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>
- /// <typeparam name="T">Provide a value type to figure out its size</typeparam>
- /// <returns>The aligned size of T in bytes.</returns>
internal static uint AlignedSizeOf<T>() where T : struct
{
- uint size = SizeOfType(typeof(T));
+ uint size = SizeOf<T>();
if (size == 1 || size == 2)
{
return size;
}
- if (IntPtr.Size == 8 && size == 4)
- {
- return size;
- }
- return AlignedSizeOfType(typeof(T));
+
+ return (uint)(((size + 3) & (~3)));
}
- // Type must be a value type with no object reference fields. We only
- // assert this, due to the lack of a suitable generic constraint.
- [MethodImpl(MethodImplOptions.InternalCall)]
- private static extern uint SizeOfType(Type type);
+ /// <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);
- // Type must be a value type with no object reference fields. We only
- // assert this, due to the lack of a suitable generic constraint.
- [MethodImpl(MethodImplOptions.InternalCall)]
- private static extern uint AlignedSizeOfType(Type type);
+ return (uint)Unsafe.SizeOf<T>();
+ }
}
}
diff --git a/src/mscorlib/src/System/Text/Normalization.Unix.cs b/src/mscorlib/shared/System/Text/Normalization.Unix.cs
index 2a10d062f2..2a10d062f2 100644
--- a/src/mscorlib/src/System/Text/Normalization.Unix.cs
+++ b/src/mscorlib/shared/System/Text/Normalization.Unix.cs
diff --git a/src/mscorlib/src/System/Threading/Tasks/TaskCompletionSource.cs b/src/mscorlib/shared/System/Threading/Tasks/TaskCompletionSource.cs
index dc59caf04f..dc59caf04f 100644
--- a/src/mscorlib/src/System/Threading/Tasks/TaskCompletionSource.cs
+++ b/src/mscorlib/shared/System/Threading/Tasks/TaskCompletionSource.cs
diff --git a/src/mscorlib/src/System/Runtime/ExceptionServices/ExceptionServicesCommon.cs b/src/mscorlib/src/System/Runtime/ExceptionServices/ExceptionDispatchInfo.cs
index 0a379667d7..0a379667d7 100644
--- a/src/mscorlib/src/System/Runtime/ExceptionServices/ExceptionServicesCommon.cs
+++ b/src/mscorlib/src/System/Runtime/ExceptionServices/ExceptionDispatchInfo.cs
diff --git a/src/mscorlib/src/System/Runtime/ExceptionServices/ExceptionNotification.cs b/src/mscorlib/src/System/Runtime/ExceptionServices/ExceptionNotification.cs
deleted file mode 100644
index d986ea9c24..0000000000
--- a/src/mscorlib/src/System/Runtime/ExceptionServices/ExceptionNotification.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.
-/*=============================================================================
-**
-**
-**
-** Purpose: Contains definitions for supporting Exception Notifications.
-**
-** Created: 10/07/2008
-**
-**
-=============================================================================*/
-using System;
-using System.Runtime.ConstrainedExecution;
-
-namespace System.Runtime.ExceptionServices
-{
- // Definition of the argument-type passed to the FirstChanceException event handler
- public class FirstChanceExceptionEventArgs : EventArgs
- {
- // Constructor
- public FirstChanceExceptionEventArgs(Exception exception)
- {
- m_Exception = exception;
- }
-
- // Returns the exception object pertaining to the first chance exception
- public Exception Exception
- {
- get { return m_Exception; }
- }
-
- // Represents the FirstChance exception instance
- private Exception m_Exception;
- }
-}
diff --git a/src/mscorlib/src/System/Runtime/InteropServices/ITypeLibConverter.cs b/src/mscorlib/src/System/Runtime/InteropServices/ITypeLibConverter.cs
deleted file mode 100644
index 85756cf84f..0000000000
--- a/src/mscorlib/src/System/Runtime/InteropServices/ITypeLibConverter.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.
-
-/*=============================================================================
-**
-**
-**
-** Purpose: Methods used to convert a TypeLib to metadata and vice versa.
-**
-**
-=============================================================================*/
-
-// ***************************************************************************
-// *** Note: The following definitions must remain synchronized with the IDL
-// *** in src/inc/TlbImpExp.idl.
-// ***************************************************************************
-
-
-using System;
-using System.Reflection;
-using System.Reflection.Emit;
-
-namespace System.Runtime.InteropServices
-{
-}
diff --git a/src/vm/ecalllist.h b/src/vm/ecalllist.h
index 207e89ac3e..14ce9dd13b 100644
--- a/src/vm/ecalllist.h
+++ b/src/vm/ecalllist.h
@@ -198,13 +198,6 @@ FCFuncStart(gCriticalHandleFuncs)
FCFuncElement("FireCustomerDebugProbe", CriticalHandle::FireCustomerDebugProbe)
FCFuncEnd()
-FCFuncStart(gSafeBufferFuncs)
- FCFuncElement("PtrToStructureNative", SafeBuffer::PtrToStructure)
- FCFuncElement("StructureToPtrNative", SafeBuffer::StructureToPtr)
- FCFuncElement("SizeOfType", SafeBuffer::SizeOfType)
- FCFuncElement("AlignedSizeOfType", SafeBuffer::AlignedSizeOfType)
-FCFuncEnd()
-
FCFuncStart(gTypedReferenceFuncs)
FCFuncElement("InternalToObject", ReflectionInvocation::TypedReferenceToObject)
FCFuncElement("InternalSetTypedReference", ReflectionInvocation::SetTypedReference)
@@ -1386,7 +1379,6 @@ FCClassElement("RuntimeModule", "System.Reflection", gCOMModuleFuncs)
FCClassElement("RuntimeThread", "Internal.Runtime.Augments", gRuntimeThreadFuncs)
FCClassElement("RuntimeType", "System", gSystem_RuntimeType)
FCClassElement("RuntimeTypeHandle", "System", gCOMTypeHandleFuncs)
-FCClassElement("SafeBuffer", "System.Runtime.InteropServices", gSafeBufferFuncs)
FCClassElement("SafeHandle", "System.Runtime.InteropServices", gSafeHandleFuncs)
FCClassElement("SafeTypeNameParserHandle", "System", gSafeTypeNameParserHandle)
diff --git a/src/vm/nativeoverlapped.h b/src/vm/nativeoverlapped.h
index 0c0693dca6..7f12f477e8 100644
--- a/src/vm/nativeoverlapped.h
+++ b/src/vm/nativeoverlapped.h
@@ -21,8 +21,7 @@
class OverlappedDataObject : public Object
{
public:
- ASYNCRESULTREF m_asyncResult;
-
+ OBJECTREF m_asyncResult;
OBJECTREF m_iocb;
OBJECTREF m_iocbHelper;
OBJECTREF m_overlapped;
diff --git a/src/vm/object.h b/src/vm/object.h
index 0fdcff39a8..a79e846621 100644
--- a/src/vm/object.h
+++ b/src/vm/object.h
@@ -2955,20 +2955,6 @@ class CriticalHandle : public Object
};
-class ReflectClassBaseObject;
-
-class SafeBuffer : SafeHandle
-{
- private:
- size_t m_numBytes;
-
- public:
- static FCDECL1(UINT, SizeOfType, ReflectClassBaseObject* typeUNSAFE);
- static FCDECL1(UINT, AlignedSizeOfType, ReflectClassBaseObject* typeUNSAFE);
- static FCDECL3_IVI(void, PtrToStructure, BYTE* ptr, FC_TypedByRef structure, UINT32 sizeofT);
- static FCDECL3_VII(void, StructureToPtr, FC_TypedByRef structure, BYTE* ptr, UINT32 sizeofT);
-};
-
#ifdef USE_CHECKED_OBJECTREFS
typedef REF<CriticalHandle> CRITICALHANDLE;
typedef REF<CriticalHandle> CRITICALHANDLEREF;
@@ -3000,44 +2986,6 @@ typedef REF<WaitHandleBase> WAITHANDLEREF;
typedef WaitHandleBase* WAITHANDLEREF;
#endif // USE_CHECKED_OBJECTREFS
-// This class corresponds to FileStreamAsyncResult on the managed side.
-class AsyncResultBase :public Object
-{
- friend class MscorlibBinder;
-
-public:
- WAITHANDLEREF GetWaitHandle() { LIMITED_METHOD_CONTRACT; return _waitHandle;}
- void SetErrorCode(int errcode) { LIMITED_METHOD_CONTRACT; _errorCode = errcode;}
- void SetNumBytes(int numBytes) { LIMITED_METHOD_CONTRACT; _numBytes = numBytes;}
- void SetIsComplete() { LIMITED_METHOD_CONTRACT; _isComplete = TRUE; }
- void SetCompletedAsynchronously() { LIMITED_METHOD_CONTRACT; _completedSynchronously = FALSE; }
-
- // README:
- // If you modify the order of these fields, make sure to update the definition in
- // BCL for this object.
-private:
- OBJECTREF _userCallback;
- OBJECTREF _userStateObject;
-
- WAITHANDLEREF _waitHandle;
- SAFEHANDLEREF _fileHandle; // For cancellation.
- LPOVERLAPPED _overlapped;
- int _EndXxxCalled; // Whether we've called EndXxx already.
- int _numBytes; // number of bytes read OR written
- int _errorCode;
- int _numBufferedBytes;
-
- CLR_BOOL _isWrite; // Whether this is a read or a write
- CLR_BOOL _isComplete;
- CLR_BOOL _completedSynchronously; // Which thread called callback
-};
-
-#ifdef USE_CHECKED_OBJECTREFS
-typedef REF<AsyncResultBase> ASYNCRESULTREF;
-#else // USE_CHECKED_OBJECTREFS
-typedef AsyncResultBase* ASYNCRESULTREF;
-#endif // USE_CHECKED_OBJECTREFS
-
// This class corresponds to System.MulticastDelegate on the managed side.
class DelegateObject : public Object
{
diff --git a/src/vm/safehandle.cpp b/src/vm/safehandle.cpp
index 5e0626b9e7..23e415d8bc 100644
--- a/src/vm/safehandle.cpp
+++ b/src/vm/safehandle.cpp
@@ -438,60 +438,3 @@ FCIMPL1(void, CriticalHandle::FireCustomerDebugProbe, CriticalHandle* refThisUNS
HELPER_METHOD_FRAME_END();
}
FCIMPLEND
-
-
-FCIMPL1(UINT, SafeBuffer::SizeOfType, ReflectClassBaseObject* typeUNSAFE)
-{
- FCALL_CONTRACT;
-
- REFLECTCLASSBASEREF type(typeUNSAFE);
-
- MethodTable* pMT = type->GetType().AsMethodTable();
-
- if (!pMT->IsValueType() || pMT->ContainsPointers())
- FCThrowArgument(W("type"), W("Argument_NeedStructWithNoRefs"));
-
- FC_GC_POLL_RET();
-
- return pMT->GetNumInstanceFieldBytes();
-}
-FCIMPLEND
-
-FCIMPL1(UINT, SafeBuffer::AlignedSizeOfType, ReflectClassBaseObject* typeUNSAFE)
-{
- FCALL_CONTRACT;
-
- REFLECTCLASSBASEREF type(typeUNSAFE);
-
- MethodTable* pMT = type->GetType().AsMethodTable();
-
- if (!pMT->IsValueType() || pMT->ContainsPointers())
- FCThrowArgument(W("type"), W("Argument_NeedStructWithNoRefs"));
-
- FC_GC_POLL_RET();
-
- return pMT->GetAlignedNumInstanceFieldBytes();
-}
-FCIMPLEND
-
-FCIMPL3_IVI(void, SafeBuffer::PtrToStructure, BYTE* ptr, FC_TypedByRef structure, UINT32 sizeofT)
-{
- FCALL_CONTRACT;
-
- LPVOID structData = structure.data;
- _ASSERTE(ptr != NULL && structData != NULL);
- memcpyNoGCRefs(structData, ptr, sizeofT);
- FC_GC_POLL();
-}
-FCIMPLEND
-
-FCIMPL3_VII(void, SafeBuffer::StructureToPtr, FC_TypedByRef structure, BYTE* ptr, UINT32 sizeofT)
-{
- FCALL_CONTRACT;
-
- LPVOID structData = structure.data;
- _ASSERTE(ptr != NULL && structData != NULL);
- memcpyNoGCRefs(ptr, structData, sizeofT);
- FC_GC_POLL();
-}
-FCIMPLEND