source: bootcd/isolinux/syslinux-6.03/core/elflink/elfutils.h

Last change on this file was e16e8f2, checked in by Edwin Eefting <edwin@datux.nl>, 3 years ago

bootstuff

  • Property mode set to 100644
File size: 1.9 KB
Line 
1#ifndef ELF_UTILS_H_
2#define ELF_UTILS_H_
3
4#include <elf.h>
5#include <stdlib.h>
6
7/**
8 * elf_get_header - Returns a pointer to the ELF header structure.
9 * @elf_image: pointer to the ELF file image in memory
10 */
11static inline Elf32_Ehdr *elf_get_header(void *elf_image)
12{
13    return (Elf32_Ehdr *) elf_image;
14}
15
16/**
17 * elf_get_pht - Returns a pointer to the first entry in the PHT.
18 * @elf_image: pointer to the ELF file image in memory
19 */
20static inline Elf32_Phdr *elf_get_pht(void *elf_image)
21{
22    Elf32_Ehdr *elf_hdr = elf_get_header(elf_image);
23
24    return (Elf32_Phdr *) ((Elf32_Off) elf_hdr + elf_hdr->e_phoff);
25}
26
27//
28/**
29 * elf_get_ph - Returns the element with the given index in the PTH
30 * @elf_image: pointer to the ELF file image in memory
31 * @index: the index of the PHT entry to look for
32 */
33static inline Elf32_Phdr *elf_get_ph(void *elf_image, int index)
34{
35    Elf32_Phdr *elf_pht = elf_get_pht(elf_image);
36    Elf32_Ehdr *elf_hdr = elf_get_header(elf_image);
37
38    return (Elf32_Phdr *) ((Elf32_Off) elf_pht + index * elf_hdr->e_phentsize);
39}
40
41/**
42 * elf_hash - Returns the index in a SysV hash table for the symbol name.
43 * @name: the name of the symbol to look for
44 */
45extern unsigned long elf_hash(const unsigned char *name);
46
47/**
48 * elf_gnu_hash - Returns the index in a GNU hash table for the symbol name.
49 * @name: the name of the symbol to look for
50 */
51extern unsigned long elf_gnu_hash(const unsigned char *name);
52
53/**
54 * elf_malloc - Allocates memory to be used by ELF module contents.
55 * @memptr: pointer to a variable to hold the address of the allocated block.
56 * @alignment: alignment constraints of the block
57 * @size: the required size of the block
58 */
59extern int elf_malloc(void **memptr, size_t alignment, size_t size);
60
61/**
62 * elf_free - Releases memory previously allocated by elf_malloc.
63 * @memptr: the address of the allocated block
64 */
65extern void elf_free(void *memptr);
66
67#endif /*ELF_UTILS_H_ */
Note: See TracBrowser for help on using the repository browser.