xref: /kvm-unit-tests/lib/alloc.h (revision 7e3e823b78c0d59dbf86ebbbc90b10e063d54b42)
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*f90ddba3SClaudio Imbrenda 	void (*free)(void *ptr);
28417d4762SAndrew Jones };
29417d4762SAndrew Jones 
30417d4762SAndrew Jones extern struct alloc_ops *alloc_ops;
31417d4762SAndrew Jones 
3211c4715fSPaolo Bonzini void *malloc(size_t size);
3311c4715fSPaolo Bonzini void *calloc(size_t nmemb, size_t size);
3411c4715fSPaolo Bonzini void free(void *ptr);
3511c4715fSPaolo Bonzini void *memalign(size_t alignment, size_t size);
36417d4762SAndrew Jones 
37417d4762SAndrew Jones #endif /* _ALLOC_H_ */
38