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