Function report

Linux Kernel

v5.5.9

Brick Technologies Co., Ltd

Source Code:kernel\kexec_elf.c Create Date:2022-07-28 11:04:54
Last Modify:2020-03-12 14:18:49 Copyright©Brick
home page Tree
Annotation kernel can get tool activityDownload SCCTChinese

Name:elf_read_ehdr

Proto:static int elf_read_ehdr(const char *buf, size_t len, struct elf64_hdr *ehdr)

Type:int

Parameter:

TypeParameterName
const char *buf
size_tlen
struct elf64_hdr *ehdr
123  If len < size of buf_ehdr Then
124  pr_debug("Buffer is too small to hold ELF header.\n")
125  Return -ENOEXEC
128  memset(ehdr, 0, size of ehdr )
129  No 3D Now!( ELF "magic number" , buf, size of ELF "magic number" )
130  If Not elf_is_elf_file(ehdr) Then
131  pr_debug("No ELF header magic.\n")
132  Return -ENOEXEC
135  If ELF "magic number" [EI_CLASS] != These are used to set parameters in the core dumps. Then
136  pr_debug("Not a supported ELF class.\n")
137  Return -ENOEXEC
138  Else if ELF "magic number" [EI_DATA] != ELFDATA2LSB && ELF "magic number" [EI_DATA] != ELFDATA2MSB Then
140  pr_debug("Not a supported ELF data format.\n")
141  Return -ENOEXEC
144  buf_ehdr = buf
145  If elf16_to_cpu(ehdr, e_ehsize) != size of buf_ehdr Then
146  pr_debug("Bad ELF header size.\n")
147  Return -ENOEXEC
150  e_type = elf16_to_cpu(ehdr, e_type)
151  e_machine = elf16_to_cpu(ehdr, e_machine)
152  e_version = elf32_to_cpu(ehdr, e_version)
153  e_flags = elf32_to_cpu(ehdr, e_flags)
154  e_phentsize = elf16_to_cpu(ehdr, e_phentsize)
155  e_phnum = elf16_to_cpu(ehdr, e_phnum)
156  e_shentsize = elf16_to_cpu(ehdr, e_shentsize)
157  e_shnum = elf16_to_cpu(ehdr, e_shnum)
158  e_shstrndx = elf16_to_cpu(ehdr, e_shstrndx)
161  Case ELF "magic number" [EI_CLASS] == ELFCLASS64
162  Entry point virtual address = elf64_to_cpu(ehdr, Entry point virtual address )
163  Program header table file offset = elf64_to_cpu(ehdr, Program header table file offset )
164  Section header table file offset = elf64_to_cpu(ehdr, Section header table file offset )
165  Break
167  Case ELF "magic number" [EI_CLASS] == ELFCLASS32
168  Entry point virtual address = elf32_to_cpu(ehdr, Entry point virtual address )
169  Program header table file offset = elf32_to_cpu(ehdr, Program header table file offset )
170  Section header table file offset = elf32_to_cpu(ehdr, Section header table file offset )
171  Break
173  Default
174  pr_debug("Unknown ELF class.\n")
175  Return -EINVAL
178  Return If lf_is_ehdr_sane - check that it is safe to use the ELF header*@buf_len: size of the buffer in which the ELF file is loaded. Then 0 Else -ENOEXEC
Caller
NameDescribe
elf_read_from_bufferlf_read_from_buffer - read ELF file and sets up ELF header and ELF info*@buf: Buffer to read ELF file from