static inline void print_report (const gchar *format, ...) { MonoError error; MonoClass *klass; MonoProperty *prop; MonoString *str; char *stack_trace; va_list ap; fprintf (stdout, "-=-=-=-=-=-=- MONO_IOMAP REPORT -=-=-=-=-=-=-\n"); va_start (ap, format); vfprintf (stdout, format, ap); fprintf (stdout, "\n"); va_end (ap); klass = mono_class_load_from_name (mono_get_corlib (), "System", "Environment"); mono_class_init (klass); prop = mono_class_get_property_from_name (klass, "StackTrace"); str = (MonoString*)mono_property_get_value_checked (prop, NULL, NULL, &error); mono_error_assert_ok (&error); stack_trace = mono_string_to_utf8_checked (str, &error); mono_error_assert_ok (&error); fprintf (stdout, "-= Stack Trace =-\n%s\n\n", stack_trace); g_free (stack_trace); fflush (stdout); }
/* this is an icall */ void * mono_mmap_open_handle (void *input_fd, MonoString *mapName, gint64 *capacity, int access, int options, int *ioerror) { MonoError error; MmapHandle *handle; if (!mapName) { handle = (MmapHandle *)open_file_map (NULL, GPOINTER_TO_INT (input_fd), FILE_MODE_OPEN, capacity, access, options, ioerror); } else { char *c_mapName = mono_string_to_utf8_checked (mapName, &error); if (mono_error_set_pending_exception (&error)) return NULL; named_regions_lock (); handle = (MmapHandle*)g_hash_table_lookup (named_regions, c_mapName); if (handle) { *ioerror = FILE_ALREADY_EXISTS; handle = NULL; } else { //XXX we're exploiting wapi HANDLE == FD equivalence. THIS IS FRAGILE, create a _wapi_handle_to_fd call handle = (MmapHandle *)open_file_map (NULL, GPOINTER_TO_INT (input_fd), FILE_MODE_OPEN, capacity, access, options, ioerror); handle->name = g_strdup (c_mapName); g_hash_table_insert (named_regions, handle->name, handle); } named_regions_unlock (); g_free (c_mapName); } return handle; }
MonoBoolean ves_icall_System_Globalization_CultureInfo_construct_internal_locale_from_name (MonoCultureInfo *this_obj, MonoString *name) { MonoError error; const CultureInfoNameEntry *ne; char *n; n = mono_string_to_utf8_checked (name, &error); if (mono_error_set_pending_exception (&error)) return FALSE; ne = (const CultureInfoNameEntry *)mono_binary_search (n, culture_name_entries, NUM_CULTURE_ENTRIES, sizeof (CultureInfoNameEntry), culture_name_locator); if (ne == NULL) { /*g_print ("ne (%s) is null\n", n);*/ g_free (n); return FALSE; } g_free (n); if (!construct_culture (this_obj, &culture_entries [ne->culture_entry_index], &error)) { mono_error_set_pending_exception (&error); return FALSE; } return TRUE; }
gboolean mono_process_get_shell_arguments (MonoProcessStartInfo *proc_start_info, gunichar2 **shell_path, MonoString **cmd) { gchar *spath = NULL; gchar *new_cmd, *cmd_utf8; MonoError mono_error; *shell_path = NULL; *cmd = proc_start_info->arguments; mono_process_complete_path (mono_string_chars (proc_start_info->filename), &spath); if (spath != NULL) { /* Seems like our CreateProcess does not work as the windows one. * This hack is needed to deal with paths containing spaces */ if (*cmd) { cmd_utf8 = mono_string_to_utf8_checked (*cmd, &mono_error); if (!mono_error_set_pending_exception (&mono_error)) { new_cmd = g_strdup_printf ("%s %s", spath, cmd_utf8); *cmd = mono_string_new_wrapper (new_cmd); g_free (cmd_utf8); g_free (new_cmd); } else { *cmd = NULL; } } else { *cmd = mono_string_new_wrapper (spath); } g_free (spath); } return (*cmd != NULL) ? TRUE : FALSE; }
/* This is an icall */ void * mono_mmap_open_file (MonoString *path, int mode, MonoString *mapName, gint64 *capacity, int access, int options, int *ioerror) { MonoError error; MmapHandle *handle = NULL; g_assert (path || mapName); if (!mapName) { char * c_path = mono_string_to_utf8_checked (path, &error); if (mono_error_set_pending_exception (&error)) return NULL; handle = open_file_map (c_path, -1, mode, capacity, access, options, ioerror); g_free (c_path); return handle; } char *c_mapName = mono_string_to_utf8_checked (mapName, &error); if (mono_error_set_pending_exception (&error)) return NULL; if (path) { named_regions_lock (); handle = (MmapHandle*)g_hash_table_lookup (named_regions, c_mapName); if (handle) { *ioerror = FILE_ALREADY_EXISTS; handle = NULL; } else { char *c_path = mono_string_to_utf8_checked (path, &error); if (is_ok (&error)) { handle = (MmapHandle *)open_file_map (c_path, -1, mode, capacity, access, options, ioerror); if (handle) { handle->name = g_strdup (c_mapName); g_hash_table_insert (named_regions, handle->name, handle); } } else { handle = NULL; } g_free (c_path); } named_regions_unlock (); } else handle = open_memory_map (c_mapName, mode, capacity, access, options, ioerror); g_free (c_mapName); return handle; }
guint32 mono_dynstream_insert_mstring (MonoDynamicStream *sh, MonoString *str, MonoError *error) { MONO_REQ_GC_UNSAFE_MODE; mono_error_init (error); char *name = mono_string_to_utf8_checked (str, error); return_val_if_nok (error, -1); guint32 idx; idx = mono_dynstream_insert_string (sh, name); g_free (name); return idx; }
int ves_icall_System_IO_InotifyWatcher_AddWatch (int fd, MonoString *name, gint32 mask) { MonoError error; char *str, *path; int retval; if (name == NULL) return -1; str = mono_string_to_utf8_checked (name, &error); if (mono_error_set_pending_exception (&error)) return -1; path = mono_portability_find_file (str, TRUE); if (!path) path = str; retval = inotify_add_watch (fd, path, mask); if (retval < 0) { switch (errno) { case EACCES: errno = ERROR_ACCESS_DENIED; break; case EBADF: errno = ERROR_INVALID_HANDLE; break; case EFAULT: errno = ERROR_INVALID_ACCESS; break; case EINVAL: errno = ERROR_INVALID_DATA; break; case ENOMEM: errno = ERROR_NOT_ENOUGH_MEMORY; break; case ENOSPC: errno = ERROR_TOO_MANY_OPEN_FILES; break; default: errno = ERROR_GEN_FAILURE; break; } mono_marshal_set_last_error (); } if (path != str) g_free (path); g_free (str); return retval; }
static gboolean saved_strings_find_func (gpointer key, gpointer value, gpointer user_data) { MonoError error; SavedStringFindInfo *info = (SavedStringFindInfo*)user_data; SavedString *saved = (SavedString*)value; gchar *utf_str; guint32 hash; if (!info || !saved || mono_string_length (saved->string) != info->len) return FALSE; utf_str = mono_string_to_utf8_checked (saved->string, &error); mono_error_assert_ok (&error); hash = do_calc_string_hash (0, utf_str); g_free (utf_str); if (hash != info->hash) return FALSE; return TRUE; }
void mono_invoke_unhandled_exception_hook (MonoObject *exc) { if (unhandled_exception_hook) { unhandled_exception_hook (exc, unhandled_exception_hook_data); } else { MonoError inner_error; MonoObject *other = NULL; MonoString *str = mono_object_try_to_string (exc, &other, &inner_error); char *msg = NULL; if (str && is_ok (&inner_error)) { msg = mono_string_to_utf8_checked (str, &inner_error); if (!is_ok (&inner_error)) { msg = g_strdup_printf ("Nested exception while formatting original exception"); mono_error_cleanup (&inner_error); } } else if (other) { char *original_backtrace = mono_exception_get_managed_backtrace ((MonoException*)exc); char *nested_backtrace = mono_exception_get_managed_backtrace ((MonoException*)other); msg = g_strdup_printf ("Nested exception detected.\nOriginal Exception: %s\nNested exception:%s\n", original_backtrace, nested_backtrace); g_free (original_backtrace); g_free (nested_backtrace); } else { msg = g_strdup ("Nested exception trying to figure out what went wrong"); } mono_runtime_printf_err ("[ERROR] FATAL UNHANDLED EXCEPTION: %s", msg); g_free (msg); #if defined(HOST_IOS) g_assertion_message ("Terminating runtime due to unhandled exception"); #else exit (mono_environment_exitcode_get ()); #endif } g_assert_not_reached (); }
MonoBoolean ves_icall_System_Globalization_RegionInfo_construct_internal_region_from_name (MonoRegionInfo *this_obj, MonoString *name) { MonoError error; const RegionInfoNameEntry *ne; char *n; n = mono_string_to_utf8_checked (name, &error); if (mono_error_set_pending_exception (&error)) return FALSE; ne = (const RegionInfoNameEntry *)mono_binary_search (n, region_name_entries, NUM_REGION_ENTRIES, sizeof (RegionInfoNameEntry), region_name_locator); if (ne == NULL) { /*g_print ("ne (%s) is null\n", n);*/ g_free (n); return FALSE; } g_free (n); return construct_region (this_obj, ®ion_entries [ne->region_entry_index]); }
MonoBoolean ves_icall_System_Globalization_CalendarData_fill_calendar_data (MonoCalendarData *this_obj, MonoString *name, gint32 calendar_index) { MonoError error; MonoDomain *domain; const DateTimeFormatEntry *dfe; const CultureInfoNameEntry *ne; const CultureInfoEntry *ci; char *n; n = mono_string_to_utf8_checked (name, &error); if (mono_error_set_pending_exception (&error)) return FALSE; ne = (const CultureInfoNameEntry *)mono_binary_search (n, culture_name_entries, NUM_CULTURE_ENTRIES, sizeof (CultureInfoNameEntry), culture_name_locator); g_free (n); if (ne == NULL) { return FALSE; } ci = &culture_entries [ne->culture_entry_index]; dfe = &datetime_format_entries [ci->datetime_format_index]; domain = mono_domain_get (); MONO_OBJECT_SETREF (this_obj, NativeName, mono_string_new (domain, idx2string (ci->nativename))); MonoArray *short_date_patterns = create_names_array_idx_dynamic (dfe->short_date_patterns, NUM_SHORT_DATE_PATTERNS, &error); return_val_and_set_pending_if_nok (&error, FALSE); MONO_OBJECT_SETREF (this_obj, ShortDatePatterns, short_date_patterns); MonoArray *year_month_patterns =create_names_array_idx_dynamic (dfe->year_month_patterns, NUM_YEAR_MONTH_PATTERNS, &error); return_val_and_set_pending_if_nok (&error, FALSE); MONO_OBJECT_SETREF (this_obj, YearMonthPatterns, year_month_patterns); MonoArray *long_date_patterns = create_names_array_idx_dynamic (dfe->long_date_patterns, NUM_LONG_DATE_PATTERNS, &error); return_val_and_set_pending_if_nok (&error, FALSE); MONO_OBJECT_SETREF (this_obj, LongDatePatterns, long_date_patterns); MONO_OBJECT_SETREF (this_obj, MonthDayPattern, mono_string_new (domain, pattern2string (dfe->month_day_pattern))); MonoArray *day_names = create_names_array_idx (dfe->day_names, NUM_DAYS, &error); return_val_and_set_pending_if_nok (&error, FALSE); MONO_OBJECT_SETREF (this_obj, DayNames, day_names); MonoArray *abbr_day_names = create_names_array_idx (dfe->abbreviated_day_names, NUM_DAYS, &error); return_val_and_set_pending_if_nok (&error, FALSE); MONO_OBJECT_SETREF (this_obj, AbbreviatedDayNames, abbr_day_names); MonoArray *ss_day_names = create_names_array_idx (dfe->shortest_day_names, NUM_DAYS, &error); return_val_and_set_pending_if_nok (&error, FALSE); MONO_OBJECT_SETREF (this_obj, SuperShortDayNames, ss_day_names); MonoArray *month_names = create_names_array_idx (dfe->month_names, NUM_MONTHS, &error); return_val_and_set_pending_if_nok (&error, FALSE); MONO_OBJECT_SETREF (this_obj, MonthNames, month_names); MonoArray *abbr_mon_names = create_names_array_idx (dfe->abbreviated_month_names, NUM_MONTHS, &error); return_val_and_set_pending_if_nok (&error, FALSE); MONO_OBJECT_SETREF (this_obj, AbbreviatedMonthNames, abbr_mon_names); MonoArray *gen_month_names = create_names_array_idx (dfe->month_genitive_names, NUM_MONTHS, &error); return_val_and_set_pending_if_nok (&error, FALSE); MONO_OBJECT_SETREF (this_obj, GenitiveMonthNames, gen_month_names); MonoArray *gen_abbr_mon_names = create_names_array_idx (dfe->abbreviated_month_genitive_names, NUM_MONTHS, &error); return_val_and_set_pending_if_nok (&error, FALSE); MONO_OBJECT_SETREF (this_obj, GenitiveAbbreviatedMonthNames, gen_abbr_mon_names); return TRUE; }
MonoBoolean ves_icall_System_ConsoleDriver_TtySetup (MonoString *keypad, MonoString *teardown, MonoArray **control_chars, int **size) { MonoError error; int dims; dims = terminal_get_dimensions (); if (dims == -1){ int cols = 0, rows = 0; const char *str = g_getenv ("COLUMNS"); if (str != NULL) cols = atoi (str); str = g_getenv ("LINES"); if (str != NULL) rows = atoi (str); if (cols != 0 && rows != 0) cols_and_lines = (cols << 16) | rows; else cols_and_lines = -1; } else { cols_and_lines = dims; } *size = &cols_and_lines; /* 17 is the number of entries set in set_control_chars() above. * NCCS is the total size, but, by now, we only care about those 17 values*/ MonoArray *control_chars_arr = mono_array_new_checked (mono_domain_get (), mono_defaults.byte_class, 17, &error); if (mono_error_set_pending_exception (&error)) return FALSE; mono_gc_wbarrier_generic_store (control_chars, (MonoObject*) control_chars_arr); if (tcgetattr (STDIN_FILENO, &initial_attr) == -1) return FALSE; mono_attr = initial_attr; mono_attr.c_lflag &= ~(ICANON); mono_attr.c_iflag &= ~(IXON|IXOFF); mono_attr.c_cc [VMIN] = 1; mono_attr.c_cc [VTIME] = 0; #ifdef VDSUSP /* Disable C-y being used as a suspend character on OSX */ mono_attr.c_cc [VDSUSP] = 255; #endif if (tcsetattr (STDIN_FILENO, TCSANOW, &mono_attr) == -1) return FALSE; set_control_chars (*control_chars, mono_attr.c_cc); /* If initialized from another appdomain... */ if (setup_finished) return TRUE; keypad_xmit_str = NULL; if (keypad != NULL) { keypad_xmit_str = mono_string_to_utf8_checked (keypad, &error); if (mono_error_set_pending_exception (&error)) return FALSE; } console_set_signal_handlers (); setup_finished = TRUE; if (!atexit_called) { if (teardown != NULL) { teardown_str = mono_string_to_utf8_checked (teardown, &error); if (mono_error_set_pending_exception (&error)) return FALSE; } mono_atexit (tty_teardown); } return TRUE; }