diff --git a/CMakeLists.txt b/CMakeLists.txt index db1e5c54..b9b07b4e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -24,6 +24,7 @@ cmake_dependent_option(SNMALLOC_STATIC_LIBRARY "Build static libraries" ON "NOT cmake_dependent_option(SNMALLOC_MEMCPY_BOUNDS "Perform bounds checks on memcpy with heap objects" OFF "NOT SNMALLOC_HEADER_ONLY_LIBRARY" OFF) cmake_dependent_option(SNMALLOC_CHECK_LOADS "Perform bounds checks on the source argument to memcpy with heap objects" OFF "SNMALLOC_MEMCPY_BOUNDS" OFF) cmake_dependent_option(SNMALLOC_OPTIMISE_FOR_CURRENT_MACHINE "Compile for current machine architecture" Off "NOT SNMALLOC_HEADER_ONLY_LIBRARY" OFF) +cmake_dependent_option(SNMALLOC_PAGEID "Set an id to memory regions" OFF "NOT SNMALLOC_PAGEID" OFF) if (NOT SNMALLOC_HEADER_ONLY_LIBRARY) # Pick a sensible default for the thread cleanup mechanism if (${CMAKE_SYSTEM_NAME} STREQUAL FreeBSD) @@ -323,6 +324,8 @@ if(NOT SNMALLOC_HEADER_ONLY_LIBRARY) target_compile_definitions(${name} PRIVATE SNMALLOC_CHECK_LOADS=$,true,false>) + target_compile_definitions(${name} PRIVATE + SNMALLOC_PAGEID=$,true,false>) install(TARGETS ${name} EXPORT snmallocConfig) diff --git a/src/snmalloc/pal/pal_linux.h b/src/snmalloc/pal/pal_linux.h index 66240fab..3a06bf8e 100644 --- a/src/snmalloc/pal/pal_linux.h +++ b/src/snmalloc/pal/pal_linux.h @@ -6,6 +6,7 @@ # include # include +# include # include extern "C" int puts(const char* str); @@ -38,7 +39,32 @@ namespace snmalloc { void* p = PALPOSIX::reserve(size); if (p) + { madvise(p, size, MADV_DONTDUMP); +# ifdef SNMALLOC_PAGEID +# ifndef PR_SET_VMA +# define PR_SET_VMA 0x53564d41 +# define PR_SET_VMA_ANON_NAME 0 +# endif + + /** + * + * If the kernel is set with CONFIG_ANON_VMA_NAME + * the reserved pages would appear as follow + * + * 7fa5f0ceb000-7fa5f0e00000 rw-p 00000000 00:00 0 [anon:snmalloc] + * 7fa5f0e00000-7fa5f1800000 rw-p 00000000 00:00 0 [anon:snmalloc] + * + */ + + prctl( + PR_SET_VMA, + PR_SET_VMA_ANON_NAME, + (unsigned long)p, + size, + (unsigned long)"snmalloc"); +# endif + } return p; }