xref: /qemu/tests/qtest/libqos/libqos-malloc.h (revision b243c73c)
1b243c73cSXuzhou Cheng /*
2b243c73cSXuzhou Cheng  * libqos malloc support
3b243c73cSXuzhou Cheng  *
4b243c73cSXuzhou Cheng  * Copyright IBM, Corp. 2012-2013
5b243c73cSXuzhou Cheng  *
6b243c73cSXuzhou Cheng  * Authors:
7b243c73cSXuzhou Cheng  *  Anthony Liguori   <aliguori@us.ibm.com>
8b243c73cSXuzhou Cheng  *
9b243c73cSXuzhou Cheng  * This work is licensed under the terms of the GNU GPL, version 2 or later.
10b243c73cSXuzhou Cheng  * See the COPYING file in the top-level directory.
11b243c73cSXuzhou Cheng  */
12b243c73cSXuzhou Cheng 
13b243c73cSXuzhou Cheng #ifndef LIBQOS_MALLOC_H
14b243c73cSXuzhou Cheng #define LIBQOS_MALLOC_H
15b243c73cSXuzhou Cheng 
16b243c73cSXuzhou Cheng #include "qemu/queue.h"
17b243c73cSXuzhou Cheng #include "../libqtest.h"
18b243c73cSXuzhou Cheng 
19b243c73cSXuzhou Cheng typedef enum {
20b243c73cSXuzhou Cheng     ALLOC_NO_FLAGS    = 0x00,
21b243c73cSXuzhou Cheng     ALLOC_LEAK_WARN   = 0x01,
22b243c73cSXuzhou Cheng     ALLOC_LEAK_ASSERT = 0x02,
23b243c73cSXuzhou Cheng     ALLOC_PARANOID    = 0x04
24b243c73cSXuzhou Cheng } QAllocOpts;
25b243c73cSXuzhou Cheng 
26b243c73cSXuzhou Cheng typedef QTAILQ_HEAD(MemList, MemBlock) MemList;
27b243c73cSXuzhou Cheng 
28b243c73cSXuzhou Cheng typedef struct QGuestAllocator {
29b243c73cSXuzhou Cheng     QAllocOpts opts;
30b243c73cSXuzhou Cheng     uint64_t start;
31b243c73cSXuzhou Cheng     uint64_t end;
32b243c73cSXuzhou Cheng     uint32_t page_size;
33b243c73cSXuzhou Cheng 
34b243c73cSXuzhou Cheng     MemList *used;
35b243c73cSXuzhou Cheng     MemList *free;
36b243c73cSXuzhou Cheng } QGuestAllocator;
37b243c73cSXuzhou Cheng 
38b243c73cSXuzhou Cheng /* Always returns page aligned values */
39b243c73cSXuzhou Cheng uint64_t guest_alloc(QGuestAllocator *allocator, size_t size);
40b243c73cSXuzhou Cheng void guest_free(QGuestAllocator *allocator, uint64_t addr);
41b243c73cSXuzhou Cheng void migrate_allocator(QGuestAllocator *src, QGuestAllocator *dst);
42b243c73cSXuzhou Cheng 
43b243c73cSXuzhou Cheng void alloc_set_flags(QGuestAllocator *allocator, QAllocOpts opts);
44b243c73cSXuzhou Cheng 
45b243c73cSXuzhou Cheng void alloc_init(QGuestAllocator *alloc, QAllocOpts flags,
46b243c73cSXuzhou Cheng                 uint64_t start, uint64_t end,
47b243c73cSXuzhou Cheng                 size_t page_size);
48b243c73cSXuzhou Cheng void alloc_destroy(QGuestAllocator *allocator);
49b243c73cSXuzhou Cheng 
50b243c73cSXuzhou Cheng #endif
51