Merge branch 'dev' into dev-slice
This commit is contained in:
commit
a4078df9d5
@ -165,7 +165,7 @@ endif()
|
|||||||
|
|
||||||
# Compiler flags
|
# Compiler flags
|
||||||
if(CMAKE_C_COMPILER_ID MATCHES "AppleClang|Clang|GNU")
|
if(CMAKE_C_COMPILER_ID MATCHES "AppleClang|Clang|GNU")
|
||||||
list(APPEND mi_cflags -Wall -Wextra -Wno-unknown-pragmas -fvisibility=hidden)
|
list(APPEND mi_cflags -Wall -Wextra -Wno-unknown-pragmas -Wstrict-prototypes -fvisibility=hidden)
|
||||||
if(CMAKE_C_COMPILER_ID MATCHES "GNU")
|
if(CMAKE_C_COMPILER_ID MATCHES "GNU")
|
||||||
list(APPEND mi_cflags -Wno-invalid-memory-model)
|
list(APPEND mi_cflags -Wno-invalid-memory-model)
|
||||||
endif()
|
endif()
|
||||||
|
@ -173,7 +173,7 @@ static inline uintptr_t mi_atomic_exchange_explicit(_Atomic(uintptr_t)*p, uintpt
|
|||||||
}
|
}
|
||||||
static inline void mi_atomic_thread_fence(mi_memory_order mo) {
|
static inline void mi_atomic_thread_fence(mi_memory_order mo) {
|
||||||
(void)(mo);
|
(void)(mo);
|
||||||
_Atomic(uintptr_t)x = 0;
|
_Atomic(uintptr_t) x = 0;
|
||||||
mi_atomic_exchange_explicit(&x, 1, mo);
|
mi_atomic_exchange_explicit(&x, 1, mo);
|
||||||
}
|
}
|
||||||
static inline uintptr_t mi_atomic_load_explicit(_Atomic(uintptr_t) const* p, mi_memory_order mo) {
|
static inline uintptr_t mi_atomic_load_explicit(_Atomic(uintptr_t) const* p, mi_memory_order mo) {
|
||||||
|
@ -57,7 +57,7 @@ static inline uintptr_t _mi_random_shuffle(uintptr_t x);
|
|||||||
extern mi_decl_cache_align mi_stats_t _mi_stats_main;
|
extern mi_decl_cache_align mi_stats_t _mi_stats_main;
|
||||||
extern mi_decl_cache_align const mi_page_t _mi_page_empty;
|
extern mi_decl_cache_align const mi_page_t _mi_page_empty;
|
||||||
bool _mi_is_main_thread(void);
|
bool _mi_is_main_thread(void);
|
||||||
bool _mi_preloading(); // true while the C runtime is not ready
|
bool _mi_preloading(void); // true while the C runtime is not ready
|
||||||
|
|
||||||
// os.c
|
// os.c
|
||||||
size_t _mi_os_page_size(void);
|
size_t _mi_os_page_size(void);
|
||||||
|
14
src/alloc.c
14
src/alloc.c
@ -4,6 +4,10 @@ This is free software; you can redistribute it and/or modify it under the
|
|||||||
terms of the MIT license. A copy of the license can be found in the file
|
terms of the MIT license. A copy of the license can be found in the file
|
||||||
"LICENSE" at the root of this distribution.
|
"LICENSE" at the root of this distribution.
|
||||||
-----------------------------------------------------------------------------*/
|
-----------------------------------------------------------------------------*/
|
||||||
|
#ifndef _DEFAULT_SOURCE
|
||||||
|
#define _DEFAULT_SOURCE // for realpath() on Linux
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "mimalloc.h"
|
#include "mimalloc.h"
|
||||||
#include "mimalloc-internal.h"
|
#include "mimalloc-internal.h"
|
||||||
#include "mimalloc-atomic.h"
|
#include "mimalloc-atomic.h"
|
||||||
@ -465,7 +469,7 @@ static inline mi_segment_t* mi_checked_ptr_segment(const void* p, const char* ms
|
|||||||
#endif
|
#endif
|
||||||
#if (MI_DEBUG>0 || MI_SECURE>=4)
|
#if (MI_DEBUG>0 || MI_SECURE>=4)
|
||||||
if (mi_unlikely(_mi_ptr_cookie(segment) != segment->cookie)) {
|
if (mi_unlikely(_mi_ptr_cookie(segment) != segment->cookie)) {
|
||||||
_mi_error_message(EINVAL, "%s: pointer does not point to a valid heap space: %p\n", p);
|
_mi_error_message(EINVAL, "%s: pointer does not point to a valid heap space: %p\n", msg, p);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
return segment;
|
return segment;
|
||||||
@ -747,7 +751,7 @@ mi_decl_restrict char* mi_heap_realpath(mi_heap_t* heap, const char* fname, char
|
|||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
#include <unistd.h> // pathconf
|
#include <unistd.h> // pathconf
|
||||||
static size_t mi_path_max() {
|
static size_t mi_path_max(void) {
|
||||||
static size_t path_max = 0;
|
static size_t path_max = 0;
|
||||||
if (path_max <= 0) {
|
if (path_max <= 0) {
|
||||||
long m = pathconf("/",_PC_PATH_MAX);
|
long m = pathconf("/",_PC_PATH_MAX);
|
||||||
@ -807,13 +811,13 @@ static bool mi_try_new_handler(bool nothrow) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
typedef void (*std_new_handler_t)();
|
typedef void (*std_new_handler_t)(void);
|
||||||
|
|
||||||
#if (defined(__GNUC__) || defined(__clang__))
|
#if (defined(__GNUC__) || defined(__clang__))
|
||||||
std_new_handler_t __attribute((weak)) _ZSt15get_new_handlerv() {
|
std_new_handler_t __attribute((weak)) _ZSt15get_new_handlerv(void) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
static std_new_handler_t mi_get_new_handler() {
|
static std_new_handler_t mi_get_new_handler(void) {
|
||||||
return _ZSt15get_new_handlerv();
|
return _ZSt15get_new_handlerv();
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
|
@ -22,7 +22,7 @@ terms of the MIT license. A copy of the license can be found in the file
|
|||||||
static uintptr_t mi_max_error_count = 16; // stop outputting errors after this
|
static uintptr_t mi_max_error_count = 16; // stop outputting errors after this
|
||||||
static uintptr_t mi_max_warning_count = 16; // stop outputting warnings after this
|
static uintptr_t mi_max_warning_count = 16; // stop outputting warnings after this
|
||||||
|
|
||||||
static void mi_add_stderr_output();
|
static void mi_add_stderr_output(void);
|
||||||
|
|
||||||
int mi_version(void) mi_attr_noexcept {
|
int mi_version(void) mi_attr_noexcept {
|
||||||
return MI_MALLOC_VERSION;
|
return MI_MALLOC_VERSION;
|
||||||
@ -412,6 +412,14 @@ static void mi_strlcat(char* dest, const char* src, size_t dest_size) {
|
|||||||
dest[dest_size - 1] = 0;
|
dest[dest_size - 1] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef MI_NO_GETENV
|
||||||
|
static bool mi_getenv(const char* name, char* result, size_t result_size) {
|
||||||
|
UNUSED(name);
|
||||||
|
UNUSED(result);
|
||||||
|
UNUSED(result_size);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
#else
|
||||||
static inline int mi_strnicmp(const char* s, const char* t, size_t n) {
|
static inline int mi_strnicmp(const char* s, const char* t, size_t n) {
|
||||||
if (n==0) return 0;
|
if (n==0) return 0;
|
||||||
for (; *s != 0 && *t != 0 && n > 0; s++, t++, n--) {
|
for (; *s != 0 && *t != 0 && n > 0; s++, t++, n--) {
|
||||||
@ -419,7 +427,6 @@ static inline int mi_strnicmp(const char* s, const char* t, size_t n) {
|
|||||||
}
|
}
|
||||||
return (n==0 ? 0 : *s - *t);
|
return (n==0 ? 0 : *s - *t);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined _WIN32
|
#if defined _WIN32
|
||||||
// On Windows use GetEnvironmentVariable instead of getenv to work
|
// On Windows use GetEnvironmentVariable instead of getenv to work
|
||||||
// reliably even when this is invoked before the C runtime is initialized.
|
// reliably even when this is invoked before the C runtime is initialized.
|
||||||
@ -487,7 +494,8 @@ static bool mi_getenv(const char* name, char* result, size_t result_size) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif // !MI_USE_ENVIRON
|
||||||
|
#endif // !MI_NO_GETENV
|
||||||
|
|
||||||
static void mi_option_init(mi_option_desc_t* desc) {
|
static void mi_option_init(mi_option_desc_t* desc) {
|
||||||
// Read option value from the environment
|
// Read option value from the environment
|
||||||
|
8
src/os.c
8
src/os.c
@ -87,7 +87,7 @@ size_t _mi_os_page_size() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// if large OS pages are supported (2 or 4MiB), then return the size, otherwise return the small page size (4KiB)
|
// if large OS pages are supported (2 or 4MiB), then return the size, otherwise return the small page size (4KiB)
|
||||||
size_t _mi_os_large_page_size() {
|
size_t _mi_os_large_page_size(void) {
|
||||||
return (large_os_page_size != 0 ? large_os_page_size : _mi_os_page_size());
|
return (large_os_page_size != 0 ? large_os_page_size : _mi_os_page_size());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -256,7 +256,7 @@ static void* mi_os_get_aligned_hint(size_t try_alignment, size_t size);
|
|||||||
|
|
||||||
static void* mi_win_virtual_allocx(void* addr, size_t size, size_t try_alignment, DWORD flags) {
|
static void* mi_win_virtual_allocx(void* addr, size_t size, size_t try_alignment, DWORD flags) {
|
||||||
#if (MI_INTPTR_SIZE >= 8)
|
#if (MI_INTPTR_SIZE >= 8)
|
||||||
// on 64-bit systems, try to use the virtual address area after 4TiB for 4MiB aligned allocations
|
// on 64-bit systems, try to use the virtual address area after 2TiB for 4MiB aligned allocations
|
||||||
void* hint;
|
void* hint;
|
||||||
if (addr == NULL && (hint = mi_os_get_aligned_hint(try_alignment,size)) != NULL) {
|
if (addr == NULL && (hint = mi_os_get_aligned_hint(try_alignment,size)) != NULL) {
|
||||||
void* p = VirtualAlloc(hint, size, flags, PAGE_READWRITE);
|
void* p = VirtualAlloc(hint, size, flags, PAGE_READWRITE);
|
||||||
@ -369,7 +369,7 @@ static void* mi_wasm_heap_grow(size_t size, size_t try_alignment) {
|
|||||||
static void* mi_unix_mmapx(void* addr, size_t size, size_t try_alignment, int protect_flags, int flags, int fd) {
|
static void* mi_unix_mmapx(void* addr, size_t size, size_t try_alignment, int protect_flags, int flags, int fd) {
|
||||||
void* p = NULL;
|
void* p = NULL;
|
||||||
#if (MI_INTPTR_SIZE >= 8) && !defined(MAP_ALIGNED)
|
#if (MI_INTPTR_SIZE >= 8) && !defined(MAP_ALIGNED)
|
||||||
// on 64-bit systems, use the virtual address area after 4TiB for 4MiB aligned allocations
|
// on 64-bit systems, use the virtual address area after 2TiB for 4MiB aligned allocations
|
||||||
void* hint;
|
void* hint;
|
||||||
if (addr == NULL && (hint = mi_os_get_aligned_hint(try_alignment, size)) != NULL) {
|
if (addr == NULL && (hint = mi_os_get_aligned_hint(try_alignment, size)) != NULL) {
|
||||||
p = mmap(hint,size,protect_flags,flags,fd,0);
|
p = mmap(hint,size,protect_flags,flags,fd,0);
|
||||||
@ -506,7 +506,7 @@ static void* mi_unix_mmap(void* addr, size_t size, size_t try_alignment, int pro
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
// On 64-bit systems, we can do efficient aligned allocation by using
|
// On 64-bit systems, we can do efficient aligned allocation by using
|
||||||
// the 4TiB to 30TiB area to allocate them.
|
// the 2TiB to 30TiB area to allocate them.
|
||||||
#if (MI_INTPTR_SIZE >= 8) && (defined(_WIN32) || (defined(MI_OS_USE_MMAP) && !defined(MAP_ALIGNED)))
|
#if (MI_INTPTR_SIZE >= 8) && (defined(_WIN32) || (defined(MI_OS_USE_MMAP) && !defined(MAP_ALIGNED)))
|
||||||
static mi_decl_cache_align _Atomic(uintptr_t) aligned_base;
|
static mi_decl_cache_align _Atomic(uintptr_t) aligned_base;
|
||||||
|
|
||||||
|
@ -4,6 +4,10 @@ This is free software; you can redistribute it and/or modify it under the
|
|||||||
terms of the MIT license. A copy of the license can be found in the file
|
terms of the MIT license. A copy of the license can be found in the file
|
||||||
"LICENSE" at the root of this distribution.
|
"LICENSE" at the root of this distribution.
|
||||||
-----------------------------------------------------------------------------*/
|
-----------------------------------------------------------------------------*/
|
||||||
|
#ifndef _DEFAULT_SOURCE
|
||||||
|
#define _DEFAULT_SOURCE // for syscall() on Linux
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "mimalloc.h"
|
#include "mimalloc.h"
|
||||||
#include "mimalloc-internal.h"
|
#include "mimalloc-internal.h"
|
||||||
|
|
||||||
|
@ -40,7 +40,7 @@ Possible issues:
|
|||||||
#include "bitmap.h"
|
#include "bitmap.h"
|
||||||
|
|
||||||
// Internal raw OS interface
|
// Internal raw OS interface
|
||||||
size_t _mi_os_large_page_size();
|
size_t _mi_os_large_page_size(void);
|
||||||
bool _mi_os_protect(void* addr, size_t size);
|
bool _mi_os_protect(void* addr, size_t size);
|
||||||
bool _mi_os_unprotect(void* addr, size_t size);
|
bool _mi_os_unprotect(void* addr, size_t size);
|
||||||
bool _mi_os_commit(void* p, size_t size, bool* is_zero, mi_stats_t* stats);
|
bool _mi_os_commit(void* p, size_t size, bool* is_zero, mi_stats_t* stats);
|
||||||
|
@ -412,10 +412,14 @@ mi_msecs_t _mi_clock_now(void) {
|
|||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#ifdef CLOCK_REALTIME
|
#if defined(CLOCK_REALTIME) || defined(CLOCK_MONOTONIC)
|
||||||
mi_msecs_t _mi_clock_now(void) {
|
mi_msecs_t _mi_clock_now(void) {
|
||||||
struct timespec t;
|
struct timespec t;
|
||||||
|
#ifdef CLOCK_MONOTONIC
|
||||||
|
clock_gettime(CLOCK_MONOTONIC, &t);
|
||||||
|
#else
|
||||||
clock_gettime(CLOCK_REALTIME, &t);
|
clock_gettime(CLOCK_REALTIME, &t);
|
||||||
|
#endif
|
||||||
return ((mi_msecs_t)t.tv_sec * 1000) + ((mi_msecs_t)t.tv_nsec / 1000000);
|
return ((mi_msecs_t)t.tv_sec * 1000) + ((mi_msecs_t)t.tv_nsec / 1000000);
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
|
@ -64,15 +64,15 @@ static int failed = 0;
|
|||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
// Test functions
|
// Test functions
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
bool test_heap1();
|
bool test_heap1(void);
|
||||||
bool test_heap2();
|
bool test_heap2(void);
|
||||||
bool test_stl_allocator1();
|
bool test_stl_allocator1(void);
|
||||||
bool test_stl_allocator2();
|
bool test_stl_allocator2(void);
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
// Main testing
|
// Main testing
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
int main() {
|
int main(void) {
|
||||||
mi_option_disable(mi_option_verbose);
|
mi_option_disable(mi_option_verbose);
|
||||||
|
|
||||||
// ---------------------------------------------------
|
// ---------------------------------------------------
|
||||||
|
Loading…
Reference in New Issue
Block a user