static int mmap_frag(abi_ulong real_start,

                     abi_ulong start, abi_ulong end,

                     int prot, int flags, int fd, abi_ulong offset)

{

    abi_ulong real_end, addr;

    void *host_start;

    int prot1, prot_new;



    real_end = real_start + qemu_host_page_size;

    host_start = g2h(real_start);



    /* get the protection of the target pages outside the mapping */

    prot1 = 0;

    for(addr = real_start; addr < real_end; addr++) {

        if (addr < start || addr >= end)

            prot1 |= page_get_flags(addr);

    }



    if (prot1 == 0) {

        /* no page was there, so we allocate one */

        void *p = mmap(host_start, qemu_host_page_size, prot,

                       flags | MAP_ANONYMOUS, -1, 0);

        if (p == MAP_FAILED)

            return -1;

        prot1 = prot;

    }

    prot1 &= PAGE_BITS;



    prot_new = prot | prot1;

    if (!(flags & MAP_ANONYMOUS)) {

        /* msync() won't work here, so we return an error if write is

           possible while it is a shared mapping */

        if ((flags & MAP_TYPE) == MAP_SHARED &&

            (prot & PROT_WRITE))

            return -EINVAL;



        /* adjust protection to be able to read */

        if (!(prot1 & PROT_WRITE))

            mprotect(host_start, qemu_host_page_size, prot1 | PROT_WRITE);



        /* read the corresponding file data */

        if (pread(fd, g2h(start), end - start, offset) == -1)

            return -1;



        /* put final protection */

        if (prot_new != (prot1 | PROT_WRITE))

            mprotect(host_start, qemu_host_page_size, prot_new);

    } else {

        /* just update the protection */

        if (prot_new != prot1) {

            mprotect(host_start, qemu_host_page_size, prot_new);

        }

    }

    return 0;

}

static int mmap_frag(abi_ulong real_start,

                     abi_ulong start, abi_ulong end,

                     int prot, int flags, int fd, abi_ulong offset)

{

    abi_ulong real_end, addr;

    void *host_start;

    int prot1, prot_new;



    real_end = real_start + qemu_host_page_size;

    host_start = g2h(real_start);



    

    prot1 = 0;

    for(addr = real_start; addr < real_end; addr++) {

        if (addr < start || addr >= end)

            prot1 |= page_get_flags(addr);

    }



    if (prot1 == 0) {

        

        void *p = mmap(host_start, qemu_host_page_size, prot,

                       flags | MAP_ANONYMOUS, -1, 0);

        if (p == MAP_FAILED)

            return -1;

        prot1 = prot;

    }

    prot1 &= PAGE_BITS;



    prot_new = prot | prot1;

    if (!(flags & MAP_ANONYMOUS)) {

        



        if ((flags & MAP_TYPE) == MAP_SHARED &&

            (prot & PROT_WRITE))

            return -EINVAL;



        

        if (!(prot1 & PROT_WRITE))

            mprotect(host_start, qemu_host_page_size, prot1 | PROT_WRITE);



        

        if (pread(fd, g2h(start), end - start, offset) == -1)

            return -1;



        

        if (prot_new != (prot1 | PROT_WRITE))

            mprotect(host_start, qemu_host_page_size, prot_new);

    } else {

        

        if (prot_new != prot1) {

            mprotect(host_start, qemu_host_page_size, prot_new);

        }

    }

    return 0;

}

static int FUNC_0(abi_ulong VAR_0,

                     abi_ulong VAR_1, abi_ulong VAR_2,

                     int VAR_3, int VAR_4, int VAR_5, abi_ulong VAR_6)

{

    abi_ulong real_end, addr;

    void *VAR_7;

    int VAR_8, VAR_9;



    real_end = VAR_0 + qemu_host_page_size;

    VAR_7 = g2h(VAR_0);



    

    VAR_8 = 0;

    for(addr = VAR_0; addr < real_end; addr++) {

        if (addr < VAR_1 || addr >= VAR_2)

            VAR_8 |= page_get_flags(addr);

    }



    if (VAR_8 == 0) {

        

        void *VAR_10 = mmap(VAR_7, qemu_host_page_size, VAR_3,

                       VAR_4 | MAP_ANONYMOUS, -1, 0);

        if (VAR_10 == MAP_FAILED)

            return -1;

        VAR_8 = VAR_3;

    }

    VAR_8 &= PAGE_BITS;



    VAR_9 = VAR_3 | VAR_8;

    if (!(VAR_4 & MAP_ANONYMOUS)) {

        



        if ((VAR_4 & MAP_TYPE) == MAP_SHARED &&

            (VAR_3 & PROT_WRITE))

            return -EINVAL;



        

        if (!(VAR_8 & PROT_WRITE))

            mprotect(VAR_7, qemu_host_page_size, VAR_8 | PROT_WRITE);



        

        if (pread(VAR_5, g2h(VAR_1), VAR_2 - VAR_1, VAR_6) == -1)

            return -1;



        

        if (VAR_9 != (VAR_8 | PROT_WRITE))

            mprotect(VAR_7, qemu_host_page_size, VAR_9);

    } else {

        

        if (VAR_9 != VAR_8) {

            mprotect(VAR_7, qemu_host_page_size, VAR_9);

        }

    }

    return 0;

}

static int FUNC_0(abi_ulong VAR_0,
abi_ulong VAR_1, abi_ulong VAR_2,
int VAR_3, int VAR_4, int VAR_5, abi_ulong VAR_6)
{ abi_ulong real_end, addr; void *VAR_7; int VAR_8, VAR_9; real_end = VAR_0 + qemu_host_page_size; VAR_7 = g2h(VAR_0); VAR_8 = 0; for(addr = VAR_0; addr < real_end; addr++) { if (addr < VAR_1 || addr >= VAR_2)
VAR_8 |= page_get_flags(addr); } if (VAR_8 == 0) { void *VAR_10 = mmap(VAR_7, qemu_host_page_size, VAR_3,
VAR_4 | MAP_ANONYMOUS, -1, 0); if (VAR_10 == MAP_FAILED)
return -1; VAR_8 = VAR_3; } VAR_8 &= PAGE_BITS; VAR_9 = VAR_3 | VAR_8; if (!(VAR_4 & MAP_ANONYMOUS)) { if ((VAR_4 & MAP_TYPE) == MAP_SHARED &&
(VAR_3 & PROT_WRITE))
return -EINVAL; if (!(VAR_8 & PROT_WRITE))
mprotect(VAR_7, qemu_host_page_size, VAR_8 | PROT_WRITE); if (pread(VAR_5, g2h(VAR_1), VAR_2 - VAR_1, VAR_6) == -1)
return -1; if (VAR_9 != (VAR_8 | PROT_WRITE))
mprotect(VAR_7, qemu_host_page_size, VAR_9); } else { if (VAR_9 != VAR_8) { mprotect(VAR_7, qemu_host_page_size, VAR_9); } } return 0; }