mirror of
https://github.com/microsoft/mimalloc.git
synced 2025-07-06 11:34:38 +03:00
merge from dev
This commit is contained in:
commit
191ea046e4
20 changed files with 269 additions and 60 deletions
|
@ -1,4 +1,4 @@
|
|||
cmake_minimum_required(VERSION 3.0)
|
||||
cmake_minimum_required(VERSION 3.18)
|
||||
project(mimalloc-test C CXX)
|
||||
|
||||
set(CMAKE_C_STANDARD 11)
|
||||
|
@ -16,10 +16,12 @@ if (NOT CMAKE_BUILD_TYPE)
|
|||
endif()
|
||||
|
||||
# Import mimalloc (if installed)
|
||||
find_package(mimalloc 2.0 REQUIRED NO_SYSTEM_ENVIRONMENT_PATH)
|
||||
find_package(mimalloc 2.2 CONFIG REQUIRED)
|
||||
message(STATUS "Found mimalloc installed at: ${MIMALLOC_LIBRARY_DIR} (${MIMALLOC_VERSION_DIR})")
|
||||
|
||||
# overriding with a dynamic library
|
||||
|
||||
# link with a dynamic shared library
|
||||
# use `LD_PRELOAD` to actually override malloc/free at runtime with mimalloc
|
||||
add_executable(dynamic-override main-override.c)
|
||||
target_link_libraries(dynamic-override PUBLIC mimalloc)
|
||||
|
||||
|
@ -29,9 +31,9 @@ target_link_libraries(dynamic-override-cxx PUBLIC mimalloc)
|
|||
|
||||
# overriding with a static object file works reliable as the symbols in the
|
||||
# object file have priority over those in library files
|
||||
add_executable(static-override-obj main-override.c ${MIMALLOC_OBJECT_DIR}/mimalloc.o)
|
||||
add_executable(static-override-obj main-override.c ${MIMALLOC_OBJECT_DIR}/mimalloc${CMAKE_C_OUTPUT_EXTENSION})
|
||||
target_include_directories(static-override-obj PUBLIC ${MIMALLOC_INCLUDE_DIR})
|
||||
target_link_libraries(static-override-obj PUBLIC pthread)
|
||||
target_link_libraries(static-override-obj PUBLIC mimalloc-static)
|
||||
|
||||
|
||||
# overriding with a static library works too if using the `mimalloc-override.h`
|
||||
|
|
|
@ -40,9 +40,9 @@ static void test_thread_local(); // issue #944
|
|||
static void test_mixed1(); // issue #942
|
||||
static void test_stl_allocators();
|
||||
|
||||
#if _WIN32
|
||||
#if x_WIN32
|
||||
#include "main-override-dep.h"
|
||||
static void test_dep(); // issue #981: test overriding in another DLL
|
||||
static void test_dep(); // issue #981: test overriding in another DLL
|
||||
#else
|
||||
static void test_dep() { };
|
||||
#endif
|
||||
|
@ -53,7 +53,7 @@ int main() {
|
|||
test_mixed1();
|
||||
|
||||
test_dep();
|
||||
|
||||
|
||||
//test_std_string();
|
||||
//test_thread_local();
|
||||
// heap_thread_free_huge();
|
||||
|
@ -117,8 +117,10 @@ static void various_tests() {
|
|||
t->~Test();
|
||||
delete[] tbuf;
|
||||
|
||||
#if _WIN32
|
||||
const char* ptr = ::_Getdays(); // test _base overrid
|
||||
free((void*)ptr);
|
||||
#endif
|
||||
}
|
||||
|
||||
class Static {
|
||||
|
@ -148,7 +150,7 @@ static bool test_stl_allocator1() {
|
|||
struct some_struct { int i; int j; double z; };
|
||||
|
||||
|
||||
#if _WIN32
|
||||
#if x_WIN32
|
||||
static void test_dep()
|
||||
{
|
||||
TestAllocInDll t;
|
||||
|
@ -417,7 +419,7 @@ void large_alloc(void)
|
|||
|
||||
// issue #372
|
||||
static void fail_aslr() {
|
||||
size_t sz = (4ULL << 40); // 4TiB
|
||||
size_t sz = (size_t)(4ULL << 40); // 4TiB
|
||||
void* p = malloc(sz);
|
||||
printf("pointer p: %p: area up to %p\n", p, (uint8_t*)p + sz);
|
||||
*(int*)0x5FFFFFFF000 = 0; // should segfault
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue