[LoongArch64] Part-5:add loongarch support in some files for LoongArch64. (#21769)
[mono-project.git] / mono / metadata / w32process-win32.c
blobf2e877e9b84ed35faad664762b9ccf058917e136
1 /**
2 * \file
3 * System.Diagnostics.Process support
5 * Author:
6 * Dick Porter (dick@ximian.com)
8 * Copyright 2002 Ximian, Inc.
9 * Copyright 2002-2006 Novell, Inc.
10 * Licensed under the MIT license. See LICENSE file in the project root for full license information.
13 #include <config.h>
15 #include <glib.h>
16 #include <string.h>
18 #include <winsock2.h>
19 #include <windows.h>
21 #include <mono/metadata/w32process.h>
22 #include <mono/metadata/assembly.h>
23 #include <mono/metadata/appdomain.h>
24 #include <mono/metadata/image.h>
25 #include <mono/metadata/cil-coff.h>
26 #include <mono/metadata/exception.h>
27 #include <mono/metadata/threadpool-io.h>
28 #include <mono/utils/strenc.h>
29 #include <mono/utils/mono-proclib.h>
30 #include <mono/metadata/w32handle.h>
31 #include <mono/utils/w32api.h>
32 #include <mono/utils/mono-threads-coop.h>
33 #include <mono/utils/w32subset.h>
35 void
36 mono_w32process_init (void)
40 void
41 mono_w32process_cleanup (void)
45 void
46 mono_w32process_signal_finished (void)
50 guint32
51 mono_w32process_get_pid (gpointer handle)
53 return GetProcessId (handle);
56 #if HAVE_API_SUPPORT_WIN32_ENUM_WINDOWS
57 typedef struct {
58 DWORD pid;
59 HWND hwnd;
60 } EnumWindowsArgs;
62 static BOOL CALLBACK
63 mono_enum_windows_callback(HWND hwnd, LPARAM lparam)
65 EnumWindowsArgs *args = (EnumWindowsArgs *)lparam;
66 DWORD pid = 0;
67 GetWindowThreadProcessId(hwnd, &pid);
68 if (pid != args->pid || GetWindow(hwnd, GW_OWNER) != NULL || !IsWindowVisible(hwnd)) return TRUE;
69 args->hwnd = hwnd;
70 return FALSE;
73 HANDLE
74 ves_icall_System_Diagnostics_Process_MainWindowHandle_internal (guint32 pid, MonoError *error)
76 EnumWindowsArgs args = {pid, NULL};
77 EnumWindows(mono_enum_windows_callback, (LPARAM)&args);
78 return args.hwnd;
80 #elif !HAVE_EXTERN_DEFINED_WIN32_ENUM_WINDOWS
81 HANDLE
82 ves_icall_System_Diagnostics_Process_MainWindowHandle_internal (guint32 pid, MonoError *error)
84 /*TODO: Implement for uwp*/
85 return NULL;
87 #endif /* HAVE_API_SUPPORT_WIN32_ENUM_WINDOWS */
89 #if HAVE_API_SUPPORT_WIN32_ENUM_PROCESS_MODULES
90 gboolean
91 mono_w32process_try_get_modules (gpointer process, gpointer *modules, guint32 size, guint32 *needed)
93 return EnumProcessModules (process, (HMODULE *)modules, size, (PDWORD)needed);
95 #elif !HAVE_EXTERN_DEFINED_WIN32_ENUM_PROCESS_MODULES
96 gboolean
97 mono_w32process_try_get_modules (gpointer process, gpointer *modules, guint32 size, guint32 *needed)
99 g_unsupported_api ("EnumProcessModules");
100 SetLastError (ERROR_NOT_SUPPORTED);
101 return FALSE;
103 #endif
105 #if HAVE_API_SUPPORT_WIN32_GET_MODULE_BASE_NAME
106 gboolean
107 mono_w32process_module_get_name (gpointer process, gpointer module, gunichar2 **str, guint32 *len)
109 return mono_get_module_basename (process, module, str, len);
111 #elif !HAVE_EXTERN_DEFINED_WIN32_GET_MODULE_BASE_NAME
112 gboolean
113 mono_w32process_module_get_name (gpointer process, gpointer module, gunichar2 **str, guint32 *len)
115 g_unsupported_api ("GetModuleBaseName");
116 SetLastError (ERROR_NOT_SUPPORTED);
117 return FALSE;
119 #endif /* HAVE_API_SUPPORT_WIN32_GET_MODULE_BASE_NAME */
121 #if HAVE_API_SUPPORT_WIN32_GET_MODULE_FILE_NAME_EX
122 gboolean
123 mono_w32process_module_get_filename (gpointer process, gpointer module, gunichar2 **str, guint32 *len)
125 return mono_get_module_filename_ex (process, module, str, len);
127 #elif !HAVE_EXTERN_DEFINED_WIN32_GET_MODULE_FILE_NAME_EX
128 gboolean
129 mono_w32process_module_get_filename (gpointer process, gpointer module, gunichar2 **str, guint32 *len)
131 g_unsupported_api ("GetModuleFileNameEx");
132 SetLastError (ERROR_NOT_SUPPORTED);
133 return FALSE;
135 #endif /* HAVE_API_SUPPORT_WIN32_GET_MODULE_FILE_NAME_EX */
137 #if HAVE_API_SUPPORT_WIN32_GET_MODULE_INFORMATION
138 gboolean
139 mono_w32process_module_get_information (gpointer process, gpointer module, gpointer modinfo, guint32 size)
141 return GetModuleInformation (process, (HMODULE)module, (MODULEINFO *)modinfo, size);
143 #elif !HAVE_EXTERN_DEFINED_WIN32_GET_MODULE_INFORMATION
144 gboolean
145 mono_w32process_module_get_information (gpointer process, gpointer module, gpointer modinfo, guint32 size)
147 g_unsupported_api ("GetModuleInformation");
148 SetLastError (ERROR_NOT_SUPPORTED);
149 return FALSE;
151 #endif /* HAVE_API_SUPPORT_WIN32_GET_MODULE_INFORMATION */
153 #if HAVE_API_SUPPORT_WIN32_GET_FILE_VERSION_INFO
154 gboolean
155 mono_w32process_get_fileversion_info (const gunichar2 *filename, gpointer *data)
157 DWORD handle;
159 g_assert (data);
160 *data = NULL;
162 DWORD datasize = GetFileVersionInfoSizeW (filename, &handle);
163 if (datasize <= 0)
164 return FALSE;
166 *data = g_malloc0 (datasize);
167 if (!GetFileVersionInfoW (filename, handle, datasize, *data)) {
168 g_free (*data);
169 return FALSE;
172 return TRUE;
174 #elif !HAVE_EXTERN_DEFINED_WIN32_GET_FILE_VERSION_INFO
175 gboolean
176 mono_w32process_get_fileversion_info (const gunichar2 *filename, gpointer *data)
178 g_unsupported_api ("GetFileVersionInfo");
179 SetLastError (ERROR_NOT_SUPPORTED);
180 return FALSE;
182 #endif /* HAVE_API_SUPPORT_WIN32_GET_FILE_VERSION_INFO */
184 #if HAVE_API_SUPPORT_WIN32_VER_QUERY_VALUE
185 gboolean
186 mono_w32process_ver_query_value (gconstpointer datablock, const gunichar2 *subblock, gpointer *buffer, guint32 *len)
188 return VerQueryValueW (datablock, subblock, buffer, len);
190 #elif !HAVE_EXTERN_DEFINED_WIN32_VER_QUERY_VALUE
191 gboolean
192 mono_w32process_ver_query_value (gconstpointer datablock, const gunichar2 *subblock, gpointer *buffer, guint32 *len)
194 g_unsupported_api ("VerQueryValue");
195 SetLastError (ERROR_NOT_SUPPORTED);
196 return FALSE;
198 #endif /* HAVE_API_SUPPORT_WIN32_VER_QUERY_VALUE */
200 #if HAVE_API_SUPPORT_WIN32_VER_LANGUAGE_NAME
201 guint32
202 mono_w32process_ver_language_name (guint32 lang, gunichar2 *lang_out, guint32 lang_len)
204 return VerLanguageNameW (lang, lang_out, lang_len);
206 #elif !HAVE_EXTERN_DEFINED_WIN32_VER_LANGUAGE_NAME
207 guint32
208 mono_w32process_ver_language_name (guint32 lang, gunichar2 *lang_out, guint32 lang_len)
210 g_unsupported_api ("VerLanguageName");
211 SetLastError (ERROR_NOT_SUPPORTED);
212 return 0;
214 #endif /* HAVE_API_SUPPORT_WIN32_VER_LANGUAGE_NAME */
216 #if HAVE_API_SUPPORT_WIN32_OPEN_PROCESS
217 HANDLE
218 ves_icall_System_Diagnostics_Process_GetProcess_internal (guint32 pid, MonoError *error)
220 HANDLE handle;
222 /* GetCurrentProcess returns a pseudo-handle, so use
223 * OpenProcess instead
225 handle = OpenProcess (PROCESS_ALL_ACCESS, TRUE, pid);
226 if (handle == NULL)
227 /* FIXME: Throw an exception */
228 return NULL;
229 return handle;
231 #elif !HAVE_EXTERN_DEFINED_WIN32_OPEN_PROCESS
232 HANDLE
233 ves_icall_System_Diagnostics_Process_GetProcess_internal (guint32 pid, MonoError *error)
235 g_unsupported_api ("OpenProcess");
236 mono_error_set_not_supported (error, G_UNSUPPORTED_API, "OpenProcess");
237 SetLastError (ERROR_NOT_SUPPORTED);
238 return NULL;
240 #endif /* HAVE_API_SUPPORT_WIN32_OPEN_PROCESS */
242 #if HAVE_API_SUPPORT_WIN32_SHELL_EXECUTE_EX
243 #include <shellapi.h>
244 MonoBoolean
245 ves_icall_System_Diagnostics_Process_ShellExecuteEx_internal (MonoW32ProcessStartInfoHandle proc_start_info, MonoW32ProcessInfo *process_info, MonoError *error)
247 MonoCreateProcessCoop coop;
248 mono_createprocess_coop_init (&coop, proc_start_info, process_info);
250 SHELLEXECUTEINFOW shellex = {0};
251 gboolean ret;
253 shellex.cbSize = sizeof(SHELLEXECUTEINFO);
254 shellex.fMask = (gulong)(SEE_MASK_NOASYNC | SEE_MASK_NOCLOSEPROCESS | SEE_MASK_UNICODE);
255 shellex.nShow = (gulong)MONO_HANDLE_GETVAL (proc_start_info, window_style);
256 shellex.nShow = (gulong)((shellex.nShow == 0) ? 1 : (shellex.nShow == 1 ? 0 : shellex.nShow));
258 shellex.lpFile = coop.filename;
259 shellex.lpParameters = coop.arguments;
261 if (coop.length.verb)
262 shellex.lpVerb = coop.verb;
264 if (coop.length.working_directory)
265 shellex.lpDirectory = coop.working_directory;
267 if (MONO_HANDLE_GETVAL (proc_start_info, error_dialog))
268 shellex.hwnd = (HWND)MONO_HANDLE_GETVAL (proc_start_info, error_dialog_parent_handle);
269 else
270 shellex.fMask = (gulong)(shellex.fMask | SEE_MASK_FLAG_NO_UI);
272 MONO_ENTER_GC_SAFE;
273 ret = ShellExecuteExW (&shellex);
274 MONO_EXIT_GC_SAFE;
276 if (ret == FALSE) {
277 process_info->pid = -GetLastError ();
278 } else {
279 process_info->process_handle = shellex.hProcess;
280 #if !defined(MONO_CROSS_COMPILE)
281 process_info->pid = GetProcessId (shellex.hProcess);
282 #else
283 process_info->pid = 0;
284 #endif
287 mono_createprocess_coop_cleanup (&coop);
289 return ret;
291 #elif !HAVE_EXTERN_DEFINED_WIN32_SHELL_EXECUTE_EX
292 MonoBoolean
293 ves_icall_System_Diagnostics_Process_ShellExecuteEx_internal (MonoW32ProcessStartInfoHandle proc_start_info, MonoW32ProcessInfo *process_info, MonoError *error)
295 g_unsupported_api ("ShellExecuteEx");
296 mono_error_set_not_supported (error, G_UNSUPPORTED_API, "ShellExecuteEx");
297 process_info->pid = (guint32)(-ERROR_NOT_SUPPORTED);
298 SetLastError (ERROR_NOT_SUPPORTED);
299 return FALSE;
301 #endif /* HAVE_API_SUPPORT_WIN32_SHELL_EXECUTE_EX */
303 #if HAVE_API_SUPPORT_WIN32_CREATE_PROCESS_WITH_LOGON || HAVE_API_SUPPORT_WIN32_CREATE_PROCESS
304 static gboolean
305 mono_process_create_process (MonoCreateProcessCoop *coop, MonoW32ProcessInfo *mono_process_info,
306 MonoStringHandle cmd, guint32 creation_flags, gunichar2 *env_vars, gunichar2 *dir,
307 HANDLE stdin_handle, HANDLE stdout_handle, HANDLE stderr_handle, PROCESS_INFORMATION *process_info, MonoError *error)
309 gboolean result = FALSE;
310 MonoGCHandle cmd_gchandle = NULL;
311 gunichar2 *cmd_chars = MONO_HANDLE_IS_NULL (cmd) ? NULL : mono_string_handle_pin_chars (cmd, &cmd_gchandle);
313 STARTUPINFOW start_info={0};
314 #if HAVE_API_SUPPORT_WIN32_CONSOLE
315 start_info.cb = sizeof(STARTUPINFOW);
316 start_info.dwFlags = STARTF_USESTDHANDLES;
317 start_info.hStdInput = stdin_handle;
318 start_info.hStdOutput = stdout_handle;
319 start_info.hStdError = stderr_handle;
320 #else
321 start_info.dwFlags = 0;
322 start_info.hStdInput = INVALID_HANDLE_VALUE;
323 start_info.hStdOutput = INVALID_HANDLE_VALUE;
324 start_info.hStdError = INVALID_HANDLE_VALUE;
325 #endif /* HAVE_API_SUPPORT_WIN32_CONSOLE */
327 MONO_ENTER_GC_SAFE;
328 if (coop->username) {
329 #if HAVE_API_SUPPORT_WIN32_CREATE_PROCESS_WITH_LOGON
330 guint32 logon_flags = mono_process_info->load_user_profile ? LOGON_WITH_PROFILE : 0;
332 result = CreateProcessWithLogonW (coop->username,
333 coop->domain,
334 mono_process_info->password,
335 logon_flags,
336 NULL,
337 cmd_chars,
338 creation_flags,
339 env_vars, dir, &start_info, process_info);
340 #else
341 memset (process_info, 0, sizeof (PROCESS_INFORMATION));
342 g_unsupported_api ("CreateProcessWithLogon");
343 mono_error_set_not_supported (error, G_UNSUPPORTED_API, "CreateProcessWithLogon");
344 SetLastError (ERROR_NOT_SUPPORTED);
345 #endif /* HAVE_API_SUPPORT_WIN32_CREATE_PROCESS_WITH_LOGON */
346 } else {
347 #if HAVE_API_SUPPORT_WIN32_CREATE_PROCESS
348 result = CreateProcessW (NULL,
349 cmd_chars,
350 NULL,
351 NULL,
352 TRUE,
353 creation_flags,
354 env_vars,
355 dir,
356 &start_info,
357 process_info);
358 #else
359 memset (process_info, 0, sizeof (PROCESS_INFORMATION));
360 g_unsupported_api ("CreateProcess");
361 mono_error_set_not_supported (error, G_UNSUPPORTED_API, "CreateProcess");
362 SetLastError (ERROR_NOT_SUPPORTED);
363 #endif
365 MONO_EXIT_GC_SAFE;
367 mono_gchandle_free_internal (cmd_gchandle);
369 return result;
371 #elif !HAVE_EXTERN_DEFINED_WIN32_CREATE_PROCESS_WITH_LOGON && !HAVE_EXTERN_DEFINED_WIN32_CREATE_PROCESS
372 static gboolean
373 mono_process_create_process (MonoCreateProcessCoop *coop, MonoW32ProcessInfo *mono_process_info,
374 MonoStringHandle cmd, guint32 creation_flags, gunichar2 *env_vars, gunichar2 *dir,
375 HANDLE stdin_handle, HANDLE stdout_handle, HANDLE stderr_handle, PROCESS_INFORMATION *process_info, MonoError *error)
377 memset (process_info, 0, sizeof (PROCESS_INFORMATION));
378 g_unsupported_api ("CreateProcessWithLogon, CreateProcess");
379 mono_error_set_not_supported (error, G_UNSUPPORTED_API, "CreateProcessWithLogon, CreateProcess");
380 SetLastError (ERROR_NOT_SUPPORTED);
381 return FALSE;
383 #endif /* HAVE_API_SUPPORT_WIN32_CREATE_PROCESS_WITH_LOGON || HAVE_API_SUPPORT_WIN32_CREATE_PROCESS */
385 static gchar*
386 process_unquote_application_name (gchar *appname)
388 size_t len = strlen (appname);
389 if (len) {
390 if (appname[len-1] == '\"')
391 appname[len-1] = '\0';
392 if (appname[0] == '\"')
393 appname++;
396 return appname;
399 static gchar*
400 process_quote_path (const gchar *path)
402 gchar *res = g_shell_quote (path);
403 gchar *q = res;
404 while (*q) {
405 if (*q == '\'')
406 *q = '\"';
407 q++;
409 return res;
412 /* Only used when UseShellExecute is false */
413 static gchar*
414 process_complete_path (const gunichar2 *appname)
416 // FIXME This function should stick to gunichar2.
418 char *utf8app;
419 char *utf8appmemory = NULL;
420 char *result;
422 utf8appmemory = g_utf16_to_utf8 (appname, -1, NULL, NULL, NULL);
423 utf8app = process_unquote_application_name (utf8appmemory);
425 result = process_quote_path (utf8app);
427 g_free (utf8appmemory);
429 return result;
432 static gboolean
433 process_get_shell_arguments (MonoCreateProcessCoop *proc_start_info, MonoStringHandle *cmd, MonoError *error)
435 char *spath = NULL;
436 char *new_cmd = NULL;
437 char *cmd_utf8 = NULL;
439 *cmd = proc_start_info->coophandle.arguments;
441 // FIXME There are excess utf8 <=> gunichar2 conversions here.
442 // We are either returning spath, or spath + " " + cmd.
443 // Just use gunichar2. Maybe move logic to C#.
445 spath = process_complete_path (proc_start_info->filename);
447 /* Seems like our CreateProcess does not work as the windows one.
448 * This hack is needed to deal with paths containing spaces */
449 if (!MONO_HANDLE_IS_NULL (*cmd)) {
450 cmd_utf8 = mono_string_handle_to_utf8 (*cmd, error);
451 goto_if_nok (error, error);
452 new_cmd = g_strdup_printf ("%s %s", spath, cmd_utf8);
453 *cmd = mono_string_new_utf8_len (mono_domain_get (), new_cmd, strlen (new_cmd), error);
454 goto_if_nok (error, error);
456 else {
457 *cmd = mono_string_new_utf8_len (mono_domain_get (), spath, strlen (spath), error);
458 goto_if_nok (error, error);
461 exit:
462 g_free (spath);
463 g_free (cmd_utf8);
464 g_free (new_cmd);
465 return !MONO_HANDLE_IS_NULL (*cmd);
466 error:
467 *cmd = NULL_HANDLE_STRING;
468 goto exit;
471 MonoBoolean
472 ves_icall_System_Diagnostics_Process_CreateProcess_internal (MonoW32ProcessStartInfoHandle proc_start_info,
473 HANDLE stdin_handle, HANDLE stdout_handle, HANDLE stderr_handle, MonoW32ProcessInfo *process_info, MonoError *error)
475 MonoCreateProcessCoop coop;
476 mono_createprocess_coop_init (&coop, proc_start_info, process_info);
478 gboolean ret;
479 gunichar2 *dir = NULL;
480 PROCESS_INFORMATION procinfo;
481 gunichar2 *env_vars = NULL;
482 MonoStringHandle cmd = NULL_HANDLE_STRING;
483 guint32 creation_flags;
485 creation_flags = CREATE_UNICODE_ENVIRONMENT;
486 if (MONO_HANDLE_GETVAL (proc_start_info, create_no_window))
487 creation_flags |= CREATE_NO_WINDOW;
489 if (process_get_shell_arguments (&coop, &cmd, error) == FALSE) {
490 // FIXME This should be passed back separately.
491 process_info->pid = -ERROR_FILE_NOT_FOUND;
492 ret = FALSE;
493 goto exit;
496 if (process_info->env_variables) {
497 MonoArrayHandle array = MONO_HANDLE_NEW (MonoArray, process_info->env_variables);
498 MonoStringHandle var = MONO_HANDLE_NEW (MonoString, NULL);
499 gsize const array_length = mono_array_handle_length (array);
501 // nul-separated and nul-terminated
502 gsize len = array_length + 1 + !array_length;
504 for (gsize i = 0; i < array_length; i++) {
505 MONO_HANDLE_ARRAY_GETREF (var, array, i);
506 len += mono_string_handle_length (var);
509 gunichar2 *ptr = g_new0 (gunichar2, len);
510 env_vars = ptr;
512 for (gsize i = 0; i < array_length; i++) {
513 MONO_HANDLE_ARRAY_GETREF (var, array, i);
514 MonoGCHandle gchandle = NULL;
515 memcpy (ptr, mono_string_handle_pin_chars (var, &gchandle), mono_string_handle_length (var) * sizeof (gunichar2));
516 mono_gchandle_free_internal (gchandle);
517 ptr += mono_string_handle_length (var);
518 ptr += 1; // Skip over the null-separator
522 /* The default dir name is "". Turn that into NULL to mean
523 * "current directory"
525 if (coop.length.working_directory)
526 dir = coop.working_directory;
528 ret = mono_process_create_process (&coop, process_info, cmd, creation_flags, env_vars, dir, stdin_handle, stdout_handle, stderr_handle, &procinfo, error);
530 g_free (env_vars);
532 if (ret) {
533 process_info->process_handle = procinfo.hProcess;
534 /*process_info->thread_handle=procinfo.hThread;*/
535 if (procinfo.hThread != NULL && procinfo.hThread != INVALID_HANDLE_VALUE)
536 CloseHandle (procinfo.hThread);
537 process_info->pid = procinfo.dwProcessId;
538 } else {
539 // FIXME This should be passed back separately.
540 process_info->pid = -GetLastError ();
543 exit:
544 mono_createprocess_coop_cleanup (&coop);
545 return ret;
548 #if HAVE_API_SUPPORT_WIN32_ENUM_PROCESSES
549 MonoArrayHandle
550 ves_icall_System_Diagnostics_Process_GetProcesses_internal (MonoError *error)
552 MonoArrayHandle procs = NULL_HANDLE_ARRAY;
553 DWORD needed = 0;
554 DWORD *pids = NULL;
555 int count = 512;
556 gboolean success;
558 do {
559 pids = g_new0 (DWORD, count);
561 MONO_ENTER_GC_SAFE;
562 success = EnumProcesses (pids, count * sizeof (DWORD), &needed);
563 MONO_EXIT_GC_SAFE;
565 if (!success)
566 goto exit;
567 if (needed < (count * sizeof (guint32)))
568 break;
569 g_free (pids);
570 pids = NULL;
571 count = (count * 3) / 2;
572 } while (TRUE);
574 count = needed / sizeof (guint32);
575 procs = mono_array_new_handle (mono_domain_get (), mono_get_int32_class (), count, error);
576 if (!is_ok (error)) {
577 procs = NULL_HANDLE_ARRAY;
578 goto exit;
581 MONO_ENTER_NO_SAFEPOINTS;
583 memcpy (mono_array_addr_internal (MONO_HANDLE_RAW (procs), guint32, 0), pids, needed);
585 MONO_EXIT_NO_SAFEPOINTS;
587 exit:
588 g_free (pids);
589 return procs;
591 #elif !HAVE_EXTERN_DEFINED_WIN32_ENUM_PROCESSES
592 MonoArrayHandle
593 ves_icall_System_Diagnostics_Process_GetProcesses_internal (MonoError *error)
595 g_unsupported_api ("EnumProcesses");
596 mono_error_set_not_supported (error, G_UNSUPPORTED_API, "EnumProcesses");
597 SetLastError (ERROR_NOT_SUPPORTED);
598 return NULL_HANDLE_ARRAY;
600 #endif /* HAVE_API_SUPPORT_WIN32_ENUM_PROCESSES */
602 MonoBoolean
603 ves_icall_Microsoft_Win32_NativeMethods_CloseProcess (gpointer handle)
605 return CloseHandle (handle);
608 MonoBoolean
609 ves_icall_Microsoft_Win32_NativeMethods_TerminateProcess (gpointer handle, gint32 exitcode)
611 return TerminateProcess (handle, exitcode);
614 MonoBoolean
615 ves_icall_Microsoft_Win32_NativeMethods_GetExitCodeProcess (gpointer handle, gint32 *exitcode)
617 return GetExitCodeProcess (handle, (PDWORD)exitcode);
620 #if HAVE_API_SUPPORT_WIN32_GET_WORKING_SET_SIZE
621 MonoBoolean
622 ves_icall_Microsoft_Win32_NativeMethods_GetProcessWorkingSetSize (gpointer handle, gsize *min, gsize *max)
624 return GetProcessWorkingSetSize (handle, (PSIZE_T)min, (PSIZE_T)max);
626 #elif !HAVE_EXTERN_DEFINED_WIN32_GET_WORKING_SET_SIZE
627 MonoBoolean
628 ves_icall_Microsoft_Win32_NativeMethods_GetProcessWorkingSetSize (gpointer handle, gsize *min, gsize *max)
630 ERROR_DECL (error);
631 g_unsupported_api ("GetProcessWorkingSetSize");
632 mono_error_set_not_supported(error, G_UNSUPPORTED_API, "GetProcessWorkingSetSize");
633 mono_error_set_pending_exception (error);
634 SetLastError (ERROR_NOT_SUPPORTED);
635 return FALSE;
637 #endif /* HAVE_API_SUPPORT_WIN32_GET_WORKING_SET_SIZE */
639 #if HAVE_API_SUPPORT_WIN32_SET_WORKING_SET_SIZE
640 MonoBoolean
641 ves_icall_Microsoft_Win32_NativeMethods_SetProcessWorkingSetSize (gpointer handle, gsize min, gsize max)
643 return SetProcessWorkingSetSize (handle, min, max);
645 #elif !HAVE_EXTERN_DEFINED_WIN32_SET_WORKING_SET_SIZE
646 MonoBoolean
647 ves_icall_Microsoft_Win32_NativeMethods_SetProcessWorkingSetSize (gpointer handle, gsize min, gsize max)
649 ERROR_DECL (error);
650 g_unsupported_api ("SetProcessWorkingSetSize");
651 mono_error_set_not_supported (error, G_UNSUPPORTED_API, "SetProcessWorkingSetSize");
652 mono_error_set_pending_exception (error);
653 SetLastError (ERROR_NOT_SUPPORTED);
654 return FALSE;
656 #endif /* HAVE_API_SUPPORT_WIN32_SET_WORKING_SET_SIZE */
658 #if HAVE_API_SUPPORT_WIN32_GET_PRIORITY_CLASS
659 gint32
660 ves_icall_Microsoft_Win32_NativeMethods_GetPriorityClass (gpointer handle)
662 return GetPriorityClass (handle);
664 #elif !HAVE_EXTERN_DEFINED_WIN32_GET_PRIORITY_CLASS
665 gint32
666 ves_icall_Microsoft_Win32_NativeMethods_GetPriorityClass (gpointer handle)
668 ERROR_DECL (error);
669 g_unsupported_api ("GetPriorityClass");
670 mono_error_set_not_supported (error, G_UNSUPPORTED_API, "GetPriorityClass");
671 mono_error_set_pending_exception (error);
672 SetLastError (ERROR_NOT_SUPPORTED);
673 return FALSE;
675 #endif /* HAVE_API_SUPPORT_WIN32_GET_PRIORITY_CLASS */
677 #if HAVE_API_SUPPORT_WIN32_SET_PRIORITY_CLASS
678 MonoBoolean
679 ves_icall_Microsoft_Win32_NativeMethods_SetPriorityClass (gpointer handle, gint32 priorityClass)
681 return SetPriorityClass (handle, (guint32) priorityClass);
683 #elif !HAVE_EXTERN_DEFINED_WIN32_SET_PRIORITY_CLASS
684 MonoBoolean
685 ves_icall_Microsoft_Win32_NativeMethods_SetPriorityClass (gpointer handle, gint32 priorityClass)
687 ERROR_DECL (error);
688 g_unsupported_api ("SetPriorityClass");
689 mono_error_set_not_supported(error, G_UNSUPPORTED_API, "SetPriorityClass");
690 mono_error_set_pending_exception (error);
691 SetLastError (ERROR_NOT_SUPPORTED);
692 return FALSE;
694 #endif /* HAVE_API_SUPPORT_WIN32_SET_PRIORITY_CLASS */
696 MonoBoolean
697 ves_icall_Microsoft_Win32_NativeMethods_GetProcessTimes (gpointer handle, gint64 *creationtime, gint64 *exittime, gint64 *kerneltime, gint64 *usertime)
699 return GetProcessTimes (handle, (LPFILETIME) creationtime, (LPFILETIME) exittime, (LPFILETIME) kerneltime, (LPFILETIME) usertime);
702 gpointer
703 ves_icall_Microsoft_Win32_NativeMethods_GetCurrentProcess (void)
705 return GetCurrentProcess ();