1 //===-- memprof_interceptors.h ---------------------------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file is a part of MemProfiler, a memory profiler.
10 //
11 // MemProf-private header for memprof_interceptors.cpp
12 //===----------------------------------------------------------------------===//
13 #ifndef MEMPROF_INTERCEPTORS_H
14 #define MEMPROF_INTERCEPTORS_H
15 
16 #include "interception/interception.h"
17 #include "memprof_interceptors_memintrinsics.h"
18 #include "memprof_internal.h"
19 #include "sanitizer_common/sanitizer_platform_interceptors.h"
20 
21 namespace __memprof {
22 
23 void InitializeMemprofInterceptors();
24 void InitializePlatformInterceptors();
25 
26 #define ENSURE_MEMPROF_INITED()                                                \
27   do {                                                                         \
28     CHECK(!memprof_init_is_running);                                           \
29     if (UNLIKELY(!memprof_inited)) {                                           \
30       MemprofInitFromRtl();                                                    \
31     }                                                                          \
32   } while (0)
33 
34 } // namespace __memprof
35 
36 DECLARE_REAL(int, memcmp, const void *a1, const void *a2, uptr size)
37 DECLARE_REAL(char *, strchr, const char *str, int c)
38 DECLARE_REAL(SIZE_T, strlen, const char *s)
39 DECLARE_REAL(char *, strncpy, char *to, const char *from, uptr size)
40 DECLARE_REAL(uptr, strnlen, const char *s, uptr maxlen)
41 DECLARE_REAL(char *, strstr, const char *s1, const char *s2)
42 
43 #define MEMPROF_INTERCEPT_FUNC(name)                                           \
44   do {                                                                         \
45     if (!INTERCEPT_FUNCTION(name))                                             \
46       VReport(1, "MemProfiler: failed to intercept '%s'\n'", #name);           \
47   } while (0)
48 #define MEMPROF_INTERCEPT_FUNC_VER(name, ver)                                  \
49   do {                                                                         \
50     if (!INTERCEPT_FUNCTION_VER(name, ver))                                    \
51       VReport(1, "MemProfiler: failed to intercept '%s@@%s'\n", #name, ver);   \
52   } while (0)
53 #define MEMPROF_INTERCEPT_FUNC_VER_UNVERSIONED_FALLBACK(name, ver)             \
54   do {                                                                         \
55     if (!INTERCEPT_FUNCTION_VER(name, ver) && !INTERCEPT_FUNCTION(name))       \
56       VReport(1, "MemProfiler: failed to intercept '%s@@%s' or '%s'\n", #name, \
57               ver, #name);                                                     \
58   } while (0)
59 
60 #endif // MEMPROF_INTERCEPTORS_H
61