xref: /freebsd/contrib/llvm-project/compiler-rt/lib/nsan/nsan_allocator.h (revision 700637cbb5e582861067a11aaca4d053546871d2)
1*700637cbSDimitry Andric //===-- nsan_allocator.h ----------------------------------------*- C++ -*-===//
2*700637cbSDimitry Andric //
3*700637cbSDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4*700637cbSDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
5*700637cbSDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6*700637cbSDimitry Andric //
7*700637cbSDimitry Andric //===----------------------------------------------------------------------===//
8*700637cbSDimitry Andric 
9*700637cbSDimitry Andric #ifndef NSAN_ALLOCATOR_H
10*700637cbSDimitry Andric #define NSAN_ALLOCATOR_H
11*700637cbSDimitry Andric 
12*700637cbSDimitry Andric #include "sanitizer_common/sanitizer_common.h"
13*700637cbSDimitry Andric 
14*700637cbSDimitry Andric namespace __nsan {
15*700637cbSDimitry Andric 
16*700637cbSDimitry Andric struct NsanThreadLocalMallocStorage {
17*700637cbSDimitry Andric   // Allocator cache contains atomic_uint64_t which must be 8-byte aligned.
18*700637cbSDimitry Andric   alignas(8) uptr allocator_cache[96 * (512 * 8 + 16)]; // Opaque.
19*700637cbSDimitry Andric   void Init();
20*700637cbSDimitry Andric   void CommitBack();
21*700637cbSDimitry Andric 
22*700637cbSDimitry Andric private:
23*700637cbSDimitry Andric   // These objects are allocated via mmap() and are zero-initialized.
NsanThreadLocalMallocStorageNsanThreadLocalMallocStorage24*700637cbSDimitry Andric   NsanThreadLocalMallocStorage() {}
25*700637cbSDimitry Andric };
26*700637cbSDimitry Andric 
27*700637cbSDimitry Andric void NsanAllocatorInit();
28*700637cbSDimitry Andric void NsanDeallocate(void *ptr);
29*700637cbSDimitry Andric 
30*700637cbSDimitry Andric void *nsan_malloc(uptr size);
31*700637cbSDimitry Andric void *nsan_calloc(uptr nmemb, uptr size);
32*700637cbSDimitry Andric void *nsan_realloc(void *ptr, uptr size);
33*700637cbSDimitry Andric void *nsan_reallocarray(void *ptr, uptr nmemb, uptr size);
34*700637cbSDimitry Andric void *nsan_valloc(uptr size);
35*700637cbSDimitry Andric void *nsan_pvalloc(uptr size);
36*700637cbSDimitry Andric void *nsan_aligned_alloc(uptr alignment, uptr size);
37*700637cbSDimitry Andric void *nsan_memalign(uptr alignment, uptr size);
38*700637cbSDimitry Andric int nsan_posix_memalign(void **memptr, uptr alignment, uptr size);
39*700637cbSDimitry Andric 
40*700637cbSDimitry Andric } // namespace __nsan
41*700637cbSDimitry Andric #endif // NSAN_ALLOCATOR_H
42