summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordaan <daanl@outlook.com>2019-07-17 15:37:36 -0700
committerdaan <daanl@outlook.com>2019-07-17 15:37:36 -0700
commitf646cc925dab5116a3677e9045cda169d9b9527c (patch)
treecc5985d8ccbfd70d8f66d899c27af5738a32d080 /src
parent8390c4650314f2286d7c52f76d0d1a8902f95453 (diff)
add is_in_heap_region function
Diffstat (limited to 'src')
-rw-r--r--src/memory.c10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/memory.c b/src/memory.c
index 030541a..83e90b0 100644
--- a/src/memory.c
+++ b/src/memory.c
@@ -104,6 +104,16 @@ static size_t mi_good_commit_size(size_t size) {
return _mi_align_up(size, _mi_os_large_page_size());
}
+// Return if a pointer points into a region reserved by us.
+bool mi_is_in_heap_region(const void* p) {
+ size_t count = mi_atomic_read(&regions_count);
+ for (size_t i = 0; i < count; i++) {
+ uint8_t* start = (uint8_t*)mi_atomic_read_ptr(&regions[i].start);
+ if (start != NULL && (uint8_t*)p >= start && (uint8_t*)p < start + MI_REGION_SIZE) return true;
+ }
+ return false;
+}
+
/* ----------------------------------------------------------------------------
Commit from a region
-----------------------------------------------------------------------------*/