INOS
cinospartitionmemory.h
Go to the documentation of this file.
1//******************************************************************************
27//******************************************************************************
28
29#ifndef INC_CINOSPARTITIONMEMORY_H
30#define INC_CINOSPARTITIONMEMORY_H
31
32//------------------------------------------------------------------------------
33// defines
34//------------------------------------------------------------------------------
35//
36//------------------------------------------------------------------------------
37// includes
38//------------------------------------------------------------------------------
39//
40// system
41//
42// C++
43//
44// project
45//
46
47//------------------------------------------------------------------------------
48// forwards
49//------------------------------------------------------------------------------
51
52//------------------------------------------------------------------------------
53// class definition
54//------------------------------------------------------------------------------
55//
57struct SINOSPMClassInfo
58{
59 // pointer to next info structure in chain
60 SINOSPMClassInfo* m_pNext;
61 // pointer to class name
62 char* m_pName;
63 // actual used size of this class
64 uint32* m_pSize;
65};
66
68struct SBackTrace
69{
70 explicit SBackTrace(
71 uint32 i_nCallStackDepth);
72 ~SBackTrace();
73 uint32 m_uCallStackDepth;
74 uint32* m_pCallStack;
75};
76
82struct SINOSPMHeader
83{
86 CINOSPartitionMemory* m_pPartition;
91 const char* m_pClassName;
95 uintptr* m_pBackTrace;
97 void* m_pOwner;
99 #if defined(INOS_64)
100 uint64 m_uReserved;
101 #endif
103 uint64 m_uTimeBase;
105 SINOSPMHeader* m_pNext;
107 SINOSPMHeader* m_pPrevious;
108};
109
115struct SINOSPMFooter
116{
119 enum {
120 eFooterPattern = 0x79811115
121 };
125 uint32 m_uPartitionFooterPattern;
130 uint32 m_uChecksum;
131};
132
138struct SINOSPMHeaderNoSecure
139{
142 CINOSPartitionMemory* m_pPartition;
144 void* m_pNext;
146 uint8 m_uPadding [16 - sizeof(m_pPartition) - sizeof(m_pNext)];
147};
149
150static_assert(sizeof(SINOSPMHeaderNoSecure) % 16 == 0,
151 "sizeof(SINOSPMHeaderNoSecure) must be a multiple of 16 bytes");
152
153class CINOSMemoryPool;
154class CINCOObject;
155class CINOSMutex;
157{
158 friend void _INI_0000_CINOSPartitionMemory();
159
171 static void* OperatorNewDuringCreate(size_t auSize);
175
176 //--- user interface ---------------------------------------------------
177
178 // public member functions
179 public :
180
182 enum {
183 eAllocAlignment = DF_INOS_MEMORY_ALLOC_ALIGNMENT
184 };
185
186 // construction / destruction
187
188 CINOSPartitionMemory (uint32 auSize, const char* apPoolName);
189 //; create partition memory with size 'auSize' which takes memory
190 //; from pool 'apPoolName'
191 static CINOSPartitionMemory* Create(uint32 auPartitionSize,
192 const char* apPoolName = 0);
193 //; create new partition memory object and return pointer to it
194 static CINOSPartitionMemory* Create(uint32 auPartitionSize,
195 const char* apPoolName, const char* apClass, uint32* apSize=0);
196 //; create new partition memory object for apClass and return pointer to it
197
198 // allocation / deallocation
199
200 void* Alloc(uint32 auSize=0, const char* apClassName = s_cNoClassNameSpecified,
201 bool abReturnNullOnFailure = false,
202 uint32 auMinimalReserve = 0);
203 //; allocate one partition and return pointer to it
204 bool Free(void* apPartition, const char* apClassName = s_cNoClassNameSpecified);
205 //; free partition 'apPartition'
206 //; returns true if the partition was actually freed (and its UsedSize counter was decremented)
207 static void* AllocGlobal(size_t auSize,
208 const char* apClassName = s_cNoClassNameSpecified,
209 bool abReturnNullOnFailure = false,
210 size_t auMinimalReserve = 0);
211 //; allocate auSize bytes for class named "apClassName". Always
212 //; prefer using DECLARE_DYNAMIC/IMPLEMENT_DYNAMIC in favor of this
213 //; function because the former is faster. AllocGlobal (and it's
214 //; counterpart FreeGlobal) were introduced to be used by 'operator
215 //; new' and 'operator delete', in order to use the partition
216 //; memory mechanism (instead of malloc/free).
217 static void FreeGlobal(void* apPartition,
218 const char* apClassName = s_cNoClassNameSpecified);
219 //; Frees memory allocated by AllocGlobal
220 uintnbr Available();
221 //; \return Overall available partition memory [bytes]. The function
222 //; takes the overhead added by the header/footer. E.g. assume
223 //; the partition size is 8. Further assume that the available
224 //; free memory (e.g. "Heap") is 64. The value returned by this
225 //; function will not be 64 in that case, because each allocation
226 //; produces some overhead. Instead (depending on the overhead
227 //; size), the function will return something like 56 or 48.
228
229 // miscelanselous
230
231 CINCOObject* GetRegister();
232 //; do inco registration and return pointer to it
233 void GetRegisterClass(CINCOObject* apClassObj,
234 const SINOSPMClassInfo* apClassInfo);
235 //; add the 'class information' (apClassInfo) to the "Classes"
236 //; object passed by apClassObj
237
238 // get / set properties
239
240 const char* GetPoolName() const { return m_pPoolName;};
241 //; return pool name this partition memory belongs to
242 CINOSMemoryPool* GetPool() const { return m_pPool;};
243 //; get pool this partition memory belongs to
244 void SetPool(CINOSMemoryPool* apPool) { m_pPool = apPool;};
245 //; set pool this partition memory belongs to
246 uint32 GetPartitionSize() const { return m_uPartitionSize;};
247 //; return pool name this partition memory belongs to
248 uint32 GetFreeCount() const { return m_uActualSize - m_uUsedSize;};
249 //; return number of free blocks
250 static CINOSPartitionMemory* GetFirst() { return m_pFirst;};
251 //; return pointer to first partition memory
252 CINOSPartitionMemory* GetNext() const { return m_pNext;};
253 //; return pointer to next partition memory
254 void SetBackTrace(const uint32 auBackTrace) { m_uBackTrace = auBackTrace; }
255 //; set new count of backtraces
256 uint32 GetBackTrace() const { return m_uBackTrace; }
257 //; \return The currently configured count of backtraces
258 static void CheckConsistency();
259 //; check consistency of all currently free partition blocks in the system
260 //; (this is just debug helper method)
261
262 //--- internals --------------------------------------------------------
263
264 friend void InitHeap(void*);
265
266 // protected member functions
267 protected :
268 uint32 CalcChecksum(SINOSPMHeader* apPartition) const;
269
270 // protected members
271 protected :
272 const char* m_pPoolName;
273 //; according memory pool name
274 CINOSMemoryPool* m_pPool;
275 //; pointer to parent pool
276 SINOSCoreLock m_Lock;
277 //; partition lock (used in multicore systems)
278 uint32 m_uPartitionSize;
279 //; partition size
280 uint32 m_uActualSize;
281 //; actual overall number of partitions this object handles
282 uint32 m_uUsedSize;
283 //; actual number of used partitions
284 uint32 m_uChecksumSize;
285 //; number of bytes to check
286 uint32 m_uBackTrace;
287 //; max. backtrace depth. If set to 0, backtraces are not stored.
288 void* m_pFstFree;
289 //; pointer to first free memory partition
290 SINOSPMHeader* m_pLstFree;
291 //; pointer to last free memory partition
292 SINOSPMHeader* m_pFstUsed;
293 //; pointer to first used memory partition
294 CINCOObject* m_pRegister;
295 //; pointer to inco registration
296 static CINOSPartitionMemory* m_pFirst;
297 //; pointer to first partition memory object in chain
298 CINOSPartitionMemory* m_pNext;
299 //; pointer to next partition memory object in chain
300 SINOSPMClassInfo* m_pFirstCI;
301 //; pointer to chain of class info
302 static const char* s_cNoClassNameSpecified;
303 //; default class name - in case that a class does not use secure
304 //; partition memory
305 static CINOSMutex s_PartitionCreationMutex;
306 //; Usually, the partition are created during the startup - there,
307 //; the function will not be executed by multiple threads. But under
308 //; certain circumstances (e.g. the INOSHeapAlloc function) the
309 //; Create function may also be executed after 'system startup'.
310 //; Then it's important to make sure only one task at a time will
311 //; 'search for' or 'create' a partition.
312};
313
314//
315//------------------------------------------------------------------------------
316//--- dynamic object handling macros -------------------------------------------
317//------------------------------------------------------------------------------
318
319#ifdef INOS_CACHE_LOCK_SUPPORT
320 #define INOS_CACHE "Cache"
321#else
322 #define INOS_CACHE 0
323#endif
324
328#define DECLARE_DYNAMIC(aClass) DECLARE_DYNAMIC_POOL(aClass,0)
330#define DECLARE_DYNAMIC_T(aClass,aT) DECLARE_DYNAMIC_POOL_T(aClass,aT,0)
332#define DECLARE_DYNAMIC_T2(aClass,aT1,aT2) DECLARE_DYNAMIC_POOL_T2(aClass,aT1,aT2,0)
334#define DECLARE_DYNAMIC_T3(aClass,aT1,aT2,aT3) DECLARE_DYNAMIC_POOL_T3(aClass,aT1,aT2,aT3,0)
336#define DECLARE_DYNAMIC_T4(aClass,aT1,aT2,aT3,aT4) DECLARE_DYNAMIC_POOL_T4(aClass,aT1,aT2,aT3,aT4,0)
338#define DECLARE_DYNAMIC_N(aClass,aN) DECLARE_DYNAMIC_POOL_N(aClass,aN,0)
340#define DECLARE_DYNAMIC_N2(aClass,aN,aM) DECLARE_DYNAMIC_POOL_N2(aClass,aN,aM,0)
341
342#define DECLARE_DYNAMIC_CACHE(aClass) DECLARE_DYNAMIC_POOL(aClass,INOS_CACHE)
345#define DECLARE_DYNAMIC_I(aClass,aInnerClass) DECLARE_DYNAMIC_POOL_T(aClass,aInnerClass,0)
348#define DECLARE_DYNAMIC_PLACEMENT(aClass) DECLARE_DYNAMIC_POOL_PLACEMENT(aClass)
356#define DECLARE_DYNAMIC_VARIADIC(aClass) DECLARE_DYNAMIC_POOL_VARIADIC(aClass,0)
357
361#define IMPLEMENT_DYNAMIC(aClass) IMPLEMENT_DYNAMIC_POOL(aClass,0)
363#define IMPLEMENT_DYNAMIC_T(aClass,aT) IMPLEMENT_DYNAMIC_POOL_T(aClass,aT,0)
365#define IMPLEMENT_DYNAMIC_T2(aClass,aT1,aT2) IMPLEMENT_DYNAMIC_POOL_T2(aClass,aT1,aT2,0)
367#define IMPLEMENT_DYNAMIC_T3(aClass,aT1,aT2,aT3) IMPLEMENT_DYNAMIC_POOL_T3(aClass,aT1,aT2,aT3,0)
369#define IMPLEMENT_DYNAMIC_T_S(aClass,aT,aS) IMPLEMENT_DYNAMIC_POOL_T_S(aClass,aT,aS,0)
371#define IMPLEMENT_DYNAMIC_T4(aClass,aT1,aT2,aT3,aT4) IMPLEMENT_DYNAMIC_POOL_T4(aClass,aT1,aT2,aT3,aT4,0)
373#define IMPLEMENT_DYNAMIC_N(aClass,aN) IMPLEMENT_DYNAMIC_POOL_N(aClass,aN,0)
375#define IMPLEMENT_DYNAMIC_N2(aClass,aN,aM) IMPLEMENT_DYNAMIC_POOL_N2(aClass,aN,aM,0)
376#define IMPLEMENT_DYNAMIC_CACHE(aClass) IMPLEMENT_DYNAMIC_POOL(aClass,INOS_CACHE)
377#define IMPLEMENT_DYNAMIC_I(aClass,aT) IMPLEMENT_DYNAMIC_POOL_I(aClass,aT,0)
378#define IMPLEMENT_DYNAMIC_PLACEMENT(aClass) IMPLEMENT_DYNAMIC_POOL_PLACEMENT(aClass)
379#define IMPLEMENT_DYNAMIC_PLACEMENT_N(aClass,N) IMPLEMENT_DYNAMIC_POOL_PLACEMENT_N(aClass, N)
380#define IMPLEMENT_DYNAMIC_T2_VARIADIC(aClass,aT1,aT2) IMPLEMENT_DYNAMIC_POOL_T2_VARIADIC(aClass,aT1,aT2,0)
381#define IMPLEMENT_DYNAMIC_T3_VARIADIC(aClass,aT1,aT2,aT3) IMPLEMENT_DYNAMIC_POOL_T3_VARIADIC(aClass,aT1,aT2,aT3,0)
382#define IMPLEMENT_DYNAMIC_T4_VARIADIC(aClass,aT1,aT2,aT3,aT4) IMPLEMENT_DYNAMIC_POOL_T4_VARIADIC(aClass,aT1,aT2,aT3,aT4,0)
383
384
388#ifdef INOS_SECURE_PARTITION_MEMORY
389#define DF_HANDLE_MEMPOOL_CLASSNAME_ARG(i_Arg) \
390 , i_Arg
391#define DF_HIDE_IF_NO_SECURE_PARTITION_MEMORY(aStatement) \
392 aStatement
393#define DF_HIDE_IF_NO_SECURE_PARTITION_MEMORY_3(aStatement1, aStatement2, aStatement3) \
394 aStatement1, aStatement2, aStatement3
395#define DF_HIDE_IF_NO_SECURE_PARTITION_MEMORY_4(aStatement1, aStatement2, aStatement3, aStatement4) \
396 aStatement1, aStatement2, aStatement3, aStatement4
397#define DF_HIDE_IF_NO_SECURE_PARTITION_MEMORY_5(aStatement1, aStatement2, aStatement3, aStatement4, aStatement5) \
398 aStatement1, aStatement2, aStatement3, aStatement4, aStatement5
399#define DF_HIDE_IF_NO_SECURE_PARTITION_MEMORY_7(aStatement1, aStatement2, aStatement3, aStatement4, aStatement5, aStatement6, aStatement7) \
400 aStatement1, aStatement2, aStatement3, aStatement4, aStatement5, aStatement6, aStatement7
401#define DF_HIDE_IF_NO_SECURE_PARTITION_MEMORY_10(aStatement1, aStatement2, aStatement3, aStatement4, aStatement5, aStatement6, aStatement7, aStatement8, aStatement9, aStatement10) \
402 aStatement1, aStatement2, aStatement3, aStatement4, aStatement5, aStatement6, aStatement7, aStatement8, aStatement9, aStatement10
403#else
404#define DF_HANDLE_MEMPOOL_CLASSNAME_ARG(i_Arg)
405#define DF_HIDE_IF_NO_SECURE_PARTITION_MEMORY(i_Statement)
406#define DF_HIDE_IF_NO_SECURE_PARTITION_MEMORY_3(aStatement1, aStatement2, aStatement3)
407#define DF_HIDE_IF_NO_SECURE_PARTITION_MEMORY_4(aStatement1, aStatement2, aStatement3, aStatement4)
408#define DF_HIDE_IF_NO_SECURE_PARTITION_MEMORY_5(aStatement1, aStatement2, aStatement3, aStatement4, aStatement5)
409#define DF_HIDE_IF_NO_SECURE_PARTITION_MEMORY_10(aStatement1, aStatement2, aStatement3, aStatement4, aStatement5, aStatement6, aStatement7, aStatement8, aStatement9, aStatement10)
410#endif
411
412
413// class
414#define DECLARE_DYNAMIC_POOL(aClass,aPool) \
415 static CINOSPartitionMemory* p##aClass##Memory; \
416 static uint32 u##aClass##Memory; \
417 DF_HIDE_IF_NO_SECURE_PARTITION_MEMORY(static const char* s##aClass##Name;) \
418 public: \
419 void* operator new(size_t aSize); \
420 void operator delete(void* aPtr);
421
422#define IMPLEMENT_DYNAMIC_POOL(aClass,aPool) \
423 CINOSPartitionMemory* aClass::p##aClass##Memory = \
424 CINOSPartitionMemory::Create(sizeof(aClass),aPool,#aClass,&aClass::u##aClass##Memory); \
425 uint32 aClass::u##aClass##Memory = 0; \
426 DF_HIDE_IF_NO_SECURE_PARTITION_MEMORY(const char* aClass::s##aClass##Name = #aClass;) \
427 void* aClass::operator new(size_t aSize) \
428 { \
429 INOS_ADD(aClass::u##aClass##Memory, 1); \
430 return p##aClass##Memory->Alloc((uint32)aSize DF_HANDLE_MEMPOOL_CLASSNAME_ARG(s##aClass##Name));\
431 } \
432 void aClass::operator delete(void* aPtr) \
433 { \
434 bool bFreed = p##aClass##Memory->Free(aPtr DF_HANDLE_MEMPOOL_CLASSNAME_ARG(s##aClass##Name)); \
435 if(bFreed) INOS_ADD(aClass::u##aClass##Memory, -1); \
436 }
437
438// class
439#define DECLARE_DYNAMIC_POOL_PLACEMENT(aClass) \
440 public: \
441 void* operator new(size_t aSize, void*);
442
443#define IMPLEMENT_DYNAMIC_POOL_PLACEMENT(aClass) \
444 void* aClass::operator new(size_t aSize, void* aAddress) \
445 { \
446 return aAddress; \
447 }
448#define IMPLEMENT_DYNAMIC_POOL_PLACEMENT_N(aClass,N) \
449 template< int aN> void* aClass< aN >::operator new(size_t aSize, void* aAddress)\
450 { \
451 return aAddress; \
452 }
453
454
455// template class
456#define DECLARE_DYNAMIC_POOL_T(aClass, aT, aPool ) \
457 static CINOSPartitionMemory* p##aClass##aT##Memory; \
458 static uint32 u##aClass##aT##Memory; \
459 DF_HIDE_IF_NO_SECURE_PARTITION_MEMORY(static const char* s##aClass##aT##Name;) \
460 public: \
461 void* operator new(size_t aSize) \
462 { \
463 INOS_ADD_(u##aClass##aT##Memory, 1); \
464 return p##aClass##aT##Memory->Alloc((uint32)aSize DF_HANDLE_MEMPOOL_CLASSNAME_ARG(s##aClass##aT##Name)); \
465 } \
466 void operator delete(void* aPtr) \
467 { \
468 bool bFreed = p##aClass##aT##Memory->Free(aPtr DF_HANDLE_MEMPOOL_CLASSNAME_ARG(s##aClass##aT##Name)); \
469 if(bFreed) INOS_ADD_(u##aClass##aT##Memory, -1); \
470 }
471
472#define IMPLEMENT_DYNAMIC_POOL_T(aClass, aT, aPool) \
473 DF_HIDE_IF_NO_SECURE_PARTITION_MEMORY(template< class aT > const char* aClass< aT >::s##aClass##aT##Name = #aClass#aT;) \
474 template< class aT > CINOSPartitionMemory* aClass< aT >::p##aClass##aT##Memory =\
475 CINOSPartitionMemory::Create(sizeof(aClass< aT >),aPool,#aClass#aT,&aClass< aT >::u##aClass##aT##Memory); \
476 template< class aT > uint32 aClass< aT >::u##aClass##aT##Memory = 0;
477
478#define IMPLEMENT_DYNAMIC_POOL_T_S(aClass, aT, aS, aPool) \
479 DF_HIDE_IF_NO_SECURE_PARTITION_MEMORY(const char* aClass< aS >::s##aClass##aT##Name = #aClass#aS;) \
480 CINOSPartitionMemory* aClass< aS >::p##aClass##aT##Memory =\
481 CINOSPartitionMemory::Create(sizeof(aClass< aS >),aPool,#aClass#aS,&aClass< aS >::u##aClass##aT##Memory); \
482 uint32 aClass< aS >::u##aClass##aT##Memory = 0;
483
484// template class (two template args)
485#define DECLARE_DYNAMIC_POOL_T2(aClass, aT1, aT2, aPool ) \
486 static CINOSPartitionMemory* p##aClass##aT1##aT2##Memory; \
487 static uint32 u##aClass##aT1##aT2##Memory; \
488 DF_HIDE_IF_NO_SECURE_PARTITION_MEMORY(static const char* s##aClass##aT1##aT2##Name;) \
489 public: \
490 void* operator new(size_t aSize) \
491 { \
492 INOS_ADD_(u##aClass##aT1##aT2##Memory, 1); \
493 return p##aClass##aT1##aT2##Memory->Alloc((uint32)aSize DF_HANDLE_MEMPOOL_CLASSNAME_ARG(s##aClass##aT1##aT2##Name)); \
494 } \
495 void operator delete(void* aPtr) \
496 { \
497 bool bFreed = p##aClass##aT1##aT2##Memory->Free(aPtr DF_HANDLE_MEMPOOL_CLASSNAME_ARG(s##aClass##aT1##aT2##Name)); \
498 if(bFreed) INOS_ADD_(u##aClass##aT1##aT2##Memory, -1); \
499 }
500
501#define IMPLEMENT_DYNAMIC_POOL_T2(aClass, aT1, aT2, aPool) \
502 DF_HIDE_IF_NO_SECURE_PARTITION_MEMORY_3(template< class aT1, class aT2 > const char* aClass< aT1, aT2 >::s##aClass##aT1##aT2##Name = #aClass#aT1#aT2;) \
503 template< class aT1, class aT2 > CINOSPartitionMemory* aClass< aT1, aT2 >::p##aClass##aT1##aT2##Memory =\
504 CINOSPartitionMemory::Create(sizeof(aClass< aT1, aT2 >),aPool,#aClass#aT1#aT2,&aClass< aT1, aT2 >::u##aClass##aT1##aT2##Memory); \
505 template< class aT1, class aT2 > uint32 aClass< aT1, aT2 >::u##aClass##aT1##aT2##Memory = 0;
506
507
508// template class (three template args)
509#define DECLARE_DYNAMIC_POOL_T3(aClass, aT1, aT2, aT3, aPool ) \
510 static CINOSPartitionMemory* p##aClass##aT1##aT2##aT3##Memory; \
511 static uint32 u##aClass##aT1##aT2##aT3##Memory; \
512 DF_HIDE_IF_NO_SECURE_PARTITION_MEMORY(static const char* s##aClass##aT1##aT2##aT3##Name;) \
513 public: \
514 void* operator new(size_t aSize) \
515 { \
516 INOS_ADD_(u##aClass##aT1##aT2##aT3##Memory, 1); \
517 return p##aClass##aT1##aT2##aT3##Memory->Alloc((uint32)aSize DF_HANDLE_MEMPOOL_CLASSNAME_ARG(s##aClass##aT1##aT2##aT3##Name)); \
518 } \
519 void operator delete(void* aPtr) \
520 { \
521 bool bFreed = p##aClass##aT1##aT2##aT3##Memory->Free(aPtr DF_HANDLE_MEMPOOL_CLASSNAME_ARG(s##aClass##aT1##aT2##aT3##Name)); \
522 if(bFreed) INOS_ADD_(u##aClass##aT1##aT2##aT3##Memory, -1); \
523 }
524
525#define IMPLEMENT_DYNAMIC_POOL_T3(aClass, aT1, aT2, aT3, aPool) \
526 DF_HIDE_IF_NO_SECURE_PARTITION_MEMORY_5(template< class aT1, class aT2, class aT3 > const char* aClass< aT1, aT2, aT3 >::s##aClass##aT1##aT2##aT3##Name = #aClass#aT1#aT2#aT3;) \
527 template< class aT1, class aT2, class aT3 > CINOSPartitionMemory* aClass< aT1, aT2, aT3 >::p##aClass##aT1##aT2##aT3##Memory =\
528 CINOSPartitionMemory::Create(sizeof(aClass< aT1, aT2, aT3 >),aPool,#aClass#aT1#aT2#aT3,&aClass< aT1, aT2, aT3 >::u##aClass##aT1##aT2##aT3##Memory); \
529 template< class aT1, class aT2, class aT3 > uint32 aClass< aT1, aT2, aT3 >::u##aClass##aT1##aT2##aT3##Memory = 0;
530
531
532// template class (four template args)
533#define DECLARE_DYNAMIC_POOL_T4(aClass, aT1, aT2, aT3, aT4, aPool ) \
534 static CINOSPartitionMemory* p##aClass##aT1##aT2##aT3##aT4##Memory; \
535 static uint32 u##aClass##aT1##aT2##aT3##aT4##Memory; \
536 DF_HIDE_IF_NO_SECURE_PARTITION_MEMORY(static const char* s##aClass##aT1##aT2##aT3##aT4##Name;) \
537 public: \
538 void* operator new(size_t aSize) \
539 { \
540 INOS_ADD_(u##aClass##aT1##aT2##aT3##aT4##Memory, 1); \
541 return p##aClass##aT1##aT2##aT3##aT4##Memory->Alloc((uint32)aSize DF_HANDLE_MEMPOOL_CLASSNAME_ARG(s##aClass##aT1##aT2##aT3##aT4##Name)); \
542 } \
543 void operator delete(void* aPtr) \
544 { \
545 bool bFreed = p##aClass##aT1##aT2##aT3##aT4##Memory->Free(aPtr DF_HANDLE_MEMPOOL_CLASSNAME_ARG(s##aClass##aT1##aT2##aT3##aT4##Name)); \
546 if(bFreed) INOS_ADD_(u##aClass##aT1##aT2##aT3##aT4##Memory, -1); \
547 }
548
549#define IMPLEMENT_DYNAMIC_POOL_T4(aClass, aT1, aT2, aT3, aT4, aPool) \
550 DF_HIDE_IF_NO_SECURE_PARTITION_MEMORY_7(template< class aT1, class aT2, class aT3, class aT4 > const char* aClass< aT1, aT2, aT3, aT4 >::s##aClass##aT1##aT2##aT3##aT4##Name = #aClass#aT1#aT2#aT3#aT4;) \
551 template< class aT1, class aT2, class aT3, class aT4 > CINOSPartitionMemory* aClass< aT1, aT2, aT3, aT4 >::p##aClass##aT1##aT2##aT3##aT4##Memory =\
552 CINOSPartitionMemory::Create(sizeof(aClass< aT1, aT2, aT3, aT4 >),aPool,#aClass#aT1#aT2#aT3#aT4,&aClass< aT1, aT2, aT3, aT4 >::u##aClass##aT1##aT2##aT3##aT4##Memory); \
553 template< class aT1, class aT2, class aT3, class aT4 > uint32 aClass< aT1, aT2, aT3, aT4 >::u##aClass##aT1##aT2##aT3##aT4##Memory = 0;
554
555// template class (one integer argument)
556#define DECLARE_DYNAMIC_POOL_N(aClass, aN, aPool ) \
557 static CINOSPartitionMemory* p##aClass##aN##Memory; \
558 static uint32 u##aClass##aN##Memory; \
559 DF_HIDE_IF_NO_SECURE_PARTITION_MEMORY(static const char* s##aClass##aN##Name;)\
560 public: \
561 void* operator new(size_t aSize) \
562 { \
563 INOS_ADD_(u##aClass##aN##Memory, 1); \
564 return p##aClass##aN##Memory->Alloc((uint32)aSize DF_HANDLE_MEMPOOL_CLASSNAME_ARG(s##aClass##aN##Name));\
565 } \
566 void operator delete(void* aPtr) \
567 { \
568 bool bFreed = p##aClass##aN##Memory->Free(aPtr DF_HANDLE_MEMPOOL_CLASSNAME_ARG(s##aClass##aN##Name));\
569 if(bFreed) INOS_ADD_(u##aClass##aN##Memory, -1); \
570 }
571#define IMPLEMENT_DYNAMIC_POOL_N(aClass, aN, aPool) \
572 DF_HIDE_IF_NO_SECURE_PARTITION_MEMORY(template< int aN> const char* aClass< aN >::s##aClass##aN##Name = #aClass#aN;) \
573 template< int aN> CINOSPartitionMemory* aClass< aN >::p##aClass##aN##Memory = \
574 CINOSPartitionMemory::Create(sizeof(aClass< aN >),aPool,#aClass#aN,&aClass< aN >::u##aClass##aN##Memory);\
575 template< int aN> uint32 aClass< aN >::u##aClass##aN##Memory = 0;
576
577// template class (two integer argument)
578#define DECLARE_DYNAMIC_POOL_N2(aClass, aN, aM, aPool ) \
579 static CINOSPartitionMemory* p##aClass##aN##aM##Memory; \
580 static uint32 u##aClass##aN##aM##Memory; \
581 DF_HIDE_IF_NO_SECURE_PARTITION_MEMORY(static const char* s##aClass##aN##aM##Name;)\
582 public: \
583 void* operator new(size_t aSize) \
584 { \
585 INOS_ADD_(u##aClass##aN##aM##Memory, 1); \
586 return p##aClass##aN##aM##Memory->Alloc((uint32)aSize DF_HANDLE_MEMPOOL_CLASSNAME_ARG(s##aClass##aN##aM##Name));\
587 } \
588 void operator delete(void* aPtr) \
589 { \
590 bool bFreed = p##aClass##aN##aM##Memory->Free(aPtr DF_HANDLE_MEMPOOL_CLASSNAME_ARG(s##aClass##aN##aM##Name));\
591 if(bFreed) INOS_ADD_(u##aClass##aN##aM##Memory, -1); \
592 }
593#define IMPLEMENT_DYNAMIC_POOL_N2(aClass, aN, aM, aPool) \
594 DF_HIDE_IF_NO_SECURE_PARTITION_MEMORY_3(template< int aN, int aM > const char* aClass< aN, aM >::s##aClass##aN##aM##Name = #aClass#aN#aM;) \
595 template< int aN, int aM > CINOSPartitionMemory* aClass< aN, aM >::p##aClass##aN##aM##Memory = \
596 CINOSPartitionMemory::Create(sizeof(aClass< aN, aM >),aPool,#aClass#aN#aM,&aClass< aN, aM >::u##aClass##aN##aM##Memory); \
597 template< int aN, int aM > uint32 aClass< aN, aM >::u##aClass##aN##aM##Memory = 0;
598
599#define IMPLEMENT_DYNAMIC_POOL_I(aClass, aInnerClass, aPool) \
600 DF_HIDE_IF_NO_SECURE_PARTITION_MEMORY(const char* aClass::aInnerClass::s##aClass##aInnerClass##Name = #aClass#aInnerClass;) \
601 CINOSPartitionMemory* aClass::aInnerClass::p##aClass##aInnerClass##Memory =\
602 CINOSPartitionMemory::Create(sizeof(aClass::aInnerClass),aPool,#aClass#aInnerClass,&aClass::aInnerClass::u##aClass##aInnerClass##Memory); \
603 uint32 aClass::aInnerClass::u##aClass##aInnerClass##Memory = 0;
604
605#define DECLARE_DYNAMIC_POOL_VARIADIC(aClass, aPool ) \
606 static CINOSPartitionMemory* pMemory; \
607 static uint32 uMemory; \
608 static const char* sName; \
609 public: \
610 void* operator new(size_t aSize); \
611 void operator delete(void* aPtr);
612
613#define IMPLEMENT_DYNAMIC_POOL_T4_VARIADIC(aClass, aT1, aT2, aT3, aT4, aPool) \
614 DF_HIDE_IF_NO_SECURE_PARTITION_MEMORY_7( \
615 template< class aT1, class aT2, class aT3, class ... aT4 > \
616 const char* aClass< aT1, aT2, aT3, aT4 ... >::sName = #aClass"<"#aT1"_"#aT2"_"#aT3"_"#aT4">";) \
617 template< class aT1, class aT2, class aT3, class ... aT4> \
618 CINOSPartitionMemory* aClass< aT1, aT2, aT3, aT4 ... >::pMemory = \
619 CINOSPartitionMemory::Create( \
620 sizeof(aClass< aT1, aT2, aT3, aT4 ... >),aPool,#aClass"<"#aT1"_"#aT2"_"#aT3"_"#aT4">", \
621 &aClass< aT1, aT2, aT3, aT4 ... >::uMemory); \
622 template< class aT1, class aT2, class aT3, class ... aT4> \
623 uint32 aClass< aT1, aT2, aT3, aT4 ... >::uMemory = 0; \
624 template< class aT1, class aT2, class aT3, class ... aT4> \
625 void* aClass< aT1, aT2, aT3, aT4 ... >::operator new(size_t aSize) { \
626 INOS_ADD_(uMemory, 1); \
627 return pMemory->Alloc((uint32)aSize DF_HANDLE_MEMPOOL_CLASSNAME_ARG(sName)); \
628 } \
629 template< class aT1, class aT2, class aT3, class ... aT4> \
630 void aClass< aT1, aT2, aT3, aT4 ... >::operator delete(void* aPtr) { \
631 bool bFreed = pMemory->Free(aPtr DF_HANDLE_MEMPOOL_CLASSNAME_ARG(sName)); \
632 if(bFreed) INOS_ADD_(uMemory, -1); \
633 }
634
635
636#define IMPLEMENT_DYNAMIC_POOL_T3_VARIADIC(aClass, aT1, aT2, aT3, aPool) \
637 DF_HIDE_IF_NO_SECURE_PARTITION_MEMORY_5( \
638 template< class aT1, class aT2, class ... aT3 > \
639 const char* aClass< aT1, aT2, aT3 ... >::sName = #aClass"<"#aT1"_"#aT2"_"#aT3">";) \
640 template< class aT1, class aT2, class ... aT3> \
641 CINOSPartitionMemory* aClass< aT1, aT2, aT3 ... >::pMemory = \
642 CINOSPartitionMemory::Create( \
643 sizeof(aClass< aT1, aT2, aT3 ... >),aPool,#aClass"<"#aT1"_"#aT2"_"#aT3">", \
644 &aClass< aT1, aT2, aT3 ... >::uMemory); \
645 template< class aT1, class aT2, class ... aT3> \
646 uint32 aClass< aT1, aT2, aT3 ... >::uMemory = 0; \
647 template< class aT1, class aT2, class ... aT3> \
648 void* aClass< aT1, aT2, aT3 ... >::operator new(size_t aSize) { \
649 INOS_ADD_(uMemory, 1); \
650 return pMemory->Alloc((uint32)aSize DF_HANDLE_MEMPOOL_CLASSNAME_ARG(sName)); \
651 } \
652 template< class aT1, class aT2, class ... aT3> \
653 void aClass< aT1, aT2, aT3 ... >::operator delete(void* aPtr) { \
654 bool bFreed = pMemory->Free(aPtr DF_HANDLE_MEMPOOL_CLASSNAME_ARG(sName)); \
655 if(bFreed) INOS_ADD_(uMemory, -1); \
656 }
657
658
659#define IMPLEMENT_DYNAMIC_POOL_T2_VARIADIC(aClass, aT1, aT2, aPool) \
660 DF_HIDE_IF_NO_SECURE_PARTITION_MEMORY_3( \
661 template< class aT1, class ... aT2 > \
662 const char* aClass< aT1, aT2 ... >::sName = #aClass"<"#aT1"_"#aT2">";) \
663 template< class aT1, class ... aT2> \
664 CINOSPartitionMemory* aClass< aT1, aT2 ... >::pMemory = \
665 CINOSPartitionMemory::Create( \
666 sizeof(aClass< aT1, aT2 ... >),aPool,#aClass"<"#aT1"_"#aT2">", \
667 &aClass< aT1, aT2 ... >::uMemory); \
668 template< class aT1, class ... aT2> uint32 aClass< aT1, aT2 ... >::uMemory = 0; \
669 template< class aT1, class ... aT2> \
670 void* aClass< aT1, aT2 ... >::operator new(size_t aSize) { \
671 INOS_ADD_(uMemory, 1); \
672 return pMemory->Alloc((uint32)aSize DF_HANDLE_MEMPOOL_CLASSNAME_ARG(sName)); \
673 } \
674 template< class aT1, class ... aT2> \
675 void aClass< aT1, aT2 ... >::operator delete(void* aPtr) { \
676 bool bFreed = pMemory->Free(aPtr DF_HANDLE_MEMPOOL_CLASSNAME_ARG(sName)); \
677 if(bFreed) INOS_ADD_(uMemory, -1); \
678 }
679
680//------------------------------------------------------------------------------
681// end of file
682//------------------------------------------------------------------------------
683
684#endif // INC_CINOSPARTITIONMEMORY_H
Definition cinosmutex.h:36
Definition cinospartitionmemory.h:157
#define DF_INOS_MEMORY_ALLOC_ALIGNMENT
Definition inosdefine.h:105
Definition inostype.h:258