xref: /kvm-unit-tests/lib/alloc.h (revision f90ddba307c570bbc518d4024478dbf56ea7e645)
1 #ifndef _ALLOC_H_
2 #define _ALLOC_H_
3 /*
4  * alloc supplies three ingredients to the test framework that are all
5  * related to the support of dynamic memory allocation.
6  *
7  * The first is a set of alloc function wrappers for malloc and its
8  * friends. Using wrappers allows test code and common code to use the
9  * same interface for memory allocation at all stages, even though the
10  * implementations may change with the stage, e.g. pre/post paging.
11  *
12  * The second is a set of implementations for the alloc function
13  * interfaces. These implementations are named early_*, as they can be
14  * used almost immediately by the test framework.
15  *
16  * The third is a very simple physical memory allocator, which the
17  * early_* alloc functions build on.
18  *
19  * Copyright (C) 2014, Red Hat Inc, Andrew Jones <drjones@redhat.com>
20  *
21  * This work is licensed under the terms of the GNU LGPL, version 2.
22  */
23 #include "libcflat.h"
24 
25 struct alloc_ops {
26 	void *(*memalign)(size_t alignment, size_t size);
27 	void (*free)(void *ptr);
28 	size_t align_min;
29 };
30 
31 extern struct alloc_ops *alloc_ops;
32 
33 void *malloc(size_t size);
34 void *calloc(size_t nmemb, size_t size);
35 void free(void *ptr);
36 void *memalign(size_t alignment, size_t size);
37 
38 #endif /* _ALLOC_H_ */
39