18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
28c2ecf20Sopenharmony_ci#ifndef __PERF_DSO
38c2ecf20Sopenharmony_ci#define __PERF_DSO
48c2ecf20Sopenharmony_ci
58c2ecf20Sopenharmony_ci#include <pthread.h>
68c2ecf20Sopenharmony_ci#include <linux/refcount.h>
78c2ecf20Sopenharmony_ci#include <linux/types.h>
88c2ecf20Sopenharmony_ci#include <linux/rbtree.h>
98c2ecf20Sopenharmony_ci#include <sys/types.h>
108c2ecf20Sopenharmony_ci#include <stdbool.h>
118c2ecf20Sopenharmony_ci#include <stdio.h>
128c2ecf20Sopenharmony_ci#include <linux/bitops.h>
138c2ecf20Sopenharmony_ci#include "build-id.h"
148c2ecf20Sopenharmony_ci
158c2ecf20Sopenharmony_cistruct machine;
168c2ecf20Sopenharmony_cistruct map;
178c2ecf20Sopenharmony_cistruct perf_env;
188c2ecf20Sopenharmony_ci
198c2ecf20Sopenharmony_ci#define DSO__NAME_KALLSYMS	"[kernel.kallsyms]"
208c2ecf20Sopenharmony_ci#define DSO__NAME_KCORE		"[kernel.kcore]"
218c2ecf20Sopenharmony_ci
228c2ecf20Sopenharmony_cienum dso_binary_type {
238c2ecf20Sopenharmony_ci	DSO_BINARY_TYPE__KALLSYMS = 0,
248c2ecf20Sopenharmony_ci	DSO_BINARY_TYPE__GUEST_KALLSYMS,
258c2ecf20Sopenharmony_ci	DSO_BINARY_TYPE__VMLINUX,
268c2ecf20Sopenharmony_ci	DSO_BINARY_TYPE__GUEST_VMLINUX,
278c2ecf20Sopenharmony_ci	DSO_BINARY_TYPE__JAVA_JIT,
288c2ecf20Sopenharmony_ci	DSO_BINARY_TYPE__DEBUGLINK,
298c2ecf20Sopenharmony_ci	DSO_BINARY_TYPE__BUILD_ID_CACHE,
308c2ecf20Sopenharmony_ci	DSO_BINARY_TYPE__BUILD_ID_CACHE_DEBUGINFO,
318c2ecf20Sopenharmony_ci	DSO_BINARY_TYPE__FEDORA_DEBUGINFO,
328c2ecf20Sopenharmony_ci	DSO_BINARY_TYPE__UBUNTU_DEBUGINFO,
338c2ecf20Sopenharmony_ci	DSO_BINARY_TYPE__MIXEDUP_UBUNTU_DEBUGINFO,
348c2ecf20Sopenharmony_ci	DSO_BINARY_TYPE__BUILDID_DEBUGINFO,
358c2ecf20Sopenharmony_ci	DSO_BINARY_TYPE__SYSTEM_PATH_DSO,
368c2ecf20Sopenharmony_ci	DSO_BINARY_TYPE__GUEST_KMODULE,
378c2ecf20Sopenharmony_ci	DSO_BINARY_TYPE__GUEST_KMODULE_COMP,
388c2ecf20Sopenharmony_ci	DSO_BINARY_TYPE__SYSTEM_PATH_KMODULE,
398c2ecf20Sopenharmony_ci	DSO_BINARY_TYPE__SYSTEM_PATH_KMODULE_COMP,
408c2ecf20Sopenharmony_ci	DSO_BINARY_TYPE__KCORE,
418c2ecf20Sopenharmony_ci	DSO_BINARY_TYPE__GUEST_KCORE,
428c2ecf20Sopenharmony_ci	DSO_BINARY_TYPE__OPENEMBEDDED_DEBUGINFO,
438c2ecf20Sopenharmony_ci	DSO_BINARY_TYPE__BPF_PROG_INFO,
448c2ecf20Sopenharmony_ci	DSO_BINARY_TYPE__BPF_IMAGE,
458c2ecf20Sopenharmony_ci	DSO_BINARY_TYPE__OOL,
468c2ecf20Sopenharmony_ci	DSO_BINARY_TYPE__NOT_FOUND,
478c2ecf20Sopenharmony_ci};
488c2ecf20Sopenharmony_ci
498c2ecf20Sopenharmony_cienum dso_space_type {
508c2ecf20Sopenharmony_ci	DSO_SPACE__USER = 0,
518c2ecf20Sopenharmony_ci	DSO_SPACE__KERNEL,
528c2ecf20Sopenharmony_ci	DSO_SPACE__KERNEL_GUEST
538c2ecf20Sopenharmony_ci};
548c2ecf20Sopenharmony_ci
558c2ecf20Sopenharmony_cienum dso_swap_type {
568c2ecf20Sopenharmony_ci	DSO_SWAP__UNSET,
578c2ecf20Sopenharmony_ci	DSO_SWAP__NO,
588c2ecf20Sopenharmony_ci	DSO_SWAP__YES,
598c2ecf20Sopenharmony_ci};
608c2ecf20Sopenharmony_ci
618c2ecf20Sopenharmony_cienum dso_data_status {
628c2ecf20Sopenharmony_ci	DSO_DATA_STATUS_ERROR	= -1,
638c2ecf20Sopenharmony_ci	DSO_DATA_STATUS_UNKNOWN	= 0,
648c2ecf20Sopenharmony_ci	DSO_DATA_STATUS_OK	= 1,
658c2ecf20Sopenharmony_ci};
668c2ecf20Sopenharmony_ci
678c2ecf20Sopenharmony_cienum dso_data_status_seen {
688c2ecf20Sopenharmony_ci	DSO_DATA_STATUS_SEEN_ITRACE,
698c2ecf20Sopenharmony_ci};
708c2ecf20Sopenharmony_ci
718c2ecf20Sopenharmony_cienum dso_type {
728c2ecf20Sopenharmony_ci	DSO__TYPE_UNKNOWN,
738c2ecf20Sopenharmony_ci	DSO__TYPE_64BIT,
748c2ecf20Sopenharmony_ci	DSO__TYPE_32BIT,
758c2ecf20Sopenharmony_ci	DSO__TYPE_X32BIT,
768c2ecf20Sopenharmony_ci};
778c2ecf20Sopenharmony_ci
788c2ecf20Sopenharmony_cienum dso_load_errno {
798c2ecf20Sopenharmony_ci	DSO_LOAD_ERRNO__SUCCESS		= 0,
808c2ecf20Sopenharmony_ci
818c2ecf20Sopenharmony_ci	/*
828c2ecf20Sopenharmony_ci	 * Choose an arbitrary negative big number not to clash with standard
838c2ecf20Sopenharmony_ci	 * errno since SUS requires the errno has distinct positive values.
848c2ecf20Sopenharmony_ci	 * See 'Issue 6' in the link below.
858c2ecf20Sopenharmony_ci	 *
868c2ecf20Sopenharmony_ci	 * http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/errno.h.html
878c2ecf20Sopenharmony_ci	 */
888c2ecf20Sopenharmony_ci	__DSO_LOAD_ERRNO__START		= -10000,
898c2ecf20Sopenharmony_ci
908c2ecf20Sopenharmony_ci	DSO_LOAD_ERRNO__INTERNAL_ERROR	= __DSO_LOAD_ERRNO__START,
918c2ecf20Sopenharmony_ci
928c2ecf20Sopenharmony_ci	/* for symsrc__init() */
938c2ecf20Sopenharmony_ci	DSO_LOAD_ERRNO__INVALID_ELF,
948c2ecf20Sopenharmony_ci	DSO_LOAD_ERRNO__CANNOT_READ_BUILDID,
958c2ecf20Sopenharmony_ci	DSO_LOAD_ERRNO__MISMATCHING_BUILDID,
968c2ecf20Sopenharmony_ci
978c2ecf20Sopenharmony_ci	/* for decompress_kmodule */
988c2ecf20Sopenharmony_ci	DSO_LOAD_ERRNO__DECOMPRESSION_FAILURE,
998c2ecf20Sopenharmony_ci
1008c2ecf20Sopenharmony_ci	__DSO_LOAD_ERRNO__END,
1018c2ecf20Sopenharmony_ci};
1028c2ecf20Sopenharmony_ci
1038c2ecf20Sopenharmony_ci#define DSO__SWAP(dso, type, val)			\
1048c2ecf20Sopenharmony_ci({							\
1058c2ecf20Sopenharmony_ci	type ____r = val;				\
1068c2ecf20Sopenharmony_ci	BUG_ON(dso->needs_swap == DSO_SWAP__UNSET);	\
1078c2ecf20Sopenharmony_ci	if (dso->needs_swap == DSO_SWAP__YES) {		\
1088c2ecf20Sopenharmony_ci		switch (sizeof(____r)) {		\
1098c2ecf20Sopenharmony_ci		case 2:					\
1108c2ecf20Sopenharmony_ci			____r = bswap_16(val);		\
1118c2ecf20Sopenharmony_ci			break;				\
1128c2ecf20Sopenharmony_ci		case 4:					\
1138c2ecf20Sopenharmony_ci			____r = bswap_32(val);		\
1148c2ecf20Sopenharmony_ci			break;				\
1158c2ecf20Sopenharmony_ci		case 8:					\
1168c2ecf20Sopenharmony_ci			____r = bswap_64(val);		\
1178c2ecf20Sopenharmony_ci			break;				\
1188c2ecf20Sopenharmony_ci		default:				\
1198c2ecf20Sopenharmony_ci			BUG_ON(1);			\
1208c2ecf20Sopenharmony_ci		}					\
1218c2ecf20Sopenharmony_ci	}						\
1228c2ecf20Sopenharmony_ci	____r;						\
1238c2ecf20Sopenharmony_ci})
1248c2ecf20Sopenharmony_ci
1258c2ecf20Sopenharmony_ci#define DSO__DATA_CACHE_SIZE 4096
1268c2ecf20Sopenharmony_ci#define DSO__DATA_CACHE_MASK ~(DSO__DATA_CACHE_SIZE - 1)
1278c2ecf20Sopenharmony_ci
1288c2ecf20Sopenharmony_ci/*
1298c2ecf20Sopenharmony_ci * Data about backing storage DSO, comes from PERF_RECORD_MMAP2 meta events
1308c2ecf20Sopenharmony_ci */
1318c2ecf20Sopenharmony_cistruct dso_id {
1328c2ecf20Sopenharmony_ci	u32	maj;
1338c2ecf20Sopenharmony_ci	u32	min;
1348c2ecf20Sopenharmony_ci	u64	ino;
1358c2ecf20Sopenharmony_ci	u64	ino_generation;
1368c2ecf20Sopenharmony_ci};
1378c2ecf20Sopenharmony_ci
1388c2ecf20Sopenharmony_cistruct dso_cache {
1398c2ecf20Sopenharmony_ci	struct rb_node	rb_node;
1408c2ecf20Sopenharmony_ci	u64 offset;
1418c2ecf20Sopenharmony_ci	u64 size;
1428c2ecf20Sopenharmony_ci	char data[];
1438c2ecf20Sopenharmony_ci};
1448c2ecf20Sopenharmony_ci
1458c2ecf20Sopenharmony_cistruct auxtrace_cache;
1468c2ecf20Sopenharmony_ci
1478c2ecf20Sopenharmony_cistruct dso {
1488c2ecf20Sopenharmony_ci	pthread_mutex_t	 lock;
1498c2ecf20Sopenharmony_ci	struct list_head node;
1508c2ecf20Sopenharmony_ci	struct rb_node	 rb_node;	/* rbtree node sorted by long name */
1518c2ecf20Sopenharmony_ci	struct rb_root	 *root;		/* root of rbtree that rb_node is in */
1528c2ecf20Sopenharmony_ci	struct rb_root_cached symbols;
1538c2ecf20Sopenharmony_ci	struct rb_root_cached symbol_names;
1548c2ecf20Sopenharmony_ci	struct rb_root_cached inlined_nodes;
1558c2ecf20Sopenharmony_ci	struct rb_root_cached srclines;
1568c2ecf20Sopenharmony_ci	struct {
1578c2ecf20Sopenharmony_ci		u64		addr;
1588c2ecf20Sopenharmony_ci		struct symbol	*symbol;
1598c2ecf20Sopenharmony_ci	} last_find_result;
1608c2ecf20Sopenharmony_ci	void		 *a2l;
1618c2ecf20Sopenharmony_ci	char		 *symsrc_filename;
1628c2ecf20Sopenharmony_ci	unsigned int	 a2l_fails;
1638c2ecf20Sopenharmony_ci	enum dso_space_type	kernel;
1648c2ecf20Sopenharmony_ci	enum dso_swap_type	needs_swap;
1658c2ecf20Sopenharmony_ci	enum dso_binary_type	symtab_type;
1668c2ecf20Sopenharmony_ci	enum dso_binary_type	binary_type;
1678c2ecf20Sopenharmony_ci	enum dso_load_errno	load_errno;
1688c2ecf20Sopenharmony_ci	u8		 adjust_symbols:1;
1698c2ecf20Sopenharmony_ci	u8		 has_build_id:1;
1708c2ecf20Sopenharmony_ci	u8		 has_srcline:1;
1718c2ecf20Sopenharmony_ci	u8		 hit:1;
1728c2ecf20Sopenharmony_ci	u8		 annotate_warned:1;
1738c2ecf20Sopenharmony_ci	u8		 short_name_allocated:1;
1748c2ecf20Sopenharmony_ci	u8		 long_name_allocated:1;
1758c2ecf20Sopenharmony_ci	u8		 is_64_bit:1;
1768c2ecf20Sopenharmony_ci	bool		 sorted_by_name;
1778c2ecf20Sopenharmony_ci	bool		 loaded;
1788c2ecf20Sopenharmony_ci	u8		 rel;
1798c2ecf20Sopenharmony_ci	struct build_id	 bid;
1808c2ecf20Sopenharmony_ci	u64		 text_offset;
1818c2ecf20Sopenharmony_ci	const char	 *short_name;
1828c2ecf20Sopenharmony_ci	const char	 *long_name;
1838c2ecf20Sopenharmony_ci	u16		 long_name_len;
1848c2ecf20Sopenharmony_ci	u16		 short_name_len;
1858c2ecf20Sopenharmony_ci	void		*dwfl;			/* DWARF debug info */
1868c2ecf20Sopenharmony_ci	struct auxtrace_cache *auxtrace_cache;
1878c2ecf20Sopenharmony_ci	int		 comp;
1888c2ecf20Sopenharmony_ci
1898c2ecf20Sopenharmony_ci	/* dso data file */
1908c2ecf20Sopenharmony_ci	struct {
1918c2ecf20Sopenharmony_ci		struct rb_root	 cache;
1928c2ecf20Sopenharmony_ci		int		 fd;
1938c2ecf20Sopenharmony_ci		int		 status;
1948c2ecf20Sopenharmony_ci		u32		 status_seen;
1958c2ecf20Sopenharmony_ci		size_t		 file_size;
1968c2ecf20Sopenharmony_ci		struct list_head open_entry;
1978c2ecf20Sopenharmony_ci		u64		 debug_frame_offset;
1988c2ecf20Sopenharmony_ci		u64		 eh_frame_hdr_offset;
1998c2ecf20Sopenharmony_ci	} data;
2008c2ecf20Sopenharmony_ci	/* bpf prog information */
2018c2ecf20Sopenharmony_ci	struct {
2028c2ecf20Sopenharmony_ci		u32		id;
2038c2ecf20Sopenharmony_ci		u32		sub_id;
2048c2ecf20Sopenharmony_ci		struct perf_env	*env;
2058c2ecf20Sopenharmony_ci	} bpf_prog;
2068c2ecf20Sopenharmony_ci
2078c2ecf20Sopenharmony_ci	union { /* Tool specific area */
2088c2ecf20Sopenharmony_ci		void	 *priv;
2098c2ecf20Sopenharmony_ci		u64	 db_id;
2108c2ecf20Sopenharmony_ci	};
2118c2ecf20Sopenharmony_ci	struct nsinfo	*nsinfo;
2128c2ecf20Sopenharmony_ci	struct dso_id	 id;
2138c2ecf20Sopenharmony_ci	refcount_t	 refcnt;
2148c2ecf20Sopenharmony_ci	char		 name[];
2158c2ecf20Sopenharmony_ci};
2168c2ecf20Sopenharmony_ci
2178c2ecf20Sopenharmony_ci/* dso__for_each_symbol - iterate over the symbols of given type
2188c2ecf20Sopenharmony_ci *
2198c2ecf20Sopenharmony_ci * @dso: the 'struct dso *' in which symbols itereated
2208c2ecf20Sopenharmony_ci * @pos: the 'struct symbol *' to use as a loop cursor
2218c2ecf20Sopenharmony_ci * @n: the 'struct rb_node *' to use as a temporary storage
2228c2ecf20Sopenharmony_ci */
2238c2ecf20Sopenharmony_ci#define dso__for_each_symbol(dso, pos, n)	\
2248c2ecf20Sopenharmony_ci	symbols__for_each_entry(&(dso)->symbols, pos, n)
2258c2ecf20Sopenharmony_ci
2268c2ecf20Sopenharmony_cistatic inline void dso__set_loaded(struct dso *dso)
2278c2ecf20Sopenharmony_ci{
2288c2ecf20Sopenharmony_ci	dso->loaded = true;
2298c2ecf20Sopenharmony_ci}
2308c2ecf20Sopenharmony_ci
2318c2ecf20Sopenharmony_cistruct dso *dso__new_id(const char *name, struct dso_id *id);
2328c2ecf20Sopenharmony_cistruct dso *dso__new(const char *name);
2338c2ecf20Sopenharmony_civoid dso__delete(struct dso *dso);
2348c2ecf20Sopenharmony_ci
2358c2ecf20Sopenharmony_ciint dso__cmp_id(struct dso *a, struct dso *b);
2368c2ecf20Sopenharmony_civoid dso__set_short_name(struct dso *dso, const char *name, bool name_allocated);
2378c2ecf20Sopenharmony_civoid dso__set_long_name(struct dso *dso, const char *name, bool name_allocated);
2388c2ecf20Sopenharmony_ci
2398c2ecf20Sopenharmony_ciint dso__name_len(const struct dso *dso);
2408c2ecf20Sopenharmony_ci
2418c2ecf20Sopenharmony_cistruct dso *dso__get(struct dso *dso);
2428c2ecf20Sopenharmony_civoid dso__put(struct dso *dso);
2438c2ecf20Sopenharmony_ci
2448c2ecf20Sopenharmony_cistatic inline void __dso__zput(struct dso **dso)
2458c2ecf20Sopenharmony_ci{
2468c2ecf20Sopenharmony_ci	dso__put(*dso);
2478c2ecf20Sopenharmony_ci	*dso = NULL;
2488c2ecf20Sopenharmony_ci}
2498c2ecf20Sopenharmony_ci
2508c2ecf20Sopenharmony_ci#define dso__zput(dso) __dso__zput(&dso)
2518c2ecf20Sopenharmony_ci
2528c2ecf20Sopenharmony_cibool dso__loaded(const struct dso *dso);
2538c2ecf20Sopenharmony_ci
2548c2ecf20Sopenharmony_cistatic inline bool dso__has_symbols(const struct dso *dso)
2558c2ecf20Sopenharmony_ci{
2568c2ecf20Sopenharmony_ci	return !RB_EMPTY_ROOT(&dso->symbols.rb_root);
2578c2ecf20Sopenharmony_ci}
2588c2ecf20Sopenharmony_ci
2598c2ecf20Sopenharmony_cibool dso__sorted_by_name(const struct dso *dso);
2608c2ecf20Sopenharmony_civoid dso__set_sorted_by_name(struct dso *dso);
2618c2ecf20Sopenharmony_civoid dso__sort_by_name(struct dso *dso);
2628c2ecf20Sopenharmony_ci
2638c2ecf20Sopenharmony_civoid dso__set_build_id(struct dso *dso, struct build_id *bid);
2648c2ecf20Sopenharmony_cibool dso__build_id_equal(const struct dso *dso, struct build_id *bid);
2658c2ecf20Sopenharmony_civoid dso__read_running_kernel_build_id(struct dso *dso,
2668c2ecf20Sopenharmony_ci				       struct machine *machine);
2678c2ecf20Sopenharmony_ciint dso__kernel_module_get_build_id(struct dso *dso, const char *root_dir);
2688c2ecf20Sopenharmony_ci
2698c2ecf20Sopenharmony_cichar dso__symtab_origin(const struct dso *dso);
2708c2ecf20Sopenharmony_ciint dso__read_binary_type_filename(const struct dso *dso, enum dso_binary_type type,
2718c2ecf20Sopenharmony_ci				   char *root_dir, char *filename, size_t size);
2728c2ecf20Sopenharmony_cibool is_kernel_module(const char *pathname, int cpumode);
2738c2ecf20Sopenharmony_cibool dso__needs_decompress(struct dso *dso);
2748c2ecf20Sopenharmony_ciint dso__decompress_kmodule_fd(struct dso *dso, const char *name);
2758c2ecf20Sopenharmony_ciint dso__decompress_kmodule_path(struct dso *dso, const char *name,
2768c2ecf20Sopenharmony_ci				 char *pathname, size_t len);
2778c2ecf20Sopenharmony_ci
2788c2ecf20Sopenharmony_ci#define KMOD_DECOMP_NAME  "/tmp/perf-kmod-XXXXXX"
2798c2ecf20Sopenharmony_ci#define KMOD_DECOMP_LEN   sizeof(KMOD_DECOMP_NAME)
2808c2ecf20Sopenharmony_ci
2818c2ecf20Sopenharmony_cistruct kmod_path {
2828c2ecf20Sopenharmony_ci	char *name;
2838c2ecf20Sopenharmony_ci	int   comp;
2848c2ecf20Sopenharmony_ci	bool  kmod;
2858c2ecf20Sopenharmony_ci};
2868c2ecf20Sopenharmony_ci
2878c2ecf20Sopenharmony_ciint __kmod_path__parse(struct kmod_path *m, const char *path,
2888c2ecf20Sopenharmony_ci		     bool alloc_name);
2898c2ecf20Sopenharmony_ci
2908c2ecf20Sopenharmony_ci#define kmod_path__parse(__m, __p)      __kmod_path__parse(__m, __p, false)
2918c2ecf20Sopenharmony_ci#define kmod_path__parse_name(__m, __p) __kmod_path__parse(__m, __p, true)
2928c2ecf20Sopenharmony_ci
2938c2ecf20Sopenharmony_civoid dso__set_module_info(struct dso *dso, struct kmod_path *m,
2948c2ecf20Sopenharmony_ci			  struct machine *machine);
2958c2ecf20Sopenharmony_ci
2968c2ecf20Sopenharmony_ci/*
2978c2ecf20Sopenharmony_ci * The dso__data_* external interface provides following functions:
2988c2ecf20Sopenharmony_ci *   dso__data_get_fd
2998c2ecf20Sopenharmony_ci *   dso__data_put_fd
3008c2ecf20Sopenharmony_ci *   dso__data_close
3018c2ecf20Sopenharmony_ci *   dso__data_size
3028c2ecf20Sopenharmony_ci *   dso__data_read_offset
3038c2ecf20Sopenharmony_ci *   dso__data_read_addr
3048c2ecf20Sopenharmony_ci *   dso__data_write_cache_offs
3058c2ecf20Sopenharmony_ci *   dso__data_write_cache_addr
3068c2ecf20Sopenharmony_ci *
3078c2ecf20Sopenharmony_ci * Please refer to the dso.c object code for each function and
3088c2ecf20Sopenharmony_ci * arguments documentation. Following text tries to explain the
3098c2ecf20Sopenharmony_ci * dso file descriptor caching.
3108c2ecf20Sopenharmony_ci *
3118c2ecf20Sopenharmony_ci * The dso__data* interface allows caching of opened file descriptors
3128c2ecf20Sopenharmony_ci * to speed up the dso data accesses. The idea is to leave the file
3138c2ecf20Sopenharmony_ci * descriptor opened ideally for the whole life of the dso object.
3148c2ecf20Sopenharmony_ci *
3158c2ecf20Sopenharmony_ci * The current usage of the dso__data_* interface is as follows:
3168c2ecf20Sopenharmony_ci *
3178c2ecf20Sopenharmony_ci * Get DSO's fd:
3188c2ecf20Sopenharmony_ci *   int fd = dso__data_get_fd(dso, machine);
3198c2ecf20Sopenharmony_ci *   if (fd >= 0) {
3208c2ecf20Sopenharmony_ci *       USE 'fd' SOMEHOW
3218c2ecf20Sopenharmony_ci *       dso__data_put_fd(dso);
3228c2ecf20Sopenharmony_ci *   }
3238c2ecf20Sopenharmony_ci *
3248c2ecf20Sopenharmony_ci * Read DSO's data:
3258c2ecf20Sopenharmony_ci *   n = dso__data_read_offset(dso_0, &machine, 0, buf, BUFSIZE);
3268c2ecf20Sopenharmony_ci *   n = dso__data_read_addr(dso_0, &machine, 0, buf, BUFSIZE);
3278c2ecf20Sopenharmony_ci *
3288c2ecf20Sopenharmony_ci * Eventually close DSO's fd:
3298c2ecf20Sopenharmony_ci *   dso__data_close(dso);
3308c2ecf20Sopenharmony_ci *
3318c2ecf20Sopenharmony_ci * It is not necessary to close the DSO object data file. Each time new
3328c2ecf20Sopenharmony_ci * DSO data file is opened, the limit (RLIMIT_NOFILE/2) is checked. Once
3338c2ecf20Sopenharmony_ci * it is crossed, the oldest opened DSO object is closed.
3348c2ecf20Sopenharmony_ci *
3358c2ecf20Sopenharmony_ci * The dso__delete function calls close_dso function to ensure the
3368c2ecf20Sopenharmony_ci * data file descriptor gets closed/unmapped before the dso object
3378c2ecf20Sopenharmony_ci * is freed.
3388c2ecf20Sopenharmony_ci *
3398c2ecf20Sopenharmony_ci * TODO
3408c2ecf20Sopenharmony_ci*/
3418c2ecf20Sopenharmony_ciint dso__data_get_fd(struct dso *dso, struct machine *machine);
3428c2ecf20Sopenharmony_civoid dso__data_put_fd(struct dso *dso);
3438c2ecf20Sopenharmony_civoid dso__data_close(struct dso *dso);
3448c2ecf20Sopenharmony_ci
3458c2ecf20Sopenharmony_ciint dso__data_file_size(struct dso *dso, struct machine *machine);
3468c2ecf20Sopenharmony_cioff_t dso__data_size(struct dso *dso, struct machine *machine);
3478c2ecf20Sopenharmony_cissize_t dso__data_read_offset(struct dso *dso, struct machine *machine,
3488c2ecf20Sopenharmony_ci			      u64 offset, u8 *data, ssize_t size);
3498c2ecf20Sopenharmony_cissize_t dso__data_read_addr(struct dso *dso, struct map *map,
3508c2ecf20Sopenharmony_ci			    struct machine *machine, u64 addr,
3518c2ecf20Sopenharmony_ci			    u8 *data, ssize_t size);
3528c2ecf20Sopenharmony_cibool dso__data_status_seen(struct dso *dso, enum dso_data_status_seen by);
3538c2ecf20Sopenharmony_cissize_t dso__data_write_cache_offs(struct dso *dso, struct machine *machine,
3548c2ecf20Sopenharmony_ci				   u64 offset, const u8 *data, ssize_t size);
3558c2ecf20Sopenharmony_cissize_t dso__data_write_cache_addr(struct dso *dso, struct map *map,
3568c2ecf20Sopenharmony_ci				   struct machine *machine, u64 addr,
3578c2ecf20Sopenharmony_ci				   const u8 *data, ssize_t size);
3588c2ecf20Sopenharmony_ci
3598c2ecf20Sopenharmony_cistruct map *dso__new_map(const char *name);
3608c2ecf20Sopenharmony_cistruct dso *machine__findnew_kernel(struct machine *machine, const char *name,
3618c2ecf20Sopenharmony_ci				    const char *short_name, int dso_type);
3628c2ecf20Sopenharmony_ci
3638c2ecf20Sopenharmony_civoid dso__reset_find_symbol_cache(struct dso *dso);
3648c2ecf20Sopenharmony_ci
3658c2ecf20Sopenharmony_cisize_t dso__fprintf_symbols_by_name(struct dso *dso, FILE *fp);
3668c2ecf20Sopenharmony_cisize_t dso__fprintf(struct dso *dso, FILE *fp);
3678c2ecf20Sopenharmony_ci
3688c2ecf20Sopenharmony_cistatic inline bool dso__is_vmlinux(struct dso *dso)
3698c2ecf20Sopenharmony_ci{
3708c2ecf20Sopenharmony_ci	return dso->binary_type == DSO_BINARY_TYPE__VMLINUX ||
3718c2ecf20Sopenharmony_ci	       dso->binary_type == DSO_BINARY_TYPE__GUEST_VMLINUX;
3728c2ecf20Sopenharmony_ci}
3738c2ecf20Sopenharmony_ci
3748c2ecf20Sopenharmony_cistatic inline bool dso__is_kcore(struct dso *dso)
3758c2ecf20Sopenharmony_ci{
3768c2ecf20Sopenharmony_ci	return dso->binary_type == DSO_BINARY_TYPE__KCORE ||
3778c2ecf20Sopenharmony_ci	       dso->binary_type == DSO_BINARY_TYPE__GUEST_KCORE;
3788c2ecf20Sopenharmony_ci}
3798c2ecf20Sopenharmony_ci
3808c2ecf20Sopenharmony_cistatic inline bool dso__is_kallsyms(struct dso *dso)
3818c2ecf20Sopenharmony_ci{
3828c2ecf20Sopenharmony_ci	return dso->kernel && dso->long_name[0] != '/';
3838c2ecf20Sopenharmony_ci}
3848c2ecf20Sopenharmony_ci
3858c2ecf20Sopenharmony_civoid dso__free_a2l(struct dso *dso);
3868c2ecf20Sopenharmony_ci
3878c2ecf20Sopenharmony_cienum dso_type dso__type(struct dso *dso, struct machine *machine);
3888c2ecf20Sopenharmony_ci
3898c2ecf20Sopenharmony_ciint dso__strerror_load(struct dso *dso, char *buf, size_t buflen);
3908c2ecf20Sopenharmony_ci
3918c2ecf20Sopenharmony_civoid reset_fd_limit(void);
3928c2ecf20Sopenharmony_ci
3938c2ecf20Sopenharmony_ci#endif /* __PERF_DSO */
394