[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-changelog] [xen-unstable] libxc: Code format cleanups.
# HG changeset patch # User Keir Fraser <keir@xxxxxxxxxxxxx> # Date 1172331019 0 # Node ID c051ed67258a2b692f23ab6482e9b844a8fffbeb # Parent 59b8d5168cc1561326f6749c79ea879093e37b0c libxc: Code format cleanups. Signed-off-by: Keir Fraser <keir@xxxxxxxxxxxxx> --- tools/libxc/xc_dom.h | 44 +- tools/libxc/xc_dom_binloader.c | 73 +--- tools/libxc/xc_dom_boot.c | 458 +++++++++++++------------- tools/libxc/xc_dom_compat_linux.c | 125 +++---- tools/libxc/xc_dom_core.c | 647 +++++++++++++++++++------------------- tools/libxc/xc_dom_elfloader.c | 349 ++++++++++---------- tools/libxc/xc_dom_ia64.c | 40 +- tools/libxc/xc_dom_x86.c | 429 +++++++++++++------------ tools/libxc/xc_efi.h | 4 tools/libxc/xc_private.c | 2 tools/libxc/xg_private.c | 116 +++--- 11 files changed, 1190 insertions(+), 1097 deletions(-) diff -r 59b8d5168cc1 -r c051ed67258a tools/libxc/xc_dom.h --- a/tools/libxc/xc_dom.h Sat Feb 24 14:48:17 2007 +0000 +++ b/tools/libxc/xc_dom.h Sat Feb 24 15:30:19 2007 +0000 @@ -158,9 +158,9 @@ int xc_dom_kernel_file(struct xc_dom_ima int xc_dom_kernel_file(struct xc_dom_image *dom, const char *filename); int xc_dom_ramdisk_file(struct xc_dom_image *dom, const char *filename); int xc_dom_kernel_mem(struct xc_dom_image *dom, const void *mem, - size_t memsize); + size_t memsize); int xc_dom_ramdisk_mem(struct xc_dom_image *dom, const void *mem, - size_t memsize); + size_t memsize); int xc_dom_parse_image(struct xc_dom_image *dom); int xc_dom_build_image(struct xc_dom_image *dom); @@ -169,7 +169,7 @@ int xc_dom_boot_xen_init(struct xc_dom_i int xc_dom_boot_xen_init(struct xc_dom_image *dom, int xc, domid_t domid); int xc_dom_boot_mem_init(struct xc_dom_image *dom); void *xc_dom_boot_domU_map(struct xc_dom_image *dom, xen_pfn_t pfn, - xen_pfn_t count); + xen_pfn_t count); int xc_dom_boot_image(struct xc_dom_image *dom); int xc_dom_compat_check(struct xc_dom_image *dom); @@ -180,12 +180,12 @@ void xc_dom_loginit(void); void xc_dom_loginit(void); int xc_dom_printf(const char *fmt, ...) __attribute__ ((format(printf, 1, 2))); int xc_dom_panic_func(const char *file, int line, xc_error_code err, - const char *fmt, ...) + const char *fmt, ...) __attribute__ ((format(printf, 4, 5))); #define xc_dom_panic(err, fmt, args...) \ - xc_dom_panic_func(__FILE__, __LINE__, err, fmt, ## args) + xc_dom_panic_func(__FILE__, __LINE__, err, fmt, ## args) #define xc_dom_trace(mark) \ - xc_dom_printf("%s:%d: trace %s\n", __FILE__, __LINE__, mark) + xc_dom_printf("%s:%d: trace %s\n", __FILE__, __LINE__, mark) void xc_dom_log_memory_footprint(struct xc_dom_image *dom); @@ -194,25 +194,25 @@ void *xc_dom_malloc(struct xc_dom_image void *xc_dom_malloc(struct xc_dom_image *dom, size_t size); void *xc_dom_malloc_page_aligned(struct xc_dom_image *dom, size_t size); void *xc_dom_malloc_filemap(struct xc_dom_image *dom, - const char *filename, size_t * size); + const char *filename, size_t * size); char *xc_dom_strdup(struct xc_dom_image *dom, const char *str); /* --- alloc memory pool ------------------------------------------- */ int xc_dom_alloc_page(struct xc_dom_image *dom, char *name); int xc_dom_alloc_segment(struct xc_dom_image *dom, - struct xc_dom_seg *seg, char *name, - xen_vaddr_t start, xen_vaddr_t size); + struct xc_dom_seg *seg, char *name, + xen_vaddr_t start, xen_vaddr_t size); /* --- misc bits --------------------------------------------------- */ void *xc_dom_pfn_to_ptr(struct xc_dom_image *dom, xen_pfn_t first, - xen_pfn_t count); + xen_pfn_t count); void xc_dom_unmap_one(struct xc_dom_image *dom, xen_pfn_t pfn); void xc_dom_unmap_all(struct xc_dom_image *dom); static inline void *xc_dom_seg_to_ptr(struct xc_dom_image *dom, - struct xc_dom_seg *seg) + struct xc_dom_seg *seg) { xen_vaddr_t segsize = seg->vend - seg->vstart; unsigned int page_size = XC_DOM_PAGE_SIZE(dom); @@ -222,16 +222,13 @@ static inline void *xc_dom_seg_to_ptr(st } static inline void *xc_dom_vaddr_to_ptr(struct xc_dom_image *dom, - xen_vaddr_t vaddr) + xen_vaddr_t vaddr) { unsigned int page_size = XC_DOM_PAGE_SIZE(dom); xen_pfn_t page = (vaddr - dom->parms.virt_base) / page_size; unsigned int offset = (vaddr - dom->parms.virt_base) % page_size; void *ptr = xc_dom_pfn_to_ptr(dom, page, 0); - - if (!ptr) - return NULL; - return ptr + offset; + return (ptr ? (ptr + offset) : NULL); } static inline int xc_dom_feature_translated(struct xc_dom_image *dom) @@ -242,17 +239,26 @@ static inline xen_pfn_t xc_dom_p2m_host( static inline xen_pfn_t xc_dom_p2m_host(struct xc_dom_image *dom, xen_pfn_t pfn) { if (dom->shadow_enabled) - return pfn; + return pfn; return dom->p2m_host[pfn]; } static inline xen_pfn_t xc_dom_p2m_guest(struct xc_dom_image *dom, - xen_pfn_t pfn) + xen_pfn_t pfn) { if (xc_dom_feature_translated(dom)) - return pfn; + return pfn; return dom->p2m_host[pfn]; } /* --- arch bits --------------------------------------------------- */ +/* + * Local variables: + * mode: C + * c-set-style: "BSD" + * c-basic-offset: 4 + * tab-width: 4 + * indent-tabs-mode: nil + * End: + */ diff -r 59b8d5168cc1 -r c051ed67258a tools/libxc/xc_dom_binloader.c --- a/tools/libxc/xc_dom_binloader.c Sat Feb 24 14:48:17 2007 +0000 +++ b/tools/libxc/xc_dom_binloader.c Sat Feb 24 15:30:19 2007 +0000 @@ -95,7 +95,7 @@ struct xen_bin_image_table /* Flags we test for */ #define FLAGS_MASK ((~ 0) & (~ XEN_MULTIBOOT_FLAG_ALIGN4K) & \ - (~ XEN_MULTIBOOT_FLAG_PAE_MASK)) + (~ XEN_MULTIBOOT_FLAG_PAE_MASK)) #define FLAGS_REQUIRED XEN_MULTIBOOT_FLAG_ADDRSVALID /* --------------------------------------------------------------------- */ @@ -108,19 +108,17 @@ static struct xen_bin_image_table *find_ probe_ptr = dom->kernel_blob; probe_end = dom->kernel_blob + dom->kernel_size - sizeof(*table); - if ((void*)probe_end > dom->kernel_blob + 8192) + if ( (void*)probe_end > (dom->kernel_blob + 8192) ) probe_end = dom->kernel_blob + 8192; - for (table = NULL; probe_ptr < probe_end; probe_ptr++) - { - if (XEN_MULTIBOOT_MAGIC3 == *probe_ptr) + for ( table = NULL; probe_ptr < probe_end; probe_ptr++ ) + { + if ( *probe_ptr == XEN_MULTIBOOT_MAGIC3 ) { table = (struct xen_bin_image_table *) probe_ptr; /* Checksum correct? */ - if (0 == table->magic + table->flags + table->checksum) - { + if ( (table->magic + table->flags + table->checksum) == 0 ) return table; - } } } return NULL; @@ -128,12 +126,7 @@ static struct xen_bin_image_table *find_ static int xc_dom_probe_bin_kernel(struct xc_dom_image *dom) { - struct xen_bin_image_table *table; - - table = find_table(dom); - if (!table) - return -EINVAL; - return 0; + return find_table(dom) ? 0 : -EINVAL; } static int xc_dom_parse_bin_kernel(struct xc_dom_image *dom) @@ -147,7 +140,7 @@ static int xc_dom_parse_bin_kernel(struc uint32_t pae_flags; image_info = find_table(dom); - if (!image_info) + if ( !image_info ) return -EINVAL; xc_dom_printf("%s: multiboot header fields\n", __FUNCTION__); @@ -159,7 +152,7 @@ static int xc_dom_parse_bin_kernel(struc xc_dom_printf(" entry_addr: 0x%" PRIx32 "\n", image_info->entry_addr); /* Check the flags */ - if ( FLAGS_REQUIRED != (image_info->flags & FLAGS_MASK) ) + if ( (image_info->flags & FLAGS_MASK) != FLAGS_REQUIRED ) { xc_dom_panic(XC_INVALID_KERNEL, "%s: xen_bin_image_table flags required " @@ -169,7 +162,7 @@ static int xc_dom_parse_bin_kernel(struc } /* Sanity check on the addresses */ - if ( image_info->header_addr < image_info->load_addr || + if ( (image_info->header_addr < image_info->load_addr) || ((char *) image_info - image) < (image_info->header_addr - image_info->load_addr) ) { @@ -187,7 +180,7 @@ static int xc_dom_parse_bin_kernel(struc xc_dom_printf(" load_end_addr: 0x%" PRIx32 "\n", load_end_addr); xc_dom_printf(" bss_end_addr: 0x%" PRIx32 "\n", bss_end_addr); - if ( start_addr + image_size < load_end_addr ) + if ( (start_addr + image_size) < load_end_addr ) { xc_dom_panic(XC_INVALID_KERNEL, "%s: Invalid load_end_addr.\n", __FUNCTION__); @@ -209,25 +202,26 @@ static int xc_dom_parse_bin_kernel(struc pae_flags = image_info->flags & XEN_MULTIBOOT_FLAG_PAE_MASK; switch (pae_flags >> XEN_MULTIBOOT_FLAG_PAE_SHIFT) { case 0: - dom->guest_type = "xen-3.0-x86_32"; - break; + dom->guest_type = "xen-3.0-x86_32"; + break; case 1: - dom->guest_type = "xen-3.0-x86_32p"; - break; + dom->guest_type = "xen-3.0-x86_32p"; + break; case 2: - dom->guest_type = "xen-3.0-x86_64"; - break; + dom->guest_type = "xen-3.0-x86_64"; + break; case 3: - /* Kernel detects PAE at runtime. So try to figure whenever - * xen supports PAE and advertise a PAE-capable kernel in case - * it does. */ - dom->guest_type = "xen-3.0-x86_32"; - if (strstr(dom->xen_caps, "xen-3.0-x86_32p")) { - xc_dom_printf("%s: PAE fixup\n", __FUNCTION__); - dom->guest_type = "xen-3.0-x86_32p"; - dom->parms.pae = 2; - } - break; + /* Kernel detects PAE at runtime. So try to figure whenever + * xen supports PAE and advertise a PAE-capable kernel in case + * it does. */ + dom->guest_type = "xen-3.0-x86_32"; + if ( strstr(dom->xen_caps, "xen-3.0-x86_32p") ) + { + xc_dom_printf("%s: PAE fixup\n", __FUNCTION__); + dom->guest_type = "xen-3.0-x86_32p"; + dom->parms.pae = 2; + } + break; } return 0; } @@ -242,10 +236,9 @@ static int xc_dom_load_bin_kernel(struct uint32_t load_end_addr; uint32_t bss_end_addr; uint32_t skip, text_size, bss_size; - uint32_t pae_flags; image_info = find_table(dom); - if (!image_info) + if ( !image_info ) return -EINVAL; start_addr = image_info->header_addr - ((char *)image_info - image); @@ -266,10 +259,6 @@ static int xc_dom_load_bin_kernel(struct memcpy(dest, image + skip, text_size); memset(dest + text_size, 0, bss_size); - pae_flags = image_info->flags & XEN_MULTIBOOT_FLAG_PAE_MASK; - if (3 == (pae_flags >> XEN_MULTIBOOT_FLAG_PAE_SHIFT) && dom->guest_xc > 0) - { - } return 0; } @@ -289,6 +278,10 @@ static void __init register_loader(void) /* * Local variables: + * mode: C + * c-set-style: "BSD" * c-basic-offset: 4 + * tab-width: 4 + * indent-tabs-mode: nil * End: */ diff -r 59b8d5168cc1 -r c051ed67258a tools/libxc/xc_dom_boot.c --- a/tools/libxc/xc_dom_boot.c Sat Feb 24 14:48:17 2007 +0000 +++ b/tools/libxc/xc_dom_boot.c Sat Feb 24 15:30:19 2007 +0000 @@ -29,20 +29,20 @@ static int setup_hypercall_page(struct x xen_pfn_t pfn; int rc; - if (-1 == dom->parms.virt_hypercall) - return 0; + if ( dom->parms.virt_hypercall == -1 ) + return 0; pfn = (dom->parms.virt_hypercall - dom->parms.virt_base) - >> XC_DOM_PAGE_SHIFT(dom); + >> XC_DOM_PAGE_SHIFT(dom); xc_dom_printf("%s: vaddr=0x%" PRIx64 " pfn=0x%" PRIpfn "\n", __FUNCTION__, - dom->parms.virt_hypercall, pfn); + dom->parms.virt_hypercall, pfn); domctl.cmd = XEN_DOMCTL_hypercall_init; domctl.domain = dom->guest_domid; domctl.u.hypercall_init.gmfn = xc_dom_p2m_guest(dom, pfn); rc = do_domctl(dom->guest_xc, &domctl); - if (0 != rc) - xc_dom_panic(XC_INTERNAL_ERROR, "%s: HYPERCALL_INIT failed (rc=%d)\n", - __FUNCTION__, rc); + if ( rc != 0 ) + xc_dom_panic(XC_INTERNAL_ERROR, "%s: HYPERCALL_INIT failed (rc=%d)\n", + __FUNCTION__, rc); return rc; } @@ -58,9 +58,9 @@ static int launch_vm(int xc, domid_t dom domctl.u.vcpucontext.vcpu = 0; set_xen_guest_handle(domctl.u.vcpucontext.ctxt, ctxt); rc = do_domctl(xc, &domctl); - if (0 != rc) - xc_dom_panic(XC_INTERNAL_ERROR, - "%s: SETVCPUCONTEXT failed (rc=%d)\n", __FUNCTION__, rc); + if ( rc != 0 ) + xc_dom_panic(XC_INTERNAL_ERROR, + "%s: SETVCPUCONTEXT failed (rc=%d)\n", __FUNCTION__, rc); return rc; } @@ -69,17 +69,17 @@ static int clear_page(struct xc_dom_imag xen_pfn_t dst; int rc; - if (0 == pfn) - return 0; + if ( pfn == 0 ) + return 0; dst = xc_dom_p2m_host(dom, pfn); xc_dom_printf("%s: pfn 0x%" PRIpfn ", mfn 0x%" PRIpfn "\n", - __FUNCTION__, pfn, dst); + __FUNCTION__, pfn, dst); rc = xc_clear_domain_page(dom->guest_xc, dom->guest_domid, dst); - if (0 != rc) - xc_dom_panic(XC_INTERNAL_ERROR, - "%s: xc_clear_domain_page failed (pfn 0x%" PRIpfn - ", rc=%d)\n", __FUNCTION__, pfn, rc); + if ( rc != 0 ) + xc_dom_panic(XC_INTERNAL_ERROR, + "%s: xc_clear_domain_page failed (pfn 0x%" PRIpfn + ", rc=%d)\n", __FUNCTION__, pfn, rc); return rc; } @@ -92,11 +92,11 @@ static int x86_compat(int xc, domid_t do static int x86_compat(int xc, domid_t domid, char *guest_type) { static const struct { - char *guest; - uint32_t size; + char *guest; + uint32_t size; } types[] = { - { "xen-3.0-x86_32p", 32 }, - { "xen-3.0-x86_64", 64 }, + { "xen-3.0-x86_32p", 32 }, + { "xen-3.0-x86_64", 64 }, }; DECLARE_DOMCTL; int i,rc; @@ -104,19 +104,19 @@ static int x86_compat(int xc, domid_t do memset(&domctl, 0, sizeof(domctl)); domctl.domain = domid; domctl.cmd = XEN_DOMCTL_set_address_size; - for (i = 0; i < sizeof(types)/sizeof(types[0]); i++) - if (0 == strcmp(types[i].guest, guest_type)) - domctl.u.address_size.size = types[i].size; - if (0 == domctl.u.address_size.size) - /* nothing to do */ - return 0; + for ( i = 0; i < sizeof(types)/sizeof(types[0]); i++ ) + if ( !strcmp(types[i].guest, guest_type) ) + domctl.u.address_size.size = types[i].size; + if ( domctl.u.address_size.size == 0 ) + /* nothing to do */ + return 0; xc_dom_printf("%s: guest %s, address size %" PRId32 "\n", __FUNCTION__, - guest_type, domctl.u.address_size.size); + guest_type, domctl.u.address_size.size); rc = do_domctl(xc, &domctl); - if (0 != rc) - xc_dom_printf("%s: warning: failed (rc=%d)\n", - __FUNCTION__, rc); + if ( rc != 0 ) + xc_dom_printf("%s: warning: failed (rc=%d)\n", + __FUNCTION__, rc); return rc; } @@ -128,17 +128,17 @@ static int x86_shadow(int xc, domid_t do xc_dom_printf("%s: called\n", __FUNCTION__); mode = XEN_DOMCTL_SHADOW_ENABLE_REFCOUNT | - XEN_DOMCTL_SHADOW_ENABLE_TRANSLATE; + XEN_DOMCTL_SHADOW_ENABLE_TRANSLATE; rc = xc_shadow_control(xc, domid, - XEN_DOMCTL_SHADOW_OP_ENABLE, - NULL, 0, NULL, mode, NULL); - if (0 != rc) - { - xc_dom_panic(XC_INTERNAL_ERROR, - "%s: SHADOW_OP_ENABLE (mode=0x%x) failed (rc=%d)\n", - __FUNCTION__, mode, rc); - return rc; + XEN_DOMCTL_SHADOW_OP_ENABLE, + NULL, 0, NULL, mode, NULL); + if ( rc != 0 ) + { + xc_dom_panic(XC_INTERNAL_ERROR, + "%s: SHADOW_OP_ENABLE (mode=0x%x) failed (rc=%d)\n", + __FUNCTION__, mode, rc); + return rc; } xc_dom_printf("%s: shadow enabled (mode=0x%x)\n", __FUNCTION__, mode); return rc; @@ -149,10 +149,10 @@ static int arch_setup_meminit(struct xc_ int rc = 0; x86_compat(dom->guest_xc, dom->guest_domid, dom->guest_type); - if (xc_dom_feature_translated(dom)) - { - dom->shadow_enabled = 1; - rc = x86_shadow(dom->guest_xc, dom->guest_domid); + if ( xc_dom_feature_translated(dom) ) + { + dom->shadow_enabled = 1; + rc = x86_shadow(dom->guest_xc, dom->guest_domid); } return rc; } @@ -166,92 +166,92 @@ static int arch_setup_bootlate(struct xc static int arch_setup_bootlate(struct xc_dom_image *dom) { static const struct { - char *guest; - unsigned long pgd_type; + char *guest; + unsigned long pgd_type; } types[] = { - { "xen-3.0-x86_32", MMUEXT_PIN_L2_TABLE}, - { "xen-3.0-x86_32p", MMUEXT_PIN_L3_TABLE}, - { "xen-3.0-x86_64", MMUEXT_PIN_L4_TABLE}, + { "xen-3.0-x86_32", MMUEXT_PIN_L2_TABLE}, + { "xen-3.0-x86_32p", MMUEXT_PIN_L3_TABLE}, + { "xen-3.0-x86_64", MMUEXT_PIN_L4_TABLE}, }; unsigned long pgd_type = 0; shared_info_t *shared_info; xen_pfn_t shinfo; int i, rc; - for (i = 0; i < sizeof(types) / sizeof(types[0]); i++) - if (0 == strcmp(types[i].guest, dom->guest_type)) - pgd_type = types[i].pgd_type; - - if (!xc_dom_feature_translated(dom)) - { - /* paravirtualized guest */ - xc_dom_unmap_one(dom, dom->pgtables_seg.pfn); - rc = pin_table(dom->guest_xc, pgd_type, - xc_dom_p2m_host(dom, dom->pgtables_seg.pfn), - dom->guest_domid); - if (0 != rc) - { - xc_dom_panic(XC_INTERNAL_ERROR, - "%s: pin_table failed (pfn 0x%" PRIpfn ", rc=%d)\n", - __FUNCTION__, dom->pgtables_seg.pfn, rc); - return rc; - } - shinfo = dom->shared_info_mfn; + for ( i = 0; i < sizeof(types) / sizeof(types[0]); i++ ) + if ( !strcmp(types[i].guest, dom->guest_type) ) + pgd_type = types[i].pgd_type; + + if ( !xc_dom_feature_translated(dom) ) + { + /* paravirtualized guest */ + xc_dom_unmap_one(dom, dom->pgtables_seg.pfn); + rc = pin_table(dom->guest_xc, pgd_type, + xc_dom_p2m_host(dom, dom->pgtables_seg.pfn), + dom->guest_domid); + if ( rc != 0 ) + { + xc_dom_panic(XC_INTERNAL_ERROR, + "%s: pin_table failed (pfn 0x%" PRIpfn ", rc=%d)\n", + __FUNCTION__, dom->pgtables_seg.pfn, rc); + return rc; + } + shinfo = dom->shared_info_mfn; } else { - /* paravirtualized guest with auto-translation */ - struct xen_add_to_physmap xatp; - int i; - - /* Map shared info frame into guest physmap. */ - xatp.domid = dom->guest_domid; - xatp.space = XENMAPSPACE_shared_info; - xatp.idx = 0; - xatp.gpfn = dom->shared_info_pfn; - rc = xc_memory_op(dom->guest_xc, XENMEM_add_to_physmap, &xatp); - if (rc != 0) - { - xc_dom_panic(XC_INTERNAL_ERROR, "%s: mapping shared_info failed " - "(pfn=0x%" PRIpfn ", rc=%d)\n", - __FUNCTION__, xatp.gpfn, rc); - return rc; - } - - /* Map grant table frames into guest physmap. */ - for (i = 0;; i++) - { - xatp.domid = dom->guest_domid; - xatp.space = XENMAPSPACE_grant_table; - xatp.idx = i; - xatp.gpfn = dom->total_pages + i; - rc = xc_memory_op(dom->guest_xc, XENMEM_add_to_physmap, &xatp); - if (rc != 0) - { - if (i > 0 && errno == EINVAL) - { - xc_dom_printf("%s: %d grant tables mapped\n", __FUNCTION__, - i); - break; - } - xc_dom_panic(XC_INTERNAL_ERROR, - "%s: mapping grant tables failed " "(pfn=0x%" - PRIpfn ", rc=%d)\n", __FUNCTION__, xatp.gpfn, rc); - return rc; - } - } - shinfo = dom->shared_info_pfn; + /* paravirtualized guest with auto-translation */ + struct xen_add_to_physmap xatp; + int i; + + /* Map shared info frame into guest physmap. */ + xatp.domid = dom->guest_domid; + xatp.space = XENMAPSPACE_shared_info; + xatp.idx = 0; + xatp.gpfn = dom->shared_info_pfn; + rc = xc_memory_op(dom->guest_xc, XENMEM_add_to_physmap, &xatp); + if ( rc != 0 ) + { + xc_dom_panic(XC_INTERNAL_ERROR, "%s: mapping shared_info failed " + "(pfn=0x%" PRIpfn ", rc=%d)\n", + __FUNCTION__, xatp.gpfn, rc); + return rc; + } + + /* Map grant table frames into guest physmap. */ + for ( i = 0; ; i++ ) + { + xatp.domid = dom->guest_domid; + xatp.space = XENMAPSPACE_grant_table; + xatp.idx = i; + xatp.gpfn = dom->total_pages + i; + rc = xc_memory_op(dom->guest_xc, XENMEM_add_to_physmap, &xatp); + if ( rc != 0 ) + { + if ( (i > 0) && (errno == EINVAL) ) + { + xc_dom_printf("%s: %d grant tables mapped\n", __FUNCTION__, + i); + break; + } + xc_dom_panic(XC_INTERNAL_ERROR, + "%s: mapping grant tables failed " "(pfn=0x%" + PRIpfn ", rc=%d)\n", __FUNCTION__, xatp.gpfn, rc); + return rc; + } + } + shinfo = dom->shared_info_pfn; } /* setup shared_info page */ xc_dom_printf("%s: shared_info: pfn 0x%" PRIpfn ", mfn 0x%" PRIpfn "\n", - __FUNCTION__, dom->shared_info_pfn, dom->shared_info_mfn); + __FUNCTION__, dom->shared_info_pfn, dom->shared_info_mfn); shared_info = xc_map_foreign_range(dom->guest_xc, dom->guest_domid, - PAGE_SIZE_X86, - PROT_READ | PROT_WRITE, - shinfo); - if (NULL == shared_info) - return -1; + PAGE_SIZE_X86, + PROT_READ | PROT_WRITE, + shinfo); + if ( shared_info == NULL ) + return -1; dom->arch_hooks->shared_info(dom, shared_info); munmap(shared_info, PAGE_SIZE_X86); @@ -282,7 +282,7 @@ static int arch_setup_bootearly(struct x domctl.u.arch_setup.flags = 0; domctl.u.arch_setup.bp = (dom->start_info_pfn << PAGE_SHIFT) - + sizeof(start_info_t); + + sizeof(start_info_t); /* 3 = start info page, xenstore page and console page */ domctl.u.arch_setup.maxmem = (dom->total_pages - 3) << PAGE_SHIFT; rc = do_domctl(dom->guest_xc, &domctl); @@ -296,13 +296,13 @@ static int arch_setup_bootlate(struct xc /* setup shared_info page */ xc_dom_printf("%s: shared_info: mfn 0x%" PRIpfn "\n", - __FUNCTION__, dom->shared_info_mfn); + __FUNCTION__, dom->shared_info_mfn); shared_info = xc_map_foreign_range(dom->guest_xc, dom->guest_domid, - page_size, - PROT_READ | PROT_WRITE, - dom->shared_info_mfn); - if (NULL == shared_info) - return -1; + page_size, + PROT_READ | PROT_WRITE, + dom->shared_info_mfn); + if ( shared_info == NULL ) + return -1; dom->arch_hooks->shared_info(dom, shared_info); munmap(shared_info, page_size); return 0; @@ -328,20 +328,20 @@ static int arch_setup_bootlate(struct xc static int arch_setup_bootlate(struct xc_dom_image *dom) { start_info_t *si = - xc_dom_pfn_to_ptr(dom, dom->start_info_pfn, 1); + xc_dom_pfn_to_ptr(dom, dom->start_info_pfn, 1); xc_dom_printf("%s: TODO: setup devtree\n", __FUNCTION__); #if 0 load_devtree(dom->guest_xc, - dom->guest_domid, - dom->p2m_host, - devtree, // FIXME - devtree_addr, // FIXME - dom->ramdisk_seg.vstart, - dom->ramdisk_seg.vend - dom->ramdisk_seg.vstart, - si, - dom->start_info_pfn << PAGE_SHIFT); + dom->guest_domid, + dom->p2m_host, + devtree, // FIXME + devtree_addr, // FIXME + dom->ramdisk_seg.vstart, + dom->ramdisk_seg.vend - dom->ramdisk_seg.vstart, + si, + dom->start_info_pfn << PAGE_SHIFT); #endif return rc; } @@ -380,19 +380,19 @@ int xc_dom_compat_check(struct xc_dom_im int match, found = 0; strcpy(xen_caps, dom->xen_caps); - for (item = strtok_r(xen_caps, " ", &ptr); - NULL != item; item = strtok_r(NULL, " ", &ptr)) - { - match = (0 == strcmp(dom->guest_type, item)); - xc_dom_printf("%s: supported guest type: %s%s\n", __FUNCTION__, - item, match ? " <= matches" : ""); - if (match) - found++; - } - if (!found) - xc_dom_panic(XC_INVALID_KERNEL, - "%s: guest type %s not supported by xen kernel, sorry\n", - __FUNCTION__, dom->guest_type); + for ( item = strtok_r(xen_caps, " ", &ptr); + item != NULL ; item = strtok_r(NULL, " ", &ptr) ) + { + match = !strcmp(dom->guest_type, item); + xc_dom_printf("%s: supported guest type: %s%s\n", __FUNCTION__, + item, match ? " <= matches" : ""); + if ( match ) + found++; + } + if ( !found ) + xc_dom_panic(XC_INVALID_KERNEL, + "%s: guest type %s not supported by xen kernel, sorry\n", + __FUNCTION__, dom->guest_type); return found; } @@ -403,13 +403,14 @@ int xc_dom_boot_xen_init(struct xc_dom_i dom->guest_domid = domid; dom->xen_version = xc_version(dom->guest_xc, XENVER_version, NULL); - if (xc_version(xc, XENVER_capabilities, &dom->xen_caps) < 0) { - xc_dom_panic(XC_INTERNAL_ERROR, "can't get xen capabilities"); - return -1; + if ( xc_version(xc, XENVER_capabilities, &dom->xen_caps) < 0 ) + { + xc_dom_panic(XC_INTERNAL_ERROR, "can't get xen capabilities"); + return -1; } xc_dom_printf("%s: ver %d.%d, caps %s\n", __FUNCTION__, - dom->xen_version >> 16, dom->xen_version & 0xff, - dom->xen_caps); + dom->xen_version >> 16, dom->xen_version & 0xff, + dom->xen_caps); return 0; } @@ -419,26 +420,26 @@ int xc_dom_boot_mem_init(struct xc_dom_i xc_dom_printf("%s: called\n", __FUNCTION__); - if (0 != (rc = arch_setup_meminit(dom))) - return rc; + if ( (rc = arch_setup_meminit(dom)) != 0 ) + return rc; /* allocate guest memory */ rc = xc_domain_memory_populate_physmap(dom->guest_xc, dom->guest_domid, - dom->total_pages, 0, 0, - dom->p2m_host); - if (0 != rc) - { - xc_dom_panic(XC_OUT_OF_MEMORY, - "%s: can't allocate low memory for domain\n", - __FUNCTION__); - return rc; + dom->total_pages, 0, 0, + dom->p2m_host); + if ( rc != 0 ) + { + xc_dom_panic(XC_OUT_OF_MEMORY, + "%s: can't allocate low memory for domain\n", + __FUNCTION__); + return rc; } return 0; } void *xc_dom_boot_domU_map(struct xc_dom_image *dom, xen_pfn_t pfn, - xen_pfn_t count) + xen_pfn_t count) { int page_shift = XC_DOM_PAGE_SHIFT(dom); privcmd_mmap_entry_t *entries; @@ -446,38 +447,39 @@ void *xc_dom_boot_domU_map(struct xc_dom int i, rc; entries = xc_dom_malloc(dom, count * sizeof(privcmd_mmap_entry_t)); - if (NULL == entries) - { - xc_dom_panic(XC_INTERNAL_ERROR, - "%s: failed to mmap domU pages 0x%" PRIpfn "+0x%" PRIpfn - " [malloc]\n", __FUNCTION__, pfn, count); - return NULL; + if ( entries == NULL ) + { + xc_dom_panic(XC_INTERNAL_ERROR, + "%s: failed to mmap domU pages 0x%" PRIpfn "+0x%" PRIpfn + " [malloc]\n", __FUNCTION__, pfn, count); + return NULL; } ptr = mmap(NULL, count << page_shift, PROT_READ | PROT_WRITE, - MAP_SHARED, dom->guest_xc, 0); - if (MAP_FAILED == ptr) - { - xc_dom_panic(XC_INTERNAL_ERROR, - "%s: failed to mmap domU pages 0x%" PRIpfn "+0x%" PRIpfn - " [mmap]\n", __FUNCTION__, pfn, count); - return NULL; - } - - for (i = 0; i < count; i++) - { - entries[i].va = (uintptr_t) ptr + (i << page_shift); - entries[i].mfn = xc_dom_p2m_host(dom, pfn + i); - entries[i].npages = 1; - } - - rc = xc_map_foreign_ranges(dom->guest_xc, dom->guest_domid, entries, count); - if (rc < 0) - { - xc_dom_panic(XC_INTERNAL_ERROR, - "%s: failed to mmap domU pages 0x%" PRIpfn "+0x%" PRIpfn - " [xenctl, rc=%d]\n", __FUNCTION__, pfn, count, rc); - return NULL; + MAP_SHARED, dom->guest_xc, 0); + if ( ptr == MAP_FAILED ) + { + xc_dom_panic(XC_INTERNAL_ERROR, + "%s: failed to mmap domU pages 0x%" PRIpfn "+0x%" PRIpfn + " [mmap]\n", __FUNCTION__, pfn, count); + return NULL; + } + + for ( i = 0; i < count; i++ ) + { + entries[i].va = (uintptr_t) ptr + (i << page_shift); + entries[i].mfn = xc_dom_p2m_host(dom, pfn + i); + entries[i].npages = 1; + } + + rc = xc_map_foreign_ranges(dom->guest_xc, dom->guest_domid, + entries, count); + if ( rc < 0 ) + { + xc_dom_panic(XC_INTERNAL_ERROR, + "%s: failed to mmap domU pages 0x%" PRIpfn "+0x%" PRIpfn + " [xenctl, rc=%d]\n", __FUNCTION__, pfn, count, rc); + return NULL; } return ptr; } @@ -491,64 +493,74 @@ int xc_dom_boot_image(struct xc_dom_imag xc_dom_printf("%s: called\n", __FUNCTION__); /* misc ia64 stuff*/ - if (0 != (rc = arch_setup_bootearly(dom))) - return rc; + if ( (rc = arch_setup_bootearly(dom)) != 0 ) + return rc; /* collect some info */ domctl.cmd = XEN_DOMCTL_getdomaininfo; domctl.domain = dom->guest_domid; rc = do_domctl(dom->guest_xc, &domctl); - if (0 != rc) - { - xc_dom_panic(XC_INTERNAL_ERROR, - "%s: getdomaininfo failed (rc=%d)\n", __FUNCTION__, rc); - return rc; - } - if (domctl.domain != dom->guest_domid) - { - xc_dom_panic(XC_INTERNAL_ERROR, - "%s: Huh? domid mismatch (%d != %d)\n", __FUNCTION__, - domctl.domain, dom->guest_domid); - return -1; + if ( rc != 0 ) + { + xc_dom_panic(XC_INTERNAL_ERROR, + "%s: getdomaininfo failed (rc=%d)\n", __FUNCTION__, rc); + return rc; + } + if ( domctl.domain != dom->guest_domid ) + { + xc_dom_panic(XC_INTERNAL_ERROR, + "%s: Huh? domid mismatch (%d != %d)\n", __FUNCTION__, + domctl.domain, dom->guest_domid); + return -1; } dom->shared_info_mfn = domctl.u.getdomaininfo.shared_info_frame; /* sanity checks */ - if (!xc_dom_compat_check(dom)) - return -1; + if ( !xc_dom_compat_check(dom) ) + return -1; /* initial mm setup */ - if (0 != (rc = xc_dom_update_guest_p2m(dom))) - return rc; - if (dom->arch_hooks->setup_pgtables) - if (0 != (rc = dom->arch_hooks->setup_pgtables(dom))) - return rc; - - if (0 != (rc = clear_page(dom, dom->console_pfn))) - return rc; - if (0 != (rc = clear_page(dom, dom->xenstore_pfn))) - return rc; + if ( (rc = xc_dom_update_guest_p2m(dom)) != 0 ) + return rc; + if ( dom->arch_hooks->setup_pgtables ) + if ( (rc = dom->arch_hooks->setup_pgtables(dom)) != 0 ) + return rc; + + if ( (rc = clear_page(dom, dom->console_pfn)) != 0 ) + return rc; + if ( (rc = clear_page(dom, dom->xenstore_pfn)) != 0 ) + return rc; /* start info page */ - if (dom->arch_hooks->start_info) - dom->arch_hooks->start_info(dom); + if ( dom->arch_hooks->start_info ) + dom->arch_hooks->start_info(dom); /* hypercall page */ - if (0 != (rc = setup_hypercall_page(dom))) - return rc; + if ( (rc = setup_hypercall_page(dom)) != 0 ) + return rc; xc_dom_log_memory_footprint(dom); /* misc x86 stuff */ - if (0 != (rc = arch_setup_bootlate(dom))) - return rc; + if ( (rc = arch_setup_bootlate(dom)) != 0 ) + return rc; /* let the vm run */ ctxt = xc_dom_malloc(dom, PAGE_SIZE * 2 /* FIXME */ ); memset(ctxt, 0, PAGE_SIZE * 2); - if (0 != (rc = dom->arch_hooks->vcpu(dom, ctxt))) - return rc; + if ( (rc = dom->arch_hooks->vcpu(dom, ctxt)) != 0 ) + return rc; xc_dom_unmap_all(dom); rc = launch_vm(dom->guest_xc, dom->guest_domid, ctxt); return rc; } + +/* + * Local variables: + * mode: C + * c-set-style: "BSD" + * c-basic-offset: 4 + * tab-width: 4 + * indent-tabs-mode: nil + * End: + */ diff -r 59b8d5168cc1 -r c051ed67258a tools/libxc/xc_dom_compat_linux.c --- a/tools/libxc/xc_dom_compat_linux.c Sat Feb 24 14:48:17 2007 +0000 +++ b/tools/libxc/xc_dom_compat_linux.c Sat Feb 24 15:30:19 2007 +0000 @@ -22,103 +22,112 @@ /* ------------------------------------------------------------------------ */ static int xc_linux_build_internal(struct xc_dom_image *dom, - int xc_handle, uint32_t domid, - unsigned int mem_mb, - unsigned long flags, - unsigned int store_evtchn, - unsigned long *store_mfn, - unsigned int console_evtchn, - unsigned long *console_mfn) + int xc_handle, uint32_t domid, + unsigned int mem_mb, + unsigned long flags, + unsigned int store_evtchn, + unsigned long *store_mfn, + unsigned int console_evtchn, + unsigned long *console_mfn) { int rc; - if (0 != (rc = xc_dom_boot_xen_init(dom, xc_handle, domid))) - goto out; - if (0 != (rc = xc_dom_parse_image(dom))) - goto out; - if (0 != (rc = xc_dom_mem_init(dom, mem_mb))) - goto out; - if (0 != (rc = xc_dom_boot_mem_init(dom))) - goto out; - if (0 != (rc = xc_dom_build_image(dom))) - goto out; + if ( (rc = xc_dom_boot_xen_init(dom, xc_handle, domid)) != 0 ) + goto out; + if ( (rc = xc_dom_parse_image(dom)) != 0 ) + goto out; + if ( (rc = xc_dom_mem_init(dom, mem_mb)) != 0 ) + goto out; + if ( (rc = xc_dom_boot_mem_init(dom)) != 0 ) + goto out; + if ( (rc = xc_dom_build_image(dom)) != 0 ) + goto out; dom->flags = flags; dom->console_evtchn = console_evtchn; dom->xenstore_evtchn = store_evtchn; rc = xc_dom_boot_image(dom); - if (0 != rc) - goto out; + if ( rc != 0 ) + goto out; *console_mfn = xc_dom_p2m_host(dom, dom->console_pfn); *store_mfn = xc_dom_p2m_host(dom, dom->xenstore_pfn); - out: + out: return rc; } int xc_linux_build_mem(int xc_handle, uint32_t domid, - unsigned int mem_mb, - const char *image_buffer, - unsigned long image_size, - const char *initrd, - unsigned long initrd_len, - const char *cmdline, - const char *features, - unsigned long flags, - unsigned int store_evtchn, - unsigned long *store_mfn, - unsigned int console_evtchn, unsigned long *console_mfn) + unsigned int mem_mb, + const char *image_buffer, + unsigned long image_size, + const char *initrd, + unsigned long initrd_len, + const char *cmdline, + const char *features, + unsigned long flags, + unsigned int store_evtchn, + unsigned long *store_mfn, + unsigned int console_evtchn, unsigned long *console_mfn) { struct xc_dom_image *dom; int rc; xc_dom_loginit(); dom = xc_dom_allocate(cmdline, features); - if (0 != (rc = xc_dom_kernel_mem(dom, image_buffer, image_size))) - goto out; - if (initrd) - if (0 != (rc = xc_dom_ramdisk_mem(dom, initrd, initrd_len))) - goto out; + if ( (rc = xc_dom_kernel_mem(dom, image_buffer, image_size)) != 0 ) + goto out; + if ( initrd && ((rc = xc_dom_ramdisk_mem(dom, initrd, initrd_len)) != 0) ) + goto out; rc = xc_linux_build_internal(dom, xc_handle, domid, - mem_mb, flags, - store_evtchn, store_mfn, - console_evtchn, console_mfn); + mem_mb, flags, + store_evtchn, store_mfn, + console_evtchn, console_mfn); - out: + out: xc_dom_release(dom); return rc; } int xc_linux_build(int xc_handle, uint32_t domid, - unsigned int mem_mb, - const char *image_name, - const char *initrd_name, - const char *cmdline, - const char *features, - unsigned long flags, - unsigned int store_evtchn, - unsigned long *store_mfn, - unsigned int console_evtchn, unsigned long *console_mfn) + unsigned int mem_mb, + const char *image_name, + const char *initrd_name, + const char *cmdline, + const char *features, + unsigned long flags, + unsigned int store_evtchn, + unsigned long *store_mfn, + unsigned int console_evtchn, unsigned long *console_mfn) { struct xc_dom_image *dom; int rc; xc_dom_loginit(); dom = xc_dom_allocate(cmdline, features); - if (0 != (rc = xc_dom_kernel_file(dom, image_name))) - goto out; - if (initrd_name && strlen(initrd_name)) - if (0 != (rc = xc_dom_ramdisk_file(dom, initrd_name))) - goto out; + if ( (rc = xc_dom_kernel_file(dom, image_name)) != 0 ) + goto out; + if ( initrd_name && strlen(initrd_name) && + ((rc = xc_dom_ramdisk_file(dom, initrd_name)) != 0) ) + goto out; rc = xc_linux_build_internal(dom, xc_handle, domid, - mem_mb, flags, - store_evtchn, store_mfn, - console_evtchn, console_mfn); + mem_mb, flags, + store_evtchn, store_mfn, + console_evtchn, console_mfn); - out: + out: xc_dom_release(dom); return rc; } + +/* + * Local variables: + * mode: C + * c-set-style: "BSD" + * c-basic-offset: 4 + * tab-width: 4 + * indent-tabs-mode: nil + * End: + */ diff -r 59b8d5168cc1 -r c051ed67258a tools/libxc/xc_dom_core.c --- a/tools/libxc/xc_dom_core.c Sat Feb 24 14:48:17 2007 +0000 +++ b/tools/libxc/xc_dom_core.c Sat Feb 24 15:30:19 2007 +0000 @@ -27,8 +27,8 @@ FILE *xc_dom_logfile = NULL; void xc_dom_loginit(void) { - if (xc_dom_logfile) - return; + if ( xc_dom_logfile ) + return; xc_dom_logfile = fopen("/var/log/xen/domain-builder-ng.log", "a"); setvbuf(xc_dom_logfile, NULL, _IONBF, 0); xc_dom_printf("### ----- xc domain builder logfile opened -----\n"); @@ -40,8 +40,8 @@ int xc_dom_printf(const char *fmt, ...) char buf[1024]; int rc; - if (!xc_dom_logfile) - return 0; + if ( !xc_dom_logfile ) + return 0; va_start(args, fmt); rc = vsnprintf(buf, sizeof(buf), fmt, args); @@ -52,7 +52,7 @@ int xc_dom_printf(const char *fmt, ...) } int xc_dom_panic_func(const char *file, int line, xc_error_code err, - const char *fmt, ...) + const char *fmt, ...) { va_list args; FILE *fp = stderr; @@ -60,8 +60,8 @@ int xc_dom_panic_func(const char *file, char pos[256]; char msg[XC_MAX_ERROR_MSG_LEN]; - if (xc_dom_logfile) - fp = xc_dom_logfile; + if ( xc_dom_logfile ) + fp = xc_dom_logfile; snprintf(pos, sizeof(pos), "%s:%d: panic: ", file, line); va_start(args, fmt); @@ -74,12 +74,12 @@ int xc_dom_panic_func(const char *file, static void print_mem(const char *name, size_t mem) { - if (mem > 32 * 1024 * 1024) - xc_dom_printf("%-24s : %zd MB\n", name, mem / (1024 * 1024)); - else if (mem > 32 * 1024) - xc_dom_printf("%-24s : %zd kB\n", name, mem / 1024); + if ( mem > (32 * 1024 * 1024) ) + xc_dom_printf("%-24s : %zd MB\n", name, mem / (1024 * 1024)); + else if ( mem > (32 * 1024) ) + xc_dom_printf("%-24s : %zd kB\n", name, mem / 1024); else - xc_dom_printf("%-24s : %zd bytes\n", name, mem); + xc_dom_printf("%-24s : %zd bytes\n", name, mem); } void xc_dom_log_memory_footprint(struct xc_dom_image *dom) @@ -101,14 +101,14 @@ void *xc_dom_malloc(struct xc_dom_image struct xc_dom_mem *block; block = malloc(sizeof(*block) + size); - if (NULL == block) - return NULL; + if ( block == NULL ) + return NULL; memset(block, 0, sizeof(*block) + size); block->next = dom->memblocks; dom->memblocks = block; dom->alloc_malloc += sizeof(*block) + size; - if (size > 100 * 1024) - print_mem(__FUNCTION__, size); + if ( size > (100 * 1024) ) + print_mem(__FUNCTION__, size); return block->memory; } @@ -117,62 +117,63 @@ void *xc_dom_malloc_page_aligned(struct struct xc_dom_mem *block; block = malloc(sizeof(*block)); - if (NULL == block) - return NULL; + if ( block == NULL ) + return NULL; memset(block, 0, sizeof(*block)); block->mmap_len = size; block->mmap_ptr = mmap(NULL, block->mmap_len, - PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, - -1, 0); - if (MAP_FAILED == block->mmap_ptr) - { - free(block); - return NULL; + PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, + -1, 0); + if ( block->mmap_ptr == MAP_FAILED ) + { + free(block); + return NULL; } block->next = dom->memblocks; dom->memblocks = block; dom->alloc_malloc += sizeof(*block); dom->alloc_mem_map += block->mmap_len; - if (size > 100 * 1024) - print_mem(__FUNCTION__, size); + if ( size > (100 * 1024) ) + print_mem(__FUNCTION__, size); return block->mmap_ptr; } void *xc_dom_malloc_filemap(struct xc_dom_image *dom, - const char *filename, size_t * size) + const char *filename, size_t * size) { struct xc_dom_mem *block = NULL; int fd = -1; fd = open(filename, O_RDONLY); - if (-1 == fd) - goto err; + if ( fd == -1 ) + goto err; lseek(fd, 0, SEEK_SET); *size = lseek(fd, 0, SEEK_END); block = malloc(sizeof(*block)); - if (NULL == block) - goto err; + if ( block == NULL ) + goto err; memset(block, 0, sizeof(*block)); block->mmap_len = *size; - block->mmap_ptr = mmap(NULL, block->mmap_len, PROT_READ, MAP_SHARED, fd, 0); - if (MAP_FAILED == block->mmap_ptr) - goto err; + block->mmap_ptr = mmap(NULL, block->mmap_len, PROT_READ, + MAP_SHARED, fd, 0); + if ( block->mmap_ptr == MAP_FAILED ) + goto err; block->next = dom->memblocks; dom->memblocks = block; dom->alloc_malloc += sizeof(*block); dom->alloc_file_map += block->mmap_len; close(fd); - if (*size > 100 * 1024) - print_mem(__FUNCTION__, *size); + if ( *size > (100 * 1024) ) + print_mem(__FUNCTION__, *size); return block->mmap_ptr; - err: - if (-1 != fd) - close(fd); - if (block) - free(block); + err: + if ( fd != -1 ) + close(fd); + if ( block != NULL ) + free(block); return NULL; } @@ -180,12 +181,12 @@ static void xc_dom_free_all(struct xc_do { struct xc_dom_mem *block; - while (NULL != (block = dom->memblocks)) - { - dom->memblocks = block->next; - if (block->mmap_ptr) - munmap(block->mmap_ptr, block->mmap_len); - free(block); + while ( (block = dom->memblocks) != NULL ) + { + dom->memblocks = block->next; + if ( block->mmap_ptr ) + munmap(block->mmap_ptr, block->mmap_len); + free(block); } } @@ -194,8 +195,8 @@ char *xc_dom_strdup(struct xc_dom_image size_t len = strlen(str) + 1; char *nstr = xc_dom_malloc(dom, len); - if (NULL == nstr) - return NULL; + if ( nstr == NULL ) + return NULL; memcpy(nstr, str, len); return nstr; } @@ -208,18 +209,18 @@ size_t xc_dom_check_gzip(void *blob, siz unsigned char *gzlen; size_t unziplen; - if (0 != strncmp(blob, "\037\213", 2)) - /* not gzipped */ - return 0; + if (strncmp(blob, "\037\213", 2)) + /* not gzipped */ + return 0; gzlen = blob + ziplen - 4; unziplen = gzlen[3] << 24 | gzlen[2] << 16 | gzlen[1] << 8 | gzlen[0]; - if (unziplen < ziplen || unziplen > ziplen * 8) - { - xc_dom_printf - ("%s: size (zip %zd, unzip %zd) looks insane, skip gunzip\n", - __FUNCTION__, ziplen, unziplen); - return 0; + if ( (unziplen < ziplen) || (unziplen > (ziplen * 8)) ) + { + xc_dom_printf + ("%s: size (zip %zd, unzip %zd) looks insane, skip gunzip\n", + __FUNCTION__, ziplen, unziplen); + return 0; } return unziplen + 16; @@ -235,23 +236,23 @@ int xc_dom_do_gunzip(void *src, size_t s zStream.avail_in = srclen; zStream.next_out = dst; zStream.avail_out = dstlen; - rc = inflateInit2(&zStream, (MAX_WBITS + 32)); /* +32 means "handle gzip" */ - if (rc != Z_OK) - { - xc_dom_panic(XC_INTERNAL_ERROR, - "%s: inflateInit2 failed (rc=%d)\n", __FUNCTION__, rc); - return -1; + rc = inflateInit2(&zStream, (MAX_WBITS + 32)); /* +32 means "handle gzip" */ + if ( rc != Z_OK ) + { + xc_dom_panic(XC_INTERNAL_ERROR, + "%s: inflateInit2 failed (rc=%d)\n", __FUNCTION__, rc); + return -1; } rc = inflate(&zStream, Z_FINISH); - if (rc != Z_STREAM_END) - { - xc_dom_panic(XC_INTERNAL_ERROR, - "%s: inflate failed (rc=%d)\n", __FUNCTION__, rc); - return -1; + if ( rc != Z_STREAM_END ) + { + xc_dom_panic(XC_INTERNAL_ERROR, + "%s: inflate failed (rc=%d)\n", __FUNCTION__, rc); + return -1; } xc_dom_printf("%s: unzip ok, 0x%zx -> 0x%zx\n", - __FUNCTION__, srclen, dstlen); + __FUNCTION__, srclen, dstlen); return 0; } @@ -261,15 +262,15 @@ int xc_dom_try_gunzip(struct xc_dom_imag size_t unziplen; unziplen = xc_dom_check_gzip(*blob, *size); - if (0 == unziplen) - return 0; + if ( unziplen == 0 ) + return 0; unzip = xc_dom_malloc(dom, unziplen); - if (NULL == unzip) - return -1; - - if (-1 == xc_dom_do_gunzip(*blob, *size, unzip, unziplen)) - return -1; + if ( unzip == NULL ) + return -1; + + if ( xc_dom_do_gunzip(*blob, *size, unzip, unziplen) == -1 ) + return -1; *blob = unzip; *size = unziplen; @@ -280,92 +281,94 @@ int xc_dom_try_gunzip(struct xc_dom_imag /* domain memory */ void *xc_dom_pfn_to_ptr(struct xc_dom_image *dom, xen_pfn_t pfn, - xen_pfn_t count) + xen_pfn_t count) { struct xc_dom_phys *phys; unsigned int page_shift = XC_DOM_PAGE_SHIFT(dom); char *mode = "unset"; - if (pfn > dom->total_pages) - { - xc_dom_printf("%s: pfn out of range (0x%" PRIpfn " > 0x%" PRIpfn ")\n", - __FUNCTION__, pfn, dom->total_pages); - return NULL; + if ( pfn > dom->total_pages ) + { + xc_dom_printf("%s: pfn out of range (0x%" PRIpfn " > 0x%" PRIpfn ")\n", + __FUNCTION__, pfn, dom->total_pages); + return NULL; } /* already allocated? */ - for (phys = dom->phys_pages; NULL != phys; phys = phys->next) - { - if (pfn >= phys->first + phys->count) - continue; - if (count) - { - /* size given: must be completely within the already allocated block */ - if (pfn + count <= phys->first) - continue; - if (pfn < phys->first || pfn + count > phys->first + phys->count) - { - xc_dom_printf("%s: request overlaps allocated block" - " (req 0x%" PRIpfn "+0x%" PRIpfn "," - " blk 0x%" PRIpfn "+0x%" PRIpfn ")\n", - __FUNCTION__, pfn, count, phys->first, - phys->count); - return NULL; - } - } - else - { - /* no size given: block must be allocated already, - just hand out a pointer to it */ - if (pfn < phys->first) - continue; - } - return phys->ptr + ((pfn - phys->first) << page_shift); + for ( phys = dom->phys_pages; phys != NULL; phys = phys->next ) + { + if ( pfn >= (phys->first + phys->count) ) + continue; + if ( count ) + { + /* size given: must be completely within the already allocated block */ + if ( (pfn + count) <= phys->first ) + continue; + if ( (pfn < phys->first) || + ((pfn + count) > (phys->first + phys->count)) ) + { + xc_dom_printf("%s: request overlaps allocated block" + " (req 0x%" PRIpfn "+0x%" PRIpfn "," + " blk 0x%" PRIpfn "+0x%" PRIpfn ")\n", + __FUNCTION__, pfn, count, phys->first, + phys->count); + return NULL; + } + } + else + { + /* no size given: block must be allocated already, + just hand out a pointer to it */ + if ( pfn < phys->first ) + continue; + } + return phys->ptr + ((pfn - phys->first) << page_shift); } /* allocating is allowed with size specified only */ - if (0 == count) - { - xc_dom_printf("%s: no block found, no size given," - " can't malloc (pfn 0x%" PRIpfn ")\n", __FUNCTION__, pfn); - return NULL; + if ( count == 0 ) + { + xc_dom_printf("%s: no block found, no size given," + " can't malloc (pfn 0x%" PRIpfn ")\n", + __FUNCTION__, pfn); + return NULL; } /* not found, no overlap => allocate */ phys = xc_dom_malloc(dom, sizeof(*phys)); - if (NULL == phys) - return NULL; + if ( phys == NULL ) + return NULL; memset(phys, 0, sizeof(*phys)); phys->first = pfn; phys->count = count; - if (dom->guest_domid) - { - mode = "domU mapping"; - phys->ptr = xc_dom_boot_domU_map(dom, phys->first, phys->count); - if (NULL == phys->ptr) - return NULL; - dom->alloc_domU_map += phys->count << page_shift; + if ( dom->guest_domid ) + { + mode = "domU mapping"; + phys->ptr = xc_dom_boot_domU_map(dom, phys->first, phys->count); + if ( phys->ptr == NULL ) + return NULL; + dom->alloc_domU_map += phys->count << page_shift; } else { - mode = "anonymous memory"; - phys->ptr = mmap(NULL, phys->count << page_shift, - PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, - -1, 0); - if (MAP_FAILED == phys->ptr) - { - xc_dom_panic(XC_OUT_OF_MEMORY, - "%s: oom: can't allocate 0x%" PRIpfn " pages\n", - __FUNCTION__, count); - return NULL; - } - dom->alloc_mem_map += phys->count << page_shift; + mode = "anonymous memory"; + phys->ptr = mmap(NULL, phys->count << page_shift, + PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, + -1, 0); + if ( phys->ptr == MAP_FAILED ) + { + xc_dom_panic(XC_OUT_OF_MEMORY, + "%s: oom: can't allocate 0x%" PRIpfn " pages\n", + __FUNCTION__, count); + return NULL; + } + dom->alloc_mem_map += phys->count << page_shift; } #if 1 xc_dom_printf("%s: %s: pfn 0x%" PRIpfn "+0x%" PRIpfn " at %p\n", - __FUNCTION__, mode, phys->first, phys->count, phys->ptr); + __FUNCTION__, mode, phys->first, phys->count, phys->ptr); #endif phys->next = dom->phys_pages; dom->phys_pages = phys; @@ -373,29 +376,29 @@ void *xc_dom_pfn_to_ptr(struct xc_dom_im } int xc_dom_alloc_segment(struct xc_dom_image *dom, - struct xc_dom_seg *seg, char *name, - xen_vaddr_t start, xen_vaddr_t size) + struct xc_dom_seg *seg, char *name, + xen_vaddr_t start, xen_vaddr_t size) { unsigned int page_size = XC_DOM_PAGE_SIZE(dom); xen_pfn_t pages = (size + page_size - 1) / page_size; void *ptr; - if (0 == start) - start = dom->virt_alloc_end; - - if (start & (page_size - 1)) - { - xc_dom_panic(XC_INTERNAL_ERROR, - "%s: segment start isn't page aligned (0x%" PRIx64 ")\n", - __FUNCTION__, start); - return -1; - } - if (start < dom->virt_alloc_end) - { - xc_dom_panic(XC_INTERNAL_ERROR, - "%s: segment start too low (0x%" PRIx64 " < 0x%" PRIx64 - ")\n", __FUNCTION__, start, dom->virt_alloc_end); - return -1; + if ( start == 0 ) + start = dom->virt_alloc_end; + + if ( start & (page_size - 1) ) + { + xc_dom_panic(XC_INTERNAL_ERROR, + "%s: segment start isn't page aligned (0x%" PRIx64 ")\n", + __FUNCTION__, start); + return -1; + } + if ( start < dom->virt_alloc_end ) + { + xc_dom_panic(XC_INTERNAL_ERROR, + "%s: segment start too low (0x%" PRIx64 " < 0x%" PRIx64 + ")\n", __FUNCTION__, start, dom->virt_alloc_end); + return -1; } seg->vstart = start; @@ -404,13 +407,13 @@ int xc_dom_alloc_segment(struct xc_dom_i dom->virt_alloc_end = seg->vend; xc_dom_printf("%-20s: %-12s : 0x%" PRIx64 " -> 0x%" PRIx64 - " (pfn 0x%" PRIpfn " + 0x%" PRIpfn " pages)\n", - __FUNCTION__, name, seg->vstart, seg->vend, seg->pfn, pages); + " (pfn 0x%" PRIpfn " + 0x%" PRIpfn " pages)\n", + __FUNCTION__, name, seg->vstart, seg->vend, seg->pfn, pages); /* map and clear pages */ ptr = xc_dom_seg_to_ptr(dom, seg); - if (NULL == ptr) - return -1; + if ( ptr == NULL ) + return -1; memset(ptr, 0, pages * page_size); return 0; @@ -427,7 +430,7 @@ int xc_dom_alloc_page(struct xc_dom_imag pfn = (start - dom->parms.virt_base) / page_size; xc_dom_printf("%-20s: %-12s : 0x%" PRIx64 " (pfn 0x%" PRIpfn ")\n", - __FUNCTION__, name, start, pfn); + __FUNCTION__, name, start, pfn); return pfn; } @@ -436,30 +439,30 @@ void xc_dom_unmap_one(struct xc_dom_imag unsigned int page_shift = XC_DOM_PAGE_SHIFT(dom); struct xc_dom_phys *phys, *prev = NULL; - for (phys = dom->phys_pages; NULL != phys; phys = phys->next) - { - if (pfn >= phys->first && pfn < phys->first + phys->count) - break; - prev = phys; - } - if (!phys) - { - xc_dom_printf("%s: Huh? no mapping with pfn 0x%" PRIpfn "\n", - __FUNCTION__, pfn); - return; + for ( phys = dom->phys_pages; phys != NULL; phys = phys->next ) + { + if ( (pfn >= phys->first) && (pfn < (phys->first + phys->count)) ) + break; + prev = phys; + } + if ( !phys ) + { + xc_dom_printf("%s: Huh? no mapping with pfn 0x%" PRIpfn "\n", + __FUNCTION__, pfn); + return; } munmap(phys->ptr, phys->count << page_shift); - if (prev) - prev->next = phys->next; + if ( prev ) + prev->next = phys->next; else - dom->phys_pages = phys->next; + dom->phys_pages = phys->next; } void xc_dom_unmap_all(struct xc_dom_image *dom) { - while (dom->phys_pages) - xc_dom_unmap_one(dom, dom->phys_pages->first); + while ( dom->phys_pages ) + xc_dom_unmap_one(dom, dom->phys_pages->first); } /* ------------------------------------------------------------------------ */ @@ -478,16 +481,16 @@ static struct xc_dom_loader *xc_dom_find { struct xc_dom_loader *loader = first_loader; - while (NULL != loader) - { - xc_dom_printf("%s: trying %s loader ... ", __FUNCTION__, loader->name); - if (0 == loader->probe(dom)) - { - xc_dom_printf("OK\n"); - return loader; - } - xc_dom_printf("failed\n"); - loader = loader->next; + while ( loader != NULL ) + { + xc_dom_printf("%s: trying %s loader ... ", __FUNCTION__, loader->name); + if ( loader->probe(dom) == 0 ) + { + xc_dom_printf("OK\n"); + return loader; + } + xc_dom_printf("failed\n"); + loader = loader->next; } xc_dom_panic(XC_INVALID_KERNEL, "%s: no loader found\n", __FUNCTION__); return NULL; @@ -503,14 +506,14 @@ static struct xc_dom_arch *xc_dom_find_a { struct xc_dom_arch *hooks = first_hook; - while (NULL != hooks) - { - if (0 == strcmp(hooks->guest_type, guest_type)) - return hooks; - hooks = hooks->next; + while ( hooks != NULL ) + { + if ( !strcmp(hooks->guest_type, guest_type)) + return hooks; + hooks = hooks->next; } xc_dom_panic(XC_INVALID_KERNEL, - "%s: not found (type %s)\n", __FUNCTION__, guest_type); + "%s: not found (type %s)\n", __FUNCTION__, guest_type); return NULL; } @@ -520,8 +523,8 @@ void xc_dom_release(struct xc_dom_image void xc_dom_release(struct xc_dom_image *dom) { xc_dom_printf("%s: called\n", __FUNCTION__); - if (dom->phys_pages) - xc_dom_unmap_all(dom); + if ( dom->phys_pages ) + xc_dom_unmap_all(dom); xc_dom_free_all(dom); free(dom); } @@ -531,16 +534,16 @@ struct xc_dom_image *xc_dom_allocate(con struct xc_dom_image *dom; xc_dom_printf("%s: cmdline=\"%s\", features=\"%s\"\n", - __FUNCTION__, cmdline, features); + __FUNCTION__, cmdline, features); dom = malloc(sizeof(*dom)); - if (!dom) - goto err; + if ( !dom ) + goto err; memset(dom, 0, sizeof(*dom)); - if (cmdline) - dom->cmdline = xc_dom_strdup(dom, cmdline); - if (features) - elf_xen_parse_features(features, dom->f_requested, NULL); + if ( cmdline ) + dom->cmdline = xc_dom_strdup(dom, cmdline); + if ( features ) + elf_xen_parse_features(features, dom->f_requested, NULL); dom->parms.virt_base = UNSET_ADDR; dom->parms.virt_entry = UNSET_ADDR; @@ -551,9 +554,9 @@ struct xc_dom_image *xc_dom_allocate(con dom->alloc_malloc += sizeof(*dom); return dom; - err: - if (dom) - xc_dom_release(dom); + err: + if ( dom ) + xc_dom_release(dom); return NULL; } @@ -561,8 +564,8 @@ int xc_dom_kernel_file(struct xc_dom_ima { xc_dom_printf("%s: filename=\"%s\"\n", __FUNCTION__, filename); dom->kernel_blob = xc_dom_malloc_filemap(dom, filename, &dom->kernel_size); - if (NULL == dom->kernel_blob) - return -1; + if ( dom->kernel_blob == NULL ) + return -1; return xc_dom_try_gunzip(dom, &dom->kernel_blob, &dom->kernel_size); } @@ -570,9 +573,9 @@ int xc_dom_ramdisk_file(struct xc_dom_im { xc_dom_printf("%s: filename=\"%s\"\n", __FUNCTION__, filename); dom->ramdisk_blob = - xc_dom_malloc_filemap(dom, filename, &dom->ramdisk_size); - if (NULL == dom->ramdisk_blob) - return -1; + xc_dom_malloc_filemap(dom, filename, &dom->ramdisk_size); + if ( dom->ramdisk_blob == NULL ) + return -1; // return xc_dom_try_gunzip(dom, &dom->ramdisk_blob, &dom->ramdisk_size); return 0; } @@ -586,7 +589,7 @@ int xc_dom_kernel_mem(struct xc_dom_imag } int xc_dom_ramdisk_mem(struct xc_dom_image *dom, const void *mem, - size_t memsize) + size_t memsize) { xc_dom_printf("%s: called\n", __FUNCTION__); dom->ramdisk_blob = (void *)mem; @@ -603,32 +606,33 @@ int xc_dom_parse_image(struct xc_dom_ima /* parse kernel image */ dom->kernel_loader = xc_dom_find_loader(dom); - if (NULL == dom->kernel_loader) - goto err; - if (0 != dom->kernel_loader->parser(dom)) - goto err; - if (NULL == dom->guest_type) - { - xc_dom_panic(XC_INTERNAL_ERROR, - "%s: guest_type not set\n", __FUNCTION__); - goto err; + if ( dom->kernel_loader == NULL ) + goto err; + if ( dom->kernel_loader->parser(dom) != 0 ) + goto err; + if ( dom->guest_type == NULL ) + { + xc_dom_panic(XC_INTERNAL_ERROR, + "%s: guest_type not set\n", __FUNCTION__); + goto err; } /* check features */ - for (i = 0; i < XENFEAT_NR_SUBMAPS; i++) - { - dom->f_active[i] |= dom->f_requested[i]; /* cmd line */ - dom->f_active[i] |= dom->parms.f_required[i]; /* kernel */ - if ((dom->f_active[i] & dom->parms.f_supported[i]) != dom->f_active[i]) - { - xc_dom_panic(XC_INVALID_PARAM, - "%s: unsupported feature requested\n", __FUNCTION__); - goto err; - } - } - return 0; - - err: + for ( i = 0; i < XENFEAT_NR_SUBMAPS; i++ ) + { + dom->f_active[i] |= dom->f_requested[i]; /* cmd line */ + dom->f_active[i] |= dom->parms.f_required[i]; /* kernel */ + if ( (dom->f_active[i] & dom->parms.f_supported[i]) != + dom->f_active[i] ) + { + xc_dom_panic(XC_INVALID_PARAM, + "%s: unsupported feature requested\n", __FUNCTION__); + goto err; + } + } + return 0; + + err: return -1; } @@ -638,27 +642,27 @@ int xc_dom_mem_init(struct xc_dom_image xen_pfn_t nr_pages, pfn; dom->arch_hooks = xc_dom_find_arch_hooks(dom->guest_type); - if (NULL == dom->arch_hooks) - { - xc_dom_panic(XC_INTERNAL_ERROR, "%s: arch hooks not set\n", - __FUNCTION__); - return -1; + if ( dom->arch_hooks == NULL ) + { + xc_dom_panic(XC_INTERNAL_ERROR, "%s: arch hooks not set\n", + __FUNCTION__); + return -1; } page_shift = XC_DOM_PAGE_SHIFT(dom); nr_pages = mem_mb << (20 - page_shift); xc_dom_printf("%s: mem %d MB, pages 0x%" PRIpfn " pages, %dk each\n", - __FUNCTION__, mem_mb, nr_pages, 1 << (page_shift-10)); + __FUNCTION__, mem_mb, nr_pages, 1 << (page_shift-10)); dom->total_pages = nr_pages; xc_dom_printf("%s: 0x%" PRIpfn " pages\n", - __FUNCTION__, dom->total_pages); + __FUNCTION__, dom->total_pages); /* setup initial p2m */ dom->p2m_host = xc_dom_malloc(dom, sizeof(xen_pfn_t) * dom->total_pages); - for (pfn = 0; pfn < dom->total_pages; pfn++) - dom->p2m_host[pfn] = pfn; + for ( pfn = 0; pfn < dom->total_pages; pfn++ ) + dom->p2m_host[pfn] = pfn; return 0; } @@ -668,36 +672,36 @@ int xc_dom_update_guest_p2m(struct xc_do uint64_t *p2m_64; xen_pfn_t i; - if (!dom->p2m_guest) - return 0; - - switch (dom->arch_hooks->sizeof_pfn) + if ( !dom->p2m_guest ) + return 0; + + switch ( dom->arch_hooks->sizeof_pfn ) { case 4: - xc_dom_printf("%s: dst 32bit, pages 0x%" PRIpfn " \n", - __FUNCTION__, dom->total_pages); - p2m_32 = dom->p2m_guest; - for (i = 0; i < dom->total_pages; i++) - if (INVALID_P2M_ENTRY != dom->p2m_host[i]) - p2m_32[i] = dom->p2m_host[i]; - else - p2m_32[i] = (uint32_t) - 1; - break; + xc_dom_printf("%s: dst 32bit, pages 0x%" PRIpfn " \n", + __FUNCTION__, dom->total_pages); + p2m_32 = dom->p2m_guest; + for ( i = 0; i < dom->total_pages; i++ ) + if ( dom->p2m_host[i] != INVALID_P2M_ENTRY ) + p2m_32[i] = dom->p2m_host[i]; + else + p2m_32[i] = (uint32_t) - 1; + break; case 8: - xc_dom_printf("%s: dst 64bit, pages 0x%" PRIpfn " \n", - __FUNCTION__, dom->total_pages); - p2m_64 = dom->p2m_guest; - for (i = 0; i < dom->total_pages; i++) - if (INVALID_P2M_ENTRY != dom->p2m_host[i]) - p2m_64[i] = dom->p2m_host[i]; - else - p2m_64[i] = (uint64_t) - 1; - break; + xc_dom_printf("%s: dst 64bit, pages 0x%" PRIpfn " \n", + __FUNCTION__, dom->total_pages); + p2m_64 = dom->p2m_guest; + for ( i = 0; i < dom->total_pages; i++ ) + if ( dom->p2m_host[i] != INVALID_P2M_ENTRY ) + p2m_64[i] = dom->p2m_host[i]; + else + p2m_64[i] = (uint64_t) - 1; + break; default: - xc_dom_panic(XC_INTERNAL_ERROR, - "sizeof_pfn is invalid (is %d, can be 4 or 8)", - dom->arch_hooks->sizeof_pfn); - return -1; + xc_dom_panic(XC_INTERNAL_ERROR, + "sizeof_pfn is invalid (is %d, can be 4 or 8)", + dom->arch_hooks->sizeof_pfn); + return -1; } return 0; } @@ -709,11 +713,11 @@ int xc_dom_build_image(struct xc_dom_ima xc_dom_printf("%s: called\n", __FUNCTION__); /* check for arch hooks */ - if (NULL == dom->arch_hooks) - { - xc_dom_panic(XC_INTERNAL_ERROR, "%s: arch hooks not set\n", - __FUNCTION__); - goto err; + if ( dom->arch_hooks == NULL ) + { + xc_dom_panic(XC_INTERNAL_ERROR, "%s: arch hooks not set\n", + __FUNCTION__); + goto err; } page_size = XC_DOM_PAGE_SIZE(dom); @@ -721,56 +725,65 @@ int xc_dom_build_image(struct xc_dom_ima dom->parms.virt_base &= ~(((uint64_t)1<<22)-1); /* load kernel */ - if (0 != xc_dom_alloc_segment(dom, &dom->kernel_seg, "kernel", - dom->kernel_seg.vstart, - dom->kernel_seg.vend - - dom->kernel_seg.vstart)) - goto err; - if (0 != dom->kernel_loader->loader(dom)) - goto err; + if ( xc_dom_alloc_segment(dom, &dom->kernel_seg, "kernel", + dom->kernel_seg.vstart, + dom->kernel_seg.vend - + dom->kernel_seg.vstart) != 0 ) + goto err; + if ( dom->kernel_loader->loader(dom) != 0 ) + goto err; /* load ramdisk */ - if (dom->ramdisk_blob) - { - size_t unziplen, ramdisklen; - void *ramdiskmap; - - unziplen = xc_dom_check_gzip(dom->ramdisk_blob, dom->ramdisk_size); - ramdisklen = unziplen ? unziplen : dom->ramdisk_size; - if (0 != xc_dom_alloc_segment(dom, &dom->ramdisk_seg, "ramdisk", 0, - ramdisklen)) - goto err; - ramdiskmap = xc_dom_seg_to_ptr(dom, &dom->ramdisk_seg); - if (unziplen) - { - if (-1 == xc_dom_do_gunzip(dom->ramdisk_blob, dom->ramdisk_size, - ramdiskmap, ramdisklen)) - goto err; - } - else - memcpy(ramdiskmap, dom->ramdisk_blob, dom->ramdisk_size); + if ( dom->ramdisk_blob ) + { + size_t unziplen, ramdisklen; + void *ramdiskmap; + + unziplen = xc_dom_check_gzip(dom->ramdisk_blob, dom->ramdisk_size); + ramdisklen = unziplen ? unziplen : dom->ramdisk_size; + if ( xc_dom_alloc_segment(dom, &dom->ramdisk_seg, "ramdisk", 0, + ramdisklen) != 0 ) + goto err; + ramdiskmap = xc_dom_seg_to_ptr(dom, &dom->ramdisk_seg); + if ( unziplen ) + { + if ( xc_dom_do_gunzip(dom->ramdisk_blob, dom->ramdisk_size, + ramdiskmap, ramdisklen) == -1 ) + goto err; + } + else + memcpy(ramdiskmap, dom->ramdisk_blob, dom->ramdisk_size); } /* allocate other pages */ - if (0 != dom->arch_hooks->alloc_magic_pages(dom)) - goto err; - if (dom->arch_hooks->count_pgtables) - { - dom->arch_hooks->count_pgtables(dom); - if (dom->pgtables > 0) - if (0 != - xc_dom_alloc_segment(dom, &dom->pgtables_seg, "page tables", 0, - dom->pgtables * page_size)) - goto err; - } - if (dom->alloc_bootstack) - dom->bootstack_pfn = xc_dom_alloc_page(dom, "boot stack"); + if ( dom->arch_hooks->alloc_magic_pages(dom) != 0 ) + goto err; + if ( dom->arch_hooks->count_pgtables ) + { + dom->arch_hooks->count_pgtables(dom); + if ( (dom->pgtables > 0) && + (xc_dom_alloc_segment(dom, &dom->pgtables_seg, "page tables", 0, + dom->pgtables * page_size) != 0) ) + goto err; + } + if ( dom->alloc_bootstack ) + dom->bootstack_pfn = xc_dom_alloc_page(dom, "boot stack"); xc_dom_printf("%-20s: virt_alloc_end : 0x%" PRIx64 "\n", - __FUNCTION__, dom->virt_alloc_end); + __FUNCTION__, dom->virt_alloc_end); xc_dom_printf("%-20s: virt_pgtab_end : 0x%" PRIx64 "\n", - __FUNCTION__, dom->virt_pgtab_end); - return 0; - - err: + __FUNCTION__, dom->virt_pgtab_end); + return 0; + + err: return -1; } + +/* + * Local variables: + * mode: C + * c-set-style: "BSD" + * c-basic-offset: 4 + * tab-width: 4 + * indent-tabs-mode: nil + * End: + */ diff -r 59b8d5168cc1 -r c051ed67258a tools/libxc/xc_dom_elfloader.c --- a/tools/libxc/xc_dom_elfloader.c Sat Feb 24 14:48:17 2007 +0000 +++ b/tools/libxc/xc_dom_elfloader.c Sat Feb 24 15:30:19 2007 +0000 @@ -19,33 +19,34 @@ /* ------------------------------------------------------------------------ */ static char *xc_dom_guest_type(struct xc_dom_image *dom, - struct elf_binary *elf) + struct elf_binary *elf) { uint64_t machine = elf_uval(elf, elf->ehdr, e_machine); - switch (machine) { + switch ( machine ) + { case EM_386: - switch (dom->parms.pae) { - case 3 /* PAEKERN_bimodal */: - if (strstr(dom->xen_caps, "xen-3.0-x86_32p")) - return "xen-3.0-x86_32p"; - return "xen-3.0-x86_32"; - case PAEKERN_extended_cr3: - case PAEKERN_yes: - return "xen-3.0-x86_32p"; - break; - case PAEKERN_no: - default: - return "xen-3.0-x86_32"; - } + switch ( dom->parms.pae ) + { + case 3 /* PAEKERN_bimodal */: + if ( strstr(dom->xen_caps, "xen-3.0-x86_32p") ) + return "xen-3.0-x86_32p"; + return "xen-3.0-x86_32"; + case PAEKERN_extended_cr3: + case PAEKERN_yes: + return "xen-3.0-x86_32p"; + case PAEKERN_no: + default: + return "xen-3.0-x86_32"; + } case EM_X86_64: - return "xen-3.0-x86_64"; + return "xen-3.0-x86_64"; case EM_IA_64: - return elf_msb(elf) ? "xen-3.0-ia64be" : "xen-3.0-ia64"; + return elf_msb(elf) ? "xen-3.0-ia64be" : "xen-3.0-ia64"; case EM_PPC64: - return "xen-3.0-powerpc64"; + return "xen-3.0-powerpc64"; default: - return "xen-3.0-unknown"; + return "xen-3.0-unknown"; } } @@ -54,20 +55,20 @@ static char *xc_dom_guest_type(struct xc static int check_elf_kernel(struct xc_dom_image *dom, int verbose) { - if (NULL == dom->kernel_blob) - { - if (verbose) - xc_dom_panic(XC_INTERNAL_ERROR, "%s: no kernel image loaded\n", - __FUNCTION__); - return -EINVAL; - } - - if (!elf_is_elfbinary(dom->kernel_blob)) - { - if (verbose) - xc_dom_panic(XC_INVALID_KERNEL, "%s: kernel is not an ELF image\n", - __FUNCTION__); - return -EINVAL; + if ( dom->kernel_blob == NULL ) + { + if ( verbose ) + xc_dom_panic(XC_INTERNAL_ERROR, "%s: no kernel image loaded\n", + __FUNCTION__); + return -EINVAL; + } + + if ( !elf_is_elfbinary(dom->kernel_blob) ) + { + if ( verbose ) + xc_dom_panic(XC_INVALID_KERNEL, "%s: kernel is not an ELF image\n", + __FUNCTION__); + return -EINVAL; } return 0; } @@ -78,7 +79,7 @@ static int xc_dom_probe_elf_kernel(struc } static int xc_dom_load_elf_symtab(struct xc_dom_image *dom, - struct elf_binary *elf, int load) + struct elf_binary *elf, int load) { struct elf_binary syms; const elf_shdr *shdr, *shdr2; @@ -87,125 +88,135 @@ static int xc_dom_load_elf_symtab(struct size_t size; int h, count, type, i, tables = 0; - if (elf_swap(elf)) { - xc_dom_printf("%s: non-native byte order, bsd symtab not supported\n", - __FUNCTION__); - return 0; - } - - if (load) { - if (!dom->bsd_symtab_start) - return 0; - size = dom->kernel_seg.vend - dom->bsd_symtab_start; - hdr = xc_dom_vaddr_to_ptr(dom, dom->bsd_symtab_start); - *(int *)hdr = size - sizeof(int); - } else { - size = sizeof(int) + elf_size(elf, elf->ehdr) + - elf_shdr_count(elf) * elf_size(elf, shdr); - hdr = xc_dom_malloc(dom, size); - if (hdr == NULL) - return 0; - dom->bsd_symtab_start = elf_round_up(&syms, dom->kernel_seg.vend); + if ( elf_swap(elf) ) + { + xc_dom_printf("%s: non-native byte order, bsd symtab not supported\n", + __FUNCTION__); + return 0; + } + + if ( load ) + { + if ( !dom->bsd_symtab_start ) + return 0; + size = dom->kernel_seg.vend - dom->bsd_symtab_start; + hdr = xc_dom_vaddr_to_ptr(dom, dom->bsd_symtab_start); + *(int *)hdr = size - sizeof(int); + } + else + { + size = sizeof(int) + elf_size(elf, elf->ehdr) + + elf_shdr_count(elf) * elf_size(elf, shdr); + hdr = xc_dom_malloc(dom, size); + if ( hdr == NULL ) + return 0; + dom->bsd_symtab_start = elf_round_up(&syms, dom->kernel_seg.vend); } memcpy(hdr + sizeof(int), - elf->image, - elf_size(elf, elf->ehdr)); + elf->image, + elf_size(elf, elf->ehdr)); memcpy(hdr + sizeof(int) + elf_size(elf, elf->ehdr), - elf->image + elf_uval(elf, elf->ehdr, e_shoff), - elf_shdr_count(elf) * elf_size(elf, shdr)); - if (elf_64bit(elf)) { - Elf64_Ehdr *ehdr = (Elf64_Ehdr *)(hdr + sizeof(int)); - ehdr->e_phoff = 0; - ehdr->e_phentsize = 0; - ehdr->e_phnum = 0; - ehdr->e_shoff = elf_size(elf, elf->ehdr); - ehdr->e_shstrndx = SHN_UNDEF; - } else { - Elf32_Ehdr *ehdr = (Elf32_Ehdr *)(hdr + sizeof(int)); - ehdr->e_phoff = 0; - ehdr->e_phentsize = 0; - ehdr->e_phnum = 0; - ehdr->e_shoff = elf_size(elf, elf->ehdr); - ehdr->e_shstrndx = SHN_UNDEF; - } - if (0 != elf_init(&syms, hdr + sizeof(int), size - sizeof(int))) - return -1; - if (xc_dom_logfile) - elf_set_logfile(&syms, xc_dom_logfile, 1); + elf->image + elf_uval(elf, elf->ehdr, e_shoff), + elf_shdr_count(elf) * elf_size(elf, shdr)); + if ( elf_64bit(elf) ) + { + Elf64_Ehdr *ehdr = (Elf64_Ehdr *)(hdr + sizeof(int)); + ehdr->e_phoff = 0; + ehdr->e_phentsize = 0; + ehdr->e_phnum = 0; + ehdr->e_shoff = elf_size(elf, elf->ehdr); + ehdr->e_shstrndx = SHN_UNDEF; + } + else + { + Elf32_Ehdr *ehdr = (Elf32_Ehdr *)(hdr + sizeof(int)); + ehdr->e_phoff = 0; + ehdr->e_phentsize = 0; + ehdr->e_phnum = 0; + ehdr->e_shoff = elf_size(elf, elf->ehdr); + ehdr->e_shstrndx = SHN_UNDEF; + } + if ( elf_init(&syms, hdr + sizeof(int), size - sizeof(int)) ) + return -1; + if ( xc_dom_logfile ) + elf_set_logfile(&syms, xc_dom_logfile, 1); symtab = dom->bsd_symtab_start + sizeof(int); maxaddr = elf_round_up(&syms, symtab + elf_size(&syms, syms.ehdr) + - elf_shdr_count(&syms) * elf_size(&syms, shdr)); + elf_shdr_count(&syms) * elf_size(&syms, shdr)); xc_dom_printf("%s/%s: bsd_symtab_start=%" PRIx64 ", kernel.end=0x%" PRIx64 - " -- symtab=0x%" PRIx64 ", maxaddr=0x%" PRIx64 "\n", - __FUNCTION__, load ? "load" : "parse", - dom->bsd_symtab_start, dom->kernel_seg.vend, symtab, maxaddr); + " -- symtab=0x%" PRIx64 ", maxaddr=0x%" PRIx64 "\n", + __FUNCTION__, load ? "load" : "parse", + dom->bsd_symtab_start, dom->kernel_seg.vend, + symtab, maxaddr); count = elf_shdr_count(&syms); - for (h = 0; h < count; h++) - { - shdr = elf_shdr_by_index(&syms, h); - type = elf_uval(&syms, shdr, sh_type); - if (type == SHT_STRTAB) - { - /* Look for a strtab @i linked to symtab @h. */ - for (i = 0; i < count; i++) { - shdr2 = elf_shdr_by_index(&syms, i); - if ((elf_uval(&syms, shdr2, sh_type) == SHT_SYMTAB) && - (elf_uval(&syms, shdr2, sh_link) == h)) - break; - } - /* Skip symtab @h if we found no corresponding strtab @i. */ - if (i == count) - { - if (elf_64bit(&syms)) - *(Elf64_Off*)(&shdr->e64.sh_offset) = 0; - else - *(Elf32_Off*)(&shdr->e32.sh_offset) = 0; - continue; - } - } - - if ((type == SHT_STRTAB) || (type == SHT_SYMTAB)) - { - /* Mangled to be based on ELF header location. */ - if (elf_64bit(&syms)) - *(Elf64_Off*)(&shdr->e64.sh_offset) = maxaddr - symtab; - else - *(Elf32_Off*)(&shdr->e32.sh_offset) = maxaddr - symtab; - size = elf_uval(&syms, shdr, sh_size); - maxaddr = elf_round_up(&syms, maxaddr + size); - tables++; - xc_dom_printf("%s: h=%d %s, size=0x%zx, maxaddr=0x%" PRIx64 "\n", - __FUNCTION__, h, - type == SHT_SYMTAB ? "symtab" : "strtab", - size, maxaddr); - - if (load) { - shdr2 = elf_shdr_by_index(elf, h); - memcpy((void*)elf_section_start(&syms, shdr), - elf_section_start(elf, shdr2), - size); - } - } - - /* Name is NULL. */ - if (elf_64bit(&syms)) - *(Elf64_Half*)(&shdr->e64.sh_name) = 0; - else - *(Elf32_Word*)(&shdr->e32.sh_name) = 0; - } - - if (0 == tables) - { - xc_dom_printf("%s: no symbol table present\n", __FUNCTION__); - dom->bsd_symtab_start = 0; - return 0; - } - if (!load) - dom->kernel_seg.vend = maxaddr; + for ( h = 0; h < count; h++ ) + { + shdr = elf_shdr_by_index(&syms, h); + type = elf_uval(&syms, shdr, sh_type); + if ( type == SHT_STRTAB ) + { + /* Look for a strtab @i linked to symtab @h. */ + for ( i = 0; i < count; i++ ) + { + shdr2 = elf_shdr_by_index(&syms, i); + if ( (elf_uval(&syms, shdr2, sh_type) == SHT_SYMTAB) && + (elf_uval(&syms, shdr2, sh_link) == h) ) + break; + } + /* Skip symtab @h if we found no corresponding strtab @i. */ + if ( i == count ) + { + if ( elf_64bit(&syms) ) + *(Elf64_Off*)(&shdr->e64.sh_offset) = 0; + else + *(Elf32_Off*)(&shdr->e32.sh_offset) = 0; + continue; + } + } + + if ( (type == SHT_STRTAB) || (type == SHT_SYMTAB) ) + { + /* Mangled to be based on ELF header location. */ + if ( elf_64bit(&syms) ) + *(Elf64_Off*)(&shdr->e64.sh_offset) = maxaddr - symtab; + else + *(Elf32_Off*)(&shdr->e32.sh_offset) = maxaddr - symtab; + size = elf_uval(&syms, shdr, sh_size); + maxaddr = elf_round_up(&syms, maxaddr + size); + tables++; + xc_dom_printf("%s: h=%d %s, size=0x%zx, maxaddr=0x%" PRIx64 "\n", + __FUNCTION__, h, + type == SHT_SYMTAB ? "symtab" : "strtab", + size, maxaddr); + + if ( load ) + { + shdr2 = elf_shdr_by_index(elf, h); + memcpy((void*)elf_section_start(&syms, shdr), + elf_section_start(elf, shdr2), + size); + } + } + + /* Name is NULL. */ + if ( elf_64bit(&syms) ) + *(Elf64_Half*)(&shdr->e64.sh_name) = 0; + else + *(Elf32_Word*)(&shdr->e32.sh_name) = 0; + } + + if ( tables == 0 ) + { + xc_dom_printf("%s: no symbol table present\n", __FUNCTION__); + dom->bsd_symtab_start = 0; + return 0; + } + if ( !load ) + dom->kernel_seg.vend = maxaddr; return 0; } @@ -215,45 +226,45 @@ static int xc_dom_parse_elf_kernel(struc int rc; rc = check_elf_kernel(dom, 1); - if (0 != rc) - return rc; + if ( rc != 0 ) + return rc; elf = xc_dom_malloc(dom, sizeof(*elf)); dom->private_loader = elf; rc = elf_init(elf, dom->kernel_blob, dom->kernel_size); - if (xc_dom_logfile) - elf_set_logfile(elf, xc_dom_logfile, 1); - if (0 != rc) - { - xc_dom_panic(XC_INVALID_KERNEL, "%s: corrupted ELF image\n", - __FUNCTION__); - return rc; + if ( xc_dom_logfile ) + elf_set_logfile(elf, xc_dom_logfile, 1); + if ( rc != 0 ) + { + xc_dom_panic(XC_INVALID_KERNEL, "%s: corrupted ELF image\n", + __FUNCTION__); + return rc; } /* Find the section-header strings table. */ - if (NULL == elf->sec_strtab) - { - xc_dom_panic(XC_INVALID_KERNEL, "%s: ELF image has no shstrtab\n", - __FUNCTION__); - return -EINVAL; + if ( elf->sec_strtab == NULL ) + { + xc_dom_panic(XC_INVALID_KERNEL, "%s: ELF image has no shstrtab\n", + __FUNCTION__); + return -EINVAL; } /* parse binary and get xen meta info */ elf_parse_binary(elf); - if (0 != (rc = elf_xen_parse(elf, &dom->parms))) - return rc; + if ( (rc = elf_xen_parse(elf, &dom->parms)) != 0 ) + return rc; /* find kernel segment */ dom->kernel_seg.vstart = dom->parms.virt_kstart; dom->kernel_seg.vend = dom->parms.virt_kend; - if (dom->parms.bsd_symtab) - xc_dom_load_elf_symtab(dom, elf, 0); + if ( dom->parms.bsd_symtab ) + xc_dom_load_elf_symtab(dom, elf, 0); dom->guest_type = xc_dom_guest_type(dom, elf); xc_dom_printf("%s: %s: 0x%" PRIx64 " -> 0x%" PRIx64 "\n", - __FUNCTION__, dom->guest_type, - dom->kernel_seg.vstart, dom->kernel_seg.vend); + __FUNCTION__, dom->guest_type, + dom->kernel_seg.vstart, dom->kernel_seg.vend); return 0; } @@ -263,8 +274,8 @@ static int xc_dom_load_elf_kernel(struct elf->dest = xc_dom_seg_to_ptr(dom, &dom->kernel_seg); elf_load_binary(elf); - if (dom->parms.bsd_symtab) - xc_dom_load_elf_symtab(dom, elf, 1); + if ( dom->parms.bsd_symtab ) + xc_dom_load_elf_symtab(dom, elf, 1); return 0; } @@ -281,3 +292,13 @@ static void __init register_loader(void) { xc_dom_register_loader(&elf_loader); } + +/* + * Local variables: + * mode: C + * c-set-style: "BSD" + * c-basic-offset: 4 + * tab-width: 4 + * indent-tabs-mode: nil + * End: + */ diff -r 59b8d5168cc1 -r c051ed67258a tools/libxc/xc_dom_ia64.c --- a/tools/libxc/xc_dom_ia64.c Sat Feb 24 14:48:17 2007 +0000 +++ b/tools/libxc/xc_dom_ia64.c Sat Feb 24 15:30:19 2007 +0000 @@ -33,9 +33,9 @@ static int start_info_ia64(struct xc_dom static int start_info_ia64(struct xc_dom_image *dom) { start_info_ia64_t *start_info = - xc_dom_pfn_to_ptr(dom, dom->start_info_pfn, 1); + xc_dom_pfn_to_ptr(dom, dom->start_info_pfn, 1); struct xen_ia64_boot_param_ia64 *bp = - (struct xen_ia64_boot_param_ia64 *)(start_info + 1); + (struct xen_ia64_boot_param_ia64 *)(start_info + 1); xc_dom_printf("%s\n", __FUNCTION__); @@ -48,19 +48,19 @@ static int start_info_ia64(struct xc_dom start_info->console.domU.mfn = dom->console_pfn; start_info->console.domU.evtchn = dom->console_evtchn; - if (dom->ramdisk_blob) + if ( dom->ramdisk_blob ) { - start_info->mod_start = dom->ramdisk_seg.vstart; - start_info->mod_len = dom->ramdisk_seg.vend - dom->ramdisk_seg.vstart; - bp->initrd_start = start_info->mod_start; - bp->initrd_size = start_info->mod_len; + start_info->mod_start = dom->ramdisk_seg.vstart; + start_info->mod_len = dom->ramdisk_seg.vend - dom->ramdisk_seg.vstart; + bp->initrd_start = start_info->mod_start; + bp->initrd_size = start_info->mod_len; } bp->command_line = (dom->start_info_pfn << PAGE_SHIFT_IA64) - + offsetof(start_info_t, cmd_line); - if (dom->cmdline) + + offsetof(start_info_t, cmd_line); + if ( dom->cmdline ) { - strncpy((char *)start_info->cmd_line, dom->cmdline, MAX_GUEST_CMDLINE); - start_info->cmd_line[MAX_GUEST_CMDLINE - 1] = '\0'; + strncpy((char *)start_info->cmd_line, dom->cmdline, MAX_GUEST_CMDLINE); + start_info->cmd_line[MAX_GUEST_CMDLINE - 1] = '\0'; } return 0; } @@ -74,7 +74,7 @@ static int shared_info_ia64(struct xc_do memset(shared_info, 0, sizeof(*shared_info)); for (i = 0; i < MAX_VIRT_CPUS; i++) - shared_info->vcpu_info[i].evtchn_upcall_mask = 1; + shared_info->vcpu_info[i].evtchn_upcall_mask = 1; shared_info->arch.start_info_pfn = dom->start_info_pfn; return 0; } @@ -91,14 +91,14 @@ static int vcpu_ia64(struct xc_dom_image memset(ctxt, 0, sizeof(*ctxt)); ctxt->flags = 0; - ctxt->user_regs.cr_ipsr = 0; /* all necessary bits filled by hypervisor */ + ctxt->user_regs.cr_ipsr = 0; /* all necessary bits filled by hypervisor */ ctxt->user_regs.cr_iip = dom->parms.virt_entry; ctxt->user_regs.cr_ifs = (uint64_t) 1 << 63; -#ifdef __ia64__ /* FIXME */ +#ifdef __ia64__ /* FIXME */ ctxt->user_regs.ar_fpsr = xc_ia64_fpsr_default(); #endif ctxt->user_regs.r28 = (dom->start_info_pfn << PAGE_SHIFT_IA64) - + sizeof(start_info_ia64_t); + + sizeof(start_info_ia64_t); return 0; } @@ -117,3 +117,13 @@ static void __init register_arch_hooks(v { xc_dom_register_arch_hooks(&xc_dom_arch); } + +/* + * Local variables: + * mode: C + * c-set-style: "BSD" + * c-basic-offset: 4 + * tab-width: 4 + * indent-tabs-mode: nil + * End: + */ diff -r 59b8d5168cc1 -r c051ed67258a tools/libxc/xc_dom_x86.c --- a/tools/libxc/xc_dom_x86.c Sat Feb 24 14:48:17 2007 +0000 +++ b/tools/libxc/xc_dom_x86.c Sat Feb 24 15:30:19 2007 +0000 @@ -29,37 +29,37 @@ #define round_down(addr, mask) ((addr) & ~(mask)) #define round_up(addr, mask) ((addr) | (mask)) -static inline unsigned long +static unsigned long nr_page_tables(xen_vaddr_t start, xen_vaddr_t end, unsigned long bits) { xen_vaddr_t mask = bits_to_mask(bits); int tables; - if (0 == bits) - return 0; /* unused */ - - if (8 * sizeof(unsigned long) == bits) - { - /* must be pgd, need one */ - start = 0; - end = -1; - tables = 1; + if ( bits == 0 ) + return 0; /* unused */ + + if ( bits == (8 * sizeof(unsigned long)) ) + { + /* must be pgd, need one */ + start = 0; + end = -1; + tables = 1; } else { - start = round_down(start, mask); - end = round_up(end, mask); - tables = ((end - start) >> bits) + 1; + start = round_down(start, mask); + end = round_up(end, mask); + tables = ((end - start) >> bits) + 1; } xc_dom_printf("%s: 0x%016" PRIx64 "/%ld: 0x%016" PRIx64 - " -> 0x%016" PRIx64 ", %d table(s)\n", - __FUNCTION__, mask, bits, start, end, tables); + " -> 0x%016" PRIx64 ", %d table(s)\n", + __FUNCTION__, mask, bits, start, end, tables); return tables; } static int count_pgtables(struct xc_dom_image *dom, int pae, - int l4_bits, int l3_bits, int l2_bits, int l1_bits) + int l4_bits, int l3_bits, int l2_bits, int l1_bits) { int pages, extra_pages; xen_vaddr_t try_virt_end; @@ -68,27 +68,28 @@ static int count_pgtables(struct xc_dom_ extra_pages += dom->extra_pages; extra_pages += 128; /* 512kB padding */ pages = extra_pages; - for (;;) - { - try_virt_end = round_up(dom->virt_alloc_end + pages * PAGE_SIZE_X86, - bits_to_mask(22)); /* 4MB alignment */ - dom->pg_l4 = - nr_page_tables(dom->parms.virt_base, try_virt_end, l4_bits); - dom->pg_l3 = - nr_page_tables(dom->parms.virt_base, try_virt_end, l3_bits); - dom->pg_l2 = - nr_page_tables(dom->parms.virt_base, try_virt_end, l2_bits); - dom->pg_l1 = - nr_page_tables(dom->parms.virt_base, try_virt_end, l1_bits); - if (pae && try_virt_end < 0xc0000000) - { - xc_dom_printf("%s: PAE: extra l2 page table for l3#3\n", __FUNCTION__); - dom->pg_l2++; - } - dom->pgtables = dom->pg_l4 + dom->pg_l3 + dom->pg_l2 + dom->pg_l1; - pages = dom->pgtables + extra_pages; - if (dom->virt_alloc_end + pages * PAGE_SIZE_X86 <= try_virt_end + 1) - break; + for ( ; ; ) + { + try_virt_end = round_up(dom->virt_alloc_end + pages * PAGE_SIZE_X86, + bits_to_mask(22)); /* 4MB alignment */ + dom->pg_l4 = + nr_page_tables(dom->parms.virt_base, try_virt_end, l4_bits); + dom->pg_l3 = + nr_page_tables(dom->parms.virt_base, try_virt_end, l3_bits); + dom->pg_l2 = + nr_page_tables(dom->parms.virt_base, try_virt_end, l2_bits); + dom->pg_l1 = + nr_page_tables(dom->parms.virt_base, try_virt_end, l1_bits); + if (pae && try_virt_end < 0xc0000000) + { + xc_dom_printf("%s: PAE: extra l2 page table for l3#3\n", + __FUNCTION__); + dom->pg_l2++; + } + dom->pgtables = dom->pg_l4 + dom->pg_l3 + dom->pg_l2 + dom->pg_l1; + pages = dom->pgtables + extra_pages; + if ( dom->virt_alloc_end + pages * PAGE_SIZE_X86 <= try_virt_end + 1 ) + break; } dom->virt_pgtab_end = try_virt_end + 1; return 0; @@ -109,7 +110,7 @@ static int count_pgtables_x86_32_pae(str static int count_pgtables_x86_32_pae(struct xc_dom_image *dom) { return count_pgtables(dom, 1, 0, 32, - L3_PAGETABLE_SHIFT_PAE, L2_PAGETABLE_SHIFT_PAE); + L3_PAGETABLE_SHIFT_PAE, L2_PAGETABLE_SHIFT_PAE); } #define pfn_to_paddr(pfn) ((xen_paddr_t)(pfn) << PAGE_SHIFT_X86) @@ -124,28 +125,29 @@ static int setup_pgtables_x86_32(struct xen_vaddr_t addr; xen_pfn_t pgpfn; - for (addr = dom->parms.virt_base; addr < dom->virt_pgtab_end; - addr += PAGE_SIZE_X86) - { - if (NULL == l1tab) - { - /* get L1 tab, make L2 entry */ - l1tab = xc_dom_pfn_to_ptr(dom, l1pfn, 1); - l2off = l2_table_offset_i386(addr); - l2tab[l2off] = - pfn_to_paddr(xc_dom_p2m_guest(dom, l1pfn)) | L2_PROT; - l1pfn++; - } - - /* make L1 entry */ - l1off = l1_table_offset_i386(addr); - pgpfn = (addr - dom->parms.virt_base) >> PAGE_SHIFT_X86; - l1tab[l1off] = - pfn_to_paddr(xc_dom_p2m_guest(dom, pgpfn)) | L1_PROT; - if (addr >= dom->pgtables_seg.vstart && addr < dom->pgtables_seg.vend) - l1tab[l1off] &= ~_PAGE_RW; /* page tables are r/o */ - if (L1_PAGETABLE_ENTRIES_I386 - 1 == l1off) - l1tab = NULL; + for ( addr = dom->parms.virt_base; addr < dom->virt_pgtab_end; + addr += PAGE_SIZE_X86 ) + { + if ( l1tab == NULL ) + { + /* get L1 tab, make L2 entry */ + l1tab = xc_dom_pfn_to_ptr(dom, l1pfn, 1); + l2off = l2_table_offset_i386(addr); + l2tab[l2off] = + pfn_to_paddr(xc_dom_p2m_guest(dom, l1pfn)) | L2_PROT; + l1pfn++; + } + + /* make L1 entry */ + l1off = l1_table_offset_i386(addr); + pgpfn = (addr - dom->parms.virt_base) >> PAGE_SHIFT_X86; + l1tab[l1off] = + pfn_to_paddr(xc_dom_p2m_guest(dom, pgpfn)) | L1_PROT; + if ( (addr >= dom->pgtables_seg.vstart) && + (addr < dom->pgtables_seg.vend) ) + l1tab[l1off] &= ~_PAGE_RW; /* page tables are r/o */ + if ( l1off == (L1_PAGETABLE_ENTRIES_I386 - 1) ) + l1tab = NULL; } return 0; } @@ -162,46 +164,47 @@ static int setup_pgtables_x86_32_pae(str xen_vaddr_t addr; xen_pfn_t pgpfn; - for (addr = dom->parms.virt_base; addr < dom->virt_pgtab_end; - addr += PAGE_SIZE_X86) - { - if (NULL == l2tab) - { - /* get L2 tab, make L3 entry */ - l2tab = xc_dom_pfn_to_ptr(dom, l2pfn, 1); - l3off = l3_table_offset_pae(addr); - l3tab[l3off] = - pfn_to_paddr(xc_dom_p2m_guest(dom, l2pfn)) | L3_PROT; - l2pfn++; - } - - if (NULL == l1tab) - { - /* get L1 tab, make L2 entry */ - l1tab = xc_dom_pfn_to_ptr(dom, l1pfn, 1); - l2off = l2_table_offset_pae(addr); - l2tab[l2off] = - pfn_to_paddr(xc_dom_p2m_guest(dom, l1pfn)) | L2_PROT; - if (L2_PAGETABLE_ENTRIES_PAE - 1 == l2off) - l2tab = NULL; - l1pfn++; - } - - /* make L1 entry */ - l1off = l1_table_offset_pae(addr); - pgpfn = (addr - dom->parms.virt_base) >> PAGE_SHIFT_X86; - l1tab[l1off] = - pfn_to_paddr(xc_dom_p2m_guest(dom, pgpfn)) | L1_PROT; - if (addr >= dom->pgtables_seg.vstart && addr < dom->pgtables_seg.vend) - l1tab[l1off] &= ~_PAGE_RW; /* page tables are r/o */ - if (L1_PAGETABLE_ENTRIES_PAE - 1 == l1off) - l1tab = NULL; - } - - if (dom->virt_pgtab_end <= 0xc0000000) - { - xc_dom_printf("%s: PAE: extra l2 page table for l3#3\n", __FUNCTION__); - l3tab[3] = pfn_to_paddr(xc_dom_p2m_guest(dom, l2pfn)) | L3_PROT; + for ( addr = dom->parms.virt_base; addr < dom->virt_pgtab_end; + addr += PAGE_SIZE_X86 ) + { + if ( l2tab == NULL ) + { + /* get L2 tab, make L3 entry */ + l2tab = xc_dom_pfn_to_ptr(dom, l2pfn, 1); + l3off = l3_table_offset_pae(addr); + l3tab[l3off] = + pfn_to_paddr(xc_dom_p2m_guest(dom, l2pfn)) | L3_PROT; + l2pfn++; + } + + if ( l1tab == NULL ) + { + /* get L1 tab, make L2 entry */ + l1tab = xc_dom_pfn_to_ptr(dom, l1pfn, 1); + l2off = l2_table_offset_pae(addr); + l2tab[l2off] = + pfn_to_paddr(xc_dom_p2m_guest(dom, l1pfn)) | L2_PROT; + if ( l2off == (L2_PAGETABLE_ENTRIES_PAE - 1) ) + l2tab = NULL; + l1pfn++; + } + + /* make L1 entry */ + l1off = l1_table_offset_pae(addr); + pgpfn = (addr - dom->parms.virt_base) >> PAGE_SHIFT_X86; + l1tab[l1off] = + pfn_to_paddr(xc_dom_p2m_guest(dom, pgpfn)) | L1_PROT; + if ( (addr >= dom->pgtables_seg.vstart) && + (addr < dom->pgtables_seg.vend) ) + l1tab[l1off] &= ~_PAGE_RW; /* page tables are r/o */ + if ( l1off == (L1_PAGETABLE_ENTRIES_PAE - 1) ) + l1tab = NULL; + } + + if ( dom->virt_pgtab_end <= 0xc0000000 ) + { + xc_dom_printf("%s: PAE: extra l2 page table for l3#3\n", __FUNCTION__); + l3tab[3] = pfn_to_paddr(xc_dom_p2m_guest(dom, l2pfn)) | L3_PROT; } return 0; } @@ -216,9 +219,10 @@ static int count_pgtables_x86_64(struct static int count_pgtables_x86_64(struct xc_dom_image *dom) { return count_pgtables(dom, 0, - L4_PAGETABLE_SHIFT_X86_64 + 9, - L4_PAGETABLE_SHIFT_X86_64, - L3_PAGETABLE_SHIFT_X86_64, L2_PAGETABLE_SHIFT_X86_64); + L4_PAGETABLE_SHIFT_X86_64 + 9, + L4_PAGETABLE_SHIFT_X86_64, + L3_PAGETABLE_SHIFT_X86_64, + L2_PAGETABLE_SHIFT_X86_64); } #define L1_PROT (_PAGE_PRESENT|_PAGE_RW|_PAGE_ACCESSED) @@ -232,7 +236,7 @@ static int setup_pgtables_x86_64(struct xen_pfn_t l3pfn = dom->pgtables_seg.pfn + dom->pg_l4; xen_pfn_t l2pfn = dom->pgtables_seg.pfn + dom->pg_l4 + dom->pg_l3; xen_pfn_t l1pfn = - dom->pgtables_seg.pfn + dom->pg_l4 + dom->pg_l3 + dom->pg_l2; + dom->pgtables_seg.pfn + dom->pg_l4 + dom->pg_l3 + dom->pg_l2; l4_pgentry_64_t *l4tab = xc_dom_pfn_to_ptr(dom, l4pfn, 1); l3_pgentry_64_t *l3tab = NULL; l2_pgentry_64_t *l2tab = NULL; @@ -241,52 +245,53 @@ static int setup_pgtables_x86_64(struct uint64_t addr; xen_pfn_t pgpfn; - for (addr = dom->parms.virt_base; addr < dom->virt_pgtab_end; - addr += PAGE_SIZE_X86) - { - if (NULL == l3tab) - { - /* get L3 tab, make L4 entry */ - l3tab = xc_dom_pfn_to_ptr(dom, l3pfn, 1); - l4off = l4_table_offset_x86_64(addr); - l4tab[l4off] = - pfn_to_paddr(xc_dom_p2m_guest(dom, l3pfn)) | L4_PROT; - l3pfn++; - } - - if (NULL == l2tab) - { - /* get L2 tab, make L3 entry */ - l2tab = xc_dom_pfn_to_ptr(dom, l2pfn, 1); - l3off = l3_table_offset_x86_64(addr); - l3tab[l3off] = - pfn_to_paddr(xc_dom_p2m_guest(dom, l2pfn)) | L3_PROT; - if (L3_PAGETABLE_ENTRIES_X86_64 - 1 == l3off) - l3tab = NULL; - l2pfn++; - } - - if (NULL == l1tab) - { - /* get L1 tab, make L2 entry */ - l1tab = xc_dom_pfn_to_ptr(dom, l1pfn, 1); - l2off = l2_table_offset_x86_64(addr); - l2tab[l2off] = - pfn_to_paddr(xc_dom_p2m_guest(dom, l1pfn)) | L2_PROT; - if (L2_PAGETABLE_ENTRIES_X86_64 - 1 == l2off) - l2tab = NULL; - l1pfn++; - } - - /* make L1 entry */ - l1off = l1_table_offset_x86_64(addr); - pgpfn = (addr - dom->parms.virt_base) >> PAGE_SHIFT_X86; - l1tab[l1off] = - pfn_to_paddr(xc_dom_p2m_guest(dom, pgpfn)) | L1_PROT; - if (addr >= dom->pgtables_seg.vstart && addr < dom->pgtables_seg.vend) - l1tab[l1off] &= ~_PAGE_RW; /* page tables are r/o */ - if (L1_PAGETABLE_ENTRIES_X86_64 - 1 == l1off) - l1tab = NULL; + for ( addr = dom->parms.virt_base; addr < dom->virt_pgtab_end; + addr += PAGE_SIZE_X86 ) + { + if ( l3tab == NULL ) + { + /* get L3 tab, make L4 entry */ + l3tab = xc_dom_pfn_to_ptr(dom, l3pfn, 1); + l4off = l4_table_offset_x86_64(addr); + l4tab[l4off] = + pfn_to_paddr(xc_dom_p2m_guest(dom, l3pfn)) | L4_PROT; + l3pfn++; + } + + if ( l2tab == NULL ) + { + /* get L2 tab, make L3 entry */ + l2tab = xc_dom_pfn_to_ptr(dom, l2pfn, 1); + l3off = l3_table_offset_x86_64(addr); + l3tab[l3off] = + pfn_to_paddr(xc_dom_p2m_guest(dom, l2pfn)) | L3_PROT; + if ( l3off == (L3_PAGETABLE_ENTRIES_X86_64 - 1) ) + l3tab = NULL; + l2pfn++; + } + + if ( l1tab == NULL ) + { + /* get L1 tab, make L2 entry */ + l1tab = xc_dom_pfn_to_ptr(dom, l1pfn, 1); + l2off = l2_table_offset_x86_64(addr); + l2tab[l2off] = + pfn_to_paddr(xc_dom_p2m_guest(dom, l1pfn)) | L2_PROT; + if ( l2off == (L2_PAGETABLE_ENTRIES_X86_64 - 1) ) + l2tab = NULL; + l1pfn++; + } + + /* make L1 entry */ + l1off = l1_table_offset_x86_64(addr); + pgpfn = (addr - dom->parms.virt_base) >> PAGE_SHIFT_X86; + l1tab[l1off] = + pfn_to_paddr(xc_dom_p2m_guest(dom, pgpfn)) | L1_PROT; + if ( (addr >= dom->pgtables_seg.vstart) && + (addr < dom->pgtables_seg.vend) ) + l1tab[l1off] &= ~_PAGE_RW; /* page tables are r/o */ + if ( l1off == (L1_PAGETABLE_ENTRIES_X86_64 - 1) ) + l1tab = NULL; } return 0; } @@ -303,16 +308,16 @@ static int alloc_magic_pages(struct xc_d size_t p2m_size = dom->total_pages * dom->arch_hooks->sizeof_pfn; /* allocate phys2mach table */ - if (0 != xc_dom_alloc_segment(dom, &dom->p2m_seg, "phys2mach", 0, p2m_size)) - return -1; + if ( xc_dom_alloc_segment(dom, &dom->p2m_seg, "phys2mach", 0, p2m_size) ) + return -1; dom->p2m_guest = xc_dom_seg_to_ptr(dom, &dom->p2m_seg); /* allocate special pages */ dom->start_info_pfn = xc_dom_alloc_page(dom, "start info"); dom->xenstore_pfn = xc_dom_alloc_page(dom, "xenstore"); dom->console_pfn = xc_dom_alloc_page(dom, "console"); - if (xc_dom_feature_translated(dom)) - dom->shared_info_pfn = xc_dom_alloc_page(dom, "shared info"); + if ( xc_dom_feature_translated(dom) ) + dom->shared_info_pfn = xc_dom_alloc_page(dom, "shared info"); dom->alloc_bootstack = 1; return 0; @@ -323,10 +328,10 @@ static int start_info_x86_32(struct xc_d static int start_info_x86_32(struct xc_dom_image *dom) { start_info_x86_32_t *start_info = - xc_dom_pfn_to_ptr(dom, dom->start_info_pfn, 1); + xc_dom_pfn_to_ptr(dom, dom->start_info_pfn, 1); xen_pfn_t shinfo = - xc_dom_feature_translated(dom) ? dom->shared_info_pfn : dom-> - shared_info_mfn; + xc_dom_feature_translated(dom) ? dom->shared_info_pfn : dom-> + shared_info_mfn; xc_dom_printf("%s: called\n", __FUNCTION__); @@ -343,26 +348,28 @@ static int start_info_x86_32(struct xc_d start_info->console.domU.mfn = xc_dom_p2m_guest(dom, dom->console_pfn); start_info->console.domU.evtchn = dom->console_evtchn; - if (dom->ramdisk_blob) - { - start_info->mod_start = dom->ramdisk_seg.vstart; - start_info->mod_len = dom->ramdisk_seg.vend - dom->ramdisk_seg.vstart; - } - if (dom->cmdline) - { - strncpy((char *)start_info->cmd_line, dom->cmdline, MAX_GUEST_CMDLINE); - start_info->cmd_line[MAX_GUEST_CMDLINE - 1] = '\0'; - } + if ( dom->ramdisk_blob ) + { + start_info->mod_start = dom->ramdisk_seg.vstart; + start_info->mod_len = dom->ramdisk_seg.vend - dom->ramdisk_seg.vstart; + } + + if ( dom->cmdline ) + { + strncpy((char *)start_info->cmd_line, dom->cmdline, MAX_GUEST_CMDLINE); + start_info->cmd_line[MAX_GUEST_CMDLINE - 1] = '\0'; + } + return 0; } static int start_info_x86_64(struct xc_dom_image *dom) { start_info_x86_64_t *start_info = - xc_dom_pfn_to_ptr(dom, dom->start_info_pfn, 1); + xc_dom_pfn_to_ptr(dom, dom->start_info_pfn, 1); xen_pfn_t shinfo = - xc_dom_feature_translated(dom) ? dom->shared_info_pfn : dom-> - shared_info_mfn; + xc_dom_feature_translated(dom) ? dom->shared_info_pfn : dom-> + shared_info_mfn; xc_dom_printf("%s: called\n", __FUNCTION__); @@ -379,16 +386,18 @@ static int start_info_x86_64(struct xc_d start_info->console.domU.mfn = xc_dom_p2m_guest(dom, dom->console_pfn); start_info->console.domU.evtchn = dom->console_evtchn; - if (dom->ramdisk_blob) - { - start_info->mod_start = dom->ramdisk_seg.vstart; - start_info->mod_len = dom->ramdisk_seg.vend - dom->ramdisk_seg.vstart; - } - if (dom->cmdline) - { - strncpy((char *)start_info->cmd_line, dom->cmdline, MAX_GUEST_CMDLINE); - start_info->cmd_line[MAX_GUEST_CMDLINE - 1] = '\0'; - } + if ( dom->ramdisk_blob ) + { + start_info->mod_start = dom->ramdisk_seg.vstart; + start_info->mod_len = dom->ramdisk_seg.vend - dom->ramdisk_seg.vstart; + } + + if ( dom->cmdline ) + { + strncpy((char *)start_info->cmd_line, dom->cmdline, MAX_GUEST_CMDLINE); + start_info->cmd_line[MAX_GUEST_CMDLINE - 1] = '\0'; + } + return 0; } @@ -400,8 +409,8 @@ static int shared_info_x86_32(struct xc_ xc_dom_printf("%s: called\n", __FUNCTION__); memset(shared_info, 0, sizeof(*shared_info)); - for (i = 0; i < MAX_VIRT_CPUS; i++) - shared_info->vcpu_info[i].evtchn_upcall_mask = 1; + for ( i = 0; i < MAX_VIRT_CPUS; i++ ) + shared_info->vcpu_info[i].evtchn_upcall_mask = 1; return 0; } @@ -413,8 +422,8 @@ static int shared_info_x86_64(struct xc_ xc_dom_printf("%s: called\n", __FUNCTION__); memset(shared_info, 0, sizeof(*shared_info)); - for (i = 0; i < MAX_VIRT_CPUS; i++) - shared_info->vcpu_info[i].evtchn_upcall_mask = 1; + for ( i = 0; i < MAX_VIRT_CPUS; i++ ) + shared_info->vcpu_info[i].evtchn_upcall_mask = 1; return 0; } @@ -432,10 +441,10 @@ static int vcpu_x86_32(struct xc_dom_ima memset(ctxt, 0, sizeof(*ctxt)); /* Virtual IDT is empty at start-of-day. */ - for (i = 0; i < 256; i++) - { - ctxt->trap_ctxt[i].vector = i; - ctxt->trap_ctxt[i].cs = FLAT_KERNEL_CS_X86_32; + for ( i = 0; i < 256; i++ ) + { + ctxt->trap_ctxt[i].vector = i; + ctxt->trap_ctxt[i].cs = FLAT_KERNEL_CS_X86_32; } /* No callback handlers. */ @@ -450,24 +459,24 @@ static int vcpu_x86_32(struct xc_dom_ima ctxt->user_regs.cs = FLAT_KERNEL_CS_X86_32; ctxt->user_regs.eip = dom->parms.virt_entry; ctxt->user_regs.esp = - dom->parms.virt_base + (dom->bootstack_pfn + 1) * PAGE_SIZE_X86; + dom->parms.virt_base + (dom->bootstack_pfn + 1) * PAGE_SIZE_X86; ctxt->user_regs.esi = - dom->parms.virt_base + (dom->start_info_pfn) * PAGE_SIZE_X86; - ctxt->user_regs.eflags = 1 << 9; /* Interrupt Enable */ + dom->parms.virt_base + (dom->start_info_pfn) * PAGE_SIZE_X86; + ctxt->user_regs.eflags = 1 << 9; /* Interrupt Enable */ ctxt->kernel_ss = FLAT_KERNEL_SS_X86_32; ctxt->kernel_sp = - dom->parms.virt_base + (dom->bootstack_pfn + 1) * PAGE_SIZE_X86; + dom->parms.virt_base + (dom->bootstack_pfn + 1) * PAGE_SIZE_X86; ctxt->flags = VGCF_in_kernel_X86_32; - if (dom->parms.pae == 2 /* extended_cr3 */ || - dom->parms.pae == 3 /* bimodal */) - ctxt->vm_assist |= (1UL << VMASST_TYPE_pae_extended_cr3); + if ( dom->parms.pae == 2 /* extended_cr3 */ || + dom->parms.pae == 3 /* bimodal */ ) + ctxt->vm_assist |= (1UL << VMASST_TYPE_pae_extended_cr3); cr3_pfn = xc_dom_p2m_guest(dom, dom->pgtables_seg.pfn); ctxt->ctrlreg[3] = xen_pfn_to_cr3_x86_32(cr3_pfn); xc_dom_printf("%s: cr3: pfn 0x%" PRIpfn " mfn 0x%" PRIpfn "\n", - __FUNCTION__, dom->pgtables_seg.pfn, cr3_pfn); + __FUNCTION__, dom->pgtables_seg.pfn, cr3_pfn); return 0; } @@ -484,10 +493,10 @@ static int vcpu_x86_64(struct xc_dom_ima memset(ctxt, 0, sizeof(*ctxt)); /* Virtual IDT is empty at start-of-day. */ - for (i = 0; i < 256; i++) - { - ctxt->trap_ctxt[i].vector = i; - ctxt->trap_ctxt[i].cs = FLAT_KERNEL_CS_X86_64; + for ( i = 0; i < 256; i++ ) + { + ctxt->trap_ctxt[i].vector = i; + ctxt->trap_ctxt[i].cs = FLAT_KERNEL_CS_X86_64; } ctxt->user_regs.ds = FLAT_KERNEL_DS_X86_64; @@ -498,20 +507,20 @@ static int vcpu_x86_64(struct xc_dom_ima ctxt->user_regs.cs = FLAT_KERNEL_CS_X86_64; ctxt->user_regs.rip = dom->parms.virt_entry; ctxt->user_regs.rsp = - dom->parms.virt_base + (dom->bootstack_pfn + 1) * PAGE_SIZE_X86; + dom->parms.virt_base + (dom->bootstack_pfn + 1) * PAGE_SIZE_X86; ctxt->user_regs.rsi = - dom->parms.virt_base + (dom->start_info_pfn) * PAGE_SIZE_X86; - ctxt->user_regs.rflags = 1 << 9; /* Interrupt Enable */ + dom->parms.virt_base + (dom->start_info_pfn) * PAGE_SIZE_X86; + ctxt->user_regs.rflags = 1 << 9; /* Interrupt Enable */ ctxt->kernel_ss = FLAT_KERNEL_SS_X86_64; ctxt->kernel_sp = - dom->parms.virt_base + (dom->bootstack_pfn + 1) * PAGE_SIZE_X86; + dom->parms.virt_base + (dom->bootstack_pfn + 1) * PAGE_SIZE_X86; ctxt->flags = VGCF_in_kernel_X86_64; cr3_pfn = xc_dom_p2m_guest(dom, dom->pgtables_seg.pfn); ctxt->ctrlreg[3] = xen_pfn_to_cr3_x86_64(cr3_pfn); xc_dom_printf("%s: cr3: pfn 0x%" PRIpfn " mfn 0x%" PRIpfn "\n", - __FUNCTION__, dom->pgtables_seg.pfn, cr3_pfn); + __FUNCTION__, dom->pgtables_seg.pfn, cr3_pfn); return 0; } @@ -559,3 +568,13 @@ static void __init register_arch_hooks(v xc_dom_register_arch_hooks(&xc_dom_32_pae); xc_dom_register_arch_hooks(&xc_dom_64); } + +/* + * Local variables: + * mode: C + * c-set-style: "BSD" + * c-basic-offset: 4 + * tab-width: 4 + * indent-tabs-mode: nil + * End: + */ diff -r 59b8d5168cc1 -r c051ed67258a tools/libxc/xc_efi.h --- a/tools/libxc/xc_efi.h Sat Feb 24 14:48:17 2007 +0000 +++ b/tools/libxc/xc_efi.h Sat Feb 24 15:30:19 2007 +0000 @@ -10,8 +10,8 @@ * Copyright (C) 1999 VA Linux Systems * Copyright (C) 1999 Walt Drummond <drummond@xxxxxxxxxxx> * Copyright (C) 1999, 2002-2003 Hewlett-Packard Co. - * David Mosberger-Tang <davidm@xxxxxxxxxx> - * Stephane Eranian <eranian@xxxxxxxxxx> + * David Mosberger-Tang <davidm@xxxxxxxxxx> + * Stephane Eranian <eranian@xxxxxxxxxx> */ /* diff -r 59b8d5168cc1 -r c051ed67258a tools/libxc/xc_private.c --- a/tools/libxc/xc_private.c Sat Feb 24 14:48:17 2007 +0000 +++ b/tools/libxc/xc_private.c Sat Feb 24 15:30:19 2007 +0000 @@ -100,7 +100,7 @@ void unlock_pages(void *addr, size_t len void unlock_pages(void *addr, size_t len) { #ifndef __sun__ - safe_munlock(addr, len); + safe_munlock(addr, len); #endif } diff -r 59b8d5168cc1 -r c051ed67258a tools/libxc/xg_private.c --- a/tools/libxc/xg_private.c Sat Feb 24 14:48:17 2007 +0000 +++ b/tools/libxc/xg_private.c Sat Feb 24 15:30:19 2007 +0000 @@ -54,45 +54,45 @@ char *xc_read_image(const char *filename #define CHUNK 1*1024*1024 while(1) { - if ( (tmp = realloc(image, *size + CHUNK)) == NULL ) - { - PERROR("Could not allocate memory for kernel image"); - free(image); - image = NULL; - goto out; - } - image = tmp; - - bytes = gzread(kernel_gfd, image + *size, CHUNK); - switch (bytes) - { - case -1: - PERROR("Error reading kernel image"); - free(image); - image = NULL; - goto out; - case 0: /* EOF */ - goto out; - default: - *size += bytes; - break; - } + if ( (tmp = realloc(image, *size + CHUNK)) == NULL ) + { + PERROR("Could not allocate memory for kernel image"); + free(image); + image = NULL; + goto out; + } + image = tmp; + + bytes = gzread(kernel_gfd, image + *size, CHUNK); + switch (bytes) + { + case -1: + PERROR("Error reading kernel image"); + free(image); + image = NULL; + goto out; + case 0: /* EOF */ + goto out; + default: + *size += bytes; + break; + } } #undef CHUNK out: if ( *size == 0 ) { - PERROR("Could not read kernel image"); - free(image); - image = NULL; + PERROR("Could not read kernel image"); + free(image); + image = NULL; } else if ( image ) { - /* Shrink allocation to fit image. */ - tmp = realloc(image, *size); - if ( tmp ) - image = tmp; + /* Shrink allocation to fit image. */ + tmp = realloc(image, *size); + if ( tmp ) + image = tmp; } if ( kernel_gfd != NULL ) @@ -189,29 +189,29 @@ unsigned long csum_page(void *page) } __attribute__((weak)) -int xc_hvm_build(int xc_handle, - uint32_t domid, - int memsize, - const char *image_name) -{ - errno = ENOSYS; - return -1; -} - -__attribute__((weak)) -int xc_hvm_save(int xc_handle, int io_fd, uint32_t dom, uint32_t max_iters, - uint32_t max_factor, uint32_t flags, - int (*suspend)(int domid)) -{ - errno = ENOSYS; - return -1; -} - -__attribute__((weak)) -int xc_hvm_restore(int xc_handle, int io_fd, uint32_t dom, - unsigned long max_pfn, unsigned int store_evtchn, - unsigned long *store_mfn, - unsigned int pae, unsigned int apic) + int xc_hvm_build(int xc_handle, + uint32_t domid, + int memsize, + const char *image_name) +{ + errno = ENOSYS; + return -1; +} + +__attribute__((weak)) + int xc_hvm_save(int xc_handle, int io_fd, uint32_t dom, uint32_t max_iters, + uint32_t max_factor, uint32_t flags, + int (*suspend)(int domid)) +{ + errno = ENOSYS; + return -1; +} + +__attribute__((weak)) + int xc_hvm_restore(int xc_handle, int io_fd, uint32_t dom, + unsigned long max_pfn, unsigned int store_evtchn, + unsigned long *store_mfn, + unsigned int pae, unsigned int apic) { errno = ENOSYS; return -1; @@ -228,3 +228,13 @@ __attribute__((weak)) int xc_set_hvm_par { return -ENOSYS; } + +/* + * Local variables: + * mode: C + * c-set-style: "BSD" + * c-basic-offset: 4 + * tab-width: 4 + * indent-tabs-mode: nil + * End: + */ _______________________________________________ Xen-changelog mailing list Xen-changelog@xxxxxxxxxxxxxxxxxxx http://lists.xensource.com/xen-changelog
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |