From 4d22e92d6dcbf33c8bec1ba1438115f51fdced29 Mon Sep 17 00:00:00 2001 From: David CARLIER Date: Sat, 27 Jun 2020 16:20:43 +0100 Subject: [PATCH] Haiku build fix proposal (#17117) ##sys --- configure | 11 ++++++++-- configure.acr | 11 ++++++++-- libr/include/r_types.h | 9 ++++++++- libr/io/p/io_gprobe.c | 2 +- libr/util/sys.c | 20 +++++++++++++++++++ .../internal/jemalloc_internal_decls.h | 2 +- 6 files changed, 48 insertions(+), 7 deletions(-) diff --git a/configure b/configure index 50a999725e..66388e418e 100755 --- a/configure +++ b/configure @@ -646,7 +646,10 @@ if [ "$HOST_OS" = "openbsd" ]; then USEROSTYPE="bsd" else if [ "$HOST_OS" = "darwin" ]; then -USEROSTYPE="darwin"; fi; fi; fi; fi; fi; fi; fi; fi; fi; fi; fi; fi +USEROSTYPE="darwin" +else +if [ "$HOST_OS" = "haiku" ]; then +USEROSTYPE="haiku"; fi; fi; fi; fi; fi; fi; fi; fi; fi; fi; fi; fi; fi if [ "$LIBVERSION" = "xxx" ]; then LIBVERSION="$VERSION"; fi if [ "$USEROSTYPE" = "gnulinux" ]; then @@ -673,8 +676,12 @@ if [ "$USEROSTYPE" = "solaris" ]; then HAVE_PTRACE="0" USE_PTRACE_WRAP="0" else +if [ "$USEROSTYPE" = "haiku" ]; then +HAVE_PTRACE="0" +USE_PTRACE_WRAP="0" +else HAVE_PTRACE="1" -USE_PTRACE_WRAP="0"; fi; fi; fi; fi; fi +USE_PTRACE_WRAP="0"; fi; fi; fi; fi; fi; fi if [ "$DEBUGGER" = "0" ]; then HAVE_PTRACE="0"; fi if [ "$WANT_PTRACE_WRAP" = "0" ]; then diff --git a/configure.acr b/configure.acr index 854d96d266..15dbdd424e 100644 --- a/configure.acr +++ b/configure.acr @@ -183,7 +183,10 @@ IFEQ USEROSTYPE auto ; { }{ IFEQ HOST_OS darwin ; { USEROSTYPE = darwin ; - } } } } } } } } } } } + }{ + IFEQ HOST_OS haiku ; { + USEROSTYPE = haiku ; + } } } } } } } } } } } } } (( this hack is required for openbsd ports )) @@ -217,10 +220,14 @@ IFEQ USEROSTYPE mingw32 ; { IFEQ USEROSTYPE solaris ; { HAVE_PTRACE = 0 ; USE_PTRACE_WRAP = 0 ; +}{ +IFEQ USEROSTYPE haiku ; { + HAVE_PTRACE = 0 ; + USE_PTRACE_WRAP = 0 ; }{ HAVE_PTRACE = 1 ; USE_PTRACE_WRAP = 0 ; -} } } } } +} } } } } } IFNOT DEBUGGER { HAVE_PTRACE = 0 ; diff --git a/libr/include/r_types.h b/libr/include/r_types.h index 9e557232d5..b1e65f0af9 100644 --- a/libr/include/r_types.h +++ b/libr/include/r_types.h @@ -140,7 +140,7 @@ static inline struct tm *gmtime_r(const time_t *t, struct tm *r) { return (gmtime_s(r, t))? NULL : r; } #endif -#if defined(EMSCRIPTEN) || defined(__linux__) || defined(__APPLE__) || defined(__GNU__) || defined(__ANDROID__) || defined(__QNX__) || defined(__sun) +#if defined(EMSCRIPTEN) || defined(__linux__) || defined(__APPLE__) || defined(__GNU__) || defined(__ANDROID__) || defined(__QNX__) || defined(__sun) || defined(__HAIKU__) #define __BSD__ 0 #define __UNIX__ 1 #endif @@ -354,6 +354,11 @@ static inline void *r_new_copy(int size, void *data) { #include #include #include +#ifdef __HAIKU__ +// Original macro cast it to clockid_t +#undef CLOCK_MONOTONIC +#define CLOCK_MONOTONIC 0 +#endif #endif #ifndef HAVE_EPRINTF @@ -593,6 +598,8 @@ enum { #define R_SYS_OS "openbsd" #elif defined (__FreeBSD__) || defined (__FreeBSD_kernel__) #define R_SYS_OS "freebsd" +#elif defined (__HAIKU__) +#define R_SYS_OS "haiku" #else #define R_SYS_OS "unknown" #endif diff --git a/libr/io/p/io_gprobe.c b/libr/io/p/io_gprobe.c index ad4017d3d8..50b1b39393 100644 --- a/libr/io/p/io_gprobe.c +++ b/libr/io/p/io_gprobe.c @@ -26,7 +26,7 @@ #include #else -#if __linux__ || __APPLE__ || __OpenBSD__ || __FreeBSD__ || __NetBSD__ || __DragonFly__ +#if __linux__ || __APPLE__ || __OpenBSD__ || __FreeBSD__ || __NetBSD__ || __DragonFly__ || __HAIKU__ #include #include #else diff --git a/libr/util/sys.c b/libr/util/sys.c index f35dd34e0f..aaaf1e2616 100644 --- a/libr/util/sys.c +++ b/libr/util/sys.c @@ -20,6 +20,10 @@ # define FREEBSD_WITH_BACKTRACE # endif #endif +#if defined(__HAIKU__) +# include +# include +#endif #include #include #include @@ -1175,6 +1179,22 @@ R_API char *r_sys_pid_to_path(int pid) { if (ret != 0) { return NULL; } +#elif __HAIKU__ + char pathbuf[MAXPATHLEN]; + int32_t group = 0; + image_info ii; + + while (get_next_image_info (0, &group, &ii) == B_OK) { + if (ii.type == B_APP_IMAGE) { + break; + } + } + + if (ii.type == B_APP_IMAGE) { + r_str_ncpy (pathbuf, ii.name, MAXPATHLEN); + } else { + pathbuf[0] = '\0'; + } #else char buf[128], pathbuf[1024]; snprintf (buf, sizeof (buf), "/proc/%d/exe", pid); diff --git a/shlr/heap/include/r_jemalloc/internal/jemalloc_internal_decls.h b/shlr/heap/include/r_jemalloc/internal/jemalloc_internal_decls.h index c907d91096..52dae8bcba 100644 --- a/shlr/heap/include/r_jemalloc/internal/jemalloc_internal_decls.h +++ b/shlr/heap/include/r_jemalloc/internal/jemalloc_internal_decls.h @@ -9,7 +9,7 @@ #else # include # include -# if !defined(__pnacl__) && !defined(__native_client__) +# if !defined(__pnacl__) && !defined(__native_client__) && !defined(__HAIKU__) # include # if !defined(SYS_write) && defined(__NR_write) # define SYS_write __NR_write