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