/[gentoo-projects]/pax-utils/paxelf.h
Gentoo

Contents of /pax-utils/paxelf.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.60 - (show annotations) (download) (as text)
Wed Jun 18 03:16:52 2014 UTC (6 months, 1 week ago) by vapier
Branch: MAIN
CVS Tags: HEAD
Changes since 1.59: +2 -1 lines
File MIME type: text/x-chdr
add support for symbol visibility

1 /*
2 * Copyright 2005-2012 Gentoo Foundation
3 * Distributed under the terms of the GNU General Public License v2
4 * $Header: /var/cvsroot/gentoo-projects/pax-utils/paxelf.h,v 1.59 2012/11/18 07:39:45 vapier Exp $
5 *
6 * Copyright 2005-2012 Ned Ludd - <solar@gentoo.org>
7 * Copyright 2005-2012 Mike Frysinger - <vapier@gentoo.org>
8 *
9 * Make sure all of the common elf stuff is setup as we expect
10 */
11
12 #ifndef _PAX_ELF_H
13 #define _PAX_ELF_H
14
15 typedef struct {
16 void *phdr;
17 void *shdr;
18 void *_data;
19 union { void *ehdr, *vdata; char *data; };
20 void *data_end;
21 char elf_class;
22 off_t len;
23 int fd;
24 int is_mmap;
25 const char *filename;
26 const char *base_filename;
27 } elfobj;
28 #define EHDR32(ptr) ((Elf32_Ehdr *)(ptr))
29 #define EHDR64(ptr) ((Elf64_Ehdr *)(ptr))
30 #define PHDR32(ptr) ((Elf32_Phdr *)(ptr))
31 #define PHDR64(ptr) ((Elf64_Phdr *)(ptr))
32 #define SHDR32(ptr) ((Elf32_Shdr *)(ptr))
33 #define SHDR64(ptr) ((Elf64_Shdr *)(ptr))
34 #define RELA32(ptr) ((Elf32_Rela *)(ptr))
35 #define RELA64(ptr) ((Elf64_Rela *)(ptr))
36 #define REL32(ptr) ((Elf32_Rel *)(ptr))
37 #define REL64(ptr) ((Elf64_Rel *)(ptr))
38 #define DYN32(ptr) ((Elf32_Dyn *)(ptr))
39 #define DYN64(ptr) ((Elf64_Dyn *)(ptr))
40 #define SYM32(ptr) ((Elf32_Sym *)(ptr))
41 #define SYM64(ptr) ((Elf64_Sym *)(ptr))
42
43 /* prototypes */
44 extern char *pax_short_hf_flags(unsigned long flags);
45 extern char *pax_short_pf_flags(unsigned long flags);
46 extern char *gnu_short_stack_flags(unsigned long flags);
47 extern elfobj *readelf_buffer(const char *filename, void *buffer, size_t buffer_len);
48 extern elfobj *_readelf_fd(const char *filename, int fd, size_t len, int read_only);
49 #define readelf_fd(filename, fd, len) _readelf_fd(filename, fd, len, 1)
50 extern elfobj *_readelf(const char *filename, int read_only);
51 #define readelf(filename) _readelf(filename, 1)
52 extern void unreadelf(elfobj *elf);
53 extern const char *get_elfeitype(int ei_type, int type);
54 extern const char *get_elfetype(elfobj *elf);
55 extern const char *get_endian(elfobj *elf);
56 extern const char *get_elfosabi(elfobj *elf);
57 extern const char *get_elf_eabi(elfobj *elf);
58 extern const char *get_elfemtype(elfobj *elf);
59 extern const char *get_elfptype(int type);
60 extern const char *get_elfdtype(int type);
61 extern const char *get_elfshntype(int type);
62 extern const char *get_elfshttype(int type);
63 extern const char *get_elfstbtype(int type);
64 extern const char *get_elfstvtype(int type);
65 extern const char *get_elfstttype(int type);
66 extern void *elf_findsecbyname(elfobj *elf, const char *name);
67 extern int get_etype(elfobj *elf);
68 extern int get_emtype(elfobj *elf);
69 extern void print_etypes(FILE *);
70 extern int etype_lookup(const char *);
71
72 /* PaX flags (to be read in elfhdr.e_flags) */
73 #define HF_PAX_PAGEEXEC 1 /* 0: Paging based non-exec pages */
74 #define HF_PAX_EMUTRAMP 2 /* 0: Emulate trampolines */
75 #define HF_PAX_MPROTECT 4 /* 0: Restrict mprotect() */
76 #define HF_PAX_RANDMMAP 8 /* 0: Randomize mmap() base */
77 #define HF_PAX_RANDEXEC 16 /* 1: Randomize ET_EXEC base */
78 #define HF_PAX_SEGMEXEC 32 /* 0: Segmentation based non-exec pages */
79
80 #define EI_PAX 14 /* Index in e_ident[] where to read flags */
81 #define __EI_PAX_FLAGS(B, elf) \
82 ((EHDR ## B (elf->ehdr)->e_ident[EI_PAX + 1] << 8) + \
83 EHDR ## B (elf->ehdr)->e_ident[EI_PAX])
84 #define EI_PAX_FLAGS(elf) \
85 (__extension__ ({ \
86 unsigned long __res; \
87 if (elf->elf_class == ELFCLASS32) \
88 __res = __EI_PAX_FLAGS(32, elf); \
89 else \
90 __res = __EI_PAX_FLAGS(64, elf); \
91 __res; \
92 }))
93
94 #endif /* _PAX_ELF_H */

  ViewVC Help
Powered by ViewVC 1.1.20