12 #include <linux/module.h>
13 #include <linux/kernel.h>
16 #include <linux/mman.h>
17 #include <linux/errno.h>
18 #include <linux/signal.h>
19 #include <linux/binfmts.h>
20 #include <linux/string.h>
22 #include <linux/slab.h>
23 #include <linux/personality.h>
24 #include <linux/elfcore.h>
27 #include <linux/compiler.h>
32 #include <linux/random.h>
33 #include <linux/elf.h>
34 #include <linux/utsname.h>
36 #include <asm/uaccess.h>
37 #include <asm/param.h>
41 #define user_long_t long
43 #ifndef user_siginfo_t
44 #define user_siginfo_t siginfo_t
48 static int load_elf_library(
struct file *);
49 static unsigned long elf_map(
struct file *,
unsigned long,
struct elf_phdr *,
50 int,
int,
unsigned long);
56 #ifdef CONFIG_ELF_CORE
59 #define elf_core_dump NULL
62 #if ELF_EXEC_PAGESIZE > PAGE_SIZE
63 #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
65 #define ELF_MIN_ALIGN PAGE_SIZE
68 #ifndef ELF_CORE_EFLAGS
69 #define ELF_CORE_EFLAGS 0
72 #define ELF_PAGESTART(_v) ((_v) & ~(unsigned long)(ELF_MIN_ALIGN-1))
73 #define ELF_PAGEOFFSET(_v) ((_v) & (ELF_MIN_ALIGN-1))
74 #define ELF_PAGEALIGN(_v) (((_v) + ELF_MIN_ALIGN - 1) & ~(ELF_MIN_ALIGN - 1))
78 .load_binary = load_elf_binary,
79 .load_shlib = load_elf_library,
84 #define BAD_ADDR(x) ((unsigned long)(x) >= TASK_SIZE)
86 static int set_brk(
unsigned long start,
unsigned long end)
92 addr =
vm_brk(start, end - start);
105 static int padzero(
unsigned long elf_bss)
112 if (
clear_user((
void __user *) elf_bss, nbyte))
119 #ifdef CONFIG_STACK_GROWSUP
120 #define STACK_ADD(sp, items) ((elf_addr_t __user *)(sp) + (items))
121 #define STACK_ROUND(sp, items) \
122 ((15 + (unsigned long) ((sp) + (items))) &~ 15UL)
123 #define STACK_ALLOC(sp, len) ({ \
124 elf_addr_t __user *old_sp = (elf_addr_t __user *)sp; sp += len; \
127 #define STACK_ADD(sp, items) ((elf_addr_t __user *)(sp) - (items))
128 #define STACK_ROUND(sp, items) \
129 (((unsigned long) (sp - items)) &~ 15UL)
130 #define STACK_ALLOC(sp, len) ({ sp -= len ; sp; })
133 #ifndef ELF_BASE_PLATFORM
139 #define ELF_BASE_PLATFORM NULL
144 unsigned long load_addr,
unsigned long interp_load_addr)
146 unsigned long p = bprm->
p;
148 int envc = bprm->
envc;
157 unsigned char k_rand_bytes[16];
191 u_base_platform =
NULL;
192 if (k_base_platform) {
193 size_t len =
strlen(k_base_platform) + 1;
206 if (
__copy_to_user(u_rand_bytes, k_rand_bytes,
sizeof(k_rand_bytes)))
247 if (k_base_platform) {
256 memset(&elf_info[ei_index], 0,
257 sizeof current->mm->saved_auxv - ei_index *
sizeof elf_info[0]);
264 items = (argc + 1) + (envc + 1) + 1;
268 #ifdef CONFIG_STACK_GROWSUP
270 bprm->
exec = (
unsigned long)
sp;
288 envp = argv + argc + 1;
324 static unsigned long elf_map(
struct file *filep,
unsigned long addr,
328 unsigned long map_addr;
330 unsigned long off = eppnt->p_offset -
ELF_PAGEOFFSET(eppnt->p_vaddr);
349 map_addr =
vm_mmap(filep, addr, total_size, prot, type, off);
351 vm_munmap(map_addr+size, total_size-size);
353 map_addr =
vm_mmap(filep, addr, size, prot, type, off);
358 static unsigned long total_mapping_size(
struct elf_phdr *
cmds,
int nr)
360 int i, first_idx = -1, last_idx = -1;
362 for (i = 0; i <
nr; i++) {
363 if (cmds[i].p_type ==
PT_LOAD) {
372 return cmds[last_idx].p_vaddr + cmds[last_idx].p_memsz -
382 static unsigned long load_elf_interp(
struct elfhdr *interp_elf_ex,
383 struct file *interpreter,
unsigned long *interp_map_addr,
384 unsigned long no_base)
388 unsigned long load_addr = 0;
389 int load_addr_set = 0;
390 unsigned long last_bss = 0, elf_bss = 0;
396 if (interp_elf_ex->e_type !=
ET_EXEC &&
397 interp_elf_ex->e_type !=
ET_DYN)
401 if (!interpreter->
f_op || !interpreter->
f_op->mmap)
408 if (interp_elf_ex->e_phentsize !=
sizeof(
struct elf_phdr))
410 if (interp_elf_ex->e_phnum < 1 ||
411 interp_elf_ex->e_phnum > 65536
U /
sizeof(
struct elf_phdr))
415 size =
sizeof(
struct elf_phdr) * interp_elf_ex->e_phnum;
422 retval =
kernel_read(interpreter, interp_elf_ex->e_phoff,
423 (
char *)elf_phdata, size);
425 if (retval != size) {
431 total_size = total_mapping_size(elf_phdata, interp_elf_ex->e_phnum);
438 for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
439 if (eppnt->p_type ==
PT_LOAD) {
442 unsigned long vaddr = 0;
443 unsigned long k, map_addr;
445 if (eppnt->p_flags &
PF_R)
447 if (eppnt->p_flags &
PF_W)
449 if (eppnt->p_flags &
PF_X)
451 vaddr = eppnt->p_vaddr;
452 if (interp_elf_ex->e_type ==
ET_EXEC || load_addr_set)
454 else if (no_base && interp_elf_ex->e_type ==
ET_DYN)
457 map_addr = elf_map(interpreter, load_addr + vaddr,
458 eppnt, elf_prot, elf_type, total_size);
460 if (!*interp_map_addr)
461 *interp_map_addr = map_addr;
466 if (!load_addr_set &&
467 interp_elf_ex->e_type ==
ET_DYN) {
477 k = load_addr + eppnt->p_vaddr;
479 eppnt->p_filesz > eppnt->p_memsz ||
490 k = load_addr + eppnt->p_vaddr + eppnt->p_filesz;
498 k = load_addr + eppnt->p_memsz + eppnt->p_vaddr;
504 if (last_bss > elf_bss) {
511 if (padzero(elf_bss)) {
520 error =
vm_brk(elf_bss, last_bss - elf_bss);
538 #define INTERPRETER_NONE 0
539 #define INTERPRETER_ELF 2
541 #ifndef STACK_RND_MASK
542 #define STACK_RND_MASK (0x7ff >> (PAGE_SHIFT - 12))
545 static unsigned long randomize_stack_top(
unsigned long stack_top)
547 unsigned int random_variable = 0;
554 #ifdef CONFIG_STACK_GROWSUP
555 return PAGE_ALIGN(stack_top) + random_variable;
557 return PAGE_ALIGN(stack_top) - random_variable;
564 unsigned long load_addr = 0, load_bias = 0;
565 int load_addr_set = 0;
566 char * elf_interpreter =
NULL;
568 struct elf_phdr *elf_ppnt, *elf_phdata;
569 unsigned long elf_bss, elf_brk;
572 unsigned long elf_entry;
573 unsigned long interp_load_addr = 0;
574 unsigned long start_code, end_code, start_data, end_data;
577 unsigned long def_flags = 0;
580 struct elfhdr interp_elf_ex;
601 if (!bprm->
file->f_op || !bprm->
file->f_op->mmap)
605 if (
loc->elf_ex.e_phentsize !=
sizeof(
struct elf_phdr))
607 if (
loc->elf_ex.e_phnum < 1 ||
610 size =
loc->elf_ex.e_phnum *
sizeof(
struct elf_phdr);
617 (
char *)elf_phdata, size);
618 if (retval != size) {
624 elf_ppnt = elf_phdata;
633 for (i = 0; i <
loc->elf_ex.e_phnum; i++) {
640 if (elf_ppnt->p_filesz >
PATH_MAX ||
641 elf_ppnt->p_filesz < 2)
645 elf_interpreter =
kmalloc(elf_ppnt->p_filesz,
647 if (!elf_interpreter)
653 if (retval != elf_ppnt->p_filesz) {
656 goto out_free_interp;
660 if (elf_interpreter[elf_ppnt->p_filesz - 1] !=
'\0')
661 goto out_free_interp;
663 interpreter =
open_exec(elf_interpreter);
664 retval = PTR_ERR(interpreter);
665 if (IS_ERR(interpreter))
666 goto out_free_interp;
680 goto out_free_dentry;
690 elf_ppnt = elf_phdata;
691 for (i = 0; i <
loc->elf_ex.e_phnum; i++, elf_ppnt++)
693 if (elf_ppnt->p_flags &
PF_X)
701 if (elf_interpreter) {
705 goto out_free_dentry;
708 goto out_free_dentry;
714 goto out_free_dentry;
717 current->mm->def_flags = def_flags;
733 current->mm->cached_hole_size = 0;
738 goto out_free_dentry;
745 for(i = 0, elf_ppnt = elf_phdata;
746 i <
loc->elf_ex.e_phnum; i++, elf_ppnt++) {
747 int elf_prot = 0, elf_flags;
750 if (elf_ppnt->p_type !=
PT_LOAD)
759 retval = set_brk(elf_bss + load_bias,
760 elf_brk + load_bias);
763 goto out_free_dentry;
768 if (nbyte > elf_brk - elf_bss)
769 nbyte = elf_brk - elf_bss;
781 if (elf_ppnt->p_flags &
PF_R)
783 if (elf_ppnt->p_flags &
PF_W)
785 if (elf_ppnt->p_flags &
PF_X)
790 vaddr = elf_ppnt->p_vaddr;
791 if (
loc->elf_ex.e_type ==
ET_EXEC || load_addr_set) {
793 }
else if (
loc->elf_ex.e_type ==
ET_DYN) {
798 #ifdef CONFIG_ARCH_BINFMT_ELF_RANDOMIZE_PIE
814 error = elf_map(bprm->
file, load_bias + vaddr, elf_ppnt,
815 elf_prot, elf_flags, 0);
818 retval = IS_ERR((
void *)error) ?
819 PTR_ERR((
void*)error) : -
EINVAL;
820 goto out_free_dentry;
823 if (!load_addr_set) {
825 load_addr = (elf_ppnt->p_vaddr - elf_ppnt->p_offset);
829 load_addr += load_bias;
830 reloc_func_desc = load_bias;
833 k = elf_ppnt->p_vaddr;
844 if (
BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
850 goto out_free_dentry;
853 k = elf_ppnt->p_vaddr + elf_ppnt->p_filesz;
857 if ((elf_ppnt->p_flags &
PF_X) && end_code < k)
861 k = elf_ppnt->p_vaddr + elf_ppnt->p_memsz;
866 loc->elf_ex.e_entry += load_bias;
867 elf_bss += load_bias;
868 elf_brk += load_bias;
869 start_code += load_bias;
870 end_code += load_bias;
871 start_data += load_bias;
872 end_data += load_bias;
879 retval = set_brk(elf_bss, elf_brk);
882 goto out_free_dentry;
887 goto out_free_dentry;
890 if (elf_interpreter) {
891 unsigned long interp_map_addr = 0;
893 elf_entry = load_elf_interp(&
loc->interp_elf_ex,
897 if (!IS_ERR((
void *)elf_entry)) {
902 interp_load_addr = elf_entry;
903 elf_entry +=
loc->interp_elf_ex.e_entry;
907 retval = IS_ERR((
void *)elf_entry) ?
909 goto out_free_dentry;
911 reloc_func_desc = interp_load_addr;
913 allow_write_access(interpreter);
915 kfree(elf_interpreter);
917 elf_entry =
loc->elf_ex.e_entry;
921 goto out_free_dentry;
929 #ifdef ARCH_HAS_SETUP_ADDITIONAL_PAGES
938 retval = create_elf_tables(bprm, &
loc->elf_ex,
939 load_addr, interp_load_addr);
945 current->mm->end_code = end_code;
946 current->mm->start_code = start_code;
947 current->mm->start_data = start_data;
948 current->mm->end_data = end_data;
951 #ifdef arch_randomize_brk
955 #ifdef CONFIG_COMPAT_BRK
993 allow_write_access(interpreter);
997 kfree(elf_interpreter);
1005 static int load_elf_library(
struct file *
file)
1009 unsigned long elf_bss, bss,
len;
1014 retval =
kernel_read(file, 0, (
char *)&elf_ex,
sizeof(elf_ex));
1015 if (retval !=
sizeof(elf_ex))
1022 if (elf_ex.e_type !=
ET_EXEC || elf_ex.e_phnum > 2 ||
1028 j =
sizeof(
struct elf_phdr) * elf_ex.e_phnum;
1038 retval =
kernel_read(file, elf_ex.e_phoff, (
char *)eppnt, j);
1042 for (j = 0, i = 0; i<elf_ex.e_phnum; i++)
1043 if ((eppnt + i)->p_type ==
PT_LOAD)
1048 while (eppnt->p_type !=
PT_LOAD)
1063 elf_bss = eppnt->p_vaddr + eppnt->p_filesz;
1064 if (padzero(elf_bss)) {
1071 bss = eppnt->p_memsz + eppnt->p_vaddr;
1082 #ifdef CONFIG_ELF_CORE
1117 unsigned long mm_flags)
1119 #define FILTER(type) (mm_flags & (1UL << MMF_DUMP_##type))
1122 if (always_dump_vma(vma))
1142 if (vma->
vm_file->f_path.dentry->d_inode->i_nlink == 0 ?
1154 if (
FILTER(MAPPED_PRIVATE))
1162 if (
FILTER(ELF_HEADERS) &&
1219 #define DUMP_WRITE(addr, nr, foffset) \
1220 do { if (!dump_write(file, (addr), (nr))) return 0; *foffset += (nr); } while(0)
1222 static int alignfile(
struct file *file, loff_t *foffset)
1224 static const char buf[4] = { 0, };
1229 static int writenote(
struct memelfnote *men,
struct file *file,
1234 en.n_descsz = men->
datasz;
1235 en.n_type = men->
type;
1239 if (!alignfile(file, foffset))
1242 if (!alignfile(file, foffset))
1249 static void fill_elf_header(
struct elfhdr *elf,
int segs,
1252 memset(elf, 0,
sizeof(*elf));
1263 elf->e_phoff =
sizeof(
struct elfhdr);
1264 elf->e_flags =
flags;
1265 elf->e_ehsize =
sizeof(
struct elfhdr);
1266 elf->e_phentsize =
sizeof(
struct elf_phdr);
1267 elf->e_phnum = segs;
1272 static void fill_elf_note_phdr(
struct elf_phdr *phdr,
int sz, loff_t
offset)
1278 phdr->p_filesz = sz;
1285 static void fill_note(
struct memelfnote *note,
const char *
name,
int type,
1286 unsigned int sz,
void *
data)
1299 static void fill_prstatus(
struct elf_prstatus *prstatus,
1308 prstatus->
pr_pid = task_pid_vnr(p);
1309 prstatus->
pr_pgrp = task_pgrp_vnr(p);
1310 prstatus->
pr_sid = task_session_vnr(p);
1311 if (thread_group_leader(p)) {
1333 unsigned int i, len;
1342 (
const char __user *)mm->
arg_start, len))
1344 for(i = 0; i < len; i++)
1352 psinfo->
pr_pid = task_pid_vnr(p);
1353 psinfo->
pr_pgrp = task_pgrp_vnr(p);
1354 psinfo->
pr_sid = task_session_vnr(p);
1358 psinfo->
pr_sname = (i > 5) ?
'.' :
"RSDTZW"[i];
1378 while (auxv[i - 2] !=
AT_NULL);
1389 fill_note(note,
"CORE",
NT_SIGINFO,
sizeof(*csigdata), csigdata);
1392 #define MAX_FILE_NOTE_SIZE (4*1024*1024)
1404 static void fill_files_note(
struct memelfnote *note)
1407 unsigned count,
size, names_ofs, remaining,
n;
1410 char *name_base, *name_curpos;
1413 count =
current->mm->map_count;
1416 names_ofs = (2 + 3 *
count) *
sizeof(data[0]);
1418 if (size >= MAX_FILE_NOTE_SIZE)
1425 start_end_ofs = data + 2;
1426 name_base = name_curpos = ((
char *)data) + names_ofs;
1427 remaining = size - names_ofs;
1436 filename =
d_path(&file->
f_path, name_curpos, remaining);
1437 if (IS_ERR(filename)) {
1440 size = size * 5 / 4;
1448 n = (name_curpos + remaining) - filename;
1449 remaining = filename - name_curpos;
1450 memmove(name_curpos, filename, n);
1454 *start_end_ofs++ = vma->
vm_end;
1468 unsigned shift_bytes = n * 3 *
sizeof(data[0]);
1469 memmove(name_base - shift_bytes, name_base,
1470 name_curpos - name_base);
1471 name_curpos -= shift_bytes;
1474 size = name_curpos - (
char *)data;
1475 fill_note(note,
"CORE",
NT_FILE, size, data);
1479 #ifdef CORE_DUMP_USE_REGSET
1482 struct elf_thread_core_info {
1483 struct elf_thread_core_info *
next;
1489 struct elf_note_info {
1490 struct elf_thread_core_info *
thread;
1513 #define PR_REG_SIZE(S) sizeof(S)
1516 #ifndef PRSTATUS_SIZE
1517 #define PRSTATUS_SIZE(S) sizeof(S)
1521 #define PR_REG_PTR(S) (&((S)->pr_reg))
1524 #ifndef SET_PR_FPVALID
1525 #define SET_PR_FPVALID(S, V) ((S)->pr_fpvalid = (V))
1528 static int fill_thread_core_info(
struct elf_thread_core_info *
t,
1530 long signr,
size_t *total)
1540 fill_prstatus(&t->prstatus, t->task, signr);
1542 0, PR_REG_SIZE(t->prstatus.pr_reg),
1543 PR_REG_PTR(&t->prstatus),
NULL);
1546 PRSTATUS_SIZE(t->prstatus), &t->prstatus);
1547 *total += notesize(&t->notes[0]);
1549 do_thread_regset_writeback(t->task, &view->
regsets[0]);
1556 for (i = 1; i < view->
n; ++
i) {
1558 do_thread_regset_writeback(t->task, regset);
1560 (!regset->
active || regset->
active(t->task, regset))) {
1562 size_t size = regset->
n * regset->
size;
1566 ret = regset->
get(t->task, regset,
1567 0, size, data,
NULL);
1572 fill_note(&t->notes[i],
"LINUX",
1576 SET_PR_FPVALID(&t->prstatus, 1);
1577 fill_note(&t->notes[i],
"CORE",
1580 *total += notesize(&t->notes[i]);
1588 static int fill_note_info(
struct elfhdr *elf,
int phdrs,
1589 struct elf_note_info *
info,
1594 struct elf_thread_core_info *
t;
1600 info->thread =
NULL;
1606 fill_note(&info->psinfo,
"CORE",
NT_PRPSINFO,
sizeof(*psinfo), psinfo);
1611 info->thread_notes = 0;
1612 for (i = 0; i < view->
n; ++
i)
1613 if (view->
regsets[i].core_note_type != 0)
1614 ++info->thread_notes;
1620 if (
unlikely(info->thread_notes == 0) ||
1629 fill_elf_header(elf, phdrs,
1635 for (ct = &dump_task->
mm->core_state->dumper; ct; ct = ct->
next) {
1636 t = kzalloc(
offsetof(
struct elf_thread_core_info,
1637 notes[info->thread_notes]),
1643 if (ct->
task == dump_task || !info->thread) {
1644 t->next = info->thread;
1651 t->next = info->thread->next;
1652 info->thread->next =
t;
1659 for (t = info->thread; t !=
NULL; t = t->next)
1660 if (!fill_thread_core_info(t, view, siginfo->
si_signo, &info->size))
1667 info->size += notesize(&info->psinfo);
1669 fill_siginfo_note(&info->signote, &info->csigdata, siginfo);
1670 info->size += notesize(&info->signote);
1672 fill_auxv_note(&info->auxv,
current->mm);
1673 info->size += notesize(&info->auxv);
1675 fill_files_note(&info->files);
1676 info->size += notesize(&info->files);
1681 static size_t get_note_info_size(
struct elf_note_info *info)
1690 static int write_note_info(
struct elf_note_info *info,
1691 struct file *file, loff_t *foffset)
1694 struct elf_thread_core_info *t = info->thread;
1699 if (!writenote(&t->notes[0], file, foffset))
1702 if (first && !writenote(&info->psinfo, file, foffset))
1704 if (first && !writenote(&info->signote, file, foffset))
1706 if (first && !writenote(&info->auxv, file, foffset))
1708 if (first && !writenote(&info->files, file, foffset))
1711 for (i = 1; i < info->thread_notes; ++
i)
1712 if (t->notes[i].data &&
1713 !writenote(&t->notes[i], file, foffset))
1723 static void free_note_info(
struct elf_note_info *info)
1725 struct elf_thread_core_info *
threads = info->thread;
1728 struct elf_thread_core_info *t =
threads;
1730 WARN_ON(t->notes[0].data && t->notes[0].data != &t->prstatus);
1731 for (i = 1; i < info->thread_notes; ++
i)
1732 kfree(t->notes[i].data);
1735 kfree(info->psinfo.data);
1736 vfree(info->files.data);
1742 struct elf_thread_status
1748 #ifdef ELF_CORE_COPY_XFPREGS
1760 static int elf_dump_thread_status(
long signr,
struct elf_thread_status *t)
1766 fill_prstatus(&t->prstatus, p, signr);
1767 elf_core_copy_task_regs(p, &t->prstatus.pr_reg);
1769 fill_note(&t->notes[0],
"CORE",
NT_PRSTATUS,
sizeof(t->prstatus),
1772 sz += notesize(&t->notes[0]);
1774 if ((t->prstatus.pr_fpvalid = elf_core_copy_task_fpregs(p,
NULL,
1776 fill_note(&t->notes[1],
"CORE",
NT_PRFPREG,
sizeof(t->fpu),
1779 sz += notesize(&t->notes[1]);
1782 #ifdef ELF_CORE_COPY_XFPREGS
1783 if (elf_core_copy_task_xfpregs(p, &t->xfpu)) {
1784 fill_note(&t->notes[2],
"LINUX", ELF_CORE_XFPREG_TYPE,
1785 sizeof(t->xfpu), &t->xfpu);
1787 sz += notesize(&t->notes[2]);
1793 struct elf_note_info {
1799 #ifdef ELF_CORE_COPY_XFPREGS
1803 int thread_status_size;
1807 static int elf_note_info_init(
struct elf_note_info *info)
1809 memset(info, 0,
sizeof(*info));
1810 INIT_LIST_HEAD(&info->thread_list);
1820 if (!info->prstatus)
1825 #ifdef ELF_CORE_COPY_XFPREGS
1833 static int fill_note_info(
struct elfhdr *elf,
int phdrs,
1834 struct elf_note_info *info,
1839 if (!elf_note_info_init(info))
1844 struct elf_thread_status *ets;
1846 for (ct =
current->mm->core_state->dumper.next;
1847 ct; ct = ct->
next) {
1852 ets->thread = ct->
task;
1853 list_add(&ets->list, &info->thread_list);
1860 sz = elf_dump_thread_status(siginfo->
si_signo, ets);
1861 info->thread_status_size += sz;
1865 memset(info->prstatus, 0,
sizeof(*info->prstatus));
1867 elf_core_copy_regs(&info->prstatus->pr_reg, regs);
1878 sizeof(*info->prstatus), info->prstatus);
1881 sizeof(*info->psinfo), info->psinfo);
1883 fill_siginfo_note(info->notes + 2, &info->csigdata, siginfo);
1884 fill_auxv_note(info->notes + 3,
current->mm);
1885 fill_files_note(info->notes + 4);
1890 info->prstatus->pr_fpvalid = elf_core_copy_task_fpregs(
current, regs,
1892 if (info->prstatus->pr_fpvalid)
1893 fill_note(info->notes + info->numnote++,
1894 "CORE",
NT_PRFPREG,
sizeof(*info->fpu), info->fpu);
1895 #ifdef ELF_CORE_COPY_XFPREGS
1896 if (elf_core_copy_task_xfpregs(
current, info->xfpu))
1897 fill_note(info->notes + info->numnote++,
1898 "LINUX", ELF_CORE_XFPREG_TYPE,
1899 sizeof(*info->xfpu), info->xfpu);
1905 static size_t get_note_info_size(
struct elf_note_info *info)
1910 for (i = 0; i < info->numnote; i++)
1911 sz += notesize(info->notes + i);
1913 sz += info->thread_status_size;
1918 static int write_note_info(
struct elf_note_info *info,
1919 struct file *file, loff_t *foffset)
1924 for (i = 0; i < info->numnote; i++)
1925 if (!writenote(info->notes + i, file, foffset))
1930 struct elf_thread_status *
tmp =
1933 for (i = 0; i < tmp->num_notes; i++)
1934 if (!writenote(&tmp->notes[i], file, foffset))
1941 static void free_note_info(
struct elf_note_info *info)
1943 while (!list_empty(&info->thread_list)) {
1944 struct list_head *tmp = info->thread_list.next;
1950 vfree(info->notes[4].data);
1952 kfree(info->prstatus);
1953 kfree(info->psinfo);
1956 #ifdef ELF_CORE_COPY_XFPREGS
1984 if (this_vma == gate_vma)
1989 static void fill_extnum_info(
struct elfhdr *elf,
struct elf_shdr *shdr4extnum,
1992 elf->e_shoff = e_shoff;
1993 elf->e_shentsize =
sizeof(*shdr4extnum);
1997 memset(shdr4extnum, 0,
sizeof(*shdr4extnum));
2000 shdr4extnum->sh_size = elf->e_shnum;
2001 shdr4extnum->sh_link = elf->e_shstrndx;
2002 shdr4extnum->sh_info = segs;
2005 static size_t elf_core_vma_data_size(
struct vm_area_struct *gate_vma,
2006 unsigned long mm_flags)
2011 for (vma = first_vma(
current, gate_vma); vma !=
NULL;
2012 vma = next_vma(vma, gate_vma))
2013 size += vma_dump_size(vma, mm_flags);
2032 loff_t
offset = 0, dataoff, foffset;
2033 struct elf_note_info info;
2059 segs =
current->mm->map_count;
2063 if (gate_vma !=
NULL)
2078 if (!fill_note_info(elf, e_phnum, &info, cprm->
siginfo, cprm->
regs))
2087 offset +=
sizeof(*elf);
2088 offset += segs *
sizeof(
struct elf_phdr);
2093 size_t sz = get_note_info_size(&info);
2101 fill_elf_note_phdr(phdr4note, sz, offset);
2107 offset += elf_core_vma_data_size(gate_vma, cprm->
mm_flags);
2115 fill_extnum_info(elf, shdr4extnum, e_shoff, segs);
2120 size +=
sizeof(*elf);
2124 size +=
sizeof(*phdr4note);
2125 if (size > cprm->
limit
2130 for (vma = first_vma(
current, gate_vma); vma !=
NULL;
2131 vma = next_vma(vma, gate_vma)) {
2138 phdr.p_filesz = vma_dump_size(vma, cprm->
mm_flags);
2140 offset += phdr.p_filesz;
2143 phdr.p_flags |=
PF_W;
2145 phdr.p_flags |=
PF_X;
2148 size +=
sizeof(phdr);
2149 if (size > cprm->
limit
2158 if (!write_note_info(&info, cprm->
file, &foffset))
2168 for (vma = first_vma(
current, gate_vma); vma !=
NULL;
2169 vma = next_vma(vma, gate_vma)) {
2179 page = get_dump_page(addr);
2181 void *kaddr =
kmap(page);
2198 size +=
sizeof(*shdr4extnum);
2199 if (size > cprm->
limit
2201 sizeof(*shdr4extnum)))
2209 free_note_info(&info);
2221 register_binfmt(&elf_format);