Home | History | Annotate | Download | only in scudo
      1 //===-- scudo_interceptors.cpp ----------------------------------*- 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 /// Linux specific malloc interception functions.
     11 ///
     12 //===----------------------------------------------------------------------===//
     13 
     14 #include "sanitizer_common/sanitizer_platform.h"
     15 #if SANITIZER_LINUX
     16 
     17 #include "scudo_allocator.h"
     18 
     19 #include "interception/interception.h"
     20 
     21 using namespace __scudo;
     22 
     23 INTERCEPTOR(void, free, void *ptr) {
     24   scudoFree(ptr, FromMalloc);
     25 }
     26 
     27 INTERCEPTOR(void, cfree, void *ptr) {
     28   scudoFree(ptr, FromMalloc);
     29 }
     30 
     31 INTERCEPTOR(void*, malloc, uptr size) {
     32   return scudoMalloc(size, FromMalloc);
     33 }
     34 
     35 INTERCEPTOR(void*, realloc, void *ptr, uptr size) {
     36   return scudoRealloc(ptr, size);
     37 }
     38 
     39 INTERCEPTOR(void*, calloc, uptr nmemb, uptr size) {
     40   return scudoCalloc(nmemb, size);
     41 }
     42 
     43 INTERCEPTOR(void*, valloc, uptr size) {
     44   return scudoValloc(size);
     45 }
     46 
     47 INTERCEPTOR(void*, memalign, uptr alignment, uptr size) {
     48   return scudoMemalign(alignment, size);
     49 }
     50 
     51 INTERCEPTOR(void*, __libc_memalign, uptr alignment, uptr size) {
     52   return scudoMemalign(alignment, size);
     53 }
     54 
     55 INTERCEPTOR(void*, pvalloc, uptr size) {
     56   return scudoPvalloc(size);
     57 }
     58 
     59 INTERCEPTOR(void*, aligned_alloc, uptr alignment, uptr size) {
     60   return scudoAlignedAlloc(alignment, size);
     61 }
     62 
     63 INTERCEPTOR(int, posix_memalign, void **memptr, uptr alignment, uptr size) {
     64   return scudoPosixMemalign(memptr, alignment, size);
     65 }
     66 
     67 INTERCEPTOR(uptr, malloc_usable_size, void *ptr) {
     68   return scudoMallocUsableSize(ptr);
     69 }
     70 
     71 INTERCEPTOR(int, mallopt, int cmd, int value) {
     72   return -1;
     73 }
     74 
     75 #endif // SANITIZER_LINUX
     76