Ticket #13554: 0001-mimalloc-building-on-Haiku.patch

File 0001-mimalloc-building-on-Haiku.patch, 4.0 KB (added by pulkomandy, 4 years ago)
  • CMakeLists.txt

    From 756c473ebfb62214fcafb31396e95e1d9ed20783 Mon Sep 17 00:00:00 2001
    From: Adrien Destugues <pulkomandy@pulkomandy.tk>
    Date: Mon, 11 May 2020 16:46:33 +0200
    Subject: [PATCH] mimalloc building on Haiku
    
    ---
     CMakeLists.txt              |  4 ++--
     include/mimalloc-internal.h |  7 +++++++
     src/os.c                    |  2 +-
     src/stats.c                 | 15 +++++++++++++++
     4 files changed, 25 insertions(+), 3 deletions(-)
    
    diff --git a/CMakeLists.txt b/CMakeLists.txt
    index e37efcb..59e858f 100644
    a b set(CMAKE_CXX_STANDARD 17)  
    77option(MI_SECURE            "Use full security mitigations (like guard pages, allocation randomization, double-free mitigation, and free-list corruption detection)" OFF)
    88option(MI_DEBUG_FULL        "Use full internal heap invariant checking in DEBUG mode (expensive)" OFF)
    99option(MI_PADDING           "Enable padding to detect heap block overflow (used only in DEBUG mode)" ON)
    10 option(MI_OVERRIDE          "Override the standard malloc interface (e.g. define entry points for malloc() etc)" ON)
     10option(MI_OVERRIDE          "Override the standard malloc interface (e.g. define entry points for malloc() etc)" OFF)
    1111option(MI_XMALLOC           "Enable abort() call on memory allocation failure by default" OFF)
    1212option(MI_SHOW_ERRORS       "Show error and warning messages by default (only enabled by default in DEBUG mode)" OFF)
    1313option(MI_USE_CXX           "Use the C++ compiler to compile the library (instead of the C compiler)" OFF)
    1414option(MI_SEE_ASM           "Generate assembly files" OFF)
    1515option(MI_INTERPOSE         "Use interpose to override standard malloc on macOS" ON)
    1616option(MI_OSX_ZONE          "Use malloc zone to override standard malloc on macOS" OFF) # enables interpose as well
    17 option(MI_LOCAL_DYNAMIC_TLS "Use slightly slower, dlopen-compatible TLS mechanism (Unix)" OFF)
     17option(MI_LOCAL_DYNAMIC_TLS "Use slightly slower, dlopen-compatible TLS mechanism (Unix)" ON)
    1818option(MI_BUILD_SHARED      "Build shared library" ON)
    1919option(MI_BUILD_STATIC      "Build static library" ON)
    2020option(MI_BUILD_OBJECT      "Build object library" ON)
  • include/mimalloc-internal.h

    diff --git a/include/mimalloc-internal.h b/include/mimalloc-internal.h
    index d0c0b3f..a70e4fa 100644
    a b static inline uintptr_t _mi_thread_id(void) mi_attr_noexcept {  
    683683  return (uintptr_t)NtCurrentTeb();
    684684}
    685685
     686#elif defined(__HAIKU__)
     687#include <OS.h>
     688static inline uintptr_t _mi_thread_id(void) mi_attr_noexcept {
     689    // This reduces to a single register load, but is not inlined because the
     690    // OS may change its mind on where to store it.
     691    return find_thread(NULL);
     692}
    686693#elif defined(__GNUC__) && \
    687694      (defined(__x86_64__) || defined(__i386__) || defined(__arm__) || defined(__aarch64__))
    688695
  • src/os.c

    diff --git a/src/os.c b/src/os.c
    index f33cfbc..0ca69a9 100644
    a b static bool mi_os_resetx(void* addr, size_t size, bool reset, mi_stats_t* stats)  
    722722    advice = MADV_DONTNEED;
    723723    err = madvise(start, csize, advice);
    724724  }
    725 #elif defined(__wasi__)
     725#elif defined(__wasi__) || defined(__HAIKU__)
    726726  int err = 0;
    727727#else
    728728  int err = madvise(start, csize, MADV_DONTNEED);
  • src/stats.c

    diff --git a/src/stats.c b/src/stats.c
    index 478f822..816adbe 100644
    a b static void mi_process_info(mi_msecs_t* utime, mi_msecs_t* stime, size_t* peak_r  
    493493  *stime = timeval_secs(&rusage.ru_stime);
    494494}
    495495
     496#elif defined(__HAIKU__)
     497#include <OS.h>
     498
     499static void mi_process_info(mi_msecs_t* utime, mi_msecs_t* stime, size_t* peak_rss, size_t* page_faults, size_t* page_reclaim, size_t* peak_commit) {
     500    team_usage_info usage;
     501    get_team_usage_info(B_CURRENT_TEAM, B_TEAM_USAGE_SELF, &usage);
     502    *utime = usage.user_time / 1000;
     503    *stime = usage.kernel_time / 1000;
     504
     505    // We don't seem to have a way to get the other stats just yet
     506  *peak_rss = 0;
     507  *page_faults = 0;
     508  *page_reclaim = 0;
     509  *peak_commit = 0;
     510}
    496511#else
    497512#ifndef __wasi__
    498513// WebAssembly instances are not processes