[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-devel] [PATCH RFC 06/25] libelf-loader: introduce elf_load_image and CONFIG_KERNEL_NO_RELOC
From: Stefano Stabellini <stefano.stabellini@xxxxxxxxxxxxx> 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 copy_to_user and clear_user when built as part of Xen, so that it can be safely called with an HVM style dom0. Introduce CONFIG_KERNEL_NO_RELOC: the dom0 kernel might not support being relocated to an address different of the one specified in the elf file. Signed-off-by: Stefano Stabellini <stefano.stabellini@xxxxxxxxxxxxx> Signed-off-by: Ian Campbell <ian.campbell@xxxxxxxxxx> Signed-off-by: Tim Deegan <Tim.Deegan@xxxxxxxxxx> --- xen/common/libelf/libelf-loader.c | 21 +++++++++++++++++++-- 1 files changed, 19 insertions(+), 2 deletions(-) diff --git a/xen/common/libelf/libelf-loader.c b/xen/common/libelf/libelf-loader.c index 1ccf7d3..21e3804 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 <asm/guest_access.h> + 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) +{ + copy_to_user(dst, src, filesz); + clear_user(dst + filesz, memsz - filesz); +} #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); @@ -265,7 +278,11 @@ void elf_load_binary(struct elf_binary *elf) void *elf_get_ptr(struct elf_binary *elf, unsigned long addr) { +#ifdef CONFIG_KERNEL_NO_RELOC + return elf->dest + addr; +#else return elf->dest + addr - elf->pstart; +#endif } uint64_t elf_lookup_addr(struct elf_binary * elf, const char *symbol) -- 1.7.2.5 _______________________________________________ Xen-devel mailing list Xen-devel@xxxxxxxxxxxxxxxxxxx http://lists.xensource.com/xen-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |