summaryrefslogtreecommitdiffstats
path: root/vespamalloc
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2023-05-23 15:35:49 +0000
committerHenning Baldersheim <balder@yahoo-inc.com>2023-05-23 15:35:49 +0000
commit1412841e3297a21b602370d8faf82f7e5f919ebf (patch)
tree4273bd0d00fd9a20bf069ba4781987c3c0c4aeb4 /vespamalloc
parent03b178afb944631bd406f5f7085b704bcf9e7348 (diff)
Ensure that both the stack and memory provided by vespamalloc are within the allowed 57 low bits of the address.
Diffstat (limited to 'vespamalloc')
-rw-r--r--vespamalloc/src/vespamalloc/malloc/common.h2
-rw-r--r--vespamalloc/src/vespamalloc/malloc/threadproxy.cpp1
-rw-r--r--vespamalloc/src/vespamalloc/util/osmem.cpp1
3 files changed, 4 insertions, 0 deletions
diff --git a/vespamalloc/src/vespamalloc/malloc/common.h b/vespamalloc/src/vespamalloc/malloc/common.h
index 58e05878f64..501b45cd067 100644
--- a/vespamalloc/src/vespamalloc/malloc/common.h
+++ b/vespamalloc/src/vespamalloc/malloc/common.h
@@ -59,6 +59,8 @@ using OSMemory = MmapMemory;
using SizeClassT = int;
constexpr size_t ALWAYS_REUSE_LIMIT = 0x100000ul;
+constexpr uint8_t MAX_PTR_BITS = 57; // Maximum number of bits a pointer can use (Intel IceLake)
+constexpr uint64_t MAX_PTR = 1ul << MAX_PTR_BITS;
inline constexpr int
msbIdx(uint64_t v) {
diff --git a/vespamalloc/src/vespamalloc/malloc/threadproxy.cpp b/vespamalloc/src/vespamalloc/malloc/threadproxy.cpp
index 02eb624ee64..4a02d599b63 100644
--- a/vespamalloc/src/vespamalloc/malloc/threadproxy.cpp
+++ b/vespamalloc/src/vespamalloc/malloc/threadproxy.cpp
@@ -58,6 +58,7 @@ void * mallocThreadProxy (void * arg)
vespamalloc::Mutex::addThread();
vespamalloc::_G_myMemP->initThisThread();
void * result = nullptr;
+ ASSERT_STACKTRACE(uint64_t(&result) < vespamalloc::MAX_PTR); // Sanity check that stack is a legal PTR.
DEBUG(fprintf(stderr, "arg(%p=%p), local(%p=%p)\n", &arg, arg, &ta, ta));
pthread_cleanup_push(cleanupThread, ta);
diff --git a/vespamalloc/src/vespamalloc/util/osmem.cpp b/vespamalloc/src/vespamalloc/util/osmem.cpp
index 0267e091bab..f1d4a527732 100644
--- a/vespamalloc/src/vespamalloc/util/osmem.cpp
+++ b/vespamalloc/src/vespamalloc/util/osmem.cpp
@@ -168,6 +168,7 @@ MmapMemory::get(size_t len)
errno = prevErrno; // The temporary error should not impact if the end is good.
memory = getNormalPages(len);
}
+ ASSERT_STACKTRACE((uint64_t(&memory) + len) < vespamalloc::MAX_PTR);
return memory;
}