1*7c3d14c8STreehugger Robot //===-- dfsan_interceptors.cc ---------------------------------------------===//
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 // This file is a part of DataFlowSanitizer.
11*7c3d14c8STreehugger Robot //
12*7c3d14c8STreehugger Robot // Interceptors for standard library functions.
13*7c3d14c8STreehugger Robot //===----------------------------------------------------------------------===//
14*7c3d14c8STreehugger Robot
15*7c3d14c8STreehugger Robot #include "dfsan/dfsan.h"
16*7c3d14c8STreehugger Robot #include "interception/interception.h"
17*7c3d14c8STreehugger Robot #include "sanitizer_common/sanitizer_common.h"
18*7c3d14c8STreehugger Robot
INTERCEPTOR(void *,mmap,void * addr,SIZE_T length,int prot,int flags,int fd,OFF_T offset)19*7c3d14c8STreehugger Robot INTERCEPTOR(void *, mmap, void *addr, SIZE_T length, int prot, int flags,
20*7c3d14c8STreehugger Robot int fd, OFF_T offset) {
21*7c3d14c8STreehugger Robot void *res = REAL(mmap)(addr, length, prot, flags, fd, offset);
22*7c3d14c8STreehugger Robot if (res != (void*)-1)
23*7c3d14c8STreehugger Robot dfsan_set_label(0, res, RoundUpTo(length, GetPageSize()));
24*7c3d14c8STreehugger Robot return res;
25*7c3d14c8STreehugger Robot }
26*7c3d14c8STreehugger Robot
INTERCEPTOR(void *,mmap64,void * addr,SIZE_T length,int prot,int flags,int fd,OFF64_T offset)27*7c3d14c8STreehugger Robot INTERCEPTOR(void *, mmap64, void *addr, SIZE_T length, int prot, int flags,
28*7c3d14c8STreehugger Robot int fd, OFF64_T offset) {
29*7c3d14c8STreehugger Robot void *res = REAL(mmap64)(addr, length, prot, flags, fd, offset);
30*7c3d14c8STreehugger Robot if (res != (void*)-1)
31*7c3d14c8STreehugger Robot dfsan_set_label(0, res, RoundUpTo(length, GetPageSize()));
32*7c3d14c8STreehugger Robot return res;
33*7c3d14c8STreehugger Robot }
34*7c3d14c8STreehugger Robot
35*7c3d14c8STreehugger Robot namespace __dfsan {
InitializeInterceptors()36*7c3d14c8STreehugger Robot void InitializeInterceptors() {
37*7c3d14c8STreehugger Robot static int inited = 0;
38*7c3d14c8STreehugger Robot CHECK_EQ(inited, 0);
39*7c3d14c8STreehugger Robot
40*7c3d14c8STreehugger Robot INTERCEPT_FUNCTION(mmap);
41*7c3d14c8STreehugger Robot INTERCEPT_FUNCTION(mmap64);
42*7c3d14c8STreehugger Robot inited = 1;
43*7c3d14c8STreehugger Robot }
44*7c3d14c8STreehugger Robot } // namespace __dfsan
45