mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-21 12:05:15 +00:00
LibC: Remove _aligned_malloc
and _aligned_free
We now have a proper aligned allocation implementation, and the toolchain patch to make Clang use the intermediary implementation has already been removed in an earlier iteration.
This commit is contained in:
parent
119567e176
commit
88ff01bb17
Notes:
sideshowbarker
2024-07-17 07:08:19 +09:00
Author: https://github.com/timschumi Commit: https://github.com/SerenityOS/serenity/commit/88ff01bb17 Pull-request: https://github.com/SerenityOS/serenity/pull/15233 Reviewed-by: https://github.com/BenWiederhake ✅ Reviewed-by: https://github.com/bgianfo
2 changed files with 0 additions and 39 deletions
|
@ -554,37 +554,6 @@ void* malloc(size_t size)
|
|||
return ptr_or_error.value();
|
||||
}
|
||||
|
||||
// This is a Microsoft extension, and is not found on other Unix-like systems.
|
||||
// FIXME: Remove this when all patches have been switched to aligned_alloc()
|
||||
//
|
||||
// This is used in libc++ to implement C++17 aligned new/delete.
|
||||
//
|
||||
// Both Unix-y alternatives to _aligned_malloc(), the C11 aligned_alloc() and
|
||||
// posix_memalign() say that the resulting pointer can be deallocated with
|
||||
// regular free(), which means that the allocator has to keep track of the
|
||||
// requested alignments. By contrast, _aligned_malloc() is paired with
|
||||
// _aligned_free(), so it can be easily implemented on top of malloc().
|
||||
void* _aligned_malloc(size_t size, size_t alignment)
|
||||
{
|
||||
if (popcount(alignment) != 1) {
|
||||
errno = EINVAL;
|
||||
return nullptr;
|
||||
}
|
||||
alignment = max(alignment, sizeof(void*));
|
||||
if (Checked<size_t>::addition_would_overflow(size, alignment)) {
|
||||
errno = ENOMEM;
|
||||
return nullptr;
|
||||
}
|
||||
void* ptr = malloc(size + alignment);
|
||||
if (!ptr) {
|
||||
errno = ENOMEM;
|
||||
return nullptr;
|
||||
}
|
||||
auto aligned_ptr = (void*)(((FlatPtr)ptr + alignment) & ~(alignment - 1));
|
||||
((void**)aligned_ptr)[-1] = ptr;
|
||||
return aligned_ptr;
|
||||
}
|
||||
|
||||
// https://pubs.opengroup.org/onlinepubs/9699919799/functions/free.html
|
||||
void free(void* ptr)
|
||||
{
|
||||
|
@ -595,12 +564,6 @@ void free(void* ptr)
|
|||
free_impl(ptr);
|
||||
}
|
||||
|
||||
void _aligned_free(void* ptr)
|
||||
{
|
||||
if (ptr)
|
||||
free(((void**)ptr)[-1]);
|
||||
}
|
||||
|
||||
// https://pubs.opengroup.org/onlinepubs/9699919799/functions/calloc.html
|
||||
void* calloc(size_t count, size_t size)
|
||||
{
|
||||
|
|
|
@ -25,8 +25,6 @@ size_t malloc_good_size(size_t);
|
|||
void serenity_dump_malloc_stats(void);
|
||||
void free(void*);
|
||||
__attribute__((alloc_size(2))) void* realloc(void* ptr, size_t);
|
||||
__attribute__((malloc, alloc_size(1), alloc_align(2))) void* _aligned_malloc(size_t size, size_t alignment);
|
||||
void _aligned_free(void* memblock);
|
||||
char* getenv(char const* name);
|
||||
char* secure_getenv(char const* name);
|
||||
int putenv(char*);
|
||||
|
|
Loading…
Add table
Reference in a new issue