2 * QEMU Host Memory Backend
4 * Copyright (C) 2013-2014 Red Hat Inc
7 * Igor Mammedov <imammedo@redhat.com>
9 * This work is licensed under the terms of the GNU GPL, version 2 or later.
10 * See the COPYING file in the top-level directory.
13 #include "qemu/osdep.h"
14 #include "sysemu/hostmem.h"
15 #include "qapi/error.h"
16 #include "qemu/module.h"
17 #include "qom/object_interfaces.h"
20 ram_backend_memory_alloc(HostMemoryBackend
*backend
, Error
**errp
)
22 g_autofree
char *name
= NULL
;
26 error_setg(errp
, "can't create backend with size 0");
30 name
= host_memory_backend_get_name(backend
);
31 ram_flags
= backend
->share
? RAM_SHARED
: 0;
32 ram_flags
|= backend
->reserve
? 0 : RAM_NORESERVE
;
33 ram_flags
|= backend
->guest_memfd
? RAM_GUEST_MEMFD
: 0;
34 return memory_region_init_ram_flags_nomigrate(&backend
->mr
, OBJECT(backend
),
40 ram_backend_class_init(ObjectClass
*oc
, void *data
)
42 HostMemoryBackendClass
*bc
= MEMORY_BACKEND_CLASS(oc
);
44 bc
->alloc
= ram_backend_memory_alloc
;
47 static const TypeInfo ram_backend_info
= {
48 .name
= TYPE_MEMORY_BACKEND_RAM
,
49 .parent
= TYPE_MEMORY_BACKEND
,
50 .class_init
= ram_backend_class_init
,
53 static void register_types(void)
55 type_register_static(&ram_backend_info
);
58 type_init(register_types
);