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