2 * process-windows.c: Windows process support.
4 * Copyright 2016 Microsoft
5 * Licensed under the MIT license. See LICENSE file in the project root for full license information.
11 #if defined(HOST_WIN32)
14 #include "mono/metadata/process-windows-internals.h"
16 #if G_HAVE_API_SUPPORT(HAVE_CLASSIC_WINAPI_SUPPORT)
17 static inline gboolean
18 mono_process_win_enum_processes (DWORD *pids, DWORD count, DWORD *needed)
20 return EnumProcesses (pids, count, needed);
22 #endif /* G_HAVE_API_SUPPORT(HAVE_CLASSIC_WINAPI_SUPPORT) */
25 ves_icall_System_Diagnostics_Process_GetProcesses_internal (void)
36 pids = g_new0 (DWORD, count);
37 ret = mono_process_win_enum_processes (pids, count * sizeof (guint32), &needed);
43 exc = mono_get_exception_not_supported ("This system does not support EnumProcesses");
44 mono_set_pending_exception (exc);
47 if (needed < (count * sizeof (guint32)))
51 count = (count * 3) / 2;
54 count = needed / sizeof (guint32);
55 procs = mono_array_new_checked (mono_domain_get (), mono_get_int32_class (), count, &error);
56 if (mono_error_set_pending_exception (&error)) {
61 memcpy (mono_array_addr (procs, guint32, 0), pids, needed);
69 mono_process_quote_path (const gchar *path)
71 gchar *res = g_shell_quote (path);
82 mono_process_unquote_application_name (gchar *appname)
84 size_t len = strlen (appname);
86 if (appname[len-1] == '\"')
87 appname[len-1] = '\0';
88 if (appname[0] == '\"')
96 mono_process_get_shell_arguments (MonoProcessStartInfo *proc_start_info, gunichar2 **shell_path, MonoString **cmd)
99 gchar *new_cmd, *cmd_utf8;
100 MonoError mono_error;
103 *cmd = proc_start_info->arguments;
105 mono_process_complete_path (mono_string_chars (proc_start_info->filename), &spath);
107 /* Seems like our CreateProcess does not work as the windows one.
108 * This hack is needed to deal with paths containing spaces */
110 cmd_utf8 = mono_string_to_utf8_checked (*cmd, &mono_error);
111 if (!mono_error_set_pending_exception (&mono_error)) {
112 new_cmd = g_strdup_printf ("%s %s", spath, cmd_utf8);
113 *cmd = mono_string_new_wrapper (new_cmd);
121 *cmd = mono_string_new_wrapper (spath);
127 return (*cmd != NULL) ? TRUE : FALSE;
129 #endif /* HOST_WIN32 */