[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] Re: [Xen-devel] [PATCH v2 08/13] xsplice: Implement payload loading (v2)
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 <ross.lagerwall@xxxxxxxxxx> 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 _______________________________________________ Xen-devel mailing list Xen-devel@xxxxxxxxxxxxx http://lists.xen.org/xen-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |