9 [__DynamicallyInvokable]
16 private static volatile GCHandleCookieTable s_cookieTable;
18 private static volatile bool s_probeIsActive;
23 [__DynamicallyInvokable]
27 [__DynamicallyInvokable]
34 return InternalGet(GetHandleValue());
37 [__DynamicallyInvokable]
44 InternalSet(GetHandleValue(), value,
IsPinned());
51 [__DynamicallyInvokable]
54 [__DynamicallyInvokable]
61 [SecuritySafeCritical]
64 s_probeIsActive = Mda.IsInvalidGCHandleCookieProbeEnabled();
67 s_cookieTable =
new GCHandleCookieTable();
78 m_handle = InternalAlloc(value, type);
86 internal GCHandle(IntPtr handle)
88 InternalCheckDomain(handle);
97 [__DynamicallyInvokable]
109 [__DynamicallyInvokable]
118 [__DynamicallyInvokable]
126 s_cookieTable.RemoveHandleIfPresent(handle);
128 InternalFree((
IntPtr)((
long)handle & -2));
148 return InternalAddrOfPinnedObject(GetHandleValue());
174 intPtr = s_cookieTable.GetHandle(value);
177 Mda.FireInvalidGCHandleCookieProbe(value);
199 return s_cookieTable.FindOrAddHandle(value.m_handle);
201 return value.m_handle;
206 [__DynamicallyInvokable]
216 [__DynamicallyInvokable]
224 return m_handle == gCHandle.m_handle;
232 [__DynamicallyInvokable]
235 return a.m_handle == b.m_handle;
243 [__DynamicallyInvokable]
246 return a.m_handle != b.m_handle;
249 internal IntPtr GetHandleValue()
251 return new IntPtr((
long)m_handle & -2);
256 return ((
long)m_handle & 1) != 0;
259 internal void SetIsPinned()
261 m_handle =
new IntPtr((
long)m_handle | 1);
266 internal static extern IntPtr InternalAlloc(
object value,
GCHandleType type);
270 internal static extern void InternalFree(IntPtr handle);
274 internal static extern object InternalGet(IntPtr handle);
278 internal static extern void InternalSet(IntPtr handle,
object value,
bool isPinned);
282 internal static extern object InternalCompareExchange(IntPtr handle,
object value,
object oldValue,
bool isPinned);
286 internal static extern IntPtr InternalAddrOfPinnedObject(IntPtr handle);
290 internal static extern void InternalCheckDomain(IntPtr handle);
294 internal static extern GCHandleType InternalGetHandleType(IntPtr handle);
static bool operator !=(GCHandle a, GCHandle b)
Returns a value indicating whether two T:System.Runtime.InteropServices.GCHandle objects are not equa...
The exception that is thrown when the value of an argument is outside the allowable range of values a...
override bool Equals(object o)
Determines whether the specified T:System.Runtime.InteropServices.GCHandle object is equal to the cur...
bool IsAllocated
Gets a value indicating whether the handle is allocated.
Provides information about, and means to manipulate, the current environment and platform....
override int GetHashCode()
Returns an identifier for the current T:System.Runtime.InteropServices.GCHandle object.
static int CompareExchange(ref int location1, int value, int comparand)
Compares two 32-bit signed integers for equality and, if they are equal, replaces the first value.
Indicates that a modified instance is pinned in memory. This class cannot be inherited.
A platform-specific type that is used to represent a pointer or a handle.
static GCHandle Alloc(object value)
Allocates a F:System.Runtime.InteropServices.GCHandleType.Normal handle for the specified object.
GCHandleType
Represents the types of handles the T:System.Runtime.InteropServices.GCHandle class can allocate.
static GCHandle Alloc(object value, GCHandleType type)
Allocates a handle of the specified type for the specified object.
Provides a way to access a managed object from unmanaged memory.
IntPtr AddrOfPinnedObject()
Retrieves the address of an object in a F:System.Runtime.InteropServices.GCHandleType....
MethodImplOptions
Defines the details of how a method is implemented.
void Free()
Releases a T:System.Runtime.InteropServices.GCHandle.
static IntPtr ToIntPtr(GCHandle value)
Returns the internal integer representation of a T:System.Runtime.InteropServices....
static bool operator==(GCHandle a, GCHandle b)
Returns a value indicating whether two T:System.Runtime.InteropServices.GCHandle objects are equal.
static readonly IntPtr Zero
A read-only field that represents a pointer or handle that has been initialized to zero.
The exception that is thrown when a method call is invalid for the object's current state.
Provides atomic operations for variables that are shared by multiple threads.
static GCHandle FromIntPtr(IntPtr value)
Returns a new T:System.Runtime.InteropServices.GCHandle object created from a handle to a managed obj...
unsafe override int GetHashCode()
Returns the hash code for this instance.
object Target
Gets or sets the object this handle represents.