From bba6808d991633a86a45fa0508e293f21a477001 Mon Sep 17 00:00:00 2001 From: Jan Kotas Date: Wed, 12 Oct 2016 15:26:51 -0700 Subject: [PATCH] Cleanup files excluded from CoreCLR build [tfs-changeset: 1633047] Commit migrated from https://github.com/dotnet/coreclr/commit/4cde2c8fad432da239f6db76158ea951ac72b856 --- .../src/mscorlib/mscorlib.shared.sources.props | 24 - .../src/mscorlib/src/System/ContextBoundObject.cs | 20 - .../mscorlib/src/System/ContextStaticAttribute.cs | 32 - .../src/mscorlib/src/System/IO/BufferedStream.cs | 1320 -------------------- .../src/System/IO/__DebugOutputTextWriter.cs | 76 -- .../Runtime/CompilerServices/CallingConvention.cs | 30 - .../CompilerServices/HasCopySemanticsAttribute.cs | 14 - .../CompilerServices/IDispatchConstantAttribute.cs | 26 - .../CompilerServices/IUnknownConstantAttribute.cs | 27 - .../src/System/Runtime/CompilerServices/IsBoxed.cs | 11 - .../System/Runtime/CompilerServices/IsByValue.cs | 11 - .../src/System/Runtime/CompilerServices/IsConst.cs | 11 - .../Runtime/CompilerServices/IsCopyConstructed.cs | 11 - .../CompilerServices/IsExplicitlyDereferenced.cs | 22 - .../CompilerServices/IsImplicitlyDereferenced.cs | 22 - .../Runtime/CompilerServices/IsJitIntrinsic.cs | 12 - .../src/System/Runtime/CompilerServices/IsLong.cs | 18 - .../System/Runtime/CompilerServices/IsPinned.cs | 11 - .../CompilerServices/IsSignUnspecifiedByte.cs | 16 - .../System/Runtime/CompilerServices/IsUdtReturn.cs | 11 - .../CompilerServices/NativeCppClassAttribute.cs | 16 - .../CompilerServices/RequiredAttributeAttribute.cs | 26 - .../CompilerServices/ScopelessEnumAttribute.cs | 14 - .../Versioning/ComponentGuaranteesAttribute.cs | 44 - .../Runtime/Versioning/ResourceAttributes.cs | 237 ---- 25 files changed, 2062 deletions(-) delete mode 100644 src/coreclr/src/mscorlib/src/System/ContextBoundObject.cs delete mode 100644 src/coreclr/src/mscorlib/src/System/ContextStaticAttribute.cs delete mode 100644 src/coreclr/src/mscorlib/src/System/IO/BufferedStream.cs delete mode 100644 src/coreclr/src/mscorlib/src/System/IO/__DebugOutputTextWriter.cs delete mode 100644 src/coreclr/src/mscorlib/src/System/Runtime/CompilerServices/CallingConvention.cs delete mode 100644 src/coreclr/src/mscorlib/src/System/Runtime/CompilerServices/HasCopySemanticsAttribute.cs delete mode 100644 src/coreclr/src/mscorlib/src/System/Runtime/CompilerServices/IDispatchConstantAttribute.cs delete mode 100644 src/coreclr/src/mscorlib/src/System/Runtime/CompilerServices/IUnknownConstantAttribute.cs delete mode 100644 src/coreclr/src/mscorlib/src/System/Runtime/CompilerServices/IsBoxed.cs delete mode 100644 src/coreclr/src/mscorlib/src/System/Runtime/CompilerServices/IsByValue.cs delete mode 100644 src/coreclr/src/mscorlib/src/System/Runtime/CompilerServices/IsConst.cs delete mode 100644 src/coreclr/src/mscorlib/src/System/Runtime/CompilerServices/IsCopyConstructed.cs delete mode 100644 src/coreclr/src/mscorlib/src/System/Runtime/CompilerServices/IsExplicitlyDereferenced.cs delete mode 100644 src/coreclr/src/mscorlib/src/System/Runtime/CompilerServices/IsImplicitlyDereferenced.cs delete mode 100644 src/coreclr/src/mscorlib/src/System/Runtime/CompilerServices/IsJitIntrinsic.cs delete mode 100644 src/coreclr/src/mscorlib/src/System/Runtime/CompilerServices/IsLong.cs delete mode 100644 src/coreclr/src/mscorlib/src/System/Runtime/CompilerServices/IsPinned.cs delete mode 100644 src/coreclr/src/mscorlib/src/System/Runtime/CompilerServices/IsSignUnspecifiedByte.cs delete mode 100644 src/coreclr/src/mscorlib/src/System/Runtime/CompilerServices/IsUdtReturn.cs delete mode 100644 src/coreclr/src/mscorlib/src/System/Runtime/CompilerServices/NativeCppClassAttribute.cs delete mode 100644 src/coreclr/src/mscorlib/src/System/Runtime/CompilerServices/RequiredAttributeAttribute.cs delete mode 100644 src/coreclr/src/mscorlib/src/System/Runtime/CompilerServices/ScopelessEnumAttribute.cs delete mode 100644 src/coreclr/src/mscorlib/src/System/Runtime/Versioning/ComponentGuaranteesAttribute.cs delete mode 100644 src/coreclr/src/mscorlib/src/System/Runtime/Versioning/ResourceAttributes.cs diff --git a/src/coreclr/src/mscorlib/mscorlib.shared.sources.props b/src/coreclr/src/mscorlib/mscorlib.shared.sources.props index 6d79a76..c497c7e 100644 --- a/src/coreclr/src/mscorlib/mscorlib.shared.sources.props +++ b/src/coreclr/src/mscorlib/mscorlib.shared.sources.props @@ -2,7 +2,6 @@ - @@ -21,29 +20,14 @@ - - - - - - - - - - - - - - - @@ -62,8 +46,6 @@ - - @@ -338,8 +320,6 @@ - - @@ -771,12 +751,10 @@ - - @@ -965,8 +943,6 @@ - - diff --git a/src/coreclr/src/mscorlib/src/System/ContextBoundObject.cs b/src/coreclr/src/mscorlib/src/System/ContextBoundObject.cs deleted file mode 100644 index d074ad1..0000000 --- a/src/coreclr/src/mscorlib/src/System/ContextBoundObject.cs +++ /dev/null @@ -1,20 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -/*============================================================ -** -** -** Purpose: Defines the root type for all context bound types -** -** -===========================================================*/ -namespace System { - - using System; - using System.Security.Permissions; - [Serializable] - [System.Runtime.InteropServices.ComVisible(true)] - public abstract class ContextBoundObject : MarshalByRefObject { - } -} diff --git a/src/coreclr/src/mscorlib/src/System/ContextStaticAttribute.cs b/src/coreclr/src/mscorlib/src/System/ContextStaticAttribute.cs deleted file mode 100644 index b875aa3..0000000 --- a/src/coreclr/src/mscorlib/src/System/ContextStaticAttribute.cs +++ /dev/null @@ -1,32 +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: Custom attribute to indicate that the field should be treated -** as a static relative to a context. -** -** -** -===========================================================*/ -namespace System { - - using System; - using System.Runtime.Remoting; -[Serializable] - [AttributeUsage(AttributeTargets.Field, Inherited = false)] - [System.Runtime.InteropServices.ComVisible(true)] -#if FEATURE_CORECLR - [Obsolete("ContextStaticAttribute is not supported in this release. It has been left in so that legacy tools can be used with this release, but it cannot be used in your code.", true)] -#endif // FEATURE_CORECLR - public class ContextStaticAttribute : Attribute - { - public ContextStaticAttribute() - { - } - } -} diff --git a/src/coreclr/src/mscorlib/src/System/IO/BufferedStream.cs b/src/coreclr/src/mscorlib/src/System/IO/BufferedStream.cs deleted file mode 100644 index 0c73b5c..0000000 --- a/src/coreclr/src/mscorlib/src/System/IO/BufferedStream.cs +++ /dev/null @@ -1,1320 +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: A composable Stream that buffers reads & writes to the underlying stream. -** -** -===========================================================*/ -using System; -using System.Runtime.InteropServices; -using System.Globalization; -using System.Diagnostics.Contracts; -using System.Runtime.CompilerServices; -using System.Threading; -using System.Collections.ObjectModel; -using System.Security; -using System.Threading.Tasks; - -namespace System.IO { - -/// -/// One of the design goals here is to prevent the buffer from getting in the way and slowing -/// down underlying stream accesses when it is not needed. If you always read & write for sizes -/// greater than the internal buffer size, then this class may not even allocate the internal buffer. -/// See a large comment in Write for the details of the write buffer heuristic. -/// -/// This class buffers reads & writes in a shared buffer. -/// (If you maintained two buffers separately, one operation would always trash the other buffer -/// anyways, so we might as well use one buffer.) -/// The assumption here is you will almost always be doing a series of reads or writes, but rarely -/// alternate between the two of them on the same stream. -/// -/// Class Invariants: -/// The class has one buffer, shared for reading & writing. -/// It can only be used for one or the other at any point in time - not both. -/// The following should be true: -/// 0 implies the read buffer is valid, but we're at the end of the buffer. -/// * _readPos == _readLen == 0 means the read buffer contains garbage. -/// * Either _writePos can be greater than 0, or _readLen & _readPos can be greater than zero, -/// but neither can be greater than zero at the same time. -/// ]]> -/// This class will never cache more bytes than the max specified buffer size. -/// However, it may use a temporary buffer of up to twice the size in order to combine several IO operations on -/// the underlying stream into a single operation. This is because we assume that memory copies are significantly -/// faster than IO operations on the underlying stream (if this was not true, using buffering is never appropriate). -/// The max size of this "shadow" buffer is limited as to not allocate it on the LOH. -/// Shadowing is always transient. Even when using this technique, this class still guarantees that the number of -/// bytes cached (not yet written to the target stream or not yet consumed by the user) is never larger than the -/// actual specified buffer size. -/// -[ComVisible(true)] -public sealed class BufferedStream : Stream { - - - private const Int32 _DefaultBufferSize = 4096; - - - private Stream _stream; // Underlying stream. Close sets _stream to null. - - private Byte[] _buffer; // Shared read/write buffer. Alloc on first use. - - private readonly Int32 _bufferSize; // Length of internal buffer (not counting the shadow buffer). - - private Int32 _readPos; // Read pointer within shared buffer. - private Int32 _readLen; // Number of bytes read in buffer from _stream. - private Int32 _writePos; // Write pointer within shared buffer. - - private BeginEndAwaitableAdapter _beginEndAwaitable; // Used to be able to await a BeginXxx call and thus to share code - // between the APM and Async pattern implementations - - private Task _lastSyncCompletedReadTask; // The last successful Task returned from ReadAsync - // (perf optimization for successive reads of the same size) - - - // Removing a private default constructor is a breaking change for the DataContractSerializer. - // Because this ctor was here previously we need to keep it around. - private BufferedStream() { } - - - public BufferedStream(Stream stream) - - : this(stream, _DefaultBufferSize) { - } - - - public BufferedStream(Stream stream, Int32 bufferSize) { - - if (stream == null) - throw new ArgumentNullException("stream"); - - if (bufferSize <= 0) - throw new ArgumentOutOfRangeException("bufferSize", Environment.GetResourceString("ArgumentOutOfRange_MustBePositive", "bufferSize")); - - Contract.EndContractBlock(); - - BCLDebug.Perf(!(stream is FileStream), "FileStream is buffered - don't wrap it in a BufferedStream"); - BCLDebug.Perf(!(stream is MemoryStream), "MemoryStream shouldn't be wrapped in a BufferedStream!"); - BCLDebug.Perf(!(stream is BufferedStream), "BufferedStream shouldn't be wrapped in another BufferedStream!"); - - _stream = stream; - _bufferSize = bufferSize; - - // Allocate _buffer on its first use - it will not be used if all reads - // & writes are greater than or equal to buffer size. - - if (!_stream.CanRead && !_stream.CanWrite) - __Error.StreamIsClosed(); - } - - - private void EnsureNotClosed() { - - if (_stream == null) - __Error.StreamIsClosed(); - } - - - private void EnsureCanSeek() { - - Contract.Requires(_stream != null); - - if (!_stream.CanSeek) - __Error.SeekNotSupported(); - } - - - private void EnsureCanRead() { - - Contract.Requires(_stream != null); - - if (!_stream.CanRead) - __Error.ReadNotSupported(); - } - - - private void EnsureCanWrite() { - - Contract.Requires(_stream != null); - - if (!_stream.CanWrite) - __Error.WriteNotSupported(); - } - - - private void EnsureBeginEndAwaitableAllocated() { - // We support only a single ongoing async operation and enforce this with a semaphore, - // so singleton is fine and no need to worry about a race condition here. - if (_beginEndAwaitable == null) - _beginEndAwaitable = new BeginEndAwaitableAdapter(); - } - - - /// MaxShadowBufferSize is chosed such that shadow buffers are not allocated on the Large Object Heap. - /// Currently, an object is allocated on the LOH if it is larger than 85000 bytes. See LARGE_OBJECT_SIZE in ndp\clr\src\vm\gc.h - /// We will go with exactly 80 KBytes, although this is somewhat arbitrary. - private const Int32 MaxShadowBufferSize = 81920; // Make sure not to get to the Large Object Heap. - private void EnsureShadowBufferAllocated() { - - Contract.Assert(_buffer != null); - Contract.Assert(_bufferSize > 0); - - // Already have shadow buffer? - if (_buffer.Length != _bufferSize || _bufferSize >= MaxShadowBufferSize) - return; - - Byte[] shadowBuffer = new Byte[Math.Min(_bufferSize + _bufferSize, MaxShadowBufferSize)]; - Buffer.InternalBlockCopy(_buffer, 0, shadowBuffer, 0, _writePos); - _buffer = shadowBuffer; - } - - - private void EnsureBufferAllocated() { - - Contract.Assert(_bufferSize > 0); - - // BufferedStream is not intended for multi-threaded use, so no worries about the get/set race conditions on _buffer. - if (_buffer == null) - _buffer = new Byte[_bufferSize]; - } - - - internal Stream UnderlyingStream { - [FriendAccessAllowed] - [Pure] - get { return _stream; } - } - - - internal Int32 BufferSize { - [FriendAccessAllowed] - [Pure] - get { return _bufferSize; } - } - - - public override bool CanRead { - [Pure] - get { return _stream != null && _stream.CanRead; } - } - - - public override bool CanWrite { - [Pure] - get { return _stream != null && _stream.CanWrite; } - } - - - public override bool CanSeek { - [Pure] - get { return _stream != null && _stream.CanSeek; } - } - - - public override Int64 Length { - get { - EnsureNotClosed(); - - if (_writePos > 0) - FlushWrite(); - - return _stream.Length; - } - } - - - public override Int64 Position { - get { - EnsureNotClosed(); - EnsureCanSeek(); - - Contract.Assert(! (_writePos > 0 && _readPos != _readLen), "Read and Write buffers cannot both have data in them at the same time."); - return _stream.Position + (_readPos - _readLen + _writePos); - } - set { - if (value < 0) - throw new ArgumentOutOfRangeException("value", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); - Contract.EndContractBlock(); - - EnsureNotClosed(); - EnsureCanSeek(); - - if (_writePos > 0) - FlushWrite(); - - _readPos = 0; - _readLen = 0; - _stream.Seek(value, SeekOrigin.Begin); - } - } - - - protected override void Dispose(bool disposing) { - - try { - if (disposing && _stream != null) { - try { - Flush(); - } finally { - _stream.Close(); - } - } - } finally { - _stream = null; - _buffer = null; - _lastSyncCompletedReadTask = null; - - // Call base.Dispose(bool) to cleanup async IO resources - base.Dispose(disposing); - } - } - - - public override void Flush() { - - EnsureNotClosed(); - - // Has WRITE data in the buffer: - if (_writePos > 0) { - - FlushWrite(); - Contract.Assert(_writePos == 0 && _readPos == 0 && _readLen == 0); - return; - } - - // Has READ data in the buffer: - if (_readPos < _readLen) { - - // If the underlying stream is not seekable AND we have something in the read buffer, then FlushRead would throw. - // We can either throw away the buffer resulting in data loss (!) or ignore the Flush. - // (We cannot throw becasue it would be a breaking change.) We opt into ignoring the Flush in that situation. - if (!_stream.CanSeek) - return; - - FlushRead(); - - // User streams may have opted to throw from Flush if CanWrite is false (although the abstract Stream does not do so). - // However, if we do not forward the Flush to the underlying stream, we may have problems when chaining several streams. - // Let us make a best effort attempt: - if (_stream.CanWrite || _stream is BufferedStream) - _stream.Flush(); - - Contract.Assert(_writePos == 0 && _readPos == 0 && _readLen == 0); - return; - } - - // We had no data in the buffer, but we still need to tell the underlying stream to flush. - if (_stream.CanWrite || _stream is BufferedStream) - _stream.Flush(); - - _writePos = _readPos = _readLen = 0; - } - - public override Task FlushAsync(CancellationToken cancellationToken) { - - if (cancellationToken.IsCancellationRequested) - return Task.FromCanceled(cancellationToken); - - EnsureNotClosed(); - - return FlushAsyncInternal(cancellationToken, this, _stream, _writePos, _readPos, _readLen); - } - - - private static async Task FlushAsyncInternal(CancellationToken cancellationToken, - BufferedStream _this, Stream stream, Int32 writePos, Int32 readPos, Int32 readLen) { - - // We bring instance fields down as local parameters to this async method becasue BufferedStream is derived from MarshalByRefObject. - // Field access would be from the async state machine i.e., not via the this pointer and would require runtime checking to see - // if we are talking to a remote object, which is currently very slow - - Contract.Assert(stream != null); - - SemaphoreSlim sem = _this.EnsureAsyncActiveSemaphoreInitialized(); - await sem.WaitAsync().ConfigureAwait(false); - try { - - if (writePos > 0) { - - await _this.FlushWriteAsync(cancellationToken).ConfigureAwait(false); - Contract.Assert(_this._writePos == 0 && _this._readPos == 0 && _this._readLen == 0); - return; - } - - if (readPos < readLen) { - - // If the underlying stream is not seekable AND we have something in the read buffer, then FlushRead would throw. - // We can either throw away the buffer resulting in date loss (!) or ignore the Flush. (We cannot throw becasue it - // would be a breaking change.) We opt into ignoring the Flush in that situation. - if (!stream.CanSeek) - return; - - _this.FlushRead(); // not async; it uses Seek, but there's no SeekAsync - - // User streams may have opted to throw from Flush if CanWrite is false (although the abstract Stream does not do so). - // However, if we do not forward the Flush to the underlying stream, we may have problems when chaining several streams. - // Let us make a best effort attempt: - if (stream.CanRead || stream is BufferedStream) - await stream.FlushAsync(cancellationToken).ConfigureAwait(false); - - Contract.Assert(_this._writePos == 0 && _this._readPos == 0 && _this._readLen == 0); - return; - } - - // We had no data in the buffer, but we still need to tell the underlying stream to flush. - if (stream.CanWrite || stream is BufferedStream) - await stream.FlushAsync(cancellationToken).ConfigureAwait(false); - - // There was nothing in the buffer: - Contract.Assert(_this._writePos == 0 && _this._readPos == _this._readLen); - - } finally { - sem.Release(); - } - } - - - // Reading is done in blocks, but someone could read 1 byte from the buffer then write. - // At that point, the underlying stream's pointer is out of sync with this stream's position. - // All write functions should call this function to ensure that the buffered data is not lost. - private void FlushRead() { - - Contract.Assert(_writePos == 0, "BufferedStream: Write buffer must be empty in FlushRead!"); - - if (_readPos - _readLen != 0) - _stream.Seek(_readPos - _readLen, SeekOrigin.Current); - - _readPos = 0; - _readLen = 0; - } - - - private void ClearReadBufferBeforeWrite() { - - // This is called by write methods to clear the read buffer. - - Contract.Assert(_readPos <= _readLen, "_readPos <= _readLen [" + _readPos +" <= " + _readLen + "]"); - - // No READ data in the buffer: - if (_readPos == _readLen) { - - _readPos = _readLen = 0; - return; - } - - // Must have READ data. - Contract.Assert(_readPos < _readLen); - - // If the underlying stream cannot seek, FlushRead would end up throwing NotSupported. - // However, since the user did not call a method that is intuitively expected to seek, a better message is in order. - // Ideally, we would throw an InvalidOperation here, but for backward compat we have to stick with NotSupported. - if (!_stream.CanSeek) - throw new NotSupportedException(Environment.GetResourceString("NotSupported_CannotWriteToBufferedStreamIfReadBufferCannotBeFlushed")); - - FlushRead(); - } - - - private void FlushWrite() { - - Contract.Assert(_readPos == 0 && _readLen == 0, - "BufferedStream: Read buffer must be empty in FlushWrite!"); - Contract.Assert(_buffer != null && _bufferSize >= _writePos, - "BufferedStream: Write buffer must be allocated and write position must be in the bounds of the buffer in FlushWrite!"); - - _stream.Write(_buffer, 0, _writePos); - _writePos = 0; - _stream.Flush(); - } - - - private async Task FlushWriteAsync(CancellationToken cancellationToken) { - - Contract.Assert(_readPos == 0 && _readLen == 0, - "BufferedStream: Read buffer must be empty in FlushWrite!"); - Contract.Assert(_buffer != null && _bufferSize >= _writePos, - "BufferedStream: Write buffer must be allocated and write position must be in the bounds of the buffer in FlushWrite!"); - - await _stream.WriteAsync(_buffer, 0, _writePos, cancellationToken).ConfigureAwait(false); - _writePos = 0; - await _stream.FlushAsync(cancellationToken).ConfigureAwait(false); - } - - - private Int32 ReadFromBuffer(Byte[] array, Int32 offset, Int32 count) { - - Int32 readBytes = _readLen - _readPos; - Contract.Assert(readBytes >= 0); - - if (readBytes == 0) - return 0; - - Contract.Assert(readBytes > 0); - - if (readBytes > count) - readBytes = count; - - Buffer.InternalBlockCopy(_buffer, _readPos, array, offset, readBytes); - _readPos += readBytes; - - return readBytes; - } - - - private Int32 ReadFromBuffer(Byte[] array, Int32 offset, Int32 count, out Exception error) { - - try { - - error = null; - return ReadFromBuffer(array, offset, count); - - } catch (Exception ex) { - error = ex; - return 0; - } - } - - - public override int Read([In, Out] Byte[] array, Int32 offset, Int32 count) { - - if (array == null) - throw new ArgumentNullException("array", Environment.GetResourceString("ArgumentNull_Buffer")); - if (offset < 0) - throw new ArgumentOutOfRangeException("offset", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); - if (count < 0) - throw new ArgumentOutOfRangeException("count", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); - if (array.Length - offset < count) - throw new ArgumentException(Environment.GetResourceString("Argument_InvalidOffLen")); - Contract.EndContractBlock(); - - EnsureNotClosed(); - EnsureCanRead(); - - Int32 bytesFromBuffer = ReadFromBuffer(array, offset, count); - - // We may have read less than the number of bytes the user asked for, but that is part of the Stream contract. - - // Reading again for more data may cause us to block if we're using a device with no clear end of file, - // such as a serial port or pipe. If we blocked here and this code was used with redirected pipes for a - // process's standard output, this can lead to deadlocks involving two processes. - // BUT - this is a breaking change. - // So: If we could not read all bytes the user asked for from the buffer, we will try once from the underlying - // stream thus ensuring the same blocking behaviour as if the underlying stream was not wrapped in this BufferedStream. - if (bytesFromBuffer == count) - return bytesFromBuffer; - - Int32 alreadySatisfied = bytesFromBuffer; - if (bytesFromBuffer > 0) { - count -= bytesFromBuffer; - offset += bytesFromBuffer; - } - - // So the READ buffer is empty. - Contract.Assert(_readLen == _readPos); - _readPos = _readLen = 0; - - // If there was anything in the WRITE buffer, clear it. - if (_writePos > 0) - FlushWrite(); - - // If the requested read is larger than buffer size, avoid the buffer and still use a single read: - if (count >= _bufferSize) { - - return _stream.Read(array, offset, count) + alreadySatisfied; - } - - // Ok. We can fill the buffer: - EnsureBufferAllocated(); - _readLen = _stream.Read(_buffer, 0, _bufferSize); - - bytesFromBuffer = ReadFromBuffer(array, offset, count); - - // We may have read less than the number of bytes the user asked for, but that is part of the Stream contract. - // Reading again for more data may cause us to block if we're using a device with no clear end of stream, - // such as a serial port or pipe. If we blocked here & this code was used with redirected pipes for a process's - // standard output, this can lead to deadlocks involving two processes. Additionally, translating one read on the - // BufferedStream to more than one read on the underlying Stream may defeat the whole purpose of buffering of the - // underlying reads are significantly more expensive. - - return bytesFromBuffer + alreadySatisfied; - } - - - public override IAsyncResult BeginRead(Byte[] buffer, Int32 offset, Int32 count, AsyncCallback callback, Object state) { - - if (buffer == null) - throw new ArgumentNullException("buffer", Environment.GetResourceString("ArgumentNull_Buffer")); - if (offset < 0) - throw new ArgumentOutOfRangeException("offset", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); - if (count < 0) - throw new ArgumentOutOfRangeException("count", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); - if (buffer.Length - offset < count) - throw new ArgumentException(Environment.GetResourceString("Argument_InvalidOffLen")); - Contract.EndContractBlock(); - - // Previous version incorrectly threw NotSupported instead of ObjectDisposed. We keep that behaviour for back-compat. - // EnsureNotClosed(); - if (_stream == null) __Error.ReadNotSupported(); - EnsureCanRead(); - - Int32 bytesFromBuffer = 0; - // Try to satisfy the request from the buffer synchronously. But still need a sem-lock in case that another - // Async IO Task accesses the buffer concurrently. If we fail to acquire the lock without waiting, make this - // an Async operation. - SemaphoreSlim sem = base.EnsureAsyncActiveSemaphoreInitialized(); - Task semaphoreLockTask = sem.WaitAsync(); - if (semaphoreLockTask.Status == TaskStatus.RanToCompletion) { - - bool completeSynchronously = true; - try { - - Exception error; - bytesFromBuffer = ReadFromBuffer(buffer, offset, count, out error); - - // If we satistied enough data from the buffer, we can complete synchronously. - // Reading again for more data may cause us to block if we're using a device with no clear end of file, - // such as a serial port or pipe. If we blocked here and this code was used with redirected pipes for a - // process's standard output, this can lead to deadlocks involving two processes. - // BUT - this is a breaking change. - // So: If we could not read all bytes the user asked for from the buffer, we will try once from the underlying - // stream thus ensuring the same blocking behaviour as if the underlying stream was not wrapped in this BufferedStream. - completeSynchronously = (bytesFromBuffer == count || error != null); - - if (completeSynchronously) { - - SynchronousAsyncResult asyncResult = (error == null) - ? new SynchronousAsyncResult(bytesFromBuffer, state) - : new SynchronousAsyncResult(error, state, isWrite: false); - if (callback != null) - callback(asyncResult); - - return asyncResult; - } - } finally { - if (completeSynchronously) // if this is FALSE, we will be entering ReadFromUnderlyingStreamAsync and releasing there. - sem.Release(); - } - } - - // Delegate to the async implementation. - return BeginReadFromUnderlyingStream(buffer, offset + bytesFromBuffer, count - bytesFromBuffer, callback, state, - bytesFromBuffer, semaphoreLockTask); - } - - - private IAsyncResult BeginReadFromUnderlyingStream(Byte[] buffer, Int32 offset, Int32 count, AsyncCallback callback, Object state, - Int32 bytesAlreadySatisfied, Task semaphoreLockTask) { - - Task readOp = ReadFromUnderlyingStreamAsync(buffer, offset, count, CancellationToken.None, - bytesAlreadySatisfied, semaphoreLockTask, useApmPattern: true); - return TaskToApm.Begin(readOp, callback, state); - } - - - public override Int32 EndRead(IAsyncResult asyncResult) { - - if (asyncResult == null) - throw new ArgumentNullException("asyncResult"); - Contract.Ensures(Contract.Result() >= 0); - Contract.EndContractBlock(); - - var sAR = asyncResult as SynchronousAsyncResult; - if (sAR != null) - return SynchronousAsyncResult.EndRead(asyncResult); - return TaskToApm.End(asyncResult); - } - - - private Task LastSyncCompletedReadTask(Int32 val) { - - Task t = _lastSyncCompletedReadTask; - Contract.Assert(t == null || t.Status == TaskStatus.RanToCompletion); - - if (t != null && t.Result == val) - return t; - - t = Task.FromResult(val); - _lastSyncCompletedReadTask = t; - return t; - } - - - public override Task ReadAsync(Byte[] buffer, Int32 offset, Int32 count, CancellationToken cancellationToken) { - - if (buffer == null) - throw new ArgumentNullException("buffer", Environment.GetResourceString("ArgumentNull_Buffer")); - if (offset < 0) - throw new ArgumentOutOfRangeException("offset", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); - if (count < 0) - throw new ArgumentOutOfRangeException("count", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); - if (buffer.Length - offset < count) - throw new ArgumentException(Environment.GetResourceString("Argument_InvalidOffLen")); - Contract.EndContractBlock(); - - // Fast path check for cancellation already requested - if (cancellationToken.IsCancellationRequested) - return Task.FromCanceled(cancellationToken); - - EnsureNotClosed(); - EnsureCanRead(); - - Int32 bytesFromBuffer = 0; - // Try to satisfy the request from the buffer synchronously. But still need a sem-lock in case that another - // Async IO Task accesses the buffer concurrently. If we fail to acquire the lock without waiting, make this - // an Async operation. - SemaphoreSlim sem = base.EnsureAsyncActiveSemaphoreInitialized(); - Task semaphoreLockTask = sem.WaitAsync(); - if (semaphoreLockTask.Status == TaskStatus.RanToCompletion) { - - bool completeSynchronously = true; - try { - Exception error; - bytesFromBuffer = ReadFromBuffer(buffer, offset, count, out error); - - // If we satistied enough data from the buffer, we can complete synchronously. - // Reading again for more data may cause us to block if we're using a device with no clear end of file, - // such as a serial port or pipe. If we blocked here and this code was used with redirected pipes for a - // process's standard output, this can lead to deadlocks involving two processes. - // BUT - this is a breaking change. - // So: If we could not read all bytes the user asked for from the buffer, we will try once from the underlying - // stream thus ensuring the same blocking behaviour as if the underlying stream was not wrapped in this BufferedStream. - completeSynchronously = (bytesFromBuffer == count || error != null); - - if (completeSynchronously) { - - return (error == null) - ? LastSyncCompletedReadTask(bytesFromBuffer) - : Task.FromException(error); - } - } finally { - if (completeSynchronously) // if this is FALSE, we will be entering ReadFromUnderlyingStreamAsync and releasing there. - sem.Release(); - } - } - - // Delegate to the async implementation. - return ReadFromUnderlyingStreamAsync(buffer, offset + bytesFromBuffer, count - bytesFromBuffer, cancellationToken, - bytesFromBuffer, semaphoreLockTask, useApmPattern: false); - } - - - /// BufferedStream should be as thin a wrapper as possible. We want that ReadAsync delegates to - /// ReadAsync of the underlying _stream and that BeginRead delegates to BeginRead of the underlying stream, - /// rather than calling the base Stream which implements the one in terms of the other. This allows BufferedStream - /// to affect the semantics of the stream it wraps as little as possible. At the same time, we want to share as - /// much code between the APM and the Async pattern implementations as possible. This method is called by both with - /// a corresponding useApmPattern value. Recall that Task implements IAsyncResult. - /// -2 if _bufferSize was set to 0 while waiting on the semaphore; otherwise num of bytes read. - private async Task ReadFromUnderlyingStreamAsync(Byte[] array, Int32 offset, Int32 count, - CancellationToken cancellationToken, - Int32 bytesAlreadySatisfied, - Task semaphoreLockTask, bool useApmPattern) { - - // Same conditions validated with exceptions in ReadAsync: - // (These should be Contract.Requires(..) but that method had some issues in async methods; using Assert(..) for now.) - Contract.Assert(array != null); - Contract.Assert(offset >= 0); - Contract.Assert(count >= 0); - Contract.Assert(array.Length - offset >= count); - Contract.Assert(_stream != null); - Contract.Assert(_stream.CanRead); - Contract.Assert(_bufferSize > 0); - Contract.Assert(semaphoreLockTask != null); - - // Employ async waiting based on the same synchronization used in BeginRead of the abstract Stream. - await semaphoreLockTask.ConfigureAwait(false); - try { - - // The buffer might have been changed by another async task while we were waiting on the semaphore. - // Check it now again. - Int32 bytesFromBuffer = ReadFromBuffer(array, offset, count); - if (bytesFromBuffer == count) - return bytesAlreadySatisfied + bytesFromBuffer; - - if (bytesFromBuffer > 0) { - count -= bytesFromBuffer; - offset += bytesFromBuffer; - bytesAlreadySatisfied += bytesFromBuffer; - } - - Contract.Assert(_readLen == _readPos); - _readPos = _readLen = 0; - - // If there was anything in the WRITE buffer, clear it. - if (_writePos > 0) - await FlushWriteAsync(cancellationToken).ConfigureAwait(false); // no Begin-End read version for Flush. Use Async. - - // If the requested read is larger than buffer size, avoid the buffer and still use a single read: - if (count >= _bufferSize) { - - if (useApmPattern) { - EnsureBeginEndAwaitableAllocated(); - _stream.BeginRead(array, offset, count, BeginEndAwaitableAdapter.Callback, _beginEndAwaitable); - return bytesAlreadySatisfied + _stream.EndRead(await _beginEndAwaitable); - } else { - return bytesAlreadySatisfied + await _stream.ReadAsync(array, offset, count, cancellationToken).ConfigureAwait(false); - } - } - - // Ok. We can fill the buffer: - EnsureBufferAllocated(); - if (useApmPattern) { - EnsureBeginEndAwaitableAllocated(); - _stream.BeginRead(_buffer, 0, _bufferSize, BeginEndAwaitableAdapter.Callback, _beginEndAwaitable); - _readLen = _stream.EndRead(await _beginEndAwaitable); - } else { - _readLen = await _stream.ReadAsync(_buffer, 0, _bufferSize, cancellationToken).ConfigureAwait(false); - } - - bytesFromBuffer = ReadFromBuffer(array, offset, count); - return bytesAlreadySatisfied + bytesFromBuffer; - - } finally { - SemaphoreSlim sem = base.EnsureAsyncActiveSemaphoreInitialized(); - sem.Release(); - } - } - - - public override Int32 ReadByte() { - - EnsureNotClosed(); - EnsureCanRead(); - - if (_readPos == _readLen) { - - if (_writePos > 0) - FlushWrite(); - - EnsureBufferAllocated(); - _readLen = _stream.Read(_buffer, 0, _bufferSize); - _readPos = 0; - } - - if (_readPos == _readLen) - return -1; - - Int32 b = _buffer[_readPos++]; - return b; - } - - - private void WriteToBuffer(Byte[] array, ref Int32 offset, ref Int32 count) { - - Int32 bytesToWrite = Math.Min(_bufferSize - _writePos, count); - - if (bytesToWrite <= 0) - return; - - EnsureBufferAllocated(); - Buffer.InternalBlockCopy(array, offset, _buffer, _writePos, bytesToWrite); - - _writePos += bytesToWrite; - count -= bytesToWrite; - offset += bytesToWrite; - } - - - private void WriteToBuffer(Byte[] array, ref Int32 offset, ref Int32 count, out Exception error) { - - try { - - error = null; - WriteToBuffer(array, ref offset, ref count); - - } catch (Exception ex) { - error = ex; - } - } - - - public override void Write(Byte[] array, Int32 offset, Int32 count) { - - if (array == null) - throw new ArgumentNullException("array", Environment.GetResourceString("ArgumentNull_Buffer")); - if (offset < 0) - throw new ArgumentOutOfRangeException("offset", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); - if (count < 0) - throw new ArgumentOutOfRangeException("count", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); - if (array.Length - offset < count) - throw new ArgumentException(Environment.GetResourceString("Argument_InvalidOffLen")); - Contract.EndContractBlock(); - - EnsureNotClosed(); - EnsureCanWrite(); - - if (_writePos == 0) - ClearReadBufferBeforeWrite(); - - #region Write algorithm comment - // We need to use the buffer, while avoiding unnecessary buffer usage / memory copies. - // We ASSUME that memory copies are much cheaper than writes to the underlying stream, so if an extra copy is - // guaranteed to reduce the number of writes, we prefer it. - // We pick a simple strategy that makes degenerate cases rare if our assumptions are right. - // - // For every write, we use a simple heuristic (below) to decide whether to use the buffer. - // The heuristic has the desirable property (*) that if the specified user data can fit into the currently available - // buffer space without filling it up completely, the heuristic will always tell us to use the buffer. It will also - // tell us to use the buffer in cases where the current write would fill the buffer, but the remaining data is small - // enough such that subsequent operations can use the buffer again. - // - // Algorithm: - // Determine whether or not to buffer according to the heuristic (below). - // If we decided to use the buffer: - // Copy as much user data as we can into the buffer. - // If we consumed all data: We are finished. - // Otherwise, write the buffer out. - // Copy the rest of user data into the now cleared buffer (no need to write out the buffer again as the heuristic - // will prevent it from being filled twice). - // If we decided not to use the buffer: - // Can the data already in the buffer and current user data be combines to a single write - // by allocating a "shadow" buffer of up to twice the size of _bufferSize (up to a limit to avoid LOH)? - // Yes, it can: - // Allocate a larger "shadow" buffer and ensure the buffered data is moved there. - // Copy user data to the shadow buffer. - // Write shadow buffer to the underlying stream in a single operation. - // No, it cannot (amount of data is still too large): - // Write out any data possibly in the buffer. - // Write out user data directly. - // - // Heuristic: - // If the subsequent write operation that follows the current write operation will result in a write to the - // underlying stream in case that we use the buffer in the current write, while it would not have if we avoided - // using the buffer in the current write (by writing current user data to the underlying stream directly), then we - // prefer to avoid using the buffer since the corresponding memory copy is wasted (it will not reduce the number - // of writes to the underlying stream, which is what we are optimising for). - // ASSUME that the next write will be for the same amount of bytes as the current write (most common case) and - // determine if it will cause a write to the underlying stream. If the next write is actually larger, our heuristic - // still yields the right behaviour, if the next write is actually smaller, we may making an unnecessary write to - // the underlying stream. However, this can only occur if the current write is larger than half the buffer size and - // we will recover after one iteration. - // We have: - // useBuffer = (_writePos + count + count < _bufferSize + _bufferSize) - // - // Example with _bufferSize = 20, _writePos = 6, count = 10: - // - // +---------------------------------------+---------------------------------------+ - // | current buffer | next iteration's "future" buffer | - // +---------------------------------------+---------------------------------------+ - // |0| | | | | | | | | |1| | | | | | | | | |2| | | | | | | | | |3| | | | | | | | | | - // |0|1|2|3|4|5|6|7|8|9|0|1|2|3|4|5|6|7|8|9|0|1|2|3|4|5|6|7|8|9|0|1|2|3|4|5|6|7|8|9| - // +-----------+-------------------+-------------------+---------------------------+ - // | _writePos | current count | assumed next count|avail buff after next write| - // +-----------+-------------------+-------------------+---------------------------+ - // - // A nice property (*) of this heuristic is that it will always succeed if the user data completely fits into the - // available buffer, i.e. if count < (_bufferSize - _writePos). - #endregion Write algorithm comment - - Contract.Assert(_writePos < _bufferSize); - - Int32 totalUserBytes; - bool useBuffer; - checked { // We do not expect buffer sizes big enough for an overflow, but if it happens, lets fail early: - totalUserBytes = _writePos + count; - useBuffer = (totalUserBytes + count < (_bufferSize + _bufferSize)); - } - - if (useBuffer) { - - WriteToBuffer(array, ref offset, ref count); - - if (_writePos < _bufferSize) { - - Contract.Assert(count == 0); - return; - } - - Contract.Assert(count >= 0); - Contract.Assert(_writePos == _bufferSize); - Contract.Assert(_buffer != null); - - _stream.Write(_buffer, 0, _writePos); - _writePos = 0; - - WriteToBuffer(array, ref offset, ref count); - - Contract.Assert(count == 0); - Contract.Assert(_writePos < _bufferSize); - - } else { // if (!useBuffer) - - // Write out the buffer if necessary. - if (_writePos > 0) { - - Contract.Assert(_buffer != null); - Contract.Assert(totalUserBytes >= _bufferSize); - - // Try avoiding extra write to underlying stream by combining previously buffered data with current user data: - if (totalUserBytes <= (_bufferSize + _bufferSize) && totalUserBytes <= MaxShadowBufferSize) { - - EnsureShadowBufferAllocated(); - Buffer.InternalBlockCopy(array, offset, _buffer, _writePos, count); - _stream.Write(_buffer, 0, totalUserBytes); - _writePos = 0; - return; - } - - _stream.Write(_buffer, 0, _writePos); - _writePos = 0; - } - - // Write out user data. - _stream.Write(array, offset, count); - } - } - - - - - public override IAsyncResult BeginWrite(Byte[] buffer, Int32 offset, Int32 count, AsyncCallback callback, Object state) { - - if (buffer == null) - throw new ArgumentNullException("buffer", Environment.GetResourceString("ArgumentNull_Buffer")); - if (offset < 0) - throw new ArgumentOutOfRangeException("offset", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); - if (count < 0) - throw new ArgumentOutOfRangeException("count", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); - if (buffer.Length - offset < count) - throw new ArgumentException(Environment.GetResourceString("Argument_InvalidOffLen")); - Contract.EndContractBlock(); - - // Previous version incorrectly threw NotSupported instead of ObjectDisposed. We keep that behaviour for back-compat. - // EnsureNotClosed(); - if (_stream == null) __Error.ReadNotSupported(); - EnsureCanWrite(); - - // Try to satisfy the request from the buffer synchronously. But still need a sem-lock in case that another - // Async IO Task accesses the buffer concurrently. If we fail to acquire the lock without waiting, make this - // an Async operation. - SemaphoreSlim sem = base.EnsureAsyncActiveSemaphoreInitialized(); - Task semaphoreLockTask = sem.WaitAsync(); - if (semaphoreLockTask.Status == TaskStatus.RanToCompletion) { - - bool completeSynchronously = true; - try { - if (_writePos == 0) - ClearReadBufferBeforeWrite(); - - // If the write completely fits into the buffer, we can complete synchronously. - Contract.Assert(_writePos < _bufferSize); - completeSynchronously = (count < _bufferSize - _writePos); - - if (completeSynchronously) { - - Exception error; - WriteToBuffer(buffer, ref offset, ref count, out error); - Contract.Assert(count == 0); - - SynchronousAsyncResult asyncResult = (error == null) - ? new SynchronousAsyncResult(state) - : new SynchronousAsyncResult(error, state, isWrite: true); - if (callback != null) - callback(asyncResult); - - return asyncResult; - } - } finally { - if (completeSynchronously) // if this is FALSE, we will be entering WriteToUnderlyingStreamAsync and releasing there. - sem.Release(); - } - } - - // Delegate to the async implementation. - return BeginWriteToUnderlyingStream(buffer, offset, count, callback, state, semaphoreLockTask); - } - - - private IAsyncResult BeginWriteToUnderlyingStream(Byte[] buffer, Int32 offset, Int32 count, AsyncCallback callback, Object state, - Task semaphoreLockTask) { - - Task writeOp = WriteToUnderlyingStreamAsync(buffer, offset, count, CancellationToken.None, semaphoreLockTask, useApmPattern: true); - return TaskToApm.Begin(writeOp, callback, state); - } - - - public override void EndWrite(IAsyncResult asyncResult) { - - if (asyncResult == null) - throw new ArgumentNullException("asyncResult"); - Contract.EndContractBlock(); - - var sAR = asyncResult as SynchronousAsyncResult; - if (sAR != null) { - SynchronousAsyncResult.EndWrite(asyncResult); - return; - } - - TaskToApm.End(asyncResult); - } - - - public override Task WriteAsync(Byte[] buffer, Int32 offset, Int32 count, CancellationToken cancellationToken) { - - if (buffer == null) - throw new ArgumentNullException("buffer", Environment.GetResourceString("ArgumentNull_Buffer")); - if (offset < 0) - throw new ArgumentOutOfRangeException("offset", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); - if (count < 0) - throw new ArgumentOutOfRangeException("count", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); - if (buffer.Length - offset < count) - throw new ArgumentException(Environment.GetResourceString("Argument_InvalidOffLen")); - Contract.EndContractBlock(); - - // Fast path check for cancellation already requested - if (cancellationToken.IsCancellationRequested) - return Task.FromCanceled(cancellationToken); - - EnsureNotClosed(); - EnsureCanWrite(); - - // Try to satisfy the request from the buffer synchronously. But still need a sem-lock in case that another - // Async IO Task accesses the buffer concurrently. If we fail to acquire the lock without waiting, make this - // an Async operation. - SemaphoreSlim sem = base.EnsureAsyncActiveSemaphoreInitialized(); - Task semaphoreLockTask = sem.WaitAsync(); - if (semaphoreLockTask.Status == TaskStatus.RanToCompletion) { - - bool completeSynchronously = true; - try { - - if (_writePos == 0) - ClearReadBufferBeforeWrite(); - - Contract.Assert(_writePos < _bufferSize); - - // If the write completely fits into the buffer, we can complete synchronously: - completeSynchronously = (count < _bufferSize - _writePos); - - if (completeSynchronously) { - - Exception error; - WriteToBuffer(buffer, ref offset, ref count, out error); - Contract.Assert(count == 0); - - return (error == null) - ? Task.CompletedTask - : Task.FromException(error); - } - } finally { - if (completeSynchronously) // if this is FALSE, we will be entering WriteToUnderlyingStreamAsync and releasing there. - sem.Release(); - } - } - - // Delegate to the async implementation. - return WriteToUnderlyingStreamAsync(buffer, offset, count, cancellationToken, semaphoreLockTask, useApmPattern: false); - } - - - /// BufferedStream should be as thin a wrapper as possible. We want that WriteAsync delegates to - /// WriteAsync of the underlying _stream and that BeginWrite delegates to BeginWrite of the underlying stream, - /// rather than calling the base Stream which implements the one in terms of the other. This allows BufferedStream - /// to affect the semantics of the stream it wraps as little as possible. At the same time, we want to share as - /// much code between the APM and the Async pattern implementations as possible. This method is called by both with - /// a corresponding useApmPattern value. Recall that Task implements IAsyncResult. - private async Task WriteToUnderlyingStreamAsync(Byte[] array, Int32 offset, Int32 count, - CancellationToken cancellationToken, - Task semaphoreLockTask, bool useApmPattern) { - - // (These should be Contract.Requires(..) but that method had some issues in async methods; using Assert(..) for now.) - Contract.Assert(array != null); - Contract.Assert(offset >= 0); - Contract.Assert(count >= 0); - Contract.Assert(array.Length - offset >= count); - Contract.Assert(_stream != null); - Contract.Assert(_stream.CanWrite); - Contract.Assert(_bufferSize > 0); - Contract.Assert(semaphoreLockTask != null); - - // See the LARGE COMMENT in Write(..) for the explanation of the write buffer algorithm. - - await semaphoreLockTask.ConfigureAwait(false); - try { - - // The buffer might have been changed by another async task while we were waiting on the semaphore. - // However, note that if we recalculate the sync completion condition to TRUE, then useBuffer will also be TRUE. - - if (_writePos == 0) - ClearReadBufferBeforeWrite(); - - Int32 totalUserBytes; - bool useBuffer; - checked { // We do not expect buffer sizes big enough for an overflow, but if it happens, lets fail early: - totalUserBytes = _writePos + count; - useBuffer = (totalUserBytes + count < (_bufferSize + _bufferSize)); - } - - if (useBuffer) { - - WriteToBuffer(array, ref offset, ref count); - - if (_writePos < _bufferSize) { - - Contract.Assert(count == 0); - return; - } - - Contract.Assert(count >= 0); - Contract.Assert(_writePos == _bufferSize); - Contract.Assert(_buffer != null); - - if (useApmPattern) { - EnsureBeginEndAwaitableAllocated(); - _stream.BeginWrite(_buffer, 0, _writePos, BeginEndAwaitableAdapter.Callback, _beginEndAwaitable); - _stream.EndWrite(await _beginEndAwaitable); - } else { - await _stream.WriteAsync(_buffer, 0, _writePos, cancellationToken).ConfigureAwait(false); - } - _writePos = 0; - - WriteToBuffer(array, ref offset, ref count); - - Contract.Assert(count == 0); - Contract.Assert(_writePos < _bufferSize); - - } else { // if (!useBuffer) - - // Write out the buffer if necessary. - if (_writePos > 0) { - - Contract.Assert(_buffer != null); - Contract.Assert(totalUserBytes >= _bufferSize); - - // Try avoiding extra write to underlying stream by combining previously buffered data with current user data: - if (totalUserBytes <= (_bufferSize + _bufferSize) && totalUserBytes <= MaxShadowBufferSize) { - - EnsureShadowBufferAllocated(); - Buffer.InternalBlockCopy(array, offset, _buffer, _writePos, count); - if (useApmPattern) { - EnsureBeginEndAwaitableAllocated(); - _stream.BeginWrite(_buffer, 0, totalUserBytes, BeginEndAwaitableAdapter.Callback, _beginEndAwaitable); - _stream.EndWrite(await _beginEndAwaitable); - } else { - await _stream.WriteAsync(_buffer, 0, totalUserBytes, cancellationToken).ConfigureAwait(false); - } - _writePos = 0; - return; - } - - if (useApmPattern) { - EnsureBeginEndAwaitableAllocated(); - _stream.BeginWrite(_buffer, 0, _writePos, BeginEndAwaitableAdapter.Callback, _beginEndAwaitable); - _stream.EndWrite(await _beginEndAwaitable); - } else { - await _stream.WriteAsync(_buffer, 0, _writePos, cancellationToken).ConfigureAwait(false); - } - _writePos = 0; - } - - // Write out user data. - if (useApmPattern) { - EnsureBeginEndAwaitableAllocated(); - _stream.BeginWrite(array, offset, count, BeginEndAwaitableAdapter.Callback, _beginEndAwaitable); - _stream.EndWrite(await _beginEndAwaitable); - } else { - await _stream.WriteAsync(array, offset, count, cancellationToken).ConfigureAwait(false); - } - } - } finally { - SemaphoreSlim sem = base.EnsureAsyncActiveSemaphoreInitialized(); - sem.Release(); - } - } - - - public override void WriteByte(Byte value) { - - EnsureNotClosed(); - - if (_writePos == 0) { - - EnsureCanWrite(); - ClearReadBufferBeforeWrite(); - EnsureBufferAllocated(); - } - - // We should not be flushing here, but only writing to the underlying stream, but previous version flushed, so we keep this. - if (_writePos >= _bufferSize - 1) - FlushWrite(); - - _buffer[_writePos++] = value; - - Contract.Assert(_writePos < _bufferSize); - } - - - public override Int64 Seek(Int64 offset, SeekOrigin origin) { - - EnsureNotClosed(); - EnsureCanSeek(); - - // If we have bytes in the WRITE buffer, flush them out, seek and be done. - if (_writePos > 0) { - - // We should be only writing the buffer and not flushing, - // but the previous version did flush and we stick to it for back-compat reasons. - FlushWrite(); - return _stream.Seek(offset, origin); - } - - // The buffer is either empty or we have a buffered READ. - - if (_readLen - _readPos > 0 && origin == SeekOrigin.Current) { - - // If we have bytes in the READ buffer, adjust the seek offset to account for the resulting difference - // between this stream's position and the underlying stream's position. - offset -= (_readLen - _readPos); - } - - Int64 oldPos = Position; - Contract.Assert(oldPos == _stream.Position + (_readPos - _readLen)); - - Int64 newPos = _stream.Seek(offset, origin); - - // If the seek destination is still within the data currently in the buffer, we want to keep the buffer data and continue using it. - // Otherwise we will throw away the buffer. This can only happen on READ, as we flushed WRITE data above. - - // The offset of the new/updated seek pointer within _buffer: - _readPos = (Int32) (newPos - (oldPos - _readPos)); - - // If the offset of the updated seek pointer in the buffer is still legal, then we can keep using the buffer: - if (0 <= _readPos && _readPos < _readLen) { - - // Adjust the seek pointer of the underlying stream to reflect the amount of useful bytes in the read buffer: - _stream.Seek(_readLen - _readPos, SeekOrigin.Current); - - } else { // The offset of the updated seek pointer is not a legal offset. Loose the buffer. - - _readPos = _readLen = 0; - } - - Contract.Assert(newPos == Position, "newPos (=" + newPos + ") == Position (=" + Position + ")"); - return newPos; - } - - - public override void SetLength(Int64 value) { - - if (value < 0) - throw new ArgumentOutOfRangeException("value", Environment.GetResourceString("ArgumentOutOfRange_NegFileSize")); - Contract.EndContractBlock(); - - EnsureNotClosed(); - EnsureCanSeek(); - EnsureCanWrite(); - - Flush(); - _stream.SetLength(value); - } - -} // class BufferedStream -} // namespace diff --git a/src/coreclr/src/mscorlib/src/System/IO/__DebugOutputTextWriter.cs b/src/coreclr/src/mscorlib/src/System/IO/__DebugOutputTextWriter.cs deleted file mode 100644 index 621bc41..0000000 --- a/src/coreclr/src/mscorlib/src/System/IO/__DebugOutputTextWriter.cs +++ /dev/null @@ -1,76 +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. - -#if _DEBUG -// This class writes to wherever OutputDebugString writes to. If you don't have -// a Windows app (ie, something hosted in IE), you can use this to redirect Console -// output for some good old-fashioned console spew in MSDEV's debug output window. - -using System; -using System.IO; -using System.Text; -using System.Security; -using System.Runtime.InteropServices; -using System.Runtime.Versioning; -using Microsoft.Win32; -using System.Globalization; - -namespace System.IO { - internal class __DebugOutputTextWriter : TextWriter { - private readonly String _consoleType; - - internal __DebugOutputTextWriter(String consoleType): base(CultureInfo.InvariantCulture) - { - _consoleType = consoleType; - } - - public override Encoding Encoding { -#if FEATURE_CORECLR - [System.Security.SecuritySafeCritical] -#endif - get { - if (Marshal.SystemDefaultCharSize == 1) - return Encoding.Default; - else - return new UnicodeEncoding(false, false); - } - } - - [System.Security.SecuritySafeCritical] // auto-generated - public override void Write(char c) - { - OutputDebugString(c.ToString()); - } - - [System.Security.SecuritySafeCritical] // auto-generated - public override void Write(String str) - { - OutputDebugString(str); - } - - [System.Security.SecuritySafeCritical] // auto-generated - public override void Write(char[] array) - { - if (array != null) - OutputDebugString(new String(array)); - } - - [System.Security.SecuritySafeCritical] // auto-generated - public override void WriteLine(String str) - { - if (str != null) - OutputDebugString(_consoleType + str); - else - OutputDebugString(""); - OutputDebugString(new String(CoreNewLine)); - } - - [System.Security.SecurityCritical] // auto-generated - [DllImport(Win32Native.KERNEL32, CharSet=CharSet.Auto)] - [SuppressUnmanagedCodeSecurityAttribute()] - private static extern void OutputDebugString(String output); - } -} - -#endif // _DEBUG diff --git a/src/coreclr/src/mscorlib/src/System/Runtime/CompilerServices/CallingConvention.cs b/src/coreclr/src/mscorlib/src/System/Runtime/CompilerServices/CallingConvention.cs deleted file mode 100644 index f44251d..0000000 --- a/src/coreclr/src/mscorlib/src/System/Runtime/CompilerServices/CallingConvention.cs +++ /dev/null @@ -1,30 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -//////////////////////////////////////////////////////////////////////////////// -//////////////////////////////////////////////////////////////////////////////// -namespace System.Runtime.CompilerServices -{ - // Types used in Custom Modifier to specify calling conventions. - [System.Runtime.InteropServices.ComVisible(true)] - public class CallConvCdecl - { - } - - [System.Runtime.InteropServices.ComVisible(true)] - public class CallConvStdcall - { - } - - [System.Runtime.InteropServices.ComVisible(true)] - public class CallConvThiscall - { - } - - [System.Runtime.InteropServices.ComVisible(true)] - public class CallConvFastcall - { - } - -} diff --git a/src/coreclr/src/mscorlib/src/System/Runtime/CompilerServices/HasCopySemanticsAttribute.cs b/src/coreclr/src/mscorlib/src/System/Runtime/CompilerServices/HasCopySemanticsAttribute.cs deleted file mode 100644 index 944a286..0000000 --- a/src/coreclr/src/mscorlib/src/System/Runtime/CompilerServices/HasCopySemanticsAttribute.cs +++ /dev/null @@ -1,14 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -namespace System.Runtime.CompilerServices -{ -[Serializable] -[AttributeUsage(AttributeTargets.Struct)] - public sealed class HasCopySemanticsAttribute : Attribute - { - public HasCopySemanticsAttribute() - {} - } -} diff --git a/src/coreclr/src/mscorlib/src/System/Runtime/CompilerServices/IDispatchConstantAttribute.cs b/src/coreclr/src/mscorlib/src/System/Runtime/CompilerServices/IDispatchConstantAttribute.cs deleted file mode 100644 index d6dfcbb..0000000 --- a/src/coreclr/src/mscorlib/src/System/Runtime/CompilerServices/IDispatchConstantAttribute.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. - -using System.Runtime.InteropServices; - -namespace System.Runtime.CompilerServices -{ -[Serializable] -[AttributeUsage(AttributeTargets.Field | AttributeTargets.Parameter, Inherited=false)] -[System.Runtime.InteropServices.ComVisible(true)] - public sealed class IDispatchConstantAttribute : CustomConstantAttribute - { - public IDispatchConstantAttribute() - { - } - - public override Object Value - { - get - { - return new DispatchWrapper(null); - } - } - } -} diff --git a/src/coreclr/src/mscorlib/src/System/Runtime/CompilerServices/IUnknownConstantAttribute.cs b/src/coreclr/src/mscorlib/src/System/Runtime/CompilerServices/IUnknownConstantAttribute.cs deleted file mode 100644 index f8717cf..0000000 --- a/src/coreclr/src/mscorlib/src/System/Runtime/CompilerServices/IUnknownConstantAttribute.cs +++ /dev/null @@ -1,27 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -using System.Runtime.InteropServices; - -namespace System.Runtime.CompilerServices -{ -[Serializable] -[AttributeUsage(AttributeTargets.Field | AttributeTargets.Parameter, Inherited=false)] -[System.Runtime.InteropServices.ComVisible(true)] - public sealed class IUnknownConstantAttribute : CustomConstantAttribute - { - public IUnknownConstantAttribute() - { - } - - public override Object Value - { - get - { - return new UnknownWrapper(null); - } - } - - } -} diff --git a/src/coreclr/src/mscorlib/src/System/Runtime/CompilerServices/IsBoxed.cs b/src/coreclr/src/mscorlib/src/System/Runtime/CompilerServices/IsBoxed.cs deleted file mode 100644 index 8b6691c..0000000 --- a/src/coreclr/src/mscorlib/src/System/Runtime/CompilerServices/IsBoxed.cs +++ /dev/null @@ -1,11 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -namespace System.Runtime.CompilerServices -{ - // Indicates that the modified reference type is a boxed valuetype - public static class IsBoxed - { - } -} diff --git a/src/coreclr/src/mscorlib/src/System/Runtime/CompilerServices/IsByValue.cs b/src/coreclr/src/mscorlib/src/System/Runtime/CompilerServices/IsByValue.cs deleted file mode 100644 index d16a853..0000000 --- a/src/coreclr/src/mscorlib/src/System/Runtime/CompilerServices/IsByValue.cs +++ /dev/null @@ -1,11 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -namespace System.Runtime.CompilerServices -{ - // Indicates that the modified method argument is passed by value - public static class IsByValue - { - } -} diff --git a/src/coreclr/src/mscorlib/src/System/Runtime/CompilerServices/IsConst.cs b/src/coreclr/src/mscorlib/src/System/Runtime/CompilerServices/IsConst.cs deleted file mode 100644 index 210e599..0000000 --- a/src/coreclr/src/mscorlib/src/System/Runtime/CompilerServices/IsConst.cs +++ /dev/null @@ -1,11 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -namespace System.Runtime.CompilerServices -{ - // Indicates that the modified type is const (i.e. has a const modifier) - public static class IsConst - { - } -} diff --git a/src/coreclr/src/mscorlib/src/System/Runtime/CompilerServices/IsCopyConstructed.cs b/src/coreclr/src/mscorlib/src/System/Runtime/CompilerServices/IsCopyConstructed.cs deleted file mode 100644 index ee40ee7..0000000 --- a/src/coreclr/src/mscorlib/src/System/Runtime/CompilerServices/IsCopyConstructed.cs +++ /dev/null @@ -1,11 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -namespace System.Runtime.CompilerServices -{ - [System.Runtime.InteropServices.ComVisible(true)] - public static class IsCopyConstructed - {} -} - diff --git a/src/coreclr/src/mscorlib/src/System/Runtime/CompilerServices/IsExplicitlyDereferenced.cs b/src/coreclr/src/mscorlib/src/System/Runtime/CompilerServices/IsExplicitlyDereferenced.cs deleted file mode 100644 index 480a621..0000000 --- a/src/coreclr/src/mscorlib/src/System/Runtime/CompilerServices/IsExplicitlyDereferenced.cs +++ /dev/null @@ -1,22 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -namespace System.Runtime.CompilerServices -{ - // Consider the following C++ method prototypes: - // 1) int foo(int ^arg); - // 2) int foo(int &arg); - // - // Both of these methods will have a .NET type signature that looks the - // same, but when importing a method from a metadata scope, the compiler - // needs to know what the calling syntax should be. This modopt and its - // partner "IsImplicitlyDereferenced" disambiguate reference versus - // pointer arguments. - // - // Indicates that the modified GC reference represents a pointer in a - // method signature. - public static class IsExplicitlyDereferenced - { - } -} diff --git a/src/coreclr/src/mscorlib/src/System/Runtime/CompilerServices/IsImplicitlyDereferenced.cs b/src/coreclr/src/mscorlib/src/System/Runtime/CompilerServices/IsImplicitlyDereferenced.cs deleted file mode 100644 index ea81cb8..0000000 --- a/src/coreclr/src/mscorlib/src/System/Runtime/CompilerServices/IsImplicitlyDereferenced.cs +++ /dev/null @@ -1,22 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -namespace System.Runtime.CompilerServices -{ - // Consider the following C++ method prototypes: - // 1) int foo(int ^arg); - // 2) int foo(int &arg); - // - // Both of these methods will have a .NET type signature that looks the - // same, but when importing a method from a metadata scope, the compiler - // needs to know what the calling syntax should be. This modopt and its - // partner "IsExplicitlyDereferenced" disambiguate reference versus - // pointer arguments. - // - // Indicates that the modified GC reference represents a reference in a - // method signature. - public static class IsImplicitlyDereferenced - { - } -} diff --git a/src/coreclr/src/mscorlib/src/System/Runtime/CompilerServices/IsJitIntrinsic.cs b/src/coreclr/src/mscorlib/src/System/Runtime/CompilerServices/IsJitIntrinsic.cs deleted file mode 100644 index 013e50f..0000000 --- a/src/coreclr/src/mscorlib/src/System/Runtime/CompilerServices/IsJitIntrinsic.cs +++ /dev/null @@ -1,12 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -namespace System.Runtime.CompilerServices -{ - // Indicates that the modified method is an intrinsic for which the JIT - // can perform special code generation. - public static class IsJitIntrinsic - { - } -} diff --git a/src/coreclr/src/mscorlib/src/System/Runtime/CompilerServices/IsLong.cs b/src/coreclr/src/mscorlib/src/System/Runtime/CompilerServices/IsLong.cs deleted file mode 100644 index e8bebfb..0000000 --- a/src/coreclr/src/mscorlib/src/System/Runtime/CompilerServices/IsLong.cs +++ /dev/null @@ -1,18 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -namespace System.Runtime.CompilerServices -{ - // The C++ standard indicates that a long is always 4-bytes, whereas the - // size of an integer is system dependent (not exceedign sizeof(long)). - // The CLR does not offer a mechanism for encoding this distinction, - // but it is critically important for maintaining language level type - // safety. - // - // Indicates that the modified integer is a standard C++ long. - // Could also be called IsAlternateIntegerType or something else. - public static class IsLong - { - } -} diff --git a/src/coreclr/src/mscorlib/src/System/Runtime/CompilerServices/IsPinned.cs b/src/coreclr/src/mscorlib/src/System/Runtime/CompilerServices/IsPinned.cs deleted file mode 100644 index e796d1a..0000000 --- a/src/coreclr/src/mscorlib/src/System/Runtime/CompilerServices/IsPinned.cs +++ /dev/null @@ -1,11 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -namespace System.Runtime.CompilerServices -{ - // Indicates that the modified instance is pinned in memory. - public static class IsPinned - { - } -} diff --git a/src/coreclr/src/mscorlib/src/System/Runtime/CompilerServices/IsSignUnspecifiedByte.cs b/src/coreclr/src/mscorlib/src/System/Runtime/CompilerServices/IsSignUnspecifiedByte.cs deleted file mode 100644 index e68f4d7..0000000 --- a/src/coreclr/src/mscorlib/src/System/Runtime/CompilerServices/IsSignUnspecifiedByte.cs +++ /dev/null @@ -1,16 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -namespace System.Runtime.CompilerServices -{ - // C++ recognizes three char types: signed char, unsigned char, and char. - // When a char is neither signed nor unsigned, it is a char. - // This modopt indicates that the modified instance is a char. - // - // Any compiler could use this to indicate that the user has not specified - // Sign behavior for the given byte. - public static class IsSignUnspecifiedByte - { - } -} diff --git a/src/coreclr/src/mscorlib/src/System/Runtime/CompilerServices/IsUdtReturn.cs b/src/coreclr/src/mscorlib/src/System/Runtime/CompilerServices/IsUdtReturn.cs deleted file mode 100644 index dd85914..0000000 --- a/src/coreclr/src/mscorlib/src/System/Runtime/CompilerServices/IsUdtReturn.cs +++ /dev/null @@ -1,11 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -namespace System.Runtime.CompilerServices -{ - // Indicates that the return type is a user defined type - public static class IsUdtReturn - { - } -} diff --git a/src/coreclr/src/mscorlib/src/System/Runtime/CompilerServices/NativeCppClassAttribute.cs b/src/coreclr/src/mscorlib/src/System/Runtime/CompilerServices/NativeCppClassAttribute.cs deleted file mode 100644 index 0d6c759..0000000 --- a/src/coreclr/src/mscorlib/src/System/Runtime/CompilerServices/NativeCppClassAttribute.cs +++ /dev/null @@ -1,16 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -using System; -using System.Runtime.InteropServices; - -namespace System.Runtime.CompilerServices { -[Serializable] -[AttributeUsage(AttributeTargets.Struct, Inherited = true), - System.Runtime.InteropServices.ComVisible(true)] - public sealed class NativeCppClassAttribute : Attribute - { - public NativeCppClassAttribute () {} - } -} diff --git a/src/coreclr/src/mscorlib/src/System/Runtime/CompilerServices/RequiredAttributeAttribute.cs b/src/coreclr/src/mscorlib/src/System/Runtime/CompilerServices/RequiredAttributeAttribute.cs deleted file mode 100644 index f363696..0000000 --- a/src/coreclr/src/mscorlib/src/System/Runtime/CompilerServices/RequiredAttributeAttribute.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. - -using System; - -namespace System.Runtime.CompilerServices -{ -[Serializable] -[AttributeUsage (AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Enum | AttributeTargets.Interface, - AllowMultiple=true, Inherited=false)] -[System.Runtime.InteropServices.ComVisible(true)] - public sealed class RequiredAttributeAttribute : Attribute - { - private Type requiredContract; - - public RequiredAttributeAttribute (Type requiredContract) - { - this.requiredContract= requiredContract; - } - public Type RequiredContract - { - get { return this.requiredContract; } - } - } -} diff --git a/src/coreclr/src/mscorlib/src/System/Runtime/CompilerServices/ScopelessEnumAttribute.cs b/src/coreclr/src/mscorlib/src/System/Runtime/CompilerServices/ScopelessEnumAttribute.cs deleted file mode 100644 index 9176918..0000000 --- a/src/coreclr/src/mscorlib/src/System/Runtime/CompilerServices/ScopelessEnumAttribute.cs +++ /dev/null @@ -1,14 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -namespace System.Runtime.CompilerServices -{ -[Serializable] -[AttributeUsage(AttributeTargets.Enum)] - public sealed class ScopelessEnumAttribute : Attribute - { - public ScopelessEnumAttribute() - {} - } -} diff --git a/src/coreclr/src/mscorlib/src/System/Runtime/Versioning/ComponentGuaranteesAttribute.cs b/src/coreclr/src/mscorlib/src/System/Runtime/Versioning/ComponentGuaranteesAttribute.cs deleted file mode 100644 index 0f906d5..0000000 --- a/src/coreclr/src/mscorlib/src/System/Runtime/Versioning/ComponentGuaranteesAttribute.cs +++ /dev/null @@ -1,44 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -/*============================================================ -** -** -** -** Purpose: Tracking whether a component signs up for a -** a strong contract spanning multiple versions. -** -===========================================================*/ -using System; - -namespace System.Runtime.Versioning { - - [Flags] - [Serializable] - public enum ComponentGuaranteesOptions - { - None = 0, - Exchange = 0x1, - Stable = 0x2, - SideBySide = 0x4, - } - - [AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Module | AttributeTargets.Class | - AttributeTargets.Struct | AttributeTargets.Interface | AttributeTargets.Delegate | - AttributeTargets.Enum | AttributeTargets.Method | AttributeTargets.Property | - AttributeTargets.Constructor | AttributeTargets.Event, - AllowMultiple = false, Inherited = false)] - public sealed class ComponentGuaranteesAttribute : Attribute { - private ComponentGuaranteesOptions _guarantees; - - public ComponentGuaranteesAttribute(ComponentGuaranteesOptions guarantees) - { - _guarantees = guarantees; - } - - public ComponentGuaranteesOptions Guarantees { - get { return _guarantees; } - } - } -} diff --git a/src/coreclr/src/mscorlib/src/System/Runtime/Versioning/ResourceAttributes.cs b/src/coreclr/src/mscorlib/src/System/Runtime/Versioning/ResourceAttributes.cs deleted file mode 100644 index 78a9ddb..0000000 --- a/src/coreclr/src/mscorlib/src/System/Runtime/Versioning/ResourceAttributes.cs +++ /dev/null @@ -1,237 +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: Resource annotation rules. -** -===========================================================*/ -using System; -using System.Diagnostics; -using System.Globalization; -using System.Runtime.CompilerServices; -using System.Text; -using Microsoft.Win32; -using System.Diagnostics.Contracts; - -namespace System.Runtime.Versioning -{ - [AttributeUsage(AttributeTargets.Method | AttributeTargets.Property | AttributeTargets.Constructor, Inherited = false)] - [Conditional("RESOURCE_ANNOTATION_WORK")] - public sealed class ResourceConsumptionAttribute : Attribute - { - private ResourceScope _consumptionScope; - private ResourceScope _resourceScope; - - public ResourceConsumptionAttribute(ResourceScope resourceScope) - { - _resourceScope = resourceScope; - _consumptionScope = _resourceScope; - } - - public ResourceConsumptionAttribute(ResourceScope resourceScope, ResourceScope consumptionScope) - { - _resourceScope = resourceScope; - _consumptionScope = consumptionScope; - } - - public ResourceScope ResourceScope { - get { return _resourceScope; } - } - - public ResourceScope ConsumptionScope { - get { return _consumptionScope; } - } - } - - [AttributeUsage(AttributeTargets.Method | AttributeTargets.Field | AttributeTargets.Property | AttributeTargets.Constructor, Inherited = false)] - [Conditional("RESOURCE_ANNOTATION_WORK")] - public sealed class ResourceExposureAttribute : Attribute - { - private ResourceScope _resourceExposureLevel; - - public ResourceExposureAttribute(ResourceScope exposureLevel) - { - _resourceExposureLevel = exposureLevel; - } - - public ResourceScope ResourceExposureLevel { - get { return _resourceExposureLevel; } - } - } - - - // Default visibility is Public, which isn't specified in this enum. - // Public == the lack of Private or Assembly - // Does this actually work? Need to investigate that. - [Flags] - public enum ResourceScope - { - None = 0, - // Resource type - Machine = 0x1, - Process = 0x2, - AppDomain = 0x4, - Library = 0x8, - // Visibility - Private = 0x10, // Private to this one class. - Assembly = 0x20, // Assembly-level, like C#'s "internal" - } - - - [Flags] - internal enum SxSRequirements - { - None = 0, - AppDomainID = 0x1, - ProcessID = 0x2, - CLRInstanceID = 0x4, // for multiple CLR's within the process - AssemblyName = 0x8, - TypeName = 0x10 - } - - public static class VersioningHelper - { - // These depend on the exact values given to members of the ResourceScope enum. - private const ResourceScope ResTypeMask = ResourceScope.Machine | ResourceScope.Process | ResourceScope.AppDomain | ResourceScope.Library; - private const ResourceScope VisibilityMask = ResourceScope.Private | ResourceScope.Assembly; - - [System.Security.SecuritySafeCritical] - [MethodImpl(MethodImplOptions.InternalCall)] - private static extern int GetRuntimeId(); - - public static String MakeVersionSafeName(String name, ResourceScope from, ResourceScope to) - { - return MakeVersionSafeName(name, from, to, null); - } - - [System.Security.SecuritySafeCritical] // auto-generated - public static String MakeVersionSafeName(String name, ResourceScope from, ResourceScope to, Type type) - { - ResourceScope fromResType = from & ResTypeMask; - ResourceScope toResType = to & ResTypeMask; - if (fromResType > toResType) - throw new ArgumentException(Environment.GetResourceString("Argument_ResourceScopeWrongDirection", fromResType, toResType), "from"); - - SxSRequirements requires = GetRequirements(to, from); - - if ((requires & (SxSRequirements.AssemblyName | SxSRequirements.TypeName)) != 0 && type == null) - throw new ArgumentNullException("type", Environment.GetResourceString("ArgumentNull_TypeRequiredByResourceScope")); - - // Add in process ID, CLR base address, and appdomain ID's. Also, use a character identifier - // to ensure that these can never accidentally overlap (ie, you create enough appdomains and your - // appdomain ID might equal your process ID). - StringBuilder safeName = new StringBuilder(name); - char separator = '_'; - if ((requires & SxSRequirements.ProcessID) != 0) { - safeName.Append(separator); - safeName.Append('p'); - safeName.Append(Win32Native.GetCurrentProcessId()); - } - if ((requires & SxSRequirements.CLRInstanceID) != 0) { - String clrID = GetCLRInstanceString(); - safeName.Append(separator); - safeName.Append('r'); - safeName.Append(clrID); - } - if ((requires & SxSRequirements.AppDomainID) != 0) { - safeName.Append(separator); - safeName.Append("ad"); - safeName.Append(AppDomain.CurrentDomain.Id); - } - if ((requires & SxSRequirements.TypeName) != 0) { - safeName.Append(separator); - safeName.Append(type.Name); - } - if ((requires & SxSRequirements.AssemblyName) != 0) { - safeName.Append(separator); - safeName.Append(type.Assembly.FullName); - } - return safeName.ToString(); - } - - private static String GetCLRInstanceString() - { - int id = GetRuntimeId(); - return id.ToString(CultureInfo.InvariantCulture); - } - - private static SxSRequirements GetRequirements(ResourceScope consumeAsScope, ResourceScope calleeScope) - { - SxSRequirements requires = SxSRequirements.None; - - switch(calleeScope & ResTypeMask) { - case ResourceScope.Machine: - switch(consumeAsScope & ResTypeMask) { - case ResourceScope.Machine: - // No work - break; - - case ResourceScope.Process: - requires |= SxSRequirements.ProcessID; - break; - - case ResourceScope.AppDomain: - requires |= SxSRequirements.AppDomainID | SxSRequirements.CLRInstanceID | SxSRequirements.ProcessID; - break; - - default: - throw new ArgumentException(Environment.GetResourceString("Argument_BadResourceScopeTypeBits", consumeAsScope), "consumeAsScope"); - } - break; - - case ResourceScope.Process: - if ((consumeAsScope & ResourceScope.AppDomain) != 0) - requires |= SxSRequirements.AppDomainID | SxSRequirements.CLRInstanceID; - break; - - case ResourceScope.AppDomain: - // No work - break; - - default: - throw new ArgumentException(Environment.GetResourceString("Argument_BadResourceScopeTypeBits", calleeScope), "calleeScope"); - } - - switch(calleeScope & VisibilityMask) { - case ResourceScope.None: // Public - implied - switch(consumeAsScope & VisibilityMask) { - case ResourceScope.None: // Public - implied - // No work - break; - - case ResourceScope.Assembly: - requires |= SxSRequirements.AssemblyName; - break; - - case ResourceScope.Private: - requires |= SxSRequirements.TypeName | SxSRequirements.AssemblyName; - break; - - default: - throw new ArgumentException(Environment.GetResourceString("Argument_BadResourceScopeVisibilityBits", consumeAsScope), "consumeAsScope"); - } - break; - - case ResourceScope.Assembly: - if ((consumeAsScope & ResourceScope.Private) != 0) - requires |= SxSRequirements.TypeName; - break; - - case ResourceScope.Private: - // No work - break; - - default: - throw new ArgumentException(Environment.GetResourceString("Argument_BadResourceScopeVisibilityBits", calleeScope), "calleeScope"); - } - - if (consumeAsScope == calleeScope) { - Contract.Assert(requires == SxSRequirements.None, "Computed a strange set of required resource scoping. It's probably wrong."); - } - - return requires; - } - } -} -- 2.7.4