- 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;