Skip to content

Commit

Permalink
sanitizer_allocator.cpp: Ensure at least sizeof(void*) alignment
Browse files Browse the repository at this point in the history
Some platforms (e.g. 64-bit CHERI) have stronger alignment requirements
on values returned from allocators. For all other platforms this does
not result in any functional change.

Reviewed By: cjappl, vitalybuka

Pull Request: llvm#84440
  • Loading branch information
arichardson authored Oct 24, 2024
1 parent 1b8cff9 commit 4c87793
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions compiler-rt/lib/sanitizer_common/sanitizer_allocator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ static void *RawInternalAlloc(uptr size, InternalAllocatorCache *cache,

static void *RawInternalRealloc(void *ptr, uptr size,
InternalAllocatorCache *cache) {
uptr alignment = 8;
constexpr usize alignment = Max<usize>(8, sizeof(void *));
if (cache == 0) {
SpinMutexLock l(&internal_allocator_cache_mu);
return internal_allocator()->Reallocate(&internal_allocator_cache, ptr,
Expand Down Expand Up @@ -137,7 +137,8 @@ void InternalAllocatorUnlock() SANITIZER_NO_THREAD_SAFETY_ANALYSIS {
}

// LowLevelAllocator
constexpr uptr kLowLevelAllocatorDefaultAlignment = 8;
constexpr usize kLowLevelAllocatorDefaultAlignment =
Max<usize>(8, sizeof(void *));
constexpr uptr kMinNumPagesRounded = 16;
constexpr uptr kMinRoundedSize = 65536;
static uptr low_level_alloc_min_alignment = kLowLevelAllocatorDefaultAlignment;
Expand Down

0 comments on commit 4c87793

Please sign in to comment.