void NodejsFunc::ExecuteActionOnV8Thread(MonoObject* action) { ClrActionContext* data = new ClrActionContext; data->action = mono_gchandle_new(action, FALSE); // released in ClrActionContext::ActionCallback uv_edge_async_t* uv_edge_async = V8SynchronizationContext::RegisterAction(ClrActionContext::ActionCallback, data); V8SynchronizationContext::ExecuteAction(uv_edge_async); }
ClrFuncInvokeContext::ClrFuncInvokeContext(v8::Local<v8::Value> callbackOrSync) : _this(0), callback(0), uv_edge_async(0) { static MonoClassField* field; static MonoClassField* syncField; if (!field) field = mono_class_get_field_from_name(GetClrFuncInvokeContextClass(), "native"); if (!syncField) syncField = mono_class_get_field_from_name(GetClrFuncInvokeContextClass(), "Sync"); MonoObject* obj = mono_object_new(mono_domain_get(), GetClrFuncInvokeContextClass()); ClrFuncInvokeContext* thisPointer = this; mono_field_set_value(obj, field, &thisPointer); this->_this = mono_gchandle_new(obj, FALSE); // released in destructor DBG("ClrFuncInvokeContext::ClrFuncInvokeContext"); if (callbackOrSync->IsFunction()) { // released in destructor this->callback = new Nan::Callback(v8::Local<v8::Function>::Cast(callbackOrSync)); this->Sync(FALSE); } else { this->Sync(callbackOrSync->BooleanValue()); } }
void mono_error_set_exception_instance (MonoError *oerror, MonoException *exc) { MonoErrorInternal *error = (MonoErrorInternal*)oerror; mono_error_prepare (error); error->error_code = MONO_ERROR_EXCEPTION_INSTANCE; error->exn.instance_handle = mono_gchandle_new (exc ? &exc->object : NULL, FALSE); }
/* * if type == -1, change the target of the handle, otherwise allocate a new handle. */ guint32 ves_icall_System_GCHandle_GetTargetHandle (MonoObject *obj, guint32 handle, gint32 type) { if (type == -1) { mono_gchandle_set_target (handle, obj); /* the handle doesn't change */ return handle; } switch (type) { case HANDLE_WEAK: return mono_gchandle_new_weakref (obj, FALSE); case HANDLE_WEAK_TRACK: return mono_gchandle_new_weakref (obj, TRUE); case HANDLE_NORMAL: return mono_gchandle_new (obj, FALSE); case HANDLE_PINNED: return mono_gchandle_new (obj, TRUE); default: g_assert_not_reached (); } return 0; }
uint32_t mono_gchandle_from_handle (MonoObjectHandle handle, mono_bool pinned) { /* FIXME: chunk_element_to_chunk_idx does a linear search through the * chunks and we only need it for the assert */ MonoThreadInfo *info = mono_thread_info_current (); HandleStack *stack = (HandleStack*) info->handle_stack; HandleChunkElem* elem = handle_to_chunk_element (handle); int elem_idx = 0; HandleChunk *chunk = chunk_element_to_chunk_idx (stack, elem, &elem_idx); /* gchandles cannot deal with interior pointers */ g_assert (chunk != NULL); return mono_gchandle_new (MONO_HANDLE_RAW (handle), pinned); }
CDynScriptArray::CDynScriptArray(MonoDomain *pDomain, IMonoClass *pContainingType, int size) { CRY_ASSERT(size >= 0); CRY_ASSERT(pDomain); m_lastIndex = -1; m_pElementClass = (pContainingType ? (MonoClass *)(pContainingType)->GetManagedObject() : m_pDefaultElementClass); CRY_ASSERT(m_pElementClass); m_pObject = (MonoObject *)mono_array_new(pDomain, m_pElementClass, size); m_objectHandle = mono_gchandle_new(m_pObject, false); m_pClass = NULL; }
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); }
char * mono_exception_get_native_backtrace (MonoException *exc) { #ifdef HAVE_BACKTRACE_SYMBOLS MonoDomain *domain; MonoArray *arr = exc->native_trace_ips; int i, len; GString *text; char **messages; if (!arr) return g_strdup (""); domain = mono_domain_get (); len = mono_array_length (arr); text = g_string_new_len (NULL, len * 20); uint32_t gchandle = mono_gchandle_new (&arr->obj, TRUE); /* pinned */ void* addr = mono_array_addr (arr, gpointer, 0); MONO_ENTER_GC_SAFE; messages = backtrace_symbols (addr, len); MONO_EXIT_GC_SAFE; mono_gchandle_free (gchandle); for (i = 0; i < len; ++i) { gpointer ip = mono_array_get (arr, gpointer, i); MonoJitInfo *ji = mono_jit_info_table_find (mono_domain_get (), (char *)ip); if (ji) { char *msg = mono_debug_print_stack_frame (mono_jit_info_get_method (ji), (char*)ip - (char*)ji->code_start, domain); g_string_append_printf (text, "%s\n", msg); g_free (msg); } else { g_string_append_printf (text, "%s\n", messages [i]); } } g_free (messages); return g_string_free (text, FALSE); #else return g_strdup (""); #endif }
uint32_t mono_gchandle_from_handle (MonoObjectHandle handle, mono_bool pinned) { return mono_gchandle_new (MONO_HANDLE_RAW(handle), pinned); }