2 * linux/fs/binfmt_elf.c
4 * These are the functions used to load ELF format executables as used
5 * on SVr4 machines. Information on the format may be found in the book
6 * "UNIX SYSTEM V RELEASE 4 Programmers Guide: Ansi C and Programming Support
9 * Copyright 1993, 1994: Eric Youngdale (ericy@cais.com).
12 #include <linux/module.h>
13 #include <linux/kernel.h>
15 #include <linux/stat.h>
16 #include <linux/time.h>
18 #include <linux/mman.h>
19 #include <linux/a.out.h>
20 #include <linux/errno.h>
21 #include <linux/signal.h>
22 #include <linux/binfmts.h>
23 #include <linux/string.h>
24 #include <linux/file.h>
25 #include <linux/fcntl.h>
26 #include <linux/ptrace.h>
27 #include <linux/slab.h>
28 #include <linux/shm.h>
29 #include <linux/personality.h>
30 #include <linux/elfcore.h>
31 #include <linux/init.h>
32 #include <linux/highuid.h>
33 #include <linux/smp.h>
34 #include <linux/smp_lock.h>
35 #include <linux/compiler.h>
36 #include <linux/highmem.h>
37 #include <linux/pagemap.h>
38 #include <linux/security.h>
39 #include <linux/syscalls.h>
40 #include <linux/vs_memory.h>
42 #include <asm/uaccess.h>
43 #include <asm/param.h>
46 #include <linux/elf.h>
48 static int load_elf_binary(struct linux_binprm * bprm, struct pt_regs * regs);
49 static int load_elf_library(struct file*);
50 static unsigned long elf_map (struct file *, unsigned long, struct elf_phdr *, int, int);
51 extern int dump_fpu (struct pt_regs *, elf_fpregset_t *);
54 #define elf_addr_t unsigned long
58 * If we don't support core dumping, then supply a NULL so we
61 #ifdef USE_ELF_CORE_DUMP
62 static int elf_core_dump(long signr, struct pt_regs * regs, struct file * file);
64 #define elf_core_dump NULL
67 #if ELF_EXEC_PAGESIZE > PAGE_SIZE
68 # define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
70 # define ELF_MIN_ALIGN PAGE_SIZE
73 #ifndef ELF_CORE_EFLAGS
74 #define ELF_CORE_EFLAGS 0
77 #define ELF_PAGESTART(_v) ((_v) & ~(unsigned long)(ELF_MIN_ALIGN-1))
78 #define ELF_PAGEOFFSET(_v) ((_v) & (ELF_MIN_ALIGN-1))
79 #define ELF_PAGEALIGN(_v) (((_v) + ELF_MIN_ALIGN - 1) & ~(ELF_MIN_ALIGN - 1))
81 static struct linux_binfmt elf_format = {
82 .module = THIS_MODULE,
83 .load_binary = load_elf_binary,
84 .load_shlib = load_elf_library,
85 .core_dump = elf_core_dump,
86 .min_coredump = ELF_EXEC_PAGESIZE
89 #define BAD_ADDR(x) ((unsigned long)(x) > TASK_SIZE)
91 static int set_brk(unsigned long start, unsigned long end)
93 start = ELF_PAGEALIGN(start);
94 end = ELF_PAGEALIGN(end);
97 down_write(¤t->mm->mmap_sem);
98 addr = do_brk(start, end - start);
99 up_write(¤t->mm->mmap_sem);
103 current->mm->start_brk = current->mm->brk = end;
108 /* We need to explicitly zero any fractional pages
109 after the data section (i.e. bss). This would
110 contain the junk from the file that should not
114 static int padzero(unsigned long elf_bss)
118 nbyte = ELF_PAGEOFFSET(elf_bss);
120 nbyte = ELF_MIN_ALIGN - nbyte;
121 if (clear_user((void __user *) elf_bss, nbyte))
127 /* Let's use some macros to make this stack manipulation a litle clearer */
128 #ifdef CONFIG_STACK_GROWSUP
129 #define STACK_ADD(sp, items) ((elf_addr_t __user *)(sp) + (items))
130 #define STACK_ROUND(sp, items) \
131 ((15 + (unsigned long) ((sp) + (items))) &~ 15UL)
132 #define STACK_ALLOC(sp, len) ({ elf_addr_t __user *old_sp = (elf_addr_t __user *)sp; sp += len; old_sp; })
134 #define STACK_ADD(sp, items) ((elf_addr_t __user *)(sp) - (items))
135 #define STACK_ROUND(sp, items) \
136 (((unsigned long) (sp - items)) &~ 15UL)
137 #define STACK_ALLOC(sp, len) ({ sp -= len ; sp; })
141 create_elf_tables(struct linux_binprm *bprm, struct elfhdr * exec,
142 int interp_aout, unsigned long load_addr,
143 unsigned long interp_load_addr)
145 unsigned long p = bprm->p;
146 int argc = bprm->argc;
147 int envc = bprm->envc;
148 elf_addr_t __user *argv;
149 elf_addr_t __user *envp;
150 elf_addr_t __user *sp;
151 elf_addr_t __user *u_platform;
152 const char *k_platform = ELF_PLATFORM;
154 elf_addr_t *elf_info;
156 struct task_struct *tsk = current;
159 * If this architecture has a platform capability string, copy it
160 * to userspace. In some cases (Sparc), this info is impossible
161 * for userspace to get any other way, in others (i386) it is
167 size_t len = strlen(k_platform) + 1;
171 * In some cases (e.g. Hyper-Threading), we want to avoid L1
172 * evictions by the processes running on the same package. One
173 * thing we can do is to shuffle the initial stack for them.
175 * The conditionals here are unneeded, but kept in to make the
176 * code behaviour the same as pre change unless we have
177 * hyperthreaded processors. This should be cleaned up
181 if (smp_num_siblings > 1)
182 STACK_ALLOC(p, ((current->pid % 64) << 7));
184 u_platform = (elf_addr_t __user *)STACK_ALLOC(p, len);
185 if (__copy_to_user(u_platform, k_platform, len))
189 /* Create the ELF interpreter info */
190 elf_info = (elf_addr_t *) current->mm->saved_auxv;
191 #define NEW_AUX_ENT(id, val) \
192 do { elf_info[ei_index++] = id; elf_info[ei_index++] = val; } while (0)
196 * ARCH_DLINFO must come first so PPC can do its special alignment of
201 NEW_AUX_ENT(AT_HWCAP, ELF_HWCAP);
202 NEW_AUX_ENT(AT_PAGESZ, ELF_EXEC_PAGESIZE);
203 NEW_AUX_ENT(AT_CLKTCK, CLOCKS_PER_SEC);
204 NEW_AUX_ENT(AT_PHDR, load_addr + exec->e_phoff);
205 NEW_AUX_ENT(AT_PHENT, sizeof (struct elf_phdr));
206 NEW_AUX_ENT(AT_PHNUM, exec->e_phnum);
207 NEW_AUX_ENT(AT_BASE, interp_load_addr);
208 NEW_AUX_ENT(AT_FLAGS, 0);
209 NEW_AUX_ENT(AT_ENTRY, exec->e_entry);
210 NEW_AUX_ENT(AT_UID, (elf_addr_t) tsk->uid);
211 NEW_AUX_ENT(AT_EUID, (elf_addr_t) tsk->euid);
212 NEW_AUX_ENT(AT_GID, (elf_addr_t) tsk->gid);
213 NEW_AUX_ENT(AT_EGID, (elf_addr_t) tsk->egid);
214 NEW_AUX_ENT(AT_SECURE, (elf_addr_t) security_bprm_secureexec(bprm));
216 NEW_AUX_ENT(AT_PLATFORM, (elf_addr_t)(unsigned long)u_platform);
218 if (bprm->interp_flags & BINPRM_FLAGS_EXECFD) {
219 NEW_AUX_ENT(AT_EXECFD, (elf_addr_t) bprm->interp_data);
222 /* AT_NULL is zero; clear the rest too */
223 memset(&elf_info[ei_index], 0,
224 sizeof current->mm->saved_auxv - ei_index * sizeof elf_info[0]);
226 /* And advance past the AT_NULL entry. */
229 sp = STACK_ADD(p, ei_index);
231 items = (argc + 1) + (envc + 1);
233 items += 3; /* a.out interpreters require argv & envp too */
235 items += 1; /* ELF interpreters only put argc on the stack */
237 bprm->p = STACK_ROUND(sp, items);
239 /* Point sp at the lowest address on the stack */
240 #ifdef CONFIG_STACK_GROWSUP
241 sp = (elf_addr_t __user *)bprm->p - items - ei_index;
242 bprm->exec = (unsigned long) sp; /* XXX: PARISC HACK */
244 sp = (elf_addr_t __user *)bprm->p;
247 /* Now, let's put argc (and argv, envp if appropriate) on the stack */
248 if (__put_user(argc, sp++))
252 envp = argv + argc + 1;
253 __put_user((elf_addr_t)(unsigned long)argv, sp++);
254 __put_user((elf_addr_t)(unsigned long)envp, sp++);
257 envp = argv + argc + 1;
260 /* Populate argv and envp */
261 p = current->mm->arg_end = current->mm->arg_start;
264 __put_user((elf_addr_t)p, argv++);
265 len = strnlen_user((void __user *)p, PAGE_SIZE*MAX_ARG_PAGES);
266 if (!len || len > PAGE_SIZE*MAX_ARG_PAGES)
270 if (__put_user(0, argv))
272 current->mm->arg_end = current->mm->env_start = p;
275 __put_user((elf_addr_t)p, envp++);
276 len = strnlen_user((void __user *)p, PAGE_SIZE*MAX_ARG_PAGES);
277 if (!len || len > PAGE_SIZE*MAX_ARG_PAGES)
281 if (__put_user(0, envp))
283 current->mm->env_end = p;
285 /* Put the elf_info on the stack in the right place. */
286 sp = (elf_addr_t __user *)envp + 1;
287 if (copy_to_user(sp, elf_info, ei_index * sizeof(elf_addr_t)))
294 static unsigned long elf_map(struct file *filep, unsigned long addr,
295 struct elf_phdr *eppnt, int prot, int type)
297 unsigned long map_addr;
299 down_write(¤t->mm->mmap_sem);
300 map_addr = do_mmap(filep, ELF_PAGESTART(addr),
301 eppnt->p_filesz + ELF_PAGEOFFSET(eppnt->p_vaddr), prot, type,
302 eppnt->p_offset - ELF_PAGEOFFSET(eppnt->p_vaddr));
303 up_write(¤t->mm->mmap_sem);
307 #endif /* !elf_map */
309 /* This is much more generalized than the library routine read function,
310 so we keep this separate. Technically the library read function
311 is only provided so that we can read a.out libraries that have
314 static unsigned long load_elf_interp(struct elfhdr * interp_elf_ex,
315 struct file * interpreter,
316 unsigned long *interp_load_addr)
318 struct elf_phdr *elf_phdata;
319 struct elf_phdr *eppnt;
320 unsigned long load_addr = 0;
321 int load_addr_set = 0;
322 unsigned long last_bss = 0, elf_bss = 0;
323 unsigned long error = ~0UL;
326 /* First of all, some simple consistency checks */
327 if (interp_elf_ex->e_type != ET_EXEC &&
328 interp_elf_ex->e_type != ET_DYN)
330 if (!elf_check_arch(interp_elf_ex))
332 if (!interpreter->f_op || !interpreter->f_op->mmap)
336 * If the size of this structure has changed, then punt, since
337 * we will be doing the wrong thing.
339 if (interp_elf_ex->e_phentsize != sizeof(struct elf_phdr))
341 if (interp_elf_ex->e_phnum < 1 ||
342 interp_elf_ex->e_phnum > 65536U / sizeof(struct elf_phdr))
345 /* Now read in all of the header information */
347 size = sizeof(struct elf_phdr) * interp_elf_ex->e_phnum;
348 if (size > ELF_MIN_ALIGN)
350 elf_phdata = (struct elf_phdr *) kmalloc(size, GFP_KERNEL);
354 retval = kernel_read(interpreter,interp_elf_ex->e_phoff,(char *)elf_phdata,size);
356 if (retval != size) {
363 for (i=0; i<interp_elf_ex->e_phnum; i++, eppnt++) {
364 if (eppnt->p_type == PT_LOAD) {
365 int elf_type = MAP_PRIVATE | MAP_DENYWRITE;
367 unsigned long vaddr = 0;
368 unsigned long k, map_addr;
370 if (eppnt->p_flags & PF_R) elf_prot = PROT_READ;
371 if (eppnt->p_flags & PF_W) elf_prot |= PROT_WRITE;
372 if (eppnt->p_flags & PF_X) elf_prot |= PROT_EXEC;
373 vaddr = eppnt->p_vaddr;
374 if (interp_elf_ex->e_type == ET_EXEC || load_addr_set)
375 elf_type |= MAP_FIXED;
377 map_addr = elf_map(interpreter, load_addr + vaddr, eppnt, elf_prot, elf_type);
379 if (BAD_ADDR(map_addr))
382 if (!load_addr_set && interp_elf_ex->e_type == ET_DYN) {
383 load_addr = map_addr - ELF_PAGESTART(vaddr);
388 * Check to see if the section's size will overflow the
389 * allowed task size. Note that p_filesz must always be
390 * <= p_memsize so it is only necessary to check p_memsz.
392 k = load_addr + eppnt->p_vaddr;
393 if (k > TASK_SIZE || eppnt->p_filesz > eppnt->p_memsz ||
394 eppnt->p_memsz > TASK_SIZE || TASK_SIZE - eppnt->p_memsz < k) {
400 * Find the end of the file mapping for this phdr, and keep
401 * track of the largest address we see for this.
403 k = load_addr + eppnt->p_vaddr + eppnt->p_filesz;
408 * Do the same thing for the memory mapping - between
409 * elf_bss and last_bss is the bss section.
411 k = load_addr + eppnt->p_memsz + eppnt->p_vaddr;
418 * Now fill out the bss section. First pad the last page up
419 * to the page boundary, and then perform a mmap to make sure
420 * that there are zero-mapped pages up to and including the
423 if (padzero(elf_bss)) {
428 elf_bss = ELF_PAGESTART(elf_bss + ELF_MIN_ALIGN - 1); /* What we have mapped so far */
430 /* Map the last of the bss segment */
431 if (last_bss > elf_bss) {
432 down_write(¤t->mm->mmap_sem);
433 error = do_brk(elf_bss, last_bss - elf_bss);
434 up_write(¤t->mm->mmap_sem);
439 *interp_load_addr = load_addr;
440 error = ((unsigned long) interp_elf_ex->e_entry) + load_addr;
448 static unsigned long load_aout_interp(struct exec * interp_ex,
449 struct file * interpreter)
451 unsigned long text_data, elf_entry = ~0UL;
455 current->mm->end_code = interp_ex->a_text;
456 text_data = interp_ex->a_text + interp_ex->a_data;
457 current->mm->end_data = text_data;
458 current->mm->brk = interp_ex->a_bss + text_data;
460 switch (N_MAGIC(*interp_ex)) {
463 addr = (char __user *)0;
467 offset = N_TXTOFF(*interp_ex);
468 addr = (char __user *) N_TXTADDR(*interp_ex);
474 down_write(¤t->mm->mmap_sem);
475 do_brk(0, text_data);
476 up_write(¤t->mm->mmap_sem);
477 if (!interpreter->f_op || !interpreter->f_op->read)
479 if (interpreter->f_op->read(interpreter, addr, text_data, &offset) < 0)
481 flush_icache_range((unsigned long)addr,
482 (unsigned long)addr + text_data);
485 down_write(¤t->mm->mmap_sem);
486 do_brk(ELF_PAGESTART(text_data + ELF_MIN_ALIGN - 1),
488 up_write(¤t->mm->mmap_sem);
489 elf_entry = interp_ex->a_entry;
496 * These are the functions used to load ELF style executables and shared
497 * libraries. There is no binary dependent code anywhere else.
500 #define INTERPRETER_NONE 0
501 #define INTERPRETER_AOUT 1
502 #define INTERPRETER_ELF 2
505 static int load_elf_binary(struct linux_binprm * bprm, struct pt_regs * regs)
507 struct file *interpreter = NULL; /* to shut gcc up */
508 unsigned long load_addr = 0, load_bias = 0;
509 int load_addr_set = 0;
510 char * elf_interpreter = NULL;
511 unsigned int interpreter_type = INTERPRETER_NONE;
512 unsigned char ibcs2_interpreter = 0;
514 struct elf_phdr * elf_ppnt, *elf_phdata;
515 unsigned long elf_bss, elf_brk;
519 unsigned long elf_entry, interp_load_addr = 0;
520 unsigned long start_code, end_code, start_data, end_data;
521 unsigned long reloc_func_desc = 0;
522 char passed_fileno[6];
523 struct files_struct *files;
524 int have_pt_gnu_stack, executable_stack = EXSTACK_DEFAULT;
525 unsigned long def_flags = 0;
527 struct elfhdr elf_ex;
528 struct elfhdr interp_elf_ex;
529 struct exec interp_ex;
532 loc = kmalloc(sizeof(*loc), GFP_KERNEL);
538 /* Get the exec-header */
539 loc->elf_ex = *((struct elfhdr *) bprm->buf);
542 /* First of all, some simple consistency checks */
543 if (memcmp(loc->elf_ex.e_ident, ELFMAG, SELFMAG) != 0)
546 if (loc->elf_ex.e_type != ET_EXEC && loc->elf_ex.e_type != ET_DYN)
548 if (!elf_check_arch(&loc->elf_ex))
550 if (!bprm->file->f_op||!bprm->file->f_op->mmap)
553 /* Now read in all of the header information */
555 if (loc->elf_ex.e_phentsize != sizeof(struct elf_phdr))
557 if (loc->elf_ex.e_phnum < 1 ||
558 loc->elf_ex.e_phnum > 65536U / sizeof(struct elf_phdr))
560 size = loc->elf_ex.e_phnum * sizeof(struct elf_phdr);
562 elf_phdata = (struct elf_phdr *) kmalloc(size, GFP_KERNEL);
566 retval = kernel_read(bprm->file, loc->elf_ex.e_phoff, (char *) elf_phdata, size);
567 if (retval != size) {
573 files = current->files; /* Refcounted so ok */
574 retval = unshare_files();
577 if (files == current->files) {
578 put_files_struct(files);
582 /* exec will make our files private anyway, but for the a.out
583 loader stuff we need to do it earlier */
585 retval = get_unused_fd();
588 get_file(bprm->file);
589 fd_install(elf_exec_fileno = retval, bprm->file);
591 elf_ppnt = elf_phdata;
600 for (i = 0; i < loc->elf_ex.e_phnum; i++) {
601 if (elf_ppnt->p_type == PT_INTERP) {
602 /* This is the program interpreter used for
603 * shared libraries - for now assume that this
604 * is an a.out format binary
608 if (elf_ppnt->p_filesz > PATH_MAX ||
609 elf_ppnt->p_filesz < 2)
613 elf_interpreter = (char *) kmalloc(elf_ppnt->p_filesz,
615 if (!elf_interpreter)
618 retval = kernel_read(bprm->file, elf_ppnt->p_offset,
621 if (retval != elf_ppnt->p_filesz) {
624 goto out_free_interp;
626 /* make sure path is NULL terminated */
628 if (elf_interpreter[elf_ppnt->p_filesz - 1] != '\0')
629 goto out_free_interp;
631 /* If the program interpreter is one of these two,
632 * then assume an iBCS2 image. Otherwise assume
633 * a native linux image.
635 if (strcmp(elf_interpreter,"/usr/lib/libc.so.1") == 0 ||
636 strcmp(elf_interpreter,"/usr/lib/ld.so.1") == 0)
637 ibcs2_interpreter = 1;
640 * The early SET_PERSONALITY here is so that the lookup
641 * for the interpreter happens in the namespace of the
642 * to-be-execed image. SET_PERSONALITY can select an
645 * However, SET_PERSONALITY is NOT allowed to switch
646 * this task into the new images's memory mapping
647 * policy - that is, TASK_SIZE must still evaluate to
648 * that which is appropriate to the execing application.
649 * This is because exit_mmap() needs to have TASK_SIZE
650 * evaluate to the size of the old image.
652 * So if (say) a 64-bit application is execing a 32-bit
653 * application it is the architecture's responsibility
654 * to defer changing the value of TASK_SIZE until the
655 * switch really is going to happen - do this in
656 * flush_thread(). - akpm
658 SET_PERSONALITY(loc->elf_ex, ibcs2_interpreter);
660 interpreter = open_exec(elf_interpreter);
661 retval = PTR_ERR(interpreter);
662 if (IS_ERR(interpreter))
663 goto out_free_interp;
664 retval = kernel_read(interpreter, 0, bprm->buf, BINPRM_BUF_SIZE);
665 if (retval != BINPRM_BUF_SIZE) {
668 goto out_free_dentry;
671 /* Get the exec headers */
672 loc->interp_ex = *((struct exec *) bprm->buf);
673 loc->interp_elf_ex = *((struct elfhdr *) bprm->buf);
679 elf_ppnt = elf_phdata;
680 for (i = 0; i < loc->elf_ex.e_phnum; i++, elf_ppnt++)
681 if (elf_ppnt->p_type == PT_GNU_STACK) {
682 if (elf_ppnt->p_flags & PF_X)
683 executable_stack = EXSTACK_ENABLE_X;
685 executable_stack = EXSTACK_DISABLE_X;
688 have_pt_gnu_stack = (i < loc->elf_ex.e_phnum);
690 /* Some simple consistency checks for the interpreter */
691 if (elf_interpreter) {
692 interpreter_type = INTERPRETER_ELF | INTERPRETER_AOUT;
694 /* Now figure out which format our binary is */
695 if ((N_MAGIC(loc->interp_ex) != OMAGIC) &&
696 (N_MAGIC(loc->interp_ex) != ZMAGIC) &&
697 (N_MAGIC(loc->interp_ex) != QMAGIC))
698 interpreter_type = INTERPRETER_ELF;
700 if (memcmp(loc->interp_elf_ex.e_ident, ELFMAG, SELFMAG) != 0)
701 interpreter_type &= ~INTERPRETER_ELF;
704 if (!interpreter_type)
705 goto out_free_dentry;
707 /* Make sure only one type was selected */
708 if ((interpreter_type & INTERPRETER_ELF) &&
709 interpreter_type != INTERPRETER_ELF) {
710 // FIXME - ratelimit this before re-enabling
711 // printk(KERN_WARNING "ELF: Ambiguous type, using ELF\n");
712 interpreter_type = INTERPRETER_ELF;
714 /* Verify the interpreter has a valid arch */
715 if ((interpreter_type == INTERPRETER_ELF) &&
716 !elf_check_arch(&loc->interp_elf_ex))
717 goto out_free_dentry;
719 /* Executables without an interpreter also need a personality */
720 SET_PERSONALITY(loc->elf_ex, ibcs2_interpreter);
723 /* OK, we are done with that, now set up the arg stuff,
724 and then start this sucker up */
726 if ((!bprm->sh_bang) && (interpreter_type == INTERPRETER_AOUT)) {
727 char *passed_p = passed_fileno;
728 sprintf(passed_fileno, "%d", elf_exec_fileno);
730 if (elf_interpreter) {
731 retval = copy_strings_kernel(1, &passed_p, bprm);
733 goto out_free_dentry;
738 /* Flush all traces of the currently running executable */
739 retval = flush_old_exec(bprm);
741 goto out_free_dentry;
743 /* Discard our unneeded old files struct */
746 put_files_struct(files);
750 /* OK, This is the point of no return */
751 current->mm->start_data = 0;
752 current->mm->end_data = 0;
753 current->mm->end_code = 0;
754 current->mm->mmap = NULL;
755 current->flags &= ~PF_FORKNOEXEC;
756 current->mm->def_flags = def_flags;
758 /* Do this immediately, since STACK_TOP as used in setup_arg_pages
759 may depend on the personality. */
760 SET_PERSONALITY(loc->elf_ex, ibcs2_interpreter);
761 if (elf_read_implies_exec(loc->elf_ex, executable_stack))
762 current->personality |= READ_IMPLIES_EXEC;
764 arch_pick_mmap_layout(current->mm);
766 /* Do this so that we can load the interpreter, if need be. We will
767 change some of these later */
768 vx_rsspages_sub(current->mm, current->mm->rss);
769 current->mm->free_area_cache = current->mm->mmap_base;
770 retval = setup_arg_pages(bprm, STACK_TOP, executable_stack);
772 send_sig(SIGKILL, current, 0);
773 goto out_free_dentry;
776 current->mm->start_stack = bprm->p;
778 /* Now we do a little grungy work by mmaping the ELF image into
779 the correct location in memory. At this point, we assume that
780 the image should be loaded at fixed address, not at a variable
783 for(i = 0, elf_ppnt = elf_phdata; i < loc->elf_ex.e_phnum; i++, elf_ppnt++) {
784 int elf_prot = 0, elf_flags;
785 unsigned long k, vaddr;
787 if (elf_ppnt->p_type != PT_LOAD)
790 if (unlikely (elf_brk > elf_bss)) {
793 /* There was a PT_LOAD segment with p_memsz > p_filesz
794 before this one. Map anonymous pages, if needed,
795 and clear the area. */
796 retval = set_brk (elf_bss + load_bias,
797 elf_brk + load_bias);
799 send_sig(SIGKILL, current, 0);
800 goto out_free_dentry;
802 nbyte = ELF_PAGEOFFSET(elf_bss);
804 nbyte = ELF_MIN_ALIGN - nbyte;
805 if (nbyte > elf_brk - elf_bss)
806 nbyte = elf_brk - elf_bss;
807 if (clear_user((void __user *)elf_bss +
810 * This bss-zeroing can fail if the ELF
811 * file specifies odd protections. So
812 * we don't check the return value
818 if (elf_ppnt->p_flags & PF_R) elf_prot |= PROT_READ;
819 if (elf_ppnt->p_flags & PF_W) elf_prot |= PROT_WRITE;
820 if (elf_ppnt->p_flags & PF_X) elf_prot |= PROT_EXEC;
822 elf_flags = MAP_PRIVATE|MAP_DENYWRITE|MAP_EXECUTABLE;
824 vaddr = elf_ppnt->p_vaddr;
825 if (loc->elf_ex.e_type == ET_EXEC || load_addr_set) {
826 elf_flags |= MAP_FIXED;
827 } else if (loc->elf_ex.e_type == ET_DYN) {
828 /* Try and get dynamic programs out of the way of the default mmap
829 base, as well as whatever program they might try to exec. This
830 is because the brk will follow the loader, and is not movable. */
831 load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
834 error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt, elf_prot, elf_flags);
835 if (BAD_ADDR(error)) {
836 send_sig(SIGKILL, current, 0);
837 goto out_free_dentry;
840 if (!load_addr_set) {
842 load_addr = (elf_ppnt->p_vaddr - elf_ppnt->p_offset);
843 if (loc->elf_ex.e_type == ET_DYN) {
845 ELF_PAGESTART(load_bias + vaddr);
846 load_addr += load_bias;
847 reloc_func_desc = load_bias;
850 k = elf_ppnt->p_vaddr;
851 if (k < start_code) start_code = k;
852 if (start_data < k) start_data = k;
855 * Check to see if the section's size will overflow the
856 * allowed task size. Note that p_filesz must always be
857 * <= p_memsz so it is only necessary to check p_memsz.
859 if (k > TASK_SIZE || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
860 elf_ppnt->p_memsz > TASK_SIZE ||
861 TASK_SIZE - elf_ppnt->p_memsz < k) {
862 /* set_brk can never work. Avoid overflows. */
863 send_sig(SIGKILL, current, 0);
864 goto out_free_dentry;
867 k = elf_ppnt->p_vaddr + elf_ppnt->p_filesz;
871 if ((elf_ppnt->p_flags & PF_X) && end_code < k)
875 k = elf_ppnt->p_vaddr + elf_ppnt->p_memsz;
880 loc->elf_ex.e_entry += load_bias;
881 elf_bss += load_bias;
882 elf_brk += load_bias;
883 start_code += load_bias;
884 end_code += load_bias;
885 start_data += load_bias;
886 end_data += load_bias;
888 /* Calling set_brk effectively mmaps the pages that we need
889 * for the bss and break sections. We must do this before
890 * mapping in the interpreter, to make sure it doesn't wind
891 * up getting placed where the bss needs to go.
893 retval = set_brk(elf_bss, elf_brk);
895 send_sig(SIGKILL, current, 0);
896 goto out_free_dentry;
898 if (padzero(elf_bss)) {
899 send_sig(SIGSEGV, current, 0);
900 retval = -EFAULT; /* Nobody gets to see this, but.. */
901 goto out_free_dentry;
904 if (elf_interpreter) {
905 if (interpreter_type == INTERPRETER_AOUT)
906 elf_entry = load_aout_interp(&loc->interp_ex,
909 elf_entry = load_elf_interp(&loc->interp_elf_ex,
912 if (BAD_ADDR(elf_entry)) {
913 printk(KERN_ERR "Unable to load interpreter %.128s\n",
915 force_sig(SIGSEGV, current);
916 retval = -ENOEXEC; /* Nobody gets to see this, but.. */
917 goto out_free_dentry;
919 reloc_func_desc = interp_load_addr;
921 allow_write_access(interpreter);
923 kfree(elf_interpreter);
925 elf_entry = loc->elf_ex.e_entry;
930 if (interpreter_type != INTERPRETER_AOUT)
931 sys_close(elf_exec_fileno);
933 set_binfmt(&elf_format);
936 current->flags &= ~PF_FORKNOEXEC;
937 create_elf_tables(bprm, &loc->elf_ex, (interpreter_type == INTERPRETER_AOUT),
938 load_addr, interp_load_addr);
939 /* N.B. passed_fileno might not be initialized? */
940 if (interpreter_type == INTERPRETER_AOUT)
941 current->mm->arg_start += strlen(passed_fileno) + 1;
942 current->mm->end_code = end_code;
943 current->mm->start_code = start_code;
944 current->mm->start_data = start_data;
945 current->mm->end_data = end_data;
946 current->mm->start_stack = bprm->p;
948 if (current->personality & MMAP_PAGE_ZERO) {
949 /* Why this, you ask??? Well SVr4 maps page 0 as read-only,
950 and some applications "depend" upon this behavior.
951 Since we do not have the power to recompile these, we
952 emulate the SVr4 behavior. Sigh. */
953 down_write(¤t->mm->mmap_sem);
954 error = do_mmap(NULL, 0, PAGE_SIZE, PROT_READ | PROT_EXEC,
955 MAP_FIXED | MAP_PRIVATE, 0);
956 up_write(¤t->mm->mmap_sem);
961 * The ABI may specify that certain registers be set up in special
962 * ways (on i386 %edx is the address of a DT_FINI function, for
963 * example. In addition, it may also specify (eg, PowerPC64 ELF)
964 * that the e_entry field is the address of the function descriptor
965 * for the startup routine, rather than the address of the startup
966 * routine itself. This macro performs whatever initialization to
967 * the regs structure is required as well as any relocations to the
968 * function descriptor entries when executing dynamically links apps.
970 ELF_PLAT_INIT(regs, reloc_func_desc);
973 start_thread(regs, elf_entry, bprm->p);
974 if (unlikely(current->ptrace & PT_PTRACED)) {
975 if (current->ptrace & PT_TRACE_EXEC)
976 ptrace_notify ((PTRACE_EVENT_EXEC << 8) | SIGTRAP);
978 send_sig(SIGTRAP, current, 0);
988 allow_write_access(interpreter);
993 kfree(elf_interpreter);
995 sys_close(elf_exec_fileno);
998 put_files_struct(current->files);
999 current->files = files;
1006 /* This is really simpleminded and specialized - we are loading an
1007 a.out library that is given an ELF header. */
1009 static int load_elf_library(struct file *file)
1011 struct elf_phdr *elf_phdata;
1012 struct elf_phdr *eppnt;
1013 unsigned long elf_bss, bss, len;
1014 int retval, error, i, j;
1015 struct elfhdr elf_ex;
1018 retval = kernel_read(file, 0, (char *) &elf_ex, sizeof(elf_ex));
1019 if (retval != sizeof(elf_ex))
1022 if (memcmp(elf_ex.e_ident, ELFMAG, SELFMAG) != 0)
1025 /* First of all, some simple consistency checks */
1026 if (elf_ex.e_type != ET_EXEC || elf_ex.e_phnum > 2 ||
1027 !elf_check_arch(&elf_ex) || !file->f_op || !file->f_op->mmap)
1030 /* Now read in all of the header information */
1032 j = sizeof(struct elf_phdr) * elf_ex.e_phnum;
1033 /* j < ELF_MIN_ALIGN because elf_ex.e_phnum <= 2 */
1036 elf_phdata = kmalloc(j, GFP_KERNEL);
1042 retval = kernel_read(file, elf_ex.e_phoff, (char *)eppnt, j);
1046 for (j = 0, i = 0; i<elf_ex.e_phnum; i++)
1047 if ((eppnt + i)->p_type == PT_LOAD)
1052 while (eppnt->p_type != PT_LOAD)
1055 /* Now use mmap to map the library into memory. */
1056 down_write(¤t->mm->mmap_sem);
1057 error = do_mmap(file,
1058 ELF_PAGESTART(eppnt->p_vaddr),
1060 ELF_PAGEOFFSET(eppnt->p_vaddr)),
1061 PROT_READ | PROT_WRITE | PROT_EXEC,
1062 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE,
1064 ELF_PAGEOFFSET(eppnt->p_vaddr)));
1065 up_write(¤t->mm->mmap_sem);
1066 if (error != ELF_PAGESTART(eppnt->p_vaddr))
1069 elf_bss = eppnt->p_vaddr + eppnt->p_filesz;
1070 if (padzero(elf_bss)) {
1075 len = ELF_PAGESTART(eppnt->p_filesz + eppnt->p_vaddr + ELF_MIN_ALIGN - 1);
1076 bss = eppnt->p_memsz + eppnt->p_vaddr;
1078 down_write(¤t->mm->mmap_sem);
1079 do_brk(len, bss - len);
1080 up_write(¤t->mm->mmap_sem);
1091 * Note that some platforms still use traditional core dumps and not
1092 * the ELF core dump. Each platform can select it as appropriate.
1094 #ifdef USE_ELF_CORE_DUMP
1099 * Modelled on fs/exec.c:aout_core_dump()
1100 * Jeremy Fitzhardinge <jeremy@sw.oz.au>
1103 * These are the only things you should do on a core-file: use only these
1104 * functions to write out all the necessary info.
1106 static int dump_write(struct file *file, const void *addr, int nr)
1108 return file->f_op->write(file, addr, nr, &file->f_pos) == nr;
1111 static int dump_seek(struct file *file, off_t off)
1113 if (file->f_op->llseek) {
1114 if (file->f_op->llseek(file, off, 0) != off)
1122 * Decide whether a segment is worth dumping; default is yes to be
1123 * sure (missing info is worse than too much; etc).
1124 * Personally I'd include everything, and use the coredump limit...
1126 * I think we should skip something. But I am not sure how. H.J.
1128 static int maydump(struct vm_area_struct *vma)
1130 /* Do not dump I/O mapped devices, shared memory, or special mappings */
1131 if (vma->vm_flags & (VM_IO | VM_SHARED | VM_RESERVED))
1134 /* If it hasn't been written to, don't write it out */
1141 #define roundup(x, y) ((((x)+((y)-1))/(y))*(y))
1143 /* An ELF note in memory */
1148 unsigned int datasz;
1152 static int notesize(struct memelfnote *en)
1156 sz = sizeof(struct elf_note);
1157 sz += roundup(strlen(en->name) + 1, 4);
1158 sz += roundup(en->datasz, 4);
1163 #define DUMP_WRITE(addr, nr) \
1164 do { if (!dump_write(file, (addr), (nr))) return 0; } while(0)
1165 #define DUMP_SEEK(off) \
1166 do { if (!dump_seek(file, (off))) return 0; } while(0)
1168 static int writenote(struct memelfnote *men, struct file *file)
1172 en.n_namesz = strlen(men->name) + 1;
1173 en.n_descsz = men->datasz;
1174 en.n_type = men->type;
1176 DUMP_WRITE(&en, sizeof(en));
1177 DUMP_WRITE(men->name, en.n_namesz);
1178 /* XXX - cast from long long to long to avoid need for libgcc.a */
1179 DUMP_SEEK(roundup((unsigned long)file->f_pos, 4)); /* XXX */
1180 DUMP_WRITE(men->data, men->datasz);
1181 DUMP_SEEK(roundup((unsigned long)file->f_pos, 4)); /* XXX */
1188 #define DUMP_WRITE(addr, nr) \
1189 if ((size += (nr)) > limit || !dump_write(file, (addr), (nr))) \
1191 #define DUMP_SEEK(off) \
1192 if (!dump_seek(file, (off))) \
1195 static inline void fill_elf_header(struct elfhdr *elf, int segs)
1197 memcpy(elf->e_ident, ELFMAG, SELFMAG);
1198 elf->e_ident[EI_CLASS] = ELF_CLASS;
1199 elf->e_ident[EI_DATA] = ELF_DATA;
1200 elf->e_ident[EI_VERSION] = EV_CURRENT;
1201 elf->e_ident[EI_OSABI] = ELF_OSABI;
1202 memset(elf->e_ident+EI_PAD, 0, EI_NIDENT-EI_PAD);
1204 elf->e_type = ET_CORE;
1205 elf->e_machine = ELF_ARCH;
1206 elf->e_version = EV_CURRENT;
1208 elf->e_phoff = sizeof(struct elfhdr);
1210 elf->e_flags = ELF_CORE_EFLAGS;
1211 elf->e_ehsize = sizeof(struct elfhdr);
1212 elf->e_phentsize = sizeof(struct elf_phdr);
1213 elf->e_phnum = segs;
1214 elf->e_shentsize = 0;
1216 elf->e_shstrndx = 0;
1220 static inline void fill_elf_note_phdr(struct elf_phdr *phdr, int sz, off_t offset)
1222 phdr->p_type = PT_NOTE;
1223 phdr->p_offset = offset;
1226 phdr->p_filesz = sz;
1233 static void fill_note(struct memelfnote *note, const char *name, int type,
1234 unsigned int sz, void *data)
1244 * fill up all the fields in prstatus from the given task struct, except registers
1245 * which need to be filled up separately.
1247 static void fill_prstatus(struct elf_prstatus *prstatus,
1248 struct task_struct *p, long signr)
1250 prstatus->pr_info.si_signo = prstatus->pr_cursig = signr;
1251 prstatus->pr_sigpend = p->pending.signal.sig[0];
1252 prstatus->pr_sighold = p->blocked.sig[0];
1253 prstatus->pr_pid = p->pid;
1254 prstatus->pr_ppid = p->parent->pid;
1255 prstatus->pr_pgrp = process_group(p);
1256 prstatus->pr_sid = p->signal->session;
1257 if (thread_group_leader(p)) {
1259 * This is the record for the group leader. Add in the
1260 * cumulative times of previous dead threads. This total
1261 * won't include the time of each live thread whose state
1262 * is included in the core dump. The final total reported
1263 * to our parent process when it calls wait4 will include
1264 * those sums as well as the little bit more time it takes
1265 * this and each other thread to finish dying after the
1266 * core dump synchronization phase.
1268 cputime_to_timeval(cputime_add(p->utime, p->signal->utime),
1269 &prstatus->pr_utime);
1270 cputime_to_timeval(cputime_add(p->stime, p->signal->stime),
1271 &prstatus->pr_stime);
1273 cputime_to_timeval(p->utime, &prstatus->pr_utime);
1274 cputime_to_timeval(p->stime, &prstatus->pr_stime);
1276 cputime_to_timeval(p->signal->cutime, &prstatus->pr_cutime);
1277 cputime_to_timeval(p->signal->cstime, &prstatus->pr_cstime);
1280 static int fill_psinfo(struct elf_prpsinfo *psinfo, struct task_struct *p,
1281 struct mm_struct *mm)
1283 unsigned int i, len;
1285 /* first copy the parameters from user space */
1286 memset(psinfo, 0, sizeof(struct elf_prpsinfo));
1288 len = mm->arg_end - mm->arg_start;
1289 if (len >= ELF_PRARGSZ)
1290 len = ELF_PRARGSZ-1;
1291 if (copy_from_user(&psinfo->pr_psargs,
1292 (const char __user *)mm->arg_start, len))
1294 for(i = 0; i < len; i++)
1295 if (psinfo->pr_psargs[i] == 0)
1296 psinfo->pr_psargs[i] = ' ';
1297 psinfo->pr_psargs[len] = 0;
1299 psinfo->pr_pid = p->pid;
1300 psinfo->pr_ppid = p->parent->pid;
1301 psinfo->pr_pgrp = process_group(p);
1302 psinfo->pr_sid = p->signal->session;
1304 i = p->state ? ffz(~p->state) + 1 : 0;
1305 psinfo->pr_state = i;
1306 psinfo->pr_sname = (i < 0 || i > 5) ? '.' : "RSDTZW"[i];
1307 psinfo->pr_zomb = psinfo->pr_sname == 'Z';
1308 psinfo->pr_nice = task_nice(p);
1309 psinfo->pr_flag = p->flags;
1310 SET_UID(psinfo->pr_uid, p->uid);
1311 SET_GID(psinfo->pr_gid, p->gid);
1312 strncpy(psinfo->pr_fname, p->comm, sizeof(psinfo->pr_fname));
1317 /* Here is the structure in which status of each thread is captured. */
1318 struct elf_thread_status
1320 struct list_head list;
1321 struct elf_prstatus prstatus; /* NT_PRSTATUS */
1322 elf_fpregset_t fpu; /* NT_PRFPREG */
1323 struct task_struct *thread;
1324 #ifdef ELF_CORE_COPY_XFPREGS
1325 elf_fpxregset_t xfpu; /* NT_PRXFPREG */
1327 struct memelfnote notes[3];
1332 * In order to add the specific thread information for the elf file format,
1333 * we need to keep a linked list of every threads pr_status and then
1334 * create a single section for them in the final core file.
1336 static int elf_dump_thread_status(long signr, struct elf_thread_status *t)
1339 struct task_struct *p = t->thread;
1342 fill_prstatus(&t->prstatus, p, signr);
1343 elf_core_copy_task_regs(p, &t->prstatus.pr_reg);
1345 fill_note(&t->notes[0], "CORE", NT_PRSTATUS, sizeof(t->prstatus), &(t->prstatus));
1347 sz += notesize(&t->notes[0]);
1349 if ((t->prstatus.pr_fpvalid = elf_core_copy_task_fpregs(p, NULL, &t->fpu))) {
1350 fill_note(&t->notes[1], "CORE", NT_PRFPREG, sizeof(t->fpu), &(t->fpu));
1352 sz += notesize(&t->notes[1]);
1355 #ifdef ELF_CORE_COPY_XFPREGS
1356 if (elf_core_copy_task_xfpregs(p, &t->xfpu)) {
1357 fill_note(&t->notes[2], "LINUX", NT_PRXFPREG, sizeof(t->xfpu), &t->xfpu);
1359 sz += notesize(&t->notes[2]);
1368 * This is a two-pass process; first we find the offsets of the bits,
1369 * and then they are actually written out. If we run out of core limit
1372 static int elf_core_dump(long signr, struct pt_regs * regs, struct file * file)
1380 struct vm_area_struct *vma;
1381 struct elfhdr *elf = NULL;
1382 off_t offset = 0, dataoff;
1383 unsigned long limit = current->signal->rlim[RLIMIT_CORE].rlim_cur;
1385 struct memelfnote *notes = NULL;
1386 struct elf_prstatus *prstatus = NULL; /* NT_PRSTATUS */
1387 struct elf_prpsinfo *psinfo = NULL; /* NT_PRPSINFO */
1388 struct task_struct *g, *p;
1389 LIST_HEAD(thread_list);
1390 struct list_head *t;
1391 elf_fpregset_t *fpu = NULL;
1392 #ifdef ELF_CORE_COPY_XFPREGS
1393 elf_fpxregset_t *xfpu = NULL;
1395 int thread_status_size = 0;
1399 * We no longer stop all VM operations.
1401 * This is because those proceses that could possibly change map_count or
1402 * the mmap / vma pages are now blocked in do_exit on current finishing
1405 * Only ptrace can touch these memory addresses, but it doesn't change
1406 * the map_count or the pages allocated. So no possibility of crashing
1407 * exists while dumping the mm->vm_next areas to the core file.
1410 /* alloc memory for large data structures: too large to be on stack */
1411 elf = kmalloc(sizeof(*elf), GFP_KERNEL);
1414 prstatus = kmalloc(sizeof(*prstatus), GFP_KERNEL);
1417 psinfo = kmalloc(sizeof(*psinfo), GFP_KERNEL);
1420 notes = kmalloc(NUM_NOTES * sizeof(struct memelfnote), GFP_KERNEL);
1423 fpu = kmalloc(sizeof(*fpu), GFP_KERNEL);
1426 #ifdef ELF_CORE_COPY_XFPREGS
1427 xfpu = kmalloc(sizeof(*xfpu), GFP_KERNEL);
1433 struct elf_thread_status *tmp;
1434 read_lock(&tasklist_lock);
1436 if (current->mm == p->mm && current != p) {
1437 tmp = kmalloc(sizeof(*tmp), GFP_ATOMIC);
1439 read_unlock(&tasklist_lock);
1442 memset(tmp, 0, sizeof(*tmp));
1443 INIT_LIST_HEAD(&tmp->list);
1445 list_add(&tmp->list, &thread_list);
1447 while_each_thread(g,p);
1448 read_unlock(&tasklist_lock);
1449 list_for_each(t, &thread_list) {
1450 struct elf_thread_status *tmp;
1453 tmp = list_entry(t, struct elf_thread_status, list);
1454 sz = elf_dump_thread_status(signr, tmp);
1455 thread_status_size += sz;
1458 /* now collect the dump for the current */
1459 memset(prstatus, 0, sizeof(*prstatus));
1460 fill_prstatus(prstatus, current, signr);
1461 elf_core_copy_regs(&prstatus->pr_reg, regs);
1463 segs = current->mm->map_count;
1464 #ifdef ELF_CORE_EXTRA_PHDRS
1465 segs += ELF_CORE_EXTRA_PHDRS;
1469 fill_elf_header(elf, segs+1); /* including notes section */
1472 current->flags |= PF_DUMPCORE;
1475 * Set up the notes in similar form to SVR4 core dumps made
1476 * with info from their /proc.
1479 fill_note(notes +0, "CORE", NT_PRSTATUS, sizeof(*prstatus), prstatus);
1481 fill_psinfo(psinfo, current->group_leader, current->mm);
1482 fill_note(notes +1, "CORE", NT_PRPSINFO, sizeof(*psinfo), psinfo);
1484 fill_note(notes +2, "CORE", NT_TASKSTRUCT, sizeof(*current), current);
1488 auxv = (elf_addr_t *) current->mm->saved_auxv;
1493 while (auxv[i - 2] != AT_NULL);
1494 fill_note(¬es[numnote++], "CORE", NT_AUXV,
1495 i * sizeof (elf_addr_t), auxv);
1497 /* Try to dump the FPU. */
1498 if ((prstatus->pr_fpvalid = elf_core_copy_task_fpregs(current, regs, fpu)))
1499 fill_note(notes + numnote++,
1500 "CORE", NT_PRFPREG, sizeof(*fpu), fpu);
1501 #ifdef ELF_CORE_COPY_XFPREGS
1502 if (elf_core_copy_task_xfpregs(current, xfpu))
1503 fill_note(notes + numnote++,
1504 "LINUX", NT_PRXFPREG, sizeof(*xfpu), xfpu);
1510 DUMP_WRITE(elf, sizeof(*elf));
1511 offset += sizeof(*elf); /* Elf header */
1512 offset += (segs+1) * sizeof(struct elf_phdr); /* Program headers */
1514 /* Write notes phdr entry */
1516 struct elf_phdr phdr;
1519 for (i = 0; i < numnote; i++)
1520 sz += notesize(notes + i);
1522 sz += thread_status_size;
1524 fill_elf_note_phdr(&phdr, sz, offset);
1526 DUMP_WRITE(&phdr, sizeof(phdr));
1529 /* Page-align dumped data */
1530 dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE);
1532 /* Write program headers for segments dump */
1533 for (vma = current->mm->mmap; vma != NULL; vma = vma->vm_next) {
1534 struct elf_phdr phdr;
1537 sz = vma->vm_end - vma->vm_start;
1539 phdr.p_type = PT_LOAD;
1540 phdr.p_offset = offset;
1541 phdr.p_vaddr = vma->vm_start;
1543 phdr.p_filesz = maydump(vma) ? sz : 0;
1545 offset += phdr.p_filesz;
1546 phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
1547 if (vma->vm_flags & VM_WRITE) phdr.p_flags |= PF_W;
1548 if (vma->vm_flags & VM_EXEC) phdr.p_flags |= PF_X;
1549 phdr.p_align = ELF_EXEC_PAGESIZE;
1551 DUMP_WRITE(&phdr, sizeof(phdr));
1554 #ifdef ELF_CORE_WRITE_EXTRA_PHDRS
1555 ELF_CORE_WRITE_EXTRA_PHDRS;
1558 /* write out the notes section */
1559 for (i = 0; i < numnote; i++)
1560 if (!writenote(notes + i, file))
1563 /* write out the thread status notes section */
1564 list_for_each(t, &thread_list) {
1565 struct elf_thread_status *tmp = list_entry(t, struct elf_thread_status, list);
1566 for (i = 0; i < tmp->num_notes; i++)
1567 if (!writenote(&tmp->notes[i], file))
1573 for (vma = current->mm->mmap; vma != NULL; vma = vma->vm_next) {
1579 for (addr = vma->vm_start;
1581 addr += PAGE_SIZE) {
1583 struct vm_area_struct *vma;
1585 if (get_user_pages(current, current->mm, addr, 1, 0, 1,
1586 &page, &vma) <= 0) {
1587 DUMP_SEEK (file->f_pos + PAGE_SIZE);
1589 if (page == ZERO_PAGE(addr)) {
1590 DUMP_SEEK (file->f_pos + PAGE_SIZE);
1593 flush_cache_page(vma, addr);
1595 if ((size += PAGE_SIZE) > limit ||
1596 !dump_write(file, kaddr,
1599 page_cache_release(page);
1604 page_cache_release(page);
1609 #ifdef ELF_CORE_WRITE_EXTRA_DATA
1610 ELF_CORE_WRITE_EXTRA_DATA;
1613 if ((off_t) file->f_pos != offset) {
1615 printk("elf_core_dump: file->f_pos (%ld) != offset (%ld)\n",
1616 (off_t) file->f_pos, offset);
1623 while(!list_empty(&thread_list)) {
1624 struct list_head *tmp = thread_list.next;
1626 kfree(list_entry(tmp, struct elf_thread_status, list));
1634 #ifdef ELF_CORE_COPY_XFPREGS
1641 #endif /* USE_ELF_CORE_DUMP */
1643 static int __init init_elf_binfmt(void)
1645 return register_binfmt(&elf_format);
1648 static void __exit exit_elf_binfmt(void)
1650 /* Remove the COFF and ELF loaders. */
1651 unregister_binfmt(&elf_format);
1654 core_initcall(init_elf_binfmt);
1655 module_exit(exit_elf_binfmt);
1656 MODULE_LICENSE("GPL");