2 * process.c: System.Diagnostics.Process support
5 * Dick Porter (dick@ximian.com)
7 * (C) 2002 Ximian, Inc.
15 #include <mono/metadata/object.h>
16 #include <mono/metadata/process.h>
17 #include <mono/metadata/assembly.h>
18 #include <mono/metadata/appdomain.h>
19 #include <mono/metadata/image.h>
20 #include <mono/metadata/cil-coff.h>
21 #include <mono/metadata/exception.h>
22 #include <mono/utils/strenc.h>
23 #include <mono/io-layer/io-layer.h>
24 /* FIXME: fix this code to not depend so much on the inetrnals */
25 #include <mono/metadata/class-internals.h>
29 HANDLE ves_icall_System_Diagnostics_Process_GetProcess_internal (guint32 pid)
35 /* GetCurrentProcess returns a pseudo-handle, so use
38 handle=OpenProcess (PROCESS_ALL_ACCESS, TRUE, pid);
41 /* FIXME: Throw an exception */
48 guint32 ves_icall_System_Diagnostics_Process_GetPid_internal (void)
52 return(GetCurrentProcessId ());
55 void ves_icall_System_Diagnostics_Process_Process_free_internal (MonoObject *this,
61 g_message (G_GNUC_PRETTY_FUNCTION ": Closing process %p, handle %p",
65 CloseHandle (process);
68 #define STASH_SYS_ASS(this) \
69 if(system_assembly == NULL) { \
70 system_assembly=this->vtable->klass->image; \
73 static MonoImage *system_assembly=NULL;
75 static guint32 unicode_chars (const gunichar2 *str)
87 static guint32 unicode_bytes (const gunichar2 *str)
93 /* Include the terminators */
101 * compare a null-terminated utf16 string and a normal string.
102 * Can be used only for ascii or latin1 chars.
105 unicode_string_equals (const gunichar2 *str1, const guchar *str2)
107 while (*str1 && *str2) {
113 return *str1 == *str2;
116 static void process_set_field_object (MonoObject *obj, const guchar *fieldname,
119 MonoClassField *field;
122 g_message (G_GNUC_PRETTY_FUNCTION ": Setting field %s to object at %p",
126 field=mono_class_get_field_from_name (mono_object_class (obj),
128 *(MonoObject **)(((char *)obj) + field->offset)=data;
131 static void process_set_field_string (MonoObject *obj, const guchar *fieldname,
132 const gunichar2 *val, guint32 len)
134 MonoClassField *field;
138 g_message (G_GNUC_PRETTY_FUNCTION ": Setting field %s to [%s]",
139 fieldname, g_utf16_to_utf8 (val, len, NULL, NULL, NULL));
142 string=mono_string_new_utf16 (mono_object_domain (obj), val, len);
144 field=mono_class_get_field_from_name (mono_object_class (obj),
146 *(MonoString **)(((char *)obj) + field->offset)=string;
149 static void process_set_field_string_utf8 (MonoObject *obj,
150 const guchar *fieldname,
153 MonoClassField *field;
157 g_message (G_GNUC_PRETTY_FUNCTION ": Setting field %s to [%s]",
161 string=mono_string_new (mono_object_domain (obj), val);
163 field=mono_class_get_field_from_name (mono_object_class (obj),
165 *(MonoString **)(((char *)obj) + field->offset)=string;
168 static void process_set_field_int (MonoObject *obj, const guchar *fieldname,
171 MonoClassField *field;
174 g_message (G_GNUC_PRETTY_FUNCTION ": Setting field %s to %d",
178 field=mono_class_get_field_from_name (mono_object_class (obj),
180 *(guint32 *)(((char *)obj) + field->offset)=val;
183 static void process_set_field_bool (MonoObject *obj, const guchar *fieldname,
186 MonoClassField *field;
189 g_message (G_GNUC_PRETTY_FUNCTION ": Setting field %s to %s",
190 fieldname, val?"TRUE":"FALSE");
193 field=mono_class_get_field_from_name (mono_object_class (obj),
195 *(guint8 *)(((char *)obj) + field->offset)=val;
205 /* Returns a pointer to the value data, because theres no way to know
206 * how big that data is (value_len is set to zero for most blocks :-()
208 static gpointer process_get_versioninfo_block (gpointer data,
211 block->data_len=*((guint16 *)data);
212 data = (char *)data + sizeof(guint16);
213 block->value_len=*((guint16 *)data);
214 data = (char *)data + sizeof(guint16);
216 /* No idea what the type is supposed to indicate */
217 block->type=*((guint16 *)data);
218 data = (char *)data + sizeof(guint16);
219 block->key=((gunichar2 *)data);
221 /* skip over the key (including the terminator) */
222 data=((gunichar2 *)data)+(unicode_chars (block->key)+1);
224 /* align on a 32-bit boundary */
225 data=(gpointer)((char *)data + 3);
226 data=(gpointer)((char *)data - (GPOINTER_TO_INT(data) & 3));
231 /* Returns a pointer to the byte following the Var block */
232 static gpointer process_read_var_block (MonoObject *filever, gpointer data_ptr,
235 /* Not currently interested in the VarFileInfo block. This
236 * might change if language support is needed for file version
237 * strings (VarFileInfo contains lists of supported
242 /* data_ptr is pointing at a Var block of length data_len */
243 data_ptr=process_get_versioninfo_block (data_ptr, &block);
244 data_ptr=((guchar *)data_ptr)+block.value_len;
249 /* Returns a pointer to the byte following the String block, or NULL
250 * if the data read hits padding. We can't recover from this because
251 * the data length does not include padding bytes, so it's not
252 * possible to just return the start position + length.
254 static gpointer process_read_string_block (MonoObject *filever,
260 guint16 string_len=28; /* Length of the StringTable block */
262 /* data_ptr is pointing at an array of one or more String
263 * blocks with total length (not including alignment padding)
266 while(string_len<data_len) {
269 /* align on a 32-bit boundary */
270 data_ptr=(gpointer)((char *)data_ptr + 3);
271 data_ptr=(gpointer)((char *)data_ptr -
272 (GPOINTER_TO_INT(data_ptr) & 3));
274 data_ptr=process_get_versioninfo_block (data_ptr, &block);
275 if(block.data_len==0) {
276 /* We must have hit padding, so give up
280 g_message (G_GNUC_PRETTY_FUNCTION
281 ": Hit 0-length block, giving up");
286 string_len=string_len+block.data_len;
287 value=(gunichar2 *)data_ptr;
288 /* Skip over the value */
289 data_ptr=((gunichar2 *)data_ptr)+block.value_len;
292 if (unicode_string_equals (block.key, "Comments")) {
293 process_set_field_string (filever, "comments", value, unicode_chars (value));
294 } else if (unicode_string_equals (block.key, "CompanyName")) {
295 process_set_field_string (filever, "companyname", value, unicode_chars (value));
296 } else if (unicode_string_equals (block.key, "FileDescription")) {
297 process_set_field_string (filever, "filedescription", value, unicode_chars (value));
298 } else if (unicode_string_equals (block.key, "FileVersion")) {
299 process_set_field_string (filever, "fileversion", value, unicode_chars (value));
300 } else if (unicode_string_equals (block.key, "InternalName")) {
301 process_set_field_string (filever, "internalname", value, unicode_chars (value));
302 } else if (unicode_string_equals (block.key, "LegalCopyright")) {
303 process_set_field_string (filever, "legalcopyright", value, unicode_chars (value));
304 } else if (unicode_string_equals (block.key, "LegalTrademarks")) {
305 process_set_field_string (filever, "legaltrademarks", value, unicode_chars (value));
306 } else if (unicode_string_equals (block.key, "OriginalFilename")) {
307 process_set_field_string (filever, "originalfilename", value, unicode_chars (value));
308 } else if (unicode_string_equals (block.key, "PrivateBuild")) {
309 process_set_field_string (filever, "privatebuild", value, unicode_chars (value));
310 } else if (unicode_string_equals (block.key, "ProductName")) {
311 process_set_field_string (filever, "productname", value, unicode_chars (value));
312 } else if (unicode_string_equals (block.key, "ProductVersion")) {
313 process_set_field_string (filever, "productversion", value, unicode_chars (value));
314 } else if (unicode_string_equals (block.key, "SpecialBuild")) {
315 process_set_field_string (filever, "specialbuild", value, unicode_chars (value));
317 /* Not an error, just not interesting
327 /* returns a pointer to the byte following the Stringtable block, or
328 * NULL if the data read hits padding. We can't recover from this
329 * because the data length does not include padding bytes, so it's not
330 * possible to just return the start position + length
332 static gpointer process_read_stringtable_block (MonoObject *filever,
338 guint16 string_len=36; /* length of the StringFileInfo block */
340 /* data_ptr is pointing at an array of StringTable blocks,
341 * with total length (not including alignment padding) of
345 while(string_len<data_len) {
346 /* align on a 32-bit boundary */
347 data_ptr=(gpointer)((char *)data_ptr + 3);
348 data_ptr=(gpointer)((char *)data_ptr -
349 (GPOINTER_TO_INT(data_ptr) & 3));
351 data_ptr=process_get_versioninfo_block (data_ptr, &block);
352 if(block.data_len==0) {
353 /* We must have hit padding, so give up
357 g_message (G_GNUC_PRETTY_FUNCTION
358 ": Hit 0-length block, giving up");
362 string_len=string_len+block.data_len;
364 language = g_utf16_to_utf8 (block.key, unicode_bytes (block.key), NULL, NULL, NULL);
365 g_strdown (language);
367 /* Kludge: treat en_US as neutral too */
368 if (!strcmp (language, "007f04b0") ||
369 !strcmp (language, "000004b0") ||
370 !strcmp (language, "040904b0")) {
371 /* Got the one we're interested in */
372 process_set_field_string_utf8 (filever, "language",
375 data_ptr=process_read_string_block (filever, data_ptr,
379 /* Some other language. We might want to do
380 * something with this in the future.
382 data_ptr=process_read_string_block (filever, data_ptr,
389 /* Child block hit padding */
391 g_message (G_GNUC_PRETTY_FUNCTION ": Child block hit 0-length block, giving up");
400 static void process_read_fixedfileinfo_block (MonoObject *filever,
401 VS_FIXEDFILEINFO *ffi)
404 g_message (G_GNUC_PRETTY_FUNCTION ": ffi: sig 0x%x, strucver 0x%x, fileverm 0x%x, fileverl 0x%x, prodverm 0x%x, prodverl 0x%x, ffmask 0x%x, ff 0x%x, os 0x%x, type 0x%x, subtype 0x%x, datem 0x%x, datel 0x%x", ffi->dwSignature, ffi->dwStrucVersion, ffi->dwFileVersionMS, ffi->dwFileVersionLS, ffi->dwProductVersionMS, ffi->dwProductVersionLS, ffi->dwFileFlagsMask, ffi->dwFileFlags, ffi->dwFileOS, ffi->dwFileType, ffi->dwFileSubtype, ffi->dwFileDateMS, ffi->dwFileDateLS);
407 process_set_field_int (filever, "filemajorpart",
408 HIWORD (ffi->dwFileVersionMS));
409 process_set_field_int (filever, "fileminorpart",
410 LOWORD (ffi->dwFileVersionMS));
411 process_set_field_int (filever, "filebuildpart",
412 HIWORD (ffi->dwFileVersionLS));
413 process_set_field_int (filever, "fileprivatepart",
414 LOWORD (ffi->dwFileVersionLS));
416 process_set_field_int (filever, "productmajorpart",
417 HIWORD (ffi->dwProductVersionMS));
418 process_set_field_int (filever, "productminorpart",
419 LOWORD (ffi->dwProductVersionMS));
420 process_set_field_int (filever, "productbuildpart",
421 HIWORD (ffi->dwProductVersionLS));
422 process_set_field_int (filever, "productprivatepart",
423 LOWORD (ffi->dwProductVersionLS));
425 process_set_field_bool (filever, "isdebug",
426 ffi->dwFileFlags&VS_FF_DEBUG);
427 process_set_field_bool (filever, "isprerelease",
428 ffi->dwFileFlags&VS_FF_PRERELEASE);
429 process_set_field_bool (filever, "ispatched",
430 ffi->dwFileFlags&VS_FF_PATCHED);
431 process_set_field_bool (filever, "isprivatebuild",
432 ffi->dwFileFlags&VS_FF_PRIVATEBUILD);
433 process_set_field_bool (filever, "isspecialbuild",
434 ffi->dwFileFlags&VS_FF_SPECIALBUILD);
437 static void process_get_fileversion (MonoObject *filever, MonoImage *image)
439 MonoPEResourceDataEntry *version_info;
441 VS_FIXEDFILEINFO *ffi;
444 gint32 data_len; /* signed to guard against underflow */
446 version_info=mono_image_lookup_resource (image,
447 MONO_PE_RESOURCE_ID_VERSION,
450 g_message (G_GNUC_PRETTY_FUNCTION ": image_lookup returned %p",
454 if(version_info==NULL) {
458 data=mono_image_rva_map (image,
459 version_info->rde_data_offset);
464 /* See io-layer/versioninfo.h for the gory details on how this
465 * data is laid out. (data should be pointing to
466 * VS_VERSIONINFO data).
469 data_ptr=process_get_versioninfo_block (data, &block);
471 data_len=block.data_len;
473 if(block.value_len!=sizeof(VS_FIXEDFILEINFO)) {
475 g_message (G_GNUC_PRETTY_FUNCTION
476 ": FIXEDFILEINFO size mismatch");
481 if (!unicode_string_equals (block.key, "VS_VERSION_INFO")) {
483 g_message (G_GNUC_PRETTY_FUNCTION
484 ": VS_VERSION_INFO mismatch");
489 ffi=((VS_FIXEDFILEINFO *)data_ptr);
490 data_ptr = (char *)data_ptr + sizeof(VS_FIXEDFILEINFO);
491 if((ffi->dwSignature!=VS_FFI_SIGNATURE) ||
492 (ffi->dwStrucVersion!=VS_FFI_STRUCVERSION)) {
494 g_message (G_GNUC_PRETTY_FUNCTION
495 ": FIXEDFILEINFO bad signature");
499 process_read_fixedfileinfo_block (filever, ffi);
501 /* Subtract the 92 bytes we've already seen */
504 /* There now follow zero or one StringFileInfo blocks and zero
505 * or one VarFileInfo blocks
507 while(data_len > 0) {
508 /* align on a 32-bit boundary */
509 data_ptr=(gpointer)((char *)data_ptr + 3);
510 data_ptr=(gpointer)((char *)data_ptr -
511 (GPOINTER_TO_INT(data_ptr) & 3));
513 data_ptr=process_get_versioninfo_block (data_ptr, &block);
514 if(block.data_len==0) {
515 /* We must have hit padding, so give up
519 g_message (G_GNUC_PRETTY_FUNCTION
520 ": Hit 0-length block, giving up");
525 data_len=data_len-block.data_len;
527 if (unicode_string_equals (block.key, "VarFileInfo")) {
528 data_ptr=process_read_var_block (filever, data_ptr,
530 } else if (unicode_string_equals (block.key, "StringFileInfo")) {
531 data_ptr=process_read_stringtable_block (filever, data_ptr, block.data_len);
535 g_message (G_GNUC_PRETTY_FUNCTION
536 ": Not a valid VERSIONINFO child block");
542 /* Child block hit padding */
544 g_message (G_GNUC_PRETTY_FUNCTION ": Child block hit 0-length block, giving up");
551 static void process_add_module (GPtrArray *modules, MonoAssembly *ass)
553 MonoClass *proc_class, *filever_class;
554 MonoObject *item, *filever;
555 MonoDomain *domain=mono_domain_get ();
557 const char* filename;
559 /* Build a System.Diagnostics.ProcessModule with the data.
560 * Leave BaseAddress and EntryPointAddress set to NULL,
561 * FileName is ass->image->name, FileVersionInfo is an object
562 * constructed from the PE image data referenced by
563 * ass->image, ModuleMemorySize set to 0, ModuleName the last
564 * component of FileName.
566 proc_class=mono_class_from_name (system_assembly, "System.Diagnostics",
568 item=mono_object_new (domain, proc_class);
570 filever_class=mono_class_from_name (system_assembly,
571 "System.Diagnostics",
573 filever=mono_object_new (domain, filever_class);
576 g_message (G_GNUC_PRETTY_FUNCTION ": recording assembly: FileName [%s] FileVersionInfo [%d.%d.%d.%d], ModuleName [%s]", ass->image->name, ass->aname.major, ass->aname.minor, ass->aname.build, ass->aname.revision, ass->image->name);
579 process_get_fileversion (filever, mono_assembly_get_image (ass));
581 filename = mono_image_get_filename (mono_assembly_get_image (ass));
582 process_set_field_string_utf8 (filever, "filename", filename);
583 process_set_field_string_utf8 (item, "filename", filename);
584 process_set_field_object (item, "version_info", filever);
586 modulename=g_path_get_basename (filename);
587 process_set_field_string_utf8 (item, "modulename", modulename);
590 g_ptr_array_add (modules, item);
593 static void process_scan_modules (gpointer data, gpointer user_data)
595 MonoAssembly *ass=data;
596 GPtrArray *modules=user_data;
598 /* The main assembly is already in the list */
599 if(mono_assembly_get_main () != ass) {
600 process_add_module (modules, ass);
605 /* Returns an array of System.Diagnostics.ProcessModule */
606 MonoArray *ves_icall_System_Diagnostics_Process_GetModules_internal (MonoObject *this)
608 /* I was going to use toolhelp for this, but then realised I
609 * was being an idiot :)
611 * (Toolhelp would give shared libraries open by the runtime,
612 * as well as open assemblies. On windows my tests didnt find
613 * the assemblies loaded by mono either.)
615 GPtrArray *modules_list=g_ptr_array_new ();
621 STASH_SYS_ASS (this);
623 /* Make sure the first entry is the main module */
624 process_add_module (modules_list, mono_assembly_get_main ());
626 mono_assembly_foreach (process_scan_modules, modules_list);
628 /* Build a MonoArray out of modules_list */
629 arr=mono_array_new (mono_domain_get (), mono_get_object_class (),
632 for(i=0; i<modules_list->len; i++) {
633 mono_array_setref (arr, i, g_ptr_array_index (modules_list, i));
636 g_ptr_array_free (modules_list, FALSE);
641 void ves_icall_System_Diagnostics_FileVersionInfo_GetVersionInfo_internal (MonoObject *this, MonoString *filename)
644 guchar *filename_utf8;
648 STASH_SYS_ASS (this);
650 filename_utf8 = mono_string_to_utf8 (filename);
651 image = mono_pe_file_open (filename_utf8, NULL);
652 g_free (filename_utf8);
655 /* FIXME: an exception might be appropriate here */
657 g_message (G_GNUC_PRETTY_FUNCTION ": Failed to load image");
663 process_get_fileversion (this, image);
664 process_set_field_string_utf8 (this, "filename", mono_image_get_filename (image));
666 mono_image_close (image);
669 /* Only used when UseShellExecute is false */
671 quote_path (const gchar *path)
673 gchar *res = g_shell_quote (path);
674 #ifdef PLATFORM_WIN32
687 /* Only used when UseShellExecute is false */
689 complete_path (const gunichar2 *appname, gchar **completed)
694 utf8app = g_utf16_to_utf8 (appname, -1, NULL, NULL, NULL);
695 if (g_path_is_absolute (utf8app)) {
696 *completed = quote_path (utf8app);
701 if (g_file_test (utf8app, G_FILE_TEST_IS_EXECUTABLE) && !g_file_test (utf8app, G_FILE_TEST_IS_DIR)) {
702 *completed = quote_path (utf8app);
707 found = g_find_program_in_path (utf8app);
714 *completed = quote_path (found);
720 MonoBoolean ves_icall_System_Diagnostics_Process_ShellExecuteEx_internal (MonoProcessStartInfo *proc_start_info, MonoProcInfo *process_info)
722 SHELLEXECUTEINFO shellex = {0};
725 shellex.cbSize = sizeof(SHELLEXECUTEINFO);
726 shellex.fMask = SEE_MASK_FLAG_DDEWAIT | SEE_MASK_NOCLOSEPROCESS | SEE_MASK_UNICODE;
727 shellex.nShow = SW_SHOWNORMAL;
729 if (proc_start_info->filename != NULL) {
730 shellex.lpFile = mono_string_chars (proc_start_info->filename);
733 if (proc_start_info->arguments != NULL) {
734 shellex.lpParameters = mono_string_chars (proc_start_info->arguments);
737 if (proc_start_info->verb != NULL &&
738 mono_string_length (proc_start_info->verb) != 0) {
739 shellex.lpVerb = mono_string_chars (proc_start_info->verb);
742 if (proc_start_info->working_directory != NULL &&
743 mono_string_length (proc_start_info->working_directory) != 0) {
744 shellex.lpDirectory = mono_string_chars (proc_start_info->working_directory);
747 ret = ShellExecuteEx (&shellex);
749 process_info->pid = -GetLastError ();
751 process_info->process_handle = shellex.hProcess;
752 process_info->thread_handle = NULL;
753 /* It appears that there's no way to get the pid from a
754 * process handle before windows xp. Really.
756 #ifdef HAVE_GETPROCESSID
757 process_info->pid = GetProcessId (shellex.hProcess);
759 process_info->pid = 0;
761 process_info->tid = 0;
767 MonoBoolean ves_icall_System_Diagnostics_Process_CreateProcess_internal (MonoProcessStartInfo *proc_start_info, HANDLE stdin_handle, HANDLE stdout_handle, HANDLE stderr_handle, MonoProcInfo *process_info)
771 STARTUPINFO startinfo={0};
772 PROCESS_INFORMATION procinfo;
773 gunichar2 *shell_path = NULL;
774 gchar *env_vars = NULL;
775 gboolean free_shell_path = TRUE;
776 #ifdef PLATFORM_WIN32
780 MonoString *cmd = proc_start_info->arguments;
784 startinfo.cb=sizeof(STARTUPINFO);
785 startinfo.dwFlags=STARTF_USESTDHANDLES;
786 startinfo.hStdInput=stdin_handle;
787 startinfo.hStdOutput=stdout_handle;
788 startinfo.hStdError=stderr_handle;
790 shell_path = mono_string_chars (proc_start_info->filename);
791 complete_path (shell_path, &spath);
793 process_info->pid = -ERROR_FILE_NOT_FOUND;
796 #ifdef PLATFORM_WIN32
797 /* Seems like our CreateProcess does not work as the windows one.
798 * This hack is needed to deal with paths containing spaces */
800 free_shell_path = FALSE;
801 tmp = mono_string_to_utf8 (cmd);
802 newcmd = g_strdup_printf ("%s %s", spath, tmp);
803 cmd = mono_string_new_wrapper (newcmd);
807 shell_path = g_utf8_to_utf16 (spath, -1, NULL, NULL, NULL);
811 if (process_info->env_keys != NULL) {
814 MonoString *key, *value;
815 gunichar2 *str, *ptr;
818 for (len = 0, i = 0; i < mono_array_length (process_info->env_keys); i++) {
819 ms = mono_array_get (process_info->env_values, MonoString *, i);
823 len += mono_string_length (ms) * sizeof (gunichar2);
824 ms = mono_array_get (process_info->env_keys, MonoString *, i);
825 len += mono_string_length (ms) * sizeof (gunichar2);
826 len += 2 * sizeof (gunichar2);
829 equals16 = g_utf8_to_utf16 ("=", 1, NULL, NULL, NULL);
830 ptr = str = g_new0 (gunichar2, len + 1);
831 for (i = 0; i < mono_array_length (process_info->env_keys); i++) {
832 value = mono_array_get (process_info->env_values, MonoString *, i);
836 key = mono_array_get (process_info->env_keys, MonoString *, i);
837 memcpy (ptr, mono_string_chars (key), mono_string_length (key) * sizeof (gunichar2));
838 ptr += mono_string_length (key);
840 memcpy (ptr, equals16, sizeof (gunichar2));
843 memcpy (ptr, mono_string_chars (value), mono_string_length (value) * sizeof (gunichar2));
844 ptr += mono_string_length (value);
849 env_vars = (gchar *) str;
852 /* The default dir name is "". Turn that into NULL to mean
853 * "current directory"
855 if(mono_string_length (proc_start_info->working_directory)==0) {
858 dir=mono_string_chars (proc_start_info->working_directory);
861 ret=CreateProcess (shell_path, mono_string_chars (cmd), NULL, NULL, TRUE, CREATE_UNICODE_ENVIRONMENT, env_vars, dir, &startinfo, &procinfo);
868 process_info->process_handle=procinfo.hProcess;
869 /*process_info->thread_handle=procinfo.hThread;*/
870 process_info->thread_handle=NULL;
871 if (procinfo.hThread != NULL)
872 CloseHandle(procinfo.hThread);
873 process_info->pid=procinfo.dwProcessId;
874 process_info->tid=procinfo.dwThreadId;
876 process_info->pid = -GetLastError ();
882 MonoBoolean ves_icall_System_Diagnostics_Process_WaitForExit_internal (MonoObject *this, HANDLE process, gint32 ms)
890 ret=WaitForSingleObjectEx (process, INFINITE, TRUE);
892 ret=WaitForSingleObjectEx (process, ms, TRUE);
894 if(ret==WAIT_OBJECT_0) {
901 gint64 ves_icall_System_Diagnostics_Process_ExitTime_internal (HANDLE process)
905 FILETIME create_time, exit_time, kernel_time, user_time;
909 ret=GetProcessTimes (process, &create_time, &exit_time, &kernel_time,
912 ticks=((guint64)exit_time.dwHighDateTime << 32) +
913 exit_time.dwLowDateTime;
921 gint64 ves_icall_System_Diagnostics_Process_StartTime_internal (HANDLE process)
925 FILETIME create_time, exit_time, kernel_time, user_time;
929 ret=GetProcessTimes (process, &create_time, &exit_time, &kernel_time,
932 ticks=((guint64)create_time.dwHighDateTime << 32) +
933 create_time.dwLowDateTime;
941 gint32 ves_icall_System_Diagnostics_Process_ExitCode_internal (HANDLE process)
947 GetExitCodeProcess (process, &code);
950 g_message (G_GNUC_PRETTY_FUNCTION ": process exit code is %d", code);
956 MonoString *ves_icall_System_Diagnostics_Process_ProcessName_internal (HANDLE process)
961 gunichar2 name[MAX_PATH];
967 ok=EnumProcessModules (process, &mod, sizeof(mod), &needed);
972 len=GetModuleBaseName (process, mod, name, MAX_PATH);
978 g_message (G_GNUC_PRETTY_FUNCTION ": process name is [%s]",
979 g_utf16_to_utf8 (name, -1, NULL, NULL, NULL));
982 string=mono_string_new_utf16 (mono_domain_get (), name, len);
987 /* Returns an array of pids */
988 MonoArray *ves_icall_System_Diagnostics_Process_GetProcesses_internal (void)
992 guint32 needed, count, i;
997 ret=EnumProcesses (pids, sizeof(pids), &needed);
999 /* FIXME: throw an exception */
1003 count=needed/sizeof(guint32);
1004 procs=mono_array_new (mono_domain_get (), mono_get_int32_class (),
1006 for(i=0; i<count; i++) {
1007 mono_array_set (procs, guint32, i, pids[i]);
1013 MonoBoolean ves_icall_System_Diagnostics_Process_GetWorkingSet_internal (HANDLE process, guint32 *min, guint32 *max)
1016 size_t ws_min, ws_max;
1018 MONO_ARCH_SAVE_REGS;
1020 ret=GetProcessWorkingSetSize (process, &ws_min, &ws_max);
1021 *min=(guint32)ws_min;
1022 *max=(guint32)ws_max;
1027 MonoBoolean ves_icall_System_Diagnostics_Process_SetWorkingSet_internal (HANDLE process, guint32 min, guint32 max, MonoBoolean use_min)
1033 MONO_ARCH_SAVE_REGS;
1035 ret=GetProcessWorkingSetSize (process, &ws_min, &ws_max);
1046 ret=SetProcessWorkingSetSize (process, ws_min, ws_max);
1052 ves_icall_System_Diagnostics_Process_Kill_internal (HANDLE process, gint32 sig)
1054 MONO_ARCH_SAVE_REGS;
1056 /* sig == 1 -> Kill, sig == 2 -> CloseMainWindow */
1058 return TerminateProcess (process, -sig);