void os_mem_prealloc(int fd, char *area, size_t memory)

{

    int ret;

    struct sigaction act, oldact;

    sigset_t set, oldset;



    memset(&act, 0, sizeof(act));

    act.sa_handler = &sigbus_handler;

    act.sa_flags = 0;



    ret = sigaction(SIGBUS, &act, &oldact);

    if (ret) {

        perror("os_mem_prealloc: failed to install signal handler");

        exit(1);

    }



    /* unblock SIGBUS */

    sigemptyset(&set);

    sigaddset(&set, SIGBUS);

    pthread_sigmask(SIG_UNBLOCK, &set, &oldset);



    if (sigsetjmp(sigjump, 1)) {

        fprintf(stderr, "os_mem_prealloc: Insufficient free host memory "

                        "pages available to allocate guest RAM\n");

        exit(1);

    } else {

        int i;

        size_t hpagesize = fd_getpagesize(fd);

        size_t numpages = DIV_ROUND_UP(memory, hpagesize);



        /* MAP_POPULATE silently ignores failures */

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

            memset(area + (hpagesize * i), 0, 1);

        }



        ret = sigaction(SIGBUS, &oldact, NULL);

        if (ret) {

            perror("os_mem_prealloc: failed to reinstall signal handler");

            exit(1);

        }



        pthread_sigmask(SIG_SETMASK, &oldset, NULL);

    }

}

void os_mem_prealloc(int fd, char *area, size_t memory)

{

    int ret;

    struct sigaction act, oldact;

    sigset_t set, oldset;



    memset(&act, 0, sizeof(act));

    act.sa_handler = &sigbus_handler;

    act.sa_flags = 0;



    ret = sigaction(SIGBUS, &act, &oldact);

    if (ret) {

        perror("os_mem_prealloc: failed to install signal handler");

        exit(1);

    }



    

    sigemptyset(&set);

    sigaddset(&set, SIGBUS);

    pthread_sigmask(SIG_UNBLOCK, &set, &oldset);



    if (sigsetjmp(sigjump, 1)) {

        fprintf(stderr, "os_mem_prealloc: Insufficient free host memory "

                        "pages available to allocate guest RAM\n");

        exit(1);

    } else {

        int i;

        size_t hpagesize = fd_getpagesize(fd);

        size_t numpages = DIV_ROUND_UP(memory, hpagesize);



        

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

            memset(area + (hpagesize * i), 0, 1);

        }



        ret = sigaction(SIGBUS, &oldact, NULL);

        if (ret) {

            perror("os_mem_prealloc: failed to reinstall signal handler");

            exit(1);

        }



        pthread_sigmask(SIG_SETMASK, &oldset, NULL);

    }

}

void FUNC_0(int VAR_0, char *VAR_1, size_t VAR_2)

{

    int VAR_3;

    struct sigaction VAR_4, VAR_5;

    sigset_t set, oldset;



    memset(&VAR_4, 0, sizeof(VAR_4));

    VAR_4.sa_handler = &sigbus_handler;

    VAR_4.sa_flags = 0;



    VAR_3 = sigaction(SIGBUS, &VAR_4, &VAR_5);

    if (VAR_3) {

        perror("FUNC_0: failed to install signal handler");

        exit(1);

    }



    

    sigemptyset(&set);

    sigaddset(&set, SIGBUS);

    pthread_sigmask(SIG_UNBLOCK, &set, &oldset);



    if (sigsetjmp(sigjump, 1)) {

        fprintf(stderr, "FUNC_0: Insufficient free host VAR_2 "

                        "pages available to allocate guest RAM\n");

        exit(1);

    } else {

        int VAR_6;

        size_t hpagesize = fd_getpagesize(VAR_0);

        size_t numpages = DIV_ROUND_UP(VAR_2, hpagesize);



        

        for (VAR_6 = 0; VAR_6 < numpages; VAR_6++) {

            memset(VAR_1 + (hpagesize * VAR_6), 0, 1);

        }



        VAR_3 = sigaction(SIGBUS, &VAR_5, NULL);

        if (VAR_3) {

            perror("FUNC_0: failed to reinstall signal handler");

            exit(1);

        }



        pthread_sigmask(SIG_SETMASK, &oldset, NULL);

    }

}

void FUNC_0(int VAR_0, char *VAR_1, size_t VAR_2)
{ int VAR_3; struct sigaction VAR_4, VAR_5; sigset_t set, oldset; memset(&VAR_4, 0, sizeof(VAR_4)); VAR_4.sa_handler = &sigbus_handler; VAR_4.sa_flags = 0; VAR_3 = sigaction(SIGBUS, &VAR_4, &VAR_5); if (VAR_3) { perror("FUNC_0: failed to install signal handler"); exit(1); } sigemptyset(&set); sigaddset(&set, SIGBUS); pthread_sigmask(SIG_UNBLOCK, &set, &oldset); if (sigsetjmp(sigjump, 1)) { fprintf(stderr, "FUNC_0: Insufficient free host VAR_2 "
"pages available to allocate guest RAM\n"); exit(1); } else { int VAR_6; size_t hpagesize = fd_getpagesize(VAR_0); size_t numpages = DIV_ROUND_UP(VAR_2, hpagesize); for (VAR_6 = 0; VAR_6 < numpages; VAR_6++) { memset(VAR_1 + (hpagesize * VAR_6), 0, 1); } VAR_3 = sigaction(SIGBUS, &VAR_5, NULL); if (VAR_3) { perror("FUNC_0: failed to reinstall signal handler"); exit(1); } pthread_sigmask(SIG_SETMASK, &oldset, NULL); } }