memprof_interceptors.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. #include "interception/interception.h"
  16. #include "memprof_interceptors_memintrinsics.h"
  17. #include "memprof_internal.h"
  18. #include "sanitizer_common/sanitizer_platform_interceptors.h"
  19. namespace __memprof {
  20. void InitializeMemprofInterceptors();
  21. void InitializePlatformInterceptors();
  22. #define ENSURE_MEMPROF_INITED() \
  23. do { \
  24. CHECK(!memprof_init_is_running); \
  25. if (UNLIKELY(!memprof_inited)) { \
  26. MemprofInitFromRtl(); \
  27. } \
  28. } while (0)
  29. } // namespace __memprof
  30. DECLARE_REAL(int, memcmp, const void *a1, const void *a2, uptr size)
  31. DECLARE_REAL(char *, strchr, const char *str, int c)
  32. DECLARE_REAL(SIZE_T, strlen, const char *s)
  33. DECLARE_REAL(char *, strncpy, char *to, const char *from, uptr size)
  34. DECLARE_REAL(uptr, strnlen, const char *s, uptr maxlen)
  35. DECLARE_REAL(char *, strstr, const char *s1, const char *s2)
  36. #define MEMPROF_INTERCEPT_FUNC(name) \
  37. do { \
  38. if (!INTERCEPT_FUNCTION(name)) \
  39. VReport(1, "MemProfiler: failed to intercept '%s'\n'", #name); \
  40. } while (0)
  41. #define MEMPROF_INTERCEPT_FUNC_VER(name, ver) \
  42. do { \
  43. if (!INTERCEPT_FUNCTION_VER(name, ver)) \
  44. VReport(1, "MemProfiler: failed to intercept '%s@@%s'\n", #name, ver); \
  45. } while (0)
  46. #define MEMPROF_INTERCEPT_FUNC_VER_UNVERSIONED_FALLBACK(name, ver) \
  47. do { \
  48. if (!INTERCEPT_FUNCTION_VER(name, ver) && !INTERCEPT_FUNCTION(name)) \
  49. VReport(1, "MemProfiler: failed to intercept '%s@@%s' or '%s'\n", #name, \
  50. ver, #name); \
  51. } while (0)
  52. #endif // MEMPROF_INTERCEPTORS_H