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