Beispiel #1
1
static void OutputExceptionDetails(MonoObject* exc)
{
	MonoClass* eclass = mono_object_get_class(exc);

	if (eclass)
	{
		MonoObject* toStringExc = nullptr;
		MonoString* msg = mono_object_to_string(exc, &toStringExc);

		MonoProperty* prop = mono_class_get_property_from_name(eclass, "StackTrace");
		MonoMethod* getter = mono_property_get_get_method(prop);
		MonoString* msg2 = (MonoString*)mono_runtime_invoke(getter, exc, NULL, NULL);

		if (toStringExc)
		{
			MonoProperty* prop = mono_class_get_property_from_name(eclass, "Message");
			MonoMethod* getter = mono_property_get_get_method(prop);
			msg = (MonoString*)mono_runtime_invoke(getter, exc, NULL, NULL);
		}

		GlobalError("Unhandled exception in Mono script environment: %s %s", mono_string_to_utf8(msg), mono_string_to_utf8(msg2));
	}
}
Beispiel #2
0
// Get string from a Mono exception 
char* PyNet_ExceptionToString(MonoObject *e) {
    MonoMethodDesc* mdesc = mono_method_desc_new(":ToString()", FALSE);
    MonoMethod* mmethod = mono_method_desc_search_in_class(mdesc, mono_get_object_class());
    mono_method_desc_free(mdesc);

    mmethod = mono_object_get_virtual_method(e, mmethod);
    MonoString* monoString = (MonoString*) mono_runtime_invoke(mmethod, e, NULL, NULL);
    mono_runtime_invoke(mmethod, e, NULL, NULL);
    return mono_string_to_utf8(monoString);
}
Beispiel #3
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 #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
/*
 * Ensure that the restrictions for partially trusted code are satisfied.
 *
 * @domain	The current application domain
 * @assembly	The assembly to query
 * return value: TRUE if the assembly is runnning at FullTrust, FALSE otherwise.
 */
static gboolean
mono_declsec_is_assembly_fulltrust (MonoDomain *domain, MonoAssembly *assembly)
{
	if (!MONO_SECMAN_FLAG_INIT (assembly->fulltrust)) {
		MonoReflectionAssembly *refass = (MonoReflectionAssembly*) mono_assembly_get_object (domain, assembly);
		MonoSecurityManager *secman = mono_security_manager_get_methods ();

		if (secman && refass) {
			MonoObject *res;
			gpointer args [1];
			args [0] = refass;

			res = mono_runtime_invoke (secman->linkdemandfulltrust, NULL, args, NULL);
			if (*(MonoBoolean *) mono_object_unbox(res)) {
				/* keep this value cached as it will be used very often */
				MONO_SECMAN_FLAG_SET_VALUE (assembly->fulltrust, TRUE);
				return TRUE;
			}
		}

		MONO_SECMAN_FLAG_SET_VALUE (assembly->fulltrust, FALSE);
		return FALSE;
	}

	return MONO_SECMAN_FLAG_GET_VALUE (assembly->fulltrust);
}
JNIEXPORT void JNICALL Java_com_koushikdutta_monojavabridge_MonoBridge_loadAssembly
    (JNIEnv *env, jclass clazz, jstring assembly)
{
    void *args[1];
    args[0] = &assembly;
    mono_runtime_invoke(g_LoadAssembly, NULL, args, NULL);
}
Beispiel #7
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;
}
Beispiel #8
0
result_t MonoCreateObjectInstance(const guid_t& guid, const guid_t& iid, void** objectRef)
{
	MonoEnsureThreadAttached();

	MonoObject* exc = nullptr;

	guid_t lguid = guid;
	guid_t liid = iid;

	void* args[2];
	args[0] = &lguid;
	args[1] = &liid;

	auto retval = mono_runtime_invoke(g_createObjectMethod, nullptr, args, &exc);

	if (exc)
	{
        return FX_E_NOINTERFACE;
	}

	*objectRef = *(void**)(mono_object_unbox(retval));

    if (!*objectRef)
    {
        return FX_E_NOINTERFACE;
    }

	return FX_S_OK;
}
Beispiel #9
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 #10
0
	MonoObject* MonoMethod::invoke(MonoObject* instance, void** params)
	{
		MonoObject* exception = nullptr;
		MonoObject* retVal = mono_runtime_invoke(mMethod, instance, params, &exception);

		MonoUtil::throwIfException(exception);
		return retVal;
	}		
Beispiel #11
0
/* Returns the exception thrown when invoking, if any */
static MonoObject *
mono_async_invoke (ThreadPool *tp, MonoAsyncResult *ares)
{
	ASyncCall *ac = (ASyncCall *)ares->object_data;
	MonoObject *res, *exc = NULL;
	MonoArray *out_args = NULL;
	HANDLE wait_event = NULL;

	if (ares->execution_context) {
		/* use captured ExecutionContext (if available) */
		MONO_OBJECT_SETREF (ares, original_context, mono_thread_get_execution_context ());
		mono_thread_set_execution_context (ares->execution_context);
	} else {
		ares->original_context = NULL;
	}

	if (ac == NULL) {
		/* Fast path from ThreadPool.*QueueUserWorkItem */
		void *pa = ares->async_state;
		mono_runtime_delegate_invoke (ares->async_delegate, &pa, &exc);
	} else {
		MonoObject *cb_exc = NULL;

		ac->msg->exc = NULL;
		res = mono_message_invoke (ares->async_delegate, ac->msg, &exc, &out_args);
		MONO_OBJECT_SETREF (ac, res, res);
		MONO_OBJECT_SETREF (ac, msg->exc, exc);
		MONO_OBJECT_SETREF (ac, out_args, out_args);

		mono_monitor_enter ((MonoObject *) ares);
		ares->completed = 1;
		if (ares->handle != NULL)
			wait_event = mono_wait_handle_get_handle ((MonoWaitHandle *) ares->handle);
		mono_monitor_exit ((MonoObject *) ares);
		/* notify listeners */
		if (wait_event != NULL)
			SetEvent (wait_event);

		/* call async callback if cb_method != null*/
		if (ac != NULL && ac->cb_method) {
			void *pa = &ares;
			cb_exc = NULL;
			mono_runtime_invoke (ac->cb_method, ac->cb_target, pa, &cb_exc);
			MONO_OBJECT_SETREF (ac->msg, exc, cb_exc);
			exc = cb_exc;
		} else {
			exc = NULL;
		}
	}

	/* restore original thread execution context if flow isn't suppressed, i.e. non null */
	if (ares->original_context) {
		mono_thread_set_execution_context (ares->original_context);
		ares->original_context = NULL;
	}
	return exc;
}
JNIEXPORT void JNICALL Java_com_koushikdutta_monojavabridge_MonoBridge_link
    (JNIEnv *env, jclass clazz, jclass cls, jstring methodName, jstring methodSignature, jstring methodParameters)
{
    void *args[4];
    args[0] = &cls;
    args[1] = &methodName;
    args[2] = &methodSignature;
    args[3] = &methodParameters;
    mono_runtime_invoke(g_Link, NULL, args, NULL);
}
Beispiel #13
0
void DOMBase::SetNextWrapper(MonoObject* next)
{	
	if (_setNextWrapperMethod == NULL)
		FindSetNextWrapper();
	
	void *args[2];
	args[0] = GetJSWrapper();
	args[1] = next;
	mono_runtime_invoke(_setNextWrapperMethod, NULL, args, NULL);
}
Beispiel #14
0
void DOMBase::SetPrevWrapper(MonoObject* prev)
{
	if (_setPrevWrapperMethod == NULL)
		FindSetPrevWrapper();
	
	void *args[2];
	args[0] = GetJSWrapper();
	args[1] = prev;
	mono_runtime_invoke(_setPrevWrapperMethod, NULL, args, NULL);
}
Beispiel #15
0
	MonoObject* MonoMethod::invokeVirtual(MonoObject* instance, void** params)
	{
		::MonoMethod* virtualMethod = mono_object_get_virtual_method(instance, mMethod);

		MonoObject* exception = nullptr;
		MonoObject* retVal = mono_runtime_invoke(virtualMethod, instance, params, &exception);

		MonoUtil::throwIfException(exception);
		return retVal;
	}		
Beispiel #16
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 #17
0
void JniManager::toProcessRequest(jobject obj, MonoObject* processRequest)
{
    JNIEnv* env = getEnv();

    MonoDomain* monoDomain = getMonoDomain();

    string c_assemblyName = typeConverter->convertToC<string>(env, env->CallObjectMethod(obj, getAssemblyName, "()Ljava/lang/String;"));
    string c_assemblyPath = typeConverter->convertToC<string>(env, env->CallObjectMethod(obj, getAssemblyPath, "()Ljava/lang/String;"));
    string c_methodName = typeConverter->convertToC<string>(env, env->CallObjectMethod(obj, getMethodName, "()Ljava/lang/String;"));

    MonoString* assemblyName = mono_string_new(monoDomain, c_assemblyName.c_str());
    MonoString* assemblyPath = mono_string_new(monoDomain, c_assemblyPath.c_str());
    MonoString* methodName = mono_string_new(monoDomain, c_methodName.c_str());
    bool fullTrust = env->CallBooleanMethod(obj, getFullTrust);
    bool isSingleton = env->CallBooleanMethod(obj, getIsSingleton);
    bool log = env->CallBooleanMethod(obj, getLog);
    bool notifyEvents = env->CallBooleanMethod(obj, getNotifyEvents);

    MonoObject* exception = NULL;

    void* args[1];
    args[0] = assemblyName;
    mono_runtime_invoke(setAssemblyNameField, processRequest, args, &exception);

    args[0] = assemblyPath;
    mono_runtime_invoke(setAssemblyPathField, processRequest, args, &exception);

    args[0] = methodName;
    mono_runtime_invoke(setMethodNameField, processRequest, args, &exception);

    args[0] = &fullTrust;
    mono_runtime_invoke(setFullTrustField, processRequest, args, &exception);

    args[0] = &log;
    mono_runtime_invoke(setLogField, processRequest, args, &exception);

    args[0] = &isSingleton;
    mono_runtime_invoke(setIsSingletonField, processRequest, args, &exception);

    args[0] = &notifyEvents;
    mono_runtime_invoke(setNotifyEventsField, processRequest, args, &exception);

    if (exception)
    {
        const char* message = mono_string_to_utf8(mono_object_to_string(exception, NULL));
        throwException(message);
    }

    jobject javaMethodArguments = env->CallObjectMethod(obj, getMethodArguments);

    setProperties(env, javaMethodArguments, addMethodArgumentsProperty, processRequest);
    //request->MethodArguments = typeConverter->convertToC<Dictionary<String^, Object^>^>(env, env->CallObjectMethod(obj, getMethodArguments));
    //request->InboundProperties = typeConverter->convertToC<Dictionary<String^, Object^>^>(env, env->CallObjectMethod(obj, getInboundProperties));
    //request->InvocationProperties = typeConverter->convertToC<Dictionary<String^, Object^>^>(env, env->CallObjectMethod(obj, getInvocationProperties));
    //request->OutboundProperties = typeConverter->convertToC<Dictionary<String^, Object^>^>(env, env->CallObjectMethod(obj, getOutboundProperties));
    //request->SessionProperties = typeConverter->convertToC<Dictionary<String^, Object^>^>(env, env->CallObjectMethod(obj, getSessionProperties));
}
Beispiel #18
0
MonoObject* ml_invoke(MonoMethod *method, void *obj, void **params)
{
	MonoObject *ret, *exception;

	ret = mono_runtime_invoke(method, obj, params, &exception);
	if (exception) {
		purple_debug(PURPLE_DEBUG_ERROR, "mono", "caught exception: %s\n", mono_class_get_name(mono_object_get_class(exception)));
	}

	return ret;
}
Beispiel #19
0
void Application::FireOnReload()
{
	for (auto& obj : instances) {
		auto klass = mono_object_get_class(obj);
		if (klass) {
			auto method = find_method(klass, "OnReload");
			if (method)
				mono_runtime_invoke(method, obj, NULL, NULL);
		}
	}
}
Beispiel #20
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 #21
0
mono::object CScriptMethod::Invoke(mono::object object, void **pParams, int numParams)
{
	MonoObject *pException = nullptr;
	MonoObject *pResult = mono_runtime_invoke(m_pMonoMethod, object, pParams, &pException);

	if(pException)
		CScriptObject::HandleException(pException);
	else if(pResult)
		return (mono::object)pResult;

	return nullptr;
}
Beispiel #22
0
MonoObject* NodejsFunc::GetFunc()
{
    static MonoMethod* method;

    if (!method)
        method = mono_class_get_method_from_name(GetNodejsFuncClass(), "GetFunc", -1);

    MonoException* exc = NULL;
    MonoObject* func = mono_runtime_invoke(method, mono_gchandle_get_target(_this), NULL, (MonoObject**)&exc);

    return func;
}
Beispiel #23
0
MonoString* MonoEmbedding::TryConvertPrimitiveOrDecimal(MonoObject* obj, MonoException** exc)
{
    static MonoMethod* method;
    *exc = NULL;

    if (!method)
        method = mono_class_get_method_from_name(MonoEmbedding::GetClass(), "TryConvertPrimitiveOrDecimal", -1);

    void* args[] = { obj };

    return (MonoString*)mono_runtime_invoke(method, NULL, args, (MonoObject**)exc);
}
Beispiel #24
0
MonoString* MonoEmbedding::ToString(MonoObject* o, MonoException** exc)
{
    static MonoMethod* method;
    *exc = NULL;

    if (!method)
        method = mono_class_get_method_from_name(MonoEmbedding::GetClass(), "ObjectToString", -1);

    void* args[] = { o };

    return (MonoString*)mono_runtime_invoke(method, NULL, args, (MonoObject**)exc);
}
Beispiel #25
0
MonoClass* MonoEmbedding::GetFuncClass()
{
    static MonoMethod* method;
    MonoException* exc = NULL;

    if (!method)
        method = mono_class_get_method_from_name(MonoEmbedding::GetClass(), "GetFuncType", -1);

    MonoReflectionType* typeObject = (MonoReflectionType*)mono_runtime_invoke(method, NULL, NULL, (MonoObject**)&exc);
    MonoType* type = mono_reflection_type_get_type(typeObject);
    MonoClass* klass = mono_class_from_mono_type(type);
    return klass;
}
Beispiel #26
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);
   }
}
Beispiel #27
0
MonoObject* MonoEmbedding::CreateExpandoObject()
{
    static MonoMethod* method;
    MonoException* exc = NULL;

    if (!method)
    {
        method = mono_class_get_method_from_name(MonoEmbedding::GetClass(), "CreateExpandoObject", -1);
    }
    MonoObject* dictionary = mono_runtime_invoke(method, NULL, NULL, (MonoObject**)&exc);

    return dictionary;
}
Beispiel #28
0
void MonoEmbedding::ContinueTask(MonoObject* task, MonoObject* state, MonoException** exc)
{
    static MonoMethod* method;
    *exc = NULL;

    if (!method)
        method = mono_class_get_method_from_name(MonoEmbedding::GetClass(), "ContinueTask", -1);

    void* args[2];
    args[0] = task;
    args[1] = state;
    mono_runtime_invoke(method, NULL, args, (MonoObject**)exc);
}
Beispiel #29
0
void JniManager::setProperties(JNIEnv* env, jobject map, MonoMethod* method, MonoObject* instance)
{
    assert(env);

    MonoDomain* monoDomain = getMonoDomain();

    if (map == NULL)
    {
        return;
    }

    int mapSize = env->CallIntMethod(map, typeConverter->size);

    jobject keys = env->CallObjectMethod(map, typeConverter->keySet);

    jobjectArray arrayOfKeys = (jobjectArray)env->CallObjectMethod(keys, typeConverter->toArray);

    for (int i = 0; i < mapSize; i++)
    {
        jstring javaKeyName = (jstring)env->GetObjectArrayElement(arrayOfKeys, i);
        string keyName = typeConverter->convertToC<string>(env, javaKeyName);
        jobject mapValue = env->CallObjectMethod(map, typeConverter->getMapValue, javaKeyName);

        //if (env->IsInstanceOf(mapValue, typeConverter->mapClazz))
        //{

        //}

        MonoObject* exc = NULL;
        void* args[2];
        args[0] = mono_string_new(monoDomain, keyName.c_str());
        args[1] = toMonoObject(env, mapValue);

        mono_runtime_invoke(method, instance, args, &exc);

        if (exc)
        {
            const char* message = mono_string_to_utf8(mono_object_to_string(exc, NULL));
            throwException(message);
            return;
        }


        env->DeleteLocalRef(javaKeyName);
        env->DeleteLocalRef(mapValue);
    }

    env->DeleteLocalRef(keys);
    env->DeleteLocalRef(arrayOfKeys);
    env->DeleteLocalRef(map);
}
Beispiel #30
0
void
mono_threadpool_ms_enqueue_work_item (MonoDomain *domain, MonoObject *work_item)
{
	static MonoClass *threadpool_class = NULL;
	static MonoMethod *unsafe_queue_custom_work_item_method = NULL;
	MonoDomain *current_domain;
	MonoBoolean f;
	gpointer args [2];

	g_assert (work_item);

	if (!threadpool_class)
		threadpool_class = mono_class_from_name (mono_defaults.corlib, "System.Threading", "ThreadPool");
	g_assert (threadpool_class);

	if (!unsafe_queue_custom_work_item_method)
		unsafe_queue_custom_work_item_method = mono_class_get_method_from_name (threadpool_class, "UnsafeQueueCustomWorkItem", 2);
	g_assert (unsafe_queue_custom_work_item_method);

	f = FALSE;

	args [0] = (gpointer) work_item;
	args [1] = (gpointer) mono_value_box (domain, mono_defaults.boolean_class, &f);

	current_domain = mono_domain_get ();
	if (current_domain == domain) {
		mono_runtime_invoke (unsafe_queue_custom_work_item_method, NULL, args, NULL);
	} else {
		mono_thread_push_appdomain_ref (domain);
		if (mono_domain_set (domain, FALSE)) {
			mono_runtime_invoke (unsafe_queue_custom_work_item_method, NULL, args, NULL);
			mono_domain_set (current_domain, TRUE);
		}
		mono_thread_pop_appdomain_ref ();
	}
}