Skip to content

Commit

Permalink
Add WA for the issue
Browse files Browse the repository at this point in the history
This WA for the issue:
oneapi-src#894
It protects us from a recursion in malloc_usable_size()
when the JEMALLOC proxy_lib_pool is used.

TODO: remove this WA when the issue is fixed.

Signed-off-by: Lukasz Dorau <[email protected]>
  • Loading branch information
ldorau committed Nov 18, 2024
1 parent 0d69471 commit ea3599d
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/proxy_lib/proxy_lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,13 @@ static umf_memory_pool_handle_t Proxy_pool = NULL;
// it protects us from recursion in umfPool*()
static __TLS int was_called_from_umfPool = 0;

// This WA for the issue:
// https://github.com/oneapi-src/unified-memory-framework/issues/894
// It protects us from a recursion in malloc_usable_size()
// when the JEMALLOC proxy_lib_pool is used.
// TODO remove this WA when the issue is fixed.
static __TLS int was_called_from_malloc_usable_size = 0;

/*****************************************************************************/
/*** The constructor and destructor of the proxy library *********************/
/*****************************************************************************/
Expand Down Expand Up @@ -454,15 +461,18 @@ size_t malloc_usable_size(void *ptr) {
return 0; // unsupported in case of the ba_leak allocator
}

if (Proxy_pool && (umfPoolByPtr(ptr) == Proxy_pool)) {
if (!was_called_from_malloc_usable_size && Proxy_pool &&
(umfPoolByPtr(ptr) == Proxy_pool)) {
was_called_from_malloc_usable_size = 1;
was_called_from_umfPool = 1;
size_t size = umfPoolMallocUsableSize(Proxy_pool, ptr);
was_called_from_umfPool = 0;
was_called_from_malloc_usable_size = 0;
return size;
}

#ifndef _WIN32
if (Size_threshold_value) {
if (!was_called_from_malloc_usable_size && Size_threshold_value) {
return System_malloc_usable_size(ptr);
}
#endif /* _WIN32 */
Expand Down

0 comments on commit ea3599d

Please sign in to comment.