static void read_guest_mem(void)

{

    uint32_t *guest_mem;

    gint64 end_time;

    int i, j;

    size_t size;



    g_mutex_lock(data_mutex);



    end_time = g_get_monotonic_time() + 5 * G_TIME_SPAN_SECOND;

    while (!fds_num) {

        if (!_cond_wait_until(data_cond, data_mutex, end_time)) {

            /* timeout has passed */

            g_assert(fds_num);

            break;

        }

    }



    /* check for sanity */

    g_assert_cmpint(fds_num, >, 0);

    g_assert_cmpint(fds_num, ==, memory.nregions);



    /* iterate all regions */

    for (i = 0; i < fds_num; i++) {



        /* We'll check only the region statring at 0x0*/

        if (memory.regions[i].guest_phys_addr != 0x0) {

            continue;

        }



        g_assert_cmpint(memory.regions[i].memory_size, >, 1024);



        size =  memory.regions[i].memory_size + memory.regions[i].mmap_offset;



        guest_mem = mmap(0, size, PROT_READ | PROT_WRITE,

                         MAP_SHARED, fds[i], 0);



        g_assert(guest_mem != MAP_FAILED);

        guest_mem += (memory.regions[i].mmap_offset / sizeof(*guest_mem));



        for (j = 0; j < 256; j++) {

            uint32_t a = readl(memory.regions[i].guest_phys_addr + j*4);

            uint32_t b = guest_mem[j];



            g_assert_cmpint(a, ==, b);

        }



        munmap(guest_mem, memory.regions[i].memory_size);

    }



    g_assert_cmpint(1, ==, 1);

    g_mutex_unlock(data_mutex);

}

static void read_guest_mem(void)

{

    uint32_t *guest_mem;

    gint64 end_time;

    int i, j;

    size_t size;



    g_mutex_lock(data_mutex);



    end_time = g_get_monotonic_time() + 5 * G_TIME_SPAN_SECOND;

    while (!fds_num) {

        if (!_cond_wait_until(data_cond, data_mutex, end_time)) {

            

            g_assert(fds_num);

            break;

        }

    }



    

    g_assert_cmpint(fds_num, >, 0);

    g_assert_cmpint(fds_num, ==, memory.nregions);



    

    for (i = 0; i < fds_num; i++) {



        

        if (memory.regions[i].guest_phys_addr != 0x0) {

            continue;

        }



        g_assert_cmpint(memory.regions[i].memory_size, >, 1024);



        size =  memory.regions[i].memory_size + memory.regions[i].mmap_offset;



        guest_mem = mmap(0, size, PROT_READ | PROT_WRITE,

                         MAP_SHARED, fds[i], 0);



        g_assert(guest_mem != MAP_FAILED);

        guest_mem += (memory.regions[i].mmap_offset / sizeof(*guest_mem));



        for (j = 0; j < 256; j++) {

            uint32_t a = readl(memory.regions[i].guest_phys_addr + j*4);

            uint32_t b = guest_mem[j];



            g_assert_cmpint(a, ==, b);

        }



        munmap(guest_mem, memory.regions[i].memory_size);

    }



    g_assert_cmpint(1, ==, 1);

    g_mutex_unlock(data_mutex);

}

static void FUNC_0(void)

{

    uint32_t *guest_mem;

    gint64 end_time;

    int VAR_0, VAR_1;

    size_t size;



    g_mutex_lock(data_mutex);



    end_time = g_get_monotonic_time() + 5 * G_TIME_SPAN_SECOND;

    while (!fds_num) {

        if (!_cond_wait_until(data_cond, data_mutex, end_time)) {

            

            g_assert(fds_num);

            break;

        }

    }



    

    g_assert_cmpint(fds_num, >, 0);

    g_assert_cmpint(fds_num, ==, memory.nregions);



    

    for (VAR_0 = 0; VAR_0 < fds_num; VAR_0++) {



        

        if (memory.regions[VAR_0].guest_phys_addr != 0x0) {

            continue;

        }



        g_assert_cmpint(memory.regions[VAR_0].memory_size, >, 1024);



        size =  memory.regions[VAR_0].memory_size + memory.regions[VAR_0].mmap_offset;



        guest_mem = mmap(0, size, PROT_READ | PROT_WRITE,

                         MAP_SHARED, fds[VAR_0], 0);



        g_assert(guest_mem != MAP_FAILED);

        guest_mem += (memory.regions[VAR_0].mmap_offset / sizeof(*guest_mem));



        for (VAR_1 = 0; VAR_1 < 256; VAR_1++) {

            uint32_t a = readl(memory.regions[VAR_0].guest_phys_addr + VAR_1*4);

            uint32_t b = guest_mem[VAR_1];



            g_assert_cmpint(a, ==, b);

        }



        munmap(guest_mem, memory.regions[VAR_0].memory_size);

    }



    g_assert_cmpint(1, ==, 1);

    g_mutex_unlock(data_mutex);

}

static void FUNC_0(void)
{ uint32_t *guest_mem; gint64 end_time; int VAR_0, VAR_1; size_t size; g_mutex_lock(data_mutex); end_time = g_get_monotonic_time() + 5 * G_TIME_SPAN_SECOND; while (!fds_num) { if (!_cond_wait_until(data_cond, data_mutex, end_time)) { g_assert(fds_num); break; } } g_assert_cmpint(fds_num, >, 0); g_assert_cmpint(fds_num, ==, memory.nregions); for (VAR_0 = 0; VAR_0 < fds_num; VAR_0++) { if (memory.regions[VAR_0].guest_phys_addr != 0x0) { continue; } g_assert_cmpint(memory.regions[VAR_0].memory_size, >, 1024); size =  memory.regions[VAR_0].memory_size + memory.regions[VAR_0].mmap_offset; guest_mem = mmap(0, size, PROT_READ | PROT_WRITE,
MAP_SHARED, fds[VAR_0], 0); g_assert(guest_mem != MAP_FAILED); guest_mem += (memory.regions[VAR_0].mmap_offset / sizeof(*guest_mem)); for (VAR_1 = 0; VAR_1 < 256; VAR_1++) { uint32_t a = readl(memory.regions[VAR_0].guest_phys_addr + VAR_1*4); uint32_t b = guest_mem[VAR_1]; g_assert_cmpint(a, ==, b); } munmap(guest_mem, memory.regions[VAR_0].memory_size); } g_assert_cmpint(1, ==, 1); g_mutex_unlock(data_mutex); }