static int htab_load(QEMUFile *f, void *opaque, int version_id)

{

    sPAPRMachineState *spapr = opaque;

    uint32_t section_hdr;

    int fd = -1;



    if (version_id < 1 || version_id > 1) {

        error_report("htab_load() bad version");

        return -EINVAL;

    }



    section_hdr = qemu_get_be32(f);



    if (section_hdr) {

        Error *local_err;



        /* First section gives the htab size */

        spapr_reallocate_hpt(spapr, section_hdr, &local_err);

        if (local_err) {

            error_report_err(local_err);

            return -EINVAL;

        }

        return 0;

    }



    if (!spapr->htab) {

        assert(kvm_enabled());



        fd = kvmppc_get_htab_fd(true);

        if (fd < 0) {

            error_report("Unable to open fd to restore KVM hash table: %s",

                         strerror(errno));

        }

    }



    while (true) {

        uint32_t index;

        uint16_t n_valid, n_invalid;



        index = qemu_get_be32(f);

        n_valid = qemu_get_be16(f);

        n_invalid = qemu_get_be16(f);



        if ((index == 0) && (n_valid == 0) && (n_invalid == 0)) {

            /* End of Stream */

            break;

        }



        if ((index + n_valid + n_invalid) >

            (HTAB_SIZE(spapr) / HASH_PTE_SIZE_64)) {

            /* Bad index in stream */

            error_report(

                "htab_load() bad index %d (%hd+%hd entries) in htab stream (htab_shift=%d)",

                index, n_valid, n_invalid, spapr->htab_shift);

            return -EINVAL;

        }



        if (spapr->htab) {

            if (n_valid) {

                qemu_get_buffer(f, HPTE(spapr->htab, index),

                                HASH_PTE_SIZE_64 * n_valid);

            }

            if (n_invalid) {

                memset(HPTE(spapr->htab, index + n_valid), 0,

                       HASH_PTE_SIZE_64 * n_invalid);

            }

        } else {

            int rc;



            assert(fd >= 0);



            rc = kvmppc_load_htab_chunk(f, fd, index, n_valid, n_invalid);

            if (rc < 0) {

                return rc;

            }

        }

    }



    if (!spapr->htab) {

        assert(fd >= 0);

        close(fd);

    }



    return 0;

}

static int htab_load(QEMUFile *f, void *opaque, int version_id)

{

    sPAPRMachineState *spapr = opaque;

    uint32_t section_hdr;

    int fd = -1;



    if (version_id < 1 || version_id > 1) {

        error_report("htab_load() bad version");

        return -EINVAL;

    }



    section_hdr = qemu_get_be32(f);



    if (section_hdr) {

        Error *local_err;



        

        spapr_reallocate_hpt(spapr, section_hdr, &local_err);

        if (local_err) {

            error_report_err(local_err);

            return -EINVAL;

        }

        return 0;

    }



    if (!spapr->htab) {

        assert(kvm_enabled());



        fd = kvmppc_get_htab_fd(true);

        if (fd < 0) {

            error_report("Unable to open fd to restore KVM hash table: %s",

                         strerror(errno));

        }

    }



    while (true) {

        uint32_t index;

        uint16_t n_valid, n_invalid;



        index = qemu_get_be32(f);

        n_valid = qemu_get_be16(f);

        n_invalid = qemu_get_be16(f);



        if ((index == 0) && (n_valid == 0) && (n_invalid == 0)) {

            

            break;

        }



        if ((index + n_valid + n_invalid) >

            (HTAB_SIZE(spapr) / HASH_PTE_SIZE_64)) {

            

            error_report(

                "htab_load() bad index %d (%hd+%hd entries) in htab stream (htab_shift=%d)",

                index, n_valid, n_invalid, spapr->htab_shift);

            return -EINVAL;

        }



        if (spapr->htab) {

            if (n_valid) {

                qemu_get_buffer(f, HPTE(spapr->htab, index),

                                HASH_PTE_SIZE_64 * n_valid);

            }

            if (n_invalid) {

                memset(HPTE(spapr->htab, index + n_valid), 0,

                       HASH_PTE_SIZE_64 * n_invalid);

            }

        } else {

            int rc;



            assert(fd >= 0);



            rc = kvmppc_load_htab_chunk(f, fd, index, n_valid, n_invalid);

            if (rc < 0) {

                return rc;

            }

        }

    }



    if (!spapr->htab) {

        assert(fd >= 0);

        close(fd);

    }



    return 0;

}

        Error *local_err;
static int FUNC_0(QEMUFile *VAR_0, void *VAR_1, int VAR_2)

{

    sPAPRMachineState *spapr = VAR_1;

    uint32_t section_hdr;

    int VAR_3 = -1;



    if (VAR_2 < 1 || VAR_2 > 1) {

        error_report("FUNC_0() bad version");

        return -EINVAL;

    }



    section_hdr = qemu_get_be32(VAR_0);



    if (section_hdr) {

        Error *local_err;



        

        spapr_reallocate_hpt(spapr, section_hdr, &local_err);

        if (local_err) {

            error_report_err(local_err);

            return -EINVAL;

        }

        return 0;

    }



    if (!spapr->htab) {

        assert(kvm_enabled());



        VAR_3 = kvmppc_get_htab_fd(true);

        if (VAR_3 < 0) {

            error_report("Unable to open VAR_3 to restore KVM hash table: %s",

                         strerror(errno));

        }

    }



    while (true) {

        uint32_t index;

        uint16_t n_valid, n_invalid;



        index = qemu_get_be32(VAR_0);

        n_valid = qemu_get_be16(VAR_0);

        n_invalid = qemu_get_be16(VAR_0);



        if ((index == 0) && (n_valid == 0) && (n_invalid == 0)) {

            

            break;

        }



        if ((index + n_valid + n_invalid) >

            (HTAB_SIZE(spapr) / HASH_PTE_SIZE_64)) {

            

            error_report(

                "FUNC_0() bad index %d (%hd+%hd entries) in htab stream (htab_shift=%d)",

                index, n_valid, n_invalid, spapr->htab_shift);

            return -EINVAL;

        }



        if (spapr->htab) {

            if (n_valid) {

                qemu_get_buffer(VAR_0, HPTE(spapr->htab, index),

                                HASH_PTE_SIZE_64 * n_valid);

            }

            if (n_invalid) {

                memset(HPTE(spapr->htab, index + n_valid), 0,

                       HASH_PTE_SIZE_64 * n_invalid);

            }

        } else {

            int VAR_4;



            assert(VAR_3 >= 0);



            VAR_4 = kvmppc_load_htab_chunk(VAR_0, VAR_3, index, n_valid, n_invalid);

            if (VAR_4 < 0) {

                return VAR_4;

            }

        }

    }



    if (!spapr->htab) {

        assert(VAR_3 >= 0);

        close(VAR_3);

    }



    return 0;

}

static int FUNC_0(QEMUFile *VAR_0, void *VAR_1, int VAR_2)
{ sPAPRMachineState *spapr = VAR_1; uint32_t section_hdr; int VAR_3 = -1; if (VAR_2 < 1 || VAR_2 > 1) { error_report("FUNC_0() bad version"); return -EINVAL; } section_hdr = qemu_get_be32(VAR_0); if (section_hdr) { Error *local_err; spapr_reallocate_hpt(spapr, section_hdr, &local_err); if (local_err) { error_report_err(local_err); return -EINVAL; } return 0; } if (!spapr->htab) { assert(kvm_enabled()); VAR_3 = kvmppc_get_htab_fd(true); if (VAR_3 < 0) { error_report("Unable to open VAR_3 to restore KVM hash table: %s",
strerror(errno)); } } while (true) { uint32_t index; uint16_t n_valid, n_invalid; index = qemu_get_be32(VAR_0); n_valid = qemu_get_be16(VAR_0); n_invalid = qemu_get_be16(VAR_0); if ((index == 0) && (n_valid == 0) && (n_invalid == 0)) { break; } if ((index + n_valid + n_invalid) >
(HTAB_SIZE(spapr) / HASH_PTE_SIZE_64)) { error_report(
"FUNC_0() bad index %d (%hd+%hd entries) in htab stream (htab_shift=%d)",
index, n_valid, n_invalid, spapr->htab_shift); return -EINVAL; } if (spapr->htab) { if (n_valid) { qemu_get_buffer(VAR_0, HPTE(spapr->htab, index),
HASH_PTE_SIZE_64 * n_valid); } if (n_invalid) { memset(HPTE(spapr->htab, index + n_valid), 0,
HASH_PTE_SIZE_64 * n_invalid); } } else { int VAR_4; assert(VAR_3 >= 0); VAR_4 = kvmppc_load_htab_chunk(VAR_0, VAR_3, index, n_valid, n_invalid); if (VAR_4 < 0) { return VAR_4; } } } if (!spapr->htab) { assert(VAR_3 >= 0); close(VAR_3); } return 0; }