Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

convert the rest of binfmt_elf_fdpic to dump_emit()

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>

Al Viro e6c1baa9 13046ece

+33 -81
+33 -81
fs/binfmt_elf_fdpic.c
··· 1267 1267 1268 1268 /* #define DEBUG */ 1269 1269 1270 - #define DUMP_WRITE(addr, nr, foffset) \ 1271 - do { if (!dump_write(file, (addr), (nr))) return 0; *foffset += (nr); } while(0) 1272 - 1273 - static int alignfile(struct file *file, loff_t *foffset) 1270 + static int alignfile(struct coredump_params *cprm) 1274 1271 { 1275 1272 static const char buf[4] = { 0, }; 1276 - DUMP_WRITE(buf, roundup(*foffset, 4) - *foffset, foffset); 1277 - return 1; 1273 + return dump_emit(cprm, buf, roundup(cprm->written, 4) - cprm->written); 1278 1274 } 1279 1275 1280 - static int writenote(struct memelfnote *men, struct file *file, 1281 - loff_t *foffset) 1276 + static int writenote(struct memelfnote *men, struct coredump_params *cprm) 1282 1277 { 1283 1278 struct elf_note en; 1284 1279 en.n_namesz = strlen(men->name) + 1; 1285 1280 en.n_descsz = men->datasz; 1286 1281 en.n_type = men->type; 1287 1282 1288 - DUMP_WRITE(&en, sizeof(en), foffset); 1289 - DUMP_WRITE(men->name, en.n_namesz, foffset); 1290 - if (!alignfile(file, foffset)) 1291 - return 0; 1292 - DUMP_WRITE(men->data, men->datasz, foffset); 1293 - if (!alignfile(file, foffset)) 1294 - return 0; 1295 - 1296 - return 1; 1283 + return dump_emit(cprm, &en, sizeof(en)) && 1284 + dump_emit(cprm, men->name, en.n_namesz) && alignfile(cprm) && 1285 + dump_emit(cprm, men->data, men->datasz) && alignfile(cprm); 1297 1286 } 1298 - #undef DUMP_WRITE 1299 1287 1300 1288 static inline void fill_elf_fdpic_header(struct elfhdr *elf, int segs) 1301 1289 { ··· 1488 1500 /* 1489 1501 * dump the segments for an MMU process 1490 1502 */ 1491 - #ifdef CONFIG_MMU 1492 - static int elf_fdpic_dump_segments(struct file *file, size_t *size, 1493 - unsigned long *limit, unsigned long mm_flags) 1503 + static bool elf_fdpic_dump_segments(struct coredump_params *cprm) 1494 1504 { 1495 1505 struct vm_area_struct *vma; 1496 - int err = 0; 1497 1506 1498 1507 for (vma = current->mm->mmap; vma; vma = vma->vm_next) { 1499 1508 unsigned long addr; 1500 1509 1501 - if (!maydump(vma, mm_flags)) 1510 + if (!maydump(vma, cprm->mm_flags)) 1502 1511 continue; 1503 1512 1513 + #ifdef CONFIG_MMU 1504 1514 for (addr = vma->vm_start; addr < vma->vm_end; 1505 1515 addr += PAGE_SIZE) { 1516 + bool res; 1506 1517 struct page *page = get_dump_page(addr); 1507 1518 if (page) { 1508 1519 void *kaddr = kmap(page); 1509 - *size += PAGE_SIZE; 1510 - if (*size > *limit) 1511 - err = -EFBIG; 1512 - else if (!dump_write(file, kaddr, PAGE_SIZE)) 1513 - err = -EIO; 1520 + res = dump_emit(cprm, kaddr, PAGE_SIZE); 1514 1521 kunmap(page); 1515 1522 page_cache_release(page); 1516 - } else if (!dump_seek(file, PAGE_SIZE)) 1517 - err = -EFBIG; 1518 - if (err) 1519 - goto out; 1523 + } else { 1524 + res = dump_seek(file, PAGE_SIZE); 1525 + } 1526 + if (!res) 1527 + return false; 1520 1528 } 1521 - } 1522 - out: 1523 - return err; 1524 - } 1525 - #endif 1526 - 1527 - /* 1528 - * dump the segments for a NOMMU process 1529 - */ 1530 - #ifndef CONFIG_MMU 1531 - static int elf_fdpic_dump_segments(struct file *file, size_t *size, 1532 - unsigned long *limit, unsigned long mm_flags) 1533 - { 1534 - struct vm_area_struct *vma; 1535 - 1536 - for (vma = current->mm->mmap; vma; vma = vma->vm_next) { 1537 - if (!maydump(vma, mm_flags)) 1538 - continue; 1539 - 1540 - if ((*size += PAGE_SIZE) > *limit) 1541 - return -EFBIG; 1542 - 1543 - if (!dump_write(file, (void *) vma->vm_start, 1529 + #else 1530 + if (!dump_emit(cprm, (void *) vma->vm_start, 1544 1531 vma->vm_end - vma->vm_start)) 1545 - return -EIO; 1546 - } 1547 - 1548 - return 0; 1549 - } 1532 + return false; 1550 1533 #endif 1534 + } 1535 + return true; 1536 + } 1551 1537 1552 1538 static size_t elf_core_vma_data_size(unsigned long mm_flags) 1553 1539 { ··· 1717 1755 1718 1756 offset = dataoff; 1719 1757 1720 - size += sizeof(*elf); 1721 - if (size > cprm->limit || !dump_write(cprm->file, elf, sizeof(*elf))) 1758 + if (!dump_emit(cprm, elf, sizeof(*elf))) 1722 1759 goto end_coredump; 1723 1760 1724 - size += sizeof(*phdr4note); 1725 - if (size > cprm->limit 1726 - || !dump_write(cprm->file, phdr4note, sizeof(*phdr4note))) 1761 + if (!dump_emit(cprm, phdr4note, sizeof(*phdr4note))) 1727 1762 goto end_coredump; 1728 1763 1729 1764 /* write program headers for segments dump */ ··· 1744 1785 phdr.p_flags |= PF_X; 1745 1786 phdr.p_align = ELF_EXEC_PAGESIZE; 1746 1787 1747 - size += sizeof(phdr); 1748 - if (size > cprm->limit 1749 - || !dump_write(cprm->file, &phdr, sizeof(phdr))) 1788 + if (!dump_emit(cprm, &phdr, sizeof(phdr))) 1750 1789 goto end_coredump; 1751 1790 } 1752 1791 1753 - cprm->written = size; 1754 1792 if (!elf_core_write_extra_phdrs(cprm, offset)) 1755 1793 goto end_coredump; 1756 1794 1757 1795 size = cprm->written; 1796 + cprm->written = foffset; 1758 1797 /* write out the notes section */ 1759 1798 for (i = 0; i < numnote; i++) 1760 - if (!writenote(notes + i, cprm->file, &foffset)) 1799 + if (!writenote(notes + i, cprm)) 1761 1800 goto end_coredump; 1762 1801 1763 1802 /* write out the thread status notes section */ ··· 1764 1807 list_entry(t, struct elf_thread_status, list); 1765 1808 1766 1809 for (i = 0; i < tmp->num_notes; i++) 1767 - if (!writenote(&tmp->notes[i], cprm->file, &foffset)) 1810 + if (!writenote(&tmp->notes[i], cprm)) 1768 1811 goto end_coredump; 1769 1812 } 1770 1813 1771 - if (!dump_seek(cprm->file, dataoff - foffset)) 1772 - goto end_coredump; 1773 - 1774 - if (elf_fdpic_dump_segments(cprm->file, &size, &cprm->limit, 1775 - cprm->mm_flags) < 0) 1814 + if (!dump_seek(cprm->file, dataoff - cprm->written)) 1776 1815 goto end_coredump; 1777 1816 1778 1817 cprm->written = size; 1818 + if (!elf_fdpic_dump_segments(cprm)) 1819 + goto end_coredump; 1820 + 1779 1821 if (!elf_core_write_extra_data(cprm)) 1780 1822 goto end_coredump; 1781 - size = cprm->written; 1782 1823 1783 1824 if (e_phnum == PN_XNUM) { 1784 - size += sizeof(*shdr4extnum); 1785 - if (size > cprm->limit 1786 - || !dump_write(cprm->file, shdr4extnum, 1787 - sizeof(*shdr4extnum))) 1825 + if (!dump_emit(cprm, shdr4extnum, sizeof(*shdr4extnum))) 1788 1826 goto end_coredump; 1789 1827 } 1790 1828