Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/corert.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Lapounov <antonl@microsoft.com>2017-06-14 04:12:55 +0300
committerAnton Lapounov <antonl@microsoft.com>2017-06-14 04:12:55 +0300
commit5fb55f6a1e2d1a2ae462ccaf50ade889728e41cb (patch)
tree1ac4628357cb765a80a93e95472ace145f849d58 /src/Runtime.Base
parentd62fbb30583226ba56740836da98e52f1ac10278 (diff)
Introduce UnsafeGCHandle and enable the blittable check in GCHandle.set_Target.
CR: JKotas, FadiM, DavidWr At some moment the CallConverterThunk code took dependency on the blittable check missing in GCHandle.set_Target (change 1566458), so we had to place that check under "#if CORERT" (https://github.com/dotnet/corert/pull/1393). This change enables the check and introduces the UnsafeGCHandle structure to use in the CallConverterThunk code. UnsafeGCHandle is a faster version of the GCHandle structure with the following differences: * The constructor assumes the handle type is valid; no range check is performed. * The pinned flag is not stored in the _handle field. * The Target getter and setter assume the UnsafeGCHandle has been allocated. * No blittable check is performed when allocating a pinned UnsafeGCHandle or setting its target. * The GetRawTargetAddress method returns the raw address of the target (the pointer to its m_pEEType field). * The Free method is not thread-safe and does not throw if the UnsafeGCHandle has not been allocated or has been already freed. Also avoid the native runtime call in release builds in the RuntimeImports.RhHandleGet method and Runtime.Base's version of the UnsafeGCHandle.get_Target method (in debug builds the runtime performs additional checks). [tfs-changeset: 1661633]
Diffstat (limited to 'src/Runtime.Base')
-rw-r--r--src/Runtime.Base/src/System/Runtime/InteropServices/UnsafeGCHandle.cs7
1 files changed, 6 insertions, 1 deletions
diff --git a/src/Runtime.Base/src/System/Runtime/InteropServices/UnsafeGCHandle.cs b/src/Runtime.Base/src/System/Runtime/InteropServices/UnsafeGCHandle.cs
index 31b7d2a26..b7b07f209 100644
--- a/src/Runtime.Base/src/System/Runtime/InteropServices/UnsafeGCHandle.cs
+++ b/src/Runtime.Base/src/System/Runtime/InteropServices/UnsafeGCHandle.cs
@@ -33,12 +33,17 @@ namespace System.Runtime.InteropServices
}
// Target property - allows getting / updating of the handle's referent.
- public Object Target
+ public unsafe Object Target
{
get
{
Debug.Assert(IsAllocated, "handle isn't initialized");
+#if DEBUG
+ // The runtime performs additional checks in debug builds
return InternalCalls.RhHandleGet(_handle);
+#else
+ return Unsafe.As<IntPtr, Object>(ref *(IntPtr*)_handle);
+#endif
}
set