xref: /qemu/tests/qtest/libqos/libqos-malloc.h (revision b243c73cf4dc7017e28577c4056df0655427a76e)
18a0743cfSAnthony Liguori /*
28a0743cfSAnthony Liguori  * libqos malloc support
38a0743cfSAnthony Liguori  *
48a0743cfSAnthony Liguori  * Copyright IBM, Corp. 2012-2013
58a0743cfSAnthony Liguori  *
68a0743cfSAnthony Liguori  * Authors:
78a0743cfSAnthony Liguori  *  Anthony Liguori   <aliguori@us.ibm.com>
88a0743cfSAnthony Liguori  *
98a0743cfSAnthony Liguori  * This work is licensed under the terms of the GNU GPL, version 2 or later.
108a0743cfSAnthony Liguori  * See the COPYING file in the top-level directory.
118a0743cfSAnthony Liguori  */
128a0743cfSAnthony Liguori 
138a0743cfSAnthony Liguori #ifndef LIBQOS_MALLOC_H
148a0743cfSAnthony Liguori #define LIBQOS_MALLOC_H
158a0743cfSAnthony Liguori 
16292be092SMarc Marí #include "qemu/queue.h"
17*907b5105SMarc-André Lureau #include "../libqtest.h"
188a0743cfSAnthony Liguori 
19292be092SMarc Marí typedef enum {
20292be092SMarc Marí     ALLOC_NO_FLAGS    = 0x00,
21292be092SMarc Marí     ALLOC_LEAK_WARN   = 0x01,
22292be092SMarc Marí     ALLOC_LEAK_ASSERT = 0x02,
23292be092SMarc Marí     ALLOC_PARANOID    = 0x04
24292be092SMarc Marí } QAllocOpts;
25292be092SMarc Marí 
26eb5937baSPaolo Bonzini typedef QTAILQ_HEAD(MemList, MemBlock) MemList;
27292be092SMarc Marí 
28eb5937baSPaolo Bonzini typedef struct QGuestAllocator {
29eb5937baSPaolo Bonzini     QAllocOpts opts;
30eb5937baSPaolo Bonzini     uint64_t start;
31eb5937baSPaolo Bonzini     uint64_t end;
32eb5937baSPaolo Bonzini     uint32_t page_size;
33eb5937baSPaolo Bonzini 
34eb5937baSPaolo Bonzini     MemList *used;
35eb5937baSPaolo Bonzini     MemList *free;
36eb5937baSPaolo Bonzini } QGuestAllocator;
378a0743cfSAnthony Liguori 
388a0743cfSAnthony Liguori /* Always returns page aligned values */
39292be092SMarc Marí uint64_t guest_alloc(QGuestAllocator *allocator, size_t size);
40292be092SMarc Marí void guest_free(QGuestAllocator *allocator, uint64_t addr);
41085248aeSJohn Snow void migrate_allocator(QGuestAllocator *src, QGuestAllocator *dst);
428a0743cfSAnthony Liguori 
43259342d3SJohn Snow void alloc_set_flags(QGuestAllocator *allocator, QAllocOpts opts);
44f6f363c1SJohn Snow 
45eb5937baSPaolo Bonzini void alloc_init(QGuestAllocator *alloc, QAllocOpts flags,
46eb5937baSPaolo Bonzini                 uint64_t start, uint64_t end,
47eb5937baSPaolo Bonzini                 size_t page_size);
48eb5937baSPaolo Bonzini void alloc_destroy(QGuestAllocator *allocator);
49eb5937baSPaolo Bonzini 
508a0743cfSAnthony Liguori #endif
51