+/**
+ * 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_file_not_found2:
+ * @msg: an informative message for the user.
+ * @fname: the name of the file not found.
+ *
+ * Returns: a new instance of the System.IO.FileNotFoundException
+ */
+MonoException *
+mono_get_exception_file_not_found2 (const char *msg, MonoString *fname)
+{
+ MonoString *s = msg ? mono_string_new (mono_domain_get (), msg) : NULL;
+
+ return mono_exception_from_name_two_strings (
+ mono_get_corlib (), "System.IO", "FileNotFoundException", s, fname);
+}
+
+/**
+ * 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;
+}
+
+/**
+ * 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_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_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_bad_image_format2:
+ * @msg: an informative message for the user.
+ * @fname: The full name of the file with the invalid image.
+ *
+ * Returns: a new instance of the System.BadImageFormatException
+ */
+MonoException *
+mono_get_exception_bad_image_format2 (const char *msg, MonoString *fname)
+{
+ MonoString *s = msg ? mono_string_new (mono_domain_get (), msg) : NULL;
+
+ return mono_exception_from_name_two_strings (
+ mono_get_corlib (), "System", "BadImageFormatException", s, fname);
+}
+
+/**
+ * mono_get_exception_stack_overflow:
+ *
+ * Returns: a new instance of the System.StackOverflowException
+ */
+MonoException *
+mono_get_exception_stack_overflow (void)
+{
+ return mono_exception_from_name (mono_get_corlib (), "System", "StackOverflowException");
+}
+
+/**
+ * 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_field_access:
+ *
+ * Returns: a new instance of the System.FieldAccessException
+ */
+MonoException *
+mono_get_exception_field_access (void)
+{
+ return mono_exception_from_name (mono_get_corlib (), "System", "FieldAccessException");
+}
+
+/**
+ * mono_get_exception_field_access2:
+ * @msg: an informative message for the user.
+ *
+ * Returns: a new instance of the System.FieldAccessException
+ */
+MonoException *
+mono_get_exception_field_access_msg (const char *msg)
+{
+ return mono_exception_from_name_msg (mono_get_corlib (), "System", "FieldAccessException", msg);
+}
+
+/**
+ * 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_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_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;
+}
+
+MonoException *
+mono_get_exception_runtime_wrapped (MonoObject *wrapped_exception)
+{
+ MonoRuntimeWrappedException *ex = (MonoRuntimeWrappedException*)
+ mono_exception_from_name (mono_get_corlib (), "System.Runtime.CompilerServices",
+ "RuntimeWrappedException");
+
+ MONO_OBJECT_SETREF (ex, wrapped_exception, wrapped_exception);
+ return (MonoException*)ex;
+}
+
+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);
+ messages = backtrace_symbols (mono_array_addr (arr, gpointer, 0), len);
+
+
+ for (i = 0; i < len; ++i) {
+ gpointer ip = mono_array_get (arr, gpointer, i);
+ MonoJitInfo *ji = mono_jit_info_table_find (mono_domain_get (), ip);
+ if (ji) {
+ char *msg = mono_debug_print_stack_frame (ji->method, (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]);
+ }
+ }
+
+ free (messages);
+ return g_string_free (text, FALSE);
+#else
+ return g_strdup ("");
+#endif
+}
+
+MonoString *
+ves_icall_Mono_Runtime_GetNativeStackTrace (MonoException *exc)
+{
+ char *trace;
+ MonoString *res;
+ if (!exc)
+ mono_raise_exception (mono_get_exception_argument_null ("exception"));
+
+ trace = mono_exception_get_native_backtrace (exc);
+ res = mono_string_new (mono_domain_get (), trace);
+ g_free (trace);
+ return res;
+}