ladybird/Userland/Libraries/LibC/stdlib.h
Daniel Bertalan 40e7ac9967 LibC: Implement _aligned_malloc and _aligned_free
C++17 introduced aligned versions of `new` and `delete`, which are
automatically called by the compiler when allocating over-aligned
objects. As with the regular allocator functions, these are generally
thin wrappers around LibC.

We did not have support for aligned allocations in LibC, so this was not
possible. While libstdc++ has a fallback implementation, libc++ does
not, so the aligned allocation function was disabled internally. This
made building the LLVM port with Clang impossible.

Note that while the Microsoft docs say that aligned_malloc and
_aligned_free are declared in `malloc.h`, libc++ doesn't #include that
file, but instead relies on the definition coming from `stdlib.h`.
Therefore, I chose to declare it in that file instead of creating a new
LibC header.

I chose not to implement the more Unix-y `memalign`, `posix_memalign`,
or the C11 `aligned_alloc`, because that would require us to
significantly alter the memory allocator's internals. See the comment in
malloc.cpp.
2021-11-14 16:46:21 +00:00

103 lines
3.1 KiB
C

/*
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <stddef.h>
#include <sys/cdefs.h>
#include <sys/types.h>
__attribute__((warn_unused_result)) int __generate_unique_filename(char* pattern);
__BEGIN_DECLS
#define EXIT_SUCCESS 0
#define EXIT_FAILURE 1
#define MB_CUR_MAX 4
__attribute__((malloc)) __attribute__((alloc_size(1))) void* malloc(size_t);
__attribute__((malloc)) __attribute__((alloc_size(1, 2))) void* calloc(size_t nmemb, size_t);
size_t malloc_size(void*);
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(const char* name);
char* secure_getenv(const char* name);
int putenv(char*);
int unsetenv(const char*);
int clearenv(void);
int setenv(const char* name, const char* value, int overwrite);
const char* getprogname();
void setprogname(const char*);
int atoi(const char*);
long atol(const char*);
long long atoll(const char*);
double strtod(const char*, char** endptr);
long double strtold(const char*, char** endptr);
float strtof(const char*, char** endptr);
long strtol(const char*, char** endptr, int base);
long long strtoll(const char*, char** endptr, int base);
unsigned long long strtoull(const char*, char** endptr, int base);
unsigned long strtoul(const char*, char** endptr, int base);
void qsort(void* base, size_t nmemb, size_t size, int (*compar)(const void*, const void*));
void qsort_r(void* base, size_t nmemb, size_t size, int (*compar)(const void*, const void*, void*), void* arg);
int atexit(void (*function)());
__attribute__((noreturn)) void exit(int status);
__attribute__((noreturn)) void abort();
char* ptsname(int fd);
int ptsname_r(int fd, char* buffer, size_t);
int abs(int);
long labs(long);
long long int llabs(long long int);
double atof(const char*);
int system(const char* command);
char* mktemp(char*);
int mkstemp(char*);
char* mkdtemp(char*);
void* bsearch(const void* key, const void* base, size_t nmemb, size_t size, int (*compar)(const void*, const void*));
int mblen(char const*, size_t);
size_t mbstowcs(wchar_t*, const char*, size_t);
int mbtowc(wchar_t*, const char*, size_t);
int wctomb(char*, wchar_t);
size_t wcstombs(char*, const wchar_t*, size_t);
char* realpath(const char* pathname, char* buffer);
__attribute__((noreturn)) void _Exit(int status);
#define RAND_MAX 32767
int rand();
void srand(unsigned seed);
long int random();
void srandom(unsigned seed);
uint32_t arc4random(void);
void arc4random_buf(void*, size_t);
uint32_t arc4random_uniform(uint32_t);
typedef struct {
int quot;
int rem;
} div_t;
div_t div(int, int);
typedef struct {
long quot;
long rem;
} ldiv_t;
ldiv_t ldiv(long, long);
typedef struct {
long long quot;
long long rem;
} lldiv_t;
lldiv_t lldiv(long long, long long);
int posix_openpt(int flags);
int grantpt(int fd);
int unlockpt(int fd);
__END_DECLS