1 //===-- sanitizer_allocator.h -----------------------------------*- C++ -*-===//
3 // This file is distributed under the University of Illinois Open Source
4 // License. See LICENSE.TXT for details.
6 //===----------------------------------------------------------------------===//
8 // Specialized memory allocator for ThreadSanitizer, MemorySanitizer, etc.
10 //===----------------------------------------------------------------------===//
12 #ifndef SANITIZER_ALLOCATOR_H
13 #define SANITIZER_ALLOCATOR_H
15 #include "sanitizer_internal_defs.h"
16 #include "sanitizer_common.h"
17 #include "sanitizer_libc.h"
18 #include "sanitizer_list.h"
19 #include "sanitizer_mutex.h"
20 #include "sanitizer_lfstack.h"
21 #include "sanitizer_procmaps.h"
23 namespace __sanitizer
{
25 // Since flags are immutable and allocator behavior can be changed at runtime
26 // (unit tests or ASan on Android are some examples), allocator_may_return_null
27 // flag value is cached here and can be altered later.
28 bool AllocatorMayReturnNull();
29 void SetAllocatorMayReturnNull(bool may_return_null
);
31 // Allocator failure handling policies:
32 // Implements AllocatorMayReturnNull policy, returns null when the flag is set,
34 struct ReturnNullOrDieOnFailure
{
35 static void *OnBadRequest();
38 // Always dies on the failure.
40 static void NORETURN
*OnBadRequest();
41 static void NORETURN
*OnOOM();
44 // Returns true if allocator detected OOM condition. Can be used to avoid memory
45 // hungry operations. Set when AllocatorReturnNullOrDieOnOOM() is called.
46 bool IsAllocatorOutOfMemory();
48 // Allocators call these callbacks on mmap/munmap.
49 struct NoOpMapUnmapCallback
{
50 void OnMap(uptr p
, uptr size
) const { }
51 void OnUnmap(uptr p
, uptr size
) const { }
54 // Callback type for iterating over chunks.
55 typedef void (*ForEachChunkCallback
)(uptr chunk
, void *arg
);
57 #include "sanitizer_allocator_size_class_map.h"
58 #include "sanitizer_allocator_stats.h"
59 #include "sanitizer_allocator_primary64.h"
60 #include "sanitizer_allocator_bytemap.h"
61 #include "sanitizer_allocator_primary32.h"
62 #include "sanitizer_allocator_local_cache.h"
63 #include "sanitizer_allocator_secondary.h"
64 #include "sanitizer_allocator_combined.h"
66 } // namespace __sanitizer
68 #endif // SANITIZER_ALLOCATOR_H