1//===-- nsan_allocator.h ----------------------------------------*- C++ -*-===//
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#ifndef NSAN_ALLOCATOR_H
10#define NSAN_ALLOCATOR_H
11
12#include "sanitizer_common/sanitizer_common.h"
13
14namespace __nsan {
15
16struct NsanThreadLocalMallocStorage {
17 // Allocator cache contains atomic_uint64_t which must be 8-byte aligned.
18 alignas(8) uptr allocator_cache[96 * (512 * 8 + 16)]; // Opaque.
19 void Init();
20 void CommitBack();
21
22private:
23 // These objects are allocated via mmap() and are zero-initialized.
24 NsanThreadLocalMallocStorage() {}
25};
26
27void NsanAllocatorInit();
28void NsanDeallocate(void *ptr);
29
30void *nsan_malloc(uptr size);
31void *nsan_calloc(uptr nmemb, uptr size);
32void *nsan_realloc(void *ptr, uptr size);
33void *nsan_reallocarray(void *ptr, uptr nmemb, uptr size);
34void *nsan_valloc(uptr size);
35void *nsan_pvalloc(uptr size);
36void *nsan_aligned_alloc(uptr alignment, uptr size);
37void *nsan_memalign(uptr alignment, uptr size);
38int nsan_posix_memalign(void **memptr, uptr alignment, uptr size);
39
40} // namespace __nsan
41#endif // NSAN_ALLOCATOR_H
42