xref: /freebsd-src/contrib/llvm-project/compiler-rt/lib/dfsan/dfsan_interceptors.cpp (revision 68d75eff68281c1b445e3010bb975eae07aac225)
1*68d75effSDimitry Andric //===-- dfsan_interceptors.cpp --------------------------------------------===//
2*68d75effSDimitry Andric //
3*68d75effSDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4*68d75effSDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
5*68d75effSDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6*68d75effSDimitry Andric //
7*68d75effSDimitry Andric //===----------------------------------------------------------------------===//
8*68d75effSDimitry Andric //
9*68d75effSDimitry Andric // This file is a part of DataFlowSanitizer.
10*68d75effSDimitry Andric //
11*68d75effSDimitry Andric // Interceptors for standard library functions.
12*68d75effSDimitry Andric //===----------------------------------------------------------------------===//
13*68d75effSDimitry Andric 
14*68d75effSDimitry Andric #include "dfsan/dfsan.h"
15*68d75effSDimitry Andric #include "interception/interception.h"
16*68d75effSDimitry Andric #include "sanitizer_common/sanitizer_common.h"
17*68d75effSDimitry Andric 
18*68d75effSDimitry Andric using namespace __sanitizer;
19*68d75effSDimitry Andric 
20*68d75effSDimitry Andric INTERCEPTOR(void *, mmap, void *addr, SIZE_T length, int prot, int flags,
21*68d75effSDimitry Andric             int fd, OFF_T offset) {
22*68d75effSDimitry Andric   void *res = REAL(mmap)(addr, length, prot, flags, fd, offset);
23*68d75effSDimitry Andric   if (res != (void*)-1)
24*68d75effSDimitry Andric     dfsan_set_label(0, res, RoundUpTo(length, GetPageSize()));
25*68d75effSDimitry Andric   return res;
26*68d75effSDimitry Andric }
27*68d75effSDimitry Andric 
28*68d75effSDimitry Andric INTERCEPTOR(void *, mmap64, void *addr, SIZE_T length, int prot, int flags,
29*68d75effSDimitry Andric             int fd, OFF64_T offset) {
30*68d75effSDimitry Andric   void *res = REAL(mmap64)(addr, length, prot, flags, fd, offset);
31*68d75effSDimitry Andric   if (res != (void*)-1)
32*68d75effSDimitry Andric     dfsan_set_label(0, res, RoundUpTo(length, GetPageSize()));
33*68d75effSDimitry Andric   return res;
34*68d75effSDimitry Andric }
35*68d75effSDimitry Andric 
36*68d75effSDimitry Andric namespace __dfsan {
37*68d75effSDimitry Andric void InitializeInterceptors() {
38*68d75effSDimitry Andric   static int inited = 0;
39*68d75effSDimitry Andric   CHECK_EQ(inited, 0);
40*68d75effSDimitry Andric 
41*68d75effSDimitry Andric   INTERCEPT_FUNCTION(mmap);
42*68d75effSDimitry Andric   INTERCEPT_FUNCTION(mmap64);
43*68d75effSDimitry Andric   inited = 1;
44*68d75effSDimitry Andric }
45*68d75effSDimitry Andric }  // namespace __dfsan
46