Blame ksymtab.h

Packit 400c17
/*
Packit 400c17
	Copyright(C) 2016, Red Hat, Inc., Stanislav Kozina
Packit 400c17
Packit 400c17
	This program is free software: you can redistribute it and/or modify
Packit 400c17
	it under the terms of the GNU General Public License as published by
Packit 400c17
	the Free Software Foundation, either version 3 of the License, or
Packit 400c17
	(at your option) any later version.
Packit 400c17
Packit 400c17
	This program is distributed in the hope that it will be useful,
Packit 400c17
	but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 400c17
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit 400c17
	GNU General Public License for more details.
Packit 400c17
Packit 400c17
	You should have received a copy of the GNU General Public License
Packit 400c17
	along with this program.  If not, see <http://www.gnu.org/licenses/>.
Packit 400c17
*/
Packit 400c17
Packit 400c17
#ifndef KSYMTAB_H_
Packit 400c17
#define	KSYMTAB_H_
Packit 400c17
Packit 400c17
#include <stdint.h>
Packit 400c17
Packit Service 28f424
struct elf_data {
Packit Service 28f424
	Elf *elf;
Packit Service 28f424
	GElf_Ehdr *ehdr;
Packit Service 28f424
	size_t shstrndx;
Packit Service 28f424
	const char *strtab;
Packit Service 28f424
	size_t strtab_size;
Packit Service 28f424
	int fd;
Packit Service 28f424
};
Packit Service 28f424
Packit 400c17
struct ksymtab;
Packit 400c17
struct ksym {
Packit 400c17
	uint64_t value;
Packit 400c17
	bool mark;
Packit 400c17
	char *link;
Packit 400c17
	struct ksymtab *ksymtab;
Packit 400c17
	char key[];
Packit 400c17
};
Packit 400c17
Packit 400c17
static inline bool ksymtab_ksym_is_marked(struct ksym *ksym)
Packit 400c17
{
Packit 400c17
	return ksym->mark;
Packit 400c17
}
Packit 400c17
Packit 400c17
static inline const char *ksymtab_ksym_get_name(struct ksym *ksym)
Packit 400c17
{
Packit 400c17
	return ksym->key;
Packit 400c17
}
Packit 400c17
Packit 400c17
static inline uint64_t ksymtab_ksym_get_value(struct ksym *ksym)
Packit 400c17
{
Packit 400c17
	return ksym->value;
Packit 400c17
}
Packit 400c17
Packit 400c17
static inline char *ksymtab_ksym_get_link(struct ksym *ksym)
Packit 400c17
{
Packit 400c17
	return ksym->link;
Packit 400c17
}
Packit 400c17
Packit 400c17
static inline void ksymtab_ksym_set_link(struct ksym *ksym, const char *link)
Packit 400c17
{
Packit 400c17
	if (ksym->link)
Packit 400c17
		free(ksym->link);
Packit 400c17
	ksym->link = safe_strdup_or_null(link);
Packit 400c17
}
Packit 400c17
Packit 400c17
extern void ksymtab_free(struct ksymtab *);
Packit Service 28f424
extern struct elf_data *elf_open(const char *);
Packit Service 28f424
extern int elf_get_exported(struct elf_data *, struct ksymtab **,
Packit Service 28f424
			    struct ksymtab **);
Packit Service 28f424
extern void elf_close(struct elf_data *);
Packit Service 28f424
extern int elf_get_endianness(struct elf_data *, unsigned int *);
Packit 400c17
extern struct ksym *ksymtab_find(struct ksymtab *, const char *);
Packit 400c17
extern size_t ksymtab_len(struct ksymtab *);
Packit 400c17
extern struct ksymtab *ksymtab_new(size_t);
Packit 400c17
extern struct ksym *ksymtab_add_sym(struct ksymtab *,
Packit 400c17
				    const char *, size_t, uint64_t);
Packit 400c17
extern struct ksym *ksymtab_copy_sym(struct ksymtab *, struct ksym *);
Packit 400c17
extern void ksymtab_for_each(struct ksymtab *,
Packit 400c17
			     void (*f)(struct ksym *, void *),
Packit 400c17
			     void *);
Packit 400c17
extern size_t ksymtab_mark_count(struct ksymtab *);
Packit 400c17
extern void ksymtab_ksym_mark(struct ksym *);
Packit 400c17
Packit 400c17
#endif /* KSYMTAB_H_ */