mirror of
https://github.com/jemalloc/jemalloc.git
synced 2026-07-23 21:23:06 +00:00
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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user