Function report

Linux Kernel

v5.5.9

Brick Technologies Co., Ltd

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

Name:load_flat_file

Proto:static int load_flat_file(struct linux_binprm *bprm, struct lib_info *libinfo, int id, unsigned long *extra_stack)

Type:int

Parameter:

TypeParameterName
struct linux_binprm *bprm
struct lib_info *libinfo
intid
unsigned long *extra_stack
432  __user * reloc
433  __user * rp
440  hdr = buf
442  text_len = ntohl(Offset of data segment from beginning offile )
443  data_len = ntohl(Offset of end of data segment from beginningof file ) - ntohl(Offset of data segment from beginning offile )
444  bss_len = ntohl(Offset of end of bss segment from beginningof file ) - ntohl(Offset of end of data segment from beginningof file )
445  stack_len = ntohl(Size of stack, in bytes )
446  If extra_stack Then
447  stack_len += extra_stack
448  extra_stack = stack_len
450  relocs = ntohl(Number of relocation records )
451  flags = ntohl(flags)
452  rev = ntohl(version (as above) )
453  full_data = data_len + relocs * sizeof(unsignedlong)
455  If strncmp(magic, "bFLT", 4) Then
463  ret = -ENOEXEC
464  Go to err
467  If flags & utput useful kernel trace for debugging Then pr_info("Loading file: %s\n", filename)
495  If rev != FLAT_VERSION Then
496  pr_err("bad flat file version 0x%x (supported 0x%lx)\n", rev, FLAT_VERSION)
498  ret = -ENOEXEC
499  Go to err
508  If ( text_len | data_len | bss_len | stack_len | full_data) >> 28 Then
509  pr_err("bad header\n")
510  ret = -ENOEXEC
511  Go to err
515  If flags & (all but the header is compressed | ly data/relocs are compressed (for XIP) ) Then
516  pr_err("Support for ZFLAT executables is not enabled.\n")
517  ret = -ENOEXEC
518  Go to err
527  rlim = rlimit(RLIMIT_DATA)
528  If rlim >= RLIM_INFINITY Then rlim = ~0
530  If data_len + bss_len > rlim Then
531  ret = -ENOMEM
532  Go to err
536  If id == 0 Then
537  ret = Calling this is the point of no return. None of the failures will be* seen by userspace since either the process is already taking a fatal* signal (via de_thread() or coredump), or will have SEGV raised
538  If ret Then Go to err
542  Change personality of the currently running process.(PER_LINUX_32BIT)
543  setup_new_exec(bprm)
549  extra = max_t - return maximum of two values, using the specified type*@type: data type to use*@x: first value*@y: second value(unsignedlong, bss_len + stack_len, relocs * sizeof(unsignedlong))
557  If Not IS_ENABLED(CONFIG_FOO) evaluates to 1 if CONFIG_FOO is set to 'y' or 'm',* 0 otherwise.(CONFIG_MMU) && Not (flags & (load program entirely into RAM | all but the header is compressed )) Then
562  pr_debug("ROM mapping of file (we hope)\n")
564  textpos = vm_mmap(file, 0, text_len, page can be read | page can be executed , Changes are private | mark it as an executable , 0)
566  If Not textpos || IS_ERR_VALUE(textpos) Then
567  ret = textpos
568  If Not textpos Then ret = -ENOMEM
570  pr_err("Unable to mmap process text, errno %d\n", ret)
571  Go to err
574  len = data_len + extra
575  len = align the pointer to the (next) page boundary (len)
576  realdatastart = vm_mmap(NULL, 0, len, page can be read | page can be written | page can be executed , Changes are private , 0)
579  If realdatastart == 0 || IS_ERR_VALUE(realdatastart) Then
580  ret = realdatastart
581  If Not realdatastart Then ret = -ENOMEM
583  pr_err("Unable to allocate RAM for process data, errno %d\n", ret)
586  Go to err
588  datapos = @a is a power of 2 value (realdatastart, User data (data section and bss) needs to be aligned.* We pick 0x20 here because it is the max value elf2flt has always* used in producing FLAT files, and because it seems to be large* enough to make all the gcc alignment related tests happy.)
590  pr_debug("Allocated data+bss+stack (%u bytes): %lx\n", data_len + bss_len + stack_len, datapos)
604  If IS_ERR_VALUE(result) Then
605  ret = result
606  pr_err("Unable to read data+bss, errno %d\n", ret)
609  Go to err
612  reloc * __user = datapos + ntohl(Offset of relocation records from beginning offile ) - text_len
614  memp = realdatastart
615  memp_size = len
616  Else
618  len = text_len + data_len + extra
619  len = align the pointer to the (next) page boundary (len)
620  textpos = vm_mmap(NULL, 0, len, page can be read | page can be executed | page can be written , Changes are private , 0)
623  If Not textpos || IS_ERR_VALUE(textpos) Then
624  ret = textpos
625  If Not textpos Then ret = -ENOMEM
627  pr_err("Unable to allocate RAM for process text/data, errno %d\n", ret)
629  Go to err
632  realdatastart = textpos + ntohl(Offset of data segment from beginning offile )
633  datapos = @a is a power of 2 value (realdatastart, User data (data section and bss) needs to be aligned.* We pick 0x20 here because it is the max value elf2flt has always* used in producing FLAT files, and because it seems to be large* enough to make all the gcc alignment related tests happy.)
635  reloc * __user = datapos + ntohl(Offset of relocation records from beginning offile ) - text_len
637  memp = textpos
638  memp_size = len
705  If IS_ERR_VALUE(result) Then
706  ret = result
707  pr_err("Unable to read code+data+bss, errno %d\n", ret)
709  Go to err
713  start_code = textpos + sizeof(structflat_hdr)
714  end_code = textpos + text_len
715  text_len -= sizeof(structflat_hdr)
718  If id == 0 Then
719  start_code = start_code
720  end_code = end_code
721  start_data = datapos
722  end_data = datapos + data_len
730  start_brk = datapos + data_len + bss_len
731  brk = start_brk + 3 & ~3
737  If flags & utput useful kernel trace for debugging Then
738  pr_info("Mapping is %lx, Entry point is %x, data_start is %x\n", textpos, 0x00ffffff & ntohl(Offset of first executable instructionwith text segment from beginning of file ), ntohl(Offset of data segment from beginning offile ))
740  pr_info("%s %s: TEXT=%lx-%lx DATA=%lx-%lx BSS=%lx-%lx\n", id ? "Lib" : "Load", filename, start_code, end_code, datapos, datapos + data_len, datapos + data_len, (datapos + data_len + bss_len + 3) & ~3)
747  Start of text segment = start_code
748  Start of data segment = datapos
749  End of data segment = datapos + data_len + bss_len
750  Length of text segment = text_len
751  Has this library been loaded? = 1
752  Start address for this module = (0x00ffffff & ntohl(Offset of first executable instructionwith text segment from beginning of file )) + textpos
753  When this one was compiled = ntohl(When the program/library was built )
767  If flags & program is PIC with GOT Then
768  cycle
772  If rp_val == 0xffffffff Then Break
774  If rp_val Then
775  addr = calc_reloc(rp_val, libinfo, id, 0)
777  ret = -ENOEXEC
778  Go to err
797  If rev > While it would be nice to keep this header clean, users of older* tools still need this support in the kernel. So this section is* purely for compatibility with old tool chains.* DO NOT make changes or enhancements to the old format please, just work Then
798  When i < relocs cycle
809  relval = ntohl(tmp)
811  rp = calc_reloc(addr, libinfo, id, 1)
813  ret = -ENOEXEC
814  Go to err
822  If addr != 0 Then
857  flush_icache_range(start_code, end_code)
860  If lear_user - Zero a block of memory in user space.*@to: Destination address, in user space.*@n: Number of bytes to zero.* Zero a block of memory in user space.* Return: number of bytes that could not be cleared.* On success, this will be zero. Then Return -EFAULT
866  Return 0
867  err :
868  Return ret
Caller
NameDescribe
load_flat_binaryThese are the functions used to load flat style executables and shared* libraries. There is no binary dependent code anywhere else.