blob: 33016e6de385834a85b879df8201b0906ffd368f [file] [log] [blame]
Thiébaud Weksteene7e750e2020-11-19 15:07:46 +01001/*
2 * Copyright (C) 2020 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef SIMPLE_PERF_KALLSYMS_H_
18#define SIMPLE_PERF_KALLSYMS_H_
19
20#include <string>
21
22#include "environment.h"
23
24namespace simpleperf {
25
26struct KernelSymbol {
27 uint64_t addr;
28 char type;
29 const char* name;
30 const char* module; // If nullptr, the symbol is not in a kernel module.
31};
32
33// Parses symbol_data as the content of /proc/kallsyms, calling the callback for
34// each symbol that is found. Stops the parsing if the callback returns true.
35bool ProcessKernelSymbols(std::string& symbol_data,
36 const std::function<bool(const KernelSymbol&)>& callback);
37
Yabin Cui36b57d92020-12-17 17:06:27 -080038#if defined(__linux__)
39
Thiébaud Weksteene7e750e2020-11-19 15:07:46 +010040// Returns the list of currently loaded kernel modules.
41std::vector<KernelMmap> GetLoadedModules();
42
43// Returns the start address of the kernel. It uses /proc/kallsyms to find this
44// address. Returns 0 if unknown.
45uint64_t GetKernelStartAddress();
46
47// Loads the /proc/kallsyms file, requesting access if required. The value of
48// kptr_restrict might be modified during the process. Its original value will
49// be restored. This usually requires root privileges.
Yabin Cui58740ff2021-03-23 13:34:51 -070050bool LoadKernelSymbols(std::string* kallsyms);
Thiébaud Weksteene7e750e2020-11-19 15:07:46 +010051
Yabin Cui6e7f33a2021-05-05 15:43:35 -070052// only for testing
53void ResetKernelAddressWarning();
54
Yabin Cui36b57d92020-12-17 17:06:27 -080055#endif // defined(__linux__)
56
Thiébaud Weksteene7e750e2020-11-19 15:07:46 +010057} // namespace simpleperf
58
59#endif // SIMPLE_PERF_KALLSYMS_H_