gboolean
mono_w32process_try_get_modules (gpointer process, gpointer *modules, guint32 size, guint32 *needed);
-gunichar2 *
-mono_w32process_module_get_name (gpointer process, gpointer module, guint32 *len);
+gboolean
+mono_w32process_module_get_name (gpointer process, gpointer module, gunichar2 **str, guint32 *len);
-gunichar2 *
-mono_w32process_module_get_filename (gpointer process, gpointer module, guint32 *len);
+gboolean
+mono_w32process_module_get_filename (gpointer process, gpointer module, gunichar2 **str, guint32 *len);
gboolean
mono_w32process_module_get_information (gpointer process, gpointer module, MODULEINFO *modinfo, guint32 size);
return TRUE;
}
-gunichar2 *
-mono_w32process_module_get_filename (gpointer handle, gpointer module, guint32 *len)
+gboolean
+mono_w32process_module_get_filename (gpointer handle, gpointer module, gunichar2 **str, guint32 *len)
{
gint pid;
gsize bytes = 0;
mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER_PROCESS, "%s: Getting module file name, process handle %p module %p " G_GUINT32_FORMAT,
__func__, handle, module);
+ if (str == NULL || len == NULL)
+ return FALSE;
+
+ *str = NULL;
*len = 0;
pid = mono_w32process_get_pid (handle);
if (pid == 0)
- return NULL;
+ return FALSE;
path = mono_w32process_get_path (pid);
if (path == NULL)
- return NULL;
+ return FALSE;
proc_path = mono_unicode_from_external (path, &bytes);
+ if (proc_path == NULL) {
+ g_free (path);
+ return FALSE;
+ }
+ *str = mono_unicode_from_external (path, &bytes);
*len = bytes / sizeof (gunichar2);
g_free (path);
- return proc_path;
+ return TRUE;
}
-gunichar2 *
-mono_w32process_module_get_name (gpointer handle, gpointer module, guint32 *len)
+gboolean
+mono_w32process_module_get_name (gpointer handle, gpointer module, gunichar2 **str, guint32 *len)
{
MonoW32Handle *handle_data;
MonoW32HandleProcess *process_handle;
mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER_PROCESS, "%s: Getting module base name, process handle %p module %p " G_GUINT32_FORMAT,
__func__, handle, module);
+ if (str == NULL || len == NULL)
+ return FALSE;
+
+ *str = NULL;
*len = 0;
if (!mono_w32handle_lookup_and_ref (handle, &handle_data)) {
mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER_PROCESS, "%s: unknown handle %p", __func__, handle);
mono_w32error_set_last (ERROR_INVALID_HANDLE);
- return NULL;
+ return FALSE;
}
if (handle_data->type != MONO_W32TYPE_PROCESS) {
mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER_PROCESS, "%s: unknown process handle %p", __func__, handle);
mono_w32error_set_last (ERROR_INVALID_HANDLE);
mono_w32handle_unref (handle_data);
- return NULL;
+ return FALSE;
}
process_handle = (MonoW32HandleProcess*) handle_data->specific;
mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER_PROCESS, "%s: Can't get modules %p", __func__, handle);
g_free (pname);
mono_w32handle_unref (handle_data);
- return 0;
+ return FALSE;
}
/* If module != NULL compare the address.
/* bugger */
g_free (procname_ext);
mono_w32handle_unref (handle_data);
- return NULL;
+ return FALSE;
}
+ *str = procname;
*len = bytes / sizeof (gunichar2);
g_free (procname_ext);
mono_w32handle_unref (handle_data);
- return procname;
+ return TRUE;
}
mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER_PROCESS, "%s: Can't find procname_ext %p", __func__, handle);
mono_w32handle_unref (handle_data);
- return NULL;
+ return FALSE;
}
gboolean
return EnumProcessModules (process, modules, size, needed);
}
-static gunichar2 *
-mono_w32process_module_get_name (gpointer process, gpointer module, guint32 *len)
-{
- gunichar2 *basename = NULL;
- guint32 size = 260; // reasonable length to start with given historical behavior
-
- basename = g_new0 (gunichar2, size);
- *len = GetModuleBaseNameW (process, (HMODULE)module, basename, size);
- // GetModuleBaseNameW will set the null byte but include it in the returned length
- while (*len >= size) {
- if (*len == 0) {
- g_free (basename);
- return NULL;
- }
- size *= 2; // double the buffer and try again
- g_free (basename);
- basename = g_new0 (gunichar2, size);
- *len = GetModuleBaseNameW (process, (HMODULE)module, basename, size);
- }
- return basename;
+static gboolean
+mono_w32process_module_get_name (gpointer process, gpointer module, gunichar2 **str, guint32 *len)
+{
+ return mono_get_module_basename (process, module, str, len);
}
-static gunichar2 *
-mono_w32process_module_get_filename (gpointer process, gpointer module, guint32 *len)
+static gboolean
+mono_w32process_module_get_filename (gpointer process, gpointer module, gunichar2 **str, guint32 *len)
{
- gunichar2 *basename = NULL;
- guint32 size = 260; // reasonable length to start with given historical behavior
-
- basename = g_new0 (gunichar2, size);
- *len = GetModuleFileNameExW (process, (HMODULE)module, basename, size);
- // GetModuleFileNameExW will set the null byte but _not_ include it in the returned length
- while (*len >= (size - 1)) {
- if (*len == 0) {
- g_free (basename);
- return NULL;
- }
- size *= 2; // double the buffer and try again
- g_free (basename);
- basename = g_new0 (gunichar2, size);
- *len = GetModuleFileNameExW (process, (HMODULE)module, basename, size);
- }
- return basename;
+ return mono_get_module_filename_ex (process, module, str, len);
}
static gboolean
return_val_if_nok (error, NULL_HANDLE_ARRAY);
for (i = 0; i < module_count; i++) {
- modname = mono_w32process_module_get_name (process, mods [i], &modname_len);
- filename = mono_w32process_module_get_filename (process, mods [i], &filename_len);
- if (modname && filename) {
+ if (mono_w32process_module_get_name (process, mods [i], &modname, &modname_len) && mono_w32process_module_get_filename (process, mods [i], &filename, &filename_len)) {
process_add_module (module, filever, str, process, mods [i], filename, modname, get_process_module_class (), error);
if (is_ok (error))
MONO_HANDLE_ARRAY_SETREF (temp_arr, num_added++, module);
if (!mono_w32process_try_get_modules (process, &mod, sizeof (mod), &needed))
return NULL_HANDLE_STRING;
- name = mono_w32process_module_get_name (process, mod, &len);
- if (!name)
+ if (!mono_w32process_module_get_name (process, mod, &name, &len))
return NULL_HANDLE_STRING;
MonoStringHandle res = mono_string_new_utf16_handle (mono_domain_get (), name, len, error);