-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathplugin.h
156 lines (139 loc) · 7.08 KB
/
plugin.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
// Copyright (c) 2024-2025 Qualcomm Innovation Center, Inc. All rights reserved.
// SPDX-License-Identifier: BSD-3-Clause-Clear
#ifndef PARSER_DEFS_H_
#define PARSER_DEFS_H_
#include <iostream>
#include <string>
#include <vector>
#include <linux/types.h>
#include <unistd.h>
#include <getopt.h>
#include <unordered_map>
#include <memory>
#include <functional>
#include <algorithm>
#include <bitset>
#include <set>
#include <regex.h>
#include <execinfo.h>
#include <stdio.h>
#include <stdlib.h>
#include <iomanip>
#include <arpa/inet.h>
#include <inttypes.h>
#include "struct_info.h"
#include "logger/log.h"
#define field_init(type,field_name) type_init(TO_STD_STRING(type),TO_STD_STRING(field_name))
#define field_size(type,field_name) type_size(TO_STD_STRING(type),TO_STD_STRING(field_name))
#define field_offset(type,field_name) type_offset(TO_STD_STRING(type),TO_STD_STRING(field_name))
#define struct_init(type) type_init(TO_STD_STRING(type))
#define struct_size(type) type_size(TO_STD_STRING(type))
#define IS_ALIGNED(x, a) (((x) & ((typeof(x))(a) - 1)) == 0)
typedef struct {
long long counter;
} atomic64_t;
typedef struct {
int counter;
} atomic_t;
typedef struct {
int counter;
} atomic_long_t;
class PaserPlugin {
protected:
std::unordered_map<std::string, std::unique_ptr<Typeinfo>> typetable;
public:
PaserPlugin();
const uint page_size = PAGESIZE();
const uint page_shift = PAGESHIFT();
const ulong page_mask = ~((ulong)(page_size - 1));
std::string cmd_name;
std::vector<std::string> help_str_list;
char** cmd_help;
virtual void cmd_main(void)=0;
void initialize(void);
void convert_size(int64_t size,char* buf);
void print_table();
void type_init(const std::string& type);
void type_init(const std::string& type,const std::string& field);
int type_offset(const std::string& type,const std::string& field);
int type_size(const std::string& type,const std::string& field);
int type_size(const std::string& type);
std::vector<ulong> for_each_rbtree(ulong rb_root,int offset);
std::vector<ulong> for_each_list(ulong list_head,int offset);
std::vector<ulong> for_each_hlist(ulong hlist_head,int offset);
std::vector<ulong> for_each_xarray(ulong xarray_addr);
std::vector<ulong> for_each_mptree(ulong maptree_addr);
std::vector<ulong> for_each_radix(ulong root_rnode);
std::vector<ulong> for_each_process();
std::vector<ulong> for_each_threads();
std::vector<ulong> for_each_vma(ulong& task_addr);
std::string read_start_args(ulong& task_addr);
ulonglong read_structure_field(ulong kvaddr,const std::string& type,const std::string& field);
std::string read_cstring(ulong kvaddr,int len, const std::string& note);
void* read_struct(ulong kvaddr,const std::string& type);
bool read_struct(ulong kvaddr,void* buf, int len, const std::string& type);
void* read_memory(ulong kvaddr,int len, const std::string& note);
void* read_phys_memory(ulong paddr, int len, const std::string& note);
ulong read_pointer(ulong kvaddr, const std::string& note);
short read_short(ulong kvaddr,const std::string& note);
ushort read_ushort(ulong kvaddr,const std::string& note);
ulonglong read_ulonglong(ulong kvaddr,const std::string& note);
ulong read_ulong(ulong kvaddr,const std::string& note);
long read_long(ulong kvaddr,const std::string& note);
uint read_uint(ulong kvaddr,const std::string& note);
int read_int(ulong kvaddr,const std::string& note);
bool read_bool(ulong kvaddr,const std::string& note);
unsigned char read_byte(ulong kvaddr, const std::string& note);
int csymbol_exists(const std::string& note);
ulong csymbol_value(const std::string& note);
bool is_kvaddr(ulong addr);
bool is_uvaddr(ulong addr, struct task_context *);
int page_to_nid(ulong page);
ulong virt_to_phy(ulong paddr);
ulong phy_to_virt(ulong vaddr);
ulong page_to_pfn(ulong page);
ulong pfn_to_page(ulong pfn);
ulong phy_to_page(ulong paddr);
physaddr_t page_to_phy(ulong page);
physaddr_t pfn_to_phy(ulong pfn);
ulong phy_to_pfn(ulong paddr);
std::string get_config_val(const std::string& conf_name);
void cfill_pgd(ulonglong pgd, int type, ulong size);
void cfill_pmd(ulonglong pmd, int type, ulong size);
void cfill_ptbl(ulonglong ptbl, int type, ulong size);
void print_backtrace();
bool is_binary_stripped(std::string& filename);
bool add_symbol_file(std::string& filename);
void verify_userspace_symbol(std::string& symbol_name);
bool isNumber(const std::string& str);
std::string extract_string(const char *input);
int is_bigendian(void);
long read_enum_val(const std::string& enum_name);
char get_printable(uint8_t d);
std::string print_line(uint64_t addr, const std::vector<uint8_t>& data);
std::string hexdump(uint64_t addr, const char* buf, size_t length, bool little_endian = true);
};
#define DEFINE_PLUGIN_INSTANCE(class_name) \
static std::unique_ptr<class_name> instance; \
static void wrapper_func() { \
if (instance) { \
instance->cmd_main(); \
} \
}
#ifndef BUILD_TARGET_TOGETHER
#define DEFINE_PLUGIN_COMMAND(class_name) \
extern "C" void class_name##_init(void); \
extern "C" void class_name##_fini(void); \
std::unique_ptr<class_name> class_name::instance = std::make_unique<class_name>(); \
static struct command_table_entry command_table[] = { \
{ &class_name::instance->cmd_name[0], &class_name::wrapper_func, class_name::instance->cmd_help, 0 }, \
{ NULL } \
}; \
extern "C" void __attribute__((constructor)) class_name##_init(void) { \
register_extension(command_table); \
} \
extern "C" void __attribute__((destructor)) class_name##_fini(void) { \
class_name::instance.reset(); \
}
#endif // BUILD_TARGET_TOGETHER
#endif // PARSER_DEFS_H_