void kvmppc_read_hptes(ppc_hash_pte64_t *hptes, hwaddr ptex, int n)

{

    int fd, rc;

    int i;



    fd = kvmppc_get_htab_fd(false, ptex, &error_abort);



    i = 0;

    while (i < n) {

        struct kvm_get_htab_header *hdr;

        int m = n < HPTES_PER_GROUP ? n : HPTES_PER_GROUP;

        char buf[sizeof(*hdr) + m * HASH_PTE_SIZE_64];



        rc = read(fd, buf, sizeof(buf));

        if (rc < 0) {

            hw_error("kvmppc_read_hptes: Unable to read HPTEs");

        }



        hdr = (struct kvm_get_htab_header *)buf;

        while ((i < n) && ((char *)hdr < (buf + rc))) {

            int invalid = hdr->n_invalid;



            if (hdr->index != (ptex + i)) {

                hw_error("kvmppc_read_hptes: Unexpected HPTE index %"PRIu32

                         " != (%"HWADDR_PRIu" + %d", hdr->index, ptex, i);

            }



            memcpy(hptes + i, hdr + 1, HASH_PTE_SIZE_64 * hdr->n_valid);

            i += hdr->n_valid;



            if ((n - i) < invalid) {

                invalid = n - i;

            }

            memset(hptes + i, 0, invalid * HASH_PTE_SIZE_64);

            i += hdr->n_invalid;



            hdr = (struct kvm_get_htab_header *)

                ((char *)(hdr + 1) + HASH_PTE_SIZE_64 * hdr->n_valid);

        }

    }



    close(fd);

}

void kvmppc_read_hptes(ppc_hash_pte64_t *hptes, hwaddr ptex, int n)

{

    int fd, rc;

    int i;



    fd = kvmppc_get_htab_fd(false, ptex, &error_abort);



    i = 0;

    while (i < n) {

        struct kvm_get_htab_header *hdr;

        int m = n < HPTES_PER_GROUP ? n : HPTES_PER_GROUP;

        char buf[sizeof(*hdr) + m * HASH_PTE_SIZE_64];



        rc = read(fd, buf, sizeof(buf));

        if (rc < 0) {

            hw_error("kvmppc_read_hptes: Unable to read HPTEs");

        }



        hdr = (struct kvm_get_htab_header *)buf;

        while ((i < n) && ((char *)hdr < (buf + rc))) {

            int invalid = hdr->n_invalid;



            if (hdr->index != (ptex + i)) {

                hw_error("kvmppc_read_hptes: Unexpected HPTE index %"PRIu32

                         " != (%"HWADDR_PRIu" + %d", hdr->index, ptex, i);

            }



            memcpy(hptes + i, hdr + 1, HASH_PTE_SIZE_64 * hdr->n_valid);

            i += hdr->n_valid;



            if ((n - i) < invalid) {

                invalid = n - i;

            }

            memset(hptes + i, 0, invalid * HASH_PTE_SIZE_64);

            i += hdr->n_invalid;



            hdr = (struct kvm_get_htab_header *)

                ((char *)(hdr + 1) + HASH_PTE_SIZE_64 * hdr->n_valid);

        }

    }



    close(fd);

}

void FUNC_0(ppc_hash_pte64_t *VAR_0, hwaddr VAR_1, int VAR_2)

{

    int VAR_3, VAR_4;

    int VAR_5;



    VAR_3 = kvmppc_get_htab_fd(false, VAR_1, &error_abort);



    VAR_5 = 0;

    while (VAR_5 < VAR_2) {

        struct kvm_get_htab_header *VAR_6;

        int VAR_7 = VAR_2 < HPTES_PER_GROUP ? VAR_2 : HPTES_PER_GROUP;

        char VAR_8[sizeof(*VAR_6) + VAR_7 * HASH_PTE_SIZE_64];



        VAR_4 = read(VAR_3, VAR_8, sizeof(VAR_8));

        if (VAR_4 < 0) {

            hw_error("FUNC_0: Unable to read HPTEs");

        }



        VAR_6 = (struct kvm_get_htab_header *)VAR_8;

        while ((VAR_5 < VAR_2) && ((char *)VAR_6 < (VAR_8 + VAR_4))) {

            int VAR_9 = VAR_6->n_invalid;



            if (VAR_6->index != (VAR_1 + VAR_5)) {

                hw_error("FUNC_0: Unexpected HPTE index %"PRIu32

                         " != (%"HWADDR_PRIu" + %d", VAR_6->index, VAR_1, VAR_5);

            }



            memcpy(VAR_0 + VAR_5, VAR_6 + 1, HASH_PTE_SIZE_64 * VAR_6->n_valid);

            VAR_5 += VAR_6->n_valid;



            if ((VAR_2 - VAR_5) < VAR_9) {

                VAR_9 = VAR_2 - VAR_5;

            }

            memset(VAR_0 + VAR_5, 0, VAR_9 * HASH_PTE_SIZE_64);

            VAR_5 += VAR_6->n_invalid;



            VAR_6 = (struct kvm_get_htab_header *)

                ((char *)(VAR_6 + 1) + HASH_PTE_SIZE_64 * VAR_6->n_valid);

        }

    }



    close(VAR_3);

}

void FUNC_0(ppc_hash_pte64_t *VAR_0, hwaddr VAR_1, int VAR_2)
{ int VAR_3, VAR_4; int VAR_5; VAR_3 = kvmppc_get_htab_fd(false, VAR_1, &error_abort); VAR_5 = 0; while (VAR_5 < VAR_2) { struct kvm_get_htab_header *VAR_6; int VAR_7 = VAR_2 < HPTES_PER_GROUP ? VAR_2 : HPTES_PER_GROUP; char VAR_8[sizeof(*VAR_6) + VAR_7 * HASH_PTE_SIZE_64]; VAR_4 = read(VAR_3, VAR_8, sizeof(VAR_8)); if (VAR_4 < 0) { hw_error("FUNC_0: Unable to read HPTEs"); } VAR_6 = (struct kvm_get_htab_header *)VAR_8; while ((VAR_5 < VAR_2) && ((char *)VAR_6 < (VAR_8 + VAR_4))) { int VAR_9 = VAR_6->n_invalid; if (VAR_6->index != (VAR_1 + VAR_5)) { hw_error("FUNC_0: Unexpected HPTE index %"PRIu32
" != (%"HWADDR_PRIu" + %d", VAR_6->index, VAR_1, VAR_5); } memcpy(VAR_0 + VAR_5, VAR_6 + 1, HASH_PTE_SIZE_64 * VAR_6->n_valid); VAR_5 += VAR_6->n_valid; if ((VAR_2 - VAR_5) < VAR_9) { VAR_9 = VAR_2 - VAR_5; } memset(VAR_0 + VAR_5, 0, VAR_9 * HASH_PTE_SIZE_64); VAR_5 += VAR_6->n_invalid; VAR_6 = (struct kvm_get_htab_header *)
((char *)(VAR_6 + 1) + HASH_PTE_SIZE_64 * VAR_6->n_valid); } } close(VAR_3); }