summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Scott <code@humanleg.org.uk>2020-02-22 18:55:46 +0000
committerAliaksey Kandratsenka <alkondratenko@gmail.com>2021-06-20 10:02:06 -0700
commit43504ab7091c0bcac9a233aa0ee0720a1549791b (patch)
treecda33b89e0a186ed3ea2bf4ac0bbb94673d52ff6
parentd57a9ea8bc92958733ac1c61a3c4f1ba2e150e96 (diff)
downloadgperftools-43504ab7091c0bcac9a233aa0ee0720a1549791b.tar.gz
tcmalloc page fences: add TCMALLOC_PAGE_FENCE_READABLE option
-rw-r--r--src/debugallocation.cc7
1 files changed, 6 insertions, 1 deletions
diff --git a/src/debugallocation.cc b/src/debugallocation.cc
index 17cd452..b0f7509 100644
--- a/src/debugallocation.cc
+++ b/src/debugallocation.cc
@@ -112,6 +112,9 @@ DEFINE_bool(malloc_page_fence_never_reclaim,
EnvToBool("TCMALLOC_PAGE_FENCE_NEVER_RECLAIM", false),
"Enables making the virtual address space inaccessible "
"upon a deallocation instead of returning it and reusing later.");
+DEFINE_bool(malloc_page_fence_readable,
+ EnvToBool("TCMALLOC_PAGE_FENCE_READABLE", false),
+ "Permits reads to the page fence.");
#else
DEFINE_bool(malloc_page_fence, false, "Not usable (requires mmap)");
DEFINE_bool(malloc_page_fence_never_reclaim, false, "Not usable (required mmap)");
@@ -508,6 +511,7 @@ class MallocBlock {
}
MallocBlock* b = NULL;
const bool use_malloc_page_fence = FLAGS_malloc_page_fence;
+ const bool malloc_page_fence_readable = FLAGS_malloc_page_fence_readable;
#ifdef HAVE_MMAP
if (use_malloc_page_fence) {
// Put the block towards the end of the page and make the next page
@@ -526,7 +530,8 @@ class MallocBlock {
strerror(errno));
}
// Mark the page after the block inaccessible
- if (mprotect(p + (num_pages - 1) * pagesize, pagesize, PROT_NONE)) {
+ if (mprotect(p + (num_pages - 1) * pagesize, pagesize,
+ PROT_NONE|(malloc_page_fence_readable ? PROT_READ : 0))) {
RAW_LOG(FATAL, "Guard page setup failed: %s", strerror(errno));
}
b = (MallocBlock*) (p + (num_pages - 1) * pagesize - sz);