tests/libqos: embed allocators instead of malloc-ing them separately

qgraph will embed these objects instead of allocating them in a separate
object.  Expose a new API "generic_alloc_init" and "generic_alloc_destroy"
for that, and rename the existing API with s/init/new/ and s/uninit/free/.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
This commit is contained in:
Paolo Bonzini 2018-11-29 12:37:04 +01:00
parent 143e6db6fa
commit eb5937bad6
21 changed files with 124 additions and 212 deletions

View file

@ -20,32 +20,14 @@
#define PAGE_SIZE (4096)
/*
* Mostly for valgrind happiness, but it does offer
* a chokepoint for debugging guest memory leaks, too.
*/
void pc_alloc_uninit(QGuestAllocator *allocator)
void pc_alloc_init(QGuestAllocator *s, QTestState *qts, QAllocOpts flags)
{
alloc_uninit(allocator);
}
QGuestAllocator *pc_alloc_init_flags(QTestState *qts, QAllocOpts flags)
{
QGuestAllocator *s;
uint64_t ram_size;
QFWCFG *fw_cfg = pc_fw_cfg_init(qts);
ram_size = qfw_cfg_get_u64(fw_cfg, FW_CFG_RAM_SIZE);
s = alloc_init_flags(flags, 1 << 20, MIN(ram_size, 0xE0000000));
alloc_set_page_size(s, PAGE_SIZE);
alloc_init(s, flags, 1 << 20, MIN(ram_size, 0xE0000000), PAGE_SIZE);
/* clean-up */
g_free(fw_cfg);
return s;
}
inline QGuestAllocator *pc_alloc_init(QTestState *qts)
{
return pc_alloc_init_flags(qts, ALLOC_NO_FLAGS);
}