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)
|
7 | 7 | option(MI_SECURE "Use full security mitigations (like guard pages, allocation randomization, double-free mitigation, and free-list corruption detection)" OFF) |
8 | 8 | option(MI_DEBUG_FULL "Use full internal heap invariant checking in DEBUG mode (expensive)" OFF) |
9 | 9 | option(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) |
| 10 | option(MI_OVERRIDE "Override the standard malloc interface (e.g. define entry points for malloc() etc)" OFF) |
11 | 11 | option(MI_XMALLOC "Enable abort() call on memory allocation failure by default" OFF) |
12 | 12 | option(MI_SHOW_ERRORS "Show error and warning messages by default (only enabled by default in DEBUG mode)" OFF) |
13 | 13 | option(MI_USE_CXX "Use the C++ compiler to compile the library (instead of the C compiler)" OFF) |
14 | 14 | option(MI_SEE_ASM "Generate assembly files" OFF) |
15 | 15 | option(MI_INTERPOSE "Use interpose to override standard malloc on macOS" ON) |
16 | 16 | option(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) |
| 17 | option(MI_LOCAL_DYNAMIC_TLS "Use slightly slower, dlopen-compatible TLS mechanism (Unix)" ON) |
18 | 18 | option(MI_BUILD_SHARED "Build shared library" ON) |
19 | 19 | option(MI_BUILD_STATIC "Build static library" ON) |
20 | 20 | option(MI_BUILD_OBJECT "Build object library" ON) |
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 {
|
683 | 683 | return (uintptr_t)NtCurrentTeb(); |
684 | 684 | } |
685 | 685 | |
| 686 | #elif defined(__HAIKU__) |
| 687 | #include <OS.h> |
| 688 | static 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 | } |
686 | 693 | #elif defined(__GNUC__) && \ |
687 | 694 | (defined(__x86_64__) || defined(__i386__) || defined(__arm__) || defined(__aarch64__)) |
688 | 695 | |
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)
|
722 | 722 | advice = MADV_DONTNEED; |
723 | 723 | err = madvise(start, csize, advice); |
724 | 724 | } |
725 | | #elif defined(__wasi__) |
| 725 | #elif defined(__wasi__) || defined(__HAIKU__) |
726 | 726 | int err = 0; |
727 | 727 | #else |
728 | 728 | int err = madvise(start, csize, MADV_DONTNEED); |
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
|
493 | 493 | *stime = timeval_secs(&rusage.ru_stime); |
494 | 494 | } |
495 | 495 | |
| 496 | #elif defined(__HAIKU__) |
| 497 | #include <OS.h> |
| 498 | |
| 499 | static 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 | } |
496 | 511 | #else |
497 | 512 | #ifndef __wasi__ |
498 | 513 | // WebAssembly instances are not processes |