static MonoClass* get_class (MonoErrorInternal *error) { MonoClass *klass = NULL; if (is_managed_exception (error)) klass = mono_object_class (mono_gchandle_get_target (error->exn.instance_handle)); else klass = error->exn.klass; return klass; }
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; }
void ClrFuncInvokeContext::InitializeAsyncOperation() { // Create a uv_edge_async instance representing V8 async operation that will complete // when the CLR function completes. The ClrActionContext is used to ensure the ClrFuncInvokeContext // remains GC-rooted while the CLR function executes. static MonoMethod* getAction = NULL; if (!getAction) getAction = mono_class_get_method_from_name( GetClrFuncInvokeContextClass(), "GetCompleteOnV8ThreadAsynchronousAction", -1); ClrActionContext* data = new ClrActionContext; data->action = mono_gchandle_new( // released in ClrActionContext::ActionCallback mono_runtime_invoke(getAction, mono_gchandle_get_target(this->_this), NULL, NULL), FALSE); this->uv_edge_async = V8SynchronizationContext::RegisterAction(ClrActionContext::ActionCallback, data); }
MonoObject* DOMBase::GetJSWrapper() { if (_JSWrapperWPtr != 0) { //printf ("%s:%d %s() Mono calling C code\n", __FILE__, __LINE__, __FUNCTION__); MonoObject* domwrapper = mono_gchandle_get_target(_JSWrapperWPtr); if (!domwrapper) FatalError("Cannot find the JS Wrapper object through the weak refrence"); return domwrapper; } else { //printf ("%s:%d %s() Mono calling C code\n", __FILE__, __LINE__, __FUNCTION__); MonoObject* wrapperObject = MakeWrapper(this, GetMakeWrapperIndex()); _JSWrapperWPtr = mono_gchandle_new_weakref(wrapperObject, false); return wrapperObject; } }
gpointer ves_icall_System_GCHandle_GetAddrOfPinnedObject (guint32 handle) { MonoObject *obj; if (mono_gchandle_get_type (handle) != HANDLE_PINNED) return (gpointer)-2; obj = mono_gchandle_get_target (handle); if (obj) { MonoClass *klass = mono_object_class (obj); if (klass == mono_defaults.string_class) { return mono_string_chars ((MonoString*)obj); } else if (klass->rank) { return mono_array_addr ((MonoArray*)obj, char, 0); } else { /* the C# code will check and throw the exception */ /* FIXME: missing !klass->blittable test, see bug #61134 */ if ((klass->flags & TYPE_ATTRIBUTE_LAYOUT_MASK) == TYPE_ATTRIBUTE_AUTO_LAYOUT) return (gpointer)-1; return (char*)obj + sizeof (MonoObject); } }
/*Can fail with out-of-memory*/ MonoException* mono_error_prepare_exception (MonoError *oerror, MonoError *error_out) { MonoErrorInternal *error = (MonoErrorInternal*)oerror; MonoException* exception = NULL; MonoString *assembly_name = NULL, *type_name = NULL, *method_name = NULL, *field_name = NULL, *msg = NULL; MonoDomain *domain = mono_domain_get (); mono_error_init (error_out); switch (error->error_code) { case MONO_ERROR_NONE: return NULL; case MONO_ERROR_MISSING_METHOD: if ((error->type_name || error->exn.klass) && error->member_name) { type_name = get_type_name_as_mono_string (error, domain, error_out); if (!mono_error_ok (error_out)) break; method_name = mono_string_new (domain, error->member_name); if (!method_name) { mono_error_set_out_of_memory (error_out, "Could not allocate method name"); break; } exception = mono_exception_from_name_two_strings_checked (mono_defaults.corlib, "System", "MissingMethodException", type_name, method_name, error_out); if (exception) set_message_on_exception (exception, error, error_out); } else { exception = mono_exception_from_name_msg (mono_defaults.corlib, "System", "MissingMethodException", error->full_message); } break; case MONO_ERROR_MISSING_FIELD: if ((error->type_name || error->exn.klass) && error->member_name) { type_name = get_type_name_as_mono_string (error, domain, error_out); if (!mono_error_ok (error_out)) break; field_name = mono_string_new (domain, error->member_name); if (!field_name) { mono_error_set_out_of_memory (error_out, "Could not allocate field name"); break; } exception = mono_exception_from_name_two_strings_checked (mono_defaults.corlib, "System", "MissingFieldException", type_name, field_name, error_out); if (exception) set_message_on_exception (exception, error, error_out); } else { exception = mono_exception_from_name_msg (mono_defaults.corlib, "System", "MissingFieldException", error->full_message); } break; case MONO_ERROR_TYPE_LOAD: if ((error->type_name && error->assembly_name) || error->exn.klass) { type_name = get_type_name_as_mono_string (error, domain, error_out); if (!mono_error_ok (error_out)) break; if (error->assembly_name) { assembly_name = mono_string_new (domain, error->assembly_name); if (!assembly_name) { mono_error_set_out_of_memory (error_out, "Could not allocate assembly name"); break; } } exception = mono_exception_from_name_two_strings_checked (mono_get_corlib (), "System", "TypeLoadException", type_name, assembly_name, error_out); if (exception) set_message_on_exception (exception, error, error_out); } else { exception = mono_exception_from_name_msg (mono_defaults.corlib, "System", "TypeLoadException", error->full_message); } break; case MONO_ERROR_FILE_NOT_FOUND: case MONO_ERROR_BAD_IMAGE: if (error->assembly_name) { msg = mono_string_new (domain, error->full_message); if (!msg) { mono_error_set_out_of_memory (error_out, "Could not allocate message"); break; } if (error->assembly_name) { assembly_name = mono_string_new (domain, error->assembly_name); if (!assembly_name) { mono_error_set_out_of_memory (error_out, "Could not allocate assembly name"); break; } } if (error->error_code == MONO_ERROR_FILE_NOT_FOUND) exception = mono_exception_from_name_two_strings_checked (mono_get_corlib (), "System.IO", "FileNotFoundException", msg, assembly_name, error_out); else exception = mono_exception_from_name_two_strings_checked (mono_defaults.corlib, "System", "BadImageFormatException", msg, assembly_name, error_out); } else { if (error->error_code == MONO_ERROR_FILE_NOT_FOUND) exception = mono_exception_from_name_msg (mono_get_corlib (), "System.IO", "FileNotFoundException", error->full_message); else exception = mono_exception_from_name_msg (mono_defaults.corlib, "System", "BadImageFormatException", error->full_message); } break; case MONO_ERROR_OUT_OF_MEMORY: exception = mono_get_exception_out_of_memory (); break; case MONO_ERROR_ARGUMENT: exception = mono_get_exception_argument (error->first_argument, error->full_message); break; case MONO_ERROR_ARGUMENT_NULL: exception = mono_get_exception_argument_null (error->first_argument); break; case MONO_ERROR_NOT_VERIFIABLE: { char *type_name = NULL, *message; if (error->exn.klass) { type_name = mono_type_get_full_name (error->exn.klass); if (!type_name) { mono_error_set_out_of_memory (error_out, "Could not allocate message"); break; } } message = g_strdup_printf ("Error in %s:%s %s", type_name, error->member_name, error->full_message); if (!message) { g_free (type_name); mono_error_set_out_of_memory (error_out, "Could not allocate message"); break; } exception = mono_exception_from_name_msg (mono_defaults.corlib, "System.Security", "VerificationException", message); g_free (message); g_free (type_name); break; } case MONO_ERROR_GENERIC: if (!error->exception_name_space || !error->exception_name) mono_error_set_execution_engine (error_out, "MonoError with generic error but no exception name was supplied"); else exception = mono_exception_from_name_msg (mono_defaults.corlib, error->exception_name_space, error->exception_name, error->full_message); break; case MONO_ERROR_EXCEPTION_INSTANCE: exception = (MonoException*) mono_gchandle_get_target (error->exn.instance_handle); break; case MONO_ERROR_CLEANUP_CALLED_SENTINEL: mono_error_set_execution_engine (error_out, "MonoError reused after mono_error_cleanup"); break; case MONO_ERROR_INVALID_PROGRAM: { gboolean lacks_message = error->flags & MONO_ERROR_INCOMPLETE; if (lacks_message) return mono_exception_from_name_msg (mono_defaults.corlib, "System", "InvalidProgramException", ""); else return mono_exception_from_name_msg (mono_defaults.corlib, "System", "InvalidProgramException", error->full_message); } default: mono_error_set_execution_engine (error_out, "Invalid error-code %d", error->error_code); } if (!mono_error_ok (error_out)) return NULL; if (!exception) mono_error_set_out_of_memory (error_out, "Could not allocate exception object"); return exception; }
MonoObject * ves_icall_System_GCHandle_GetTarget (guint32 handle) { return mono_gchandle_get_target (handle); }
MonoObjectHandle mono_gchandle_get_target_handle (uint32_t gchandle) { return MONO_HANDLE_NEW (MonoObject, mono_gchandle_get_target (gchandle)); }
MonoObject* ClrFuncInvokeContext::GetMonoObject() { return mono_gchandle_get_target(_this); }