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 INTERCEPTOR(void *, mmap, void *addr, SIZE_T length, int prot, int flags, 20 int fd, OFF_T offset) { 21 void *res = REAL(mmap)(addr, length, prot, flags, fd, offset); 22 if (res != (void*)-1) 23 dfsan_set_label(0, res, RoundUpTo(length, GetPageSize())); 24 return res; 25 } 26 27 INTERCEPTOR(void *, mmap64, void *addr, SIZE_T length, int prot, int flags, 28 int fd, OFF64_T offset) { 29 void *res = REAL(mmap64)(addr, length, prot, flags, fd, offset); 30 if (res != (void*)-1) 31 dfsan_set_label(0, res, RoundUpTo(length, GetPageSize())); 32 return res; 33 } 34 35 namespace __dfsan { 36 void InitializeInterceptors() { 37 static int inited = 0; 38 CHECK_EQ(inited, 0); 39 40 INTERCEPT_FUNCTION(mmap); 41 INTERCEPT_FUNCTION(mmap64); 42 inited = 1; 43 } 44 } // namespace __dfsan 45