[libc-commits] [libc] [libc][stdlib] Make the FreeListHeap constant-initializable (PR #95453)

via libc-commits libc-commits at lists.llvm.org
Thu Jun 13 15:50:27 PDT 2024


================
@@ -0,0 +1,42 @@
+//===-- Implementation for freelist_malloc --------------------------------===//
+//
+// 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 "freelist_heap.h"
+
+#include <stddef.h>
+
+namespace LIBC_NAMESPACE {
+
+namespace {
+// Users can define LIBC_FREELIST_MALLOC_SIZE for setting the default buffer
+// size used by freelist malloc.
+#ifdef LIBC_FREELIST_MALLOC_SIZE
+constexpr size_t SIZE = LIBC_FREELIST_MALLOC_SIZE;
+#else
+// TODO: We should probably have something akin to what scudo/sanitizer
+// allocators do where each platform defines this.
+constexpr size_t SIZE = 0x40000000ULL; // 1GB
+#endif
+LIBC_CONSTINIT FreeListHeapBuffer<SIZE> freelist_heap_buffer;
+} // namespace
+
+FreeListHeap<> *freelist_heap = &freelist_heap_buffer;
+
+void *malloc(size_t size) { return freelist_heap->allocate(size); }
----------------
PiJoules wrote:

Done. Although not sure if using the LLVM_LIBC_FUNCTION wrapper is the correct way.

https://github.com/llvm/llvm-project/pull/95453


More information about the libc-commits mailing list