Get Mono running further on Haiku by fixing proclib/threads
authorCalvin <calvin@openmailbox.org>
Mon, 13 Feb 2017 17:58:05 +0000 (13:58 -0400)
committerCalvin <calvin@openmailbox.org>
Mon, 27 Feb 2017 15:27:49 +0000 (11:27 -0400)
* proclib: Adapted Andreas' code to the refactored proclib.
  Allocates ahead of time.

* threads: pthread_setschedparam is semantically different on Haiku,
  because it returns positive numbers on success. Handle this
  difference.

With these changes, Mono can now get to the point Roslyn runs, and
fails immediately due to lack of stack walking.

mono/metadata/threads.c
mono/utils/mono-proclib.c

index c756a06c94082952563abe49d4326798d669fb8a..14b6f54fd60769db75639ddfcf241f34790ab80b 100644 (file)
@@ -642,7 +642,13 @@ mono_thread_internal_set_priority (MonoInternalThread *internal, MonoThreadPrior
        }
 
        res = pthread_setschedparam (tid, policy, &param);
+#if defined(__HAIKU__)
+       /* On Haiku, pthread_setschedparam returns a positive number on success,
+           which is the priority, or a negative number, which is the errno. */
+       if (res < 0) {
+#else
        if (res != 0) {
+#endif
                if (res == EPERM) {
                        g_warning ("%s: pthread_setschedparam failed, error: \"%s\" (%d)", __func__, g_strerror (res), res);
                        return;
index 2f7ef0cfadd9a69f450473c00443d219a846ea41..294e37a677a0609ab6271eca29b5c0c39d120702 100644 (file)
@@ -33,6 +33,9 @@
 #endif
 #include <sys/resource.h>
 #endif
+#if defined(__HAIKU__)
+#include <os/kernel/OS.h>
+#endif
 #if defined(__APPLE__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__)
 #include <sys/proc.h>
 #if defined(__APPLE__)
@@ -157,9 +160,20 @@ mono_process_list (int *size)
                *size = res;
        return buf;
 #elif defined(__HAIKU__)
-       /* FIXME: Add back the code from 9185fcc305e43428d0f40f3ee37c8a405d41c9ae */
-       g_assert_not_reached ();
-       return NULL;
+       int32 cookie = 0;
+       int32 i = 0;
+       team_info ti;
+       system_info si;
+
+       get_system_info(&si);
+       void **buf = g_calloc(si.used_teams, sizeof(void*));
+
+       while (get_next_team_info(&cookie, &ti) == B_OK && i < si.used_teams) {
+               buf[i++] = GINT_TO_POINTER (ti.team);
+       }
+       *size = i;
+
+       return buf;
 #else
        const char *name;
        void **buf = NULL;