1 | /** @file
|
---|
2 | * innotek Portable Runtime - A Simple Heap.
|
---|
3 | */
|
---|
4 |
|
---|
5 | /*
|
---|
6 | * Copyright (C) 2006-2007 innotek GmbH
|
---|
7 | *
|
---|
8 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
9 | * available from http://www.virtualbox.org. This file is free software;
|
---|
10 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
11 | * General Public License as published by the Free Software Foundation,
|
---|
12 | * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
|
---|
13 | * distribution. VirtualBox OSE is distributed in the hope that it will
|
---|
14 | * be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
15 | */
|
---|
16 |
|
---|
17 | #ifndef ___iprt_heap_h
|
---|
18 | #define ___iprt_heap_h
|
---|
19 |
|
---|
20 | #include <iprt/cdefs.h>
|
---|
21 | #include <iprt/types.h>
|
---|
22 |
|
---|
23 | __BEGIN_DECLS
|
---|
24 |
|
---|
25 | /**
|
---|
26 | * Initializes the heap.
|
---|
27 | *
|
---|
28 | * @returns IPRT status code on success.
|
---|
29 | * @param pHeap Where to store the heap anchor block on success.
|
---|
30 | * @param pvMemory Pointer to the heap memory.
|
---|
31 | * @param cbMemory The size of the heap memory.
|
---|
32 | */
|
---|
33 | RTDECL(int) RTHeapSimpleInit(PRTHEAPSIMPLE pHeap, void *pvMemory, size_t cbMemory);
|
---|
34 |
|
---|
35 | /**
|
---|
36 | * Merge two simple heaps into one.
|
---|
37 | *
|
---|
38 | * The requiremet is of course that they next two each other memory wise.
|
---|
39 | *
|
---|
40 | * @returns IPRT status code on success.
|
---|
41 | * @param pHeap Where to store the handle to the merged heap on success.
|
---|
42 | * @param Heap1 Handle to the first heap.
|
---|
43 | * @param Heap2 Handle to the second heap.
|
---|
44 | * @remark This API isn't implemented yet.
|
---|
45 | */
|
---|
46 | RTDECL(int) RTHeapSimpleMerge(PRTHEAPSIMPLE pHeap, RTHEAPSIMPLE Heap1, RTHEAPSIMPLE Heap2);
|
---|
47 |
|
---|
48 | /**
|
---|
49 | * Allocates memory from the specified simple heap.
|
---|
50 | *
|
---|
51 | * @returns Pointer to the allocated memory block on success.
|
---|
52 | * @returns NULL if the request cannot be satisfied. (A VERR_NO_MEMORY condition.)
|
---|
53 | *
|
---|
54 | * @param Heap The heap to allocate the memory on.
|
---|
55 | * @param cb The requested heap block size.
|
---|
56 | * @param cbAlignment The requested heap block alignment. Pass 0 for default alignment.
|
---|
57 | * Must be a power of 2.
|
---|
58 | */
|
---|
59 | RTDECL(void *) RTHeapSimpleAlloc(RTHEAPSIMPLE Heap, size_t cb, size_t cbAlignment);
|
---|
60 |
|
---|
61 | /**
|
---|
62 | * Allocates zeroed memory from the specified simple heap.
|
---|
63 | *
|
---|
64 | * @returns Pointer to the allocated memory block on success.
|
---|
65 | * @returns NULL if the request cannot be satisfied. (A VERR_NO_MEMORY condition.)
|
---|
66 | *
|
---|
67 | * @param Heap The heap to allocate the memory on.
|
---|
68 | * @param cb The requested heap block size.
|
---|
69 | * @param cbAlignment The requested heap block alignment. Pass 0 for default alignment.
|
---|
70 | * Must be a power of 2.
|
---|
71 | */
|
---|
72 | RTDECL(void *) RTHeapSimpleAllocZ(RTHEAPSIMPLE Heap, size_t cb, size_t cbAlignment);
|
---|
73 |
|
---|
74 | /**
|
---|
75 | * Reallocates / Allocates / Frees a heap block.
|
---|
76 | *
|
---|
77 | * @param Heap The heap. This is optional and will only be used for strict assertions.
|
---|
78 | * @param pv The heap block returned by RTHeapSimple. If NULL it behaves like RTHeapSimpleAlloc().
|
---|
79 | * @param cbNew The new size of the heap block. If NULL it behaves like RTHeapSimpleFree().
|
---|
80 | * @param cbAlignment The requested heap block alignment. Pass 0 for default alignment.
|
---|
81 | * Must be a power of 2.
|
---|
82 | * @remark This API isn't implemented yet.
|
---|
83 | */
|
---|
84 | RTDECL(void *) RTHeapSimpleRealloc(RTHEAPSIMPLE Heap, void *pv, size_t cbNew, size_t cbAlignment);
|
---|
85 |
|
---|
86 | /**
|
---|
87 | * Reallocates / Allocates / Frees a heap block, zeroing any new bits.
|
---|
88 | *
|
---|
89 | * @param Heap The heap. This is optional and will only be used for strict assertions.
|
---|
90 | * @param pv The heap block returned by RTHeapSimple. If NULL it behaves like RTHeapSimpleAllocZ().
|
---|
91 | * @param cbNew The new size of the heap block. If NULL it behaves like RTHeapSimpleFree().
|
---|
92 | * @param cbAlignment The requested heap block alignment. Pass 0 for default alignment.
|
---|
93 | * Must be a power of 2.
|
---|
94 | * @remark This API isn't implemented yet.
|
---|
95 | */
|
---|
96 | RTDECL(void *) RTHeapSimpleReallocZ(RTHEAPSIMPLE Heap, void *pv, size_t cbNew, size_t cbAlignment);
|
---|
97 |
|
---|
98 | /**
|
---|
99 | * Frees memory allocated from a simple heap.
|
---|
100 | *
|
---|
101 | * @param Heap The heap. This is optional and will only be used for strict assertions.
|
---|
102 | * @param pv The heap block returned by RTHeapSimple
|
---|
103 | */
|
---|
104 | RTDECL(void) RTHeapSimpleFree(RTHEAPSIMPLE Heap, void *pv);
|
---|
105 |
|
---|
106 | /**
|
---|
107 | * Gets the size of the specified heap block.
|
---|
108 | *
|
---|
109 | * @returns The actual size of the heap block.
|
---|
110 | * @returns 0 if \a pv is NULL or it doesn't point to a valid heap block. An invalid \a pv
|
---|
111 | * can also cause traps or trigger assertions.
|
---|
112 | * @param Heap The heap. This is optional and will only be used for strict assertions.
|
---|
113 | * @param pv The heap block returned by RTHeapSimple
|
---|
114 | */
|
---|
115 | RTDECL(size_t) RTHeapSimpleSize(RTHEAPSIMPLE Heap, void *pv);
|
---|
116 |
|
---|
117 | /**
|
---|
118 | * Gets the size of the heap.
|
---|
119 | *
|
---|
120 | * This size includes all the internal heap structures. So, even if the heap is
|
---|
121 | * empty the RTHeapSimpleGetFreeSize() will never reach the heap size returned
|
---|
122 | * by this function.
|
---|
123 | *
|
---|
124 | * @returns The heap size.
|
---|
125 | * @returns 0 if heap was safely detected as being bad.
|
---|
126 | * @param Heap The heap.
|
---|
127 | */
|
---|
128 | RTDECL(size_t) RTHeapSimpleGetHeapSize(RTHEAPSIMPLE Heap);
|
---|
129 |
|
---|
130 | /**
|
---|
131 | * Returns the sum of all free heap blocks.
|
---|
132 | *
|
---|
133 | * This is the amount of memory you can theoretically allocate
|
---|
134 | * if you do allocations exactly matching the free blocks.
|
---|
135 | *
|
---|
136 | * @returns The size of the free blocks.
|
---|
137 | * @returns 0 if heap was safely detected as being bad.
|
---|
138 | * @param Heap The heap.
|
---|
139 | */
|
---|
140 | RTDECL(size_t) RTHeapSimpleGetFreeSize(RTHEAPSIMPLE Heap);
|
---|
141 |
|
---|
142 | /**
|
---|
143 | * Printf like callbaclk function for RTHeapSimpleDump.
|
---|
144 | * @param pszFormat IPRT format string.
|
---|
145 | * @param ... Format arguments.
|
---|
146 | */
|
---|
147 | typedef DECLCALLBACK(void) FNRTHEAPSIMPLEPRINTF(const char *pszFormat, ...);
|
---|
148 | /** Pointer to a FNRTHEAPSIMPLEPRINTF function. */
|
---|
149 | typedef FNRTHEAPSIMPLEPRINTF *PFNRTHEAPSIMPLEPRINTF;
|
---|
150 |
|
---|
151 | /**
|
---|
152 | * Dumps the hypervisor heap.
|
---|
153 | *
|
---|
154 | * @param Heap The heap handle.
|
---|
155 | * @param pfnPrintf Printf like function that groks IPRT formatting.
|
---|
156 | */
|
---|
157 | RTDECL(void) RTHeapSimpleDump(RTHEAPSIMPLE Heap, PFNRTHEAPSIMPLEPRINTF pfnPrintf);
|
---|
158 |
|
---|
159 | __END_DECLS
|
---|
160 |
|
---|
161 | #endif
|
---|
162 |
|
---|