Lines Matching refs:elf

0 /* elf.c - load ELF files */
21 #include <grub/elf.h>
32 grub_elf_check_header (grub_elf_t elf)
34 Elf32_Ehdr *e = &elf->ehdr.ehdr32;
48 grub_elf_close (grub_elf_t elf)
50 grub_file_t file = elf->file;
52 grub_free (elf->phdrs);
53 grub_free (elf);
64 grub_elf_t elf;
66 elf = grub_zalloc (sizeof (*elf));
67 if (! elf)
70 elf->file = file;
72 if (grub_file_seek (elf->file, 0) == (grub_off_t) -1)
75 if (grub_file_read (elf->file, &elf->ehdr, sizeof (elf->ehdr))
76 != sizeof (elf->ehdr))
83 if (grub_elf_check_header (elf))
86 return elf;
89 grub_free (elf->phdrs);
90 grub_free (elf);
98 grub_elf_t elf;
104 elf = grub_elf_file (file);
105 if (! elf)
108 return elf;
116 grub_elf_is_elf32 (grub_elf_t elf)
118 return elf->ehdr.ehdr32.e_ident[EI_CLASS] == ELFCLASS32;
122 grub_elf32_load_phdrs (grub_elf_t elf)
126 phdrs_size = elf->ehdr.ehdr32.e_phnum * elf->ehdr.ehdr32.e_phentsize;
128 grub_dprintf ("elf", "Loading program headers at 0x%llx, size 0x%lx.\n",
129 (unsigned long long) elf->ehdr.ehdr32.e_phoff,
132 elf->phdrs = grub_malloc (phdrs_size);
133 if (! elf->phdrs)
136 if ((grub_file_seek (elf->file, elf->ehdr.ehdr32.e_phoff) == (grub_off_t) -1)
137 || (grub_file_read (elf->file, elf->phdrs, phdrs_size) != phdrs_size))
147 grub_elf32_phdr_iterate (grub_elf_t elf,
154 if (! elf->phdrs)
155 if (grub_elf32_load_phdrs (elf))
157 phdrs = elf->phdrs;
159 for (i = 0; i < elf->ehdr.ehdr32.e_phnum; i++)
162 grub_dprintf ("elf",
169 if (hook (elf, phdr, hook_arg))
178 grub_elf32_size (grub_elf_t elf, Elf32_Addr *base, grub_uint32_t *max_align)
205 grub_elf32_phdr_iterate (elf, calcsize, 0);
239 auto int NESTED_FUNC_ATTR grub_elf32_load_segment (grub_elf_t elf, Elf32_Phdr *phdr, void *hook);
240 int NESTED_FUNC_ATTR grub_elf32_load_segment (grub_elf_t elf, Elf32_Phdr *phdr, void *hook)
256 grub_dprintf ("elf", "Loading segment at 0x%llx, size 0x%llx\n",
260 if (grub_file_seek (elf->file, phdr->p_offset) == (grub_off_t) -1)
270 read = grub_file_read (elf->file, (void *) load_addr, phdr->p_filesz);
306 grub_elf_is_elf64 (grub_elf_t elf)
308 return elf->ehdr.ehdr64.e_ident[EI_CLASS] == ELFCLASS64;
312 grub_elf64_load_phdrs (grub_elf_t elf)
316 phdrs_size = elf->ehdr.ehdr64.e_phnum * elf->ehdr.ehdr64.e_phentsize;
318 grub_dprintf ("elf", "Loading program headers at 0x%llx, size 0x%lx.\n",
319 (unsigned long long) elf->ehdr.ehdr64.e_phoff,
322 elf->phdrs = grub_malloc (phdrs_size);
323 if (! elf->phdrs)
326 if ((grub_file_seek (elf->file, elf->ehdr.ehdr64.e_phoff) == (grub_off_t) -1)
327 || (grub_file_read (elf->file, elf->phdrs, phdrs_size) != phdrs_size))
337 grub_elf64_phdr_iterate (grub_elf_t elf,
344 if (! elf->phdrs)
345 if (grub_elf64_load_phdrs (elf))
347 phdrs = elf->phdrs;
349 for (i = 0; i < elf->ehdr.ehdr64.e_phnum; i++)
352 grub_dprintf ("elf",
359 if (hook (elf, phdr, hook_arg))
368 grub_elf64_size (grub_elf_t elf, Elf64_Addr *base, grub_uint64_t *max_align)
395 grub_elf64_phdr_iterate (elf, calcsize, 0);
429 auto int NESTED_FUNC_ATTR grub_elf64_load_segment (grub_elf_t elf, Elf64_Phdr *phdr,
431 int NESTED_FUNC_ATTR grub_elf64_load_segment (grub_elf_t elf, Elf64_Phdr *phdr, void *hook)
447 grub_dprintf ("elf", "Loading segment at 0x%llx, size 0x%llx\n",
451 if (grub_file_seek (elf->file, phdr->p_offset) == (grub_off_t) -1)
461 read = grub_file_read (elf->file, (void *) load_addr, phdr->p_filesz);