add android support (#171)
* adjust for android * update docs * add const qualifier to `alloc_size` * check const qualifier in cmake
This commit is contained in:
@@ -457,7 +457,7 @@ namespace snmalloc
|
||||
return pointer_cast<void>(external_address<location>(p));
|
||||
}
|
||||
|
||||
static size_t alloc_size(void* p)
|
||||
static size_t alloc_size(const void* p)
|
||||
{
|
||||
// This must be called on an external pointer.
|
||||
size_t size = ChunkMap::get(address_cast(p));
|
||||
|
||||
@@ -39,9 +39,10 @@ namespace snmalloc
|
||||
return OS_PAGE_SIZE;
|
||||
}
|
||||
|
||||
static Mediumslab* get(void* p)
|
||||
static Mediumslab* get(const void* p)
|
||||
{
|
||||
return pointer_align_down<SUPERSLAB_SIZE, Mediumslab>(p);
|
||||
return pointer_align_down<SUPERSLAB_SIZE, Mediumslab>(
|
||||
const_cast<void*>(p));
|
||||
}
|
||||
|
||||
void init(RemoteAllocator* alloc, sizeclass_t sc, size_t rsize)
|
||||
|
||||
@@ -140,9 +140,9 @@ namespace snmalloc
|
||||
return (slab_end - allocation_start) % size == 0;
|
||||
}
|
||||
|
||||
static Slab* get_slab(void* p)
|
||||
static Slab* get_slab(const void* p)
|
||||
{
|
||||
return pointer_align_down<SLAB_SIZE, Slab>(p);
|
||||
return pointer_align_down<SLAB_SIZE, Slab>(const_cast<void*>(p));
|
||||
}
|
||||
|
||||
static bool is_short(Slab* p)
|
||||
|
||||
@@ -65,9 +65,10 @@ namespace snmalloc
|
||||
StatusChange = 2
|
||||
};
|
||||
|
||||
static Superslab* get(void* p)
|
||||
static Superslab* get(const void* p)
|
||||
{
|
||||
return pointer_align_down<SUPERSLAB_SIZE, Superslab>(p);
|
||||
return pointer_align_down<SUPERSLAB_SIZE, Superslab>(
|
||||
const_cast<void*>(p));
|
||||
}
|
||||
|
||||
static bool is_short_sizeclass(sizeclass_t sizeclass)
|
||||
|
||||
@@ -14,6 +14,10 @@ using namespace snmalloc;
|
||||
# define SNMALLOC_NAME_MANGLE(a) a
|
||||
#endif
|
||||
|
||||
#ifndef MALLOC_USABLE_SIZE_QUALIFIER
|
||||
# define MALLOC_USABLE_SIZE_QUALIFIER
|
||||
#endif
|
||||
|
||||
extern "C"
|
||||
{
|
||||
SNMALLOC_EXPORT void* SNMALLOC_NAME_MANGLE(__malloc_end_pointer)(void* ptr)
|
||||
@@ -43,7 +47,9 @@ extern "C"
|
||||
return ThreadAlloc::get_noncachable()->alloc<ZeroMem::YesZero>(sz);
|
||||
}
|
||||
|
||||
SNMALLOC_EXPORT size_t SNMALLOC_NAME_MANGLE(malloc_usable_size)(void* ptr)
|
||||
SNMALLOC_EXPORT
|
||||
size_t SNMALLOC_NAME_MANGLE(malloc_usable_size)(
|
||||
MALLOC_USABLE_SIZE_QUALIFIER void* ptr)
|
||||
{
|
||||
return Alloc::alloc_size(ptr);
|
||||
}
|
||||
|
||||
@@ -2,8 +2,10 @@
|
||||
|
||||
#include "../ds/address.h"
|
||||
#include "../mem/allocconfig.h"
|
||||
|
||||
#include <execinfo.h>
|
||||
#if __has_include(<execinfo.h>)
|
||||
# define SNMALLOC_HAS_BACKTRACE 1
|
||||
# include <execinfo.h>
|
||||
#endif
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
@@ -40,6 +42,7 @@ namespace snmalloc
|
||||
|
||||
static void print_stack_trace()
|
||||
{
|
||||
#ifdef SNMALLOC_HAS_BACKTRACE
|
||||
constexpr int SIZE = 1024;
|
||||
void* buffer[SIZE];
|
||||
auto nptrs = backtrace(buffer, SIZE);
|
||||
@@ -47,6 +50,7 @@ namespace snmalloc
|
||||
backtrace_symbols_fd(buffer, nptrs, STDOUT_FILENO);
|
||||
puts("");
|
||||
fflush(stdout);
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user