Home | History | Annotate | Download | only in scudo
      1 //===-- 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 
     25 namespace __scudo {
     26 
     27 enum 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 
     34 struct 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 
     46 void initAllocator(const AllocatorOptions &options);
     47 void drainQuarantine();
     48 
     49 void *scudoMalloc(uptr Size, AllocType Type);
     50 void scudoFree(void *Ptr, AllocType Type);
     51 void scudoSizedFree(void *Ptr, uptr Size, AllocType Type);
     52 void *scudoRealloc(void *Ptr, uptr Size);
     53 void *scudoCalloc(uptr NMemB, uptr Size);
     54 void *scudoMemalign(uptr Alignment, uptr Size);
     55 void *scudoValloc(uptr Size);
     56 void *scudoPvalloc(uptr Size);
     57 int scudoPosixMemalign(void **MemPtr, uptr Alignment, uptr Size);
     58 void *scudoAlignedAlloc(uptr Alignment, uptr Size);
     59 uptr scudoMallocUsableSize(void *Ptr);
     60 
     61 } // namespace __scudo
     62 
     63 #endif  // SCUDO_ALLOCATOR_H_
     64