]> granicus.if.org Git - gc/commitdiff
Initial support of Haiku/amd64
authorCalvin Hill <calvin@hakobaito.co.uk>
Tue, 23 Jan 2018 14:54:59 +0000 (17:54 +0300)
committerIvan Maidanski <ivmai@mail.ru>
Tue, 17 Apr 2018 19:55:38 +0000 (22:55 +0300)
(back-port of commits 847927f2396ce1 from 'master')

* configure.ac (GC_HAIKU_THREADS): New AH_TEMPLATE.
* configure.ac [THREADS=posix && host=*-*-haiku*] (GC_THREADS,
_REENTRANT): Define macro.
* include/gc_config_macros.h [!GC_THREADS && GC_HAIKU_THREADS]
(GC_THREADS): Likewise.
* include/gc_config_macros.h [GC_THREADS && __HAIKU__]
(GC_HAIKU_THREADS): Likewise.
* include/gc_config_macros.h [__HAIKU__ && !GC_CAN_SAVE_CALL_STACKS]
(GC_ADD_CALLER): Define macro.
* include/private/gcconfig.h [__HAIKU__ && _X86_] (I386, HAIKU,
mach_type_known): Likewise.
* include/private/gcconfig.h [__HAIKU__ && (__amd64__ || __x86_64__)]
(X86_64, HAIKU, mach_type_known): Likewise.
* include/private/gcconfig.h [I386 && HAIKU] (DYNAMIC_LOADING,
MPROTECT_VDB): Likewise.
* include/private/gcconfig.h [X86_64 && HAIKU] (OS_TYPE, GETPAGESIZE,
DYNAMIC_LOADING, MPROTECT_VDB, HEURISTIC2, SEARCH_FOR_DATA_START):
Likewise.
* include/private/gcconfig.h [HAIKU] (UNIX_LIKE, GET_MEM): Likewise.
* os_dep.c [MPROTECT_VDB && !DARWIN && !MSWIN32 && !MSWINCE
&& HAIKU] (CODE_OK): Likewise.
* include/private/gcconfig.h [UNIX_LIKE && HAIKU] (NO_GETCONTEXT):
Likewise.
* dyn_load.c [HAIKU] (GC_register_dynamic_libraries): Implement.
* os_dep.c [HAIKU] (GC_haiku_get_mem): Likewise.
* include/private/gcconfig.h (BEOS): Rename to HAIKU.
* os_dep.c (BEOS): Likewise.
* include/private/gcconfig.h [I386 && HAIKU] (OS_TYPE): Change value
to "HAIKU".
* include/private/gcconfig.h [X86_64 && HAIKU]: Include OS.h.
* include/private/gcconfig.h [HAIKU] (GC_haiku_get_mem): Declare
prototype.
* include/private/thread_local_alloc.h [GC_HAIKU_THREADS]
(USE_PTHREAD_SPECIFIC): Likewise.
* os_dep.c [(NEED_FIND_LIMIT || UNIX_LIKE) && HAIKU] (old_segv_act):
Define static variable.
* os_dep.c [(NEED_FIND_LIMIT || UNIX_LIKE) && HAIKU]
(GC_set_and_save_fault_handler): Use old_segv_act; call
sigaction(SIGSEGV).
* os_dep.c [NEED_FIND_LIMIT || (USE_PROC_FOR_LIBRARIES && THREADS)]
(GC_reset_fault_handler): Likewise.
* os_dep.c [MPROTECT_VDB && !DARWIN && !USE_WINALLOC && HAIKU]: Do not
include sys/syscall.h.
* pthread_support.c [GC_HAIKU_THREADS] (GC_get_nprocs): Define function.

configure.ac
dyn_load.c
include/gc_config_macros.h
include/private/gcconfig.h
include/private/thread_local_alloc.h
os_dep.c
pthread_support.c

index da9cded03c566a92638a9b1fb6c1ab47cd0c1c50..67d9a6f36d03163993c03cc598b9c58621c1fbcf 100644 (file)
@@ -140,6 +140,7 @@ AH_TEMPLATE([GC_AIX_THREADS],       [Define to support IBM AIX threads.])
 AH_TEMPLATE([GC_DARWIN_THREADS],    [Define to support Darwin pthreads.])
 AH_TEMPLATE([GC_FREEBSD_THREADS],   [Define to support FreeBSD pthreads.])
 AH_TEMPLATE([GC_GNU_THREADS],       [Define to support GNU pthreads.])
+AH_TEMPLATE([GC_HAIKU_THREADS],     [Define to support Haiku pthreads.])
 AH_TEMPLATE([GC_HPUX_THREADS],      [Define to support HP/UX 11 pthreads.])
 AH_TEMPLATE([GC_IRIX_THREADS],      [Define to support Irix pthreads.])
 AH_TEMPLATE([GC_LINUX_THREADS],     [Define to support pthreads on Linux.])
@@ -201,6 +202,10 @@ case "$THREADS" in
         AC_DEFINE(GC_AIX_THREADS)
         AC_DEFINE(_REENTRANT)
         ;;
+     *-*-haiku*)
+        AC_DEFINE(GC_HAIKU_THREADS)
+        AC_DEFINE(_REENTRANT)
+        ;;
      *-*-hpux11*)
         AC_MSG_WARN("Only HP/UX 11 POSIX threads are supported.")
         AC_DEFINE(GC_HPUX_THREADS)
index 0f36f7779ce59fa658735cb1784b0c5ee63fc947..b83dcb7193052c2a05358668b9fbfb2c2e57c596 100644 (file)
@@ -58,7 +58,8 @@ STATIC GC_has_static_roots_func GC_has_static_roots = 0;
     && !(defined(ALPHA) && defined(OSF1)) \
     && !(defined(FREEBSD) && defined(__ELF__)) \
     && !((defined(LINUX) || defined(NACL)) && defined(__ELF__)) \
-    && !(defined(NETBSD) && defined(__ELF__)) && !defined(HURD) \
+    && !(defined(NETBSD) && defined(__ELF__)) \
+    && !defined(HAIKU) && !defined(HURD) \
     && !(defined(OPENBSD) && (defined(__ELF__) || defined(M68K))) \
     && !defined(CPPCHECK)
 # error We only know how to find data segments of dynamic libraries for above.
@@ -1490,6 +1491,21 @@ GC_INNER GC_bool GC_register_main_static_data(void)
 
 #endif /* DARWIN */
 
+#if defined(HAIKU)
+# include <kernel/image.h>
+
+  GC_INNER void GC_register_dynamic_libraries(void)
+  {
+    image_info info;
+    int32 cookie = 0;
+
+    while (get_next_image_info(0, &cookie, &info) == B_OK) {
+      ptr_t data = (ptr_t)info.data;
+      GC_add_roots_inner(data, data + info.data_size, TRUE);
+    }
+  }
+#endif /* HAIKU */
+
 #elif defined(PCR)
 
 # include "il/PCR_IL.h"
index 8c8991292178f69d01e28509f6f5c1d66c6232e3..d9885bb7c896e686273f85a2b2f5243bd2bce45b 100644 (file)
@@ -64,7 +64,8 @@
 
 #if defined(GC_AIX_THREADS) || defined(GC_DARWIN_THREADS) \
     || defined(GC_DGUX386_THREADS) || defined(GC_FREEBSD_THREADS) \
-    || defined(GC_GNU_THREADS) || defined(GC_HPUX_THREADS) \
+    || defined(GC_GNU_THREADS) \
+    || defined(GC_HAIKU_THREADS) || defined(GC_HPUX_THREADS) \
     || defined(GC_IRIX_THREADS) || defined(GC_LINUX_THREADS) \
     || defined(GC_NETBSD_THREADS) || defined(GC_OPENBSD_THREADS) \
     || defined(GC_OSF1_THREADS) || defined(GC_SOLARIS_THREADS) \
@@ -94,6 +95,8 @@
 #   define GC_SOLARIS_THREADS
 # elif defined(__APPLE__) && defined(__MACH__)
 #   define GC_DARWIN_THREADS
+# elif defined(__HAIKU__)
+#   define GC_HAIKU_THREADS
 # elif defined(__OpenBSD__)
 #   define GC_OPENBSD_THREADS
 # elif !defined(GC_LINUX_THREADS) && !defined(GC_HPUX_THREADS) \
 /* This may also be desirable if it is possible but expensive to        */
 /* retrieve the call chain.                                             */
 #if (defined(__linux__) || defined(__NetBSD__) || defined(__OpenBSD__) \
-     || defined(__FreeBSD__) || defined(__DragonFly__) \
+     || defined(__FreeBSD__) || defined(__DragonFly__) || defined(__HAIKU__) \
      || defined(__FreeBSD_kernel__) \
      || defined(PLATFORM_ANDROID) || defined(__ANDROID__)) \
     && !defined(GC_CAN_SAVE_CALL_STACKS)
index 086c3c3d57719b0bae833ac56e7691a187047500..052e773a4e3e43b81be03ebd457f47cc0a881db5 100644 (file)
 #   endif
 #   define mach_type_known
 # endif
-# if defined(__BEOS__) && defined(_X86_)
+# if (defined(__BEOS__) || defined(__HAIKU__)) && defined(_X86_)
 #    define I386
-#    define BEOS
+#    define HAIKU
+#    define mach_type_known
+# endif
+# if defined(__HAIKU__) && (defined(__amd64__) || defined(__x86_64__))
+#    define X86_64
+#    define HAIKU
 #    define mach_type_known
 # endif
 # if defined(OPENBSD) && defined(__amd64__)
 #       define DATASTART ((ptr_t)((((word)(etext)) + 0xfff) & ~0xfff))
 #       define STACKBOTTOM ((ptr_t)0x3ffff000)
 #   endif
-#   ifdef BEOS
-#     define OS_TYPE "BEOS"
+#   ifdef HAIKU
+#     define OS_TYPE "HAIKU"
 #     include <OS.h>
 #     define GETPAGESIZE() (unsigned)B_PAGE_SIZE
       extern int etext[];
 #     define DATASTART ((ptr_t)((((word)(etext)) + 0xfff) & ~0xfff))
+#     define DYNAMIC_LOADING
+#     define MPROTECT_VDB
 #   endif
 #   ifdef SOLARIS
 #       define OS_TYPE "SOLARIS"
 #           define SEARCH_FOR_DATA_START
 #       endif
 #   endif
+#   ifdef HAIKU
+#     define OS_TYPE "HAIKU"
+#     include <OS.h>
+#     define GETPAGESIZE() (unsigned)B_PAGE_SIZE
+#     define HEURISTIC2
+#     define SEARCH_FOR_DATA_START
+#     define DYNAMIC_LOADING
+#     define MPROTECT_VDB
+#   endif
 #   ifdef SOLARIS
 #       define OS_TYPE "SOLARIS"
 #       define ELF_CLASS ELFCLASS64
 
 #if defined(SVR4) || defined(LINUX) || defined(IRIX5) || defined(HPUX) \
     || defined(OPENBSD) || defined(NETBSD) || defined(FREEBSD) \
-    || defined(DGUX) || defined(BSD) || defined(HURD) \
+    || defined(DGUX) || defined(BSD) || defined(HAIKU) || defined(HURD) \
     || defined(AIX) || defined(DARWIN) || defined(OSF1)
 # define UNIX_LIKE      /* Basic Unix-like system calls work.   */
 #endif
 # define DEFAULT_VDB
 #endif
 
-#if ((defined(UNIX_LIKE) && (defined(DARWIN) || defined(HURD) \
-                             || defined(OPENBSD) || defined(ARM32) \
-                             || defined(MIPS) || defined(AVR32) \
-                             || defined(OR1K) || defined(NIOS2))) \
+#if ((defined(UNIX_LIKE) && (defined(DARWIN) || defined(HAIKU) \
+                             || defined(HURD) || defined(OPENBSD) \
+                             || defined(ARM32) \
+                             || defined(AVR32) || defined(MIPS) \
+                             || defined(NIOS2) || defined(OR1K))) \
      || (defined(LINUX) && !defined(__gnu_linux__)) \
      || (defined(RTEMS) && defined(I386)) || defined(PLATFORM_ANDROID)) \
     && !defined(NO_GETCONTEXT)
 # elif defined(SN_TARGET_PS3)
     void *ps3_get_mem(size_t bytes);
 #   define GET_MEM(bytes) (struct hblk*)ps3_get_mem(bytes)
+# elif defined(HAIKU)
+    ptr_t GC_haiku_get_mem(size_t bytes);
+#   define GET_MEM(bytes) (struct hblk*)GC_haiku_get_mem(bytes)
 # else
     ptr_t GC_unix_get_mem(size_t bytes);
 #   define GET_MEM(bytes) (struct hblk *)GC_unix_get_mem(bytes)
index 7e7627c7b56aadb5ed87b67b41cdaec67761f258..36e8c6d71ddf5939837478ad1eea8e53c57f3e51 100644 (file)
@@ -59,7 +59,8 @@
 # elif defined(GC_DGUX386_THREADS) || defined(GC_OSF1_THREADS) \
        || defined(GC_AIX_THREADS) || defined(GC_DARWIN_THREADS) \
        || defined(GC_FREEBSD_THREADS) || defined(GC_NETBSD_THREADS) \
-       || defined(GC_LINUX_THREADS) || defined(GC_RTEMS_PTHREADS)
+       || defined(GC_LINUX_THREADS) || defined(GC_HAIKU_THREADS) \
+       || defined(GC_RTEMS_PTHREADS)
 #   define USE_PTHREAD_SPECIFIC
 # elif defined(GC_HPUX_THREADS)
 #   ifdef __GNUC__
index 64a84553996b35cd2e51242c13d1ac6958d9727b..f2c549b803ba952f64d1eb267c74a73b4c12d047 100644 (file)
--- a/os_dep.c
+++ b/os_dep.c
@@ -829,7 +829,7 @@ GC_INNER size_t GC_page_size = 0;
   }
 #endif /* !MSWIN32 */
 
-#ifdef BEOS
+#ifdef HAIKU
 # include <kernel/OS.h>
 
   GC_API int GC_CALL GC_get_stack_base(struct GC_stack_base *sb)
@@ -840,7 +840,7 @@ GC_INNER size_t GC_page_size = 0;
     return GC_SUCCESS;
   }
 # define HAVE_GET_STACK_BASE
-#endif /* BEOS */
+#endif /* HAIKU */
 
 #ifdef OS2
   GC_API int GC_CALL GC_get_stack_base(struct GC_stack_base *sb)
@@ -869,7 +869,8 @@ GC_INNER size_t GC_page_size = 0;
     typedef void (*GC_fault_handler_t)(int);
 
 #   if defined(SUNOS5SIGS) || defined(IRIX5) || defined(OSF1) \
-       || defined(HURD) || defined(FREEBSD) || defined(NETBSD)
+       || defined(HAIKU) || defined(HURD) || defined(FREEBSD) \
+       || defined(NETBSD)
         static struct sigaction old_segv_act;
 #       if defined(_sigargs) /* !Irix6.x */ \
            || defined(HURD) || defined(NETBSD) || defined(FREEBSD)
@@ -885,7 +886,8 @@ GC_INNER size_t GC_page_size = 0;
     GC_INNER void GC_set_and_save_fault_handler(GC_fault_handler_t h)
     {
 #       if defined(SUNOS5SIGS) || defined(IRIX5) || defined(OSF1) \
-            || defined(HURD) || defined(FREEBSD) || defined(NETBSD)
+           || defined(HAIKU) || defined(HURD) || defined(FREEBSD) \
+           || defined(NETBSD)
           struct sigaction act;
 
           act.sa_handler = h;
@@ -949,7 +951,8 @@ GC_INNER size_t GC_page_size = 0;
     GC_INNER void GC_reset_fault_handler(void)
     {
 #       if defined(SUNOS5SIGS) || defined(IRIX5) || defined(OSF1) \
-           || defined(HURD) || defined(FREEBSD) || defined(NETBSD)
+           || defined(HAIKU) || defined(HURD) || defined(FREEBSD) \
+           || defined(NETBSD)
           (void) sigaction(SIGSEGV, &old_segv_act, 0);
 #         if defined(IRIX5) && defined(_sigargs) /* Irix 5.x, not 6.x */ \
              || defined(HURD) || defined(NETBSD)
@@ -1190,7 +1193,7 @@ GC_INNER size_t GC_page_size = 0;
     return (ptr_t)GC_get_main_symbian_stack_base();
   }
 # define GET_MAIN_STACKBASE_SPECIAL
-#elif !defined(BEOS) && !defined(AMIGA) && !defined(OS2) \
+#elif !defined(AMIGA) && !defined(HAIKU) && !defined(OS2) \
       && !defined(MSWIN32) && !defined(MSWINCE) && !defined(CYGWIN32) \
       && !defined(GC_OPENBSD_THREADS) \
       && (!defined(GC_SOLARIS_THREADS) || defined(_STRICT_STDC))
@@ -1291,7 +1294,7 @@ GC_INNER size_t GC_page_size = 0;
     return(result);
   }
 # define GET_MAIN_STACKBASE_SPECIAL
-#endif /* !AMIGA, !BEOS, !OPENBSD, !OS2, !Windows */
+#endif /* !AMIGA, !HAIKU, !OPENBSD, !OS2, !Windows */
 
 #if (defined(HAVE_PTHREAD_ATTR_GET_NP) || defined(HAVE_PTHREAD_GETATTR_NP)) \
     && defined(THREADS) && !defined(HAVE_GET_STACK_BASE)
@@ -2427,6 +2430,19 @@ void * os2_alloc(size_t bytes)
 # undef GC_AMIGA_AM
 #endif
 
+#if defined(HAIKU)
+# include <stdlib.h>
+  ptr_t GC_haiku_get_mem(size_t bytes)
+  {
+    void* mem;
+
+    GC_ASSERT(GC_page_size != 0);
+    if (posix_memalign(&mem, GC_page_size, bytes) == 0)
+      return mem;
+    return NULL;
+  }
+#endif /* HAIKU */
+
 #ifdef USE_MUNMAP
 
 /* For now, this only works on Win32/WinCE and some Unix-like   */
@@ -3023,7 +3039,9 @@ GC_API GC_push_other_roots_proc GC_CALL GC_get_push_other_roots(void)
 # elif !defined(USE_WINALLOC)
 #   include <sys/mman.h>
 #   include <signal.h>
-#   include <sys/syscall.h>
+#   if !defined(HAIKU)
+#     include <sys/syscall.h>
+#   endif
 
 #   define PROTECT(addr, len) \
         if (mprotect((caddr_t)(addr), (size_t)(len), \
@@ -3183,7 +3201,7 @@ GC_API GC_push_other_roots_proc GC_CALL GC_get_push_other_roots(void)
 #     define CODE_OK (si -> si_code == 2 /* experimentally determined */)
 #   elif defined(IRIX5)
 #     define CODE_OK (si -> si_code == EACCES)
-#   elif defined(HURD)
+#   elif defined(HAIKU) || defined(HURD)
 #     define CODE_OK TRUE
 #   elif defined(LINUX)
 #     define CODE_OK TRUE
index bfc4c7e372281ca744f9b005f0a10cdc05a2238e..f0b8e929d224773657edfb71b7d5e9b9e2b63b9c 100644 (file)
@@ -873,7 +873,8 @@ STATIC void GC_remove_all_threads_but_me(void)
 # define GC_get_nprocs() pthread_num_processors_np()
 
 #elif defined(GC_OSF1_THREADS) || defined(GC_AIX_THREADS) \
-      || defined(GC_SOLARIS_THREADS) || defined(GC_GNU_THREADS) \
+      || defined(GC_HAIKU_THREADS) || defined(GC_SOLARIS_THREADS) \
+      || defined(GC_GNU_THREADS) \
       || defined(PLATFORM_ANDROID) || defined(NACL)
   GC_INLINE int GC_get_nprocs(void)
   {