We need you! We're working hard on the next version of Developer Fusion -
Let us know what you think we should be up to!
- ////////////////////////////////////////////////////////////////////////////////
- ////////////////////////////////////////////////////////////////////////////////
- namespace System.Runtime.CompilerServices
- {
-
- using System;
- using System.Runtime.CompilerServices;
- using System.Runtime.InteropServices;
- using System.Runtime.ConstrainedExecution;
- using System.Security.Permissions;
- using System.Threading;
-
- public static class RuntimeHelpers
- {
- [MethodImplAttribute(MethodImplOptions.InternalCall)]
- public static extern void InitializeArray(Array array, RuntimeFieldHandle fldHandle);
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- [MethodImplAttribute(MethodImplOptions.InternalCall)]
- public static extern object GetObjectValue(object obj);
-
-
-
-
-
-
-
-
-
- [MethodImplAttribute(MethodImplOptions.InternalCall)]
- private static extern void _RunClassConstructor(IntPtr type);
- public static void RunClassConstructor(RuntimeTypeHandle type)
- {
- _RunClassConstructor(type.Value);
- }
-
-
-
-
-
-
-
-
-
- [MethodImplAttribute(MethodImplOptions.InternalCall)]
- private static extern void _RunModuleConstructor(IntPtr module);
-
- public static void RunModuleConstructor(ModuleHandle module)
- {
- unsafe {
- _RunModuleConstructor(new IntPtr(module.Value));
- }
- }
-
- [MethodImplAttribute(MethodImplOptions.InternalCall)]
- private static extern void _PrepareMethod(IntPtr method, RuntimeTypeHandle[] instantiation);
-
-
- [SecurityPermission(SecurityAction.LinkDemand, UnmanagedCode = true)]
- public static void PrepareMethod(RuntimeMethodHandle method)
- {
- _PrepareMethod(method.Value, null);
- }
-
-
- [SecurityPermission(SecurityAction.LinkDemand, UnmanagedCode = true)]
- public static void PrepareMethod(RuntimeMethodHandle method, RuntimeTypeHandle[] instantiation)
- {
- _PrepareMethod(method.Value, instantiation);
- }
-
-
-
-
-
-
-
-
-
-
- [MethodImplAttribute(MethodImplOptions.InternalCall)]
- [SecurityPermission(SecurityAction.LinkDemand, UnmanagedCode = true)]
- public static extern void PrepareDelegate(Delegate d);
-
- public static int GetHashCode(object o)
- {
- return Object.InternalGetHashCode(o);
- }
-
- public static new bool Equals(object o1, object o2)
- {
- return Object.InternalEquals(o1, o2);
- }
-
- public static int OffsetToStringData {
- get {
-
-
-
-
-
-
-
- #if WIN32
- return 12;
- #else
- return 16;
- #endif
- }
- }
-
- [MethodImplAttribute(MethodImplOptions.InternalCall)]
- [SecurityPermission(SecurityAction.LinkDemand, UnmanagedCode = true)]
- [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
- public static extern void ProbeForSufficientStack();
-
-
-
- [SecurityPermission(SecurityAction.LinkDemand, UnmanagedCode = true)]
- [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
- public static void PrepareConstrainedRegions()
- {
- ProbeForSufficientStack();
- }
-
-
-
- [SecurityPermission(SecurityAction.LinkDemand, UnmanagedCode = true)]
- [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
- public static void PrepareConstrainedRegionsNoOP()
- {
- }
-
- public delegate void TryCode(object userData);
-
- public delegate void CleanupCode(object userData, bool exceptionThrown);
-
- [MethodImplAttribute(MethodImplOptions.InternalCall)]
- [SecurityPermission(SecurityAction.LinkDemand, UnmanagedCode = true)]
- public static extern void ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, object userData);
-
- [PrePrepareMethod()]
- static internal void ExecuteBackoutCodeHelper(object backoutCode, object userData, bool exceptionThrown)
- {
- ((CleanupCode)backoutCode)(userData, exceptionThrown);
- }
-
- [SecurityPermission(SecurityAction.LinkDemand, UnmanagedCode = true)]
- [HostProtection(Synchronization = true)]
- static internal void ExecuteCodeWithLock(object lockObject, TryCode code, object userState)
- {
- ExecuteWithLockHelper execHelper = new ExecuteWithLockHelper(lockObject, code, userState);
- ExecuteCodeWithGuaranteedCleanup(s_EnterMonitor, s_ExitMonitor, execHelper);
- }
-
- private static TryCode s_EnterMonitor = new TryCode(EnterMonitorAndTryCode);
- private static CleanupCode s_ExitMonitor = new CleanupCode(ExitMonitorOnBackout);
-
- private static void EnterMonitorAndTryCode(object helper)
- {
- ExecuteWithLockHelper execHelper = (ExecuteWithLockHelper)helper;
- BCLDebug.Assert(execHelper != null, "ExecuteWithLockHelper is null");
- BCLDebug.Assert(execHelper.m_lockObject != null, "LockObject is null");
- BCLDebug.Assert(execHelper.m_userCode != null, "UserCode is null");
-
- Monitor.ReliableEnter(execHelper.m_lockObject, ref execHelper.m_tookLock);
- execHelper.m_userCode(execHelper.m_userState);
- }
-
- [PrePrepareMethod()]
- private static void ExitMonitorOnBackout(object helper, bool exceptionThrown)
- {
- ExecuteWithLockHelper execHelper = (ExecuteWithLockHelper)helper;
- BCLDebug.Assert(execHelper != null, "ExecuteWithLockHelper is null");
- BCLDebug.Assert(execHelper.m_lockObject != null, "LockObject is null");
-
- if (execHelper.m_tookLock)
- Monitor.Exit(execHelper.m_lockObject);
- }
-
- class ExecuteWithLockHelper
- {
- internal object m_lockObject;
- internal bool m_tookLock;
- internal TryCode m_userCode;
- internal object m_userState;
-
- internal ExecuteWithLockHelper(object lockObject, TryCode userCode, object userState)
- {
- m_lockObject = lockObject;
- m_userCode = userCode;
- m_userState = userState;
- }
-
- }
- }
- }