From mboxrd@z Thu Jan 1 00:00:00 1970 From: Ross Lagerwall Subject: Re: [PATCH v2 08/13] xsplice: Implement payload loading (v2) Date: Tue, 19 Jan 2016 16:45:09 +0000 Message-ID: <569E6815.2060806@citrix.com> References: <1452808031-706-1-git-send-email-konrad.wilk@oracle.com> <1452808031-706-9-git-send-email-konrad.wilk@oracle.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii"; Format="flowed" Content-Transfer-Encoding: 7bit Return-path: Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1aLZP7-0006JT-Di for xen-devel@lists.xenproject.org; Tue, 19 Jan 2016 16:45:13 +0000 In-Reply-To: <1452808031-706-9-git-send-email-konrad.wilk@oracle.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: Konrad Rzeszutek Wilk , xen-devel@lists.xenproject.org, mpohlack@amazon.com, andrew.cooper3@citrix.com, stefano.stabellini@citrix.com, jbeulich@suse.com, ian.jackson@eu.citrix.com, ian.campbell@citrix.com, wei.liu2@citrix.com, sasha.levin@oracle.com List-Id: xen-devel@lists.xenproject.org On 01/14/2016 09:47 PM, Konrad Rzeszutek Wilk wrote: snip > +static int move_payload(struct payload *payload, struct xsplice_elf *elf) > +{ > + uint8_t *buf; > + unsigned int i; > + size_t core_size = 0; > + > + /* Compute text regions */ > + for ( i = 0; i < elf->hdr->e_shnum; i++ ) > + { > + if ( (elf->sec[i].sec->sh_flags & (SHF_ALLOC|SHF_EXECINSTR)) == > + (SHF_ALLOC|SHF_EXECINSTR) ) > + calc_section(&elf->sec[i], &core_size); > + } > + > + /* Compute rw data */ > + for ( i = 0; i < elf->hdr->e_shnum; i++ ) > + { > + if ( (elf->sec[i].sec->sh_flags & SHF_ALLOC) && > + !(elf->sec[i].sec->sh_flags & SHF_EXECINSTR) && > + (elf->sec[i].sec->sh_flags & SHF_WRITE) ) > + calc_section(&elf->sec[i], &core_size); > + } > + > + /* Compute ro data */ > + for ( i = 0; i < elf->hdr->e_shnum; i++ ) > + { > + if ( (elf->sec[i].sec->sh_flags & SHF_ALLOC) && > + !(elf->sec[i].sec->sh_flags & SHF_EXECINSTR) && > + !(elf->sec[i].sec->sh_flags & SHF_WRITE) ) > + calc_section(&elf->sec[i], &core_size); > + } > + > + buf = alloc_payload(core_size); > + if ( !buf ) { > + printk(XENLOG_ERR "%s: Could not allocate memory for module\n", > + elf->name); > + return -ENOMEM; > + } > + memset(buf, 0, core_size); > + > + for ( i = 0; i < elf->hdr->e_shnum; i++ ) > + { > + if ( elf->sec[i].sec->sh_flags & SHF_ALLOC ) > + { > + elf->sec[i].load_addr = buf + elf->sec[i].sec->sh_entsize; > + memcpy(elf->sec[i].load_addr, elf->sec[i].data, > + elf->sec[i].sec->sh_size); > + printk(XENLOG_DEBUG "%s: Loaded %s at 0x%p\n", > + elf->name, elf->sec[i].name, elf->sec[i].load_addr); > + } > + } I found this bug a while back but didn't get round to pushing it anywhere. 8-<------------------------------------------------ commit 72803a4c765026c54f31988a4c689048c8723575 Author: Ross Lagerwall Date: Fri Nov 6 12:48:39 2015 +0000 Don't copy NOBITS sections (fixes BSS initialization) diff --git a/xen/common/xsplice.c b/xen/common/xsplice.c index 9450b2a..799ccb5 100644 --- a/xen/common/xsplice.c +++ b/xen/common/xsplice.c @@ -600,8 +600,9 @@ static int move_module(struct payload *payload, struct xsplice_elf *elf) if ( elf->sec[i].sec->sh_flags & SHF_ALLOC ) { elf->sec[i].load_addr = buf + elf->sec[i].sec->sh_entsize; - memcpy(elf->sec[i].load_addr, elf->sec[i].data, - elf->sec[i].sec->sh_size); + if ( elf->sec[i].sec->sh_type != SHT_NOBITS ) + memcpy(elf->sec[i].load_addr, elf->sec[i].data, + elf->sec[i].sec->sh_size); printk(XENLOG_DEBUG "Loaded %s at 0x%p\n", elf->sec[i].name, elf->sec[i].load_addr); } -- Ross Lagerwall