Merge pull request #3 from neobrain/feature_is_known_alloc

Add public helper to check if an allocation is managed by jemalloc
This commit is contained in:
Ryan Houdek 2022-07-27 03:22:52 -07:00 committed by GitHub
commit 99e34d76bd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 0 deletions

View File

@ -269,6 +269,7 @@ JEMALLOC_EXPORT void JEMALLOC_NOTHROW je_malloc_stats_print(
const char *opts); const char *opts);
JEMALLOC_EXPORT size_t JEMALLOC_NOTHROW je_malloc_usable_size( JEMALLOC_EXPORT size_t JEMALLOC_NOTHROW je_malloc_usable_size(
JEMALLOC_USABLE_SIZE_CONST void *ptr) JEMALLOC_CXX_THROW; JEMALLOC_USABLE_SIZE_CONST void *ptr) JEMALLOC_CXX_THROW;
JEMALLOC_EXPORT int JEMALLOC_NOTHROW je_is_known_allocation(void* ptr) JEMALLOC_CXX_THROW;
#ifdef JEMALLOC_OVERRIDE_MEMALIGN #ifdef JEMALLOC_OVERRIDE_MEMALIGN
JEMALLOC_EXPORT JEMALLOC_ALLOCATOR JEMALLOC_RESTRICT_RETURN JEMALLOC_EXPORT JEMALLOC_ALLOCATOR JEMALLOC_RESTRICT_RETURN

View File

@ -3763,6 +3763,24 @@ je_malloc_usable_size(JEMALLOC_USABLE_SIZE_CONST void *ptr) {
return ret; return ret;
} }
JEMALLOC_EXPORT int JEMALLOC_NOTHROW
je_is_known_allocation(void* ptr) {
int ret = 0;
tsdn_t *tsdn = tsdn_fetch();
assert(malloc_initialized() || IS_INITIALIZER);
tsdn = tsdn_fetch();
check_entry_exit_locking(tsdn);
if (likely(ptr != NULL)) {
ret = ivsalloc(tsdn, ptr);
}
check_entry_exit_locking(tsdn);
return ret;
}
/* /*
* End non-standard functions. * End non-standard functions.
*/ */