Haiku support proposal. (#218)
* Haiku support proposal. Basic PAL implementation. This platform does not support TLS modes. * MAP_NORESERVE usage
This commit is contained in:
@@ -168,7 +168,11 @@ if(NOT DEFINED SNMALLOC_ONLY_HEADER_LIBRARY)
|
||||
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /Zi")
|
||||
set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} /DEBUG")
|
||||
else()
|
||||
add_compile_options(-fno-exceptions -fno-rtti -g -ftls-model=initial-exec -fomit-frame-pointer)
|
||||
add_compile_options(-fno-exceptions -fno-rtti -g -fomit-frame-pointer)
|
||||
# Static TLS model unsupported on Haiku
|
||||
if (NOT CMAKE_SYSTEM_NAME MATCHES "Haiku")
|
||||
add_compile_options(-ftls-model=initial-exec)
|
||||
endif()
|
||||
if(SNMALLOC_CI_BUILD OR (${CMAKE_BUILD_TYPE} MATCHES "Debug"))
|
||||
# Get better stack traces in CI and Debug.
|
||||
target_link_libraries(snmalloc_lib INTERFACE "-rdynamic")
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
# include "pal_apple.h"
|
||||
# include "pal_freebsd.h"
|
||||
# include "pal_freebsd_kernel.h"
|
||||
# include "pal_haiku.h"
|
||||
# include "pal_linux.h"
|
||||
# include "pal_netbsd.h"
|
||||
# include "pal_openbsd.h"
|
||||
@@ -31,6 +32,8 @@ namespace snmalloc
|
||||
PALFreeBSDKernel;
|
||||
# elif defined(__FreeBSD__)
|
||||
PALFreeBSD;
|
||||
# elif defined(__HAIKU__)
|
||||
PALHaiku;
|
||||
# elif defined(__NetBSD__)
|
||||
PALNetBSD;
|
||||
# elif defined(__OpenBSD__)
|
||||
|
||||
84
src/pal/pal_haiku.h
Normal file
84
src/pal/pal_haiku.h
Normal file
@@ -0,0 +1,84 @@
|
||||
#pragma once
|
||||
|
||||
#if defined(__HAIKU__)
|
||||
# include "pal_posix.h"
|
||||
|
||||
# include <sys/mman.h>
|
||||
|
||||
namespace snmalloc
|
||||
{
|
||||
/**
|
||||
* Platform abstraction layer for Haiku. This provides features for this
|
||||
* system.
|
||||
*/
|
||||
class PALHaiku : public PALPOSIX<PALHaiku>
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Bitmap of PalFeatures flags indicating the optional features that this
|
||||
* PAL supports.
|
||||
*
|
||||
*/
|
||||
static constexpr uint64_t pal_features = PALPOSIX::pal_features;
|
||||
|
||||
/**
|
||||
* Notify platform that we will not be needing these pages.
|
||||
* Haiku does not provide madvise call per say only the posix equivalent.
|
||||
*/
|
||||
void notify_not_using(void* p, size_t size) noexcept
|
||||
{
|
||||
SNMALLOC_ASSERT(is_aligned_block<page_size>(p, size));
|
||||
posix_madvise(p, size, POSIX_MADV_DONTNEED);
|
||||
}
|
||||
|
||||
/**
|
||||
* OS specific function for zeroing memory
|
||||
* using MAP_NORESERVE for explicit over commit appliance.
|
||||
*/
|
||||
template<bool page_aligned = false>
|
||||
void zero(void* p, size_t size)
|
||||
{
|
||||
if (page_aligned || is_aligned_block<page_size>(p, size))
|
||||
{
|
||||
SNMALLOC_ASSERT(is_aligned_block<page_size>(p, size));
|
||||
void* r = mmap(
|
||||
p,
|
||||
size,
|
||||
PROT_READ | PROT_WRITE,
|
||||
MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED | MAP_NORESERVE,
|
||||
-1,
|
||||
0);
|
||||
|
||||
if (r != MAP_FAILED)
|
||||
return;
|
||||
}
|
||||
|
||||
bzero(p, size);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reserve memory using MAP_NORESERVE for explicit
|
||||
* over commit applicance.
|
||||
*/
|
||||
std::pair<void*, size_t> reserve_at_least(size_t size)
|
||||
{
|
||||
constexpr size_t min_size =
|
||||
bits::is64() ? bits::one_at_bit(32) : bits::one_at_bit(28);
|
||||
auto size_request = bits::max(size, min_size);
|
||||
|
||||
void* p = mmap(
|
||||
nullptr,
|
||||
size_request,
|
||||
PROT_READ | PROT_WRITE,
|
||||
MAP_PRIVATE | MAP_ANONYMOUS | MAP_NORESERVE,
|
||||
-1,
|
||||
0);
|
||||
|
||||
if (p == MAP_FAILED)
|
||||
error("Out of memory");
|
||||
|
||||
return {p, size_request};
|
||||
}
|
||||
};
|
||||
} // namespace snmalloc
|
||||
#endif
|
||||
Reference in New Issue
Block a user