MCPcopy Create free account
hub / github.com/coreboot/coreboot / elf_headers

Function elf_headers

util/cbfstool/elfheaders.c:581–612  ·  view source on GitHub ↗

Get the headers from the buffer. * Return -1 in the event of an error. * The section headers are optional; if NULL * is passed in for pshdr they won't be parsed. * We don't (yet) make payload parsing optional * because we've never seen a use case. */

Source from the content-addressed store, hash-verified

579 * because we've never seen a use case.
580 */
581int
582elf_headers(const struct buffer *pinput,
583 Elf64_Ehdr *ehdr,
584 Elf64_Phdr **pphdr,
585 Elf64_Shdr **pshdr)
586{
587 struct parsed_elf pelf;
588 int flags;
589
590 flags = ELF_PARSE_PHDR;
591
592 if (pshdr != NULL)
593 flags |= ELF_PARSE_SHDR;
594
595 if (parse_elf(pinput, &pelf, flags))
596 return -1;
597
598 /* Copy out the parsed elf header. */
599 memcpy(ehdr, &pelf.ehdr, sizeof(*ehdr));
600
601 *pphdr = calloc(ehdr->e_phnum, sizeof(Elf64_Phdr));
602 memcpy(*pphdr, pelf.phdr, ehdr->e_phnum * sizeof(Elf64_Phdr));
603
604 if (pshdr != NULL) {
605 *pshdr = calloc(ehdr->e_shnum, sizeof(Elf64_Shdr));
606 memcpy(*pshdr, pelf.shdr, ehdr->e_shnum * sizeof(Elf64_Shdr));
607 }
608
609 parsed_elf_destroy(&pelf);
610
611 return 0;
612}
613
614/* ELF Writing Support
615 *

Callers 2

parse_elf_to_payloadFunction · 0.85

Calls 4

parse_elfFunction · 0.85
parsed_elf_destroyFunction · 0.85
memcpyFunction · 0.50
callocFunction · 0.50

Tested by

no test coverage detected