Beispiel #1
0
MaigreMonoBridge *
maigre_mono_bridge ()
{
    static MaigreMonoBridge *bridge;
    static gboolean load_attempted;

    if (load_attempted) {
        return bridge;
    }

    load_attempted = TRUE;

    bridge = g_new0 (MaigreMonoBridge, 1);

    bridge->domain = mono_domain_get ();

    if (bridge->domain == NULL) {
        mono_config_parse (NULL);
        bridge->domain = mono_jit_init ("maigre-domain");
    }

    if ((bridge->assembly = mono_domain_assembly_open (
            bridge->domain, ".run/engines/Maigre.dll")) == NULL ||
        (bridge->image = mono_assembly_get_image (bridge->assembly)) == NULL) {
        g_warning ("Could not load Maigre.dll assembly");
        g_free (bridge);
        bridge = NULL;
    }

    return bridge;
}
Beispiel #2
0
static HRESULT RuntimeHost_GetIUnknownForDomain(RuntimeHost *This, MonoDomain *domain, IUnknown **punk)
{
    HRESULT hr;
    void *args[1];
    MonoAssembly *assembly;
    MonoImage *image;
    MonoClass *klass;
    MonoMethod *method;
    MonoObject *appdomain_object;
    IUnknown *unk;

    mono_thread_attach(domain);

    assembly = mono_domain_assembly_open(domain, "mscorlib");
    if (!assembly)
    {
        ERR("Cannot load mscorlib\n");
        return E_FAIL;
    }

    image = mono_assembly_get_image(assembly);
    if (!image)
    {
        ERR("Couldn't get assembly image\n");
        return E_FAIL;
    }

    klass = mono_class_from_name(image, "System", "AppDomain");
    if (!klass)
    {
        ERR("Couldn't get class from image\n");
        return E_FAIL;
    }

    method = mono_class_get_method_from_name(klass, "get_CurrentDomain", 0);
    if (!method)
    {
        ERR("Couldn't get method from class\n");
        return E_FAIL;
    }

    args[0] = NULL;
    appdomain_object = mono_runtime_invoke(method, NULL, args, NULL);
    if (!appdomain_object)
    {
        ERR("Couldn't get result pointer\n");
        return E_FAIL;
    }

    hr = RuntimeHost_GetIUnknownForObject(This, appdomain_object, &unk);

    if (SUCCEEDED(hr))
    {
        hr = IUnknown_QueryInterface(unk, &IID__AppDomain, (void**)punk);

        IUnknown_Release(unk);
    }

    return hr;
}
Beispiel #3
0
//============================================================
// <T>析构脚本工作器。</T>
//
// @return 处理结果
//============================================================
TResult FMonoLibrary::Open(){
   TResult resultCd = FScriptLibrary::Open();
   // 打开资源
   FAssetStream* pStream = RAssetManager::Instance().OpenAssetStreamFormat(_name);
   MO_ERROR_CHECK(pStream, return NULL, "Open template stream failure. (name=%s)", (TCharC*)_name);
   // 加载映像
   MonoImageOpenStatus statusCd = MONO_IMAGE_IMAGE_INVALID;
   _pMonoImage = mono_image_open_from_data_full((TChar*)pStream->MemoryC(), pStream->Length(), true, &statusCd, false);
   MO_FATAL_CHECK(_pMonoImage, return EFailure, "Open assembly image failure. (name=%s)", (TCharC*)_name);
   if(statusCd != MONO_IMAGE_OK){
      MO_FATAL("Open assembly image failure. (file_name=%s)", _name);
      return EFailure;
   }
   // 加载装配数据
   MonoImageOpenStatus assemblyStatusCd = MONO_IMAGE_IMAGE_INVALID;
   MonoAssembly* pAssembly = mono_assembly_load_from_full(_pMonoImage, _name, &assemblyStatusCd, false);
   MO_FATAL_CHECK(pAssembly, return EFailure, "Load assembly failure. (name=%s)", (TCharC*)_name);
   if(mono_assembly_get_image(pAssembly) != _pMonoImage){
      MO_FATAL("Check mono image failure. (image=0x%08X)", _pMonoImage);
      return EFailure;
   }
   // 释放资源
   RAssetManager::Instance().CloseAssetStream(pStream);
   return resultCd;
}
Beispiel #4
0
void invoke_protected_memory_method (MonoArray *data, MonoObject *scope, gboolean encrypt)
{
    MonoClass *klass;
    MonoMethod *method;
    void *params [2];

    MONO_ARCH_SAVE_REGS;

    if (system_security_assembly == NULL) {
        system_security_assembly = mono_image_loaded ("System.Security");
        if (!system_security_assembly) {
            MonoAssembly *sa = mono_assembly_open ("System.Security.dll", NULL);
            if (!sa)
                g_assert_not_reached ();
            system_security_assembly = mono_assembly_get_image (sa);
        }
    }

    klass = mono_class_from_name (system_security_assembly,
                                  "System.Security.Cryptography", "ProtectedMemory");
    method = mono_class_get_method_from_name (klass, encrypt ? "Protect" : "Unprotect", 2);
    params [0] = data;
    params [1] = scope; /* MemoryProtectionScope.SameProcess */
    mono_runtime_invoke (method, NULL, params, NULL);
}
Beispiel #5
0
static MonoObject *
mono_jit_exec_virt (MonoAssembly *assembly, char *mtd_name, MonoArray *v_args)
{
  MonoImage *image = mono_assembly_get_image (assembly);
  MonoMethod *method;
  MonoClass *class;
  MonoMethodDesc *desc;
  MonoObject *exc = NULL, *ret;

  class = mono_class_from_name (image, "", "VInvoke");
  desc = mono_method_desc_new (mtd_name, 1);
  method = mono_method_desc_search_in_image (desc, image);

  mono_assembly_set_main (
      mono_image_get_assembly (
	mono_class_get_image (
	  mono_method_get_class (method))));
  /*mono_start_method = mono_marshal_get_runtime_invoke (method);*/

  ret = virt_mono_runtime_exec_main (method, v_args, &exc);
  if (exc)
    virt_mono_throw_unhandled_exception (exc);

  return ret;
}
Beispiel #6
0
static void
mono_debug_add_assembly (MonoAssembly *assembly, gpointer user_data)
{
    mono_debugger_lock ();
    mono_debug_open_image (mono_assembly_get_image (assembly), NULL, 0);
    mono_debugger_unlock ();
}
Beispiel #7
0
static void
process_assembly (MonoAssembly *assembly, gboolean all) {
	MonoCustomAttrInfo* cattrs;
	process_image (mono_assembly_get_image (assembly), all);
	cattrs = mono_custom_attrs_from_assembly (assembly);
	handle_cattrs (cattrs);
}
Beispiel #8
0
static void
output_assembly (MonoAssembly *assembly, MonoAssembly *assembly2, FILE *outfile)
{
	MonoImage *image = mono_assembly_get_image (assembly);
	fprintf (outfile, "\t<assembly name=\"%s\" guid=\"%s\" filename=\"%s\"/>\n",
		mono_image_get_name (image), mono_image_get_guid (image), mono_image_get_filename (image));
}
Beispiel #9
0
void MonoEmbedding::Initialize()
{
    // Construct the absolute file path to MonoEmbedding.exe assuming
    // it is located next to edge.node
    Dl_info dlinfo;
    char fullPath[PATH_MAX];
    dladdr((void*)&MonoEmbedding::Initialize, &dlinfo);
    strcpy(fullPath, dlinfo.dli_fname);
    strcpy(fullPath, dirname(fullPath));
    strcat(fullPath, "/MonoEmbedding.exe");

    mono_jit_init (fullPath);
    assembly = mono_domain_assembly_open (mono_domain_get(), fullPath);
    MonoClass* klass = mono_class_from_name(mono_assembly_get_image(assembly), "", "MonoEmbedding");
    MonoMethod* main = mono_class_get_method_from_name(klass, "Main", -1);
    MonoException* exc;
    MonoArray* args = mono_array_new(mono_domain_get(), mono_get_string_class(), 0);
    mono_runtime_exec_main(main, args, (MonoObject**)&exc);

    mono_add_internal_call("ClrFuncInvokeContext::CompleteOnV8ThreadAsynchronousICall", (const void*)&ClrFuncInvokeContext::CompleteOnV8ThreadAsynchronous); 
    mono_add_internal_call("ClrFuncInvokeContext::CompleteOnCLRThreadICall", (const void*)&ClrFuncInvokeContext::CompleteOnCLRThread); 
    mono_add_internal_call("NodejsFuncInvokeContext::CallFuncOnV8ThreadInternal", (const void*)&NodejsFuncInvokeContext::CallFuncOnV8Thread); 
    mono_add_internal_call("NodejsFunc::ExecuteActionOnV8Thread", (const void*)&NodejsFunc::ExecuteActionOnV8Thread); 
    mono_add_internal_call("NodejsFunc::Release", (const void*)&NodejsFunc::Release); 
}
Beispiel #10
0
/* Get an IUnknown pointer for a Mono object.
 *
 * This is just a "light" wrapper around
 * System.Runtime.InteropServices.Marshal:GetIUnknownForObject
 *
 * NOTE: The IUnknown* is created with a reference to the object.
 * Until they have a reference, objects must be in the stack to prevent the
 * garbage collector from freeing them.
 *
 * mono_thread_attach must have already been called for this thread. */
HRESULT RuntimeHost_GetIUnknownForObject(RuntimeHost *This, MonoObject *obj,
    IUnknown **ppUnk)
{
    MonoDomain *domain;
    MonoAssembly *assembly;
    MonoImage *image;
    MonoClass *klass;
    MonoMethod *method;
    MonoObject *result;
    void *args[2];

    domain = mono_object_get_domain(obj);

    assembly = mono_domain_assembly_open(domain, "mscorlib");
    if (!assembly)
    {
        ERR("Cannot load mscorlib\n");
        return E_FAIL;
    }

    image = mono_assembly_get_image(assembly);
    if (!image)
    {
        ERR("Couldn't get assembly image\n");
        return E_FAIL;
    }

    klass = mono_class_from_name(image, "System.Runtime.InteropServices", "Marshal");
    if (!klass)
    {
        ERR("Couldn't get class from image\n");
        return E_FAIL;
    }

    method = mono_class_get_method_from_name(klass, "GetIUnknownForObject", 1);
    if (!method)
    {
        ERR("Couldn't get method from class\n");
        return E_FAIL;
    }

    args[0] = obj;
    args[1] = NULL;
    result = mono_runtime_invoke(method, NULL, args, NULL);
    if (!result)
    {
        ERR("Couldn't get result pointer\n");
        return E_FAIL;
    }

    *ppUnk = *(IUnknown**)mono_object_unbox(result);
    if (!*ppUnk)
    {
        ERR("GetIUnknownForObject returned 0\n");
        return E_FAIL;
    }

    return S_OK;
}
Beispiel #11
0
int main()
{
#if LOADDYNAMIC
	SetupMono();
#endif

#if WIN32
	SetEnvironmentVariable(L"MONO_PATH",L"..\\..\\..\\builds\\monodistribution\\lib\\mono\\2.0");
#else
	setenv("MONO_PATH","../../../builds/monodistribution/lib/mono/2.0",1);
#endif

        MonoDomain* domain = mono_jit_init_version ("Unity Root Domain","v2.0.50727");

        //create and set child domain
        MonoDomain* child = mono_domain_create_appdomain("Unity Child Domain",NULL);
        mono_domain_set(child,0);

        //load assembly and call entrypoint
        MonoAssembly* ass = mono_domain_assembly_open (mono_domain_get (),"lucas.exe");
        MonoImage* img = mono_assembly_get_image(ass);
        printf("image %p\n",img);
        MonoMethodDesc* desc = mono_method_desc_new("Main2:Main",1);
        MonoMethod* m = mono_method_desc_search_in_image(desc,img);
        printf("method %p\n",m);
        MonoObject* exc;
        MonoObject* newinst = mono_object_new(mono_domain_get(),mono_method_get_class(m));
        MonoObject* ret = mono_runtime_invoke(m,newinst,0,&exc);
        printf ("Exception: %p\n",exc);
        if (exc)
        {
                MonoException* exc2 = (MonoException*) exc;
                printf ("exc msg:%s\n",mono_class_get_name(mono_object_get_class((MonoObject*)exc)));
        }
        printf ("ret: %p\n",ret);

		Sleep(0);

        //switch back to root domain
        mono_domain_set(domain,0);
        mono_domain_unload(child);
		mono_runtime_set_shutting_down ();
		mono_threads_set_shutting_down ();
		mono_thread_pool_cleanup ();
		mono_domain_finalize(mono_get_root_domain(),2000);
		mono_runtime_cleanup(mono_get_root_domain());

		printf("Unloading mono\n");
#if LOADDYNAMIC
	CleanupMono();
#endif

		while(1){} //sleep so stale monothreads have a chance to crash
        return 0;
}
Beispiel #12
0
void RuntimeHost_ExitProcess(RuntimeHost *This, INT exitcode)
{
    HRESULT hr;
    void *args[2];
    MonoDomain *domain;
    MonoAssembly *assembly;
    MonoImage *image;
    MonoClass *klass;
    MonoMethod *method;

    hr = RuntimeHost_GetDefaultDomain(This, &domain);
    if (FAILED(hr))
    {
        ERR("Cannot get domain, hr=%x\n", hr);
        return;
    }

    mono_thread_attach(domain);

    assembly = mono_domain_assembly_open(domain, "mscorlib");
    if (!assembly)
    {
        ERR("Cannot load mscorlib\n");
        return;
    }

    image = mono_assembly_get_image(assembly);
    if (!image)
    {
        ERR("Couldn't get assembly image\n");
        return;
    }

    klass = mono_class_from_name(image, "System", "Environment");
    if (!klass)
    {
        ERR("Couldn't get class from image\n");
        return;
    }

    method = mono_class_get_method_from_name(klass, "Exit", 1);
    if (!method)
    {
        ERR("Couldn't get method from class\n");
        return;
    }

    args[0] = &exitcode;
    args[1] = NULL;
    mono_runtime_invoke(method, NULL, args, NULL);

    ERR("Process should have exited\n");
}
Beispiel #13
0
static void
mono_debug_add_assembly (MonoAssembly *assembly, gpointer user_data)
{
	MonoDebugHandle *handle;
	MonoImage *image;

	mono_debugger_lock ();
	image = mono_assembly_get_image (assembly);
	handle = open_symfile_from_bundle (image);
	if (!handle)
		mono_debug_open_image (image, NULL, 0);
	mono_debugger_unlock ();
}
Beispiel #14
0
IMonoAssembly *CScriptDomain::LoadAssembly(const char *file, bool shadowCopy, bool convertPdbToMdb)
{
	const char *path;
	if(shadowCopy)
		path = GetTempPath().append(PathUtil::GetFile(file));
	else
		path = file;

	for each(auto assembly in m_assemblies)
	{
		if(!strcmp(path, assembly->GetPath()))
			return assembly;
	}

	if(shadowCopy)
		CopyFile(file, path, false);

	string sAssemblyPath(path);
#ifndef _RELEASE
	if(g_pMonoCVars->mono_generateMdbIfPdbIsPresent != 0 && convertPdbToMdb && sAssemblyPath.find("pdb2mdb")==-1)
	{
		if (IMonoAssembly *pDebugDatabaseCreator = static_cast<CScriptSystem *>(GetMonoScriptSystem())->GetDebugDatabaseCreator())
		{
			if(IMonoClass *pDriverClass = pDebugDatabaseCreator->GetClass("Driver", ""))
			{
				if(IMonoMethod *pConvertMethod = pDriverClass->GetMethod("Convert", 1))
				{
					IMonoArray *pArgs = CreateMonoArray(1);
					pArgs->Insert(path);
					pConvertMethod->InvokeArray(nullptr, pArgs);
					SAFE_RELEASE(pArgs);
				}
			}
		}
	}
#endif

	if(MonoAssembly *pMonoAssembly = mono_domain_assembly_open(m_pDomain, path))
	{
		CScriptAssembly *pAssembly = new CScriptAssembly(this, mono_assembly_get_image(pMonoAssembly), path);
		m_assemblies.push_back(pAssembly);

		return pAssembly;
	}

	return nullptr;
}
Beispiel #15
0
gboolean
mono_trace_eval (MonoMethod *method)
{
	int include = 0;
	int i;

	for (i = 0; i < trace_spec.len; i++){
		MonoTraceOperation *op = &trace_spec.ops [i];
		int inc = 0;
		
		switch (op->op){
		case MONO_TRACEOP_ALL:
			inc = 1; break;
		case MONO_TRACEOP_PROGRAM:
			if (trace_spec.assembly && (method->klass->image == mono_assembly_get_image (trace_spec.assembly)))
				inc = 1; break;
		case MONO_TRACEOP_WRAPPER:
			if ((method->wrapper_type == MONO_WRAPPER_NATIVE_TO_MANAGED) ||
				(method->wrapper_type == MONO_WRAPPER_MANAGED_TO_NATIVE))
				inc = 1; break;
		case MONO_TRACEOP_METHOD:
			if (mono_method_desc_full_match ((MonoMethodDesc *) op->data, method))
				inc = 1; break;
		case MONO_TRACEOP_CLASS:
			if (strcmp (method->klass->name_space, op->data) == 0)
				if (strcmp (method->klass->name, op->data2) == 0)
					inc = 1;
			break;
		case MONO_TRACEOP_ASSEMBLY:
			if (strcmp (mono_image_get_name (method->klass->image), op->data) == 0)
				inc = 1; break;
		case MONO_TRACEOP_NAMESPACE:
			if (strcmp (method->klass->name_space, op->data) == 0)
				inc = 1;
		case MONO_TRACEOP_EXCEPTION:
			break;
		}
		if (op->exclude){
			if (inc)
				include = 0;
		} else if (inc)
			include = 1;
	}
	return include;
}
Beispiel #16
0
int
mini_debugger_main (MonoDomain *domain, MonoAssembly *assembly, int argc, char **argv)
{
	MainThreadArgs main_args;
	MonoImage *image;
	MonoMethod *main_method;

	/*
	 * Get and compile the main function.
	 */

	image = mono_assembly_get_image (assembly);
	main_method = mono_get_method (image, mono_image_get_entry_point (image), NULL);

	/*
	 * Initialize managed code.
	 */
	mono_debugger_event (MONO_DEBUGGER_EVENT_INITIALIZE_MANAGED_CODE,
			     (guint64) (gssize) main_method, 0);

	/*
	 * Start the main thread and wait until it's ready.
	 */

	main_args.domain = domain;
	main_args.method = main_method;
	main_args.argc = argc;
	main_args.argv = argv;

#if RUN_IN_SUBTHREAD
	mono_thread_create (domain, main_thread_handler, &main_args);
#else
	main_thread_handler (&main_args);
#endif

	mono_thread_manage ();

	/*
	 * This will never return.
	 */
	mono_debugger_event (MONO_DEBUGGER_EVENT_WRAPPER_MAIN, 0, 0);

	return 0;
}
Beispiel #17
0
static int
mono_attach_load_agent (MonoDomain *domain, char *agent, char *args, MonoObject **exc)
{
	MonoError error;
	MonoAssembly *agent_assembly;
	MonoImage *image;
	MonoMethod *method;
	guint32 entry;
	MonoArray *main_args;
	gpointer pa [1];
	MonoImageOpenStatus open_status;

	agent_assembly = mono_assembly_open (agent, &open_status);
	if (!agent_assembly) {
		fprintf (stderr, "Cannot open agent assembly '%s': %s.\n", agent, mono_image_strerror (open_status));
		g_free (agent);
		return 2;
	}

	/* 
	 * Can't use mono_jit_exec (), as it sets things which might confuse the
	 * real Main method.
	 */
	image = mono_assembly_get_image (agent_assembly);
	entry = mono_image_get_entry_point (image);
	if (!entry) {
		g_print ("Assembly '%s' doesn't have an entry point.\n", mono_image_get_filename (image));
		g_free (agent);
		return 1;
	}

	method = mono_get_method_checked (image, entry, NULL, NULL, &error);
	if (method == NULL){
		g_print ("The entry point method of assembly '%s' could not be loaded due to %s\n", agent, mono_error_get_message (&error));
		mono_error_cleanup (&error);
		g_free (agent);
		return 1;
	}
	
	if (args) {
		main_args = (MonoArray*)mono_array_new (domain, mono_defaults.string_class, 1);
		mono_array_set (main_args, MonoString*, 0, mono_string_new (domain, args));
	} else {
Beispiel #18
0
IMonoAssembly *CScriptDomain::LoadAssembly(const char *file, bool shadowCopy, bool convertPdbToMdb)
{
	const char *path;
	if(shadowCopy)
		path = GetTempPath().append(PathUtil::GetFile(file));
	else
		path = file;

	for each(auto assembly in m_assemblies)
	{
		if(!strcmp(path, assembly->GetPath()))
			return assembly;
	}

	if(shadowCopy)
		CopyFile(file, path, false);

	string sAssemblyPath(path);
#ifndef _RELEASE
	if(convertPdbToMdb && sAssemblyPath.find("pdb2mdb")==-1)
	{
		if(IMonoAssembly *pDebugDatabaseCreator = g_pScriptSystem->GetDebugDatabaseCreator())
		{
			if(IMonoClass *pDriverClass = pDebugDatabaseCreator->GetClass("Driver", ""))
			{
				IMonoArray *pArgs = CreateMonoArray(1);
				pArgs->Insert(path);
				pDriverClass->InvokeArray(NULL, "Convert", pArgs);
				SAFE_RELEASE(pArgs);
			}
		}
	}
#endif

	MonoAssembly *pMonoAssembly = mono_domain_assembly_open(m_pDomain, path);
	CRY_ASSERT(pMonoAssembly);

	CScriptAssembly *pAssembly = new CScriptAssembly(this, mono_assembly_get_image(pMonoAssembly), path);
	m_assemblies.push_back(pAssembly);
	return pAssembly;
}
bool SharpSource::SDK_OnLoad(char *error, size_t maxlength, bool late)
{
  domain = mono_jit_init(library);
  assembly = mono_domain_assembly_open(domain, library);
  char cwd[1024];

  if (!assembly) {
    strcpy(error, "Can't find the .NET assembly file in the sharpmod directory");
    return false;
  }

  MonoImage *image = mono_assembly_get_image(assembly);
  if (!image) {
    strcpy(error, "Can't load the assembly image");
    return false;
  }

  MonoClass *metamod_class = mono_class_from_name(image, "AlliedMods", "Core");

  if (!metamod_class) {
    strcpy(error, "Can't find the class SharpSource::MainClass in the provided assembly");
    return false;
  }

  MonoMethod *init = mono_class_get_method_from_name(metamod_class, "Init", 5);

  if (!init) {
    strcpy(error, "Can't find the method Init in MainClass");
    return false;
  }

  void *args[5];
  args[0] = &smutils;
  args[1] = &sharesys;
  args[2] = &myself;
  args[3] = &playerhelpers;
  args[4] = &timersys;
  mono_runtime_invoke(init, NULL, args, NULL);

  return true;
}
Beispiel #20
0
	void ScriptProvider::Initialize()
	{
		const char* szScriptAssembly = "TalonScript.dll";
		ScriptDomain = mono_jit_init(szScriptAssembly);
		ScriptAssembly = mono_domain_assembly_open(ScriptDomain, szScriptAssembly);
		ScriptAssemblyImage = mono_assembly_get_image(ScriptAssembly);

		Module.SetDomain(ScriptDomain);
		Module.SetImage(ScriptAssemblyImage);

		printf("Mapping Scripted Types:\n");
		std::vector<ScriptType*>::iterator itCurrent = s_registeredTypes->begin();
		std::vector<ScriptType*>::iterator itEnd = s_registeredTypes->end();
		while (itCurrent != itEnd)
		{
			ScriptType* pType = *itCurrent;
			printf("\t%s\n", pType->GetName());
			
			pType->MapType();

			itCurrent++;
		}
	}
Beispiel #21
0
static void processThroughMono(std::string& dll)
{    
    //Initialize mono runtime
    MonoDomain* domain = mono_jit_init (dll.c_str());
    MonoAssembly *assembly;

    assembly = mono_domain_assembly_open (domain, dll.c_str());
    assert(assembly);

    MonoImage *image =  mono_assembly_get_image  (assembly);
    assert(image);
    MonoMethodDesc* desc = mono_method_desc_new ("TestDLL.Program:process", true);
    assert(desc);

    MonoMethod* method = mono_method_desc_search_in_image (desc, image);
    assert(method);

    //Create our container
    Container* c = new Container();

    //Cast to uint64
    uint64_t ptr = reinterpret_cast<uint64_t>(c);

    //Fill it as an argument before the mono method invokation
    void* args[1];
    args[0] = &ptr;

    //Invoke C# code
    mono_runtime_invoke (method, nullptr, args, nullptr);

    //Clean mono runtime
    mono_jit_cleanup (domain);

    //We did it!
    c->dump();

}
Beispiel #22
0
static HRESULT WINAPI CLRRuntimeHost_ExecuteInDefaultAppDomain(ICLRRuntimeHost* iface,
    LPCWSTR pwzAssemblyPath, LPCWSTR pwzTypeName, LPCWSTR pwzMethodName,
    LPCWSTR pwzArgument, DWORD *pReturnValue)
{
    RuntimeHost *This = impl_from_ICLRRuntimeHost( iface );
    HRESULT hr;
    MonoDomain *domain;
    MonoAssembly *assembly;
    MonoImage *image;
    MonoClass *klass;
    MonoMethod *method;
    MonoObject *result;
    MonoString *str;
    void *args[2];
    char *filenameA = NULL, *classA = NULL, *methodA = NULL;
    char *argsA = NULL, *ns;

    TRACE("(%p,%s,%s,%s,%s)\n", iface, debugstr_w(pwzAssemblyPath),
        debugstr_w(pwzTypeName), debugstr_w(pwzMethodName), debugstr_w(pwzArgument));

    hr = RuntimeHost_GetDefaultDomain(This, &domain);
    if(hr != S_OK)
    {
        ERR("Couldn't get Default Domain\n");
        return hr;
    }

    hr = E_FAIL;

    mono_thread_attach(domain);

    filenameA = WtoA(pwzAssemblyPath);
    assembly = mono_domain_assembly_open(domain, filenameA);
    if (!assembly)
    {
        ERR("Cannot open assembly %s\n", filenameA);
        goto cleanup;
    }

    image = mono_assembly_get_image(assembly);
    if (!image)
    {
        ERR("Couldn't get assembly image\n");
        goto cleanup;
    }

    classA = WtoA(pwzTypeName);
    ns = strrchr(classA, '.');
    *ns = '\0';
    klass = mono_class_from_name(image, classA, ns+1);
    if (!klass)
    {
        ERR("Couldn't get class from image\n");
        goto cleanup;
    }

    methodA = WtoA(pwzMethodName);
    method = mono_class_get_method_from_name(klass, methodA, 1);
    if (!method)
    {
        ERR("Couldn't get method from class\n");
        goto cleanup;
    }

    /* The .NET function we are calling has the following declaration
     *   public static int functionName(String param)
     */
    argsA = WtoA(pwzArgument);
    str = mono_string_new(domain, argsA);
    args[0] = str;
    args[1] = NULL;
    result = mono_runtime_invoke(method, NULL, args, NULL);
    if (!result)
        ERR("Couldn't get result pointer\n");
    else
    {
        *pReturnValue = *(DWORD*)mono_object_unbox(result);
        hr = S_OK;
    }

cleanup:
    HeapFree(GetProcessHeap(), 0, filenameA);
    HeapFree(GetProcessHeap(), 0, classA);
    HeapFree(GetProcessHeap(), 0, argsA);
    HeapFree(GetProcessHeap(), 0, methodA);

    return hr;
}
Beispiel #23
0
MonoImage* MonoEmbedding::GetImage()
{
    return mono_assembly_get_image(assembly);
}
Beispiel #24
0
void try_mono() {
  MonoDomain *domain;
  MonoAssembly *ma;
  MonoImage *mi;
  MonoClass *mc;
  MonoMethodDesc *mmd;
  MonoMethod *mm;
  MonoObject *mo;
  FILE *mscorlib;
  char *corlib_data = NULL;
  void *args [2];
  static int x = 123000;
  args [0] = &x;
  args [1] = "hello world";

#if defined(__native_client__)
  mscorlib = fopen("mscorlib.dll", "r");
  if (NULL != mscorlib) {
    size_t size;
    struct stat st;
    if (0 == stat("mscorlib.dll", &st)) {
      size = st.st_size;
      printf("reading mscorlib.dll, size %ld\n", size);
      corlib_data = malloc(size);
      if (corlib_data != NULL) {
        while (fread(corlib_data, 1, size, mscorlib) != 0) ;
        if (!ferror(mscorlib)) {
          mono_set_corlib_data(corlib_data, size);
        } else {
          perror("error reading mscorlib.dll");
          free(corlib_data);
          corlib_data = NULL;
        }
      } else {
        perror("Could not allocate memory");
      }
    } else {
      perror("stat error");
    }
    fclose(mscorlib);
  }
#endif

#ifdef AOT_VERSION
  printf("address of mono_aot_module_mscorlib_info:  %p\n", mono_aot_module_mscorlib_info);
  printf("address of mono_aot_module_hw_info:  %p\n", mono_aot_module_hw_info);

  // mono_jit_set_aot_only(TRUE) should be enabled now.
  // if not enabled, I suspect we're still jitting...
  mono_jit_set_aot_only(TRUE);

  mono_aot_register_module(mono_aot_module_mscorlib_info);
  mono_aot_register_module(mono_aot_module_hw_info);
#endif

  mono_debug_init(MONO_DEBUG_FORMAT_MONO);
  domain = mono_jit_init("hw.exe", "v2.0.50727");

  printf("mono domain: %p\n", domain);

  ma = mono_domain_assembly_open(domain, "hw.exe");
  printf("mono assembly: %p\n", ma);

  mi = mono_assembly_get_image(ma);
  printf("mono image: %p\n", mi);

  mc = mono_class_from_name(mi, "Test", "HelloWorld");
  printf("mono class: %p\n", mc);

  mmd = mono_method_desc_new("Test.HelloWorld:Foobar(int,string)", TRUE);
  printf("mono desc method: %p\n", mmd);

  mm = mono_method_desc_search_in_image(mmd, mi);
  printf("mono method: %p\n", mm);

  // add c functions for mono test code to invoke
  mono_add_internal_call("Test.c_code::my_c_func", (void *) my_c_func);
  mono_add_internal_call("Test.c_code::my_c_pass", (void *) my_c_pass);

  mo = mono_runtime_invoke(mm, NULL, args, NULL);

  printf("mono object: %p\n", mo);
  if (NULL != corlib_data) free(corlib_data);
}
Beispiel #25
0
int
main (void)
{
	int res = 0;
	MonoDomain *domain = NULL;
	MonoAssembly *assembly = NULL;
	MonoImage *prog_image = NULL;
	MonoImage *corlib = NULL;
	MonoClass *prog_klass, *console_klass;
	MonoMethod *meth;
	MonoImageOpenStatus status;

	//FIXME This is a fugly hack due to embedding simply not working from the tree
	mono_set_assemblies_path ("../../mcs/class/lib/net_4_x");

	test_methods = g_array_new (FALSE, TRUE, sizeof (MonoMethod *));
	if (!test_methods) {
		res = 1;
		printf ("FAILED INITIALIZING METHODS ARRAY\n");
		goto out;
	}

	domain = mono_jit_init_version ("TEST RUNNER", "mobile");
	assembly = mono_assembly_open (TESTPROG, &status);
	if (!domain || !assembly) {
		res = 1;
		printf("FAILED LOADING TEST PROGRAM\n");
		goto out;
	}

	mono_callspec_set_assembly(assembly);

	prog_image = mono_assembly_get_image (assembly);

	prog_klass = test_mono_class_from_name (prog_image, "Baz", "Foo");
	if (!prog_klass) {
		res = 1;
		printf ("FAILED FINDING Baz.Foo\n");
		goto out;
	}
	meth = mono_class_get_method_from_name (prog_klass, "Bar", 0);
	if (!meth) {
		res = 1;
		printf ("FAILED FINDING Baz.Foo:Bar ()\n");
		goto out;
	}
	g_array_append_val (test_methods, meth);
	meth = mono_class_get_method_from_name (prog_klass, "Bar", 1);
	if (!meth) {
		res = 1;
		printf ("FAILED FINDING Baz.Foo:Bar (string)\n");
		goto out;
	}
	g_array_append_val (test_methods, meth);

	prog_klass = test_mono_class_from_name (prog_image, "Baz", "Goo");
	if (!prog_klass) {
		res = 1;
		printf ("FAILED FINDING Baz.Goo\n");
		goto out;
	}
	meth = mono_class_get_method_from_name (prog_klass, "Bar", 1);
	if (!meth) {
		res = 1;
		printf ("FAILED FINDING Baz.Goo:Bar (string)\n");
		goto out;
	}
	g_array_append_val (test_methods, meth);

	prog_klass = test_mono_class_from_name (prog_image, "Baz", "Foo2");
	if (!prog_klass) {
		res = 1;
		printf ("FAILED FINDING Baz.Foo2\n");
		goto out;
	}
	meth = mono_class_get_method_from_name (prog_klass, "Bar", 1);
	if (!meth) {
		res = 1;
		printf ("FAILED FINDING Baz.Foo2:Bar (string)\n");
		goto out;
	}
	g_array_append_val (test_methods, meth);

	corlib = mono_get_corlib ();

	console_klass = test_mono_class_from_name (corlib, "System", "Console");
	if (!console_klass) {
		res = 1;
		printf ("FAILED FINDING System.Console\n");
		goto out;
	}
	meth = mono_class_get_method_from_name (console_klass, "WriteLine", 1);
	if (!meth) {
		res = 1;
		printf ("FAILED FINDING System.Console:WriteLine\n");
		goto out;
	}
	g_array_append_val (test_methods, meth);

	res = test_all_callspecs ();
out:
	return res;
}
Beispiel #26
0
//#####################################################################
// Function listAssembliesHelper
//#####################################################################
static void listAssembliesHelper(MonoAssembly* assembly, MonoSystem* this_ptr) {
    MonoImage* image = mono_assembly_get_image(assembly);
    printf("Assembly Image: %s\n", mono_image_get_name(image));
}
JNIEXPORT jboolean JNICALL Java_com_koushikdutta_monojavabridge_MonoBridge_initializeMono
  (JNIEnv *env, jclass clazz, jstring debuggerAgentOptions)
{
   // setenv("HOME", "/data/data/com.koushikdutta.twitter/", 1);
#ifdef PLATFORM_ANDROID
    if (debuggerAgentOptions != NULL)
    {
        LOGI("Debugger enabled...");
        int length = (*env)->GetStringLength(env, debuggerAgentOptions);
        const jbyte *str = (*env)->GetStringUTFChars(env, debuggerAgentOptions, NULL);
        char *copy = (char*)malloc(length + 1);
        copy[length] = NULL;
        memcpy(copy, str, length);
        mono_debugger_agent_parse_options(copy);
        free(copy);
        (*env)->ReleaseStringUTFChars(env, debuggerAgentOptions, str);
        mono_debug_init (MONO_DEBUG_FORMAT_MONO);
    }
#endif
    
    //guint32 opt = mono_parse_default_optimizations(NULL);
	//mono_set_defaults (1, opt);
    //mono_trace_parse_options ("");
    
    setenv("MONO_PATH", "/data/data/com.koushikdutta.mono/", 0);

#ifdef PLATFORM_ANDROID
    LOGI("mono_jit_init...");
#endif
	g_Domain = mono_jit_init (MONOJAVABRIDGE_DLL);

#ifdef PLATFORM_ANDROID
    LOGI("mono_domain_assembly_open...", NULL);
#endif
    g_Assembly = mono_domain_assembly_open (g_Domain, MONOJAVABRIDGE_DLL);
    if (!g_Assembly)
    {
        printf("Unable to load MonoJavaBridge.dll.");
        return FALSE;
    }

    mono_add_internal_call("MonoJavaBridge.JavaBridge::mono_object_to_pointer(object)", mono_objectpointer_conversion);
    mono_add_internal_call("MonoJavaBridge.JavaBridge::mono_pointer_to_object(intptr)", mono_objectpointer_conversion);
    mono_add_internal_call("MonoJavaBridge.JavaBridge::log(intptr)", logcat_print);

    MonoImage *image = mono_assembly_get_image(g_Assembly);
    MonoMethodDesc* desc = mono_method_desc_new ("MonoJavaBridge.JavaBridge:Initialize(intptr)", 1);
    MonoMethod* method = mono_method_desc_search_in_image (desc, image);
    mono_method_desc_free(desc);
    pointer args[1];
    args[0] = &g_JavaVM;
    mono_runtime_invoke(method, NULL, args, NULL);

    desc = mono_method_desc_new ("MonoJavaBridge.JavaBridge:Link(intptr,intptr,intptr,intptr)", 1);
    g_Link = mono_method_desc_search_in_image (desc, image);
    mono_method_desc_free(desc);

    desc = mono_method_desc_new ("MonoJavaBridge.JavaBridge:LoadAssembly(intptr)", 1);
    g_LoadAssembly = mono_method_desc_search_in_image (desc, image);
    mono_method_desc_free(desc);
    
    return TRUE;
}
Beispiel #28
0
void main_thread_handler (gpointer user_data) {
    PyNet_Args *pn_args=(PyNet_Args *)user_data;
    MonoMethod *init;
    MonoImage *pr_image;
    MonoClass *pythonengine;
    MonoObject *exception = NULL;
    MonoObject *init_result;

#ifndef _WIN32
    // Get the filename of the python shared object and set
    // LD_LIBRARY_PATH so Mono can find it.
    Dl_info dlinfo = {0};
    if (0 != dladdr(&Py_Initialize, &dlinfo)) {
        char* fname = alloca(strlen(dlinfo.dli_fname) + 1);
        strcpy(fname, dlinfo.dli_fname);
        char* py_libdir = dirname(fname);
        char* ld_library_path = getenv("LD_LIBRARY_PATH");
        if (NULL == ld_library_path) {
            setenv("LD_LIBRARY_PATH", py_libdir, 1);
        } else {
            char* new_ld_library_path = alloca(strlen(py_libdir)
                                                + strlen(ld_library_path)
                                                + 2);
            strcpy(new_ld_library_path, py_libdir);
            strcat(new_ld_library_path, ":");
            strcat(new_ld_library_path, ld_library_path);
            setenv("LD_LIBRARY_PATH", py_libdir, 1);
        }
    }

    //get python path system variable
    PyObject* syspath = PySys_GetObject("path");
    char* runtime_full_path = (char*) malloc(1024);
    const char* slash = "/";
    int found = 0;

    int ii = 0;
    for (ii = 0; ii < PyList_Size(syspath); ++ii) {
#if PY_MAJOR_VERSION > 2
        Py_ssize_t wlen;
        wchar_t *wstr = PyUnicode_AsWideCharString(PyList_GetItem(syspath, ii), &wlen);
        char* pydir = (char*)malloc(wlen + 1);
        size_t mblen = wcstombs(pydir, wstr, wlen + 1);
        if (mblen > wlen)
            pydir[wlen] = '\0';
        PyMem_Free(wstr);
#else
        const char* pydir = PyString_AsString(PyList_GetItem(syspath, ii));
#endif
        char* curdir = (char*) malloc(1024);
        strncpy(curdir, strlen(pydir) > 0 ? pydir : ".", 1024);
        strncat(curdir, slash, 1024);

#if PY_MAJOR_VERSION > 2
        free(pydir);
#endif

        //look in this directory for the pn_args->pr_file
        DIR* dirp = opendir(curdir);
        if (dirp != NULL) {

            struct dirent *dp;
            while ((dp = readdir(dirp)) != NULL) {
                if (strcmp(dp->d_name, pn_args->pr_file) == 0) {
                    strcpy(runtime_full_path, curdir);
                    strcat(runtime_full_path, pn_args->pr_file);
                    found = 1;
                    break;
                }
            }
            closedir(dirp);
        }
        free(curdir);

        if (found) {
            pn_args->pr_file = runtime_full_path;
            break;
        }
    }

    if (!found) {
        fprintf(stderr, "Could not find assembly %s. \n", pn_args->pr_file);
        return;
    }
#endif


    pn_args->pr_assm = mono_domain_assembly_open(pn_args->domain, pn_args->pr_file);
    if (!pn_args->pr_assm) {
        pn_args->error = "Unable to load assembly";
        return;
    }
#ifndef _WIN32
    free(runtime_full_path);
#endif

    pr_image = mono_assembly_get_image(pn_args->pr_assm);
    if (!pr_image) {
        pn_args->error = "Unable to get image";
        return;
    }

    pythonengine = mono_class_from_name(pr_image, "Python.Runtime", "PythonEngine");
    if (!pythonengine) {
        pn_args->error = "Unable to load class PythonEngine from Python.Runtime";
        return;
    }

    init = getMethodFromClass(pythonengine, pn_args->init_name);
    if (!init) {
        pn_args->error = "Unable to fetch Init method from PythonEngine";
        return;
    }

    pn_args->shutdown = getMethodFromClass(pythonengine, pn_args->shutdown_name);
    if (!pn_args->shutdown) {
        pn_args->error = "Unable to fetch shutdown method from PythonEngine";
        return;
    }

    init_result = mono_runtime_invoke(init, NULL, NULL, &exception);
    if (exception) {
        pn_args->error = PyNet_ExceptionToString(exception);
        return;
    }

#if PY_MAJOR_VERSION >= 3
    if (NULL != init_result)
        pn_args->module = *(PyObject**)mono_object_unbox(init_result);
#endif

}
Beispiel #29
0
HRESULT create_monodata(REFIID riid, LPVOID *ppObj )
{
    static const WCHAR wszAssembly[] = {'A','s','s','e','m','b','l','y',0};
    static const WCHAR wszCodebase[] = {'C','o','d','e','B','a','s','e',0};
    static const WCHAR wszClass[] = {'C','l','a','s','s',0};
    static const WCHAR wszFileSlash[] = {'f','i','l','e',':','/','/','/',0};
    static const WCHAR wszCLSIDSlash[] = {'C','L','S','I','D','\\',0};
    static const WCHAR wszInprocServer32[] = {'\\','I','n','p','r','o','c','S','e','r','v','e','r','3','2',0};
    static const WCHAR wszDLL[] = {'.','d','l','l',0};
    WCHAR path[CHARS_IN_GUID + ARRAYSIZE(wszCLSIDSlash) + ARRAYSIZE(wszInprocServer32) - 1];
    MonoDomain *domain;
    MonoAssembly *assembly;
    ICLRRuntimeInfo *info = NULL;
    RuntimeHost *host;
    HRESULT hr;
    HKEY key, subkey;
    LONG res;
    int offset = 0;
    DWORD numKeys, keyLength;
    WCHAR codebase[MAX_PATH + 8];
    WCHAR classname[350], subkeyName[256];
    WCHAR filename[MAX_PATH];

    DWORD dwBufLen = 350;

    lstrcpyW(path, wszCLSIDSlash);
    StringFromGUID2(riid, path + lstrlenW(wszCLSIDSlash), CHARS_IN_GUID);
    lstrcatW(path, wszInprocServer32);

    TRACE("Registry key: %s\n", debugstr_w(path));

    res = RegOpenKeyExW(HKEY_CLASSES_ROOT, path, 0, KEY_READ, &key);
    if (res == ERROR_FILE_NOT_FOUND)
        return CLASS_E_CLASSNOTAVAILABLE;

    res = RegGetValueW( key, NULL, wszClass, RRF_RT_REG_SZ, NULL, classname, &dwBufLen);
    if(res != ERROR_SUCCESS)
    {
        WARN("Class value cannot be found.\n");
        hr = CLASS_E_CLASSNOTAVAILABLE;
        goto cleanup;
    }

    TRACE("classname (%s)\n", debugstr_w(classname));

    dwBufLen = MAX_PATH + 8;
    res = RegGetValueW( key, NULL, wszCodebase, RRF_RT_REG_SZ, NULL, codebase, &dwBufLen);
    if(res == ERROR_SUCCESS)
    {
        /* Strip file:/// */
        if(strncmpW(codebase, wszFileSlash, strlenW(wszFileSlash)) == 0)
            offset = strlenW(wszFileSlash);

        strcpyW(filename, codebase + offset);
    }
    else
    {
        WCHAR assemblyname[MAX_PATH + 8];

        hr = CLASS_E_CLASSNOTAVAILABLE;
        WARN("CodeBase value cannot be found, trying Assembly.\n");
        /* get the last subkey of InprocServer32 */
        res = RegQueryInfoKeyW(key, 0, 0, 0, &numKeys, 0, 0, 0, 0, 0, 0, 0);
        if (res != ERROR_SUCCESS || numKeys == 0)
            goto cleanup;
        numKeys--;
        keyLength = sizeof(subkeyName) / sizeof(WCHAR);
        res = RegEnumKeyExW(key, numKeys, subkeyName, &keyLength, 0, 0, 0, 0);
        if (res != ERROR_SUCCESS)
            goto cleanup;
        res = RegOpenKeyExW(key, subkeyName, 0, KEY_READ, &subkey);
        if (res != ERROR_SUCCESS)
            goto cleanup;
        dwBufLen = MAX_PATH + 8;
        res = RegGetValueW(subkey, NULL, wszAssembly, RRF_RT_REG_SZ, NULL, assemblyname, &dwBufLen);
        RegCloseKey(subkey);
        if (res != ERROR_SUCCESS)
            goto cleanup;

        hr = get_file_from_strongname(assemblyname, filename, MAX_PATH);
        if (!SUCCEEDED(hr))
        {
            /*
             * The registry doesn't have a CodeBase entry and it's not in the GAC.
             *
             * Use the Assembly Key to retrieve the filename.
             *    Assembly : REG_SZ : AssemblyName, Version=X.X.X.X, Culture=neutral, PublicKeyToken=null
             */
            WCHAR *ns;

            WARN("Attempt to load from the application directory.\n");
            GetModuleFileNameW(NULL, filename, MAX_PATH);
            ns = strrchrW(filename, '\\');
            *(ns+1) = '\0';

            ns = strchrW(assemblyname, ',');
            *(ns) = '\0';
            strcatW(filename, assemblyname);
            *(ns) = '.';
            strcatW(filename, wszDLL);
        }
    }

    TRACE("filename (%s)\n", debugstr_w(filename));

    *ppObj = NULL;


    hr = get_runtime_info(filename, NULL, NULL, 0, 0, FALSE, &info);
    if (SUCCEEDED(hr))
    {
        hr = ICLRRuntimeInfo_GetRuntimeHost(info, &host);

        if (SUCCEEDED(hr))
            hr = RuntimeHost_GetDefaultDomain(host, &domain);

        if (SUCCEEDED(hr))
        {
            MonoImage *image;
            MonoClass *klass;
            MonoObject *result;
            IUnknown *unk = NULL;
            char *filenameA, *ns;
            char *classA;

            hr = CLASS_E_CLASSNOTAVAILABLE;

            mono_thread_attach(domain);

            filenameA = WtoA(filename);
            assembly = mono_domain_assembly_open(domain, filenameA);
            HeapFree(GetProcessHeap(), 0, filenameA);
            if (!assembly)
            {
                ERR("Cannot open assembly %s\n", filenameA);
                goto cleanup;
            }

            image = mono_assembly_get_image(assembly);
            if (!image)
            {
                ERR("Couldn't get assembly image\n");
                goto cleanup;
            }

            classA = WtoA(classname);
            ns = strrchr(classA, '.');
            *ns = '\0';

            klass = mono_class_from_name(image, classA, ns+1);
            HeapFree(GetProcessHeap(), 0, classA);
            if (!klass)
            {
                ERR("Couldn't get class from image\n");
                goto cleanup;
            }

            /*
             * Use the default constructor for the .NET class.
             */
            result = mono_object_new(domain, klass);
            mono_runtime_object_init(result);

            hr = RuntimeHost_GetIUnknownForObject(host, result, &unk);
            if (SUCCEEDED(hr))
            {
                hr = IUnknown_QueryInterface(unk, &IID_IUnknown, ppObj);

                IUnknown_Release(unk);
            }
            else
                hr = CLASS_E_CLASSNOTAVAILABLE;
        }
        else
            hr = CLASS_E_CLASSNOTAVAILABLE;
    }
    else
        hr = CLASS_E_CLASSNOTAVAILABLE;

cleanup:
    if(info)
        ICLRRuntimeInfo_Release(info);

    RegCloseKey(key);

    return hr;
}
Beispiel #30
0
static void CDECL ReallyFixupVTable(struct dll_fixup *fixup)
{
    HRESULT hr=S_OK;
    WCHAR filename[MAX_PATH];
    ICLRRuntimeInfo *info=NULL;
    RuntimeHost *host;
    char *filenameA;
    MonoImage *image=NULL;
    MonoAssembly *assembly=NULL;
    MonoImageOpenStatus status=0;
    MonoDomain *domain;

    if (fixup->done) return;

    /* It's possible we'll have two threads doing this at once. This is
     * considered preferable to the potential deadlock if we use a mutex. */

    GetModuleFileNameW(fixup->dll, filename, MAX_PATH);

    TRACE("%p,%p,%s\n", fixup, fixup->dll, debugstr_w(filename));

    filenameA = WtoA(filename);
    if (!filenameA)
        hr = E_OUTOFMEMORY;

    if (SUCCEEDED(hr))
        hr = get_runtime_info(filename, NULL, NULL, 0, 0, FALSE, &info);

    if (SUCCEEDED(hr))
        hr = ICLRRuntimeInfo_GetRuntimeHost(info, &host);

    if (SUCCEEDED(hr))
        hr = RuntimeHost_GetDefaultDomain(host, &domain);

    if (SUCCEEDED(hr))
    {
        mono_thread_attach(domain);

        assembly = mono_assembly_open(filenameA, &status);
    }

    if (assembly)
    {
        int i;

        /* Mono needs an image that belongs to an assembly. */
        image = mono_assembly_get_image(assembly);

        if (fixup->fixup->type & COR_VTABLE_32BIT)
        {
            DWORD *vtable = fixup->vtable;
            DWORD *tokens = fixup->tokens;
            for (i=0; i<fixup->fixup->count; i++)
            {
                TRACE("%x\n", tokens[i]);
                vtable[i] = PtrToUint(mono_marshal_get_vtfixup_ftnptr(
                    image, tokens[i], fixup->fixup->type));
            }
        }

        fixup->done = TRUE;
    }

    if (info != NULL)
        ICLRRuntimeInfo_Release(info);

    HeapFree(GetProcessHeap(), 0, filenameA);

    if (!fixup->done)
    {
        ERR("unable to fixup vtable, hr=%x, status=%d\n", hr, status);
        /* If we returned now, we'd get an infinite loop. */
        assert(0);
    }
}