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 * struct dso_id
190 *
191 * Data about backing storage DSO, comes from PERF_RECORD_MMAP2 meta events,
192 * reading from /proc/pid/maps or synthesis of build_ids from DSOs. Possibly
193 * incomplete at any particular use.
194 */
195 struct dso_id {
196 /* Data related to the mmap2 event or read from /proc/pid/maps. */
197 struct {
198 u32 maj;
199 u32 min;
200 u64 ino;
201 u64 ino_generation;
202 };
203 /** @mmap2_valid: Are the maj, min and ino fields valid? */
204 bool mmap2_valid;
205 /**
206 * @mmap2_ino_generation_valid: Is the ino_generation valid? Generally
207 * false for /proc/pid/maps mmap event.
208 */
209 bool mmap2_ino_generation_valid;
210 /**
211 * @build_id: A possibly populated build_id. build_id__is_defined checks
212 * whether it is populated.
213 */
214 struct build_id build_id;
215 };
216
217 struct dso_cache {
218 struct rb_node rb_node;
219 u64 offset;
220 u64 size;
221 char data[];
222 };
223
224 struct dso_data {
225 struct rb_root cache;
226 struct list_head open_entry;
227 #ifdef REFCNT_CHECKING
228 struct dso *dso;
229 #endif
230 int fd;
231 int status;
232 u32 status_seen;
233 u64 file_size;
234 #ifdef HAVE_LIBUNWIND_SUPPORT
235 u64 elf_base_addr;
236 u64 debug_frame_offset;
237 u64 eh_frame_hdr_addr;
238 u64 eh_frame_hdr_offset;
239 #endif
240 };
241
242 struct dso_bpf_prog {
243 u32 id;
244 u32 sub_id;
245 struct perf_env *env;
246 };
247
248 struct auxtrace_cache;
249
DECLARE_RC_STRUCT(dso)250 DECLARE_RC_STRUCT(dso) {
251 struct mutex lock;
252 struct dsos *dsos;
253 struct rb_root_cached symbols;
254 struct symbol **symbol_names;
255 size_t symbol_names_len;
256 struct rb_root_cached inlined_nodes;
257 struct rb_root_cached srclines;
258 struct rb_root data_types;
259 struct rb_root global_vars;
260
261 struct {
262 u64 addr;
263 struct symbol *symbol;
264 } last_find_result;
265 u64 text_offset;
266 u64 text_end;
267 const char *short_name;
268 const char *long_name;
269 void *a2l;
270 char *symsrc_filename;
271 #if defined(__powerpc__)
272 void *dwfl; /* DWARF debug info */
273 #endif
274 struct nsinfo *nsinfo;
275 struct auxtrace_cache *auxtrace_cache;
276 union { /* Tool specific area */
277 void *priv;
278 u64 db_id;
279 };
280 /* bpf prog information */
281 struct dso_bpf_prog bpf_prog;
282 /* dso data file */
283 struct dso_data data;
284 struct dso_id id;
285 unsigned int a2l_fails;
286 int comp;
287 refcount_t refcnt;
288 enum dso_load_errno load_errno;
289 u16 long_name_len;
290 u16 short_name_len;
291 enum dso_binary_type symtab_type:8;
292 enum dso_binary_type binary_type:8;
293 enum dso_space_type kernel:2;
294 enum dso_swap_type needs_swap:2;
295 bool is_kmod:1;
296 u8 adjust_symbols:1;
297 u8 header_build_id:1;
298 u8 has_srcline:1;
299 u8 hit:1;
300 u8 annotate_warned:1;
301 u8 auxtrace_warned:1;
302 u8 short_name_allocated:1;
303 u8 long_name_allocated:1;
304 u8 is_64_bit:1;
305 bool sorted_by_name;
306 bool loaded;
307 u8 rel;
308 char name[];
309 };
310
311 extern struct mutex _dso__data_open_lock;
312 extern const struct dso_id dso_id_empty;
313
314 int dso_id__cmp(const struct dso_id *a, const struct dso_id *b);
315
316 /* dso__for_each_symbol - iterate over the symbols of given type
317 *
318 * @dso: the 'struct dso *' in which symbols are iterated
319 * @pos: the 'struct symbol *' to use as a loop cursor
320 * @n: the 'struct rb_node *' to use as a temporary storage
321 */
322 #define dso__for_each_symbol(dso, pos, n) \
323 symbols__for_each_entry(dso__symbols(dso), pos, n)
324
dso__a2l(const struct dso * dso)325 static inline void *dso__a2l(const struct dso *dso)
326 {
327 return RC_CHK_ACCESS(dso)->a2l;
328 }
329
dso__set_a2l(struct dso * dso,void * val)330 static inline void dso__set_a2l(struct dso *dso, void *val)
331 {
332 RC_CHK_ACCESS(dso)->a2l = val;
333 }
334
dso__a2l_fails(const struct dso * dso)335 static inline unsigned int dso__a2l_fails(const struct dso *dso)
336 {
337 return RC_CHK_ACCESS(dso)->a2l_fails;
338 }
339
dso__set_a2l_fails(struct dso * dso,unsigned int val)340 static inline void dso__set_a2l_fails(struct dso *dso, unsigned int val)
341 {
342 RC_CHK_ACCESS(dso)->a2l_fails = val;
343 }
344
dso__adjust_symbols(const struct dso * dso)345 static inline bool dso__adjust_symbols(const struct dso *dso)
346 {
347 return RC_CHK_ACCESS(dso)->adjust_symbols;
348 }
349
dso__set_adjust_symbols(struct dso * dso,bool val)350 static inline void dso__set_adjust_symbols(struct dso *dso, bool val)
351 {
352 RC_CHK_ACCESS(dso)->adjust_symbols = val;
353 }
354
dso__annotate_warned(const struct dso * dso)355 static inline bool dso__annotate_warned(const struct dso *dso)
356 {
357 return RC_CHK_ACCESS(dso)->annotate_warned;
358 }
359
dso__set_annotate_warned(struct dso * dso)360 static inline void dso__set_annotate_warned(struct dso *dso)
361 {
362 RC_CHK_ACCESS(dso)->annotate_warned = 1;
363 }
364
dso__auxtrace_warned(const struct dso * dso)365 static inline bool dso__auxtrace_warned(const struct dso *dso)
366 {
367 return RC_CHK_ACCESS(dso)->auxtrace_warned;
368 }
369
dso__set_auxtrace_warned(struct dso * dso)370 static inline void dso__set_auxtrace_warned(struct dso *dso)
371 {
372 RC_CHK_ACCESS(dso)->auxtrace_warned = 1;
373 }
374
dso__auxtrace_cache(struct dso * dso)375 static inline struct auxtrace_cache *dso__auxtrace_cache(struct dso *dso)
376 {
377 return RC_CHK_ACCESS(dso)->auxtrace_cache;
378 }
379
dso__set_auxtrace_cache(struct dso * dso,struct auxtrace_cache * cache)380 static inline void dso__set_auxtrace_cache(struct dso *dso, struct auxtrace_cache *cache)
381 {
382 RC_CHK_ACCESS(dso)->auxtrace_cache = cache;
383 }
384
dso__bpf_prog(struct dso * dso)385 static inline struct dso_bpf_prog *dso__bpf_prog(struct dso *dso)
386 {
387 return &RC_CHK_ACCESS(dso)->bpf_prog;
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__bid(const struct dso * dso)465 static inline const struct build_id *dso__bid(const struct dso *dso)
466 {
467 return &dso__id_const(dso)->build_id;
468 }
469
dso__has_build_id(const struct dso * dso)470 static inline bool dso__has_build_id(const struct dso *dso)
471 {
472 return build_id__is_defined(dso__bid(dso));
473 }
474
dso__inlined_nodes(struct dso * dso)475 static inline struct rb_root_cached *dso__inlined_nodes(struct dso *dso)
476 {
477 return &RC_CHK_ACCESS(dso)->inlined_nodes;
478 }
479
dso__is_64_bit(const struct dso * dso)480 static inline bool dso__is_64_bit(const struct dso *dso)
481 {
482 return RC_CHK_ACCESS(dso)->is_64_bit;
483 }
484
dso__set_is_64_bit(struct dso * dso,bool is)485 static inline void dso__set_is_64_bit(struct dso *dso, bool is)
486 {
487 RC_CHK_ACCESS(dso)->is_64_bit = is;
488 }
489
dso__is_kmod(const struct dso * dso)490 static inline bool dso__is_kmod(const struct dso *dso)
491 {
492 return RC_CHK_ACCESS(dso)->is_kmod;
493 }
494
dso__set_is_kmod(struct dso * dso)495 static inline void dso__set_is_kmod(struct dso *dso)
496 {
497 RC_CHK_ACCESS(dso)->is_kmod = 1;
498 }
499
dso__kernel(const struct dso * dso)500 static inline enum dso_space_type dso__kernel(const struct dso *dso)
501 {
502 return RC_CHK_ACCESS(dso)->kernel;
503 }
504
dso__set_kernel(struct dso * dso,enum dso_space_type kernel)505 static inline void dso__set_kernel(struct dso *dso, enum dso_space_type kernel)
506 {
507 RC_CHK_ACCESS(dso)->kernel = kernel;
508 }
509
dso__last_find_result_addr(const struct dso * dso)510 static inline u64 dso__last_find_result_addr(const struct dso *dso)
511 {
512 return RC_CHK_ACCESS(dso)->last_find_result.addr;
513 }
514
dso__set_last_find_result_addr(struct dso * dso,u64 addr)515 static inline void dso__set_last_find_result_addr(struct dso *dso, u64 addr)
516 {
517 RC_CHK_ACCESS(dso)->last_find_result.addr = addr;
518 }
519
dso__last_find_result_symbol(const struct dso * dso)520 static inline struct symbol *dso__last_find_result_symbol(const struct dso *dso)
521 {
522 return RC_CHK_ACCESS(dso)->last_find_result.symbol;
523 }
524
dso__set_last_find_result_symbol(struct dso * dso,struct symbol * symbol)525 static inline void dso__set_last_find_result_symbol(struct dso *dso, struct symbol *symbol)
526 {
527 RC_CHK_ACCESS(dso)->last_find_result.symbol = symbol;
528 }
529
dso__load_errno(struct dso * dso)530 static inline enum dso_load_errno *dso__load_errno(struct dso *dso)
531 {
532 return &RC_CHK_ACCESS(dso)->load_errno;
533 }
534
dso__set_loaded(struct dso * dso)535 static inline void dso__set_loaded(struct dso *dso)
536 {
537 RC_CHK_ACCESS(dso)->loaded = true;
538 }
539
dso__lock(struct dso * dso)540 static inline struct mutex *dso__lock(struct dso *dso)
541 {
542 return &RC_CHK_ACCESS(dso)->lock;
543 }
544
dso__long_name(const struct dso * dso)545 static inline const char *dso__long_name(const struct dso *dso)
546 {
547 return RC_CHK_ACCESS(dso)->long_name;
548 }
549
dso__long_name_allocated(const struct dso * dso)550 static inline bool dso__long_name_allocated(const struct dso *dso)
551 {
552 return RC_CHK_ACCESS(dso)->long_name_allocated;
553 }
554
dso__set_long_name_allocated(struct dso * dso,bool allocated)555 static inline void dso__set_long_name_allocated(struct dso *dso, bool allocated)
556 {
557 RC_CHK_ACCESS(dso)->long_name_allocated = allocated;
558 }
559
dso__long_name_len(const struct dso * dso)560 static inline u16 dso__long_name_len(const struct dso *dso)
561 {
562 return RC_CHK_ACCESS(dso)->long_name_len;
563 }
564
dso__name(const struct dso * dso)565 static inline const char *dso__name(const struct dso *dso)
566 {
567 return RC_CHK_ACCESS(dso)->name;
568 }
569
dso__needs_swap(const struct dso * dso)570 static inline enum dso_swap_type dso__needs_swap(const struct dso *dso)
571 {
572 return RC_CHK_ACCESS(dso)->needs_swap;
573 }
574
dso__set_needs_swap(struct dso * dso,enum dso_swap_type type)575 static inline void dso__set_needs_swap(struct dso *dso, enum dso_swap_type type)
576 {
577 RC_CHK_ACCESS(dso)->needs_swap = type;
578 }
579
dso__nsinfo(struct dso * dso)580 static inline struct nsinfo *dso__nsinfo(struct dso *dso)
581 {
582 return RC_CHK_ACCESS(dso)->nsinfo;
583 }
584
dso__nsinfo_const(const struct dso * dso)585 static inline const struct nsinfo *dso__nsinfo_const(const struct dso *dso)
586 {
587 return RC_CHK_ACCESS(dso)->nsinfo;
588 }
589
dso__nsinfo_ptr(struct dso * dso)590 static inline struct nsinfo **dso__nsinfo_ptr(struct dso *dso)
591 {
592 return &RC_CHK_ACCESS(dso)->nsinfo;
593 }
594
595 void dso__set_nsinfo(struct dso *dso, struct nsinfo *nsi);
596
dso__rel(const struct dso * dso)597 static inline u8 dso__rel(const struct dso *dso)
598 {
599 return RC_CHK_ACCESS(dso)->rel;
600 }
601
dso__set_rel(struct dso * dso,u8 rel)602 static inline void dso__set_rel(struct dso *dso, u8 rel)
603 {
604 RC_CHK_ACCESS(dso)->rel = rel;
605 }
606
dso__short_name(const struct dso * dso)607 static inline const char *dso__short_name(const struct dso *dso)
608 {
609 return RC_CHK_ACCESS(dso)->short_name;
610 }
611
dso__short_name_allocated(const struct dso * dso)612 static inline bool dso__short_name_allocated(const struct dso *dso)
613 {
614 return RC_CHK_ACCESS(dso)->short_name_allocated;
615 }
616
dso__set_short_name_allocated(struct dso * dso,bool allocated)617 static inline void dso__set_short_name_allocated(struct dso *dso, bool allocated)
618 {
619 RC_CHK_ACCESS(dso)->short_name_allocated = allocated;
620 }
621
dso__short_name_len(const struct dso * dso)622 static inline u16 dso__short_name_len(const struct dso *dso)
623 {
624 return RC_CHK_ACCESS(dso)->short_name_len;
625 }
626
dso__srclines(struct dso * dso)627 static inline struct rb_root_cached *dso__srclines(struct dso *dso)
628 {
629 return &RC_CHK_ACCESS(dso)->srclines;
630 }
631
dso__data_types(struct dso * dso)632 static inline struct rb_root *dso__data_types(struct dso *dso)
633 {
634 return &RC_CHK_ACCESS(dso)->data_types;
635 }
636
dso__global_vars(struct dso * dso)637 static inline struct rb_root *dso__global_vars(struct dso *dso)
638 {
639 return &RC_CHK_ACCESS(dso)->global_vars;
640 }
641
dso__symbols(struct dso * dso)642 static inline struct rb_root_cached *dso__symbols(struct dso *dso)
643 {
644 return &RC_CHK_ACCESS(dso)->symbols;
645 }
646
dso__symbol_names(struct dso * dso)647 static inline struct symbol **dso__symbol_names(struct dso *dso)
648 {
649 return RC_CHK_ACCESS(dso)->symbol_names;
650 }
651
dso__set_symbol_names(struct dso * dso,struct symbol ** names)652 static inline void dso__set_symbol_names(struct dso *dso, struct symbol **names)
653 {
654 RC_CHK_ACCESS(dso)->symbol_names = names;
655 }
656
dso__symbol_names_len(struct dso * dso)657 static inline size_t dso__symbol_names_len(struct dso *dso)
658 {
659 return RC_CHK_ACCESS(dso)->symbol_names_len;
660 }
661
dso__set_symbol_names_len(struct dso * dso,size_t len)662 static inline void dso__set_symbol_names_len(struct dso *dso, size_t len)
663 {
664 RC_CHK_ACCESS(dso)->symbol_names_len = len;
665 }
666
dso__symsrc_filename(const struct dso * dso)667 static inline const char *dso__symsrc_filename(const struct dso *dso)
668 {
669 return RC_CHK_ACCESS(dso)->symsrc_filename;
670 }
671
dso__set_symsrc_filename(struct dso * dso,char * val)672 static inline void dso__set_symsrc_filename(struct dso *dso, char *val)
673 {
674 RC_CHK_ACCESS(dso)->symsrc_filename = val;
675 }
676
dso__free_symsrc_filename(struct dso * dso)677 static inline void dso__free_symsrc_filename(struct dso *dso)
678 {
679 zfree(&RC_CHK_ACCESS(dso)->symsrc_filename);
680 }
681
dso__symtab_type(const struct dso * dso)682 static inline enum dso_binary_type dso__symtab_type(const struct dso *dso)
683 {
684 return RC_CHK_ACCESS(dso)->symtab_type;
685 }
686
dso__set_symtab_type(struct dso * dso,enum dso_binary_type bt)687 static inline void dso__set_symtab_type(struct dso *dso, enum dso_binary_type bt)
688 {
689 RC_CHK_ACCESS(dso)->symtab_type = bt;
690 }
691
dso__text_end(const struct dso * dso)692 static inline u64 dso__text_end(const struct dso *dso)
693 {
694 return RC_CHK_ACCESS(dso)->text_end;
695 }
696
dso__set_text_end(struct dso * dso,u64 val)697 static inline void dso__set_text_end(struct dso *dso, u64 val)
698 {
699 RC_CHK_ACCESS(dso)->text_end = val;
700 }
701
dso__text_offset(const struct dso * dso)702 static inline u64 dso__text_offset(const struct dso *dso)
703 {
704 return RC_CHK_ACCESS(dso)->text_offset;
705 }
706
dso__set_text_offset(struct dso * dso,u64 val)707 static inline void dso__set_text_offset(struct dso *dso, u64 val)
708 {
709 RC_CHK_ACCESS(dso)->text_offset = val;
710 }
711
712 struct dso *dso__new_id(const char *name, const struct dso_id *id);
713 struct dso *dso__new(const char *name);
714 void dso__delete(struct dso *dso);
715
716 int dso__cmp_id(struct dso *a, struct dso *b);
717 void dso__set_short_name(struct dso *dso, const char *name, bool name_allocated);
718 void dso__set_long_name(struct dso *dso, const char *name, bool name_allocated);
719 void __dso__improve_id(struct dso *dso, const struct dso_id *id);
720
721 int dso__name_len(const struct dso *dso);
722
723 struct dso *dso__get(struct dso *dso);
724 void dso__put(struct dso *dso) LOCKS_EXCLUDED(_dso__data_open_lock);
725
__dso__zput(struct dso ** dso)726 static inline void __dso__zput(struct dso **dso)
727 {
728 dso__put(*dso);
729 *dso = NULL;
730 }
731
732 #define dso__zput(dso) __dso__zput(&dso)
733
734 bool dso__loaded(const struct dso *dso);
735
dso__has_symbols(const struct dso * dso)736 static inline bool dso__has_symbols(const struct dso *dso)
737 {
738 return !RB_EMPTY_ROOT(&RC_CHK_ACCESS(dso)->symbols.rb_root);
739 }
740
741 char *dso__filename_with_chroot(const struct dso *dso, const char *filename);
742
743 bool dso__sorted_by_name(const struct dso *dso);
744 void dso__set_sorted_by_name(struct dso *dso);
745 void dso__sort_by_name(struct dso *dso);
746
747 int dso__swap_init(struct dso *dso, unsigned char eidata);
748
749 void dso__set_build_id(struct dso *dso, const struct build_id *bid);
750 bool dso__build_id_equal(const struct dso *dso, const struct build_id *bid);
751 void dso__read_running_kernel_build_id(struct dso *dso,
752 struct machine *machine);
753 int dso__kernel_module_get_build_id(struct dso *dso, const char *root_dir);
754
755 char dso__symtab_origin(const struct dso *dso);
756 int dso__read_binary_type_filename(const struct dso *dso, enum dso_binary_type type,
757 char *root_dir, char *filename, size_t size);
758 bool is_kernel_module(const char *pathname, int cpumode);
759 bool dso__needs_decompress(struct dso *dso);
760 int dso__decompress_kmodule_fd(struct dso *dso, const char *name);
761 int dso__decompress_kmodule_path(struct dso *dso, const char *name,
762 char *pathname, size_t len);
763 int filename__decompress(const char *name, char *pathname,
764 size_t len, int comp, int *err);
765
766 #define KMOD_DECOMP_NAME "/tmp/perf-kmod-XXXXXX"
767 #define KMOD_DECOMP_LEN sizeof(KMOD_DECOMP_NAME)
768
769 struct kmod_path {
770 char *name;
771 int comp;
772 bool kmod;
773 };
774
775 int __kmod_path__parse(struct kmod_path *m, const char *path,
776 bool alloc_name);
777
778 #define kmod_path__parse(__m, __p) __kmod_path__parse(__m, __p, false)
779 #define kmod_path__parse_name(__m, __p) __kmod_path__parse(__m, __p, true)
780
781 void dso__set_module_info(struct dso *dso, struct kmod_path *m,
782 struct machine *machine);
783
784 /*
785 * The dso__data_* external interface provides following functions:
786 * dso__data_get_fd
787 * dso__data_put_fd
788 * dso__data_close
789 * dso__data_size
790 * dso__data_read_offset
791 * dso__data_read_addr
792 * dso__data_write_cache_offs
793 * dso__data_write_cache_addr
794 *
795 * Please refer to the dso.c object code for each function and
796 * arguments documentation. Following text tries to explain the
797 * dso file descriptor caching.
798 *
799 * The dso__data* interface allows caching of opened file descriptors
800 * to speed up the dso data accesses. The idea is to leave the file
801 * descriptor opened ideally for the whole life of the dso object.
802 *
803 * The current usage of the dso__data_* interface is as follows:
804 *
805 * Get DSO's fd:
806 * int fd;
807 * if (dso__data_get_fd(dso, machine, &fd)) {
808 * USE 'fd' SOMEHOW
809 * dso__data_put_fd(dso);
810 * }
811 *
812 * Read DSO's data:
813 * n = dso__data_read_offset(dso_0, &machine, 0, buf, BUFSIZE);
814 * n = dso__data_read_addr(dso_0, &machine, 0, buf, BUFSIZE);
815 *
816 * Eventually close DSO's fd:
817 * dso__data_close(dso);
818 *
819 * It is not necessary to close the DSO object data file. Each time new
820 * DSO data file is opened, the limit (RLIMIT_NOFILE/2) is checked. Once
821 * it is crossed, the oldest opened DSO object is closed.
822 *
823 * The dso__delete function calls close_dso function to ensure the
824 * data file descriptor gets closed/unmapped before the dso object
825 * is freed.
826 *
827 * TODO
828 */
829 bool dso__data_get_fd(struct dso *dso, struct machine *machine, int *fd)
830 EXCLUSIVE_TRYLOCK_FUNCTION(true, _dso__data_open_lock);
831 void dso__data_put_fd(struct dso *dso) UNLOCK_FUNCTION(_dso__data_open_lock);
832 void dso__data_close(struct dso *dso) LOCKS_EXCLUDED(_dso__data_open_lock);
833
834 int dso__data_file_size(struct dso *dso, struct machine *machine);
835 off_t dso__data_size(struct dso *dso, struct machine *machine);
836 ssize_t dso__data_read_offset(struct dso *dso, struct machine *machine,
837 u64 offset, u8 *data, ssize_t size);
838 uint16_t dso__e_machine(struct dso *dso, struct machine *machine);
839 ssize_t dso__data_read_addr(struct dso *dso, struct map *map,
840 struct machine *machine, u64 addr,
841 u8 *data, ssize_t size);
842 bool dso__data_status_seen(struct dso *dso, enum dso_data_status_seen by);
843 ssize_t dso__data_write_cache_offs(struct dso *dso, struct machine *machine,
844 u64 offset, const u8 *data, ssize_t size);
845 ssize_t dso__data_write_cache_addr(struct dso *dso, struct map *map,
846 struct machine *machine, u64 addr,
847 const u8 *data, ssize_t size);
848
849 struct map *dso__new_map(const char *name);
850 struct dso *machine__findnew_kernel(struct machine *machine, const char *name,
851 const char *short_name, int dso_type);
852
853 void dso__reset_find_symbol_cache(struct dso *dso);
854
855 size_t dso__fprintf_symbols_by_name(struct dso *dso, FILE *fp);
856 size_t dso__fprintf(struct dso *dso, FILE *fp);
857
dso__binary_type(const struct dso * dso)858 static inline enum dso_binary_type dso__binary_type(const struct dso *dso)
859 {
860 return RC_CHK_ACCESS(dso)->binary_type;
861 }
862
dso__set_binary_type(struct dso * dso,enum dso_binary_type bt)863 static inline void dso__set_binary_type(struct dso *dso, enum dso_binary_type bt)
864 {
865 RC_CHK_ACCESS(dso)->binary_type = bt;
866 }
867
dso__is_vmlinux(const struct dso * dso)868 static inline bool dso__is_vmlinux(const struct dso *dso)
869 {
870 enum dso_binary_type bt = dso__binary_type(dso);
871
872 return bt == DSO_BINARY_TYPE__VMLINUX || bt == DSO_BINARY_TYPE__GUEST_VMLINUX;
873 }
874
dso__is_kcore(const struct dso * dso)875 static inline bool dso__is_kcore(const struct dso *dso)
876 {
877 enum dso_binary_type bt = dso__binary_type(dso);
878
879 return bt == DSO_BINARY_TYPE__KCORE || bt == DSO_BINARY_TYPE__GUEST_KCORE;
880 }
881
dso__is_kallsyms(const struct dso * dso)882 static inline bool dso__is_kallsyms(const struct dso *dso)
883 {
884 enum dso_binary_type bt = dso__binary_type(dso);
885
886 return bt == DSO_BINARY_TYPE__KALLSYMS || bt == DSO_BINARY_TYPE__GUEST_KALLSYMS;
887 }
888
889 bool dso__is_object_file(const struct dso *dso);
890
891 void dso__free_a2l(struct dso *dso);
892
893 enum dso_type dso__type(struct dso *dso, struct machine *machine);
894
895 int dso__strerror_load(struct dso *dso, char *buf, size_t buflen);
896
897 void reset_fd_limit(void);
898
899 u64 dso__find_global_type(struct dso *dso, u64 addr);
900 u64 dso__findnew_global_type(struct dso *dso, u64 addr, u64 offset);
901
902 /* Check if dso name is of format "/tmp/perf-%d.map" */
903 bool perf_pid_map_tid(const char *dso_name, int *tid);
904 bool is_perf_pid_map_name(const char *dso_name);
905
906 #endif /* __PERF_DSO */
907