<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" />
<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>
<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" />
<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" />
<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>
<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" />
<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" />
<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" />
<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>
--- /dev/null
+// 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; }
+ }
+}
/*============================================================
**
-** 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
// 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.
//
// 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
{
}
/// <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>
}
/// <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)]
}
/// <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)]
}
// 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
// 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
throw NotInitialized();
pointer = null;
- RuntimeHelpers.PrepareConstrainedRegions();
bool junk = false;
DangerousAddRef(ref junk);
/// 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)]
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
{
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
{
/// 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)]
// *((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
{
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
{
}
}
-
/// <summary>
/// Returns the number of bytes in the memory region.
/// </summary>
}
}
- /* 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)
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>();
+ }
}
}
+++ /dev/null
-// 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;
- }
-}
+++ /dev/null
-// 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
-{
-}
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)
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)
class OverlappedDataObject : public Object
{
public:
- ASYNCRESULTREF m_asyncResult;
-
+ OBJECTREF m_asyncResult;
OBJECTREF m_iocb;
OBJECTREF m_iocbHelper;
OBJECTREF m_overlapped;
};
-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;
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
{
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