New option to name reserved pages.

This commit is contained in:
David Carlier 2022-04-03 07:54:57 +01:00 коммит произвёл Matthew Parkinson
Родитель 848a7b1499
Коммит bf54eeb7be
2 изменённых файлов: 29 добавлений и 0 удалений

Просмотреть файл

@ -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=$<IF:$<BOOL:${SNMALLOC_CHECK_LOADS}>,true,false>)
target_compile_definitions(${name} PRIVATE
SNMALLOC_PAGEID=$<IF:$<BOOL:${SNMALLOC_PAGEID}>,true,false>)
install(TARGETS ${name} EXPORT snmallocConfig)

Просмотреть файл

@ -6,6 +6,7 @@
# include <string.h>
# include <sys/mman.h>
# include <sys/prctl.h>
# include <syscall.h>
extern "C" int puts(const char* str);
@ -38,7 +39,32 @@ namespace snmalloc
{
void* p = PALPOSIX<PALLinux>::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;
}