static void qemu_remap_bucket(MapCacheEntry *entry,

                              target_phys_addr_t size,

                              target_phys_addr_t address_index)

{

    uint8_t *vaddr_base;

    xen_pfn_t *pfns;

    int *err;

    unsigned int i, j;

    target_phys_addr_t nb_pfn = size >> XC_PAGE_SHIFT;



    trace_qemu_remap_bucket(address_index);



    pfns = qemu_mallocz(nb_pfn * sizeof (xen_pfn_t));

    err = qemu_mallocz(nb_pfn * sizeof (int));



    if (entry->vaddr_base != NULL) {

        if (munmap(entry->vaddr_base, size) != 0) {

            perror("unmap fails");

            exit(-1);

        }

    }



    for (i = 0; i < nb_pfn; i++) {

        pfns[i] = (address_index << (MCACHE_BUCKET_SHIFT-XC_PAGE_SHIFT)) + i;

    }



    vaddr_base = xc_map_foreign_bulk(xen_xc, xen_domid, PROT_READ|PROT_WRITE,

                                     pfns, err, nb_pfn);

    if (vaddr_base == NULL) {

        perror("xc_map_foreign_bulk");

        exit(-1);

    }



    entry->vaddr_base = vaddr_base;

    entry->paddr_index = address_index;



    for (i = 0; i < nb_pfn; i += BITS_PER_LONG) {

        unsigned long word = 0;

        if ((i + BITS_PER_LONG) > nb_pfn) {

            j = nb_pfn % BITS_PER_LONG;

        } else {

            j = BITS_PER_LONG;

        }

        while (j > 0) {

            word = (word << 1) | !err[i + --j];

        }

        entry->valid_mapping[i / BITS_PER_LONG] = word;

    }



    qemu_free(pfns);

    qemu_free(err);

}

static void qemu_remap_bucket(MapCacheEntry *entry,

                              target_phys_addr_t size,

                              target_phys_addr_t address_index)

{

    uint8_t *vaddr_base;

    xen_pfn_t *pfns;

    int *err;

    unsigned int i, j;

    target_phys_addr_t nb_pfn = size >> XC_PAGE_SHIFT;



    trace_qemu_remap_bucket(address_index);



    pfns = qemu_mallocz(nb_pfn * sizeof (xen_pfn_t));

    err = qemu_mallocz(nb_pfn * sizeof (int));



    if (entry->vaddr_base != NULL) {

        if (munmap(entry->vaddr_base, size) != 0) {

            perror("unmap fails");

            exit(-1);

        }

    }



    for (i = 0; i < nb_pfn; i++) {

        pfns[i] = (address_index << (MCACHE_BUCKET_SHIFT-XC_PAGE_SHIFT)) + i;

    }



    vaddr_base = xc_map_foreign_bulk(xen_xc, xen_domid, PROT_READ|PROT_WRITE,

                                     pfns, err, nb_pfn);

    if (vaddr_base == NULL) {

        perror("xc_map_foreign_bulk");

        exit(-1);

    }



    entry->vaddr_base = vaddr_base;

    entry->paddr_index = address_index;



    for (i = 0; i < nb_pfn; i += BITS_PER_LONG) {

        unsigned long word = 0;

        if ((i + BITS_PER_LONG) > nb_pfn) {

            j = nb_pfn % BITS_PER_LONG;

        } else {

            j = BITS_PER_LONG;

        }

        while (j > 0) {

            word = (word << 1) | !err[i + --j];

        }

        entry->valid_mapping[i / BITS_PER_LONG] = word;

    }



    qemu_free(pfns);

    qemu_free(err);

}

static void FUNC_0(MapCacheEntry *VAR_0,

                              target_phys_addr_t VAR_1,

                              target_phys_addr_t VAR_2)

{

    uint8_t *vaddr_base;

    xen_pfn_t *pfns;

    int *VAR_3;

    unsigned int VAR_4, VAR_5;

    target_phys_addr_t nb_pfn = VAR_1 >> XC_PAGE_SHIFT;



    trace_qemu_remap_bucket(VAR_2);



    pfns = qemu_mallocz(nb_pfn * sizeof (xen_pfn_t));

    VAR_3 = qemu_mallocz(nb_pfn * sizeof (int));



    if (VAR_0->vaddr_base != NULL) {

        if (munmap(VAR_0->vaddr_base, VAR_1) != 0) {

            perror("unmap fails");

            exit(-1);

        }

    }



    for (VAR_4 = 0; VAR_4 < nb_pfn; VAR_4++) {

        pfns[VAR_4] = (VAR_2 << (MCACHE_BUCKET_SHIFT-XC_PAGE_SHIFT)) + VAR_4;

    }



    vaddr_base = xc_map_foreign_bulk(xen_xc, xen_domid, PROT_READ|PROT_WRITE,

                                     pfns, VAR_3, nb_pfn);

    if (vaddr_base == NULL) {

        perror("xc_map_foreign_bulk");

        exit(-1);

    }



    VAR_0->vaddr_base = vaddr_base;

    VAR_0->paddr_index = VAR_2;



    for (VAR_4 = 0; VAR_4 < nb_pfn; VAR_4 += BITS_PER_LONG) {

        unsigned long word = 0;

        if ((VAR_4 + BITS_PER_LONG) > nb_pfn) {

            VAR_5 = nb_pfn % BITS_PER_LONG;

        } else {

            VAR_5 = BITS_PER_LONG;

        }

        while (VAR_5 > 0) {

            word = (word << 1) | !VAR_3[VAR_4 + --VAR_5];

        }

        VAR_0->valid_mapping[VAR_4 / BITS_PER_LONG] = word;

    }



    qemu_free(pfns);

    qemu_free(VAR_3);

}

static void FUNC_0(MapCacheEntry *VAR_0,
target_phys_addr_t VAR_1,
target_phys_addr_t VAR_2)
{ uint8_t *vaddr_base; xen_pfn_t *pfns; int *VAR_3; unsigned int VAR_4, VAR_5; target_phys_addr_t nb_pfn = VAR_1 >> XC_PAGE_SHIFT; trace_qemu_remap_bucket(VAR_2); pfns = qemu_mallocz(nb_pfn * sizeof (xen_pfn_t)); VAR_3 = qemu_mallocz(nb_pfn * sizeof (int)); if (VAR_0->vaddr_base != NULL) { if (munmap(VAR_0->vaddr_base, VAR_1) != 0) { perror("unmap fails"); exit(-1); } } for (VAR_4 = 0; VAR_4 < nb_pfn; VAR_4++) { pfns[VAR_4] = (VAR_2 << (MCACHE_BUCKET_SHIFT-XC_PAGE_SHIFT)) + VAR_4; } vaddr_base = xc_map_foreign_bulk(xen_xc, xen_domid, PROT_READ|PROT_WRITE,
pfns, VAR_3, nb_pfn); if (vaddr_base == NULL) { perror("xc_map_foreign_bulk"); exit(-1); } VAR_0->vaddr_base = vaddr_base; VAR_0->paddr_index = VAR_2; for (VAR_4 = 0; VAR_4 < nb_pfn; VAR_4 += BITS_PER_LONG) { unsigned long word = 0; if ((VAR_4 + BITS_PER_LONG) > nb_pfn) { VAR_5 = nb_pfn % BITS_PER_LONG; } else { VAR_5 = BITS_PER_LONG; } while (VAR_5 > 0) { word = (word << 1) | !VAR_3[VAR_4 + --VAR_5]; } VAR_0->valid_mapping[VAR_4 / BITS_PER_LONG] = word; } qemu_free(pfns); qemu_free(VAR_3); }