Skip to content

Commit

Permalink
Check for mallocx alignment bug.
Browse files Browse the repository at this point in the history
CTSRD-CHERI/cheribsd#1964

This was fixed, but the assertions here might be useful in case someone
tries to run this on an affected CheriBSD.
  • Loading branch information
jacobbramley committed Dec 13, 2023
1 parent e0cdb51 commit e84f8c8
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions Source/WTF/wtf/ContinuousArenaMalloc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,25 @@ void *ContinuousArenaMalloc::internalAllocateAligned(size_t alignment,
ASSERT((alignment & (alignment - 1)) == 0);
ASSERT(s_Initialized);

return mallocx(size, MALLOCX_ALIGN(alignment) | MALLOCX_TCACHE_NONE | MALLOCX_ARENA(s_arenaIndex));
void * result = mallocx(size, MALLOCX_ALIGN(alignment) | MALLOCX_TCACHE_NONE | MALLOCX_ARENA(s_arenaIndex));
#if __has_feature(capabilities)
// If this happens, try disabling capability revocation.
// See: https://github.com/CTSRD-CHERI/cheribsd/issues/1964
ASSERT(cheri_is_aligned(result, size));
#endif
return result;
}

void *ContinuousArenaMalloc::internalReallocate(void *ptr, size_t size)
{
ASSERT(s_Initialized);
return rallocx(ptr, size, MALLOCX_TCACHE_NONE | MALLOCX_ARENA(s_arenaIndex));
void * result = rallocx(ptr, size, MALLOCX_TCACHE_NONE | MALLOCX_ARENA(s_arenaIndex));
#if __has_feature(capabilities)
// If this happens, try disabling capability revocation.
// See: https://github.com/CTSRD-CHERI/cheribsd/issues/1964
ASSERT(cheri_is_aligned(result, size));
#endif
return result;
}

void ContinuousArenaMalloc::internalFree(void *ptr)
Expand Down

0 comments on commit e84f8c8

Please sign in to comment.