From c73acaef356091cfb970ecf57be4294bd4001ca2 Mon Sep 17 00:00:00 2001 From: dotnet-maestro-bot Date: Wed, 13 Dec 2017 09:50:37 -0800 Subject: [PATCH 1/5] Update BuildTools, CoreClr, CoreFx, CoreSetup, ProjectNTfs, ProjectNTfsTestILC to prerelease-02312-02, preview1-26013-03, preview1-26013-06, preview1-26012-06, beta-26013-00, beta-26013-00, respectively --- BuildToolsVersion.txt | 2 +- dependencies.props | 32 ++++++++++++++--------------- external/test-runtime/optional.json | 6 +++--- tools-local/ILAsmVersion.txt | 2 +- 4 files changed, 21 insertions(+), 21 deletions(-) diff --git a/BuildToolsVersion.txt b/BuildToolsVersion.txt index ded5fccdd2bc..6543f08fce36 100644 --- a/BuildToolsVersion.txt +++ b/BuildToolsVersion.txt @@ -1 +1 @@ -2.1.0-prerelease-02304-01 +2.1.0-prerelease-02312-02 diff --git a/dependencies.props b/dependencies.props index 90df5ffea313..2e97de6614fa 100644 --- a/dependencies.props +++ b/dependencies.props @@ -9,15 +9,15 @@ These ref versions are pulled from https://github.com/dotnet/versions. --> - ba779d501d3d8c70deb52b7e1074b897b6b9b357 - ba779d501d3d8c70deb52b7e1074b897b6b9b357 - 92e0b8eb154b97421de10a605fcda7993f99466c + fb15a62b48c5f6cc1cd3d658c7b74ddc3a5e1a78 + fb15a62b48c5f6cc1cd3d658c7b74ddc3a5e1a78 + fb15a62b48c5f6cc1cd3d658c7b74ddc3a5e1a78 96dc7805f5df4a70a55783964ce69dcd91bfca80 - 92e0b8eb154b97421de10a605fcda7993f99466c - 92e0b8eb154b97421de10a605fcda7993f99466c + fb15a62b48c5f6cc1cd3d658c7b74ddc3a5e1a78 + fb15a62b48c5f6cc1cd3d658c7b74ddc3a5e1a78 8bd1ec5fac9f0eec34ff6b34b1d878b4359e02dd 6298244e25cf84d91e3cda9627315f2425274624 - ee6b82e62028a90468bb3827a660ee946d990409 + fb15a62b48c5f6cc1cd3d658c7b74ddc3a5e1a78 @@ -31,16 +31,16 @@ - preview1-26007-02 - 2.1.0-preview1-26007-02 - 2.1.0-preview1-26007-01 - beta-26007-00 - beta-26007-00 - 1.0.0-beta-26007-00 + preview1-26013-06 + 2.1.0-preview1-26013-06 + 2.1.0-preview1-26013-03 + beta-26013-00 + beta-26013-00 + 1.0.0-beta-26013-00 2.1.0-preview1-25929-07 2.1.0-preview1-25929-07 - 2.1.0-preview1-26007-02 - 2.1.0-preview1-26007-02 + 2.1.0-preview1-26012-06 + 2.1.0-preview1-26012-06 4.4.0 @@ -48,13 +48,13 @@ 1.0.3-prerelease-00921-01 1.0.0-beta-build0007 1.0.3-alpha-experimental - 2.1.0-prerelease-02304-01 + 2.1.0-prerelease-02312-02 Microsoft.DotNet.Build.Tasks.Feed - 2.1.0-prerelease-02304-01 + 2.1.0-prerelease-02312-02 diff --git a/external/test-runtime/optional.json b/external/test-runtime/optional.json index 30533ec08aeb..8af2635f4bf2 100644 --- a/external/test-runtime/optional.json +++ b/external/test-runtime/optional.json @@ -3,9 +3,9 @@ "net45": { "dependencies": { "Microsoft.DotNet.IBCMerge": "4.6.0-alpha-00001", - "TestILC.amd64ret": "1.0.0-beta-26007-00", - "TestILC.armret": "1.0.0-beta-26007-00", - "TestILC.x86ret": "1.0.0-beta-26007-00" + "TestILC.amd64ret": "1.0.0-beta-26013-00", + "TestILC.armret": "1.0.0-beta-26013-00", + "TestILC.x86ret": "1.0.0-beta-26013-00" } } } diff --git a/tools-local/ILAsmVersion.txt b/tools-local/ILAsmVersion.txt index 8e75bd05c19f..11c88677ba0d 100644 --- a/tools-local/ILAsmVersion.txt +++ b/tools-local/ILAsmVersion.txt @@ -1 +1 @@ -2.1.0-preview1-26007-01 \ No newline at end of file +2.1.0-preview1-26013-03 \ No newline at end of file From 8d54c4744b997fdf3a42c80df392f2e39c91d5ec Mon Sep 17 00:00:00 2001 From: ahsonkhan Date: Wed, 6 Dec 2017 19:31:34 -0800 Subject: [PATCH 2/5] Change Pin to take an optional integer offset. --- .../tests/System/Buffers/NativeOwnedMemory.cs | 6 +++++- src/System.Memory/ref/System.Memory.cs | 2 +- .../src/System/Buffers/MemoryHandle.cs | 18 ------------------ .../src/System/Buffers/OwnedMemory.cs | 2 +- src/System.Memory/src/System/Memory.cs | 3 +-- src/System.Memory/src/System/ReadOnlyMemory.cs | 3 +-- .../tests/Memory/CustomMemoryForTest.cs | 4 ++-- 7 files changed, 11 insertions(+), 27 deletions(-) diff --git a/src/Common/tests/System/Buffers/NativeOwnedMemory.cs b/src/Common/tests/System/Buffers/NativeOwnedMemory.cs index c5fd2fe3756f..ec7dff5d2371 100644 --- a/src/Common/tests/System/Buffers/NativeOwnedMemory.cs +++ b/src/Common/tests/System/Buffers/NativeOwnedMemory.cs @@ -53,7 +53,11 @@ protected override bool IsRetained public override unsafe Span Span => new Span((void*)_ptr, _length); - public override unsafe MemoryHandle Pin() => new MemoryHandle(this, (void*)_ptr); + public override unsafe MemoryHandle Pin(int offset = 0) + { + void* pointer = (void*)((byte*)_ptr + offset); + return new MemoryHandle(this, _ptr); + } public override bool Release() { diff --git a/src/System.Memory/ref/System.Memory.cs b/src/System.Memory/ref/System.Memory.cs index ee872fc66921..bb1e343e2ec6 100644 --- a/src/System.Memory/ref/System.Memory.cs +++ b/src/System.Memory/ref/System.Memory.cs @@ -228,7 +228,7 @@ public abstract class OwnedMemory : IDisposable, IRetainable public abstract Span Span { get; } public void Dispose() { throw null; } protected abstract void Dispose(bool disposing); - public abstract MemoryHandle Pin(); + public abstract MemoryHandle Pin(int offset = 0); public abstract bool Release(); public abstract void Retain(); protected internal abstract bool TryGetArray(out ArraySegment arraySegment); diff --git a/src/System.Memory/src/System/Buffers/MemoryHandle.cs b/src/System.Memory/src/System/Buffers/MemoryHandle.cs index fb192d1a6bc9..a7e859798adc 100644 --- a/src/System.Memory/src/System/Buffers/MemoryHandle.cs +++ b/src/System.Memory/src/System/Buffers/MemoryHandle.cs @@ -41,24 +41,6 @@ public unsafe struct MemoryHandle : IDisposable /// public bool HasPointer => _pointer != null; - /// - /// Adds an offset to the pinned pointer. - /// - /// - /// Throw when pinned pointer is null. - /// - internal void AddOffset(int offset) - { - if (_pointer == null) - { - ThrowHelper.ThrowArgumentNullException(ExceptionArgument.pointer); - } - else - { - _pointer = (void*)((byte*)_pointer + offset); - } - } - /// /// Frees the pinned handle and releases IRetainable. /// diff --git a/src/System.Memory/src/System/Buffers/OwnedMemory.cs b/src/System.Memory/src/System/Buffers/OwnedMemory.cs index 0342ed9196bc..f78bf73804bd 100644 --- a/src/System.Memory/src/System/Buffers/OwnedMemory.cs +++ b/src/System.Memory/src/System/Buffers/OwnedMemory.cs @@ -45,7 +45,7 @@ public Memory Memory /// /// Returns a handle for the array that has been pinned and hence its address can be taken /// - public abstract MemoryHandle Pin(); + public abstract MemoryHandle Pin(int offset = 0); /// /// Returns an array segment. diff --git a/src/System.Memory/src/System/Memory.cs b/src/System.Memory/src/System/Memory.cs index e998455d2adb..7f161ee704f7 100644 --- a/src/System.Memory/src/System/Memory.cs +++ b/src/System.Memory/src/System/Memory.cs @@ -235,8 +235,7 @@ public unsafe MemoryHandle Retain(bool pin = false) { if (_index < 0) { - memoryHandle = ((OwnedMemory)_object).Pin(); - memoryHandle.AddOffset((_index & RemoveOwnedFlagBitMask) * Unsafe.SizeOf()); + memoryHandle = ((OwnedMemory)_object).Pin((_index & RemoveOwnedFlagBitMask) * Unsafe.SizeOf()); } else if (typeof(T) == typeof(char) && _object is string s) { diff --git a/src/System.Memory/src/System/ReadOnlyMemory.cs b/src/System.Memory/src/System/ReadOnlyMemory.cs index 6a27ecf1e206..889b25b4fc75 100644 --- a/src/System.Memory/src/System/ReadOnlyMemory.cs +++ b/src/System.Memory/src/System/ReadOnlyMemory.cs @@ -209,8 +209,7 @@ public unsafe MemoryHandle Retain(bool pin = false) { if (_index < 0) { - memoryHandle = ((OwnedMemory)_object).Pin(); - memoryHandle.AddOffset((_index & RemoveOwnedFlagBitMask) * Unsafe.SizeOf()); + memoryHandle = ((OwnedMemory)_object).Pin((_index & RemoveOwnedFlagBitMask) * Unsafe.SizeOf()); } else if (typeof(T) == typeof(char) && _object is string s) { diff --git a/src/System.Memory/tests/Memory/CustomMemoryForTest.cs b/src/System.Memory/tests/Memory/CustomMemoryForTest.cs index 04f6c2d30db5..a3a80c00e0f3 100644 --- a/src/System.Memory/tests/Memory/CustomMemoryForTest.cs +++ b/src/System.Memory/tests/Memory/CustomMemoryForTest.cs @@ -38,13 +38,13 @@ public override Span Span } } - public override MemoryHandle Pin() + public override MemoryHandle Pin(int index = 0) { unsafe { Retain(); var handle = GCHandle.Alloc(_array, GCHandleType.Pinned); - return new MemoryHandle(this, (void*)handle.AddrOfPinnedObject(), handle); + return new MemoryHandle(this, Unsafe.Add((void*)handle.AddrOfPinnedObject(), index), handle); } } From 1db2d8b7b9a9d3ee4324963352d7094507f1f3ae Mon Sep 17 00:00:00 2001 From: ahsonkhan Date: Wed, 6 Dec 2017 19:37:23 -0800 Subject: [PATCH 3/5] Add optional offset to Pin in System.Runtime ref. --- src/System.Runtime/ref/System.Runtime.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/System.Runtime/ref/System.Runtime.cs b/src/System.Runtime/ref/System.Runtime.cs index 960e91f4279e..731da2910d4c 100644 --- a/src/System.Runtime/ref/System.Runtime.cs +++ b/src/System.Runtime/ref/System.Runtime.cs @@ -3889,7 +3889,7 @@ public abstract class OwnedMemory : IDisposable, IRetainable public abstract Span Span { get; } public void Dispose() { throw null; } protected abstract void Dispose(bool disposing); - public abstract MemoryHandle Pin(); + public abstract MemoryHandle Pin(int offset = 0); public abstract bool Release(); public abstract void Retain(); protected internal abstract bool TryGetArray(out ArraySegment arraySegment); From 19dc774e82e6fd4cd146c409d7f9dbfde69562a7 Mon Sep 17 00:00:00 2001 From: ahsonkhan Date: Thu, 7 Dec 2017 21:34:01 -0800 Subject: [PATCH 4/5] Add bounds checks for offset in classes that impl OwnedMemory --- src/Common/tests/System/Buffers/NativeOwnedMemory.cs | 3 ++- src/System.Memory/tests/Memory/CustomMemoryForTest.cs | 5 +++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/Common/tests/System/Buffers/NativeOwnedMemory.cs b/src/Common/tests/System/Buffers/NativeOwnedMemory.cs index ec7dff5d2371..9ae39d88260c 100644 --- a/src/Common/tests/System/Buffers/NativeOwnedMemory.cs +++ b/src/Common/tests/System/Buffers/NativeOwnedMemory.cs @@ -55,8 +55,9 @@ protected override bool IsRetained public override unsafe MemoryHandle Pin(int offset = 0) { + if (offset < 0 || offset >= _length) throw new ArgumentOutOfRangeException(nameof(offset)); void* pointer = (void*)((byte*)_ptr + offset); - return new MemoryHandle(this, _ptr); + return new MemoryHandle(this, pointer); } public override bool Release() diff --git a/src/System.Memory/tests/Memory/CustomMemoryForTest.cs b/src/System.Memory/tests/Memory/CustomMemoryForTest.cs index a3a80c00e0f3..e0596432108c 100644 --- a/src/System.Memory/tests/Memory/CustomMemoryForTest.cs +++ b/src/System.Memory/tests/Memory/CustomMemoryForTest.cs @@ -38,13 +38,14 @@ public override Span Span } } - public override MemoryHandle Pin(int index = 0) + public override MemoryHandle Pin(int offset = 0) { unsafe { Retain(); + if (offset < 0 || offset >= _array.Length) throw new ArgumentOutOfRangeException(nameof(offset)); var handle = GCHandle.Alloc(_array, GCHandleType.Pinned); - return new MemoryHandle(this, Unsafe.Add((void*)handle.AddrOfPinnedObject(), index), handle); + return new MemoryHandle(this, Unsafe.Add((void*)handle.AddrOfPinnedObject(), offset), handle); } } From 687a93a8eb246ef3529b847c99e65d1d69ea1a63 Mon Sep 17 00:00:00 2001 From: ahsonkhan Date: Fri, 8 Dec 2017 18:29:16 -0800 Subject: [PATCH 5/5] Adding compiler services using directive to use Unsafe. --- src/System.Memory/tests/Memory/CustomMemoryForTest.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/System.Memory/tests/Memory/CustomMemoryForTest.cs b/src/System.Memory/tests/Memory/CustomMemoryForTest.cs index e0596432108c..c90c0ceeabf6 100644 --- a/src/System.Memory/tests/Memory/CustomMemoryForTest.cs +++ b/src/System.Memory/tests/Memory/CustomMemoryForTest.cs @@ -3,6 +3,7 @@ // See the LICENSE file in the project root for more information. using System.Buffers; +using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Threading;