unsigned long init_guest_space(unsigned long host_start,

                               unsigned long host_size,

                               unsigned long guest_start,

                               bool fixed)

{

    unsigned long current_start, real_start;

    int flags;



    assert(host_start || host_size);



    /* If just a starting address is given, then just verify that

     * address.  */

    if (host_start && !host_size) {

        if (guest_validate_base(host_start)) {

            return host_start;

        } else {

            return (unsigned long)-1;

        }

    }



    /* Setup the initial flags and start address.  */

    current_start = host_start & qemu_host_page_mask;

    flags = MAP_ANONYMOUS | MAP_PRIVATE | MAP_NORESERVE;

    if (fixed) {

        flags |= MAP_FIXED;

    }



    /* Otherwise, a non-zero size region of memory needs to be mapped

     * and validated.  */

    while (1) {

        /* Do not use mmap_find_vma here because that is limited to the

         * guest address space.  We are going to make the

         * guest address space fit whatever we're given.

         */

        real_start = (unsigned long)

            mmap((void *)current_start, host_size, PROT_NONE, flags, -1, 0);

        if (real_start == (unsigned long)-1) {

            return (unsigned long)-1;

        }



        if ((real_start == current_start)

            && guest_validate_base(real_start - guest_start)) {

            break;

        }



        /* That address didn't work.  Unmap and try a different one.

         * The address the host picked because is typically right at

         * the top of the host address space and leaves the guest with

         * no usable address space.  Resort to a linear search.  We

         * already compensated for mmap_min_addr, so this should not

         * happen often.  Probably means we got unlucky and host

         * address space randomization put a shared library somewhere

         * inconvenient.

         */

        munmap((void *)real_start, host_size);

        current_start += qemu_host_page_size;

        if (host_start == current_start) {

            /* Theoretically possible if host doesn't have any suitably

             * aligned areas.  Normally the first mmap will fail.

             */

            return (unsigned long)-1;

        }

    }



    return real_start;

}

unsigned long init_guest_space(unsigned long host_start,

                               unsigned long host_size,

                               unsigned long guest_start,

                               bool fixed)

{

    unsigned long current_start, real_start;

    int flags;



    assert(host_start || host_size);



    



    if (host_start && !host_size) {

        if (guest_validate_base(host_start)) {

            return host_start;

        } else {

            return (unsigned long)-1;

        }

    }



    

    current_start = host_start & qemu_host_page_mask;

    flags = MAP_ANONYMOUS | MAP_PRIVATE | MAP_NORESERVE;

    if (fixed) {

        flags |= MAP_FIXED;

    }



    



    while (1) {

        







        real_start = (unsigned long)

            mmap((void *)current_start, host_size, PROT_NONE, flags, -1, 0);

        if (real_start == (unsigned long)-1) {

            return (unsigned long)-1;

        }



        if ((real_start == current_start)

            && guest_validate_base(real_start - guest_start)) {

            break;

        }



        

















        munmap((void *)real_start, host_size);

        current_start += qemu_host_page_size;

        if (host_start == current_start) {

            





            return (unsigned long)-1;

        }

    }



    return real_start;

}

        if (guest_validate_base(host_start)) {         if ((real_start == current_start)             && guest_validate_base(real_start - guest_start)) {             break;
unsigned long FUNC_0(unsigned long VAR_0,

                               unsigned long VAR_1,

                               unsigned long VAR_2,

                               bool VAR_3)

{

    unsigned long VAR_4, VAR_5;

    int VAR_6;



    assert(VAR_0 || VAR_1);



    



    if (VAR_0 && !VAR_1) {

        if (guest_validate_base(VAR_0)) {

            return VAR_0;

        } else {

            return (unsigned long)-1;

        }

    }



    

    VAR_4 = VAR_0 & qemu_host_page_mask;

    VAR_6 = MAP_ANONYMOUS | MAP_PRIVATE | MAP_NORESERVE;

    if (VAR_3) {

        VAR_6 |= MAP_FIXED;

    }



    



    while (1) {

        







        VAR_5 = (unsigned long)

            mmap((void *)VAR_4, VAR_1, PROT_NONE, VAR_6, -1, 0);

        if (VAR_5 == (unsigned long)-1) {

            return (unsigned long)-1;

        }



        if ((VAR_5 == VAR_4)

            && guest_validate_base(VAR_5 - VAR_2)) {

            break;

        }



        

















        munmap((void *)VAR_5, VAR_1);

        VAR_4 += qemu_host_page_size;

        if (VAR_0 == VAR_4) {

            





            return (unsigned long)-1;

        }

    }



    return VAR_5;

}

unsigned long FUNC_0(unsigned long VAR_0,
unsigned long VAR_1,
unsigned long VAR_2,
bool VAR_3)
{ unsigned long VAR_4, VAR_5; int VAR_6; assert(VAR_0 || VAR_1); if (VAR_0 && !VAR_1) { if (guest_validate_base(VAR_0)) { return VAR_0; } else { return (unsigned long)-1; } } VAR_4 = VAR_0 & qemu_host_page_mask; VAR_6 = MAP_ANONYMOUS | MAP_PRIVATE | MAP_NORESERVE; if (VAR_3) { VAR_6 |= MAP_FIXED; } while (1) { VAR_5 = (unsigned long)
mmap((void *)VAR_4, VAR_1, PROT_NONE, VAR_6, -1, 0); if (VAR_5 == (unsigned long)-1) { return (unsigned long)-1; } if ((VAR_5 == VAR_4)
&& guest_validate_base(VAR_5 - VAR_2)) { break; } munmap((void *)VAR_5, VAR_1); VAR_4 += qemu_host_page_size; if (VAR_0 == VAR_4) { return (unsigned long)-1; } } return VAR_5; }