Implement guard pages.

Adding guarded extents, which are regular extents surrounded by guard pages
(mprotected).  To reduce syscalls, small guarded extents are cached as a
separate eset in ecache, and decay through the dirty / muzzy / retained pipeline
as usual.
This commit is contained in:
Qi Wang
2021-04-26 14:22:25 -07:00
committed by Qi Wang
parent 7bb05e04be
commit deb8e62a83
41 changed files with 920 additions and 251 deletions

View File

@@ -1,4 +1,5 @@
#include "test/jemalloc_test.h"
#include "test/guard.h"
#include "jemalloc/internal/safety_check.h"
@@ -30,8 +31,18 @@ TEST_BEGIN(test_large_double_free_tcache) {
test_large_double_free_pre();
char *ptr = malloc(SC_LARGE_MINCLASS);
bool guarded = extent_is_guarded(tsdn_fetch(), ptr);
free(ptr);
free(ptr);
if (!guarded) {
free(ptr);
} else {
/*
* Skip because guarded extents may unguard immediately on
* deallocation, in which case the second free will crash before
* reaching the intended safety check.
*/
fake_abort_called = true;
}
mallctl("thread.tcache.flush", NULL, NULL, NULL, 0);
test_large_double_free_post();
}
@@ -43,8 +54,18 @@ TEST_BEGIN(test_large_double_free_no_tcache) {
test_large_double_free_pre();
char *ptr = mallocx(SC_LARGE_MINCLASS, MALLOCX_TCACHE_NONE);
bool guarded = extent_is_guarded(tsdn_fetch(), ptr);
dallocx(ptr, MALLOCX_TCACHE_NONE);
dallocx(ptr, MALLOCX_TCACHE_NONE);
if (!guarded) {
dallocx(ptr, MALLOCX_TCACHE_NONE);
} else {
/*
* Skip because guarded extents may unguard immediately on
* deallocation, in which case the second free will crash before
* reaching the intended safety check.
*/
fake_abort_called = true;
}
test_large_double_free_post();
}
TEST_END