int vfio_mmap_region(Object *obj, VFIORegion *region,

                     MemoryRegion *mem, MemoryRegion *submem,

                     void **map, size_t size, off_t offset,

                     const char *name)

{

    int ret = 0;

    VFIODevice *vbasedev = region->vbasedev;



    if (vbasedev->allow_mmap && size && region->flags &

        VFIO_REGION_INFO_FLAG_MMAP) {

        int prot = 0;



        if (region->flags & VFIO_REGION_INFO_FLAG_READ) {

            prot |= PROT_READ;

        }



        if (region->flags & VFIO_REGION_INFO_FLAG_WRITE) {

            prot |= PROT_WRITE;

        }



        *map = mmap(NULL, size, prot, MAP_SHARED,

                    vbasedev->fd,

                    region->fd_offset + offset);

        if (*map == MAP_FAILED) {

            *map = NULL;

            ret = -errno;

            goto empty_region;

        }



        memory_region_init_ram_ptr(submem, obj, name, size, *map);

        memory_region_set_skip_dump(submem);

    } else {

empty_region:

        /* Create a zero sized sub-region to make cleanup easy. */

        memory_region_init(submem, obj, name, 0);

    }



    memory_region_add_subregion(mem, offset, submem);



    return ret;

}

int vfio_mmap_region(Object *obj, VFIORegion *region,

                     MemoryRegion *mem, MemoryRegion *submem,

                     void **map, size_t size, off_t offset,

                     const char *name)

{

    int ret = 0;

    VFIODevice *vbasedev = region->vbasedev;



    if (vbasedev->allow_mmap && size && region->flags &

        VFIO_REGION_INFO_FLAG_MMAP) {

        int prot = 0;



        if (region->flags & VFIO_REGION_INFO_FLAG_READ) {

            prot |= PROT_READ;

        }



        if (region->flags & VFIO_REGION_INFO_FLAG_WRITE) {

            prot |= PROT_WRITE;

        }



        *map = mmap(NULL, size, prot, MAP_SHARED,

                    vbasedev->fd,

                    region->fd_offset + offset);

        if (*map == MAP_FAILED) {

            *map = NULL;

            ret = -errno;

            goto empty_region;

        }



        memory_region_init_ram_ptr(submem, obj, name, size, *map);

        memory_region_set_skip_dump(submem);

    } else {

empty_region:

        

        memory_region_init(submem, obj, name, 0);

    }



    memory_region_add_subregion(mem, offset, submem);



    return ret;

}

int FUNC_0(Object *VAR_0, VFIORegion *VAR_1,

                     MemoryRegion *VAR_2, MemoryRegion *VAR_3,

                     void **VAR_4, size_t VAR_5, off_t VAR_6,

                     const char *VAR_7)

{

    int VAR_8 = 0;

    VFIODevice *vbasedev = VAR_1->vbasedev;



    if (vbasedev->allow_mmap && VAR_5 && VAR_1->flags &

        VFIO_REGION_INFO_FLAG_MMAP) {

        int VAR_9 = 0;



        if (VAR_1->flags & VFIO_REGION_INFO_FLAG_READ) {

            VAR_9 |= PROT_READ;

        }



        if (VAR_1->flags & VFIO_REGION_INFO_FLAG_WRITE) {

            VAR_9 |= PROT_WRITE;

        }



        *VAR_4 = mmap(NULL, VAR_5, VAR_9, MAP_SHARED,

                    vbasedev->fd,

                    VAR_1->fd_offset + VAR_6);

        if (*VAR_4 == MAP_FAILED) {

            *VAR_4 = NULL;

            VAR_8 = -errno;

            goto empty_region;

        }



        memory_region_init_ram_ptr(VAR_3, VAR_0, VAR_7, VAR_5, *VAR_4);

        memory_region_set_skip_dump(VAR_3);

    } else {

empty_region:

        

        memory_region_init(VAR_3, VAR_0, VAR_7, 0);

    }



    memory_region_add_subregion(VAR_2, VAR_6, VAR_3);



    return VAR_8;

}

int FUNC_0(Object *VAR_0, VFIORegion *VAR_1,
MemoryRegion *VAR_2, MemoryRegion *VAR_3,
void **VAR_4, size_t VAR_5, off_t VAR_6,
const char *VAR_7)
{ int VAR_8 = 0; VFIODevice *vbasedev = VAR_1->vbasedev; if (vbasedev->allow_mmap && VAR_5 && VAR_1->flags &
VFIO_REGION_INFO_FLAG_MMAP) { int VAR_9 = 0; if (VAR_1->flags & VFIO_REGION_INFO_FLAG_READ) { VAR_9 |= PROT_READ; } if (VAR_1->flags & VFIO_REGION_INFO_FLAG_WRITE) { VAR_9 |= PROT_WRITE; } *VAR_4 = mmap(NULL, VAR_5, VAR_9, MAP_SHARED,
vbasedev->fd,
VAR_1->fd_offset + VAR_6); if (*VAR_4 == MAP_FAILED) { *VAR_4 = NULL; VAR_8 = -errno; goto empty_region; } memory_region_init_ram_ptr(VAR_3, VAR_0, VAR_7, VAR_5, *VAR_4); memory_region_set_skip_dump(VAR_3); } else { empty_region:
memory_region_init(VAR_3, VAR_0, VAR_7, 0); } memory_region_add_subregion(VAR_2, VAR_6, VAR_3); return VAR_8; }