1 | //===-- memprof_linux.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 is a part of MemProfiler, a memory profiler. |
10 | // |
11 | // Linux-specific details. |
12 | //===----------------------------------------------------------------------===// |
13 | |
14 | #include "sanitizer_common/sanitizer_platform.h" |
15 | #if !SANITIZER_LINUX |
16 | #error Unsupported OS |
17 | #endif |
18 | |
19 | #include "memprof_interceptors.h" |
20 | #include "memprof_internal.h" |
21 | #include "memprof_thread.h" |
22 | #include "sanitizer_common/sanitizer_flags.h" |
23 | #include "sanitizer_common/sanitizer_libc.h" |
24 | #include "sanitizer_common/sanitizer_procmaps.h" |
25 | |
26 | #include <dlfcn.h> |
27 | #include <fcntl.h> |
28 | #include <limits.h> |
29 | #include <link.h> |
30 | #include <pthread.h> |
31 | #include <stdio.h> |
32 | #include <sys/mman.h> |
33 | #include <sys/resource.h> |
34 | #include <sys/syscall.h> |
35 | #include <sys/time.h> |
36 | #include <sys/types.h> |
37 | #include <sys/ucontext.h> |
38 | #include <unistd.h> |
39 | #include <unwind.h> |
40 | |
41 | typedef enum { |
42 | MEMPROF_RT_VERSION_UNDEFINED = 0, |
43 | MEMPROF_RT_VERSION_DYNAMIC, |
44 | MEMPROF_RT_VERSION_STATIC, |
45 | } memprof_rt_version_t; |
46 | |
47 | // FIXME: perhaps also store abi version here? |
48 | extern "C"{ |
49 | SANITIZER_INTERFACE_ATTRIBUTE |
50 | memprof_rt_version_t __memprof_rt_version; |
51 | } |
52 | |
53 | namespace __memprof { |
54 | |
55 | void InitializePlatformInterceptors() {} |
56 | void InitializePlatformExceptionHandlers() {} |
57 | |
58 | uptr FindDynamicShadowStart() { |
59 | uptr shadow_size_bytes = MemToShadowSize(size: kHighMemEnd); |
60 | return MapDynamicShadow(shadow_size_bytes, SHADOW_SCALE, |
61 | /*min_shadow_base_alignment*/ 0, high_mem_end&: kHighMemEnd); |
62 | } |
63 | |
64 | void *MemprofDlSymNext(const char *sym) { return dlsym(RTLD_NEXT, name: sym); } |
65 | |
66 | } // namespace __memprof |
67 |