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_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 // current->mm->rss = 0;
769 vx_rsspages_sub(current->mm, current->mm->rss);
770 current->mm->free_area_cache = current->mm->mmap_base;
771 retval = setup_arg_pages(bprm, STACK_TOP, executable_stack);
773 send_sig(SIGKILL, current, 0);
774 goto out_free_dentry;
777 current->mm->start_stack = bprm->p;
779 /* Now we do a little grungy work by mmaping the ELF image into
780 the correct location in memory. At this point, we assume that
781 the image should be loaded at fixed address, not at a variable
784 for(i = 0, elf_ppnt = elf_phdata; i < loc->elf_ex.e_phnum; i++, elf_ppnt++) {
785 int elf_prot = 0, elf_flags;
786 unsigned long k, vaddr;
788 if (elf_ppnt->p_type != PT_LOAD)
791 if (unlikely (elf_brk > elf_bss)) {
794 /* There was a PT_LOAD segment with p_memsz > p_filesz
795 before this one. Map anonymous pages, if needed,
796 and clear the area. */
797 retval = set_brk (elf_bss + load_bias,
798 elf_brk + load_bias);
800 send_sig(SIGKILL, current, 0);
801 goto out_free_dentry;
803 nbyte = ELF_PAGEOFFSET(elf_bss);
805 nbyte = ELF_MIN_ALIGN - nbyte;
806 if (nbyte > elf_brk - elf_bss)
807 nbyte = elf_brk - elf_bss;
808 if (clear_user((void __user *)elf_bss +
811 * This bss-zeroing can fail if the ELF
812 * file specifies odd protections. So
813 * we don't check the return value
819 if (elf_ppnt->p_flags & PF_R) elf_prot |= PROT_READ;
820 if (elf_ppnt->p_flags & PF_W) elf_prot |= PROT_WRITE;
821 if (elf_ppnt->p_flags & PF_X) elf_prot |= PROT_EXEC;
823 elf_flags = MAP_PRIVATE|MAP_DENYWRITE|MAP_EXECUTABLE;
825 vaddr = elf_ppnt->p_vaddr;
826 if (loc->elf_ex.e_type == ET_EXEC || load_addr_set) {
827 elf_flags |= MAP_FIXED;
828 } else if (loc->elf_ex.e_type == ET_DYN) {
829 /* Try and get dynamic programs out of the way of the default mmap
830 base, as well as whatever program they might try to exec. This
831 is because the brk will follow the loader, and is not movable. */
832 load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
835 error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt, elf_prot, elf_flags);
836 if (BAD_ADDR(error)) {
837 send_sig(SIGKILL, current, 0);
838 goto out_free_dentry;
841 if (!load_addr_set) {
843 load_addr = (elf_ppnt->p_vaddr - elf_ppnt->p_offset);
844 if (loc->elf_ex.e_type == ET_DYN) {
846 ELF_PAGESTART(load_bias + vaddr);
847 load_addr += load_bias;
848 reloc_func_desc = load_bias;
851 k = elf_ppnt->p_vaddr;
852 if (k < start_code) start_code = k;
853 if (start_data < k) start_data = k;
856 * Check to see if the section's size will overflow the
857 * allowed task size. Note that p_filesz must always be
858 * <= p_memsz so it is only necessary to check p_memsz.
860 if (k > TASK_SIZE || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
861 elf_ppnt->p_memsz > TASK_SIZE ||
862 TASK_SIZE - elf_ppnt->p_memsz < k) {
863 /* set_brk can never work. Avoid overflows. */
864 send_sig(SIGKILL, current, 0);
865 goto out_free_dentry;
868 k = elf_ppnt->p_vaddr + elf_ppnt->p_filesz;
872 if ((elf_ppnt->p_flags & PF_X) && end_code < k)
876 k = elf_ppnt->p_vaddr + elf_ppnt->p_memsz;
881 loc->elf_ex.e_entry += load_bias;
882 elf_bss += load_bias;
883 elf_brk += load_bias;
884 start_code += load_bias;
885 end_code += load_bias;
886 start_data += load_bias;
887 end_data += load_bias;
889 /* Calling set_brk effectively mmaps the pages that we need
890 * for the bss and break sections. We must do this before
891 * mapping in the interpreter, to make sure it doesn't wind
892 * up getting placed where the bss needs to go.
894 retval = set_brk(elf_bss, elf_brk);
896 send_sig(SIGKILL, current, 0);
897 goto out_free_dentry;
899 if (padzero(elf_bss)) {
900 send_sig(SIGSEGV, current, 0);
901 retval = -EFAULT; /* Nobody gets to see this, but.. */
902 goto out_free_dentry;
905 if (elf_interpreter) {
906 if (interpreter_type == INTERPRETER_AOUT)
907 elf_entry = load_aout_interp(&loc->interp_ex,
910 elf_entry = load_elf_interp(&loc->interp_elf_ex,
913 if (BAD_ADDR(elf_entry)) {
914 printk(KERN_ERR "Unable to load interpreter %.128s\n",
916 force_sig(SIGSEGV, current);
917 retval = -ENOEXEC; /* Nobody gets to see this, but.. */
918 goto out_free_dentry;
920 reloc_func_desc = interp_load_addr;
922 allow_write_access(interpreter);
924 kfree(elf_interpreter);
926 elf_entry = loc->elf_ex.e_entry;
931 if (interpreter_type != INTERPRETER_AOUT)
932 sys_close(elf_exec_fileno);
934 set_binfmt(&elf_format);
937 current->flags &= ~PF_FORKNOEXEC;
938 create_elf_tables(bprm, &loc->elf_ex, (interpreter_type == INTERPRETER_AOUT),
939 load_addr, interp_load_addr);
940 /* N.B. passed_fileno might not be initialized? */
941 if (interpreter_type == INTERPRETER_AOUT)
942 current->mm->arg_start += strlen(passed_fileno) + 1;
943 current->mm->end_code = end_code;
944 current->mm->start_code = start_code;
945 current->mm->start_data = start_data;
946 current->mm->end_data = end_data;
947 current->mm->start_stack = bprm->p;
949 if (current->personality & MMAP_PAGE_ZERO) {
950 /* Why this, you ask??? Well SVr4 maps page 0 as read-only,
951 and some applications "depend" upon this behavior.
952 Since we do not have the power to recompile these, we
953 emulate the SVr4 behavior. Sigh. */
954 down_write(¤t->mm->mmap_sem);
955 error = do_mmap(NULL, 0, PAGE_SIZE, PROT_READ | PROT_EXEC,
956 MAP_FIXED | MAP_PRIVATE, 0);
957 up_write(¤t->mm->mmap_sem);
962 * The ABI may specify that certain registers be set up in special
963 * ways (on i386 %edx is the address of a DT_FINI function, for
964 * example. In addition, it may also specify (eg, PowerPC64 ELF)
965 * that the e_entry field is the address of the function descriptor
966 * for the startup routine, rather than the address of the startup
967 * routine itself. This macro performs whatever initialization to
968 * the regs structure is required as well as any relocations to the
969 * function descriptor entries when executing dynamically links apps.
971 ELF_PLAT_INIT(regs, reloc_func_desc);
974 start_thread(regs, elf_entry, bprm->p);
975 if (unlikely(current->ptrace & PT_PTRACED)) {
976 if (current->ptrace & PT_TRACE_EXEC)
977 ptrace_notify ((PTRACE_EVENT_EXEC << 8) | SIGTRAP);
979 send_sig(SIGTRAP, current, 0);
989 allow_write_access(interpreter);
994 kfree(elf_interpreter);
996 sys_close(elf_exec_fileno);
999 put_files_struct(current->files);
1000 current->files = files;
1007 /* This is really simpleminded and specialized - we are loading an
1008 a.out library that is given an ELF header. */
1010 static int load_elf_library(struct file *file)
1012 struct elf_phdr *elf_phdata;
1013 struct elf_phdr *eppnt;
1014 unsigned long elf_bss, bss, len;
1015 int retval, error, i, j;
1016 struct elfhdr elf_ex;
1019 retval = kernel_read(file, 0, (char *) &elf_ex, sizeof(elf_ex));
1020 if (retval != sizeof(elf_ex))
1023 if (memcmp(elf_ex.e_ident, ELFMAG, SELFMAG) != 0)
1026 /* First of all, some simple consistency checks */
1027 if (elf_ex.e_type != ET_EXEC || elf_ex.e_phnum > 2 ||
1028 !elf_check_arch(&elf_ex) || !file->f_op || !file->f_op->mmap)
1031 /* Now read in all of the header information */
1033 j = sizeof(struct elf_phdr) * elf_ex.e_phnum;
1034 /* j < ELF_MIN_ALIGN because elf_ex.e_phnum <= 2 */
1037 elf_phdata = kmalloc(j, GFP_KERNEL);
1043 retval = kernel_read(file, elf_ex.e_phoff, (char *)eppnt, j);
1047 for (j = 0, i = 0; i<elf_ex.e_phnum; i++)
1048 if ((eppnt + i)->p_type == PT_LOAD)
1053 while (eppnt->p_type != PT_LOAD)
1056 /* Now use mmap to map the library into memory. */
1057 down_write(¤t->mm->mmap_sem);
1058 error = do_mmap(file,
1059 ELF_PAGESTART(eppnt->p_vaddr),
1061 ELF_PAGEOFFSET(eppnt->p_vaddr)),
1062 PROT_READ | PROT_WRITE | PROT_EXEC,
1063 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE,
1065 ELF_PAGEOFFSET(eppnt->p_vaddr)));
1066 up_write(¤t->mm->mmap_sem);
1067 if (error != ELF_PAGESTART(eppnt->p_vaddr))
1070 elf_bss = eppnt->p_vaddr + eppnt->p_filesz;
1071 if (padzero(elf_bss)) {
1076 len = ELF_PAGESTART(eppnt->p_filesz + eppnt->p_vaddr + ELF_MIN_ALIGN - 1);
1077 bss = eppnt->p_memsz + eppnt->p_vaddr;
1079 down_write(¤t->mm->mmap_sem);
1080 do_brk(len, bss - len);
1081 up_write(¤t->mm->mmap_sem);
1092 * Note that some platforms still use traditional core dumps and not
1093 * the ELF core dump. Each platform can select it as appropriate.
1095 #ifdef USE_ELF_CORE_DUMP
1100 * Modelled on fs/exec.c:aout_core_dump()
1101 * Jeremy Fitzhardinge <jeremy@sw.oz.au>
1104 * These are the only things you should do on a core-file: use only these
1105 * functions to write out all the necessary info.
1107 static int dump_write(struct file *file, const void *addr, int nr)
1109 return file->f_op->write(file, addr, nr, &file->f_pos) == nr;
1112 static int dump_seek(struct file *file, off_t off)
1114 if (file->f_op->llseek) {
1115 if (file->f_op->llseek(file, off, 0) != off)
1123 * Decide whether a segment is worth dumping; default is yes to be
1124 * sure (missing info is worse than too much; etc).
1125 * Personally I'd include everything, and use the coredump limit...
1127 * I think we should skip something. But I am not sure how. H.J.
1129 static int maydump(struct vm_area_struct *vma)
1131 /* Do not dump I/O mapped devices, shared memory, or special mappings */
1132 if (vma->vm_flags & (VM_IO | VM_SHARED | VM_RESERVED))
1135 /* If it hasn't been written to, don't write it out */
1142 #define roundup(x, y) ((((x)+((y)-1))/(y))*(y))
1144 /* An ELF note in memory */
1149 unsigned int datasz;
1153 static int notesize(struct memelfnote *en)
1157 sz = sizeof(struct elf_note);
1158 sz += roundup(strlen(en->name) + 1, 4);
1159 sz += roundup(en->datasz, 4);
1164 #define DUMP_WRITE(addr, nr) \
1165 do { if (!dump_write(file, (addr), (nr))) return 0; } while(0)
1166 #define DUMP_SEEK(off) \
1167 do { if (!dump_seek(file, (off))) return 0; } while(0)
1169 static int writenote(struct memelfnote *men, struct file *file)
1173 en.n_namesz = strlen(men->name) + 1;
1174 en.n_descsz = men->datasz;
1175 en.n_type = men->type;
1177 DUMP_WRITE(&en, sizeof(en));
1178 DUMP_WRITE(men->name, en.n_namesz);
1179 /* XXX - cast from long long to long to avoid need for libgcc.a */
1180 DUMP_SEEK(roundup((unsigned long)file->f_pos, 4)); /* XXX */
1181 DUMP_WRITE(men->data, men->datasz);
1182 DUMP_SEEK(roundup((unsigned long)file->f_pos, 4)); /* XXX */
1189 #define DUMP_WRITE(addr, nr) \
1190 if ((size += (nr)) > limit || !dump_write(file, (addr), (nr))) \
1192 #define DUMP_SEEK(off) \
1193 if (!dump_seek(file, (off))) \
1196 static inline void fill_elf_header(struct elfhdr *elf, int segs)
1198 memcpy(elf->e_ident, ELFMAG, SELFMAG);
1199 elf->e_ident[EI_CLASS] = ELF_CLASS;
1200 elf->e_ident[EI_DATA] = ELF_DATA;
1201 elf->e_ident[EI_VERSION] = EV_CURRENT;
1202 elf->e_ident[EI_OSABI] = ELF_OSABI;
1203 memset(elf->e_ident+EI_PAD, 0, EI_NIDENT-EI_PAD);
1205 elf->e_type = ET_CORE;
1206 elf->e_machine = ELF_ARCH;
1207 elf->e_version = EV_CURRENT;
1209 elf->e_phoff = sizeof(struct elfhdr);
1211 elf->e_flags = ELF_CORE_EFLAGS;
1212 elf->e_ehsize = sizeof(struct elfhdr);
1213 elf->e_phentsize = sizeof(struct elf_phdr);
1214 elf->e_phnum = segs;
1215 elf->e_shentsize = 0;
1217 elf->e_shstrndx = 0;
1221 static inline void fill_elf_note_phdr(struct elf_phdr *phdr, int sz, off_t offset)
1223 phdr->p_type = PT_NOTE;
1224 phdr->p_offset = offset;
1227 phdr->p_filesz = sz;
1234 static void fill_note(struct memelfnote *note, const char *name, int type,
1235 unsigned int sz, void *data)
1245 * fill up all the fields in prstatus from the given task struct, except registers
1246 * which need to be filled up separately.
1248 static void fill_prstatus(struct elf_prstatus *prstatus,
1249 struct task_struct *p, long signr)
1251 prstatus->pr_info.si_signo = prstatus->pr_cursig = signr;
1252 prstatus->pr_sigpend = p->pending.signal.sig[0];
1253 prstatus->pr_sighold = p->blocked.sig[0];
1254 prstatus->pr_pid = p->pid;
1255 prstatus->pr_ppid = p->parent->pid;
1256 prstatus->pr_pgrp = process_group(p);
1257 prstatus->pr_sid = p->signal->session;
1258 if (thread_group_leader(p)) {
1260 * This is the record for the group leader. Add in the
1261 * cumulative times of previous dead threads. This total
1262 * won't include the time of each live thread whose state
1263 * is included in the core dump. The final total reported
1264 * to our parent process when it calls wait4 will include
1265 * those sums as well as the little bit more time it takes
1266 * this and each other thread to finish dying after the
1267 * core dump synchronization phase.
1269 cputime_to_timeval(cputime_add(p->utime, p->signal->utime),
1270 &prstatus->pr_utime);
1271 cputime_to_timeval(cputime_add(p->stime, p->signal->stime),
1272 &prstatus->pr_stime);
1274 cputime_to_timeval(p->utime, &prstatus->pr_utime);
1275 cputime_to_timeval(p->stime, &prstatus->pr_stime);
1277 cputime_to_timeval(p->signal->cutime, &prstatus->pr_cutime);
1278 cputime_to_timeval(p->signal->cstime, &prstatus->pr_cstime);
1281 static int fill_psinfo(struct elf_prpsinfo *psinfo, struct task_struct *p,
1282 struct mm_struct *mm)
1286 /* first copy the parameters from user space */
1287 memset(psinfo, 0, sizeof(struct elf_prpsinfo));
1289 len = mm->arg_end - mm->arg_start;
1290 if (len >= ELF_PRARGSZ)
1291 len = ELF_PRARGSZ-1;
1292 if (copy_from_user(&psinfo->pr_psargs,
1293 (const char __user *)mm->arg_start, len))
1295 for(i = 0; i < len; i++)
1296 if (psinfo->pr_psargs[i] == 0)
1297 psinfo->pr_psargs[i] = ' ';
1298 psinfo->pr_psargs[len] = 0;
1300 psinfo->pr_pid = p->pid;
1301 psinfo->pr_ppid = p->parent->pid;
1302 psinfo->pr_pgrp = process_group(p);
1303 psinfo->pr_sid = p->signal->session;
1305 i = p->state ? ffz(~p->state) + 1 : 0;
1306 psinfo->pr_state = i;
1307 psinfo->pr_sname = (i < 0 || i > 5) ? '.' : "RSDTZW"[i];
1308 psinfo->pr_zomb = psinfo->pr_sname == 'Z';
1309 psinfo->pr_nice = task_nice(p);
1310 psinfo->pr_flag = p->flags;
1311 SET_UID(psinfo->pr_uid, p->uid);
1312 SET_GID(psinfo->pr_gid, p->gid);
1313 strncpy(psinfo->pr_fname, p->comm, sizeof(psinfo->pr_fname));
1318 /* Here is the structure in which status of each thread is captured. */
1319 struct elf_thread_status
1321 struct list_head list;
1322 struct elf_prstatus prstatus; /* NT_PRSTATUS */
1323 elf_fpregset_t fpu; /* NT_PRFPREG */
1324 struct task_struct *thread;
1325 #ifdef ELF_CORE_COPY_XFPREGS
1326 elf_fpxregset_t xfpu; /* NT_PRXFPREG */
1328 struct memelfnote notes[3];
1333 * In order to add the specific thread information for the elf file format,
1334 * we need to keep a linked list of every threads pr_status and then
1335 * create a single section for them in the final core file.
1337 static int elf_dump_thread_status(long signr, struct elf_thread_status *t)
1340 struct task_struct *p = t->thread;
1343 fill_prstatus(&t->prstatus, p, signr);
1344 elf_core_copy_task_regs(p, &t->prstatus.pr_reg);
1346 fill_note(&t->notes[0], "CORE", NT_PRSTATUS, sizeof(t->prstatus), &(t->prstatus));
1348 sz += notesize(&t->notes[0]);
1350 if ((t->prstatus.pr_fpvalid = elf_core_copy_task_fpregs(p, NULL, &t->fpu))) {
1351 fill_note(&t->notes[1], "CORE", NT_PRFPREG, sizeof(t->fpu), &(t->fpu));
1353 sz += notesize(&t->notes[1]);
1356 #ifdef ELF_CORE_COPY_XFPREGS
1357 if (elf_core_copy_task_xfpregs(p, &t->xfpu)) {
1358 fill_note(&t->notes[2], "LINUX", NT_PRXFPREG, sizeof(t->xfpu), &t->xfpu);
1360 sz += notesize(&t->notes[2]);
1369 * This is a two-pass process; first we find the offsets of the bits,
1370 * and then they are actually written out. If we run out of core limit
1373 static int elf_core_dump(long signr, struct pt_regs * regs, struct file * file)
1381 struct vm_area_struct *vma;
1382 struct elfhdr *elf = NULL;
1383 off_t offset = 0, dataoff;
1384 unsigned long limit = current->signal->rlim[RLIMIT_CORE].rlim_cur;
1386 struct memelfnote *notes = NULL;
1387 struct elf_prstatus *prstatus = NULL; /* NT_PRSTATUS */
1388 struct elf_prpsinfo *psinfo = NULL; /* NT_PRPSINFO */
1389 struct task_struct *g, *p;
1390 LIST_HEAD(thread_list);
1391 struct list_head *t;
1392 elf_fpregset_t *fpu = NULL;
1393 #ifdef ELF_CORE_COPY_XFPREGS
1394 elf_fpxregset_t *xfpu = NULL;
1396 int thread_status_size = 0;
1400 * We no longer stop all VM operations.
1402 * This is because those proceses that could possibly change map_count or
1403 * the mmap / vma pages are now blocked in do_exit on current finishing
1406 * Only ptrace can touch these memory addresses, but it doesn't change
1407 * the map_count or the pages allocated. So no possibility of crashing
1408 * exists while dumping the mm->vm_next areas to the core file.
1411 /* alloc memory for large data structures: too large to be on stack */
1412 elf = kmalloc(sizeof(*elf), GFP_KERNEL);
1415 prstatus = kmalloc(sizeof(*prstatus), GFP_KERNEL);
1418 psinfo = kmalloc(sizeof(*psinfo), GFP_KERNEL);
1421 notes = kmalloc(NUM_NOTES * sizeof(struct memelfnote), GFP_KERNEL);
1424 fpu = kmalloc(sizeof(*fpu), GFP_KERNEL);
1427 #ifdef ELF_CORE_COPY_XFPREGS
1428 xfpu = kmalloc(sizeof(*xfpu), GFP_KERNEL);
1434 struct elf_thread_status *tmp;
1435 read_lock(&tasklist_lock);
1437 if (current->mm == p->mm && current != p) {
1438 tmp = kmalloc(sizeof(*tmp), GFP_ATOMIC);
1440 read_unlock(&tasklist_lock);
1443 memset(tmp, 0, sizeof(*tmp));
1444 INIT_LIST_HEAD(&tmp->list);
1446 list_add(&tmp->list, &thread_list);
1448 while_each_thread(g,p);
1449 read_unlock(&tasklist_lock);
1450 list_for_each(t, &thread_list) {
1451 struct elf_thread_status *tmp;
1454 tmp = list_entry(t, struct elf_thread_status, list);
1455 sz = elf_dump_thread_status(signr, tmp);
1456 thread_status_size += sz;
1459 /* now collect the dump for the current */
1460 memset(prstatus, 0, sizeof(*prstatus));
1461 fill_prstatus(prstatus, current, signr);
1462 elf_core_copy_regs(&prstatus->pr_reg, regs);
1464 segs = current->mm->map_count;
1465 #ifdef ELF_CORE_EXTRA_PHDRS
1466 segs += ELF_CORE_EXTRA_PHDRS;
1470 fill_elf_header(elf, segs+1); /* including notes section */
1473 current->flags |= PF_DUMPCORE;
1476 * Set up the notes in similar form to SVR4 core dumps made
1477 * with info from their /proc.
1480 fill_note(notes +0, "CORE", NT_PRSTATUS, sizeof(*prstatus), prstatus);
1482 fill_psinfo(psinfo, current->group_leader, current->mm);
1483 fill_note(notes +1, "CORE", NT_PRPSINFO, sizeof(*psinfo), psinfo);
1485 fill_note(notes +2, "CORE", NT_TASKSTRUCT, sizeof(*current), current);
1489 auxv = (elf_addr_t *) current->mm->saved_auxv;
1494 while (auxv[i - 2] != AT_NULL);
1495 fill_note(¬es[numnote++], "CORE", NT_AUXV,
1496 i * sizeof (elf_addr_t), auxv);
1498 /* Try to dump the FPU. */
1499 if ((prstatus->pr_fpvalid = elf_core_copy_task_fpregs(current, regs, fpu)))
1500 fill_note(notes + numnote++,
1501 "CORE", NT_PRFPREG, sizeof(*fpu), fpu);
1502 #ifdef ELF_CORE_COPY_XFPREGS
1503 if (elf_core_copy_task_xfpregs(current, xfpu))
1504 fill_note(notes + numnote++,
1505 "LINUX", NT_PRXFPREG, sizeof(*xfpu), xfpu);
1511 DUMP_WRITE(elf, sizeof(*elf));
1512 offset += sizeof(*elf); /* Elf header */
1513 offset += (segs+1) * sizeof(struct elf_phdr); /* Program headers */
1515 /* Write notes phdr entry */
1517 struct elf_phdr phdr;
1520 for (i = 0; i < numnote; i++)
1521 sz += notesize(notes + i);
1523 sz += thread_status_size;
1525 fill_elf_note_phdr(&phdr, sz, offset);
1527 DUMP_WRITE(&phdr, sizeof(phdr));
1530 /* Page-align dumped data */
1531 dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE);
1533 /* Write program headers for segments dump */
1534 for (vma = current->mm->mmap; vma != NULL; vma = vma->vm_next) {
1535 struct elf_phdr phdr;
1538 sz = vma->vm_end - vma->vm_start;
1540 phdr.p_type = PT_LOAD;
1541 phdr.p_offset = offset;
1542 phdr.p_vaddr = vma->vm_start;
1544 phdr.p_filesz = maydump(vma) ? sz : 0;
1546 offset += phdr.p_filesz;
1547 phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
1548 if (vma->vm_flags & VM_WRITE) phdr.p_flags |= PF_W;
1549 if (vma->vm_flags & VM_EXEC) phdr.p_flags |= PF_X;
1550 phdr.p_align = ELF_EXEC_PAGESIZE;
1552 DUMP_WRITE(&phdr, sizeof(phdr));
1555 #ifdef ELF_CORE_WRITE_EXTRA_PHDRS
1556 ELF_CORE_WRITE_EXTRA_PHDRS;
1559 /* write out the notes section */
1560 for (i = 0; i < numnote; i++)
1561 if (!writenote(notes + i, file))
1564 /* write out the thread status notes section */
1565 list_for_each(t, &thread_list) {
1566 struct elf_thread_status *tmp = list_entry(t, struct elf_thread_status, list);
1567 for (i = 0; i < tmp->num_notes; i++)
1568 if (!writenote(&tmp->notes[i], file))
1574 for (vma = current->mm->mmap; vma != NULL; vma = vma->vm_next) {
1580 for (addr = vma->vm_start;
1582 addr += PAGE_SIZE) {
1584 struct vm_area_struct *vma;
1586 if (get_user_pages(current, current->mm, addr, 1, 0, 1,
1587 &page, &vma) <= 0) {
1588 DUMP_SEEK (file->f_pos + PAGE_SIZE);
1590 if (page == ZERO_PAGE(addr)) {
1591 DUMP_SEEK (file->f_pos + PAGE_SIZE);
1594 flush_cache_page(vma, addr);
1596 if ((size += PAGE_SIZE) > limit ||
1597 !dump_write(file, kaddr,
1600 page_cache_release(page);
1605 page_cache_release(page);
1610 #ifdef ELF_CORE_WRITE_EXTRA_DATA
1611 ELF_CORE_WRITE_EXTRA_DATA;
1614 if ((off_t) file->f_pos != offset) {
1616 printk("elf_core_dump: file->f_pos (%ld) != offset (%ld)\n",
1617 (off_t) file->f_pos, offset);
1624 while(!list_empty(&thread_list)) {
1625 struct list_head *tmp = thread_list.next;
1627 kfree(list_entry(tmp, struct elf_thread_status, list));
1635 #ifdef ELF_CORE_COPY_XFPREGS
1642 #endif /* USE_ELF_CORE_DUMP */
1644 static int __init init_elf_binfmt(void)
1646 return register_binfmt(&elf_format);
1649 static void __exit exit_elf_binfmt(void)
1651 /* Remove the COFF and ELF loaders. */
1652 unregister_binfmt(&elf_format);
1655 core_initcall(init_elf_binfmt);
1656 module_exit(exit_elf_binfmt);
1657 MODULE_LICENSE("GPL");