elfload.h 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /*
  2. * GRUB -- GRand Unified Bootloader
  3. * Copyright (C) 2003, 2004, 2005, 2006, 2007 Free Software Foundation, Inc.
  4. *
  5. * GRUB is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * GRUB is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #ifndef GRUB_ELFLOAD_HEADER
  19. #define GRUB_ELFLOAD_HEADER 1
  20. #include <grub/err.h>
  21. #include <grub/elf.h>
  22. #include <grub/file.h>
  23. #include <grub/symbol.h>
  24. #include <grub/types.h>
  25. struct grub_elf_file
  26. {
  27. grub_file_t file;
  28. union {
  29. Elf64_Ehdr ehdr64;
  30. Elf32_Ehdr ehdr32;
  31. } ehdr;
  32. void *phdrs;
  33. char *filename;
  34. };
  35. typedef struct grub_elf_file *grub_elf_t;
  36. typedef int (*grub_elf32_phdr_iterate_hook_t)
  37. (grub_elf_t elf, Elf32_Phdr *phdr, void *arg);
  38. typedef int (*grub_elf64_phdr_iterate_hook_t)
  39. (grub_elf_t elf, Elf64_Phdr *phdr, void *arg);
  40. grub_elf_t grub_elf_open (const char *, enum grub_file_type type);
  41. grub_elf_t grub_elf_file (grub_file_t file, const char *filename);
  42. grub_err_t grub_elf_close (grub_elf_t);
  43. int grub_elf_is_elf32 (grub_elf_t);
  44. grub_size_t grub_elf32_size (grub_elf_t,
  45. Elf32_Addr *, grub_uint32_t *);
  46. enum grub_elf_load_flags
  47. {
  48. GRUB_ELF_LOAD_FLAGS_NONE = 0,
  49. GRUB_ELF_LOAD_FLAGS_LOAD_PT_DYNAMIC = 1,
  50. GRUB_ELF_LOAD_FLAGS_BITS = 6,
  51. GRUB_ELF_LOAD_FLAGS_ALL_BITS = 0,
  52. GRUB_ELF_LOAD_FLAGS_28BITS = 2,
  53. GRUB_ELF_LOAD_FLAGS_30BITS = 4,
  54. GRUB_ELF_LOAD_FLAGS_62BITS = 6,
  55. };
  56. grub_err_t grub_elf32_load (grub_elf_t, const char *filename,
  57. void *load_offset, enum grub_elf_load_flags flags, grub_addr_t *,
  58. grub_size_t *);
  59. int grub_elf_is_elf64 (grub_elf_t);
  60. grub_size_t grub_elf64_size (grub_elf_t,
  61. Elf64_Addr *, grub_uint64_t *);
  62. grub_err_t grub_elf64_load (grub_elf_t, const char *filename,
  63. void *load_offset, enum grub_elf_load_flags flags, grub_addr_t *,
  64. grub_size_t *);
  65. grub_err_t grub_elf32_load_phdrs (grub_elf_t elf);
  66. grub_err_t grub_elf64_load_phdrs (grub_elf_t elf);
  67. #define FOR_ELF32_PHDRS(elf, phdr) \
  68. for (grub_elf32_load_phdrs (elf), phdr = elf->phdrs; \
  69. phdr && phdr < (Elf32_Phdr *) elf->phdrs + elf->ehdr.ehdr32.e_phnum; phdr++)
  70. #define FOR_ELF64_PHDRS(elf, phdr) \
  71. for (grub_elf64_load_phdrs (elf), phdr = elf->phdrs; \
  72. phdr && phdr < (Elf64_Phdr *) elf->phdrs + elf->ehdr.ehdr64.e_phnum; phdr++)
  73. #endif /* ! GRUB_ELFLOAD_HEADER */