Imported Upstream version 0.14
[platform/upstream/chrpath.git] / protos.h
1 #ifndef PROTOS_H
2 #define PROTOS_H
3
4 #include <byteswap.h>
5 #include <elf.h>
6 #include "config.h"
7
8 #ifdef WORDS_BIGENDIAN
9 #define ELFDATA2 ELFDATA2MSB
10 #else
11 #define ELFDATA2 ELFDATA2LSB
12 #endif
13 #if SIZEOF_VOID_P != 8 && SIZEOF_VOID_P != 4
14 #error "Unknown word size (SIZEOF_VOID_P)!"
15 #endif
16
17 typedef union {
18   unsigned char e_ident[EI_NIDENT];
19   Elf32_Ehdr e32;
20   Elf64_Ehdr e64;
21 } Elf_Ehdr;
22
23 typedef union {
24   Elf32_Shdr e32;
25   Elf64_Shdr e64;
26 } Elf_Shdr;
27
28 typedef union {
29   Elf32_Phdr e32;
30   Elf64_Phdr e64;
31 } Elf_Phdr;
32
33 int is_e32(void);
34 int swap_bytes(void);
35
36 #define DO_SWAPU32(x) ( !swap_bytes() ? x : (uint32_t)bswap_32(x) )
37 #define DO_SWAPU64(x) ( !swap_bytes() ? x : (uint64_t)bswap_64(x) )
38 #define DO_SWAPS32(x) ( !swap_bytes() ? x : (int32_t)bswap_32(x) )
39 #define DO_SWAPS64(x) ( !swap_bytes() ? x : (int64_t)bswap_64(x) )
40
41 #define EHDRS(x) (is_e32() ? DO_SWAPS32(ehdr.e32.x) : DO_SWAPS64(ehdr.e64.x))
42 #define EHDRU(x) (is_e32() ? DO_SWAPU32(ehdr.e32.x) : DO_SWAPU64(ehdr.e64.x))
43 #define PHDR(x) (is_e32() ? DO_SWAPU32(phdr.e32.x) : DO_SWAPU64(phdr.e64.x))
44 #define SHDR(x) (is_e32() ? DO_SWAPU32(shdr.e32.x) : DO_SWAPU64(shdr.e64.x))
45 #define DYNSU(i,x) (is_e32() ? DO_SWAPU32(((Elf32_Dyn *)dyns)[i].x) \
46   : DO_SWAPU64(((Elf64_Dyn *)dyns)[i].x))
47 #define DYNSS(i,x) (is_e32() ? DO_SWAPS32(((Elf32_Dyn *)dyns)[i].x) \
48   : DO_SWAPS64(((Elf64_Dyn *)dyns)[i].x))
49
50 int killrpath(const char *filename);
51 int chrpath(const char *filename, const char *newpath, int convert);
52
53 int elf_open(const char *filename, int flags, Elf_Ehdr *ehdr);
54 void elf_close(int fd);
55 int elf_find_dynamic_section(int fd, Elf_Ehdr *ehdr, Elf_Phdr *phdr);
56 const char *elf_tagname(int tag);
57 int elf_dynpath_tag(int tag);
58
59 #endif /* PROTOS_H */