int page_unprotect(target_ulong address, unsigned long pc, void *puc)

{

    unsigned int page_index, prot, pindex;

    PageDesc *p, *p1;

    target_ulong host_start, host_end, addr;



    /* Technically this isn't safe inside a signal handler.  However we

       know this only ever happens in a synchronous SEGV handler, so in

       practice it seems to be ok.  */

    mmap_lock();



    host_start = address & qemu_host_page_mask;

    page_index = host_start >> TARGET_PAGE_BITS;

    p1 = page_find(page_index);

    if (!p1) {

        mmap_unlock();

        return 0;

    }

    host_end = host_start + qemu_host_page_size;

    p = p1;

    prot = 0;

    for(addr = host_start;addr < host_end; addr += TARGET_PAGE_SIZE) {

        prot |= p->flags;

        p++;

    }

    /* if the page was really writable, then we change its

       protection back to writable */

    if (prot & PAGE_WRITE_ORG) {

        pindex = (address - host_start) >> TARGET_PAGE_BITS;

        if (!(p1[pindex].flags & PAGE_WRITE)) {

            mprotect((void *)g2h(host_start), qemu_host_page_size,

                     (prot & PAGE_BITS) | PAGE_WRITE);

            p1[pindex].flags |= PAGE_WRITE;

            /* and since the content will be modified, we must invalidate

               the corresponding translated code. */

            tb_invalidate_phys_page(address, pc, puc);

#ifdef DEBUG_TB_CHECK

            tb_invalidate_check(address);

#endif

            mmap_unlock();

            return 1;

        }

    }

    mmap_unlock();

    return 0;

}

int page_unprotect(target_ulong address, unsigned long pc, void *puc)

{

    unsigned int page_index, prot, pindex;

    PageDesc *p, *p1;

    target_ulong host_start, host_end, addr;



    





    mmap_lock();



    host_start = address & qemu_host_page_mask;

    page_index = host_start >> TARGET_PAGE_BITS;

    p1 = page_find(page_index);

    if (!p1) {

        mmap_unlock();

        return 0;

    }

    host_end = host_start + qemu_host_page_size;

    p = p1;

    prot = 0;

    for(addr = host_start;addr < host_end; addr += TARGET_PAGE_SIZE) {

        prot |= p->flags;

        p++;

    }

    



    if (prot & PAGE_WRITE_ORG) {

        pindex = (address - host_start) >> TARGET_PAGE_BITS;

        if (!(p1[pindex].flags & PAGE_WRITE)) {

            mprotect((void *)g2h(host_start), qemu_host_page_size,

                     (prot & PAGE_BITS) | PAGE_WRITE);

            p1[pindex].flags |= PAGE_WRITE;

            



            tb_invalidate_phys_page(address, pc, puc);

#ifdef DEBUG_TB_CHECK

            tb_invalidate_check(address);

#endif

            mmap_unlock();

            return 1;

        }

    }

    mmap_unlock();

    return 0;

}

int FUNC_0(target_ulong VAR_0, unsigned long VAR_1, void *VAR_2)

{

    unsigned int VAR_3, VAR_4, VAR_5;

    PageDesc *p, *p1;

    target_ulong host_start, host_end, addr;



    





    mmap_lock();



    host_start = VAR_0 & qemu_host_page_mask;

    VAR_3 = host_start >> TARGET_PAGE_BITS;

    p1 = page_find(VAR_3);

    if (!p1) {

        mmap_unlock();

        return 0;

    }

    host_end = host_start + qemu_host_page_size;

    p = p1;

    VAR_4 = 0;

    for(addr = host_start;addr < host_end; addr += TARGET_PAGE_SIZE) {

        VAR_4 |= p->flags;

        p++;

    }

    



    if (VAR_4 & PAGE_WRITE_ORG) {

        VAR_5 = (VAR_0 - host_start) >> TARGET_PAGE_BITS;

        if (!(p1[VAR_5].flags & PAGE_WRITE)) {

            mprotect((void *)g2h(host_start), qemu_host_page_size,

                     (VAR_4 & PAGE_BITS) | PAGE_WRITE);

            p1[VAR_5].flags |= PAGE_WRITE;

            



            tb_invalidate_phys_page(VAR_0, VAR_1, VAR_2);

#ifdef DEBUG_TB_CHECK

            tb_invalidate_check(VAR_0);

#endif

            mmap_unlock();

            return 1;

        }

    }

    mmap_unlock();

    return 0;

}

int FUNC_0(target_ulong VAR_0, unsigned long VAR_1, void *VAR_2)
{ unsigned int VAR_3, VAR_4, VAR_5; PageDesc *p, *p1; target_ulong host_start, host_end, addr; mmap_lock(); host_start = VAR_0 & qemu_host_page_mask; VAR_3 = host_start >> TARGET_PAGE_BITS; p1 = page_find(VAR_3); if (!p1) { mmap_unlock(); return 0; } host_end = host_start + qemu_host_page_size; p = p1; VAR_4 = 0; for(addr = host_start;addr < host_end; addr += TARGET_PAGE_SIZE) { VAR_4 |= p->flags; p++; } if (VAR_4 & PAGE_WRITE_ORG) { VAR_5 = (VAR_0 - host_start) >> TARGET_PAGE_BITS; if (!(p1[VAR_5].flags & PAGE_WRITE)) { mprotect((void *)g2h(host_start), qemu_host_page_size,
(VAR_4 & PAGE_BITS) | PAGE_WRITE); p1[VAR_5].flags |= PAGE_WRITE; tb_invalidate_phys_page(VAR_0, VAR_1, VAR_2); #ifdef DEBUG_TB_CHECK
tb_invalidate_check(VAR_0); #endif
mmap_unlock(); return 1; } } mmap_unlock(); return 0; }