/** * mono_get_exception_thread_state: * @msg: the message to present to the user * * Returns: a new instance of the `System.Threading.ThreadStateException` */ MonoException * mono_get_exception_thread_state (const char *msg) { return mono_exception_from_name_msg ( mono_get_corlib (), "System.Threading", "ThreadStateException", msg); }
/** * mono_get_exception_invalid_operation: * \param msg the message to pass to the user * \returns a new instance of the \c System.InvalidOperationException */ MonoException * mono_get_exception_invalid_operation (const char *msg) { return mono_exception_from_name_msg (mono_get_corlib (), "System", "InvalidOperationException", msg); }
/** * mono_get_exception_index_out_of_range: * \returns a new instance of the \c System.IndexOutOfRangeException */ MonoException * mono_get_exception_index_out_of_range () { return mono_exception_from_name (mono_get_corlib (), "System", "IndexOutOfRangeException"); }
/** * mono_get_exception_overflow: * \returns a new instance of the \c System.OverflowException */ MonoException * mono_get_exception_overflow (void) { return mono_exception_from_name (mono_get_corlib (), "System", "OverflowException"); }
/** * mono_get_exception_serialization: * \param msg the message to pass to the user * \returns a new instance of the \c System.Runtime.Serialization.SerializationException */ MonoException * mono_get_exception_serialization (const char *msg) { return mono_exception_from_name_msg (mono_get_corlib (), "System.Runtime.Serialization", "SerializationException", msg); }
/** * mono_get_exception_thread_abort: * \returns a new instance of the \c System.Threading.ThreadAbortException */ MonoException * mono_get_exception_thread_abort (void) { return mono_exception_from_name (mono_get_corlib (), "System.Threading", "ThreadAbortException"); }
/** * mono_get_exception_thread_interrupted: * \returns a new instance of the \c System.Threading.ThreadInterruptedException */ MonoException * mono_get_exception_thread_interrupted (void) { return mono_exception_from_name (mono_get_corlib (), "System.Threading", "ThreadInterruptedException"); }
/** * mono_get_exception_bad_image_format: * @msg: an informative message for the user. * * Returns: a new instance of the `System.BadImageFormatException` */ MonoException * mono_get_exception_bad_image_format (const char *msg) { return mono_exception_from_name_msg (mono_get_corlib (), "System", "BadImageFormatException", msg); }
/** * mono_get_exception_out_of_memory: * * Returns: a new instance of the `System.OutOfMemoryException` */ MonoException * mono_get_exception_out_of_memory (void) { return mono_exception_from_name (mono_get_corlib (), "System", "OutOfMemoryException"); }
/** * mono_get_exception_cannot_unload_appdomain: * @inner: the inner exception. * * Returns: a new instance of the `System.CannotUnloadAppDomainException` */ MonoException * mono_get_exception_cannot_unload_appdomain (const char *msg) { return mono_exception_from_name_msg (mono_get_corlib (), "System", "CannotUnloadAppDomainException", msg); }
/** * mono_get_exception_appdomain_unloaded * * Returns: a new instance of the `System.AppDomainUnloadedException` */ MonoException * mono_get_exception_appdomain_unloaded (void) { return mono_exception_from_name (mono_get_corlib (), "System", "AppDomainUnloadedException"); }
/** * mono_get_exception_synchronization_lock: * @inner: the inner exception. * * Returns: a new instance of the `System.SynchronizationLockException` */ MonoException * mono_get_exception_synchronization_lock (const char *msg) { return mono_exception_from_name_msg (mono_get_corlib (), "System.Threading", "SynchronizationLockException", msg); }
/** * mono_get_exception_file_not_found: * @fname: the name of the file not found. * * Returns: a new instance of the `System.IO.FileNotFoundException` */ MonoException * mono_get_exception_file_not_found (MonoString *fname) { return mono_exception_from_name_two_strings ( mono_get_corlib (), "System.IO", "FileNotFoundException", fname, fname); }
/** * mono_get_exception_io: * @msg: the message to present to the user * * Returns: a new instance of the `System.IO.IOException` */ MonoException * mono_get_exception_io (const char *msg) { return mono_exception_from_name_msg ( mono_get_corlib (), "System.IO", "IOException", msg); }
/** * mono_get_exception_security: * \returns a new instance of the \c System.Security.SecurityException */ MonoException * mono_get_exception_security (void) { return mono_exception_from_name (mono_get_corlib (), "System.Security", "SecurityException"); }
/** * mono_get_exception_method_access: * * Returns: a new instance of the `System.MethodAccessException` */ MonoException * mono_get_exception_method_access (void) { return mono_exception_from_name (mono_get_corlib (), "System", "MethodAccessException"); }
/** * mono_exception_new_thread_abort: * \returns a new instance of the \c System.Threading.ThreadAbortException */ MonoExceptionHandle mono_exception_new_thread_abort (MonoError *error) { return mono_exception_new_by_name (mono_get_corlib (), "System.Threading", "ThreadAbortException", error); }
/** * mono_get_exception_method_access2: * @msg: an informative message for the user. * * Returns: a new instance of the `System.MethodAccessException` */ MonoException * mono_get_exception_method_access_msg (const char *msg) { return mono_exception_from_name_msg (mono_get_corlib (), "System", "MethodAccessException", msg); }
/** * mono_exception_new_thread_interrupted: * \returns a new instance of the \c System.Threading.ThreadInterruptedException */ MonoExceptionHandle mono_exception_new_thread_interrupted (MonoError *error) { return mono_exception_new_by_name (mono_get_corlib (), "System.Threading", "ThreadInterruptedException", error); }
IMonoAssembly *CScriptSystem::GetCorlibAssembly() { return m_pRootDomain->TryGetAssembly(mono_get_corlib()); }
/** * mono_get_exception_arithmetic: * \returns a new instance of the \c System.ArithmeticException */ MonoException * mono_get_exception_arithmetic (void) { return mono_exception_from_name (mono_get_corlib (), "System", "ArithmeticException"); }
/*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 (mono_defaults.corlib, "System", "MissingMethodException", type_name, method_name); 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 (mono_defaults.corlib, "System", "MissingFieldException", type_name, field_name); 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) { 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 (mono_get_corlib (), "System", "TypeLoadException", type_name, assembly_name); 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 (mono_get_corlib (), "System.IO", "FileNotFoundException", msg, assembly_name); else exception = mono_exception_from_name_two_strings (mono_defaults.corlib, "System", "BadImageFormatException", msg, assembly_name); } 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_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_generic_error (error_out, "System", "ExecutionEngineException", "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; default: mono_error_set_generic_error (error_out, "System", "ExecutionEngineException", "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; }
/** * mono_get_exception_null_reference: * \returns a new instance of the \c System.NullReferenceException */ MonoException * mono_get_exception_null_reference (void) { return mono_exception_from_name (mono_get_corlib (), "System", "NullReferenceException"); }
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; }
/** * mono_get_exception_invalid_cast: * \returns a new instance of the \c System.InvalidCastException */ MonoException * mono_get_exception_invalid_cast () { return mono_exception_from_name (mono_get_corlib (), "System", "InvalidCastException"); }
/** * mono_mempool_alloc: * @pool: the momory pool to use * @size: size of the momory block * * Allocates a new block of memory in @pool. * * Returns: the address of a newly allocated memory block. */ gpointer mono_mempool_alloc (MonoMemPool *pool, guint size) { gpointer rval; size = (size + MEM_ALIGN - 1) & ~(MEM_ALIGN - 1); #ifdef MALLOC_ALLOCATION { Chunk *c = g_malloc (size); c->next = pool->chunks; pool->chunks = c; c->size = size - sizeof(Chunk); pool->allocated += size; rval = ((guint8*)c) + sizeof (Chunk); } #else rval = pool->pos; pool->pos = (guint8*)rval + size; #ifdef TRACE_ALLOCATIONS if (pool == mono_get_corlib ()->mempool) { mono_backtrace (size); } #endif if (G_UNLIKELY (pool->pos >= pool->end)) { pool->pos -= size; if (size >= 4096) { MonoMemPool *np = g_malloc (sizeof (MonoMemPool) + size); np->next = pool->next; pool->next = np; np->pos = (guint8*)np + sizeof (MonoMemPool); np->size = sizeof (MonoMemPool) + size; np->end = np->pos + np->size - sizeof (MonoMemPool); pool->d.allocated += sizeof (MonoMemPool) + size; total_bytes_allocated += sizeof (MonoMemPool) + size; return (guint8*)np + sizeof (MonoMemPool); } else { int new_size = get_next_size (pool, size); MonoMemPool *np = g_malloc (new_size); np->next = pool->next; pool->next = np; pool->pos = (guint8*)np + sizeof (MonoMemPool); np->pos = (guint8*)np + sizeof (MonoMemPool); np->size = new_size; np->end = np->pos; pool->end = pool->pos + new_size - sizeof (MonoMemPool); pool->d.allocated += new_size; total_bytes_allocated += new_size; rval = pool->pos; pool->pos += size; } } #endif return rval; }
MonoExceptionHandle mono_exception_new_invalid_operation (const char *msg, MonoError *error) { return mono_exception_new_by_name_msg (mono_get_corlib (), "System", "InvalidOperationException", msg, error); }
/** * mono_get_exception_divide_by_zero: * \returns a new instance of the \c System.DivideByZeroException */ MonoException * mono_get_exception_divide_by_zero (void) { return mono_exception_from_name (mono_get_corlib (), "System", "DivideByZeroException"); }
/** * mono_get_exception_array_type_mismatch: * \returns a new instance of the \c System.ArrayTypeMismatchException */ MonoException * mono_get_exception_array_type_mismatch (void) { return mono_exception_from_name (mono_get_corlib (), "System", "ArrayTypeMismatchException"); }
/** * mono_get_exception_not_supported: * @msg: the message to pass to the user * * Returns: a new instance of the `System.NotSupportedException` */ MonoException * mono_get_exception_not_supported (const char *msg) { return mono_exception_from_name_msg (mono_get_corlib (), "System", "NotSupportedException", msg); }