All of lore.kernel.org
 help / color / mirror / Atom feed
From: Thanh-Lam NGUYEN <thanh-lam.nguyen@alcatel-lucent.com>
To: Alexander Viro <viro@zeniv.linux.org.uk>
Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] binfmt_elf.c: core file shrinking
Date: Fri, 14 Oct 2011 10:52:15 +0200	[thread overview]
Message-ID: <4E97F83F.6050501@alcatel-lucent.com> (raw)
In-Reply-To: <4E946279.8090800@alcatel-lucent.com>

Sorry for upping the patch,
as it is my first contribution I would like to know if there is any
problem with it.

Best regard
Thanh lam NGUYEN

On 11/10/2011 17:36, Thanh-Lam NGUYEN wrote:

> The vma_shrink function looks for the 1st allocated and the last
> allocated page. Only this part is dumped to the disk (the virual
> start address and the size are dupdated to reflect the new dumped
> information).
> 
> Signed-off-by: Thanh Lam NGUYEN <thanh-lam.nguyen@alcatel-lucent.com>
> Signed-off-by: Benjamin ZORES <Benjamin.Zores@alcatel-lucent.com>
> ---
>  linux/fs/binfmt_elf.c |   54
> ++++++++++++++++++++++++++++++++++++++++++++++----
>  1 file changed, 55 insertions(+), 4 deletions(-)
> 
> --- linux/fs/binfmt_elf.c
> +++ linux/fs/binfmt_elf.c
> @@ -1085,6 +1085,48 @@
>   * Jeremy Fitzhardinge <jeremy@sw.oz.au>
>   */
> 
> +/*
> + * Search for 1st and last allocated page from vma_start to vma_end.
> + * Update vma_start and vma_end to reflect the result.
> + */
> +void vma_shrink(struct vm_area_struct *vma, unsigned long *vma_start,
> +		unsigned long *vma_end)
> +{
> +	int allocated;
> +	unsigned long start, addr, end;
> +
> +	allocated = 0;
> +	start = end = *vma_start;
> +	for (addr = *vma_start; _addr < *vma_end; addr += PAGE_SIZE) {
> +		struct page *page;
> +		if (get_user_pages(current, current->mm, addr, 1, 0, 1,
> +				   &page, NULL) <= 0) {
> +			/* NO PAGE */
> +			if (!allocated)
> +				start = addr;
> +		} else {
> +			if (page == ZERO_PAGE(0)) {
> +				/* ZERO PAGE */
> +				if (!allocated)
> +					start = addr;
> +			} else {
> +				/* ALLOCATED PAGE */
> +				if (!allocated)
> +					start = addr;
> +				end = addr;
> +				allocated = 1;
> +			}
> +			page_cache_release(page);
> +		}
> +	}
> +	if (end < start)
> +		end = start;
> +	if (allocated)
> +		end += PAGE_SIZE;
> +	*vma_start = start;
> +	*vma_end = end;
> +}
> +
>  /*
>   * Decide what to dump of a segment, part, all or none.
>   */
> @@ -1980,13 +2022,19 @@ static int elf_core_dump(struct coredump_params
> *cprm)
>  	for (vma = first_vma(current, gate_vma); vma != NULL;
>  			vma = next_vma(vma, gate_vma)) {
>  		struct elf_phdr phdr;
> +		unsigned long start = vma->vm_start;
> +		unsigned long end = vma->vm_end;
>   		phdr.p_type = PT_LOAD;
>  		phdr.p_offset = offset;
> -		phdr.p_vaddr = vma->vm_start;
>  		phdr.p_paddr = 0;
>  		phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags);
> -		phdr.p_memsz = vma->vm_end - vma->vm_start;
> +		if (phdr.p_filesz) {
> +			vma_shrink(vma, &start, &end);
> +			phdr.p_filesz = end-start;
> +		}
> +		phdr.p_vaddr = start;
> +		phdr.p_memsz = vma->vm_end - phdr.p_vaddr;
>  		offset += phdr.p_filesz;
>  		phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
>  		if (vma->vm_flags & VM_WRITE)
> @@ -2018,11 +2066,15 @@ static int elf_core_dump(struct coredump_params
> *cprm)
>  	for (vma = first_vma(current, gate_vma); vma != NULL;
>  			vma = next_vma(vma, gate_vma)) {
>  		unsigned long addr;
> +		unsigned long start;
>  		unsigned long end;
>  -		end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags);
> +		start = vma->vm_start;
> +		end = start + vma_dump_size(vma, cprm->mm_flags);
> +		if (start < end)
> +			vma_shrink(vma, &start, &end);
>  -		for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
> +		for (addr = start; addr < end; addr += PAGE_SIZE) {
>  			struct page *page;
>  			int stop;
> 
> ---
> =~=~=~=~=~=~=~=~=~=~=~=~==~=~=~=~=~=~=~=~=~=~=~=~=~=~=
> Thanh lam NGUYEN
> Prestataire externe ALTEN        | ALTEN Subcontractor
> pour ALCATEL-LUCENT              | in ALCATEL-LUCENT
> 
> email: tlnguyen@webmail.alten.fr
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at  http://www.tux.org/lkml/
> 



-- 
=~=~=~=~=~=~=~=~=~=~=~=~==~=~=~=~=~=~=~=~=~=~=~=~=~=~=
Thanh lam NGUYEN
Prestataire externe ALTEN        | ALTEN Subcontractor
pour ALCATEL-LUCENT              | in ALCATEL-LUCENT

Tel: +333906 77095

Equipe/Team: SWINT
email: tlnguyen@webmail.alten.fr

  reply	other threads:[~2011-10-14  8:52 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-10-11 15:36 [PATCH] binfmt_elf.c: core file shrinking Thanh-Lam NGUYEN
2011-10-14  8:52 ` Thanh-Lam NGUYEN [this message]
2011-10-14 14:45   ` Hillf Danton
2011-10-14 15:04     ` Thanh-Lam NGUYEN
2011-10-18  7:52 ` Thanh-Lam NGUYEN

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4E97F83F.6050501@alcatel-lucent.com \
    --to=thanh-lam.nguyen@alcatel-lucent.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=viro@zeniv.linux.org.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.