mirror of
				https://github.com/torvalds/linux.git
				synced 2025-11-04 02:30:34 +02:00 
			
		
		
		
	dump_skip(): dump_seek() replacement taking coredump_params
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
This commit is contained in:
		
							parent
							
								
									2507a4fbd4
								
							
						
					
					
						commit
						9b56d54380
					
				
					 6 changed files with 22 additions and 43 deletions
				
			
		| 
						 | 
					@ -187,7 +187,7 @@ static int aout_core_dump(struct coredump_params *cprm)
 | 
				
			||||||
	if (!dump_emit(cprm, &dump, sizeof(dump)))
 | 
						if (!dump_emit(cprm, &dump, sizeof(dump)))
 | 
				
			||||||
		goto end_coredump;
 | 
							goto end_coredump;
 | 
				
			||||||
	/* Now dump all of the user data.  Include malloced stuff as well */
 | 
						/* Now dump all of the user data.  Include malloced stuff as well */
 | 
				
			||||||
	if (!dump_seek(cprm->file, PAGE_SIZE - sizeof(dump)))
 | 
						if (!dump_skip(cprm, PAGE_SIZE - sizeof(dump)))
 | 
				
			||||||
		goto end_coredump;
 | 
							goto end_coredump;
 | 
				
			||||||
	/* now we start writing out the user space info */
 | 
						/* now we start writing out the user space info */
 | 
				
			||||||
	set_fs(USER_DS);
 | 
						set_fs(USER_DS);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -87,7 +87,7 @@ static int aout_core_dump(struct coredump_params *cprm)
 | 
				
			||||||
	if (!dump_emit(cprm, &dump, sizeof(dump)))
 | 
						if (!dump_emit(cprm, &dump, sizeof(dump)))
 | 
				
			||||||
		goto end_coredump;
 | 
							goto end_coredump;
 | 
				
			||||||
/* Now dump all of the user data.  Include malloced stuff as well */
 | 
					/* Now dump all of the user data.  Include malloced stuff as well */
 | 
				
			||||||
	if (!dump_seek(cprm->file, PAGE_SIZE - sizeof(dump)))
 | 
						if (!dump_skip(cprm, PAGE_SIZE - sizeof(dump)))
 | 
				
			||||||
		goto end_coredump;
 | 
							goto end_coredump;
 | 
				
			||||||
/* now we start writing out the user space info */
 | 
					/* now we start writing out the user space info */
 | 
				
			||||||
	set_fs(USER_DS);
 | 
						set_fs(USER_DS);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -2162,7 +2162,7 @@ static int elf_core_dump(struct coredump_params *cprm)
 | 
				
			||||||
		goto end_coredump;
 | 
							goto end_coredump;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/* Align to page */
 | 
						/* Align to page */
 | 
				
			||||||
	if (!dump_seek(cprm->file, dataoff - cprm->written))
 | 
						if (!dump_skip(cprm, dataoff - cprm->written))
 | 
				
			||||||
		goto end_coredump;
 | 
							goto end_coredump;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	for (vma = first_vma(current, gate_vma); vma != NULL;
 | 
						for (vma = first_vma(current, gate_vma); vma != NULL;
 | 
				
			||||||
| 
						 | 
					@ -2183,7 +2183,7 @@ static int elf_core_dump(struct coredump_params *cprm)
 | 
				
			||||||
				kunmap(page);
 | 
									kunmap(page);
 | 
				
			||||||
				page_cache_release(page);
 | 
									page_cache_release(page);
 | 
				
			||||||
			} else
 | 
								} else
 | 
				
			||||||
				stop = !dump_seek(cprm->file, PAGE_SIZE);
 | 
									stop = !dump_skip(cprm, PAGE_SIZE);
 | 
				
			||||||
			if (stop)
 | 
								if (stop)
 | 
				
			||||||
				goto end_coredump;
 | 
									goto end_coredump;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1509,7 +1509,7 @@ static bool elf_fdpic_dump_segments(struct coredump_params *cprm)
 | 
				
			||||||
				kunmap(page);
 | 
									kunmap(page);
 | 
				
			||||||
				page_cache_release(page);
 | 
									page_cache_release(page);
 | 
				
			||||||
			} else {
 | 
								} else {
 | 
				
			||||||
				res = dump_seek(file, PAGE_SIZE);
 | 
									res = dump_skip(cprm, PAGE_SIZE);
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			if (!res)
 | 
								if (!res)
 | 
				
			||||||
				return false;
 | 
									return false;
 | 
				
			||||||
| 
						 | 
					@ -1547,11 +1547,10 @@ static int elf_fdpic_core_dump(struct coredump_params *cprm)
 | 
				
			||||||
	int has_dumped = 0;
 | 
						int has_dumped = 0;
 | 
				
			||||||
	mm_segment_t fs;
 | 
						mm_segment_t fs;
 | 
				
			||||||
	int segs;
 | 
						int segs;
 | 
				
			||||||
	size_t size = 0;
 | 
					 | 
				
			||||||
	int i;
 | 
						int i;
 | 
				
			||||||
	struct vm_area_struct *vma;
 | 
						struct vm_area_struct *vma;
 | 
				
			||||||
	struct elfhdr *elf = NULL;
 | 
						struct elfhdr *elf = NULL;
 | 
				
			||||||
	loff_t offset = 0, dataoff, foffset;
 | 
						loff_t offset = 0, dataoff;
 | 
				
			||||||
	int numnote;
 | 
						int numnote;
 | 
				
			||||||
	struct memelfnote *notes = NULL;
 | 
						struct memelfnote *notes = NULL;
 | 
				
			||||||
	struct elf_prstatus *prstatus = NULL;	/* NT_PRSTATUS */
 | 
						struct elf_prstatus *prstatus = NULL;	/* NT_PRSTATUS */
 | 
				
			||||||
| 
						 | 
					@ -1682,7 +1681,6 @@ static int elf_fdpic_core_dump(struct coredump_params *cprm)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	offset += sizeof(*elf);				/* Elf header */
 | 
						offset += sizeof(*elf);				/* Elf header */
 | 
				
			||||||
	offset += segs * sizeof(struct elf_phdr);	/* Program headers */
 | 
						offset += segs * sizeof(struct elf_phdr);	/* Program headers */
 | 
				
			||||||
	foffset = offset;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/* Write notes phdr entry */
 | 
						/* Write notes phdr entry */
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
| 
						 | 
					@ -1751,8 +1749,6 @@ static int elf_fdpic_core_dump(struct coredump_params *cprm)
 | 
				
			||||||
	if (!elf_core_write_extra_phdrs(cprm, offset))
 | 
						if (!elf_core_write_extra_phdrs(cprm, offset))
 | 
				
			||||||
		goto end_coredump;
 | 
							goto end_coredump;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	size = cprm->written;
 | 
					 | 
				
			||||||
	cprm->written = foffset;
 | 
					 | 
				
			||||||
 	/* write out the notes section */
 | 
					 	/* write out the notes section */
 | 
				
			||||||
	for (i = 0; i < numnote; i++)
 | 
						for (i = 0; i < numnote; i++)
 | 
				
			||||||
		if (!writenote(notes + i, cprm))
 | 
							if (!writenote(notes + i, cprm))
 | 
				
			||||||
| 
						 | 
					@ -1768,10 +1764,9 @@ static int elf_fdpic_core_dump(struct coredump_params *cprm)
 | 
				
			||||||
				goto end_coredump;
 | 
									goto end_coredump;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (!dump_seek(cprm->file, dataoff - cprm->written))
 | 
						if (!dump_skip(cprm, dataoff - cprm->written))
 | 
				
			||||||
		goto end_coredump;
 | 
							goto end_coredump;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	cprm->written = size;
 | 
					 | 
				
			||||||
	if (!elf_fdpic_dump_segments(cprm))
 | 
						if (!elf_fdpic_dump_segments(cprm))
 | 
				
			||||||
		goto end_coredump;
 | 
							goto end_coredump;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -685,14 +685,6 @@ void do_coredump(siginfo_t *siginfo)
 | 
				
			||||||
 * do on a core-file: use only these functions to write out all the
 | 
					 * do on a core-file: use only these functions to write out all the
 | 
				
			||||||
 * necessary info.
 | 
					 * necessary info.
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
int dump_write(struct file *file, const void *addr, int nr)
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
	return !dump_interrupted() &&
 | 
					 | 
				
			||||||
		access_ok(VERIFY_READ, addr, nr) &&
 | 
					 | 
				
			||||||
		file->f_op->write(file, addr, nr, &file->f_pos) == nr;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
EXPORT_SYMBOL(dump_write);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
int dump_emit(struct coredump_params *cprm, const void *addr, int nr)
 | 
					int dump_emit(struct coredump_params *cprm, const void *addr, int nr)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	struct file *file = cprm->file;
 | 
						struct file *file = cprm->file;
 | 
				
			||||||
| 
						 | 
					@ -714,32 +706,25 @@ int dump_emit(struct coredump_params *cprm, const void *addr, int nr)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
EXPORT_SYMBOL(dump_emit);
 | 
					EXPORT_SYMBOL(dump_emit);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int dump_seek(struct file *file, loff_t off)
 | 
					int dump_skip(struct coredump_params *cprm, size_t nr)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	int ret = 1;
 | 
						static char zeroes[PAGE_SIZE];
 | 
				
			||||||
 | 
						struct file *file = cprm->file;
 | 
				
			||||||
	if (file->f_op->llseek && file->f_op->llseek != no_llseek) {
 | 
						if (file->f_op->llseek && file->f_op->llseek != no_llseek) {
 | 
				
			||||||
 | 
							if (cprm->written + nr > cprm->limit)
 | 
				
			||||||
 | 
								return 0;
 | 
				
			||||||
		if (dump_interrupted() ||
 | 
							if (dump_interrupted() ||
 | 
				
			||||||
		    file->f_op->llseek(file, off, SEEK_CUR) < 0)
 | 
							    file->f_op->llseek(file, nr, SEEK_CUR) < 0)
 | 
				
			||||||
			return 0;
 | 
								return 0;
 | 
				
			||||||
 | 
							cprm->written += nr;
 | 
				
			||||||
 | 
							return 1;
 | 
				
			||||||
	} else {
 | 
						} else {
 | 
				
			||||||
		char *buf = (char *)get_zeroed_page(GFP_KERNEL);
 | 
							while (nr > PAGE_SIZE) {
 | 
				
			||||||
 | 
								if (!dump_emit(cprm, zeroes, PAGE_SIZE))
 | 
				
			||||||
		if (!buf)
 | 
									return 0;
 | 
				
			||||||
			return 0;
 | 
								nr -= PAGE_SIZE;
 | 
				
			||||||
		while (off > 0) {
 | 
					 | 
				
			||||||
			unsigned long n = off;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
			if (n > PAGE_SIZE)
 | 
					 | 
				
			||||||
				n = PAGE_SIZE;
 | 
					 | 
				
			||||||
			if (!dump_write(file, buf, n)) {
 | 
					 | 
				
			||||||
				ret = 0;
 | 
					 | 
				
			||||||
				break;
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
			off -= n;
 | 
					 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		free_page((unsigned long)buf);
 | 
							return dump_emit(cprm, zeroes, nr);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	return ret;
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
EXPORT_SYMBOL(dump_seek);
 | 
					EXPORT_SYMBOL(dump_skip);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -11,8 +11,7 @@
 | 
				
			||||||
 * functions to write out all the necessary info.
 | 
					 * functions to write out all the necessary info.
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
struct coredump_params;
 | 
					struct coredump_params;
 | 
				
			||||||
extern int dump_write(struct file *file, const void *addr, int nr);
 | 
					extern int dump_skip(struct coredump_params *cprm, size_t nr);
 | 
				
			||||||
extern int dump_seek(struct file *file, loff_t off);
 | 
					 | 
				
			||||||
extern int dump_emit(struct coredump_params *cprm, const void *addr, int nr);
 | 
					extern int dump_emit(struct coredump_params *cprm, const void *addr, int nr);
 | 
				
			||||||
#ifdef CONFIG_COREDUMP
 | 
					#ifdef CONFIG_COREDUMP
 | 
				
			||||||
extern void do_coredump(siginfo_t *siginfo);
 | 
					extern void do_coredump(siginfo_t *siginfo);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in a new issue