summaryrefslogtreecommitdiff
path: root/src/mscorlib
diff options
context:
space:
mode:
authorAhson Ahmed Khan <ahsonkhan@users.noreply.github.com>2017-09-28 20:05:35 -0700
committerGitHub <noreply@github.com>2017-09-28 20:05:35 -0700
commiteab3a973346bf4bc5ddffc5201f862141a96b000 (patch)
tree9aaddb47ca7642f0eccaac84cd0b30ecc74641de /src/mscorlib
parent591983b2b475f9d2a08e29b5640d6a70b124d816 (diff)
downloadcoreclr-eab3a973346bf4bc5ddffc5201f862141a96b000.tar.gz
coreclr-eab3a973346bf4bc5ddffc5201f862141a96b000.tar.bz2
coreclr-eab3a973346bf4bc5ddffc5201f862141a96b000.zip
Fixing Retain to return MemoryHandle with correct PinnedPointer (#14248)
* Fixing Retain to return MemoryHandle with correct PinnedPointer. * Make MemoryHandle AddOffset internal.
Diffstat (limited to 'src/mscorlib')
-rw-r--r--src/mscorlib/shared/System/Buffers/MemoryHandle.cs12
-rw-r--r--src/mscorlib/shared/System/Memory.cs1
-rw-r--r--src/mscorlib/shared/System/ReadOnlyMemory.cs1
-rw-r--r--src/mscorlib/src/System/ThrowHelper.cs3
4 files changed, 16 insertions, 1 deletions
diff --git a/src/mscorlib/shared/System/Buffers/MemoryHandle.cs b/src/mscorlib/shared/System/Buffers/MemoryHandle.cs
index fcdc7fe17f..bcbb527b50 100644
--- a/src/mscorlib/shared/System/Buffers/MemoryHandle.cs
+++ b/src/mscorlib/shared/System/Buffers/MemoryHandle.cs
@@ -21,6 +21,18 @@ namespace System.Buffers
_handle = handle;
}
+ internal void AddOffset(int offset)
+ {
+ if (_pointer == null)
+ {
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.pointer);
+ }
+ else
+ {
+ _pointer = (void*)((byte*)_pointer + offset);
+ }
+ }
+
[CLSCompliant(false)]
public void* PinnedPointer => _pointer;
diff --git a/src/mscorlib/shared/System/Memory.cs b/src/mscorlib/shared/System/Memory.cs
index 0ea4bdca0e..63d36a9641 100644
--- a/src/mscorlib/shared/System/Memory.cs
+++ b/src/mscorlib/shared/System/Memory.cs
@@ -185,6 +185,7 @@ namespace System
if (_index < 0)
{
memoryHandle = ((OwnedMemory<T>)_arrayOrOwnedMemory).Pin();
+ memoryHandle.AddOffset((_index & RemoveOwnedFlagBitMask) * Unsafe.SizeOf<T>());
}
else
{
diff --git a/src/mscorlib/shared/System/ReadOnlyMemory.cs b/src/mscorlib/shared/System/ReadOnlyMemory.cs
index c19d381aaf..ddbfbdde89 100644
--- a/src/mscorlib/shared/System/ReadOnlyMemory.cs
+++ b/src/mscorlib/shared/System/ReadOnlyMemory.cs
@@ -170,6 +170,7 @@ namespace System
if (_index < 0)
{
memoryHandle = ((OwnedMemory<T>)_arrayOrOwnedMemory).Pin();
+ memoryHandle.AddOffset((_index & RemoveOwnedFlagBitMask) * Unsafe.SizeOf<T>());
}
else
{
diff --git a/src/mscorlib/src/System/ThrowHelper.cs b/src/mscorlib/src/System/ThrowHelper.cs
index 876f5926e7..68eff515f5 100644
--- a/src/mscorlib/src/System/ThrowHelper.cs
+++ b/src/mscorlib/src/System/ThrowHelper.cs
@@ -430,7 +430,8 @@ namespace System
s,
keyValuePair,
input,
- ownedMemory
+ ownedMemory,
+ pointer
}
//