#include <mono/utils/strenc.h>
#include <mono/utils/mono-proclib.h>
#include <mono/io-layer/io-layer.h>
+#if defined (MINGW_CROSS_COMPILE) && defined (HAVE_GETPROCESSID)
+#undef HAVE_GETPROCESSID
+#endif
+#ifndef HAVE_GETPROCESSID
+#if defined(_MSC_VER) || defined(HAVE_WINTERNL_H)
+#include <winternl.h>
+#ifndef NT_SUCCESS
+#define NT_SUCCESS(status) ((NTSTATUS) (status) >= 0)
+#endif /* !NT_SUCCESS */
+#else /* ! (defined(_MSC_VER) || defined(HAVE_WINTERNL_H)) */
+#include <ddk/ntddk.h>
+#include <ddk/ntapi.h>
+#endif /* (defined(_MSC_VER) || defined(HAVE_WINTERNL_H)) */
+#endif /* !HAVE_GETPROCESSID */
/* FIXME: fix this code to not depend so much on the inetrnals */
#include <mono/metadata/class-internals.h>
g_message ("%s: Closing process %p, handle %p", __func__, this, process);
#endif
-#if TARGET_WIN32
+#if defined(TARGET_WIN32) || defined(HOST_WIN32)
CloseHandle (process);
#else
CloseProcess (process);
return TRUE;
}
-#if defined (MINGW_CROSS_COMPILE) && defined (HAVE_GETPROCESSID)
-#undef HAVE_GETPROCESSID
-#endif
-
#ifndef HAVE_GETPROCESSID
/* Run-time GetProcessId detection for Windows */
#ifdef TARGET_WIN32
gboolean ret;
shellex.cbSize = sizeof(SHELLEXECUTEINFO);
- shellex.fMask = SEE_MASK_FLAG_DDEWAIT | SEE_MASK_NOCLOSEPROCESS | SEE_MASK_UNICODE;
+ shellex.fMask = SEE_MASK_FLAG_DDEWAIT | SEE_MASK_UNICODE;
shellex.nShow = proc_start_info->window_style;
shellex.nShow = (shellex.nShow == 0) ? 1 : (shellex.nShow == 1 ? 0 : shellex.nShow);
}
ret = ShellExecuteEx (&shellex);
- if (ret == FALSE) {
- process_info->pid = -GetLastError ();
- } else {
- process_info->process_handle = shellex.hProcess;
- process_info->thread_handle = NULL;
- /* It appears that there's no way to get the pid from a
- * process handle before windows xp. Really.
- */
-#if defined(HAVE_GETPROCESSID) && !defined(MONO_CROSS_COMPILE)
- process_info->pid = GetProcessId (shellex.hProcess);
-#else
- process_info->pid = 0;
-#endif
- process_info->tid = 0;
- }
-
return (ret);
}
/* The default dir name is "". Turn that into NULL to mean
* "current directory"
*/
- if(mono_string_length (proc_start_info->working_directory)==0) {
+ if(proc_start_info->working_directory == NULL || mono_string_length (proc_start_info->working_directory)==0) {
dir=NULL;
} else {
dir=mono_string_chars (proc_start_info->working_directory);
MonoArray *procs;
gboolean ret;
DWORD needed;
- guint32 count, i;
- DWORD pids[1024];
+ guint32 count;
+ guint32 *pids;
MONO_ARCH_SAVE_REGS;
- ret=EnumProcesses (pids, sizeof(pids), &needed);
- if(ret==FALSE) {
- /* FIXME: throw an exception */
- return(NULL);
- }
-
- count=needed/sizeof(DWORD);
- procs=mono_array_new (mono_domain_get (), mono_get_int32_class (),
- count);
- for(i=0; i<count; i++) {
- mono_array_set (procs, guint32, i, pids[i]);
- }
+ count = 512;
+ do {
+ pids = g_new0 (guint32, count);
+ ret = EnumProcesses (pids, count * sizeof (guint32), &needed);
+ if (ret == FALSE) {
+ MonoException *exc;
+
+ g_free (pids);
+ pids = NULL;
+ exc = mono_get_exception_not_supported ("This system does not support EnumProcesses");
+ mono_raise_exception (exc);
+ g_assert_not_reached ();
+ }
+ if (needed < (count * sizeof (guint32)))
+ break;
+ g_free (pids);
+ pids = NULL;
+ count = (count * 3) / 2;
+ } while (TRUE);
+
+ count = needed / sizeof (guint32);
+ procs = mono_array_new (mono_domain_get (), mono_get_int32_class (), count);
+ memcpy (mono_array_addr (procs, guint32, 0), pids, needed);
+ g_free (pids);
+ pids = NULL;
- return(procs);
+ return procs;
}
MonoBoolean ves_icall_System_Diagnostics_Process_GetWorkingSet_internal (HANDLE process, guint32 *min, guint32 *max)