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