xref: /linux/tools/perf/util/dso.h (revision 266aa3b4812e97942a8ce5c7aafa7da059f7b5b8)
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 
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 
243 static inline void *dso__a2l(const struct dso *dso)
244 {
245 	return RC_CHK_ACCESS(dso)->a2l;
246 }
247 
248 static inline void dso__set_a2l(struct dso *dso, void *val)
249 {
250 	RC_CHK_ACCESS(dso)->a2l = val;
251 }
252 
253 static inline unsigned int dso__a2l_fails(const struct dso *dso)
254 {
255 	return RC_CHK_ACCESS(dso)->a2l_fails;
256 }
257 
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 
263 static inline bool dso__adjust_symbols(const struct dso *dso)
264 {
265 	return RC_CHK_ACCESS(dso)->adjust_symbols;
266 }
267 
268 static inline void dso__set_adjust_symbols(struct dso *dso, bool val)
269 {
270 	RC_CHK_ACCESS(dso)->adjust_symbols = val;
271 }
272 
273 static inline bool dso__annotate_warned(const struct dso *dso)
274 {
275 	return RC_CHK_ACCESS(dso)->annotate_warned;
276 }
277 
278 static inline void dso__set_annotate_warned(struct dso *dso)
279 {
280 	RC_CHK_ACCESS(dso)->annotate_warned = 1;
281 }
282 
283 static inline struct auxtrace_cache *dso__auxtrace_cache(struct dso *dso)
284 {
285 	return RC_CHK_ACCESS(dso)->auxtrace_cache;
286 }
287 
288 static inline void dso__set_auxtrace_cache(struct dso *dso, struct auxtrace_cache *cache)
289 {
290 	RC_CHK_ACCESS(dso)->auxtrace_cache = cache;
291 }
292 
293 static inline struct build_id *dso__bid(struct dso *dso)
294 {
295 	return &RC_CHK_ACCESS(dso)->bid;
296 }
297 
298 static inline const struct build_id *dso__bid_const(const struct dso *dso)
299 {
300 	return &RC_CHK_ACCESS(dso)->bid;
301 }
302 
303 static inline struct dso_bpf_prog *dso__bpf_prog(struct dso *dso)
304 {
305 	return &RC_CHK_ACCESS(dso)->bpf_prog;
306 }
307 
308 static inline bool dso__has_build_id(const struct dso *dso)
309 {
310 	return RC_CHK_ACCESS(dso)->has_build_id;
311 }
312 
313 static inline void dso__set_has_build_id(struct dso *dso)
314 {
315 	RC_CHK_ACCESS(dso)->has_build_id = true;
316 }
317 
318 static inline bool dso__has_srcline(const struct dso *dso)
319 {
320 	return RC_CHK_ACCESS(dso)->has_srcline;
321 }
322 
323 static inline void dso__set_has_srcline(struct dso *dso, bool val)
324 {
325 	RC_CHK_ACCESS(dso)->has_srcline = val;
326 }
327 
328 static inline int dso__comp(const struct dso *dso)
329 {
330 	return RC_CHK_ACCESS(dso)->comp;
331 }
332 
333 static inline void dso__set_comp(struct dso *dso, int comp)
334 {
335 	RC_CHK_ACCESS(dso)->comp = comp;
336 }
337 
338 static inline struct dso_data *dso__data(struct dso *dso)
339 {
340 	return &RC_CHK_ACCESS(dso)->data;
341 }
342 
343 static inline u64 dso__db_id(const struct dso *dso)
344 {
345 	return RC_CHK_ACCESS(dso)->db_id;
346 }
347 
348 static inline void dso__set_db_id(struct dso *dso, u64 db_id)
349 {
350 	RC_CHK_ACCESS(dso)->db_id = db_id;
351 }
352 
353 static inline struct dsos *dso__dsos(struct dso *dso)
354 {
355 	return RC_CHK_ACCESS(dso)->dsos;
356 }
357 
358 static inline void dso__set_dsos(struct dso *dso, struct dsos *dsos)
359 {
360 	RC_CHK_ACCESS(dso)->dsos = dsos;
361 }
362 
363 static inline bool dso__header_build_id(struct dso *dso)
364 {
365 	return RC_CHK_ACCESS(dso)->header_build_id;
366 }
367 
368 static inline void dso__set_header_build_id(struct dso *dso, bool val)
369 {
370 	RC_CHK_ACCESS(dso)->header_build_id = val;
371 }
372 
373 static inline bool dso__hit(const struct dso *dso)
374 {
375 	return RC_CHK_ACCESS(dso)->hit;
376 }
377 
378 static inline void dso__set_hit(struct dso *dso)
379 {
380 	RC_CHK_ACCESS(dso)->hit = 1;
381 }
382 
383 static inline struct dso_id *dso__id(struct dso *dso)
384 {
385 	return &RC_CHK_ACCESS(dso)->id;
386 }
387 
388 static inline const struct dso_id *dso__id_const(const struct dso *dso)
389 {
390 	return &RC_CHK_ACCESS(dso)->id;
391 }
392 
393 static inline struct rb_root_cached *dso__inlined_nodes(struct dso *dso)
394 {
395 	return &RC_CHK_ACCESS(dso)->inlined_nodes;
396 }
397 
398 static inline bool dso__is_64_bit(const struct dso *dso)
399 {
400 	return RC_CHK_ACCESS(dso)->is_64_bit;
401 }
402 
403 static inline void dso__set_is_64_bit(struct dso *dso, bool is)
404 {
405 	RC_CHK_ACCESS(dso)->is_64_bit = is;
406 }
407 
408 static inline bool dso__is_kmod(const struct dso *dso)
409 {
410 	return RC_CHK_ACCESS(dso)->is_kmod;
411 }
412 
413 static inline void dso__set_is_kmod(struct dso *dso)
414 {
415 	RC_CHK_ACCESS(dso)->is_kmod = 1;
416 }
417 
418 static inline enum dso_space_type dso__kernel(const struct dso *dso)
419 {
420 	return RC_CHK_ACCESS(dso)->kernel;
421 }
422 
423 static inline void dso__set_kernel(struct dso *dso, enum dso_space_type kernel)
424 {
425 	RC_CHK_ACCESS(dso)->kernel = kernel;
426 }
427 
428 static inline u64 dso__last_find_result_addr(const struct dso *dso)
429 {
430 	return RC_CHK_ACCESS(dso)->last_find_result.addr;
431 }
432 
433 static inline void dso__set_last_find_result_addr(struct dso *dso, u64 addr)
434 {
435 	RC_CHK_ACCESS(dso)->last_find_result.addr = addr;
436 }
437 
438 static inline struct symbol *dso__last_find_result_symbol(const struct dso *dso)
439 {
440 	return RC_CHK_ACCESS(dso)->last_find_result.symbol;
441 }
442 
443 static inline void dso__set_last_find_result_symbol(struct dso *dso, struct symbol *symbol)
444 {
445 	RC_CHK_ACCESS(dso)->last_find_result.symbol = symbol;
446 }
447 
448 static inline enum dso_load_errno *dso__load_errno(struct dso *dso)
449 {
450 	return &RC_CHK_ACCESS(dso)->load_errno;
451 }
452 
453 static inline void dso__set_loaded(struct dso *dso)
454 {
455 	RC_CHK_ACCESS(dso)->loaded = true;
456 }
457 
458 static inline struct mutex *dso__lock(struct dso *dso)
459 {
460 	return &RC_CHK_ACCESS(dso)->lock;
461 }
462 
463 static inline const char *dso__long_name(const struct dso *dso)
464 {
465 	return RC_CHK_ACCESS(dso)->long_name;
466 }
467 
468 static inline bool dso__long_name_allocated(const struct dso *dso)
469 {
470 	return RC_CHK_ACCESS(dso)->long_name_allocated;
471 }
472 
473 static inline void dso__set_long_name_allocated(struct dso *dso, bool allocated)
474 {
475 	RC_CHK_ACCESS(dso)->long_name_allocated = allocated;
476 }
477 
478 static inline u16 dso__long_name_len(const struct dso *dso)
479 {
480 	return RC_CHK_ACCESS(dso)->long_name_len;
481 }
482 
483 static inline const char *dso__name(const struct dso *dso)
484 {
485 	return RC_CHK_ACCESS(dso)->name;
486 }
487 
488 static inline enum dso_swap_type dso__needs_swap(const struct dso *dso)
489 {
490 	return RC_CHK_ACCESS(dso)->needs_swap;
491 }
492 
493 static inline void dso__set_needs_swap(struct dso *dso, enum dso_swap_type type)
494 {
495 	RC_CHK_ACCESS(dso)->needs_swap = type;
496 }
497 
498 static inline struct nsinfo *dso__nsinfo(struct dso *dso)
499 {
500 	return RC_CHK_ACCESS(dso)->nsinfo;
501 }
502 
503 static inline const struct nsinfo *dso__nsinfo_const(const struct dso *dso)
504 {
505 	return RC_CHK_ACCESS(dso)->nsinfo;
506 }
507 
508 static inline struct nsinfo **dso__nsinfo_ptr(struct dso *dso)
509 {
510 	return &RC_CHK_ACCESS(dso)->nsinfo;
511 }
512 
513 void dso__set_nsinfo(struct dso *dso, struct nsinfo *nsi);
514 
515 static inline u8 dso__rel(const struct dso *dso)
516 {
517 	return RC_CHK_ACCESS(dso)->rel;
518 }
519 
520 static inline void dso__set_rel(struct dso *dso, u8 rel)
521 {
522 	RC_CHK_ACCESS(dso)->rel = rel;
523 }
524 
525 static inline const char *dso__short_name(const struct dso *dso)
526 {
527 	return RC_CHK_ACCESS(dso)->short_name;
528 }
529 
530 static inline bool dso__short_name_allocated(const struct dso *dso)
531 {
532 	return RC_CHK_ACCESS(dso)->short_name_allocated;
533 }
534 
535 static inline void dso__set_short_name_allocated(struct dso *dso, bool allocated)
536 {
537 	RC_CHK_ACCESS(dso)->short_name_allocated = allocated;
538 }
539 
540 static inline u16 dso__short_name_len(const struct dso *dso)
541 {
542 	return RC_CHK_ACCESS(dso)->short_name_len;
543 }
544 
545 static inline struct rb_root_cached *dso__srclines(struct dso *dso)
546 {
547 	return &RC_CHK_ACCESS(dso)->srclines;
548 }
549 
550 static inline struct rb_root *dso__data_types(struct dso *dso)
551 {
552 	return &RC_CHK_ACCESS(dso)->data_types;
553 }
554 
555 static inline struct rb_root *dso__global_vars(struct dso *dso)
556 {
557 	return &RC_CHK_ACCESS(dso)->global_vars;
558 }
559 
560 static inline struct rb_root_cached *dso__symbols(struct dso *dso)
561 {
562 	return &RC_CHK_ACCESS(dso)->symbols;
563 }
564 
565 static inline struct symbol **dso__symbol_names(struct dso *dso)
566 {
567 	return RC_CHK_ACCESS(dso)->symbol_names;
568 }
569 
570 static inline void dso__set_symbol_names(struct dso *dso, struct symbol **names)
571 {
572 	RC_CHK_ACCESS(dso)->symbol_names = names;
573 }
574 
575 static inline size_t dso__symbol_names_len(struct dso *dso)
576 {
577 	return RC_CHK_ACCESS(dso)->symbol_names_len;
578 }
579 
580 static inline void dso__set_symbol_names_len(struct dso *dso, size_t len)
581 {
582 	RC_CHK_ACCESS(dso)->symbol_names_len = len;
583 }
584 
585 static inline const char *dso__symsrc_filename(const struct dso *dso)
586 {
587 	return RC_CHK_ACCESS(dso)->symsrc_filename;
588 }
589 
590 static inline void dso__set_symsrc_filename(struct dso *dso, char *val)
591 {
592 	RC_CHK_ACCESS(dso)->symsrc_filename = val;
593 }
594 
595 static inline enum dso_binary_type dso__symtab_type(const struct dso *dso)
596 {
597 	return RC_CHK_ACCESS(dso)->symtab_type;
598 }
599 
600 static inline void dso__set_symtab_type(struct dso *dso, enum dso_binary_type bt)
601 {
602 	RC_CHK_ACCESS(dso)->symtab_type = bt;
603 }
604 
605 static inline u64 dso__text_end(const struct dso *dso)
606 {
607 	return RC_CHK_ACCESS(dso)->text_end;
608 }
609 
610 static inline void dso__set_text_end(struct dso *dso, u64 val)
611 {
612 	RC_CHK_ACCESS(dso)->text_end = val;
613 }
614 
615 static inline u64 dso__text_offset(const struct dso *dso)
616 {
617 	return RC_CHK_ACCESS(dso)->text_offset;
618 }
619 
620 static inline void dso__set_text_offset(struct dso *dso, u64 val)
621 {
622 	RC_CHK_ACCESS(dso)->text_offset = val;
623 }
624 
625 int dso_id__cmp(const struct dso_id *a, const struct dso_id *b);
626 bool dso_id__empty(const struct dso_id *id);
627 
628 struct dso *dso__new_id(const char *name, struct dso_id *id);
629 struct dso *dso__new(const char *name);
630 void dso__delete(struct dso *dso);
631 
632 int dso__cmp_id(struct dso *a, struct dso *b);
633 void dso__set_short_name(struct dso *dso, const char *name, bool name_allocated);
634 void dso__set_long_name(struct dso *dso, const char *name, bool name_allocated);
635 void __dso__inject_id(struct dso *dso, struct dso_id *id);
636 
637 int dso__name_len(const struct dso *dso);
638 
639 struct dso *dso__get(struct dso *dso);
640 void dso__put(struct dso *dso);
641 
642 static inline void __dso__zput(struct dso **dso)
643 {
644 	dso__put(*dso);
645 	*dso = NULL;
646 }
647 
648 #define dso__zput(dso) __dso__zput(&dso)
649 
650 bool dso__loaded(const struct dso *dso);
651 
652 static inline bool dso__has_symbols(const struct dso *dso)
653 {
654 	return !RB_EMPTY_ROOT(&RC_CHK_ACCESS(dso)->symbols.rb_root);
655 }
656 
657 char *dso__filename_with_chroot(const struct dso *dso, const char *filename);
658 
659 bool dso__sorted_by_name(const struct dso *dso);
660 void dso__set_sorted_by_name(struct dso *dso);
661 void dso__sort_by_name(struct dso *dso);
662 
663 void dso__set_build_id(struct dso *dso, struct build_id *bid);
664 bool dso__build_id_equal(const struct dso *dso, struct build_id *bid);
665 void dso__read_running_kernel_build_id(struct dso *dso,
666 				       struct machine *machine);
667 int dso__kernel_module_get_build_id(struct dso *dso, const char *root_dir);
668 
669 char dso__symtab_origin(const struct dso *dso);
670 int dso__read_binary_type_filename(const struct dso *dso, enum dso_binary_type type,
671 				   char *root_dir, char *filename, size_t size);
672 bool is_kernel_module(const char *pathname, int cpumode);
673 bool dso__needs_decompress(struct dso *dso);
674 int dso__decompress_kmodule_fd(struct dso *dso, const char *name);
675 int dso__decompress_kmodule_path(struct dso *dso, const char *name,
676 				 char *pathname, size_t len);
677 int filename__decompress(const char *name, char *pathname,
678 			 size_t len, int comp, int *err);
679 
680 #define KMOD_DECOMP_NAME  "/tmp/perf-kmod-XXXXXX"
681 #define KMOD_DECOMP_LEN   sizeof(KMOD_DECOMP_NAME)
682 
683 struct kmod_path {
684 	char *name;
685 	int   comp;
686 	bool  kmod;
687 };
688 
689 int __kmod_path__parse(struct kmod_path *m, const char *path,
690 		     bool alloc_name);
691 
692 #define kmod_path__parse(__m, __p)      __kmod_path__parse(__m, __p, false)
693 #define kmod_path__parse_name(__m, __p) __kmod_path__parse(__m, __p, true)
694 
695 void dso__set_module_info(struct dso *dso, struct kmod_path *m,
696 			  struct machine *machine);
697 
698 /*
699  * The dso__data_* external interface provides following functions:
700  *   dso__data_get_fd
701  *   dso__data_put_fd
702  *   dso__data_close
703  *   dso__data_size
704  *   dso__data_read_offset
705  *   dso__data_read_addr
706  *   dso__data_write_cache_offs
707  *   dso__data_write_cache_addr
708  *
709  * Please refer to the dso.c object code for each function and
710  * arguments documentation. Following text tries to explain the
711  * dso file descriptor caching.
712  *
713  * The dso__data* interface allows caching of opened file descriptors
714  * to speed up the dso data accesses. The idea is to leave the file
715  * descriptor opened ideally for the whole life of the dso object.
716  *
717  * The current usage of the dso__data_* interface is as follows:
718  *
719  * Get DSO's fd:
720  *   int fd = dso__data_get_fd(dso, machine);
721  *   if (fd >= 0) {
722  *       USE 'fd' SOMEHOW
723  *       dso__data_put_fd(dso);
724  *   }
725  *
726  * Read DSO's data:
727  *   n = dso__data_read_offset(dso_0, &machine, 0, buf, BUFSIZE);
728  *   n = dso__data_read_addr(dso_0, &machine, 0, buf, BUFSIZE);
729  *
730  * Eventually close DSO's fd:
731  *   dso__data_close(dso);
732  *
733  * It is not necessary to close the DSO object data file. Each time new
734  * DSO data file is opened, the limit (RLIMIT_NOFILE/2) is checked. Once
735  * it is crossed, the oldest opened DSO object is closed.
736  *
737  * The dso__delete function calls close_dso function to ensure the
738  * data file descriptor gets closed/unmapped before the dso object
739  * is freed.
740  *
741  * TODO
742 */
743 int dso__data_get_fd(struct dso *dso, struct machine *machine);
744 void dso__data_put_fd(struct dso *dso);
745 void dso__data_close(struct dso *dso);
746 
747 int dso__data_file_size(struct dso *dso, struct machine *machine);
748 off_t dso__data_size(struct dso *dso, struct machine *machine);
749 ssize_t dso__data_read_offset(struct dso *dso, struct machine *machine,
750 			      u64 offset, u8 *data, ssize_t size);
751 ssize_t dso__data_read_addr(struct dso *dso, struct map *map,
752 			    struct machine *machine, u64 addr,
753 			    u8 *data, ssize_t size);
754 bool dso__data_status_seen(struct dso *dso, enum dso_data_status_seen by);
755 ssize_t dso__data_write_cache_offs(struct dso *dso, struct machine *machine,
756 				   u64 offset, const u8 *data, ssize_t size);
757 ssize_t dso__data_write_cache_addr(struct dso *dso, struct map *map,
758 				   struct machine *machine, u64 addr,
759 				   const u8 *data, ssize_t size);
760 
761 struct map *dso__new_map(const char *name);
762 struct dso *machine__findnew_kernel(struct machine *machine, const char *name,
763 				    const char *short_name, int dso_type);
764 
765 void dso__reset_find_symbol_cache(struct dso *dso);
766 
767 size_t dso__fprintf_symbols_by_name(struct dso *dso, FILE *fp);
768 size_t dso__fprintf(struct dso *dso, FILE *fp);
769 
770 static inline enum dso_binary_type dso__binary_type(const struct dso *dso)
771 {
772 	return RC_CHK_ACCESS(dso)->binary_type;
773 }
774 
775 static inline void dso__set_binary_type(struct dso *dso, enum dso_binary_type bt)
776 {
777 	RC_CHK_ACCESS(dso)->binary_type = bt;
778 }
779 
780 static inline bool dso__is_vmlinux(const struct dso *dso)
781 {
782 	enum dso_binary_type bt = dso__binary_type(dso);
783 
784 	return bt == DSO_BINARY_TYPE__VMLINUX || bt == DSO_BINARY_TYPE__GUEST_VMLINUX;
785 }
786 
787 static inline bool dso__is_kcore(const struct dso *dso)
788 {
789 	enum dso_binary_type bt = dso__binary_type(dso);
790 
791 	return bt == DSO_BINARY_TYPE__KCORE || bt == DSO_BINARY_TYPE__GUEST_KCORE;
792 }
793 
794 static inline bool dso__is_kallsyms(const struct dso *dso)
795 {
796 	return RC_CHK_ACCESS(dso)->kernel && RC_CHK_ACCESS(dso)->long_name[0] != '/';
797 }
798 
799 bool dso__is_object_file(const struct dso *dso);
800 
801 void dso__free_a2l(struct dso *dso);
802 
803 enum dso_type dso__type(struct dso *dso, struct machine *machine);
804 
805 int dso__strerror_load(struct dso *dso, char *buf, size_t buflen);
806 
807 void reset_fd_limit(void);
808 
809 u64 dso__find_global_type(struct dso *dso, u64 addr);
810 u64 dso__findnew_global_type(struct dso *dso, u64 addr, u64 offset);
811 
812 #endif /* __PERF_DSO */
813