1//===-- copyprof_interceptors.cpp ----------------------------------------===//
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 implements standard library function interceptors for CopyProf,
10/// tracking memory operations across intercepted library calls.
11///
12//===----------------------------------------------------------------------===//
13
14#include "copyprof_interceptors.h"
15
16#include "copyprof/copyprof_interface_internal.h"
17#include "copyprof/copyprof_internal.h"
18#include "interception/interception.h"
19#include "sanitizer_common/sanitizer_allocator_dlsym.h"
20#include "sanitizer_common/sanitizer_common.h"
21#include "sanitizer_common/sanitizer_flags.h"
22#include "sanitizer_common/sanitizer_internal_defs.h"
23
24using namespace __copyprof;
25
26namespace __copyprof {
27
28int CopyProfOnExit() { return 0; }
29
30} // namespace __copyprof
31
32#define COMMON_INTERCEPTOR_DIR_ACQUIRE(ctx, path) \
33 do { \
34 } while (false)
35
36#define COMMON_INTERCEPTOR_FD_ACQUIRE(ctx, fd) \
37 do { \
38 } while (false)
39
40#define COMMON_INTERCEPTOR_FD_RELEASE(ctx, fd) \
41 do { \
42 } while (false)
43
44#define COMMON_INTERCEPTOR_FD_SOCKET_ACCEPT(ctx, fd, newfd) \
45 do { \
46 } while (false)
47
48#define COMMON_INTERCEPTOR_SET_THREAD_NAME(ctx, name) \
49 do { \
50 } while (false)
51
52#define COMMON_INTERCEPTOR_ON_EXIT(ctx) CopyProfOnExit()
53
54#define COMMON_INTERCEPTOR_SET_PTHREAD_NAME(ctx, thread, name) \
55 do { \
56 } while (false)
57
58#define COMMON_INTERCEPT_FUNCTION_VER(name, ver) \
59 do { \
60 if (!INTERCEPT_FUNCTION_VER(name, ver)) \
61 VReport(1, "CopyProf: failed to intercept '%s@@%s'\n", #name, ver); \
62 } while (0)
63
64#define COMMON_INTERCEPT_FUNCTION_VER_UNVERSIONED_FALLBACK(name, ver) \
65 do { \
66 if (!INTERCEPT_FUNCTION_VER(name, ver) && !INTERCEPT_FUNCTION(name)) \
67 VReport(1, "CopyProf: failed to intercept '%s@@%s' or '%s'\n", #name, \
68 ver, #name); \
69 } while (0)
70
71#define COMMON_INTERCEPTOR_BLOCK_REAL(name) REAL(name)
72
73#include "sanitizer_common/sanitizer_common_interceptors.inc"
74
75namespace __copyprof {
76
77void InitializeInterceptors() {
78 static bool initialized;
79 CHECK(!initialized);
80 initialized = true;
81 InitializeHeapInterceptors();
82 InitializeCommonInterceptors();
83}
84
85} // namespace __copyprof
86