Example #1
0
static MonoClass*
find_class (MonoImage *image, char *name)
{
	char *p = strrchr (name, '.');
	if (p) {
		*p = 0;
		return mono_class_from_name (image, name, p + 1);
	}
	return mono_class_from_name (image, "", name);
}
Example #2
0
MonoMethod* find_method(MonoImage* image, const char* className, const char* namspace, const char* methodName)
{
	MonoClass* klass = mono_class_from_name(image, namspace, className);
	if (!klass)	return NULL;

	return find_method(klass, methodName);
}
Example #3
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);
}
Example #4
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); 
}
Example #5
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;
}
Example #6
0
/**
 * mono_get_exception_type_initialization:
 * @type_name: the name of the type that failed to initialize.
 * @inner: the inner exception.
 *
 * Returns: a new instance of the System.TypeInitializationException
 */
MonoException *
mono_get_exception_type_initialization (const gchar *type_name, MonoException *inner)
{
	MonoClass *klass;
	gpointer args [2];
	MonoObject *exc;
	MonoMethod *method;
	gpointer iter;

	klass = mono_class_from_name (mono_get_corlib (), "System", "TypeInitializationException");
	g_assert (klass);

	mono_class_init (klass);

	/* TypeInitializationException only has 1 ctor with 2 args */
	iter = NULL;
	while ((method = mono_class_get_methods (klass, &iter))) {
		if (!strcmp (".ctor", mono_method_get_name (method)) && mono_method_signature (method)->param_count == 2)
			break;
		method = NULL;
	}

	g_assert (method);

	args [0] = mono_string_new (mono_domain_get (), type_name);
	args [1] = inner;

	exc = mono_object_new (mono_domain_get (), klass);
	mono_runtime_invoke (method, exc, args, NULL);

	return (MonoException *) exc;
}
Example #7
0
static gint64
debugger_lookup_class (guint64 image_argument, G_GNUC_UNUSED guint64 dummy,
		       G_GNUC_UNUSED guint64 dummy2, gchar *full_name)
{
	MonoImage *image = (MonoImage *) GUINT_TO_POINTER ((gsize) image_argument);
	gchar *name_space, *name, *pos;
	MonoClass *klass;

	pos = strrchr (full_name, '.');
	if (pos) {
		name_space = full_name;
		*pos = 0;
		name = pos + 1;
	} else {
		name = full_name;
		name_space = NULL;
	}

	klass = mono_class_from_name (image, name_space ? name_space : "", name);
	if (!klass)
		return -1;

	mono_class_init (klass);
	mono_class_setup_methods (klass);
	return (gint64) (gssize) klass;
}
Example #8
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;
}
Example #9
0
void
mono_thread_pool_init ()
{
	gint threads_per_cpu = 1;
	gint thread_count;
	gint cpu_count = mono_cpu_count ();
	int result;

	if (tp_inited == 2)
		return;

	result = InterlockedCompareExchange (&tp_inited, 1, 0);
	if (result == 1) {
		while (1) {
			SleepEx (1, FALSE);
			if (tp_inited == 2)
				return;
		}
	}

	MONO_GC_REGISTER_ROOT_FIXED (socket_io_data.sock_to_state);
	InitializeCriticalSection (&socket_io_data.io_lock);
	if (g_getenv ("MONO_THREADS_PER_CPU") != NULL) {
		threads_per_cpu = atoi (g_getenv ("MONO_THREADS_PER_CPU"));
		if (threads_per_cpu < 1)
			threads_per_cpu = 1;
	}

	thread_count = MIN (cpu_count * threads_per_cpu, 100 * cpu_count);
	threadpool_init (&async_tp, thread_count, MAX (100 * cpu_count, thread_count), async_invoke_thread);
	threadpool_init (&async_io_tp, cpu_count * 2, cpu_count * 4, async_invoke_thread);
	async_io_tp.is_io = TRUE;

	async_call_klass = mono_class_from_name (mono_defaults.corlib, "System", "MonoAsyncCall");
	g_assert (async_call_klass);

	InitializeCriticalSection (&wsqs_lock);
	wsqs = g_ptr_array_sized_new (MAX (100 * cpu_count, thread_count));
	mono_wsq_init ();

#ifndef DISABLE_PERFCOUNTERS
	async_tp.pc_nitems = init_perf_counter ("Mono Threadpool", "Work Items Added");
	g_assert (async_tp.pc_nitems);

	async_io_tp.pc_nitems = init_perf_counter ("Mono Threadpool", "IO Work Items Added");
	g_assert (async_io_tp.pc_nitems);

	async_tp.pc_nthreads = init_perf_counter ("Mono Threadpool", "# of Threads");
	g_assert (async_tp.pc_nthreads);

	async_io_tp.pc_nthreads = init_perf_counter ("Mono Threadpool", "# of IO Threads");
	g_assert (async_io_tp.pc_nthreads);
#endif
	tp_inited = 2;
#ifdef DEBUG
	signal (SIGALRM, signal_handler);
	alarm (2);
#endif
}
Example #10
0
/**
 * mono_exception_from_name_two_strings:
 * @image: the Mono image where to look for the class
 * @name_space: the namespace for the class
 * @name: class name
 * @a1: first string argument to pass
 * @a2: second string argument to pass
 *
 * Creates an exception from a constructor that takes two string
 * arguments.
 *
 * Returns: the initialized exception instance.
 */
MonoException *
mono_exception_from_name_two_strings (MonoImage *image, const char *name_space,
				      const char *name, MonoString *a1, MonoString *a2)
{
	MonoClass *klass = mono_class_from_name (image, name_space, name);

	return create_exception_two_strings (klass, a1, a2);
}
Example #11
0
static MonoClass* GetClrFuncInvokeContextClass()
{
    static MonoClass* klass;

    if (!klass)
        klass = mono_class_from_name(MonoEmbedding::GetImage(), "", "ClrFuncInvokeContext");

    return klass;
}
Example #12
0
static MonoClass* GetNodejsFuncClass()
{
    static MonoClass* klass;

    if (!klass)
        klass = mono_class_from_name(MonoEmbedding::GetImage(), "", "NodejsFunc");

    return klass;
}
Example #13
0
MonoClass* MonoEmbedding::GetClass()
{
    static MonoClass* klass;

    if (!klass)
        klass = mono_class_from_name(GetImage(), "", "MonoEmbedding");

    return klass;
}
Example #14
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");
}
Example #15
0
MonoArray*
ves_icall_System_Globalization_CultureInfo_internal_get_cultures (MonoBoolean neutral,
		MonoBoolean specific, MonoBoolean installed)
{
	MonoArray *ret;
	MonoClass *klass;
	MonoCultureInfo *culture;
	MonoDomain *domain;
	const CultureInfoEntry *ci;
	gint i, len;
	gboolean is_neutral;

	domain = mono_domain_get ();

	len = 0;
	for (i = 0; i < NUM_CULTURE_ENTRIES; i++) {
		ci = &culture_entries [i];
		is_neutral = ci->territory == 0;
		if ((neutral && is_neutral) || (specific && !is_neutral))
			len++;
	}

	klass = mono_class_from_name (mono_get_corlib (),
			"System.Globalization", "CultureInfo");

	/* The InvariantCulture is not in culture_entries */
	/* We reserve the first slot in the array for it */
	if (neutral)
		len++;

	ret = mono_array_new (domain, klass, len);

	if (len == 0)
		return ret;

	len = 0;
	if (neutral)
		mono_array_setref (ret, len++, NULL);

	for (i = 0; i < NUM_CULTURE_ENTRIES; i++) {
		ci = &culture_entries [i];
		is_neutral = ci->territory == 0;
		if ((neutral && is_neutral) || (specific && !is_neutral)) {
			culture = (MonoCultureInfo *) mono_object_new (domain, klass);
			mono_runtime_object_init ((MonoObject *) culture);
			construct_culture (culture, ci);
			culture->use_user_override = TRUE;
			mono_array_setref (ret, len++, culture);
		}
	}

	return ret;
}
Example #16
0
static MonoClass*
security_safe_critical_attribute (void)
{
	static MonoClass *klass = NULL;

	if (!klass) {
		klass = mono_class_from_name (mono_defaults.corlib, "System.Security", 
			"SecuritySafeCriticalAttribute");
	}
	g_assert (klass);
	return klass;
}
Example #17
0
G_MODULE_EXPORT void
theme_exit ()
{
    MaigreMonoBridge *bridge = maigre_mono_bridge ();
    MonoClass *klass;
    MonoMethod *method;

    if (bridge != NULL &&
        (klass = mono_class_from_name (bridge->image, "Maigre", "ThemeModule")) != NULL &&
        (method = mono_class_get_method_from_name (klass, "Exit", 0)) != NULL) {
        mono_runtime_invoke (method, NULL, NULL, NULL);
   }
}
Example #18
0
/**
 * mono_mlist_alloc:
 * @data: object to use as data
 *
 * Allocates a new managed list node with @data as the contents.
 * A managed list node also represents a singly-linked list.
 * Managed lists are garbage collected, so there is no free routine
 * and the user is required to keep references to the managed list
 * to prevent it from being garbage collected.
 */
MonoMList*
mono_mlist_alloc (MonoObject *data)
{
	MonoError error;
	MonoMList* res;
	if (!monolist_item_vtable) {
		MonoClass *klass = mono_class_from_name (mono_defaults.corlib, "System", "MonoListItem");
		monolist_item_vtable = mono_class_vtable (mono_get_root_domain (), klass);
		g_assert (monolist_item_vtable);
	}
	res = (MonoMList*)mono_object_new_fast_checked (monolist_item_vtable, &error);
	mono_error_raise_exception (&error);
	MONO_OBJECT_SETREF (res, data, data);
	return res;
}
Example #19
0
/*
 * mono_class_find
 *
 *     Get class by its signature
 */
MonoClass*
mono_class_find(MonoImage *image, char *sig)
{
	MonoClass *klass = NULL;
	char *p = sig;

	while (!klass && (p = strchr(p, '.')))
	{
		*p = '\0';
		klass = mono_class_from_name(image, sig, p + 1);
		*p = '.';
	}

	return klass;
}
Example #20
0
void JniManager::setMono(MonoImage* monoImage)
{
    processRequestClass = mono_class_from_name(monoImage, "Org.Mule.Api.Routing", "ProcessRequest");
    setAssemblyNameField = mono_class_get_method_from_name(processRequestClass, "set_AssemblyName", 1);
    setMethodNameField = mono_class_get_method_from_name(processRequestClass, "set_MethodName", 1);
    setAssemblyPathField = mono_class_get_method_from_name(processRequestClass, "set_AssemblyPath", 1);
    setFullTrustField = mono_class_get_method_from_name(processRequestClass, "set_FullTrust", 1);
    setIsSingletonField = mono_class_get_method_from_name(processRequestClass, "set_IsSingleton", 1);
    setLogField = mono_class_get_method_from_name(processRequestClass, "set_Log", 1);
    getResult = mono_class_get_method_from_name(processRequestClass, "get_Result", 0);
    setNotifyEventsField = mono_class_get_method_from_name(processRequestClass, "set_NotifyEvents", 1);
    addMethodArgumentsProperty = mono_class_get_method_from_name(processRequestClass, "AddMethodArgumentProperty", 2);
    addInboundProperty = mono_class_get_method_from_name(processRequestClass, "AddInboundProperty", 2);
    addInvocationProperty = mono_class_get_method_from_name(processRequestClass, "AddInvocationProperty", 2);
    addSessionProperty = mono_class_get_method_from_name(processRequestClass, "AddSessionProperty", 2);
    addOutboundProperty = mono_class_get_method_from_name(processRequestClass, "AddOutboundProperty", 2);
}
Example #21
0
void
mono_threadpool_ms_enqueue_async_result (MonoDomain *domain, MonoAsyncResult *ares)
{
	static MonoClass *runtime_work_item_class = NULL;
	MonoRuntimeWorkItem *rwi;

	g_assert (ares);

	if (!runtime_work_item_class)
		runtime_work_item_class = mono_class_from_name (mono_defaults.corlib, "System.Threading", "MonoRuntimeWorkItem");
	g_assert (runtime_work_item_class);

	rwi = (MonoRuntimeWorkItem*) mono_object_new (domain, runtime_work_item_class);
	MONO_OBJECT_SETREF (rwi, async_result, ares);

	mono_threadpool_ms_enqueue_work_item (domain, (MonoObject*) rwi);
}
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;
}
Example #23
0
G_MODULE_EXPORT void
theme_init (GTypeModule *module)
{
    MaigreMonoBridge *bridge = maigre_mono_bridge ();
    MonoClass *klass;
    MonoMethod *method;

    if (bridge == NULL) {
        g_warning ("Maigre failed to initialize. Default internal "
            "GtkRcStyle/GtkStyle will be used.");
        return;
    }

    maigre_rc_style_register_types (module);

    if (bridge != NULL &&
        (klass = mono_class_from_name (bridge->image, "Maigre", "ThemeModule")) != NULL &&
        (method = mono_class_get_method_from_name (klass, "Init", 0)) != NULL) {
        mono_runtime_invoke (method, NULL, NULL, NULL);
   }
}
Example #24
0
/**
 * mono_exception_from_name_domain:
 * @domain: Domain where the return object will be created.
 * @image: the Mono image where to look for the class
 * @name_space: the namespace for the class
 * @name: class name
 *
 * Creates an exception object of the given namespace/name class on
 * the given domain.
 *
 * Returns: the initialized exception instance.
 */
MonoException *
mono_exception_from_name_domain (MonoDomain *domain, MonoImage *image, 
				 const char* name_space, const char *name)
{
	MonoClass *klass;
	MonoObject *o;
	MonoDomain *caller_domain = mono_domain_get ();

	klass = mono_class_from_name (image, name_space, name);

	o = mono_object_new (domain, klass);
	g_assert (o != NULL);

	if (domain != caller_domain)
		mono_domain_set_internal (domain);
	mono_runtime_object_init (o);
	if (domain != caller_domain)
		mono_domain_set_internal (caller_domain);

	return (MonoException *)o;
}
Example #25
0
MonoObject* ml_create_api_object(char *class_name)
{
	MonoObject *obj = NULL;
	MonoClass *klass = NULL;

	klass = mono_class_from_name(ml_get_api_image(), "Purple", class_name);
	if (!klass) {
		purple_debug(PURPLE_DEBUG_FATAL, "mono", "couldn't find the '%s' class\n", class_name);
		return NULL;
	}

	obj = mono_object_new(ml_get_domain(), klass);
	if (!obj) {
		purple_debug(PURPLE_DEBUG_FATAL, "mono", "couldn't create the object from class '%s'\n", class_name);
		return NULL;
	}

	mono_runtime_object_init(obj);

	return obj;
}
Example #26
0
	MonoClass* MonoAssembly::getClass(const String& namespaceName, const String& name) const
	{
		if(!mIsLoaded)
			BS_EXCEPT(InvalidStateException, "Trying to use an unloaded assembly.");

		MonoAssembly::ClassId classId(namespaceName, name);
		auto iterFind = mClasses.find(classId);

		if(iterFind != mClasses.end())
			return iterFind->second;

		::MonoClass* monoClass = mono_class_from_name(mMonoImage, namespaceName.c_str(), name.c_str());
		if(monoClass == nullptr)
			return nullptr;

		MonoClass* newClass = new (bs_alloc<MonoClass>()) MonoClass(namespaceName, name, monoClass, this);
		mClasses[classId] = newClass;
		mClassesByRaw[monoClass] = newClass;

		return newClass;
	}
Example #27
0
__stub void *new_Test_TestClass2(int start)
{
	MonoException *exception;
	MonoObject *obj;
	
slow_path:
	sp_ensure_runtime();
	Test_TestClass = mono_class_from_name(m_image, "Test", "TestClass");
	Fnnew_Test_TestClass2 = sp_get_method_thunk("Test.TestClass:.ctor(int)");
	sp_rewrite_me(&&slow_path, &&fast_path);

fast_path:		
	obj = mono_object_new(m_domain, Test_TestClass);
	Fnnew_Test_TestClass2(obj, start, &exception);
	if (exception != NULL) {
		mono_raise_exception(exception);
		return NULL;
	}
	
	return obj;
}
Example #28
0
static void
do_console_cancel_event (void)
{
	static MonoClassField *cancel_handler_field;
	MonoDomain *domain = mono_domain_get ();
	MonoClass *klass;
	MonoDelegate *load_value;
	MonoMethod *method;
	MonoMethodMessage *msg;
	MonoMethod *im;
	MonoVTable *vtable;

	/* FIXME: this should likely iterate all the domains, instead */
	if (!domain->domain)
		return;

	klass = mono_class_from_name (mono_defaults.corlib, "System", "Console");
	if (klass == NULL)
		return;

	if (cancel_handler_field == NULL) {
		cancel_handler_field = mono_class_get_field_from_name (klass, "cancel_handler");
		g_assert (cancel_handler_field);
	}

	vtable = mono_class_vtable_full (domain, klass, FALSE);
	if (vtable == NULL)
		return;
	mono_field_static_get_value (vtable, cancel_handler_field, &load_value);
	if (load_value == NULL)
		return;

	klass = load_value->object.vtable->klass;
	method = mono_class_get_method_from_name (klass, "BeginInvoke", -1);
	g_assert (method != NULL);
	im = mono_get_delegate_invoke (method->klass);
	msg = mono_method_call_message_new (method, NULL, im, NULL, NULL);
	mono_thread_pool_add ((MonoObject *) load_value, msg, NULL, NULL);
}
Example #29
0
/**
 * mono_exception_from_name_domain:
 * @domain: Domain where the return object will be created.
 * @image: the Mono image where to look for the class
 * @name_space: the namespace for the class
 * @name: class name
 *
 * Creates an exception object of the given namespace/name class on
 * the given domain.
 *
 * Returns: the initialized exception instance.
 */
MonoException *
mono_exception_from_name_domain (MonoDomain *domain, MonoImage *image, 
				 const char* name_space, const char *name)
{
	MonoError error;
	MonoClass *klass;
	MonoObject *o;
	MonoDomain *caller_domain = mono_domain_get ();

	klass = mono_class_from_name (image, name_space, name);

	o = mono_object_new_checked (domain, klass, &error);
	g_assert (o != NULL && mono_error_ok (&error)); /* FIXME don't swallow the error */

	if (domain != caller_domain)
		mono_domain_set_internal (domain);
	mono_runtime_object_init (o);
	if (domain != caller_domain)
		mono_domain_set_internal (caller_domain);

	return (MonoException *)o;
}
Example #30
0
/**
 * mono_get_exception_reflection_type_load:
 * @types: an array of types that were defined in the moduled loaded.
 * @exceptions: an array of exceptions that were thrown during the type loading.
 *
 * Returns: a new instance of the System.Reflection.ReflectionTypeLoadException
 */
MonoException *
mono_get_exception_reflection_type_load (MonoArray *types, MonoArray *exceptions)
{
	MonoClass *klass;
	gpointer args [2];
	MonoObject *exc;
	MonoMethod *method;

	klass = mono_class_from_name (mono_get_corlib (), "System.Reflection", "ReflectionTypeLoadException");
	g_assert (klass);
	mono_class_init (klass);

	method = mono_class_get_method_from_name (klass, ".ctor", 2);
	g_assert (method);

	args [0] = types;
	args [1] = exceptions;

	exc = mono_object_new (mono_domain_get (), klass);
	mono_runtime_invoke (method, exc, args, NULL);

	return (MonoException *) exc;
}