llvm-project
50 строк · 1.5 Кб
1//===-- Implementation for freelist_malloc --------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#include "src/__support/freelist_heap.h"10#include "src/stdlib/aligned_alloc.h"11#include "src/stdlib/calloc.h"12#include "src/stdlib/free.h"13#include "src/stdlib/malloc.h"14#include "src/stdlib/realloc.h"15
16#include <stddef.h>17
18namespace LIBC_NAMESPACE {19
20namespace {21#ifdef LIBC_FREELIST_MALLOC_SIZE22// This is set via the LIBC_CONF_FREELIST_MALLOC_BUFFER_SIZE configuration.
23constexpr size_t SIZE = LIBC_FREELIST_MALLOC_SIZE;24#else25#error "LIBC_FREELIST_MALLOC_SIZE was not defined for this build."26#endif27LIBC_CONSTINIT FreeListHeapBuffer<SIZE> freelist_heap_buffer;28} // namespace29
30FreeListHeap<> *freelist_heap = &freelist_heap_buffer;31
32LLVM_LIBC_FUNCTION(void *, malloc, (size_t size)) {33return freelist_heap->allocate(size);34}
35
36LLVM_LIBC_FUNCTION(void, free, (void *ptr)) { return freelist_heap->free(ptr); }37
38LLVM_LIBC_FUNCTION(void *, calloc, (size_t num, size_t size)) {39return freelist_heap->calloc(num, size);40}
41
42LLVM_LIBC_FUNCTION(void *, realloc, (void *ptr, size_t size)) {43return freelist_heap->realloc(ptr, size);44}
45
46LLVM_LIBC_FUNCTION(void *, aligned_alloc, (size_t alignment, size_t size)) {47return freelist_heap->aligned_allocate(alignment, size);48}
49
50} // namespace LIBC_NAMESPACE51