[libc] Fix aligned_alloc used in hermetic tests. (#213041)
Use the provided alignment for the pointer to the returned
memory chunk instead of the size.
This fixes occasional segfaults in `hsearch` tests after
ce62aab97e, since
hash-table bitmask implementation uses SSE2 intrinsics with 16-byte
alignment.
This commit is contained in:
parent
57a38f251b
commit
2e838bf84d
1 changed files with 3 additions and 1 deletions
|
|
@ -73,7 +73,9 @@ int atexit(void (*func)(void)) { return LIBC_NAMESPACE::atexit(func); }
|
|||
void *aligned_alloc(size_t align, size_t s) {
|
||||
if (align & (align - 1)) // Must be power of 2
|
||||
return nullptr;
|
||||
s = ((s + align - 1) / align) * align;
|
||||
uintptr_t ptr_val = reinterpret_cast<uintptr_t>(ptr);
|
||||
uintptr_t aligned_ptr_val = ((ptr_val + align - 1) / align) * align;
|
||||
ptr = reinterpret_cast<uint8_t *>(aligned_ptr_val);
|
||||
void *mem = ptr;
|
||||
ptr += s;
|
||||
return static_cast<uint64_t>(ptr - memory) >= MEMORY_SIZE ? nullptr : mem;
|
||||
|
|
|
|||
Loading…
Reference in a new issue