From: "Jan Beulich" Subject: Re: [PATCH v3 06/25] libelf-loader: introduce elf_load_image Date: Thu, 15 Dec 2011 16:54:01 +0000 Message-ID: <4EEA343902000078000684FC@nat28.tlf.novell.com> References: <1323966657-19790-6-git-send-email-stefano.stabellini@eu.citrix.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <1323966657-19790-6-git-send-email-stefano.stabellini@eu.citrix.com> Content-Disposition: inline List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: stefano.stabellini@eu.citrix.com Cc: xen-devel@lists.xensource.com, keir.xen@gmail.com, Ian Campbell , Tim.Deegan@citrix.com List-Id: xen-devel@lists.xenproject.org >>> On 15.12.11 at 17:30, wrote: > From: Stefano Stabellini > > Implement a new function, called elf_load_image, to perform the actually > copy of the elf image and clearing the padding. > The function is implemented as memcpy and memset when the library is > built as part of the tools, but it is implemented as raw_copy_to_guest and > raw_clear_guest when built as part of Xen, so that it can be safely called > with an HVM style dom0. > > > Changes in v3: > > - switch to raw_copy_to_guest and raw_clear_guest. > > > Changes in v2: > > - remove CONFIG_KERNEL_NO_RELOC. > > > Signed-off-by: Stefano Stabellini > Signed-off-by: Ian Campbell > Signed-off-by: Tim Deegan > --- > xen/common/libelf/libelf-loader.c | 17 +++++++++++++++-- > 1 files changed, 15 insertions(+), 2 deletions(-) > > diff --git a/xen/common/libelf/libelf-loader.c > b/xen/common/libelf/libelf-loader.c > index 1ccf7d3..d2cb5b3 100644 > --- a/xen/common/libelf/libelf-loader.c > +++ b/xen/common/libelf/libelf-loader.c > @@ -107,11 +107,25 @@ void elf_set_log(struct elf_binary *elf, > elf_log_callback *log_callback, > elf->log_caller_data = log_caller_data; > elf->verbose = verbose; > } > + > +static void elf_load_image(void *dst, const void *src, uint64_t filesz, > uint64_t memsz) > +{ > + memcpy(dst, src, filesz); > + memset(dst + filesz, 0, memsz - filesz); > +} > #else > +#include > + > void elf_set_verbose(struct elf_binary *elf) > { > elf->verbose = 1; > } > + > +static void elf_load_image(void *dst, const void *src, uint64_t filesz, > uint64_t memsz) > +{ > + raw_copy_to_guest(dst, src, filesz); > + raw_clear_guest(dst + filesz, memsz - filesz); I thought I had mentioned this already - calling user/guest access functions without checking their return value is bogus. Jan > +} > #endif > > /* Calculate the required additional kernel space for the elf image */ > @@ -256,8 +270,7 @@ void elf_load_binary(struct elf_binary *elf) > dest = elf_get_ptr(elf, paddr); > elf_msg(elf, "%s: phdr %" PRIu64 " at 0x%p -> 0x%p\n", > __func__, i, dest, dest + filesz); > - memcpy(dest, elf->image + offset, filesz); > - memset(dest + filesz, 0, memsz - filesz); > + elf_load_image(dest, elf->image + offset, filesz, memsz); > } > > elf_load_bsdsyms(elf); > -- > 1.7.2.5