1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef __PERF_DSO
3 #define __PERF_DSO
4
5 #include <linux/refcount.h>
6 #include <linux/types.h>
7 #include <linux/rbtree.h>
8 #include <sys/types.h>
9 #include <stdbool.h>
10 #include <stdio.h>
11 #include <linux/bitops.h>
12 #include "build-id.h"
13 #include "debuginfo.h"
14 #include "mutex.h"
15 #include <internal/rc_check.h>
16
17 struct machine;
18 struct map;
19 struct perf_env;
20
21 #define DSO__NAME_KALLSYMS "[kernel.kallsyms]"
22 #define DSO__NAME_KCORE "[kernel.kcore]"
23
24 /**
25 * enum dso_binary_type - The kind of DSO generally associated with a memory
26 * region (struct map).
27 */
28 enum dso_binary_type {
29 /** @DSO_BINARY_TYPE__KALLSYMS: Symbols from /proc/kallsyms file. */
30 DSO_BINARY_TYPE__KALLSYMS = 0,
31 /** @DSO_BINARY_TYPE__GUEST_KALLSYMS: Guest /proc/kallsyms file. */
32 DSO_BINARY_TYPE__GUEST_KALLSYMS,
33 /** @DSO_BINARY_TYPE__VMLINUX: Path to kernel /boot/vmlinux file. */
34 DSO_BINARY_TYPE__VMLINUX,
35 /** @DSO_BINARY_TYPE__GUEST_VMLINUX: Path to guest kernel /boot/vmlinux file. */
36 DSO_BINARY_TYPE__GUEST_VMLINUX,
37 /** @DSO_BINARY_TYPE__JAVA_JIT: Symbols from /tmp/perf.map file. */
38 DSO_BINARY_TYPE__JAVA_JIT,
39 /**
40 * @DSO_BINARY_TYPE__DEBUGLINK: Debug file readable from the file path
41 * in the .gnu_debuglink ELF section of the dso.
42 */
43 DSO_BINARY_TYPE__DEBUGLINK,
44 /**
45 * @DSO_BINARY_TYPE__BUILD_ID_CACHE: File named after buildid located in
46 * the buildid cache with an elf filename.
47 */
48 DSO_BINARY_TYPE__BUILD_ID_CACHE,
49 /**
50 * @DSO_BINARY_TYPE__BUILD_ID_CACHE_DEBUGINFO: File named after buildid
51 * located in the buildid cache with a debug filename.
52 */
53 DSO_BINARY_TYPE__BUILD_ID_CACHE_DEBUGINFO,
54 /**
55 * @DSO_BINARY_TYPE__FEDORA_DEBUGINFO: Debug file in /usr/lib/debug
56 * with .debug suffix.
57 */
58 DSO_BINARY_TYPE__FEDORA_DEBUGINFO,
59 /** @DSO_BINARY_TYPE__UBUNTU_DEBUGINFO: Debug file in /usr/lib/debug. */
60 DSO_BINARY_TYPE__UBUNTU_DEBUGINFO,
61 /**
62 * @DSO_BINARY_TYPE__MIXEDUP_UBUNTU_DEBUGINFO: dso__long_name debuginfo
63 * file in /usr/lib/debug/lib rather than the expected
64 * /usr/lib/debug/usr/lib.
65 */
66 DSO_BINARY_TYPE__MIXEDUP_UBUNTU_DEBUGINFO,
67 /**
68 * @DSO_BINARY_TYPE__BUILDID_DEBUGINFO: File named after buildid located
69 * in /usr/lib/debug/.build-id/.
70 */
71 DSO_BINARY_TYPE__BUILDID_DEBUGINFO,
72 /**
73 * @DSO_BINARY_TYPE__GNU_DEBUGDATA: MiniDebuginfo where a compressed
74 * ELF file is placed in a .gnu_debugdata section.
75 */
76 DSO_BINARY_TYPE__GNU_DEBUGDATA,
77 /** @DSO_BINARY_TYPE__SYSTEM_PATH_DSO: A regular executable/shared-object file. */
78 DSO_BINARY_TYPE__SYSTEM_PATH_DSO,
79 /** @DSO_BINARY_TYPE__GUEST_KMODULE: Guest kernel module .ko file. */
80 DSO_BINARY_TYPE__GUEST_KMODULE,
81 /** @DSO_BINARY_TYPE__GUEST_KMODULE_COMP: Guest kernel module .ko.gz file. */
82 DSO_BINARY_TYPE__GUEST_KMODULE_COMP,
83 /** @DSO_BINARY_TYPE__SYSTEM_PATH_KMODULE: Kernel module .ko file. */
84 DSO_BINARY_TYPE__SYSTEM_PATH_KMODULE,
85 /** @DSO_BINARY_TYPE__SYSTEM_PATH_KMODULE_COMP: Kernel module .ko.gz file. */
86 DSO_BINARY_TYPE__SYSTEM_PATH_KMODULE_COMP,
87 /** @DSO_BINARY_TYPE__KCORE: /proc/kcore file. */
88 DSO_BINARY_TYPE__KCORE,
89 /** @DSO_BINARY_TYPE__GUEST_KCORE: Guest /proc/kcore file. */
90 DSO_BINARY_TYPE__GUEST_KCORE,
91 /**
92 * @DSO_BINARY_TYPE__OPENEMBEDDED_DEBUGINFO: Openembedded/Yocto -dbg
93 * package debug info.
94 */
95 DSO_BINARY_TYPE__OPENEMBEDDED_DEBUGINFO,
96 /** @DSO_BINARY_TYPE__BPF_PROG_INFO: jitted BPF code. */
97 DSO_BINARY_TYPE__BPF_PROG_INFO,
98 /** @DSO_BINARY_TYPE__BPF_IMAGE: jitted BPF trampoline or dispatcher code. */
99 DSO_BINARY_TYPE__BPF_IMAGE,
100 /**
101 * @DSO_BINARY_TYPE__OOL: out of line code such as kprobe-replaced
102 * instructions or optimized kprobes or ftrace trampolines.
103 */
104 DSO_BINARY_TYPE__OOL,
105 /** @DSO_BINARY_TYPE__NOT_FOUND: Unknown DSO kind. */
106 DSO_BINARY_TYPE__NOT_FOUND,
107 };
108
109 enum dso_space_type {
110 DSO_SPACE__USER = 0,
111 DSO_SPACE__KERNEL,
112 DSO_SPACE__KERNEL_GUEST
113 };
114
115 enum dso_swap_type {
116 DSO_SWAP__UNSET,
117 DSO_SWAP__NO,
118 DSO_SWAP__YES,
119 };
120
121 enum dso_data_status {
122 DSO_DATA_STATUS_ERROR = -1,
123 DSO_DATA_STATUS_UNKNOWN = 0,
124 DSO_DATA_STATUS_OK = 1,
125 };
126
127 enum dso_data_status_seen {
128 DSO_DATA_STATUS_SEEN_ITRACE,
129 };
130
131 enum dso_type {
132 DSO__TYPE_UNKNOWN,
133 DSO__TYPE_64BIT,
134 DSO__TYPE_32BIT,
135 DSO__TYPE_X32BIT,
136 };
137
138 enum dso_load_errno {
139 DSO_LOAD_ERRNO__SUCCESS = 0,
140
141 /*
142 * Choose an arbitrary negative big number not to clash with standard
143 * errno since SUS requires the errno has distinct positive values.
144 * See 'Issue 6' in the link below.
145 *
146 * http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/errno.h.html
147 */
148 __DSO_LOAD_ERRNO__START = -10000,
149
150 DSO_LOAD_ERRNO__INTERNAL_ERROR = __DSO_LOAD_ERRNO__START,
151
152 /* for symsrc__init() */
153 DSO_LOAD_ERRNO__INVALID_ELF,
154 DSO_LOAD_ERRNO__CANNOT_READ_BUILDID,
155 DSO_LOAD_ERRNO__MISMATCHING_BUILDID,
156
157 /* for decompress_kmodule */
158 DSO_LOAD_ERRNO__DECOMPRESSION_FAILURE,
159
160 __DSO_LOAD_ERRNO__END,
161 };
162
163 #define DSO__SWAP(dso, type, val) \
164 ({ \
165 type ____r = val; \
166 enum dso_swap_type ___dst = dso__needs_swap(dso); \
167 BUG_ON(___dst == DSO_SWAP__UNSET); \
168 if (___dst == DSO_SWAP__YES) { \
169 switch (sizeof(____r)) { \
170 case 2: \
171 ____r = bswap_16(val); \
172 break; \
173 case 4: \
174 ____r = bswap_32(val); \
175 break; \
176 case 8: \
177 ____r = bswap_64(val); \
178 break; \
179 default: \
180 BUG_ON(1); \
181 } \
182 } \
183 ____r; \
184 })
185
186 #define DSO__DATA_CACHE_SIZE 4096
187 #define DSO__DATA_CACHE_MASK ~(DSO__DATA_CACHE_SIZE - 1)
188
189 /**
190 * struct dso_id
191 *
192 * Data about backing storage DSO, comes from PERF_RECORD_MMAP2 meta events,
193 * reading from /proc/pid/maps or synthesis of build_ids from DSOs. Possibly
194 * incomplete at any particular use.
195 */
196 struct dso_id {
197 /* Data related to the mmap2 event or read from /proc/pid/maps. */
198 struct {
199 u32 maj;
200 u32 min;
201 u64 ino;
202 u64 ino_generation;
203 };
204 /** @mmap2_valid: Are the maj, min and ino fields valid? */
205 bool mmap2_valid;
206 /**
207 * @mmap2_ino_generation_valid: Is the ino_generation valid? Generally
208 * false for /proc/pid/maps mmap event.
209 */
210 bool mmap2_ino_generation_valid;
211 /**
212 * @build_id: A possibly populated build_id. build_id__is_defined checks
213 * whether it is populated.
214 */
215 struct build_id build_id;
216 };
217
218 struct dso_cache {
219 struct rb_node rb_node;
220 u64 offset;
221 u64 size;
222 char data[];
223 };
224
225 struct dso_data {
226 struct rb_root cache;
227 struct list_head open_entry;
228 #ifdef REFCNT_CHECKING
229 struct dso *dso;
230 #endif
231 int fd;
232 int status;
233 u32 status_seen;
234 u64 file_size;
235 #ifdef HAVE_LIBUNWIND_SUPPORT
236 u64 elf_base_addr;
237 u64 debug_frame_offset;
238 u64 eh_frame_hdr_addr;
239 u64 eh_frame_hdr_offset;
240 #endif
241 };
242
243 struct dso_bpf_prog {
244 u32 id;
245 u32 sub_id;
246 struct perf_env *env;
247 };
248
249 struct auxtrace_cache;
250
DECLARE_RC_STRUCT(dso)251 DECLARE_RC_STRUCT(dso) {
252 struct mutex lock;
253 struct dsos *dsos;
254 struct rb_root_cached symbols;
255 struct symbol **symbol_names;
256 size_t symbol_names_len;
257 struct rb_root_cached inlined_nodes;
258 struct rb_root_cached srclines;
259 struct rb_root data_types;
260 struct rb_root global_vars;
261
262 struct {
263 u64 addr;
264 struct symbol *symbol;
265 } last_find_result;
266 u64 text_offset;
267 u64 text_end;
268 const char *short_name;
269 const char *long_name;
270 void *a2l;
271 char *symsrc_filename;
272 #if defined(__powerpc__)
273 void *dwfl; /* DWARF debug info */
274 #endif
275 struct nsinfo *nsinfo;
276 struct auxtrace_cache *auxtrace_cache;
277 union { /* Tool specific area */
278 void *priv;
279 u64 db_id;
280 };
281 /* bpf prog information */
282 struct dso_bpf_prog bpf_prog;
283 /* dso data file */
284 struct dso_data data;
285 struct dso_id id;
286 unsigned int a2l_fails;
287 int comp;
288 refcount_t refcnt;
289 enum dso_load_errno load_errno;
290 u16 long_name_len;
291 u16 short_name_len;
292 enum dso_binary_type symtab_type:8;
293 enum dso_binary_type binary_type:8;
294 enum dso_space_type kernel:2;
295 enum dso_swap_type needs_swap:2;
296 bool is_kmod:1;
297 u8 adjust_symbols:1;
298 u8 header_build_id:1;
299 u8 has_srcline:1;
300 u8 hit:1;
301 u8 annotate_warned:1;
302 u8 auxtrace_warned:1;
303 u8 debuginfo_warned:1;
304 u8 short_name_allocated:1;
305 u8 long_name_allocated:1;
306 u8 is_64_bit:1;
307 bool sorted_by_name;
308 bool loaded;
309 u8 rel;
310 char name[];
311 };
312
313 extern struct mutex _dso__data_open_lock;
314 extern const struct dso_id dso_id_empty;
315
316 int dso_id__cmp(const struct dso_id *a, const struct dso_id *b);
317
318 /* dso__for_each_symbol - iterate over the symbols of given type
319 *
320 * @dso: the 'struct dso *' in which symbols are iterated
321 * @pos: the 'struct symbol *' to use as a loop cursor
322 * @n: the 'struct rb_node *' to use as a temporary storage
323 */
324 #define dso__for_each_symbol(dso, pos, n) \
325 symbols__for_each_entry(dso__symbols(dso), pos, n)
326
dso__a2l(const struct dso * dso)327 static inline void *dso__a2l(const struct dso *dso)
328 {
329 return RC_CHK_ACCESS(dso)->a2l;
330 }
331
dso__set_a2l(struct dso * dso,void * val)332 static inline void dso__set_a2l(struct dso *dso, void *val)
333 {
334 RC_CHK_ACCESS(dso)->a2l = val;
335 }
336
dso__a2l_fails(const struct dso * dso)337 static inline unsigned int dso__a2l_fails(const struct dso *dso)
338 {
339 return RC_CHK_ACCESS(dso)->a2l_fails;
340 }
341
dso__set_a2l_fails(struct dso * dso,unsigned int val)342 static inline void dso__set_a2l_fails(struct dso *dso, unsigned int val)
343 {
344 RC_CHK_ACCESS(dso)->a2l_fails = val;
345 }
346
dso__adjust_symbols(const struct dso * dso)347 static inline bool dso__adjust_symbols(const struct dso *dso)
348 {
349 return RC_CHK_ACCESS(dso)->adjust_symbols;
350 }
351
dso__set_adjust_symbols(struct dso * dso,bool val)352 static inline void dso__set_adjust_symbols(struct dso *dso, bool val)
353 {
354 RC_CHK_ACCESS(dso)->adjust_symbols = val;
355 }
356
dso__annotate_warned(const struct dso * dso)357 static inline bool dso__annotate_warned(const struct dso *dso)
358 {
359 return RC_CHK_ACCESS(dso)->annotate_warned;
360 }
361
dso__set_annotate_warned(struct dso * dso)362 static inline void dso__set_annotate_warned(struct dso *dso)
363 {
364 RC_CHK_ACCESS(dso)->annotate_warned = 1;
365 }
366
dso__debuginfo_warned(const struct dso * dso)367 static inline bool dso__debuginfo_warned(const struct dso *dso)
368 {
369 return RC_CHK_ACCESS(dso)->debuginfo_warned;
370 }
371
dso__set_debuginfo_warned(struct dso * dso)372 static inline void dso__set_debuginfo_warned(struct dso *dso)
373 {
374 RC_CHK_ACCESS(dso)->debuginfo_warned = 1;
375 }
376
dso__auxtrace_warned(const struct dso * dso)377 static inline bool dso__auxtrace_warned(const struct dso *dso)
378 {
379 return RC_CHK_ACCESS(dso)->auxtrace_warned;
380 }
381
dso__set_auxtrace_warned(struct dso * dso)382 static inline void dso__set_auxtrace_warned(struct dso *dso)
383 {
384 RC_CHK_ACCESS(dso)->auxtrace_warned = 1;
385 }
386
dso__auxtrace_cache(struct dso * dso)387 static inline struct auxtrace_cache *dso__auxtrace_cache(struct dso *dso)
388 {
389 return RC_CHK_ACCESS(dso)->auxtrace_cache;
390 }
391
dso__set_auxtrace_cache(struct dso * dso,struct auxtrace_cache * cache)392 static inline void dso__set_auxtrace_cache(struct dso *dso, struct auxtrace_cache *cache)
393 {
394 RC_CHK_ACCESS(dso)->auxtrace_cache = cache;
395 }
396
dso__bpf_prog(struct dso * dso)397 static inline struct dso_bpf_prog *dso__bpf_prog(struct dso *dso)
398 {
399 return &RC_CHK_ACCESS(dso)->bpf_prog;
400 }
401
dso__has_srcline(const struct dso * dso)402 static inline bool dso__has_srcline(const struct dso *dso)
403 {
404 return RC_CHK_ACCESS(dso)->has_srcline;
405 }
406
dso__set_has_srcline(struct dso * dso,bool val)407 static inline void dso__set_has_srcline(struct dso *dso, bool val)
408 {
409 RC_CHK_ACCESS(dso)->has_srcline = val;
410 }
411
dso__comp(const struct dso * dso)412 static inline int dso__comp(const struct dso *dso)
413 {
414 return RC_CHK_ACCESS(dso)->comp;
415 }
416
dso__set_comp(struct dso * dso,int comp)417 static inline void dso__set_comp(struct dso *dso, int comp)
418 {
419 RC_CHK_ACCESS(dso)->comp = comp;
420 }
421
dso__data(struct dso * dso)422 static inline struct dso_data *dso__data(struct dso *dso)
423 {
424 return &RC_CHK_ACCESS(dso)->data;
425 }
426
dso__db_id(const struct dso * dso)427 static inline u64 dso__db_id(const struct dso *dso)
428 {
429 return RC_CHK_ACCESS(dso)->db_id;
430 }
431
dso__set_db_id(struct dso * dso,u64 db_id)432 static inline void dso__set_db_id(struct dso *dso, u64 db_id)
433 {
434 RC_CHK_ACCESS(dso)->db_id = db_id;
435 }
436
dso__dsos(struct dso * dso)437 static inline struct dsos *dso__dsos(struct dso *dso)
438 {
439 return RC_CHK_ACCESS(dso)->dsos;
440 }
441
dso__set_dsos(struct dso * dso,struct dsos * dsos)442 static inline void dso__set_dsos(struct dso *dso, struct dsos *dsos)
443 {
444 RC_CHK_ACCESS(dso)->dsos = dsos;
445 }
446
dso__header_build_id(struct dso * dso)447 static inline bool dso__header_build_id(struct dso *dso)
448 {
449 return RC_CHK_ACCESS(dso)->header_build_id;
450 }
451
dso__set_header_build_id(struct dso * dso,bool val)452 static inline void dso__set_header_build_id(struct dso *dso, bool val)
453 {
454 RC_CHK_ACCESS(dso)->header_build_id = val;
455 }
456
dso__hit(const struct dso * dso)457 static inline bool dso__hit(const struct dso *dso)
458 {
459 return RC_CHK_ACCESS(dso)->hit;
460 }
461
dso__set_hit(struct dso * dso)462 static inline void dso__set_hit(struct dso *dso)
463 {
464 RC_CHK_ACCESS(dso)->hit = 1;
465 }
466
dso__id(struct dso * dso)467 static inline struct dso_id *dso__id(struct dso *dso)
468 {
469 return &RC_CHK_ACCESS(dso)->id;
470 }
471
dso__id_const(const struct dso * dso)472 static inline const struct dso_id *dso__id_const(const struct dso *dso)
473 {
474 return &RC_CHK_ACCESS(dso)->id;
475 }
476
dso__bid(const struct dso * dso)477 static inline const struct build_id *dso__bid(const struct dso *dso)
478 {
479 return &dso__id_const(dso)->build_id;
480 }
481
dso__has_build_id(const struct dso * dso)482 static inline bool dso__has_build_id(const struct dso *dso)
483 {
484 return build_id__is_defined(dso__bid(dso));
485 }
486
dso__inlined_nodes(struct dso * dso)487 static inline struct rb_root_cached *dso__inlined_nodes(struct dso *dso)
488 {
489 return &RC_CHK_ACCESS(dso)->inlined_nodes;
490 }
491
dso__is_64_bit(const struct dso * dso)492 static inline bool dso__is_64_bit(const struct dso *dso)
493 {
494 return RC_CHK_ACCESS(dso)->is_64_bit;
495 }
496
dso__set_is_64_bit(struct dso * dso,bool is)497 static inline void dso__set_is_64_bit(struct dso *dso, bool is)
498 {
499 RC_CHK_ACCESS(dso)->is_64_bit = is;
500 }
501
dso__is_kmod(const struct dso * dso)502 static inline bool dso__is_kmod(const struct dso *dso)
503 {
504 return RC_CHK_ACCESS(dso)->is_kmod;
505 }
506
dso__set_is_kmod(struct dso * dso)507 static inline void dso__set_is_kmod(struct dso *dso)
508 {
509 RC_CHK_ACCESS(dso)->is_kmod = 1;
510 }
511
dso__kernel(const struct dso * dso)512 static inline enum dso_space_type dso__kernel(const struct dso *dso)
513 {
514 return RC_CHK_ACCESS(dso)->kernel;
515 }
516
dso__set_kernel(struct dso * dso,enum dso_space_type kernel)517 static inline void dso__set_kernel(struct dso *dso, enum dso_space_type kernel)
518 {
519 RC_CHK_ACCESS(dso)->kernel = kernel;
520 }
521
dso__last_find_result_addr(const struct dso * dso)522 static inline u64 dso__last_find_result_addr(const struct dso *dso)
523 {
524 return RC_CHK_ACCESS(dso)->last_find_result.addr;
525 }
526
dso__set_last_find_result_addr(struct dso * dso,u64 addr)527 static inline void dso__set_last_find_result_addr(struct dso *dso, u64 addr)
528 {
529 RC_CHK_ACCESS(dso)->last_find_result.addr = addr;
530 }
531
dso__last_find_result_symbol(const struct dso * dso)532 static inline struct symbol *dso__last_find_result_symbol(const struct dso *dso)
533 {
534 return RC_CHK_ACCESS(dso)->last_find_result.symbol;
535 }
536
dso__set_last_find_result_symbol(struct dso * dso,struct symbol * symbol)537 static inline void dso__set_last_find_result_symbol(struct dso *dso, struct symbol *symbol)
538 {
539 RC_CHK_ACCESS(dso)->last_find_result.symbol = symbol;
540 }
541
dso__load_errno(struct dso * dso)542 static inline enum dso_load_errno *dso__load_errno(struct dso *dso)
543 {
544 return &RC_CHK_ACCESS(dso)->load_errno;
545 }
546
dso__set_loaded(struct dso * dso)547 static inline void dso__set_loaded(struct dso *dso)
548 {
549 RC_CHK_ACCESS(dso)->loaded = true;
550 }
551
dso__lock(struct dso * dso)552 static inline struct mutex *dso__lock(struct dso *dso)
553 {
554 return &RC_CHK_ACCESS(dso)->lock;
555 }
556
dso__long_name(const struct dso * dso)557 static inline const char *dso__long_name(const struct dso *dso)
558 {
559 return RC_CHK_ACCESS(dso)->long_name;
560 }
561
dso__long_name_allocated(const struct dso * dso)562 static inline bool dso__long_name_allocated(const struct dso *dso)
563 {
564 return RC_CHK_ACCESS(dso)->long_name_allocated;
565 }
566
dso__set_long_name_allocated(struct dso * dso,bool allocated)567 static inline void dso__set_long_name_allocated(struct dso *dso, bool allocated)
568 {
569 RC_CHK_ACCESS(dso)->long_name_allocated = allocated;
570 }
571
dso__long_name_len(const struct dso * dso)572 static inline u16 dso__long_name_len(const struct dso *dso)
573 {
574 return RC_CHK_ACCESS(dso)->long_name_len;
575 }
576
dso__name(const struct dso * dso)577 static inline const char *dso__name(const struct dso *dso)
578 {
579 return RC_CHK_ACCESS(dso)->name;
580 }
581
dso__needs_swap(const struct dso * dso)582 static inline enum dso_swap_type dso__needs_swap(const struct dso *dso)
583 {
584 return RC_CHK_ACCESS(dso)->needs_swap;
585 }
586
dso__set_needs_swap(struct dso * dso,enum dso_swap_type type)587 static inline void dso__set_needs_swap(struct dso *dso, enum dso_swap_type type)
588 {
589 RC_CHK_ACCESS(dso)->needs_swap = type;
590 }
591
dso__nsinfo(struct dso * dso)592 static inline struct nsinfo *dso__nsinfo(struct dso *dso)
593 {
594 return RC_CHK_ACCESS(dso)->nsinfo;
595 }
596
dso__nsinfo_const(const struct dso * dso)597 static inline const struct nsinfo *dso__nsinfo_const(const struct dso *dso)
598 {
599 return RC_CHK_ACCESS(dso)->nsinfo;
600 }
601
dso__nsinfo_ptr(struct dso * dso)602 static inline struct nsinfo **dso__nsinfo_ptr(struct dso *dso)
603 {
604 return &RC_CHK_ACCESS(dso)->nsinfo;
605 }
606
607 void dso__set_nsinfo(struct dso *dso, struct nsinfo *nsi);
608
dso__rel(const struct dso * dso)609 static inline u8 dso__rel(const struct dso *dso)
610 {
611 return RC_CHK_ACCESS(dso)->rel;
612 }
613
dso__set_rel(struct dso * dso,u8 rel)614 static inline void dso__set_rel(struct dso *dso, u8 rel)
615 {
616 RC_CHK_ACCESS(dso)->rel = rel;
617 }
618
dso__short_name(const struct dso * dso)619 static inline const char *dso__short_name(const struct dso *dso)
620 {
621 return RC_CHK_ACCESS(dso)->short_name;
622 }
623
dso__short_name_allocated(const struct dso * dso)624 static inline bool dso__short_name_allocated(const struct dso *dso)
625 {
626 return RC_CHK_ACCESS(dso)->short_name_allocated;
627 }
628
dso__set_short_name_allocated(struct dso * dso,bool allocated)629 static inline void dso__set_short_name_allocated(struct dso *dso, bool allocated)
630 {
631 RC_CHK_ACCESS(dso)->short_name_allocated = allocated;
632 }
633
dso__short_name_len(const struct dso * dso)634 static inline u16 dso__short_name_len(const struct dso *dso)
635 {
636 return RC_CHK_ACCESS(dso)->short_name_len;
637 }
638
dso__srclines(struct dso * dso)639 static inline struct rb_root_cached *dso__srclines(struct dso *dso)
640 {
641 return &RC_CHK_ACCESS(dso)->srclines;
642 }
643
dso__data_types(struct dso * dso)644 static inline struct rb_root *dso__data_types(struct dso *dso)
645 {
646 return &RC_CHK_ACCESS(dso)->data_types;
647 }
648
dso__global_vars(struct dso * dso)649 static inline struct rb_root *dso__global_vars(struct dso *dso)
650 {
651 return &RC_CHK_ACCESS(dso)->global_vars;
652 }
653
dso__symbols(struct dso * dso)654 static inline struct rb_root_cached *dso__symbols(struct dso *dso)
655 {
656 return &RC_CHK_ACCESS(dso)->symbols;
657 }
658
dso__symbol_names(struct dso * dso)659 static inline struct symbol **dso__symbol_names(struct dso *dso)
660 {
661 return RC_CHK_ACCESS(dso)->symbol_names;
662 }
663
dso__set_symbol_names(struct dso * dso,struct symbol ** names)664 static inline void dso__set_symbol_names(struct dso *dso, struct symbol **names)
665 {
666 RC_CHK_ACCESS(dso)->symbol_names = names;
667 }
668
dso__symbol_names_len(struct dso * dso)669 static inline size_t dso__symbol_names_len(struct dso *dso)
670 {
671 return RC_CHK_ACCESS(dso)->symbol_names_len;
672 }
673
dso__set_symbol_names_len(struct dso * dso,size_t len)674 static inline void dso__set_symbol_names_len(struct dso *dso, size_t len)
675 {
676 RC_CHK_ACCESS(dso)->symbol_names_len = len;
677 }
678
dso__symsrc_filename(const struct dso * dso)679 static inline const char *dso__symsrc_filename(const struct dso *dso)
680 {
681 return RC_CHK_ACCESS(dso)->symsrc_filename;
682 }
683
dso__set_symsrc_filename(struct dso * dso,char * val)684 static inline void dso__set_symsrc_filename(struct dso *dso, char *val)
685 {
686 RC_CHK_ACCESS(dso)->symsrc_filename = val;
687 }
688
dso__free_symsrc_filename(struct dso * dso)689 static inline void dso__free_symsrc_filename(struct dso *dso)
690 {
691 zfree(&RC_CHK_ACCESS(dso)->symsrc_filename);
692 }
693
dso__symtab_type(const struct dso * dso)694 static inline enum dso_binary_type dso__symtab_type(const struct dso *dso)
695 {
696 return RC_CHK_ACCESS(dso)->symtab_type;
697 }
698
dso__set_symtab_type(struct dso * dso,enum dso_binary_type bt)699 static inline void dso__set_symtab_type(struct dso *dso, enum dso_binary_type bt)
700 {
701 RC_CHK_ACCESS(dso)->symtab_type = bt;
702 }
703
dso__text_end(const struct dso * dso)704 static inline u64 dso__text_end(const struct dso *dso)
705 {
706 return RC_CHK_ACCESS(dso)->text_end;
707 }
708
dso__set_text_end(struct dso * dso,u64 val)709 static inline void dso__set_text_end(struct dso *dso, u64 val)
710 {
711 RC_CHK_ACCESS(dso)->text_end = val;
712 }
713
dso__text_offset(const struct dso * dso)714 static inline u64 dso__text_offset(const struct dso *dso)
715 {
716 return RC_CHK_ACCESS(dso)->text_offset;
717 }
718
dso__set_text_offset(struct dso * dso,u64 val)719 static inline void dso__set_text_offset(struct dso *dso, u64 val)
720 {
721 RC_CHK_ACCESS(dso)->text_offset = val;
722 }
723
724 struct dso *dso__new_id(const char *name, const struct dso_id *id);
725 struct dso *dso__new(const char *name);
726 void dso__delete(struct dso *dso);
727
728 int dso__cmp_id(struct dso *a, struct dso *b);
729 void dso__set_short_name(struct dso *dso, const char *name, bool name_allocated);
730 void dso__set_long_name(struct dso *dso, const char *name, bool name_allocated);
731 void __dso__improve_id(struct dso *dso, const struct dso_id *id);
732
733 int dso__name_len(const struct dso *dso);
734
735 struct dso *dso__get(struct dso *dso);
736 void dso__put(struct dso *dso) LOCKS_EXCLUDED(_dso__data_open_lock);
737
__dso__zput(struct dso ** dso)738 static inline void __dso__zput(struct dso **dso)
739 {
740 dso__put(*dso);
741 *dso = NULL;
742 }
743
744 #define dso__zput(dso) __dso__zput(&dso)
745
746 bool dso__loaded(const struct dso *dso);
747
dso__has_symbols(const struct dso * dso)748 static inline bool dso__has_symbols(const struct dso *dso)
749 {
750 return !RB_EMPTY_ROOT(&RC_CHK_ACCESS(dso)->symbols.rb_root);
751 }
752
753 char *dso__filename_with_chroot(const struct dso *dso, const char *filename);
754
755 bool dso__sorted_by_name(const struct dso *dso);
756 void dso__set_sorted_by_name(struct dso *dso);
757 void dso__sort_by_name(struct dso *dso);
758
759 int dso__swap_init(struct dso *dso, unsigned char eidata);
760
761 void dso__set_build_id(struct dso *dso, const struct build_id *bid);
762 bool dso__build_id_equal(const struct dso *dso, const struct build_id *bid);
763 void dso__read_running_kernel_build_id(struct dso *dso,
764 struct machine *machine);
765 int dso__kernel_module_get_build_id(struct dso *dso, const char *root_dir);
766
767 char dso__symtab_origin(const struct dso *dso);
768 int dso__read_binary_type_filename(const struct dso *dso, enum dso_binary_type type,
769 char *root_dir, char *filename, size_t size);
770 bool is_kernel_module(const char *pathname, int cpumode);
771 bool dso__needs_decompress(struct dso *dso);
772 int dso__decompress_kmodule_fd(struct dso *dso, const char *name);
773 int dso__decompress_kmodule_path(struct dso *dso, const char *name,
774 char *pathname, size_t len);
775 int filename__decompress(const char *name, char *pathname,
776 size_t len, int comp, int *err);
777
778 #define KMOD_DECOMP_NAME "/tmp/perf-kmod-XXXXXX"
779 #define KMOD_DECOMP_LEN sizeof(KMOD_DECOMP_NAME)
780
781 struct kmod_path {
782 char *name;
783 int comp;
784 bool kmod;
785 };
786
787 int __kmod_path__parse(struct kmod_path *m, const char *path,
788 bool alloc_name);
789
790 #define kmod_path__parse(__m, __p) __kmod_path__parse(__m, __p, false)
791 #define kmod_path__parse_name(__m, __p) __kmod_path__parse(__m, __p, true)
792
793 void dso__set_module_info(struct dso *dso, struct kmod_path *m,
794 struct machine *machine);
795
796 /*
797 * The dso__data_* external interface provides following functions:
798 * dso__data_get_fd
799 * dso__data_put_fd
800 * dso__data_close
801 * dso__data_size
802 * dso__data_read_offset
803 * dso__data_read_addr
804 * dso__data_write_cache_offs
805 * dso__data_write_cache_addr
806 *
807 * Please refer to the dso.c object code for each function and
808 * arguments documentation. Following text tries to explain the
809 * dso file descriptor caching.
810 *
811 * The dso__data* interface allows caching of opened file descriptors
812 * to speed up the dso data accesses. The idea is to leave the file
813 * descriptor opened ideally for the whole life of the dso object.
814 *
815 * The current usage of the dso__data_* interface is as follows:
816 *
817 * Get DSO's fd:
818 * int fd;
819 * if (dso__data_get_fd(dso, machine, &fd)) {
820 * USE 'fd' SOMEHOW
821 * dso__data_put_fd(dso);
822 * }
823 *
824 * Read DSO's data:
825 * n = dso__data_read_offset(dso_0, &machine, 0, buf, BUFSIZE);
826 * n = dso__data_read_addr(dso_0, &machine, 0, buf, BUFSIZE);
827 *
828 * Eventually close DSO's fd:
829 * dso__data_close(dso);
830 *
831 * It is not necessary to close the DSO object data file. Each time new
832 * DSO data file is opened, the limit (RLIMIT_NOFILE/2) is checked. Once
833 * it is crossed, the oldest opened DSO object is closed.
834 *
835 * The dso__delete function calls close_dso function to ensure the
836 * data file descriptor gets closed/unmapped before the dso object
837 * is freed.
838 *
839 * TODO
840 */
841 bool dso__data_get_fd(struct dso *dso, struct machine *machine, int *fd)
842 EXCLUSIVE_TRYLOCK_FUNCTION(true, _dso__data_open_lock);
843 void dso__data_put_fd(struct dso *dso) UNLOCK_FUNCTION(_dso__data_open_lock);
844 void dso__data_close(struct dso *dso) LOCKS_EXCLUDED(_dso__data_open_lock);
845
846 int dso__data_file_size(struct dso *dso, struct machine *machine);
847 off_t dso__data_size(struct dso *dso, struct machine *machine);
848 ssize_t dso__data_read_offset(struct dso *dso, struct machine *machine,
849 u64 offset, u8 *data, ssize_t size);
850 uint16_t dso__e_machine(struct dso *dso, struct machine *machine);
851 ssize_t dso__data_read_addr(struct dso *dso, struct map *map,
852 struct machine *machine, u64 addr,
853 u8 *data, ssize_t size);
854 bool dso__data_status_seen(struct dso *dso, enum dso_data_status_seen by);
855 ssize_t dso__data_write_cache_offs(struct dso *dso, struct machine *machine,
856 u64 offset, const u8 *data, ssize_t size);
857 ssize_t dso__data_write_cache_addr(struct dso *dso, struct map *map,
858 struct machine *machine, u64 addr,
859 const u8 *data, ssize_t size);
860
861 struct map *dso__new_map(const char *name);
862 struct dso *machine__findnew_kernel(struct machine *machine, const char *name,
863 const char *short_name, int dso_type);
864
865 void dso__reset_find_symbol_cache(struct dso *dso);
866
867 size_t dso__fprintf_symbols_by_name(struct dso *dso, FILE *fp);
868 size_t dso__fprintf(struct dso *dso, FILE *fp);
869
dso__binary_type(const struct dso * dso)870 static inline enum dso_binary_type dso__binary_type(const struct dso *dso)
871 {
872 return RC_CHK_ACCESS(dso)->binary_type;
873 }
874
dso__set_binary_type(struct dso * dso,enum dso_binary_type bt)875 static inline void dso__set_binary_type(struct dso *dso, enum dso_binary_type bt)
876 {
877 RC_CHK_ACCESS(dso)->binary_type = bt;
878 }
879
dso__is_vmlinux(const struct dso * dso)880 static inline bool dso__is_vmlinux(const struct dso *dso)
881 {
882 enum dso_binary_type bt = dso__binary_type(dso);
883
884 return bt == DSO_BINARY_TYPE__VMLINUX || bt == DSO_BINARY_TYPE__GUEST_VMLINUX;
885 }
886
dso__is_kcore(const struct dso * dso)887 static inline bool dso__is_kcore(const struct dso *dso)
888 {
889 enum dso_binary_type bt = dso__binary_type(dso);
890
891 return bt == DSO_BINARY_TYPE__KCORE || bt == DSO_BINARY_TYPE__GUEST_KCORE;
892 }
893
dso__is_kallsyms(const struct dso * dso)894 static inline bool dso__is_kallsyms(const struct dso *dso)
895 {
896 enum dso_binary_type bt = dso__binary_type(dso);
897
898 return bt == DSO_BINARY_TYPE__KALLSYMS || bt == DSO_BINARY_TYPE__GUEST_KALLSYMS;
899 }
900
901 bool dso__is_object_file(const struct dso *dso);
902
903 void dso__free_a2l(struct dso *dso);
904
905 enum dso_type dso__type(struct dso *dso, struct machine *machine);
906
907 int dso__strerror_load(struct dso *dso, char *buf, size_t buflen);
908
909 void reset_fd_limit(void);
910
911 u64 dso__find_global_type(struct dso *dso, u64 addr);
912 u64 dso__findnew_global_type(struct dso *dso, u64 addr, u64 offset);
913
914 /* Check if dso name is of format "/tmp/perf-%d.map" */
915 bool perf_pid_map_tid(const char *dso_name, int *tid);
916 bool is_perf_pid_map_name(const char *dso_name);
917
918 /*
919 * In the future, we may get debuginfo using build-ID (w/o path).
920 * Add this helper is for the smooth conversion.
921 */
dso__debuginfo(struct dso * dso)922 static inline struct debuginfo *dso__debuginfo(struct dso *dso)
923 {
924 return debuginfo__new(dso__long_name(dso));
925 }
926
927 const u8 *dso__read_symbol(struct dso *dso, const char *symfs_filename,
928 const struct map *map, const struct symbol *sym,
929 u8 **out_buf, u64 *out_buf_len, bool *is_64bit);
930
931 #endif /* __PERF_DSO */
932