2010-04-06 Jb Evain <jbevain@novell.com>
[mcs.git] / class / corlib / System.Runtime.CompilerServices / RuntimeHelpers.cs
blob4a8672b28583003b1d1cecfe1d90c6f61d746ad8
1 // System.Runtime.CompilerServices.RuntimeHelpers
2 //
3 // Sean MacIsaac (macisaac@ximian.com)
4 // Paolo Molaro (lupus@ximian.com)
5 //
6 // (C) Ximian, Inc. 2001
8 //
9 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
18 //
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
21 //
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 using System.Runtime.ConstrainedExecution;
32 using System.Reflection;
34 namespace System.Runtime.CompilerServices
36 public static class RuntimeHelpers
38 public delegate void TryCode (Object userData);
40 public delegate void CleanupCode (Object userData, bool exceptionThrown);
42 [MethodImplAttribute(MethodImplOptions.InternalCall)]
43 static extern void InitializeArray (Array array, IntPtr fldHandle);
45 public static void InitializeArray (Array array, RuntimeFieldHandle fldHandle)
47 if ((array == null) || (fldHandle.Value == IntPtr.Zero))
48 throw new ArgumentNullException ();
50 InitializeArray (array, fldHandle.Value);
53 public static extern int OffsetToStringData {
54 [MethodImpl (MethodImplOptions.InternalCall)]
55 get;
58 public static int GetHashCode (object o) {
59 return Object.InternalGetHashCode (o);
62 public static new bool Equals (object o1, object o2) {
63 // LAMESPEC: According to MSDN, this is equivalent to
64 // Object::Equals (). But the MS version of Object::Equals()
65 // includes the functionality of ValueType::Equals(), while
66 // our version does not.
67 if (o1 == o2)
68 return true;
69 if ((o1 == null) || (o2 == null))
70 return false;
71 if (o1 is ValueType)
72 return ValueType.DefaultEquals (o1, o2);
73 else
74 return Object.Equals (o1, o2);
77 [MethodImplAttribute(MethodImplOptions.InternalCall)]
78 public static extern object GetObjectValue (object obj);
80 [MethodImplAttribute(MethodImplOptions.InternalCall)]
81 static extern void RunClassConstructor (IntPtr type);
83 public static void RunClassConstructor (RuntimeTypeHandle type)
85 if (type.Value == IntPtr.Zero)
86 throw new ArgumentException ("Handle is not initialized.", "type");
88 RunClassConstructor (type.Value);
91 #if NET_4_0
92 [MethodImplAttribute (MethodImplOptions.InternalCall)]
93 static extern bool SufficientExecutionStack ();
95 [ReliabilityContract (Consistency.WillNotCorruptState, Cer.MayFail)]
96 public static void EnsureSufficientExecutionStack ()
98 if (SufficientExecutionStack ())
99 return;
100 throw new InsufficientExecutionStackException ();
102 #endif
104 [MonoTODO("Currently a no-op")]
105 public static void ExecuteCodeWithGuaranteedCleanup (TryCode code, CleanupCode backoutCode, Object userData)
109 [MonoTODO("Currently a no-op")]
110 [ReliabilityContract (Consistency.WillNotCorruptState, Cer.MayFail)]
111 public static void PrepareConstrainedRegions ()
115 [MonoTODO("Currently a no-op")]
116 [ReliabilityContract (Consistency.WillNotCorruptState, Cer.MayFail)]
117 public static void PrepareConstrainedRegionsNoOP ()
121 [MonoTODO("Currently a no-op")]
122 [ReliabilityContract (Consistency.WillNotCorruptState, Cer.MayFail)]
123 public static void ProbeForSufficientStack()
127 [MonoTODO("Currently a no-op")]
128 public static void PrepareDelegate (Delegate d)
130 if (d == null)
131 throw new ArgumentNullException ("d");
134 [MonoTODO("Currently a no-op")]
135 public static void PrepareMethod (RuntimeMethodHandle method)
139 [MonoTODO("Currently a no-op")]
140 public static void PrepareMethod (RuntimeMethodHandle method, RuntimeTypeHandle[] instantiation)
144 public static void RunModuleConstructor (ModuleHandle module)
146 if (module == ModuleHandle.EmptyHandle)
147 throw new ArgumentException ("Handle is not initialized.", "module");
149 RunModuleConstructor (module.Value);
152 [MethodImplAttribute (MethodImplOptions.InternalCall)]
153 public static extern void RunModuleConstructor (IntPtr module);