Function report

Linux Kernel

v5.5.9

Brick Technologies Co., Ltd

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

Name:map a binary by direct mmap() of the individual PT_LOAD segments

Proto:static int elf_fdpic_map_file_by_direct_mmap(struct elf_fdpic_params *params, struct file *file, struct mm_struct *mm)

Type:int

Parameter:

TypeParameterName
struct elf_fdpic_params *params
struct file *file
struct mm_struct *mm
1013  load_addr = user address at which to map binary
1014  delta_vaddr = 0
1015  dvset = 0
1017  seg = segs
1020  phdr = copy of PT_PHDR table
1021  When loop < e_phnum cycle
1023  prot = 0
1025  If p_type != PT_LOAD Then Continue
1028  kdebug("[LOAD] va=%lx of=%lx fs=%lx ms=%lx", (unsignedlong)p_vaddr, (unsignedlong)p_offset, (unsignedlong)p_filesz, (unsignedlong)p_memsz)
1035  If p_flags & These constants define the permissions on sections in the programheader, p_flags. Then prot |= page can be read
1036  If p_flags & PF_W Then prot |= page can be written
1037  If p_flags & PF_X Then prot |= page can be executed
1039  flags = Changes are private | ETXTBSY
1040  If flags & T if this object is the executable Then flags |= mark it as an executable
1043  maddr = 0
1048  Break
1052  maddr = p_vaddr
1054  Break
1061  If Not dvset Then
1062  maddr = load_addr
1063  delta_vaddr = p_vaddr
1064  dvset = 1
1065  Else
1069  Break
1073  Break
1075  Default
1076  BUG()
1079  maddr &= PAGE_MASK
1082  disp = p_vaddr & ~PAGE_MASK
1083  maddr = vm_mmap(file, maddr, p_memsz + disp, prot, flags, p_offset - disp)
1086  kdebug("mmap[%d] <file> sz=%lx pr=%x fl=%x of=%lx --> %08lx", loop, p_memsz + disp, prot, flags, p_offset - disp, maddr)
1090  If IS_ERR_VALUE(maddr) Then Return maddr
1093  If (flags & PT_LOAD arrangement flags ) == PT_LOADs should be contiguous Then load_addr += align the pointer to the (next) page boundary (p_memsz + disp)
1097  core address to which mapped = maddr + disp
1098  VMA recorded in file = p_vaddr
1099  allocation size recorded in file = p_memsz
1102  If p_offset == 0 Then mapped ELF header user address = core address to which mapped
1107  If prot & page can be written && disp > 0 Then
1108  kdebug("clear[%d] ad=%lx sz=%lx", loop, maddr, disp)
1111  maddr += disp
1119  excess = p_memsz - p_filesz
1120  excess1 = PAGE_SIZE - ( maddr + p_filesz & ~PAGE_MASK)
1123  If excess > excess1 Then
1124  xaddr = maddr + p_filesz + excess1
1131  kdebug("mmap[%d] <anon> ad=%lx sz=%lx pr=%x fl=%x of=0 --> %08lx", loop, xaddr, excess - excess1, prot, flags, xmaddr)
1136  If xmaddr != xaddr Then Return -ENOMEM
1140  If prot & page can be written && excess1 > 0 Then
1141  kdebug("clear[%d] ad=%lx sz=%lx", loop, maddr + p_filesz, excess1)
1157  If mm Then
1158  If p_flags & PF_X Then
1159  If Not start_code Then
1160  start_code = maddr
1161  end_code = maddr + p_memsz
1163  Else if Not start_data Then
1164  start_data = maddr
1165  end_data = maddr + p_memsz
1169  seg++
1172  Return 0
Caller
NameDescribe
elf_fdpic_map_fileload the appropriate binary image (executable or interpreter) into memory* - we assume no MMU is available* - if no other PIC bits are set in params->hdr->e_flags* - we assume that the LOADable segments in the binary are independently relocatable* - we