From 487b036c284f43fb4ab6640de288773a0750b235 Mon Sep 17 00:00:00 2001 From: Calvin Date: Sun, 12 Feb 2017 21:14:12 -0400 Subject: Restore Haiku support Much of the code was bitrotting as refactors were done. With this, mono-sgen can be compiled. Code in support/ is still broken, however. The compiled binary hasn't been tested yet as a result. Run configure as: LIBS=-ltextencoding ./configure --disable-boehm boehm looks to be a mess to port and diverged from upstream making integration of Haiku support difficult. For now, SGen should be OK. --- configure.ac | 4 ++++ mono/metadata/w32file-unix.c | 2 +- mono/metadata/w32process-unix-haiku.c | 3 ++- mono/metadata/w32process-unix-internals.h | 2 ++ mono/mini/mini-x86.h | 6 ------ mono/utils/Makefile.am | 1 + mono/utils/mono-context.h | 13 ++++++++++--- mono/utils/mono-proclib.c | 2 ++ mono/utils/mono-threads-haiku.c | 19 +++++++++++++++++++ mono/utils/mono-threads-posix.c | 6 ++++++ 10 files changed, 47 insertions(+), 11 deletions(-) create mode 100644 mono/utils/mono-threads-haiku.c diff --git a/configure.ac b/configure.ac index c3a0beb8a94..9f211b3f9e6 100644 --- a/configure.ac +++ b/configure.ac @@ -1910,6 +1910,10 @@ if test x$host_win32 = xno; then # and libpthread does not exist # case "${host}" in + *-*-*haiku*) + # Haiku has pthread in libroot (libc equiv) + AC_CHECK_LIB(pthread, main, LIBS="$LIBS") + ;; *-*-*freebsd*) AC_CHECK_LIB(pthread, main, LIBS="$LIBS -pthread") ;; diff --git a/mono/metadata/w32file-unix.c b/mono/metadata/w32file-unix.c index 9666cb67d9d..cda335d25a6 100644 --- a/mono/metadata/w32file-unix.c +++ b/mono/metadata/w32file-unix.c @@ -4928,7 +4928,7 @@ mono_w32file_get_drive_type(const gunichar2 *root_path_name) return (drive_type); } -#if defined (PLATFORM_MACOSX) || defined (__linux__) || defined(PLATFORM_BSD) || defined(__native_client__) || defined(__FreeBSD_kernel__) +#if defined (PLATFORM_MACOSX) || defined (__linux__) || defined(PLATFORM_BSD) || defined(__native_client__) || defined(__FreeBSD_kernel__) || defined(__HAIKU__) static gchar* get_fstypename (gchar *utfpath) { diff --git a/mono/metadata/w32process-unix-haiku.c b/mono/metadata/w32process-unix-haiku.c index 4311993bb10..3dfee3c6078 100644 --- a/mono/metadata/w32process-unix-haiku.c +++ b/mono/metadata/w32process-unix-haiku.c @@ -4,7 +4,8 @@ #ifdef USE_HAIKU_BACKEND -#include +/* KernelKit.h doesn't include the right headers? */ +#include gchar* mono_w32process_get_name (pid_t pid) diff --git a/mono/metadata/w32process-unix-internals.h b/mono/metadata/w32process-unix-internals.h index 71226c3109d..72fd6088860 100644 --- a/mono/metadata/w32process-unix-internals.h +++ b/mono/metadata/w32process-unix-internals.h @@ -15,6 +15,8 @@ #define USE_BSD_BACKEND #elif defined(__HAIKU__) #define USE_HAIKU_BACKEND +/* Define header for team_info */ +#include #else #define USE_DEFAULT_BACKEND #endif diff --git a/mono/mini/mini-x86.h b/mono/mini/mini-x86.h index 6e04f7d3758..edc0bb19ecc 100644 --- a/mono/mini/mini-x86.h +++ b/mono/mini/mini-x86.h @@ -34,12 +34,6 @@ LONG CALLBACK seh_handler(EXCEPTION_POINTERS* ep); #endif /* HOST_WIN32 */ -#ifdef __HAIKU__ -struct sigcontext { - vregs regs; -}; -#endif /* __HAIKU__ */ - #if defined( __linux__) || defined(__sun) || defined(__APPLE__) || defined(__NetBSD__) || \ defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__OpenBSD__) #define MONO_ARCH_USE_SIGACTION diff --git a/mono/utils/Makefile.am b/mono/utils/Makefile.am index 2172b996ba0..4b051613420 100644 --- a/mono/utils/Makefile.am +++ b/mono/utils/Makefile.am @@ -134,6 +134,7 @@ monoutils_sources = \ mono-threads-netbsd.c \ mono-threads-openbsd.c \ mono-threads-android.c \ + mono-threads-haiku.c \ mono-threads.h \ mono-threads-debug.h \ mono-threads-api.h \ diff --git a/mono/utils/mono-context.h b/mono/utils/mono-context.h index 3a6f44636c8..6e7cf7bd442 100644 --- a/mono/utils/mono-context.h +++ b/mono/utils/mono-context.h @@ -47,6 +47,13 @@ typedef struct __darwin_xmm_reg MonoContextSimdReg; #undef MONO_SIGNAL_USE_UCONTEXT_T #endif +#ifdef __HAIKU__ +/* sigcontext surrogate */ +struct sigcontext { + vregs regs; +}; +#endif + #ifdef HOST_WIN32 /* sigcontext surrogate */ struct sigcontext { @@ -74,14 +81,14 @@ struct sigcontext { # define SC_ESI sc_esi #elif defined(__HAIKU__) # define SC_EAX regs.eax -# define SC_EBX regs._reserved_2[2] +# define SC_EBX regs.ebx # define SC_ECX regs.ecx # define SC_EDX regs.edx # define SC_EBP regs.ebp # define SC_EIP regs.eip # define SC_ESP regs.esp -# define SC_EDI regs._reserved_2[0] -# define SC_ESI regs._reserved_2[1] +# define SC_EDI regs.edi +# define SC_ESI regs.esi #else # define SC_EAX eax # define SC_EBX ebx diff --git a/mono/utils/mono-proclib.c b/mono/utils/mono-proclib.c index 515104efaf6..2f7ef0cfadd 100644 --- a/mono/utils/mono-proclib.c +++ b/mono/utils/mono-proclib.c @@ -20,7 +20,9 @@ #endif #if defined(_POSIX_VERSION) +#if !defined(__HAIKU__) #include +#endif #include #include #ifdef HAVE_SYS_TYPES_H diff --git a/mono/utils/mono-threads-haiku.c b/mono/utils/mono-threads-haiku.c new file mode 100644 index 00000000000..e5c3563902a --- /dev/null +++ b/mono/utils/mono-threads-haiku.c @@ -0,0 +1,19 @@ +#include + +#if defined(__HAIKU__) + +#include +#include +#include + +void +mono_threads_platform_get_stack_bounds (guint8 **staddr, size_t *stsize) +{ + thread_info ti; + get_thread_info(get_pthread_thread_id(pthread_self()), &ti); + + *staddr = ti.stack_base; + *stsize = ti.stack_end - ti.stack_base; +} + +#endif diff --git a/mono/utils/mono-threads-posix.c b/mono/utils/mono-threads-posix.c index dcb7e27d2a1..846ac4023fd 100644 --- a/mono/utils/mono-threads-posix.c +++ b/mono/utils/mono-threads-posix.c @@ -35,6 +35,8 @@ extern int tkill (pid_t tid, int signal); #include +/* FIXME: Haiku lacks pthread_attr_setschedpolicy */ +#if !defined(__HAIKU__) static void reset_priority (pthread_attr_t *attr) { @@ -82,6 +84,7 @@ reset_priority (pthread_attr_t *attr) if (res != 0) g_error ("%s: pthread_attr_setschedparam failed, error: \"%s\" (%d)", __func__, g_strerror (res), res); } +#endif int mono_threads_platform_create_thread (MonoThreadStart thread_fn, gpointer thread_data, gsize* const stack_size, MonoNativeThreadId *out_tid) @@ -121,7 +124,10 @@ mono_threads_platform_create_thread (MonoThreadStart thread_fn, gpointer thread_ g_assert (!res); #endif /* HAVE_PTHREAD_ATTR_SETSTACKSIZE */ +/* FIXME: Haiku lacks pthread_attr_setschedpolicy */ +#if !defined(__HAIKU__) reset_priority (&attr); +#endif if (stack_size) { res = pthread_attr_getstacksize (&attr, &min_stack_size); -- cgit v1.2.3 From ce4977fd6ca732681d3e3c3932fff8f73e5a96b9 Mon Sep 17 00:00:00 2001 From: Calvin Date: Sun, 12 Feb 2017 21:56:09 -0400 Subject: Get support libraries compiling These return no-ops, but its enough to make it happy --- support/serial.c | 5 +++++ support/sys-mman.c | 13 +++++++++++++ support/sys-time.c | 6 ++++++ 3 files changed, 24 insertions(+) diff --git a/support/serial.c b/support/serial.c index ec02e48b5e8..5e3d732c005 100644 --- a/support/serial.c +++ b/support/serial.c @@ -175,6 +175,11 @@ discard_buffer (int fd, gboolean input) gint32 get_bytes_in_buffer (int fd, gboolean input) { +#if defined(__HAIKU__) + /* FIXME: Haiku doesn't support TIOCOUTQ nor FIONREAD on fds */ + return -1; +#define TIOCOUTQ 0 +#endif gint32 retval; if (ioctl (fd, input ? FIONREAD : TIOCOUTQ, &retval) == -1) { diff --git a/support/sys-mman.c b/support/sys-mman.c index 1dd61bc372b..08c1fea9fd3 100644 --- a/support/sys-mman.c +++ b/support/sys-mman.c @@ -88,17 +88,26 @@ Mono_Posix_Syscall_msync (void *start, mph_size_t len, int flags) int Mono_Posix_Syscall_mlock (void *start, mph_size_t len) { +/* FIXME: Haiku lacks support for m(un)lock and mincore */ +#if defined(__HAIKU__) + return ENOSYS; +#else mph_return_if_size_t_overflow (len); return mlock (start, (size_t) len); +#endif } int Mono_Posix_Syscall_munlock (void *start, mph_size_t len) { +#if defined(__HAIKU__) + return ENOSYS; +#else mph_return_if_size_t_overflow (len); return munlock (start, (size_t) len); +#endif } #ifdef HAVE_MREMAP @@ -129,9 +138,13 @@ Mono_Posix_Syscall_mremap (void *old_address, mph_size_t old_size, int Mono_Posix_Syscall_mincore (void *start, mph_size_t length, unsigned char *vec) { +#if defined(__HAIKU__) + return ENOSYS; +#else mph_return_if_size_t_overflow (length); return mincore (start, (size_t) length, (void*)vec); +#endif } #ifdef HAVE_POSIX_MADVISE diff --git a/support/sys-time.c b/support/sys-time.c index a1c0ba0b184..83afa0c8466 100644 --- a/support/sys-time.c +++ b/support/sys-time.c @@ -47,6 +47,11 @@ Mono_Posix_Syscall_settimeofday ( struct Mono_Posix_Timeval *tv, struct Mono_Posix_Timezone *tz) { +#if defined(__HAIKU__) + /* FIXME: Haiku doesn't support this either, consider + using set_real_time_clock instead? */ + return -1; +#else struct timeval _tv = {0}; struct timeval *ptv = NULL; struct timezone _tz = {0}; @@ -67,6 +72,7 @@ Mono_Posix_Syscall_settimeofday ( r = settimeofday (ptv, ptz); return r; +#endif } static inline struct timeval* -- cgit v1.2.3 From 68c190b1d6a167e5255e4d6dce76683b40a62326 Mon Sep 17 00:00:00 2001 From: Calvin Date: Mon, 13 Feb 2017 13:58:05 -0400 Subject: Get Mono running further on Haiku by fixing proclib/threads * 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 | 6 ++++++ mono/utils/mono-proclib.c | 20 +++++++++++++++++--- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/mono/metadata/threads.c b/mono/metadata/threads.c index c756a06c940..14b6f54fd60 100644 --- a/mono/metadata/threads.c +++ b/mono/metadata/threads.c @@ -642,7 +642,13 @@ mono_thread_internal_set_priority (MonoInternalThread *internal, MonoThreadPrior } res = pthread_setschedparam (tid, policy, ¶m); +#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; diff --git a/mono/utils/mono-proclib.c b/mono/utils/mono-proclib.c index 2f7ef0cfadd..294e37a677a 100644 --- a/mono/utils/mono-proclib.c +++ b/mono/utils/mono-proclib.c @@ -33,6 +33,9 @@ #endif #include #endif +#if defined(__HAIKU__) +#include +#endif #if defined(__APPLE__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) #include #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; -- cgit v1.2.3 From 3e2a367d9154f01d3b4fc1dffc0c694415539cd1 Mon Sep 17 00:00:00 2001 From: Calvin Date: Tue, 14 Feb 2017 13:07:52 -0400 Subject: Polish on configure script * Set boehm to disabled * Set threading to use pthreads, not __thread (causes static TLS issues) * Add the library needs for locale (FIXME: does this apply to eglib?) --- configure.ac | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/configure.ac b/configure.ac index 9f211b3f9e6..1ad5cd6d37d 100644 --- a/configure.ac +++ b/configure.ac @@ -334,9 +334,14 @@ case "$host" in CPPFLAGS="$CPPFLAGS -D_REENTRANT -D_THREAD_SAFE" libmono_cflags="-D_REENTRANT -D_THREAD_SAFE" libdl= - LIBS="$LIBS -lnetwork" + dnl FIXME: Does eglib pick this up? + LIBS="$LIBS -lnetwork -;textencoding" need_link_unlink=yes AC_DEFINE(PTHREAD_POINTER_ID) + dnl Haiku does not support static TLS with __thread + with_tls=pthread + dnl Boehm is too much work to backport Haiku support for + support_boehm=no libgc_threads=pthreads use_sigposix=yes ;; @@ -1911,7 +1916,7 @@ if test x$host_win32 = xno; then # case "${host}" in *-*-*haiku*) - # Haiku has pthread in libroot (libc equiv) + dnl Haiku has pthread in libroot (libc equiv) AC_CHECK_LIB(pthread, main, LIBS="$LIBS") ;; *-*-*freebsd*) -- cgit v1.2.3 From 52d4b9dcb79e9d5b0c86e6d9ff297e563d80bdee Mon Sep 17 00:00:00 2001 From: Calvin Date: Tue, 14 Feb 2017 19:05:31 -0400 Subject: Improve build and configure * detect sys/errno.h * Fix errenous LIBS in haiku * use HAVE_MINCORE --- configure.ac | 6 +++++- mono/utils/mono-proclib.c | 2 +- support/sys-mman.c | 3 +-- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/configure.ac b/configure.ac index 1ad5cd6d37d..738689b81d4 100644 --- a/configure.ac +++ b/configure.ac @@ -335,7 +335,7 @@ case "$host" in libmono_cflags="-D_REENTRANT -D_THREAD_SAFE" libdl= dnl FIXME: Does eglib pick this up? - LIBS="$LIBS -lnetwork -;textencoding" + LIBS="$LIBS -lnetwork -ltextencoding" need_link_unlink=yes AC_DEFINE(PTHREAD_POINTER_ID) dnl Haiku does not support static TLS with __thread @@ -2328,6 +2328,10 @@ if test x$host_win32 = xno; then AC_MSG_RESULT(no) ]) + dnl ********************************** + dnl *** Checks for proclib *** + dnl ********************************** + AC_CHECK_HEADER(sys/errno.h, [AC_DEFINE(HAVE_SYS_ERRNO_H, 1, Define to 1 if you have the header file.)]) dnl ********************************** dnl *** Checks for MonoPosixHelper *** dnl ********************************** diff --git a/mono/utils/mono-proclib.c b/mono/utils/mono-proclib.c index 294e37a677a..5f6d145b6da 100644 --- a/mono/utils/mono-proclib.c +++ b/mono/utils/mono-proclib.c @@ -20,7 +20,7 @@ #endif #if defined(_POSIX_VERSION) -#if !defined(__HAIKU__) +#ifdef HAVE_SYS_ERRNO_H #include #endif #include diff --git a/support/sys-mman.c b/support/sys-mman.c index 08c1fea9fd3..afbe4662444 100644 --- a/support/sys-mman.c +++ b/support/sys-mman.c @@ -88,8 +88,7 @@ Mono_Posix_Syscall_msync (void *start, mph_size_t len, int flags) int Mono_Posix_Syscall_mlock (void *start, mph_size_t len) { -/* FIXME: Haiku lacks support for m(un)lock and mincore */ -#if defined(__HAIKU__) +#if !defined(HAVE_MINCORE) return ENOSYS; #else mph_return_if_size_t_overflow (len); -- cgit v1.2.3 From 79f69c8cd7048037ecffd40df223fb60f803cbdb Mon Sep 17 00:00:00 2001 From: Calvin Date: Tue, 14 Feb 2017 19:30:52 -0400 Subject: Fix eglibc configure script on Haiku Now properly recognizes -ltextencoding --- configure.ac | 1 - eglib/configure.ac | 3 +++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index 738689b81d4..a01830680ca 100644 --- a/configure.ac +++ b/configure.ac @@ -334,7 +334,6 @@ case "$host" in CPPFLAGS="$CPPFLAGS -D_REENTRANT -D_THREAD_SAFE" libmono_cflags="-D_REENTRANT -D_THREAD_SAFE" libdl= - dnl FIXME: Does eglib pick this up? LIBS="$LIBS -lnetwork -ltextencoding" need_link_unlink=yes AC_DEFINE(PTHREAD_POINTER_ID) diff --git a/eglib/configure.ac b/eglib/configure.ac index 89f85d18e59..92cd6156f94 100644 --- a/eglib/configure.ac +++ b/eglib/configure.ac @@ -94,6 +94,9 @@ arm*-darwin*|aarch64*-*) i*86-*-darwin*) ORDER=G_LITTLE_ENDIAN ;; +*-*-haiku*) + LDFLAGS="$LDFLAGS -ltextencoding" + ;; *-*-openbsd*) CFLAGS="$CFLAGS -pthread" LDFLAGS="$LDFLAGS -pthread" -- cgit v1.2.3 From 8120d7baade9cf49a46e60a6bccf1428680895b7 Mon Sep 17 00:00:00 2001 From: Calvin Date: Wed, 15 Feb 2017 00:25:34 -0400 Subject: More proper detection of reset_priority, make stub for Haiku --- mono/utils/mono-threads-haiku.c | 6 ++++++ mono/utils/mono-threads-posix.c | 12 ++++-------- mono/utils/mono-threads.h | 7 +++++++ 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/mono/utils/mono-threads-haiku.c b/mono/utils/mono-threads-haiku.c index e5c3563902a..231ff3be8f4 100644 --- a/mono/utils/mono-threads-haiku.c +++ b/mono/utils/mono-threads-haiku.c @@ -6,6 +6,12 @@ #include #include +void +mono_threads_platform_reset_priority(pthread_attr_t *attr) +{ + /* FIXME: Implement this on Haiku */ +} + void mono_threads_platform_get_stack_bounds (guint8 **staddr, size_t *stsize) { diff --git a/mono/utils/mono-threads-posix.c b/mono/utils/mono-threads-posix.c index 846ac4023fd..2b48be021d9 100644 --- a/mono/utils/mono-threads-posix.c +++ b/mono/utils/mono-threads-posix.c @@ -35,10 +35,9 @@ extern int tkill (pid_t tid, int signal); #include -/* FIXME: Haiku lacks pthread_attr_setschedpolicy */ -#if !defined(__HAIKU__) -static void -reset_priority (pthread_attr_t *attr) +#ifdef MONO_THREADS_PLATFORM_HAS_ATTR_SETSCHED +void +mono_threads_platform_reset_priority (pthread_attr_t *attr) { struct sched_param param; gint res; @@ -124,10 +123,7 @@ mono_threads_platform_create_thread (MonoThreadStart thread_fn, gpointer thread_ g_assert (!res); #endif /* HAVE_PTHREAD_ATTR_SETSTACKSIZE */ -/* FIXME: Haiku lacks pthread_attr_setschedpolicy */ -#if !defined(__HAIKU__) - reset_priority (&attr); -#endif + mono_threads_platform_reset_priority (&attr); if (stack_size) { res = pthread_attr_getstacksize (&attr, &min_stack_size); diff --git a/mono/utils/mono-threads.h b/mono/utils/mono-threads.h index 0e77e395663..344fbdec3c8 100644 --- a/mono/utils/mono-threads.h +++ b/mono/utils/mono-threads.h @@ -62,6 +62,10 @@ typedef gsize mono_thread_start_return_t; typedef gsize (*MonoThreadStart)(gpointer); +#if !defined(__HAIKU__) +#define MONO_THREADS_PLATFORM_HAS_ATTR_SETSCHED +#endif /* !defined(__HAIKU__) */ + #endif /* #ifdef HOST_WIN32 */ #ifndef MONO_INFINITE_WAIT @@ -478,6 +482,9 @@ gint mono_threads_suspend_get_suspend_signal (void); gint mono_threads_suspend_get_restart_signal (void); gint mono_threads_suspend_get_abort_signal (void); +#if defined(USE_POSIX_BACKEND) +void mono_threads_platform_reset_priority (pthread_attr_t *attr); +#endif /* defined(USE_POSIX_BACKEND) */ int mono_threads_platform_create_thread (MonoThreadStart thread_fn, gpointer thread_data, gsize* const stack_size, MonoNativeThreadId *out_tid); void mono_threads_platform_get_stack_bounds (guint8 **staddr, size_t *stsize); void mono_threads_platform_init (void); -- cgit v1.2.3 From 530ad57bc96414984e211053910dc8735b0557d0 Mon Sep 17 00:00:00 2001 From: Calvin Date: Thu, 16 Feb 2017 12:36:32 -0400 Subject: Haiku hrev50954 makes this ifdef unnecessary --- mono/metadata/threads.c | 6 ------ 1 file changed, 6 deletions(-) diff --git a/mono/metadata/threads.c b/mono/metadata/threads.c index 14b6f54fd60..c756a06c940 100644 --- a/mono/metadata/threads.c +++ b/mono/metadata/threads.c @@ -642,13 +642,7 @@ mono_thread_internal_set_priority (MonoInternalThread *internal, MonoThreadPrior } res = pthread_setschedparam (tid, policy, ¶m); -#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; -- cgit v1.2.3