xref: /aosp_15_r20/external/compiler-rt/lib/scudo/scudo_allocator.h (revision 7c3d14c8b49c529e04be81a3ce6f5cc23712e4c6)
1*7c3d14c8STreehugger Robot //===-- scudo_allocator.h ---------------------------------------*- C++ -*-===//
2*7c3d14c8STreehugger Robot //
3*7c3d14c8STreehugger Robot //                     The LLVM Compiler Infrastructure
4*7c3d14c8STreehugger Robot //
5*7c3d14c8STreehugger Robot // This file is distributed under the University of Illinois Open Source
6*7c3d14c8STreehugger Robot // License. See LICENSE.TXT for details.
7*7c3d14c8STreehugger Robot //
8*7c3d14c8STreehugger Robot //===----------------------------------------------------------------------===//
9*7c3d14c8STreehugger Robot ///
10*7c3d14c8STreehugger Robot /// Header for scudo_allocator.cpp.
11*7c3d14c8STreehugger Robot ///
12*7c3d14c8STreehugger Robot //===----------------------------------------------------------------------===//
13*7c3d14c8STreehugger Robot 
14*7c3d14c8STreehugger Robot #ifndef SCUDO_ALLOCATOR_H_
15*7c3d14c8STreehugger Robot #define SCUDO_ALLOCATOR_H_
16*7c3d14c8STreehugger Robot 
17*7c3d14c8STreehugger Robot #ifndef __x86_64__
18*7c3d14c8STreehugger Robot # error "The Scudo hardened allocator currently only supports x86_64."
19*7c3d14c8STreehugger Robot #endif
20*7c3d14c8STreehugger Robot 
21*7c3d14c8STreehugger Robot #include "scudo_flags.h"
22*7c3d14c8STreehugger Robot 
23*7c3d14c8STreehugger Robot #include "sanitizer_common/sanitizer_allocator.h"
24*7c3d14c8STreehugger Robot 
25*7c3d14c8STreehugger Robot namespace __scudo {
26*7c3d14c8STreehugger Robot 
27*7c3d14c8STreehugger Robot enum AllocType : u8 {
28*7c3d14c8STreehugger Robot   FromMalloc    = 0, // Memory block came from malloc, realloc, calloc, etc.
29*7c3d14c8STreehugger Robot   FromNew       = 1, // Memory block came from operator new.
30*7c3d14c8STreehugger Robot   FromNewArray  = 2, // Memory block came from operator new [].
31*7c3d14c8STreehugger Robot   FromMemalign  = 3, // Memory block came from memalign, posix_memalign, etc.
32*7c3d14c8STreehugger Robot };
33*7c3d14c8STreehugger Robot 
34*7c3d14c8STreehugger Robot struct AllocatorOptions {
35*7c3d14c8STreehugger Robot   u32 QuarantineSizeMb;
36*7c3d14c8STreehugger Robot   u32 ThreadLocalQuarantineSizeKb;
37*7c3d14c8STreehugger Robot   bool MayReturnNull;
38*7c3d14c8STreehugger Robot   bool DeallocationTypeMismatch;
39*7c3d14c8STreehugger Robot   bool DeleteSizeMismatch;
40*7c3d14c8STreehugger Robot   bool ZeroContents;
41*7c3d14c8STreehugger Robot 
42*7c3d14c8STreehugger Robot   void setFrom(const Flags *f, const CommonFlags *cf);
43*7c3d14c8STreehugger Robot   void copyTo(Flags *f, CommonFlags *cf) const;
44*7c3d14c8STreehugger Robot };
45*7c3d14c8STreehugger Robot 
46*7c3d14c8STreehugger Robot void initAllocator(const AllocatorOptions &options);
47*7c3d14c8STreehugger Robot void drainQuarantine();
48*7c3d14c8STreehugger Robot 
49*7c3d14c8STreehugger Robot void *scudoMalloc(uptr Size, AllocType Type);
50*7c3d14c8STreehugger Robot void scudoFree(void *Ptr, AllocType Type);
51*7c3d14c8STreehugger Robot void scudoSizedFree(void *Ptr, uptr Size, AllocType Type);
52*7c3d14c8STreehugger Robot void *scudoRealloc(void *Ptr, uptr Size);
53*7c3d14c8STreehugger Robot void *scudoCalloc(uptr NMemB, uptr Size);
54*7c3d14c8STreehugger Robot void *scudoMemalign(uptr Alignment, uptr Size);
55*7c3d14c8STreehugger Robot void *scudoValloc(uptr Size);
56*7c3d14c8STreehugger Robot void *scudoPvalloc(uptr Size);
57*7c3d14c8STreehugger Robot int scudoPosixMemalign(void **MemPtr, uptr Alignment, uptr Size);
58*7c3d14c8STreehugger Robot void *scudoAlignedAlloc(uptr Alignment, uptr Size);
59*7c3d14c8STreehugger Robot uptr scudoMallocUsableSize(void *Ptr);
60*7c3d14c8STreehugger Robot 
61*7c3d14c8STreehugger Robot } // namespace __scudo
62*7c3d14c8STreehugger Robot 
63*7c3d14c8STreehugger Robot #endif  // SCUDO_ALLOCATOR_H_
64