fs/binfmt_elf_fdpic.c
Source file repositories/reference/linux-study-clean/fs/binfmt_elf_fdpic.c
File Facts
- System
- Linux kernel
- Corpus path
fs/binfmt_elf_fdpic.c- Extension
.c- Size
- 44849 bytes
- Lines
- 1668
- Domain
- Core OS
- Bucket
- VFS And Filesystem Core
- Inferred role
- Core OS: exported/initcall integration point
- Status
- integration implementation candidate
Why This File Exists
Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- Touches user memory; correctness depends on fault-safe copying and privilege boundary handling.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/module.hlinux/fs.hlinux/stat.hlinux/sched.hlinux/sched/coredump.hlinux/sched/task_stack.hlinux/sched/cputime.hlinux/mm.hlinux/mman.hlinux/errno.hlinux/signal.hlinux/binfmts.hlinux/string.hlinux/file.hlinux/fcntl.hlinux/slab.hlinux/pagemap.hlinux/security.hlinux/highmem.hlinux/highuid.hlinux/personality.hlinux/ptrace.hlinux/init.hlinux/elf.hlinux/elf-fdpic.hlinux/elfcore.hlinux/coredump.hlinux/dax.hlinux/regset.hlinux/uaccess.hasm/param.h
Detected Declarations
struct elf_prstatus_fdpicstruct memelfnotestruct elf_thread_statusfunction init_elf_fdpic_binfmtfunction exit_elf_fdpic_binfmtfunction is_elffunction is_constdispfunction elf_fdpic_fetch_phdrsfunction load_elf_fdpic_binaryfunction ELF_BASE_PLATFORMfunction imagefunction elf_fdpic_map_file_constdisp_on_uclinuxfunction mmapfunction notesizefunction writenotefunction fill_elf_fdpic_headerfunction fill_elf_note_phdrfunction __fill_notefunction fill_prstatusfunction fill_psinfofunction fill_extnum_infofunction elf_fdpic_dump_segmentsfunction elf_fdpic_core_dumpmodule init init_elf_fdpic_binfmt
Annotated Snippet
core_initcall(init_elf_fdpic_binfmt);
module_exit(exit_elf_fdpic_binfmt);
static int is_elf(struct elfhdr *hdr, struct file *file)
{
if (memcmp(hdr->e_ident, ELFMAG, SELFMAG) != 0)
return 0;
if (hdr->e_type != ET_EXEC && hdr->e_type != ET_DYN)
return 0;
if (!elf_check_arch(hdr))
return 0;
if (!can_mmap_file(file))
return 0;
return 1;
}
#ifndef elf_check_fdpic
#define elf_check_fdpic(x) 0
#endif
#ifndef elf_check_const_displacement
#define elf_check_const_displacement(x) 0
#endif
static int is_constdisp(struct elfhdr *hdr)
{
if (!elf_check_fdpic(hdr))
return 1;
if (elf_check_const_displacement(hdr))
return 1;
return 0;
}
/*****************************************************************************/
/*
* read the program headers table into memory
*/
static int elf_fdpic_fetch_phdrs(struct elf_fdpic_params *params,
struct file *file)
{
struct elf_phdr *phdr;
unsigned long size;
int retval, loop;
loff_t pos = params->hdr.e_phoff;
if (params->hdr.e_phentsize != sizeof(struct elf_phdr))
return -ENOMEM;
if (params->hdr.e_phnum > 65536U / sizeof(struct elf_phdr))
return -ENOMEM;
size = params->hdr.e_phnum * sizeof(struct elf_phdr);
params->phdrs = kmalloc(size, GFP_KERNEL);
if (!params->phdrs)
return -ENOMEM;
retval = kernel_read(file, params->phdrs, size, &pos);
if (unlikely(retval != size))
return retval < 0 ? retval : -ENOEXEC;
/* determine stack size for this binary */
phdr = params->phdrs;
for (loop = 0; loop < params->hdr.e_phnum; loop++, phdr++) {
if (phdr->p_type != PT_GNU_STACK)
continue;
if (phdr->p_flags & PF_X)
params->flags |= ELF_FDPIC_FLAG_EXEC_STACK;
else
params->flags |= ELF_FDPIC_FLAG_NOEXEC_STACK;
params->stack_size = phdr->p_memsz;
break;
}
return 0;
}
/*****************************************************************************/
/*
* load an fdpic binary into various bits of memory
*/
static int load_elf_fdpic_binary(struct linux_binprm *bprm)
{
struct elf_fdpic_params exec_params, interp_params;
struct pt_regs *regs = current_pt_regs();
struct elf_phdr *phdr;
unsigned long stack_size, entryaddr;
#ifdef ELF_FDPIC_PLAT_INIT
unsigned long dynaddr;
#endif
Annotation
- Immediate include surface: `linux/module.h`, `linux/fs.h`, `linux/stat.h`, `linux/sched.h`, `linux/sched/coredump.h`, `linux/sched/task_stack.h`, `linux/sched/cputime.h`, `linux/mm.h`.
- Detected declarations: `struct elf_prstatus_fdpic`, `struct memelfnote`, `struct elf_thread_status`, `function init_elf_fdpic_binfmt`, `function exit_elf_fdpic_binfmt`, `function is_elf`, `function is_constdisp`, `function elf_fdpic_fetch_phdrs`, `function load_elf_fdpic_binary`, `function ELF_BASE_PLATFORM`.
- Atlas domain: Core OS / VFS And Filesystem Core.
- Implementation status: integration implementation candidate.
- This snippet crosses the user/kernel memory boundary; validate fault handling and access checks before translating the pattern.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.