static void *file_ram_alloc(RAMBlock *block,

                            ram_addr_t memory,

                            const char *path,

                            Error **errp)

{

    char *filename;

    char *sanitized_name;

    char *c;

    void *area;

    int fd;

    uint64_t hpagesize;

    Error *local_err = NULL;



    hpagesize = gethugepagesize(path, &local_err);

    if (local_err) {

        error_propagate(errp, local_err);

        goto error;

    }

    block->mr->align = hpagesize;



    if (memory < hpagesize) {

        error_setg(errp, "memory size 0x" RAM_ADDR_FMT " must be equal to "

                   "or larger than huge page size 0x%" PRIx64,

                   memory, hpagesize);

        goto error;

    }



    if (kvm_enabled() && !kvm_has_sync_mmu()) {

        error_setg(errp,

                   "host lacks kvm mmu notifiers, -mem-path unsupported");

        goto error;

    }



    /* Make name safe to use with mkstemp by replacing '/' with '_'. */

    sanitized_name = g_strdup(memory_region_name(block->mr));

    for (c = sanitized_name; *c != '\0'; c++) {

        if (*c == '/')

            *c = '_';

    }



    filename = g_strdup_printf("%s/qemu_back_mem.%s.XXXXXX", path,

                               sanitized_name);

    g_free(sanitized_name);



    fd = mkstemp(filename);

    if (fd < 0) {

        error_setg_errno(errp, errno,

                         "unable to create backing store for hugepages");

        g_free(filename);

        goto error;

    }

    unlink(filename);

    g_free(filename);



    memory = ROUND_UP(memory, hpagesize);



    /*

     * ftruncate is not supported by hugetlbfs in older

     * hosts, so don't bother bailing out on errors.

     * If anything goes wrong with it under other filesystems,

     * mmap will fail.

     */

    if (ftruncate(fd, memory)) {

        perror("ftruncate");

    }



    area = qemu_ram_mmap(fd, memory, hpagesize, block->flags & RAM_SHARED);

    if (area == MAP_FAILED) {

        error_setg_errno(errp, errno,

                         "unable to map backing store for hugepages");

        close(fd);

        goto error;

    }



    if (mem_prealloc) {

        os_mem_prealloc(fd, area, memory);

    }



    block->fd = fd;

    return area;



error:

    return NULL;

}

static void *file_ram_alloc(RAMBlock *block,

                            ram_addr_t memory,

                            const char *path,

                            Error **errp)

{

    char *filename;

    char *sanitized_name;

    char *c;

    void *area;

    int fd;

    uint64_t hpagesize;

    Error *local_err = NULL;



    hpagesize = gethugepagesize(path, &local_err);

    if (local_err) {

        error_propagate(errp, local_err);

        goto error;

    }

    block->mr->align = hpagesize;



    if (memory < hpagesize) {

        error_setg(errp, "memory size 0x" RAM_ADDR_FMT " must be equal to "

                   "or larger than huge page size 0x%" PRIx64,

                   memory, hpagesize);

        goto error;

    }



    if (kvm_enabled() && !kvm_has_sync_mmu()) {

        error_setg(errp,

                   "host lacks kvm mmu notifiers, -mem-path unsupported");

        goto error;

    }



    

    sanitized_name = g_strdup(memory_region_name(block->mr));

    for (c = sanitized_name; *c != '\0'; c++) {

        if (*c == '/')

            *c = '_';

    }



    filename = g_strdup_printf("%s/qemu_back_mem.%s.XXXXXX", path,

                               sanitized_name);

    g_free(sanitized_name);



    fd = mkstemp(filename);

    if (fd < 0) {

        error_setg_errno(errp, errno,

                         "unable to create backing store for hugepages");

        g_free(filename);

        goto error;

    }

    unlink(filename);

    g_free(filename);



    memory = ROUND_UP(memory, hpagesize);



    











    if (ftruncate(fd, memory)) {

        perror("ftruncate");

    }



    area = qemu_ram_mmap(fd, memory, hpagesize, block->flags & RAM_SHARED);

    if (area == MAP_FAILED) {

        error_setg_errno(errp, errno,

                         "unable to map backing store for hugepages");

        close(fd);

        goto error;

    }



    if (mem_prealloc) {

        os_mem_prealloc(fd, area, memory);

    }



    block->fd = fd;

    return area;



error:

    return NULL;

}

static void *FUNC_0(RAMBlock *VAR_0,

                            ram_addr_t VAR_1,

                            const char *VAR_2,

                            Error **VAR_3)

{

    char *VAR_4;

    char *VAR_5;

    char *VAR_6;

    void *VAR_7;

    int VAR_8;

    uint64_t hpagesize;

    Error *local_err = NULL;



    hpagesize = gethugepagesize(VAR_2, &local_err);

    if (local_err) {

        error_propagate(VAR_3, local_err);

        goto error;

    }

    VAR_0->mr->align = hpagesize;



    if (VAR_1 < hpagesize) {

        error_setg(VAR_3, "VAR_1 size 0x" RAM_ADDR_FMT " must be equal to "

                   "or larger than huge page size 0x%" PRIx64,

                   VAR_1, hpagesize);

        goto error;

    }



    if (kvm_enabled() && !kvm_has_sync_mmu()) {

        error_setg(VAR_3,

                   "host lacks kvm mmu notifiers, -mem-VAR_2 unsupported");

        goto error;

    }



    

    VAR_5 = g_strdup(memory_region_name(VAR_0->mr));

    for (VAR_6 = VAR_5; *VAR_6 != '\0'; VAR_6++) {

        if (*VAR_6 == '/')

            *VAR_6 = '_';

    }



    VAR_4 = g_strdup_printf("%s/qemu_back_mem.%s.XXXXXX", VAR_2,

                               VAR_5);

    g_free(VAR_5);



    VAR_8 = mkstemp(VAR_4);

    if (VAR_8 < 0) {

        error_setg_errno(VAR_3, errno,

                         "unable to create backing store for hugepages");

        g_free(VAR_4);

        goto error;

    }

    unlink(VAR_4);

    g_free(VAR_4);



    VAR_1 = ROUND_UP(VAR_1, hpagesize);



    











    if (ftruncate(VAR_8, VAR_1)) {

        perror("ftruncate");

    }



    VAR_7 = qemu_ram_mmap(VAR_8, VAR_1, hpagesize, VAR_0->flags & RAM_SHARED);

    if (VAR_7 == MAP_FAILED) {

        error_setg_errno(VAR_3, errno,

                         "unable to map backing store for hugepages");

        close(VAR_8);

        goto error;

    }



    if (mem_prealloc) {

        os_mem_prealloc(VAR_8, VAR_7, VAR_1);

    }



    VAR_0->VAR_8 = VAR_8;

    return VAR_7;



error:

    return NULL;

}

static void *FUNC_0(RAMBlock *VAR_0,
ram_addr_t VAR_1,
const char *VAR_2,
Error **VAR_3)
{ char *VAR_4; char *VAR_5; char *VAR_6; void *VAR_7; int VAR_8; uint64_t hpagesize; Error *local_err = NULL; hpagesize = gethugepagesize(VAR_2, &local_err); if (local_err) { error_propagate(VAR_3, local_err); goto error; } VAR_0->mr->align = hpagesize; if (VAR_1 < hpagesize) { error_setg(VAR_3, "VAR_1 size 0x" RAM_ADDR_FMT " must be equal to "
"or larger than huge page size 0x%" PRIx64,
VAR_1, hpagesize); goto error; } if (kvm_enabled() && !kvm_has_sync_mmu()) { error_setg(VAR_3,
"host lacks kvm mmu notifiers, -mem-VAR_2 unsupported"); goto error; } VAR_5 = g_strdup(memory_region_name(VAR_0->mr)); for (VAR_6 = VAR_5; *VAR_6 != '\0'; VAR_6++) { if (*VAR_6 == '/')
*VAR_6 = '_'; } VAR_4 = g_strdup_printf("%s/qemu_back_mem.%s.XXXXXX", VAR_2,
VAR_5); g_free(VAR_5); VAR_8 = mkstemp(VAR_4); if (VAR_8 < 0) { error_setg_errno(VAR_3, errno,
"unable to create backing store for hugepages"); g_free(VAR_4); goto error; } unlink(VAR_4); g_free(VAR_4); VAR_1 = ROUND_UP(VAR_1, hpagesize); if (ftruncate(VAR_8, VAR_1)) { perror("ftruncate"); } VAR_7 = qemu_ram_mmap(VAR_8, VAR_1, hpagesize, VAR_0->flags & RAM_SHARED); if (VAR_7 == MAP_FAILED) { error_setg_errno(VAR_3, errno,
"unable to map backing store for hugepages"); close(VAR_8); goto error; } if (mem_prealloc) { os_mem_prealloc(VAR_8, VAR_7, VAR_1); } VAR_0->VAR_8 = VAR_8; return VAR_7; error:
return NULL; }