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