xref: /kvm-unit-tests/lib/alloc.h (revision 11c4715fbf87ba97eedcd5578785dcf51c5d7f1e)
1417d4762SAndrew Jones #ifndef _ALLOC_H_
2417d4762SAndrew Jones #define _ALLOC_H_
3417d4762SAndrew Jones /*
4417d4762SAndrew Jones  * alloc supplies three ingredients to the test framework that are all
5417d4762SAndrew Jones  * related to the support of dynamic memory allocation.
6417d4762SAndrew Jones  *
7417d4762SAndrew Jones  * The first is a set of alloc function wrappers for malloc and its
8417d4762SAndrew Jones  * friends. Using wrappers allows test code and common code to use the
9417d4762SAndrew Jones  * same interface for memory allocation at all stages, even though the
10417d4762SAndrew Jones  * implementations may change with the stage, e.g. pre/post paging.
11417d4762SAndrew Jones  *
12417d4762SAndrew Jones  * The second is a set of implementations for the alloc function
13417d4762SAndrew Jones  * interfaces. These implementations are named early_*, as they can be
14417d4762SAndrew Jones  * used almost immediately by the test framework.
15417d4762SAndrew Jones  *
16417d4762SAndrew Jones  * The third is a very simple physical memory allocator, which the
17417d4762SAndrew Jones  * early_* alloc functions build on.
18417d4762SAndrew Jones  *
19417d4762SAndrew Jones  * Copyright (C) 2014, Red Hat Inc, Andrew Jones <drjones@redhat.com>
20417d4762SAndrew Jones  *
21417d4762SAndrew Jones  * This work is licensed under the terms of the GNU LGPL, version 2.
22417d4762SAndrew Jones  */
23417d4762SAndrew Jones #include "libcflat.h"
24417d4762SAndrew Jones 
25417d4762SAndrew Jones struct alloc_ops {
26417d4762SAndrew Jones 	void *(*memalign)(size_t alignment, size_t size);
27*11c4715fSPaolo Bonzini 	void (*free)(void *ptr, size_t size);
28*11c4715fSPaolo Bonzini 	size_t align_min;
29417d4762SAndrew Jones };
30417d4762SAndrew Jones 
31417d4762SAndrew Jones extern struct alloc_ops *alloc_ops;
32417d4762SAndrew Jones 
33*11c4715fSPaolo Bonzini void *malloc(size_t size);
34*11c4715fSPaolo Bonzini void *calloc(size_t nmemb, size_t size);
35*11c4715fSPaolo Bonzini void free(void *ptr);
36*11c4715fSPaolo Bonzini void *memalign(size_t alignment, size_t size);
37417d4762SAndrew Jones 
38*11c4715fSPaolo Bonzini extern struct alloc_ops *alloc_ops;
39417d4762SAndrew Jones 
40417d4762SAndrew Jones #endif /* _ALLOC_H_ */
41