summaryrefslogtreecommitdiff
path: root/libc/src/stdlib/aligned_alloc.h
diff options
context:
space:
mode:
authorPiJoules <6019989+PiJoules@users.noreply.github.com>2024-07-03 16:26:00 -0700
committerGitHub <noreply@github.com>2024-07-03 16:26:00 -0700
commit3eebeb7e50c49ece2788ff4d5ffab5cc6c3da455 (patch)
treeaf708b927a718961ce3145fcc5cc6f44f1e0aeea /libc/src/stdlib/aligned_alloc.h
parentd3a76b03d8f35903bc17cb85c14c9816c963cff6 (diff)
[libc] Add aligned_alloc (#96586)
This adds support for aligned_alloc with the freelist allocator. This works by finding blocks large enough to hold the requested size plus some shift amount that's at most the requested alignment. Blocks that meet this requirement but aren't properly aligned can be split such that the usable_space of a new block is aligned properly. The "padding" block created will be merged with the previous block if one exists.
Diffstat (limited to 'libc/src/stdlib/aligned_alloc.h')
-rw-r--r--libc/src/stdlib/aligned_alloc.h20
1 files changed, 20 insertions, 0 deletions
diff --git a/libc/src/stdlib/aligned_alloc.h b/libc/src/stdlib/aligned_alloc.h
new file mode 100644
index 000000000000..7f294c8114d4
--- /dev/null
+++ b/libc/src/stdlib/aligned_alloc.h
@@ -0,0 +1,20 @@
+//===-- Implementation header for aligned_alloc -----------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include <stddef.h>
+
+#ifndef LLVM_LIBC_SRC_STDLIB_ALIGNED_ALLOC_H
+#define LLVM_LIBC_SRC_STDLIB_ALIGNED_ALLOC_H
+
+namespace LIBC_NAMESPACE {
+
+void *aligned_alloc(size_t alignment, size_t size);
+
+} // namespace LIBC_NAMESPACE
+
+#endif // LLVM_LIBC_SRC_STDLIB_ALIGNED_ALLOC_H