1/* $FreeBSD$ */
2
3#ifndef _EF_H_
4#define _EF_H_
5
6#define	EFT_KLD		1
7#define	EFT_KERNEL	2
8
9#define EF_RELOC_REL	1
10#define EF_RELOC_RELA	2
11
12#define EF_GET_TYPE(ef) \
13    (ef)->ef_ops->get_type((ef)->ef_ef)
14#define EF_CLOSE(ef) \
15    (ef)->ef_ops->close((ef)->ef_ef)
16#define EF_READ(ef, offset, len, dest) \
17    (ef)->ef_ops->read((ef)->ef_ef, offset, len, dest)
18#define EF_READ_ENTRY(ef, offset, len, ptr) \
19    (ef)->ef_ops->read_entry((ef)->ef_ef, offset, len, ptr)
20#define EF_SEG_READ(ef, offset, len, dest) \
21    (ef)->ef_ops->seg_read((ef)->ef_ef, offset, len, dest)
22#define EF_SEG_READ_REL(ef, offset, len, dest) \
23    (ef)->ef_ops->seg_read_rel((ef)->ef_ef, offset, len, dest)
24#define EF_SEG_READ_STRING(ef, offset, len, dest) \
25    (ef)->ef_ops->seg_read_string((ef)->ef_ef, offset, len, dest)
26#define EF_SEG_READ_ENTRY(ef, offset, len, ptr) \
27    (ef)->ef_ops->seg_read_entry((ef)->kf_ef, offset, len, ptr)
28#define EF_SEG_READ_ENTRY_REL(ef, offset, len, ptr) \
29    (ef)->ef_ops->seg_read_entry_rel((ef)->ef_ef, offset, len, ptr)
30#define EF_SYMADDR(ef, symidx) \
31    (ef)->ef_ops->symaddr((ef)->ef_ef, symidx)
32#define EF_LOOKUP_SET(ef, name, startp, stopp, countp) \
33    (ef)->ef_ops->lookup_set((ef)->ef_ef, name, startp, stopp, countp)
34#define EF_LOOKUP_SYMBOL(ef, name, sym) \
35    (ef)->ef_ops->lookup_symbol((ef)->ef_ef, name, sym)
36
37/* XXX, should have a different name. */
38typedef struct ef_file *elf_file_t;
39
40struct elf_file_ops {
41	int (*get_type)(elf_file_t ef);
42	int (*close)(elf_file_t ef);
43	int (*read)(elf_file_t ef, Elf_Off offset, size_t len, void* dest);
44	int (*read_entry)(elf_file_t ef, Elf_Off offset, size_t len,
45	    void **ptr);
46	int (*seg_read)(elf_file_t ef, Elf_Off offset, size_t len, void *dest);
47	int (*seg_read_rel)(elf_file_t ef, Elf_Off offset, size_t len,
48	    void *dest);
49	int (*seg_read_string)(elf_file_t, Elf_Off offset, size_t len,
50	    char *dest);
51	int (*seg_read_entry)(elf_file_t ef, Elf_Off offset, size_t len,
52	    void**ptr);
53	int (*seg_read_entry_rel)(elf_file_t ef, Elf_Off offset, size_t len,
54	    void**ptr);
55	Elf_Addr (*symaddr)(elf_file_t ef, Elf_Size symidx);
56	int (*lookup_set)(elf_file_t ef, const char *name, long *startp,
57	    long *stopp, long *countp);
58	int (*lookup_symbol)(elf_file_t ef, const char* name, Elf_Sym** sym);
59};
60
61struct elf_file {
62	elf_file_t ef_ef;
63	struct elf_file_ops *ef_ops;
64};
65
66__BEGIN_DECLS
67int ef_open(const char *filename, struct elf_file *ef, int verbose);
68int ef_obj_open(const char *filename, struct elf_file *ef, int verbose);
69int ef_reloc(struct elf_file *ef, const void *reldata, int reltype,
70    Elf_Off relbase, Elf_Off dataoff, size_t len, void *dest);
71__END_DECLS
72
73#endif /* _EF_H_*/
74