Merge pull request #1909 from esdrubal/reflection
authorMarcos Henrich <marcoshenrich@gmail.com>
Mon, 27 Jul 2015 11:43:38 +0000 (12:43 +0100)
committerMarcos Henrich <marcoshenrich@gmail.com>
Mon, 27 Jul 2015 11:43:38 +0000 (12:43 +0100)
[SRE] Implemented missing SRE features.

12 files changed:
mcs/class/corlib/System.Reflection.Emit/ConstructorBuilder.cs
mcs/class/corlib/System.Reflection.Emit/ILGenerator.cs
mcs/class/corlib/System.Reflection.Emit/MethodBuilder.cs
mcs/class/corlib/System.Reflection.Emit/ModuleBuilder.cs
mcs/class/corlib/System.Reflection.Emit/TypeBuilder.cs
mcs/class/corlib/System.Reflection/ExceptionHandlingClauseOptions.cs [deleted file]
mcs/class/corlib/Test/System.Reflection.Emit/MethodBuilderTestIL.cs [new file with mode: 0644]
mcs/class/corlib/Test/System.Reflection.Emit/ModuleBuilderTest.cs
mcs/class/corlib/corlib.dll.sources
mcs/class/corlib/corlib_test.dll.sources
mono/metadata/icall-def.h
mono/metadata/icall.c

index 2c3a49eba2983286d4fbeffb5413dfce4fcc88cd..d74a09a1cede25bf4933c69f466f1cdf9a1b2c97 100644 (file)
@@ -32,6 +32,7 @@
 
 #if !FULL_AOT_RUNTIME
 using System;
+using System.Collections.Generic;
 using System.Reflection;
 using System.Reflection.Emit;
 using System.Globalization;
@@ -270,6 +271,14 @@ namespace System.Reflection.Emit {
                        return ilgen;
                }
 
+               public void SetMethodBody (byte[] il, int maxStack, byte[] localSignature,
+                       IEnumerable<ExceptionHandler> exceptionHandlers, IEnumerable<int> tokenFixups)
+               {
+                       var ilgen = GetILGenerator ();
+                       ilgen.Init (il, maxStack, localSignature, exceptionHandlers, tokenFixups);
+               }
+
+
                public void SetCustomAttribute (CustomAttributeBuilder customBuilder)
                {
                        if (customBuilder == null)
index 44fa9d56321bcb5793ef9e20f0346ad283c599f4..ac4fda04472f0572052c8433509685a8e063af93 100644 (file)
@@ -34,6 +34,7 @@
 #if !FULL_AOT_RUNTIME
 using System;
 using System.Collections;
+using System.Collections.Generic;
 using System.Diagnostics.SymbolStore;
 using System.Runtime.InteropServices;
 
@@ -65,9 +66,9 @@ namespace System.Reflection.Emit {
        internal struct ILExceptionInfo {
 #pragma warning disable 169
 #pragma warning disable 414
-               ILExceptionBlock[] handlers;
+               internal ILExceptionBlock[] handlers;
                internal int start;
-               int len;
+               internal int len;
                internal Label end;
 #pragma warning restore 169
 #pragma warning restore 414
@@ -1006,7 +1007,17 @@ namespace System.Reflection.Emit {
                        }
                }
 
-               // Used by DynamicILGenerator
+               // Used by MethodBuilder.SetMethodBody
+               internal void SetExceptionHandlers (ILExceptionInfo[] exHandlers) {
+                       this.ex_handlers = exHandlers;
+               }
+
+               // Used by MethodBuilder.SetMethodBody
+               internal void SetTokenFixups (ILTokenInfo[] tokenFixups) {
+                       this.token_fixups = tokenFixups;
+               }
+
+               // Used by DynamicILGenerator and MethodBuilder.SetMethodBody
                internal void SetCode (byte[] code, int max_stack) {
                        // Make a copy to avoid possible security problems
                        this.code = (byte[])code.Clone ();
@@ -1025,6 +1036,68 @@ namespace System.Reflection.Emit {
                        this.cur_stack = 0;
                }
 
+               internal void Init (byte[] il, int maxStack, byte[] localSignature,
+                       IEnumerable<ExceptionHandler> exceptionHandlers, IEnumerable<int> tokenFixups)
+               {
+                       SetCode (il, maxStack);
+
+                       // FIXME: Process local signature
+
+                       // Process exception handlers
+                       if (exceptionHandlers != null) {
+                               // Group exception handlers by try blocks
+                               var tryBlocks = new Dictionary <Tuple<int, int>, List<ExceptionHandler>> ();
+                               foreach (var h in exceptionHandlers) {
+                                       List<ExceptionHandler> list;
+                                       var key = new Tuple <int, int> (h.TryOffset, h.TryLength);
+                                       if (!tryBlocks.TryGetValue (key, out list)) {
+                                               list = new List<ExceptionHandler> ();
+                                               tryBlocks.Add (key, list);
+                                       }
+                                       list.Add (h);
+                               }
+
+                               // Generate ILExceptionInfo from tryBlocks
+                               var infos = new List<ILExceptionInfo> ();
+                               foreach (var kv in tryBlocks) {
+                                       var info = new ILExceptionInfo () {
+                                               start = kv.Key.Item1,
+                                               len = kv.Key.Item2,
+                                               handlers = new ILExceptionBlock [kv.Value.Count],
+                                       };
+                                       infos.Add (info);
+                                       var i = 0;
+                                       foreach (var b in kv.Value) {
+                                               info.handlers [i++] = new ILExceptionBlock () {
+                                                       start = b.HandlerOffset,
+                                                       len = b.HandlerLength,
+                                                       filter_offset = b.FilterOffset,
+                                                       type = (int) b.Kind,
+                                                       extype = module.ResolveType (b.ExceptionTypeToken),
+                                               };
+                                       }
+                               }
+
+                               SetExceptionHandlers (infos.ToArray ());
+                       }
+
+                       // Process token fixups
+                       if (tokenFixups != null) {
+                               var tokenInfos = new List<ILTokenInfo> ();
+                               foreach (var pos in tokenFixups) {
+                                       var token = (int) BitConverter.ToUInt32 (il, pos);
+                                       var tokenInfo = new ILTokenInfo () {
+                                               code_pos = pos,
+                                               member = ((ModuleBuilder) module).ResolveOrGetRegisteredToken (token, null, null)
+                                       };
+                                       tokenInfos.Add (tokenInfo);
+                               }
+
+                               SetTokenFixups (tokenInfos.ToArray ());
+                       }
+               }
+
+
                internal TokenGenerator TokenGenerator {
                        get {
                                return token_gen;
index 97e6fd81b93299261db7512e638eecac33600249..3772d98b82c90381dc2b8da1dba39a4308e8063e 100644 (file)
@@ -40,6 +40,7 @@ using System.Security.Permissions;
 using System.Runtime.CompilerServices;
 using System.Runtime.InteropServices;
 using System.Diagnostics.SymbolStore;
+using System.Collections.Generic;
 
 namespace System.Reflection.Emit
 {
@@ -268,6 +269,13 @@ namespace System.Reflection.Emit
                        }
                }
 
+               public void SetMethodBody (byte[] il, int maxStack, byte[] localSignature,
+                       IEnumerable<ExceptionHandler> exceptionHandlers, IEnumerable<int> tokenFixups)
+               {
+                       var ilgen = GetILGenerator ();
+                       ilgen.Init (il, maxStack, localSignature, exceptionHandlers, tokenFixups);
+               }
+
                public override Object Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
                {
                        throw NotSupported ();
index d137414ff5c2a036e880216e9ef2d7d332071155..26b89423c471ac27d7aacd55dcecd5067c0ce88e 100644 (file)
@@ -586,6 +586,14 @@ namespace System.Reflection.Emit {
 
                        return new MethodToken (GetToken (method));
                }
+               
+               public MethodToken GetMethodToken (MethodInfo method, IEnumerable<Type> optionalParameterTypes)
+               {
+                       if (method == null)
+                               throw new ArgumentNullException ("method");
+
+                       return new MethodToken (GetToken (method, optionalParameterTypes));
+               }
 
                public MethodToken GetArrayMethodToken (Type arrayClass, string methodName, CallingConventions callingConvention, Type returnType, Type[] parameterTypes)
                {
@@ -597,17 +605,23 @@ namespace System.Reflection.Emit {
                {
                        if (con == null)
                                throw new ArgumentNullException ("con");
-                       if (con.DeclaringType.Module != this)
-                               throw new InvalidOperationException ("The constructor is not in this module");
+
                        return new MethodToken (GetToken (con));
                }
+               
+               public MethodToken GetConstructorToken (ConstructorInfo constructor, IEnumerable<Type> optionalParameterTypes)
+               {
+                       if (constructor == null)
+                               throw new ArgumentNullException ("constructor");
+
+                       return new MethodToken (GetToken (constructor, optionalParameterTypes));
+               }
 
                public FieldToken GetFieldToken (FieldInfo field)
                {
                        if (field == null)
                                throw new ArgumentNullException ("field");
-                       if (field.DeclaringType.Module != this)
-                               throw new InvalidOperationException ("The method is not in this module");
+
                        return new FieldToken (GetToken (field));
                }
 
@@ -676,6 +690,14 @@ namespace System.Reflection.Emit {
                        return getToken (this, member, create_open_instance);
                }
 
+               internal int GetToken (MethodBase method, IEnumerable<Type> opt_param_types) {
+                       if (opt_param_types == null)
+                               return getToken (this, method, true);
+
+                       var optParamTypes = new List<Type> (opt_param_types);
+                       return  getMethodToken (this, method, optParamTypes.ToArray ());
+               }
+               
                internal int GetToken (MethodBase method, Type[] opt_param_types) {
                        return getMethodToken (this, method, opt_param_types);
                }
@@ -691,6 +713,12 @@ namespace System.Reflection.Emit {
                [MethodImplAttribute(MethodImplOptions.InternalCall)]
                internal extern void RegisterToken (object obj, int token);
 
+               /*
+                * Returns MemberInfo registered with the given token.
+                */
+               [MethodImplAttribute(MethodImplOptions.InternalCall)]
+               internal extern object GetRegisteredToken (int token);
+
                internal TokenGenerator GetTokenGenerator () {
                        if (token_gen == null)
                                token_gen = new ModuleBuilderTokenGenerator (this);
@@ -874,6 +902,20 @@ namespace System.Reflection.Emit {
                                return m;
                }
 
+               internal MemberInfo ResolveOrGetRegisteredToken (int metadataToken, Type [] genericTypeArguments, Type [] genericMethodArguments)
+               {
+                       ResolveTokenError error;
+                       MemberInfo m = ResolveMemberToken (_impl, metadataToken, ptrs_from_types (genericTypeArguments), ptrs_from_types (genericMethodArguments), out error);
+                       if (m != null)
+                               return m;
+
+                       m = GetRegisteredToken (metadataToken) as MemberInfo;
+                       if (m == null)
+                               throw resolve_token_exception (metadataToken, error, "MemberInfo");
+                       else
+                               return m;
+               }
+
                public override MethodBase ResolveMethod (int metadataToken, Type [] genericTypeArguments, Type [] genericMethodArguments) {
                        ResolveTokenError error;
 
index edf6d58852807e250a372202a96240db1ef8aa41..9eff8440e156e0f529df1291592e687f10bcd466 100644 (file)
@@ -448,6 +448,12 @@ namespace System.Reflection.Emit
                        return DefineNestedType (name, attr, parent, null, packSize, UnspecifiedTypeSize);
                }
 
+               public TypeBuilder DefineNestedType (string name, TypeAttributes attr, Type parent, PackingSize packSize,
+                                                    int typeSize)
+               {
+                       return DefineNestedType (name, attr, parent, null, packSize, typeSize);
+               }
+
                [ComVisible (true)]
                public ConstructorBuilder DefineConstructor (MethodAttributes attributes, CallingConventions callingConvention, Type[] parameterTypes)
                {
diff --git a/mcs/class/corlib/System.Reflection/ExceptionHandlingClauseOptions.cs b/mcs/class/corlib/System.Reflection/ExceptionHandlingClauseOptions.cs
deleted file mode 100644 (file)
index 13b5ded..0000000
+++ /dev/null
@@ -1,44 +0,0 @@
-//
-// System.Reflection/ExceptionHandlingClauseOptions.cs
-//
-// Author:
-//   Zoltan Varga (vargaz@gmail.com)
-//
-// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
-//
-// Permission is hereby granted, free of charge, to any person obtaining
-// a copy of this software and associated documentation files (the
-// "Software"), to deal in the Software without restriction, including
-// without limitation the rights to use, copy, modify, merge, publish,
-// distribute, sublicense, and/or sell copies of the Software, and to
-// permit persons to whom the Software is furnished to do so, subject to
-// the following conditions:
-// 
-// The above copyright notice and this permission notice shall be
-// included in all copies or substantial portions of the Software.
-// 
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-//
-
-
-using System;
-using System.Runtime.InteropServices;
-
-namespace System.Reflection {
-
-       [ComVisible (true)]
-       [Flags]
-       public enum ExceptionHandlingClauseOptions {
-               Clause = 0x0,
-               Filter = 0x1,
-               Finally = 0x2,
-               Fault = 0x4
-       }
-
-}
diff --git a/mcs/class/corlib/Test/System.Reflection.Emit/MethodBuilderTestIL.cs b/mcs/class/corlib/Test/System.Reflection.Emit/MethodBuilderTestIL.cs
new file mode 100644 (file)
index 0000000..da8cd3e
--- /dev/null
@@ -0,0 +1,154 @@
+       //
+       // MethodBuilderTestIL.cs - NUnit Test Cases for MethodBuilder.CreateMethodBody and MethodBuilder.SetMethodBody
+       //
+       // Marcos Henrich (marcos.henrich@xamarin.com)
+       //
+       // (C) Xamarin, Inc.
+
+       using System;
+       using System.Linq;
+       using System.Reflection;
+       using System.Reflection.Emit;
+       using System.Threading;
+
+       using NUnit.Framework;
+       using System.IO;
+
+       namespace MonoTests.System.Reflection.Emit
+       {
+               public abstract class MethodBuilderTestIL
+               {
+                       protected abstract void SetIL (MethodBuilder methodBuilder, MemoryStream ilStream);
+
+                       public static ModuleBuilder CreateModuleBuilder ()
+                       {
+                               AppDomain currentDom = Thread.GetDomain ();
+
+                               AssemblyBuilder assemblyBuilder = currentDom.DefineDynamicAssembly (
+                                       new AssemblyName ("NewDynamicAssembly"),
+                                       AssemblyBuilderAccess.Run);
+
+                               return assemblyBuilder.DefineDynamicModule ("NewModule");
+                       }
+
+                       public static object Invoke (Type type, MethodBuilder methodBuilder, params object[] parameters)
+                       {
+                               var method = type.GetMethods ().First (m => {
+                                       if (m.Name != methodBuilder.Name)
+                                               return false;
+                                       var params1 = m.GetParameters ();
+                                       var params2 = methodBuilder.GetParameters ();
+                                       if (params1.Length != params2.Length)
+                                               return false;
+                                       for (var i = 0; i < params1.Length; i++)
+                                               if (params1 [i].ParameterType.FullName != params2 [i].ParameterType.FullName)
+                                                       return false;
+
+                                       return true;
+                               });
+
+                               object inst = Activator.CreateInstance (type, new object [0]);
+
+                               return method.Invoke (inst, parameters);
+                       }
+
+                       [Test]
+                       public void CallMethodRef ()
+                       {
+                               var expected = "value";
+
+                               var moduleBuilder = CreateModuleBuilder ();
+                               var typeBuilder = moduleBuilder.DefineType ("NewType");
+
+                               var methodBuilder1 = typeBuilder.DefineMethod ("NewMethod1",
+                                       MethodAttributes.Public | MethodAttributes.Static,
+                                       typeof (string),
+                                       Type.EmptyTypes);
+
+                               var gen1 = methodBuilder1.GetILGenerator ();
+                               gen1.Emit (OpCodes.Ldstr, expected);
+                               gen1.Emit (OpCodes.Ret);
+
+                               var methodBuilder2 = typeBuilder.DefineMethod ("NewMethod2",
+                               MethodAttributes.Public | MethodAttributes.Static,
+                                       typeof (string),
+                                       Type.EmptyTypes);
+
+                               var ilStream = new MemoryStream ();
+                               var ilWriter = new BinaryWriter (ilStream);
+                               ilWriter.Write ((byte) 0x28); // call
+                               ilWriter.Write ((int)  moduleBuilder.GetMethodToken (methodBuilder1).Token);
+                               ilWriter.Write ((byte) 0x2A); // ret
+
+                               SetIL (methodBuilder2, ilStream);
+
+                               var type = typeBuilder.CreateType ();
+
+                               Assert.AreEqual (expected, Invoke (type, methodBuilder2));
+                       }
+
+                       [Test]
+                       public void CallMethodDef ()
+                       {
+                               var expected = "value";
+
+                               var moduleBuilder1 = CreateModuleBuilder ();
+                               var typeBuilder1 = moduleBuilder1.DefineType ("NewType1", TypeAttributes.Public);
+
+                               var methodBuilder1 = typeBuilder1.DefineMethod ("NewMethod1",
+                                MethodAttributes.Public | MethodAttributes.Static,
+                                       typeof (string),
+                                       Type.EmptyTypes);
+
+                               var gen1 = methodBuilder1.GetILGenerator ();
+                               gen1.Emit (OpCodes.Ldstr, expected);
+                               gen1.Emit (OpCodes.Ret);
+
+                               typeBuilder1.CreateType ();
+
+                               var moduleBuilder2 = CreateModuleBuilder ();
+                               var typeBuilder2 = moduleBuilder2.DefineType ("NewType2");
+
+                               var methodBuilder2 = typeBuilder2.DefineMethod ("NewMethod2",
+                                       MethodAttributes.Public | MethodAttributes.Static,
+                                       typeof (string),
+                                       Type.EmptyTypes);
+
+                               var ilStream = new MemoryStream ();
+                               var ilWriter = new BinaryWriter (ilStream);
+                               ilWriter.Write ((byte) 0x28); // call
+                               ilWriter.Write ((int) moduleBuilder2.GetMethodToken (methodBuilder1).Token);
+                               ilWriter.Write ((byte) 0x2A); // ret
+
+                               SetIL (methodBuilder2, ilStream);
+
+                               var type = typeBuilder2.CreateType ();
+
+                               Assert.AreEqual (expected, Invoke (type, methodBuilder2));
+                       }
+               }
+
+               /*
+                * Tests MethodBuilder.CreateMethodBody
+                */
+               [TestFixture]
+               public class MethodBuilderTestIL_CreateMethodBody : MethodBuilderTestIL
+               {
+                       protected override void SetIL (MethodBuilder methodBuilder, MemoryStream ilStream)
+                       {
+                               methodBuilder.CreateMethodBody (ilStream.ToArray (), (int) ilStream.Length);
+                       }
+               }
+
+               /*
+                * Tests MethodBuilder.SetMethodBody
+                */
+               [TestFixture]
+               public class MethodBuilderTestIL_SetMethodBody : MethodBuilderTestIL
+               {
+                       protected override void SetIL (MethodBuilder methodBuilder, MemoryStream ilStream)
+                       {
+                               methodBuilder.SetMethodBody (ilStream.ToArray (), 999, null, null, null);
+                       }
+               }
+       }
index d9292c16ad2733324e1ec08b5321cd636d1f1213..aa6f1ba35833bdb3b1c4bf28e54fedd5b0a83718 100644 (file)
@@ -728,5 +728,31 @@ namespace MonoTests.System.Reflection.Emit
                        catch (ArgumentException) {
                        }
                }
+
+               [Test]
+               public void GetMethodTokenNullParam ()
+               {
+                       AssemblyName an = genAssemblyName ();
+                       AssemblyBuilder ab = AppDomain.CurrentDomain.DefineDynamicAssembly (an, AssemblyBuilderAccess.Run);
+                       ModuleBuilder module = ab.DefineDynamicModule ("mod");
+
+                       var method = typeof (object).GetMethod ("GetType");
+
+                       // ArgumentNullException should not occur.
+                       module.GetMethodToken (method, null);
+               }
+
+               [Test]
+               public void GetConstructorTokenNullParam ()
+               {
+                       AssemblyName an = genAssemblyName ();
+                       AssemblyBuilder ab = AppDomain.CurrentDomain.DefineDynamicAssembly (an, AssemblyBuilderAccess.Run);
+                       ModuleBuilder module = ab.DefineDynamicModule ("mod");
+
+                       var method = typeof (object).GetConstructor (Type.EmptyTypes);
+
+                       // ArgumentNullException should not occur.
+                       module.GetConstructorToken (method, null);
+               }
        }
 }
index 391aedc68728cec206a4cc6a5758c199b5cf143c..961c6928149290423fac42911fc9ce51e50093b4 100644 (file)
@@ -233,7 +233,6 @@ System.Reflection/CustomAttributeNamedArgument.cs
 System.Reflection/CustomAttributeTypedArgument.cs
 System.Reflection/EventInfo.cs
 System.Reflection/ExceptionHandlingClause.cs
-System.Reflection/ExceptionHandlingClauseOptions.cs
 System.Reflection/FieldInfo.cs
 System.Reflection/ImageFileMachine.cs
 System.Reflection/LocalVariableInfo.cs
@@ -1224,6 +1223,7 @@ ReferenceSources/SecurityContext.cs
 ../../../external/referencesource/mscorlib/system/reflection/membertypes.cs
 ../../../external/referencesource/mscorlib/system/reflection/methodattributes.cs
 ../../../external/referencesource/mscorlib/system/reflection/methodbase.cs
+../../../external/referencesource/mscorlib/system/reflection/methodbody.cs
 ../../../external/referencesource/mscorlib/system/reflection/methodimplattributes.cs
 ../../../external/referencesource/mscorlib/system/reflection/missing.cs
 ../../../external/referencesource/mscorlib/system/reflection/obfuscateassemblyattribute.cs
@@ -1240,6 +1240,8 @@ ReferenceSources/SecurityContext.cs
 ../../../external/referencesource/mscorlib/system/reflection/typefilter.cs
 ../../../external/referencesource/mscorlib/system/reflection/typeinfo.cs
 
+../../../external/referencesource/mscorlib/system/reflection/emit/methodbuilder.cs
+
 ../../../external/referencesource/mscorlib/system/resources/__fastresourcecomparer.cs
 ../../../external/referencesource/mscorlib/system/resources/__hresults.cs
 ../../../external/referencesource/mscorlib/system/resources/filebasedresourcegroveler.cs
index 0efa920e17539a27f0f498e4b13893e485fb1bfc..baad693bffc1f7c5f147b72f4763e0d93ac817fc 100644 (file)
@@ -164,6 +164,7 @@ System.Reflection.Emit/FieldBuilderTest.cs
 System.Reflection.Emit/GenericTypeParameterBuilderTest.cs
 System.Reflection.Emit/ILGeneratorTest.cs
 System.Reflection.Emit/MethodBuilderTest.cs
+System.Reflection.Emit/MethodBuilderTestIL.cs
 System.Reflection.Emit/MethodOnTypeBuilderInstTest.cs
 System.Reflection.Emit/MethodRentalTest.cs
 System.Reflection.Emit/ModuleBuilderTest.cs
index 2dfe551cf1448b7bffaf2c6944759bc79e41c88e..677769c97e54d7930a40f7071b20d2b16412ae1d 100644 (file)
@@ -512,7 +512,8 @@ ICALL(GPARB_1, "initialize", mono_reflection_initialize_generic_parameter)
 ICALL_TYPE(METHODB, "System.Reflection.Emit.MethodBuilder", METHODB_1)
 ICALL(METHODB_1, "MakeGenericMethod", mono_reflection_bind_generic_method_parameters)
 
-ICALL_TYPE(MODULEB, "System.Reflection.Emit.ModuleBuilder", MODULEB_8)
+ICALL_TYPE(MODULEB, "System.Reflection.Emit.ModuleBuilder", MODULEB_10)
+ICALL(MODULEB_10, "GetRegisteredToken", ves_icall_ModuleBuilder_GetRegisteredToken)
 ICALL(MODULEB_8, "RegisterToken", ves_icall_ModuleBuilder_RegisterToken)
 ICALL(MODULEB_1, "WriteToFile", ves_icall_ModuleBuilder_WriteToFile)
 ICALL(MODULEB_2, "basic_init", mono_image_module_basic_init)
index a02b4674ef135e3bca20e5b93ef16d9be483038d..6ab999ba126cb69b9da05f76c2ad1ba78591dc3a 100644 (file)
@@ -1161,6 +1161,18 @@ ves_icall_ModuleBuilder_RegisterToken (MonoReflectionModuleBuilder *mb, MonoObje
        mono_image_register_token (mb->dynamic_image, token, obj);
 }
 
+ICALL_EXPORT MonoObject*
+ves_icall_ModuleBuilder_GetRegisteredToken (MonoReflectionModuleBuilder *mb, guint32 token)
+{
+       gpointer obj;
+
+       mono_loader_lock ();
+       obj = mono_g_hash_table_lookup (mb->dynamic_image->tokens, GUINT_TO_POINTER (token));
+       mono_loader_unlock ();
+
+       return obj;
+}
+
 static gboolean
 get_caller (MonoMethod *m, gint32 no, gint32 ilo, gboolean managed, gpointer data)
 {