Files @ d0a14f973771
Branch filter:

Location: vmkdrivers/BLD/build/HEADERS/vmkapi-current-all-public/vmkernel64/release/base/vmkapi_heap.h

unknown
ESXi-5.0-U1
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
/* **********************************************************
 * Copyright 1998 - 2010 VMware, Inc.  All rights reserved.
 * **********************************************************/

/*
 * @VMKAPIMOD_LICENSE@
 */

/*
 ***********************************************************************
 * Heap                                                           */ /**
 * \addtogroup Core
 * @{
 * \defgroup Heap Heaps
 *
 * vmkernel has local heaps to help isolate VMKernel subsystems from
 * one another. Benefits include:
 * \li Makes it easier to track per-subssystem memory consumption,
 *     enforce a cap on  how much memory a given subsystem can allocate,
 *     locate the origin of memory leaks, ...
 * \li Confines most memory corruptions to the guilty subsystem.
 *
 * @{
 ***********************************************************************
 */

#ifndef _VMKAPI_HEAP_H_
#define _VMKAPI_HEAP_H_

/** \cond never */
#ifndef VMK_HEADER_INCLUDED_FROM_VMKAPI_H
#error This vmkapi file should never be included directly but only via vmkapi.h
#endif
/** \endcond never */

#define VMK_INVALID_HEAP_ID NULL

typedef struct Heap* vmk_HeapID;

/**
 * \brief Types of heaps.
 */
typedef enum {
   /** 
    * \brief Heaps that get their own memory pool.
    *
    * Heaps of type VMK_HEAP_TYPE_SIMPLE get memory of type
    * VMK_MEM_PHYS_ANY_CONTIGUITY and VMK_PHYS_ADDR_ANY, which are suitable
    * for purely software heaps, and may be suitable for some heaps that
    * need to be addressable by hardware.  A new memory pool will be 
    * constructed for this heap.  VMK_HEAP_TYPE_CUSTOM or VMK_HEAP_TYPE_MEMPOOL
    * must be used in order to specify different contiguity or physical
    * constraints, or to use an existing memory pool.
    */
   VMK_HEAP_TYPE_SIMPLE = 0,

   /** \brief Heaps that can customize additional parameters. */
   VMK_HEAP_TYPE_CUSTOM = 1,

   /** \brief Heaps whose memory comes from a specified memPool. */
   VMK_HEAP_TYPE_MEMPOOL = 2,
} vmk_HeapType;


/**
 * \brief Properties for creating a heap allocator.
 */
typedef struct vmk_HeapCreateProps {
   /** \brief Type of heap. */
   vmk_HeapType type;

   /** \brief Name associated with this heap. */
   vmk_Name name;

   /** \brief Module ID of the module creating this heap. */
   vmk_ModuleID module;

   /** \brief Initial size of the heap in bytes. */
   vmk_ByteCountSmall initial;

   /** \brief Maximum size of the heap in bytes. */
   vmk_ByteCountSmall max;

   /** \brief How long to wait for memory during heap creation. */
   vmk_uint32 creationTimeoutMS;
   
   /** \brief Type-specific heap properties. */
   union {
      /** \brief Properties for VMK_HEAP_TYPE_CUSTOM. */
      struct {
         /** \brief Physical contiguity allocated from this heap. */
         vmk_MemPhysContiguity physContiguity;

         /** \brief Physical address resrictions. */
         vmk_MemPhysAddrConstraint physRange;
      } custom;
    
      /** \brief Properties for VMK_HEAP_TYPE_MEMPOOL. */
      struct {
         /** \brief Physical contiguity allocated from this heap. */
         vmk_MemPhysContiguity physContiguity;

         /** \brief Physical address resrictions. */
         vmk_MemPhysAddrConstraint physRange;

         /** \brief Memory pool to back this heap. */
         vmk_MemPool memPool;
      } memPool;
   } typeSpecific;
} vmk_HeapCreateProps;

/**
 * \brief Structure for querying properties of a heap.
 */
typedef struct vmk_HeapGetProps {
   /** \brief Name associated with this heap. */
   vmk_Name name;

   /** \brief Module ID of the module that created this heap. */
   vmk_ModuleID module;

   /** \brief Initial size of the heap in bytes. */
   vmk_ByteCountSmall initial;

   /** \brief Maximum size of the heap in bytes. */
   vmk_ByteCountSmall max;

   /** \brief Physical contiguity allocated from this heap. */
   vmk_MemPhysContiguity physContiguity;

   /** \brief Physical address resrictions. */
   vmk_MemPhysAddrConstraint physRange;

   /** \brief Memory pool backing this heap. */
   vmk_MemPool memPool;
} vmk_HeapGetProps;


/**
 * \brief Describes characteristics of allocation from a heap.
 */
typedef struct vmk_HeapAllocationDescriptor {
   /** \brief The size of the object being allocated. */
   vmk_ByteCount size;
   /** \brief The alignment at which these objects will be allocated. */
   vmk_ByteCount alignment;
   /** \brief The number of objects of this size and alignment being allocated. */
   vmk_uint64 count;
} vmk_HeapAllocationDescriptor;


/*
 ***********************************************************************
 * vmk_HeapCreate --                                              */ /**
 *
 * \brief Create a heap that can grow dynamically up to the max size.
 *
 * \note  This function may block if heapCreationTimeoutMS is not
 *        VMK_TIMEOUT_NONBLOCKING.
 *
 * \param[in]  props     Properties of the heap.
 * \param[out] heapID    Newly created heap or VMK_INVALID_HEAP_ID
 *                       on failure.
 *
 * \retval VMK_NO_MEM    The heap could not be allocated.
 * \retval VMK_BAD_PARAM Invalid combination of props->initial and props->max
 *                       was specified.
 *
 ***********************************************************************
 */
VMK_ReturnStatus vmk_HeapCreate(vmk_HeapCreateProps *props,
                                vmk_HeapID *heapID);

/*
 ***********************************************************************
 * vmk_HeapDestroy --                                             */ /**
 *
 * \brief Destroy a dynamic heap
 *
 * \note  This function will not block.
 *
 * \param[in] heap   Heap to destroy.
 *
 * \pre All memory allocated on the heap should be freed before the heap
 *      is destroyed.
 *
 ***********************************************************************
 */
void vmk_HeapDestroy(vmk_HeapID heap);

/*
 ***********************************************************************
 * vmk_HeapFree --                                                */ /**
 *
 * \brief Free memory allocated with vmk_HeapAlloc.
 *
 * \note  This function will not block.
 *
 * \param[in] heap   Heap that memory to be freed was allocated from.
 * \param[in] mem    Memory to be freed. Should not be NULL.
 *
 ***********************************************************************
 */
void vmk_HeapFree(vmk_HeapID heap, void *mem);

/*
 ***********************************************************************
 * vmk_HeapAllocWithRA --                                         */ /**
 *
 * \brief Allocate memory and specify the caller's address.
 *
 * \note  This function will not block.
 *
 * This is useful when allocating memory from a wrapper function.
 *
 * \param[in] heap   Heap that memory to be freed was allocated from.
 * \param[in] size   Number of bytes to allocate.
 * \param[in] ra     Address to return to.
 *
 * \retval NULL Cannot allocate 'size' bytes from specified heap.
 * \return Address of allocated memory of the specified size.
 *
 ***********************************************************************
 */
void *vmk_HeapAllocWithRA(vmk_HeapID heap, vmk_uint32 size, void *ra);

/*
 ***********************************************************************
 * vmk_HeapAlignWithRA --                                         */ /**
 *
 * \brief Allocate aligned memory and specify the caller's address
 *
 * This is useful when allocating memory from a wrapper function.
 *
 * \note  This function will not block.
 *
 * \param[in] heap   Heap that memory to be freed was allocated from.
 * \param[in] size   Number of bytes to allocate.
 * \param[in] align  Number of bytes the allocation should be aligned
 *                   on.
 * \param[in] ra     Address to return to after allocation.
 *
 * \retval NULL Cannot allocate 'size' bytes from specified heap.
 * \return Address of allocated memory of the specified size.
 *
 ***********************************************************************
 */
void *vmk_HeapAlignWithRA(vmk_HeapID heap, vmk_uint32 size,
			  vmk_uint32 align, void *ra);

/*
 ***********************************************************************
 * vmk_HeapAlloc --                                               */ /**
 *
 * \brief Allocate memory in the specified heap
 *
 * \note  This function will not block.
 * 
 * \param[in] _heap   Heap to allocate from.
 * \param[in] _size   Number of bytes to allocate.
 *
 * \retval NULL Cannot allocate 'size' bytes from specified heap.
 * \return Address of allocated memory of the specified size.
 *
 ***********************************************************************
 */
#define vmk_HeapAlloc(_heap, _size) \
   (vmk_HeapAllocWithRA((_heap), (_size), __builtin_return_address(0)))

/*
 ***********************************************************************
 * vmk_HeapAlign --                                               */ /**
 *
 * \brief Allocate aligned memory
 *
 * \param[in] _heap       Heap to allocate from.
 * \param[in] _size       Number of bytes to allocate.
 * \param[in] _alignment  Number of bytes the allocation should be
 *                        aligned on.
 *
 * \note  This function will not block.
 *
 * \retval NULL Cannot allocate 'size' bytes from specified heap.
 * \return Address of allocated memory of the specified size.
 *
 ***********************************************************************
 */
#define vmk_HeapAlign(_heap, _size, _alignment)         \
   (vmk_HeapAlignWithRA((_heap), (_size), (_alignment), \
                        __builtin_return_address(0)))

/*
 ***********************************************************************
 * vmk_HeapAllocWithTimeoutAndRA --                               */ /**
 *
 * \brief Allocate memory, possibly waiting for physical memory.
 *
 * If the heap is not already at maximum size, this call may block
 * for up to timeoutMS milliseconds for memory to become available
 * to grow the heap.  If the heap is full and is already at maximum
 * size, no blocking will be performed.
 *
 * This is useful when allocating memory from a wrapper function.
 *
 * \note  This function may block.
 *
 * \param[in] heap         Heap to allocate from.
 * \param[in] size         Number of bytes to allocate.
 * \param[in] timeoutMS    Maximum wait time in milliseconds.
 * \param[in] ra           Address to return to.
 *
 * \retval NULL Cannot allocate 'size' bytes from specified heap.
 * \return Address of allocated memory of the specified size.
 *
 ***********************************************************************
 */
void *vmk_HeapAllocWithTimeoutAndRA(vmk_HeapID heap, vmk_uint32 size, 
                                    vmk_uint32 timeoutMS, void *ra);

/*
 ***********************************************************************
 * vmk_HeapAlignWithTimeoutAndRA --                               */ /**
 *
 * \brief Allocate aligned memory, possibly waiting for physical memory.
 *
 * If the heap is not already at maximum size, this call may block
 * for up to timeoutMS milliseconds for memory to become available
 * to grow the heap.  If the heap is full and is already at maximum
 * size, no blocking will be performed.
 *
 * This is useful when allocating memory from a wrapper function.
 *
 * \note  This function may block.
 *
 * \param[in] heap        Heap to allocate from.
 * \param[in] size        Number of bytes to allocate.
 * \param[in] align       Number of bytes the allocation should be
 *                        aligned on.
 * \param[in] timeoutMS   Maximum wait time in milliseconds.
 * \param[in] ra          Address to return to after allocation.
 *
 * \retval NULL Cannot allocate 'size' bytes from specified heap.
 * \return Address of allocated memory of the specified size.
 *
 ***********************************************************************
 */
void *vmk_HeapAlignWithTimeoutAndRA(vmk_HeapID heap, vmk_uint32 size,
                                    vmk_uint32 align, vmk_uint32 timeoutMS,
                                    void *ra);

/*
 ***********************************************************************
 * vmk_HeapAllocWithTimeout --                                    */ /**
 *
 * \brief Allocate memory, possibly waiting for physical memory.
 *
 * If the heap is not already at maximum size, this call may block
 * for up to timeoutMS milliseconds for memory to become available
 * to grow the heap.  If the heap is full and is already at maximum
 * size, no blocking will be performed.
 *
 * \note  This function may block.
 *
 * \param[in] _heap        Heap to allocate from.
 * \param[in] _size        Number of bytes to allocate.
 * \param[in] _timeoutMS   Maximum wait time in milliseconds.
 *
 * \retval NULL Cannot allocate 'size' bytes from specified heap.
 * \return Address of allocated memory of the specified size.
 *
 ***********************************************************************
 */
#define vmk_HeapAllocWithTimeout(_heap, _size, _timeoutMS)             \
        (vmk_HeapAllocWithTimeoutAndRA((_heap), (_size), (_timeoutMS), \
                                       __builtin_return_address(0)))

/*
 ***********************************************************************
 * vmk_HeapAlignWithTimeout --                                    */ /**
 *
 * \brief Allocate aligned memory, possibly waiting for physical memory.
 *
 * If the heap is not already at maximum size, this call may block
 * for up to timeoutMS milliseconds for memory to become available
 * to grow the heap.  If the heap is full and is already at maximum
 * size, no blocking will be performed.
 *
 * \note  This function may block.
 *
 * \param[in] _heap         Heap to allocate from.
 * \param[in] _size         Number of bytes to allocate.
 * \param[in] _alignment    Number of bytes the allocation should be
 *                          aligned on.
 * \param[in] _timeoutMS    Maximum wait time in milliseconds.
 *
 * \retval NULL Cannot allocate 'size' bytes from specified heap.
 * \return Address of allocated memory of the specified size.
 *
 ***********************************************************************
 */
#define vmk_HeapAlignWithTimeout(_heap, _size, _alignment, _timeoutMS)       \
   (vmk_HeapAlignWithTimeoutAndRA((_heap), (_size), (_alignment),            \
                                  (_timeoutMS),  __builtin_return_address(0)))

/*
 ***********************************************************************
 * vmk_HeapGetProperties --                                       */ /**
 *
 * \brief Get the properties of the heap
 *
 * \note  The properties returned may not necessarily be the same as
 *        those specified when the heap was created.  Some properties are
 *        adjusted by the heap internal implementation to conform to
 *        implementation details.  For example, a heap maximum size may
 *        be rounded up due to alignment of allocations.  The values
 *        returned are those that are actually used by the heap.
 *
 * \note  This function will not block.
 *
 * \param[in]  heap      Heap that caller is interogating.
 * \param[out] props     The heap's properties.
 *
 * \retval VMK_OK          Properties successfully retrieved.
 * \retval VMK_BAD_PARAM   heap was not a valid heap ID.
 *
 ***********************************************************************
 */
VMK_ReturnStatus
vmk_HeapGetProperties(vmk_HeapID heap, vmk_HeapGetProps *props);

/*
 ***********************************************************************
 * vmk_HeapDetermineMaxSize --                                    */ /**
 *
 * \brief Determines the required maximum size of a heap in bytes.
 *
 * Determines the required maximum size of a heap that will contain
 * the descriptors described in the descriptors array. Note that this
 * does not include overhead for fragmentation within the heap and it
 * is the caller's responsibility to add that in when creating the heap.
 *
 * \note  This function will not block.
 *
 * \param[in]  descriptors     Pointer to an array of descriptors that
 *                             the heap will contain.  An alignment of
 *                             zero for a descriptor indicates no
 *                             alignment is specified by the caller and
 *                             the heap code will use a value it
 *                             determines.
 * \param[in]  numDescriptors  Number of vmk_HeapAllocationDescriptors
 *                             in the array pointed to by descriptors.
 * \param[out] maxSize         The determined maximum size.
 *
 * \retval VMK_OK              Size determined successfully and placed
 *                             in maxSize.
 * \retval VMK_BAD_PARAM       One of the arguments is invalid, or one
 *                             of the descriptors contains an invalid
 *                             value.
 * \retval VMK_LIMIT_EXCEEDED  The total size required for the
 *                             provided descriptors results in a heap
 *                             greater than the largest possible
 *                             allowed.
 *
 ***********************************************************************
 */
VMK_ReturnStatus
vmk_HeapDetermineMaxSize(vmk_HeapAllocationDescriptor *descriptors,
                         vmk_uint64 numDescriptors,
                         vmk_ByteCount *maxSize);

#endif /* _VMKAPI_HEAP_H_ */
/** @} */
/** @} */