Main Page   Modules   Class Hierarchy   Data Structures   File List   Data Fields   Globals   Related Pages  

oscl_mem_audit.h

Go to the documentation of this file.
00001 // -*- c++ -*-
00002 // = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
00003 
00004 //                   O S C L _ M E M _ A U D I T
00005 
00006 // = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
00007 
00018 #ifndef OSCL_MEM_AUDIT_H_INCLUDED
00019 #define OSCL_MEM_AUDIT_H_INCLUDED
00020 
00021 #ifndef OSCL_LOCK_BASE_H_INCLUDED
00022 #include "oscl_lock_base.h"
00023 #endif
00024 
00025 #ifndef OSCL_BASE_ALLOC_H_INCLUDED
00026 #include "oscl_base_alloc.h"
00027 #endif
00028 
00029 #ifndef OSCL_TAGTREE_H_INCLUDED
00030 #include "oscl_tagtree.h"
00031 #endif
00032 
00033 #ifndef OSCL_MEM_H_INCLUDED
00034 #include "oscl_mem.h"
00035 #endif
00036 
00037 #ifndef OSCL_MEM_AUTO_PTR_H_INCLUDED
00038 #include "oscl_mem_auto_ptr.h"
00039 #endif
00040 
00041 #define OSCL_DISABLE_WARNING_TRUNCATE_DEBUG_MESSAGE
00042 #include "osclconfig_compiler_warnings.h"
00043 
00044 
00045 /* DATA TYPES */
00046 struct MM_Stats_t
00047 {
00048     uint32  numBytes;
00049     uint32  peakNumBytes;
00050     uint32  numAllocs;
00051     uint32  peakNumAllocs;
00052     uint32  numAllocFails;
00053     uint32  totalNumAllocs;
00054     uint32  totalNumBytes;
00055 
00056     MM_Stats_t()
00057     {
00058         oscl_memset(this, 0, sizeof(MM_Stats_t));
00059     };
00060     MM_Stats_t(uint32 sizeIn)
00061     {
00062         numBytes = peakNumBytes = sizeIn;
00063         peakNumAllocs = numAllocs = 1;
00064         numAllocFails = 0;
00065         totalNumAllocs = 1;
00066         totalNumBytes = sizeIn;
00067     };
00068 
00069     void reset()
00070     {
00071         oscl_memset(this, 0, sizeof(MM_Stats_t));
00072     };
00073 
00074     void update(const MM_Stats_t& delta, bool add)
00075     {
00076         if (add)
00077         {
00078             numBytes += delta.numBytes;
00079             numAllocs += delta.numAllocs;
00080             numAllocFails += delta.numAllocFails;
00081             if (numBytes > peakNumBytes)
00082             {
00083                 peakNumBytes = numBytes;
00084             }
00085             if (numAllocs > peakNumAllocs)
00086             {
00087                 peakNumAllocs = numAllocs;
00088             }
00089 
00090             totalNumAllocs += delta.numAllocs;
00091             totalNumBytes += delta.numBytes;
00092 
00093         }
00094         else
00095         {
00096             numBytes -= delta.numBytes;
00097             numAllocs -= delta.numAllocs;
00098             numAllocFails -= delta.numAllocFails;
00099         }
00100     }
00101 
00102     void *operator new(oscl_memsize_t size)
00103     {
00104         OSCL_UNUSED_ARG(size);
00105         Oscl_TAlloc<MM_Stats_t, OsclMemBasicAllocator> statsAlloc;
00106         MM_Stats_t *ptr = statsAlloc.allocate(1);
00107         return ptr;
00108     };
00109 
00110     void *operator new(oscl_memsize_t size, MM_Stats_t* ptr)
00111     {
00112         OSCL_UNUSED_ARG(size);
00113         return ptr;
00114     };
00115 
00116 
00117     void operator delete(void *ptr) throw()
00118     {
00119         Oscl_TAlloc<MM_Stats_t, OsclMemBasicAllocator> statsAlloc;
00120         statsAlloc.deallocate((MM_Stats_t*)ptr);
00121     };
00122 
00123     /* won't build on ADS
00124     void operator delete(void *ptr, MM_Stats_t* mptr) {
00125          OSCL_UNUSED_ARG(ptr);
00126          OSCL_UNUSED_ARG(mptr);
00127      };
00128          */
00129 };
00130 
00131 struct MM_FailInsertParam
00132 {
00133     uint32 nAllocNum;
00134     uint16 xsubi[3];
00135     MM_FailInsertParam(): nAllocNum(0)
00136     {
00137         oscl_memset(xsubi, 0, 3*sizeof(xsubi[0]));
00138     }
00139 
00140     void reset()
00141     {
00142         nAllocNum = 0;
00143         oscl_memset(xsubi, 0, 3*sizeof(xsubi[0]));
00144     };
00145 
00146     void *operator new(oscl_memsize_t size)
00147     {
00148         OSCL_UNUSED_ARG(size);
00149         Oscl_TAlloc<MM_FailInsertParam, OsclMemBasicAllocator> failAlloc;
00150         MM_FailInsertParam *ptr = failAlloc.allocate(1);
00151         return ptr;
00152     };
00153 
00154     void *operator new(oscl_memsize_t size, MM_FailInsertParam* ptr)
00155     {
00156         OSCL_UNUSED_ARG(size);
00157         return ptr;
00158     };
00159 
00160 
00161     void operator delete(void *ptr) throw()
00162     {
00163         Oscl_TAlloc<MM_FailInsertParam, OsclMemBasicAllocator> failAlloc;
00164         failAlloc.deallocate((MM_FailInsertParam*)ptr);
00165     };
00166 
00167     /* won't build on ADS
00168     void operator delete(void *ptr, MM_FailInsertParam* mptr) {
00169         OSCL_UNUSED_ARG(ptr);
00170         OSCL_UNUSED_ARG(mptr);
00171     };*/
00172 };
00173 
00174 class OsclMemStatsNode
00175 {
00176     public:
00177 
00178         MM_Stats_t *pMMStats;
00179         MM_FailInsertParam *pMMFIParam;
00180 
00181         /* set a link to map, especially for getting the tags of children nodes */
00182         char *tag;
00183 
00184         OsclMemStatsNode()
00185         {
00186             pMMStats = NULL;
00187             pMMFIParam = NULL;
00188             tag = NULL;
00189         }
00190 
00191         void reset()
00192         {
00193             if (pMMStats) pMMStats->reset();
00194             if (pMMFIParam) pMMFIParam->reset();
00195         };
00196 
00197         ~OsclMemStatsNode()
00198         {
00199             OSCL_DELETE(pMMStats);
00200             OSCL_DELETE(pMMFIParam);
00201             Oscl_TAlloc<char, OsclMemBasicAllocator> charAlloc;
00202             charAlloc.deallocate(tag);
00203         }
00204 
00205         void *operator new(oscl_memsize_t size)
00206         {
00207             OSCL_UNUSED_ARG(size);
00208             Oscl_TAlloc<OsclMemStatsNode, OsclMemBasicAllocator> statsNodeAlloc;
00209             OsclMemStatsNode *ptr = statsNodeAlloc.allocate(1);
00210             return ptr;
00211         };
00212 
00213         void *operator new(oscl_memsize_t size, OsclMemStatsNode* ptr)
00214         {
00215             OSCL_UNUSED_ARG(size);
00216             return ptr;
00217         };
00218 
00219 
00220         void operator delete(void *ptr) throw()
00221         {
00222             Oscl_TAlloc<OsclMemStatsNode, OsclMemBasicAllocator> statsNodeAlloc;
00223             statsNodeAlloc.deallocate((OsclMemStatsNode*)ptr);
00224         };
00225 
00226         /* won't build on ADS
00227         void operator delete(void *ptr, OsclMemStatsNode* mptr) {
00228             OSCL_UNUSED_ARG(ptr);
00229             OSCL_UNUSED_ARG(mptr);
00230         };*/
00231 };
00232 
00233 struct MM_Stats_CB
00234 {
00235     const char *tag;
00236     const MM_Stats_t *pStats;
00237     uint32 num_child_nodes;
00238 
00239     MM_Stats_CB()
00240     {
00241         oscl_memset(this, 0, sizeof(MM_Stats_CB));
00242     }
00243 
00244     void *operator new(oscl_memsize_t size)
00245     {
00246         OSCL_UNUSED_ARG(size);
00247         Oscl_TAlloc<MM_Stats_CB, OsclMemBasicAllocator> statsCBAlloc;
00248         MM_Stats_CB *ptr = statsCBAlloc.allocate(1);
00249         return ptr;
00250     };
00251 
00252     void *operator new(oscl_memsize_t size, MM_Stats_CB* ptr)
00253     {
00254         OSCL_UNUSED_ARG(size);
00255         return ptr;
00256     };
00257 
00258 
00259     void operator delete(void *ptr) throw()
00260     {
00261         Oscl_TAlloc<MM_Stats_CB, OsclMemBasicAllocator> statsCBAlloc;
00262         statsCBAlloc.deallocate((MM_Stats_CB*)ptr);
00263     };
00264 
00265     /* won't build on ADS
00266     void operator delete(void *ptr, MM_Stats_CB* mptr) {
00267         OSCL_UNUSED_ARG(ptr);
00268         OSCL_UNUSED_ARG(mptr);
00269     };*/
00270 };
00271 
00272 #define MM_ALLOC_MAX_QUERY_FILENAME_LEN 128
00273 #define MM_ALLOC_MAX_QUERY_TAG_LEN 64
00274 
00275 struct MM_AllocQueryInfo
00276 {
00277     uint32 allocNum;
00278     char fileName[MM_ALLOC_MAX_QUERY_FILENAME_LEN];
00279     uint32 lineNo;
00280     uint32 size;
00281     const void *pMemBlock;
00282     char tag[MM_ALLOC_MAX_QUERY_TAG_LEN];
00283 };
00284 
00285 
00286 struct MM_AllocInfo
00287 {
00288     uint32 allocNum;
00289     char *pFileName;
00290     uint32 lineNo;
00291     uint32 size;
00292     void *pMemBlock;
00293     OsclMemStatsNode *pStatsNode;
00294     bool bSetFailure;
00295 
00296     MM_AllocInfo()
00297     {
00298         oscl_memset(this, 0, sizeof(MM_AllocInfo));
00299     }
00300 
00301     ~MM_AllocInfo()
00302     {
00303         Oscl_TAlloc<char, OsclMemBasicAllocator> charAlloc;
00304         charAlloc.deallocate(pFileName);
00305     }
00306 
00307 
00308     void *operator new(oscl_memsize_t size)
00309     {
00310         OSCL_UNUSED_ARG(size);
00311         Oscl_TAlloc<MM_AllocInfo, OsclMemBasicAllocator> allocInfoAlloc;
00312         MM_AllocInfo *ptr = allocInfoAlloc.allocate(1);
00313         return ptr;
00314     };
00315 
00316     void *operator new(oscl_memsize_t size, MM_AllocInfo* ptr)
00317     {
00318         OSCL_UNUSED_ARG(size);
00319         return ptr;
00320     };
00321 
00322 
00323     void operator delete(void *ptr) throw()
00324     {
00325         Oscl_TAlloc<MM_AllocInfo, OsclMemBasicAllocator> allocInfoAlloc;
00326         allocInfoAlloc.deallocate((MM_AllocInfo*)ptr);
00327     };
00328 
00329     /* won't build on ADS
00330     void operator delete(void *ptr, MM_AllocInfo* mptr) {
00331         OSCL_UNUSED_ARG(ptr);
00332         OSCL_UNUSED_ARG(mptr);
00333     };*/
00334 };
00335 
00336 
00337 struct MM_AllocNode
00338 {
00339     MM_AllocInfo *pAllocInfo;
00340 
00341     MM_AllocNode *pPrev;
00342     MM_AllocNode *pNext;
00343     MM_AllocNode()
00344     {
00345         oscl_memset(this, 0, sizeof(MM_AllocNode));
00346     }
00347 
00348     ~MM_AllocNode()
00349     {
00350         OSCL_DELETE(pAllocInfo);
00351     }
00352 
00353     void *operator new(oscl_memsize_t size)
00354     {
00355         OSCL_UNUSED_ARG(size);
00356         Oscl_TAlloc<MM_AllocNode, OsclMemBasicAllocator> allocNodeAlloc;
00357         MM_AllocNode *ptr = allocNodeAlloc.allocate(1);
00358         return ptr;
00359     };
00360 
00361     void *operator new(oscl_memsize_t size, MM_AllocNode* ptr)
00362     {
00363         OSCL_UNUSED_ARG(size);
00364         return ptr;
00365     };
00366 
00367 
00368     void operator delete(void *ptr) throw()
00369     {
00370         Oscl_TAlloc<MM_AllocNode, OsclMemBasicAllocator> allocNodeAlloc;
00371         allocNodeAlloc.deallocate((MM_AllocNode*)ptr);
00372     };
00373 
00374     /* won't build on ADS
00375     void operator delete(void *ptr, MM_AllocNode* mptr) {
00376         OSCL_UNUSED_ARG(ptr);
00377         OSCL_UNUSED_ARG(mptr);
00378     };*/
00379 };
00380 
00381 
00382 /* Define internal auto ptr classes that don't go through mem mgmt */
00383 typedef OSCLMemAutoPtr<char, Oscl_TAlloc<char, OsclMemBasicAllocator> > MMAuditCharAutoPtr;
00384 typedef OSCLMemAutoPtr<uint8, Oscl_TAlloc<uint8, _OsclBasicAllocator> > MMAuditUint8AutoPtr;
00385 typedef OSCLMemAutoPtr<MM_AllocNode, Oscl_TAlloc<MM_AllocNode, OsclMemBasicAllocator> > MM_AllocNodeAutoPtr;
00386 
00387 typedef OSCLMemAutoPtr<OsclMemStatsNode, Oscl_TAlloc<OsclMemStatsNode, OsclMemBasicAllocator> > MM_StatsNodeTagTreeType;
00388 typedef OSCLMemAutoPtr<OsclMemStatsNode, Oscl_TAlloc<OsclMemStatsNode, OsclMemBasicAllocator> > OsclMemStatsNodeAutoPtr;
00389 typedef Oscl_TAlloc<MM_StatsNodeTagTreeType, OsclMemBasicAllocator> TagTree_Allocator;
00390 typedef Oscl_TagTree<MM_StatsNodeTagTreeType, TagTree_Allocator> OsclTagTreeType;
00391 
00392 
00393 #define MM_AUDIT_VALIDATE_BLOCK 1
00394 #define MM_AUDIT_PREFILL_FLAG 0x1
00395 #define MM_AUDIT_POSTFILL_FLAG 0x2
00396 #define MM_AUDIT_VALIDATE_ALL_HEAP_FLAG 0x4
00397 #define MM_AUDIT_VALIDATE_ON_FREE_FLAG 0x8
00398 #define MM_AUDIT_ALLOC_NODE_ENABLE_FLAG 0x10
00399 #define MM_AUDIT_SUPPRESS_FILENAME_FLAG 0x20
00400 
00401 #if(PVMEM_INST_LEVEL>0)
00402 #define DEFAULT_MM_AUDIT_MODE (MM_AUDIT_PREFILL_FLAG | \
00403                                MM_AUDIT_POSTFILL_FLAG | \
00404                                MM_AUDIT_VALIDATE_ON_FREE_FLAG | \
00405                                MM_AUDIT_ALLOC_NODE_ENABLE_FLAG )
00406 
00407 
00408 
00409 #else
00410 #define DEFAULT_MM_AUDIT_MODE 0
00411 #endif
00412 
00413 
00414 struct MM_AuditOverheadStats
00415 {
00416     uint32 per_allocation_overhead;
00417     uint32 stats_overhead;
00418 };
00419 
00420 #if OSCL_BYPASS_MEMMGT
00421 //an empty class for compilation only
00422 class MM_Audit_Imp
00423 {
00424     public:
00425 };
00426 #else
00427 class MM_Audit_Imp
00428 {
00429     public:
00430 
00434         MM_Audit_Imp();
00435 
00439         ~MM_Audit_Imp();
00440 
00447         OSCL_IMPORT_REF void *MM_allocate(const OsclMemStatsNode*  statsNode,
00448                                           uint32 sizeIn,
00449                                           const char *pFileName,
00450                                           uint32 lineNumber,
00451                                           bool allocNodeTracking = false);
00452 
00456         OSCL_IMPORT_REF bool MM_deallocate(void *pMemBlockIn);
00457 
00462         OSCL_IMPORT_REF MM_Stats_t * MM_GetStats(const char * const  tagIn);
00463 
00468         OSCL_IMPORT_REF uint32 MM_GetStatsInDepth(const char *  tagIn, MM_Stats_CB *array_ptr, uint32 max_nodes);
00469 
00475         OSCL_IMPORT_REF uint32 MM_GetTreeNodes(const char *  tagIn);
00476 
00482         OSCL_IMPORT_REF bool MM_AddTag(const char * tagIn)
00483         {
00484             return (MM_GetTagNode(tagIn) != NULL);
00485         };
00486 
00493         OSCL_IMPORT_REF const OsclMemStatsNode* MM_GetTagNode(const char * tagIn);
00494 
00495 
00502         OSCL_IMPORT_REF const OsclMemStatsNode* MM_GetExistingTag(const char * tagIn);
00503 
00504 
00505         OSCL_IMPORT_REF const OsclMemStatsNode* MM_GetRootNode()
00506         {
00507             return mpStatsNode;
00508         };
00509 
00514         OSCL_IMPORT_REF MM_AllocQueryInfo* MM_CreateAllocNodeInfo(uint32 max_array_size);
00515         OSCL_IMPORT_REF void MM_ReleaseAllocNodeInfo(MM_AllocQueryInfo* info);
00516 
00526         OSCL_IMPORT_REF uint32 MM_GetAllocNodeInfo(MM_AllocQueryInfo* output_array,
00527                 uint32 max_array_size, uint32 offset);
00528 
00534         OSCL_IMPORT_REF bool MM_Validate(const void *ptrIn);
00535 
00540         uint32 MM_GetAllocNo(void)
00541         {
00542             return mnAllocNum;
00543         }
00544 
00549         void MM_GetOverheadStats(MM_AuditOverheadStats& stats)
00550         {
00551             stats.per_allocation_overhead = mm_audit_per_block_overhead;
00552             stats.stats_overhead = mm_audit_stats_overhead;
00553         }
00554 
00559         uint32 MM_GetNumAllocNodes()
00560         {
00561             return mNumAllocNodes;
00562         };
00563 
00567         uint32 MM_GetMode(void)
00568         {
00569             return mode;
00570         }
00571 
00576         uint8 MM_GetPrefillPattern(void)
00577         {
00578             return prefill_pattern;
00579         }
00580 
00585         uint32 MM_GetPostfillPattern(void)
00586         {
00587             return postfill_pattern;
00588         }
00589 
00593         OSCL_IMPORT_REF void MM_SetMode(uint32 inMode);
00594 
00598         OSCL_IMPORT_REF void MM_SetPrefillPattern(uint8 pattern);
00599 
00603         OSCL_IMPORT_REF void MM_SetPostfillPattern(uint8 pattern);
00604 
00609         OSCL_IMPORT_REF void MM_SetTagLevel(uint32 level);
00610 
00617         OSCL_IMPORT_REF bool MM_SetFailurePoint(const char * tagIn, uint32 alloc_number);
00618 
00623         OSCL_IMPORT_REF void MM_UnsetFailurePoint(const char * tagIn);
00624 
00625 
00626         /*
00627         * The following are private member functions
00628         */
00629 
00630 
00634         MM_AllocNode* addAllocNode(void *pMem, uint32 sizeIn, OsclMemStatsNode* pStatsNode, const char *pFileName, uint32 lineNumber);
00638         OsclMemStatsNode* removeAllocNode(void *pMemBlockIn, uint32& size);
00639         void removeALLAllocNodes();
00640 
00644         OsclMemStatsNode* createStatsNode(const char *  tagIn);
00648         bool updateStatsNode(OsclMemStatsNode *pCurrStatsNode,
00649                              const MM_Stats_t& pDelta, bool bAdd);
00653         bool updateStatsNodeInFailure(const char * tagIn);
00654         bool updateStatsNodeInFailure(OsclMemStatsNode * pStatsNode);
00658         bool pruneSubtree(OsclMemStatsNode *pNode);
00659         bool pruneSubtree(const char * tagIn);
00660 
00661         void retrieveParentTag(char *tag);
00665         int32 retrieveParentTagLength(const char *tag, int32 bound);
00669         void makeValidTag(const char * tagIn, MMAuditCharAutoPtr& autoptr);
00673         uint32 getTagActualSize(const char * tagIn);
00680         bool isSetFailure(const char * tagIn);
00681 
00682         bool isSetFailure(OsclMemStatsNode * statsNode);
00686         static bool validate(void *ptrIn);
00687 
00691         static OsclMemAudit* getAuditRoot(void *ptrIn);
00692 
00696         static uint32 getSize(void *ptrIn);
00697 
00701         bool validate_all_heap();
00702 
00703     private:
00704 
00705         void populateChildren(const char *tagIn,
00706                               MM_Stats_CB *array_ptr,
00707                               uint32 &curr_array_index,
00708                               uint32 max_nodes);
00709 
00710         /*
00711         * The following are private data members
00712         */
00713 
00718         MM_AllocNode *mpAllocNode, *mpCurrAllocNode;
00719 
00724         uint32 mNumAllocNodes;
00725 
00729         OsclMemStatsNode *mpStatsNode;
00734         OsclTagTreeType          mTagTree;
00738         uint32 mnAllocNum;
00739         uint32 mnMaxTagLevel;
00740         uint32 mode;
00741 
00742         uint32 mm_audit_per_block_overhead;
00743         uint32 mm_audit_stats_overhead;
00744 
00745         uint8 prefill_pattern;
00746         uint8 postfill_pattern;
00747 
00748 };
00749 #endif
00750 
00751 #if OSCL_BYPASS_MEMMGT
00752 //an empty class for compilation only.
00753 class OsclMemAudit
00754 {
00755     public:
00756 };
00757 #else
00758 class OsclMemAudit
00759 {
00760     public:
00764         OsclMemAudit()
00765         {
00766             void * p = _oscl_malloc(sizeof(MM_Audit_Imp));
00767             OsclError::LeaveIfNull(p);
00768 
00769             // this will invoke system placement new operator
00770             _pMM_Audit_Imp = OSCL_PLACEMENT_NEW(p, MM_Audit_Imp());
00771             iLock = &iSingletonLock;
00772             iRefCount = 1;
00773         };
00774 
00778         ~OsclMemAudit()
00779         {
00780             _pMM_Audit_Imp->~MM_Audit_Imp();
00781             _oscl_free((void *) _pMM_Audit_Imp);
00782         };
00783 
00790         void *MM_allocate(const OsclMemStatsNode*  statsNode,
00791                           uint32 sizeIn,
00792                           const char *pFileName,
00793                           uint32 lineNumber,
00794                           bool allocNodeTracking = false)
00795         {
00796             // make sure lock is acquired and freed up upon return
00797             iLock->Lock();
00798 
00799             void* result = _pMM_Audit_Imp->MM_allocate(statsNode, sizeIn, pFileName, lineNumber, allocNodeTracking);
00800 
00801             iLock->Unlock();
00802             return result;
00803         };
00804 
00808         bool MM_deallocate(void *pMemBlockIn)
00809         {
00810             // make sure lock is acquired and freed up upon return
00811             iLock->Lock();
00812 
00813             bool result = _pMM_Audit_Imp->MM_deallocate(pMemBlockIn);
00814 
00815             iLock->Unlock();
00816             return result;
00817         };
00818 
00823         MM_Stats_t * MM_GetStats(const char * const  tagIn)
00824         {
00825             // make sure lock is acquired and freed up upon return
00826             iLock->Lock();
00827 
00828             MM_Stats_t* result = (_pMM_Audit_Imp->MM_GetStats(tagIn));
00829 
00830             iLock->Unlock();
00831             return result;
00832         };
00833 
00838         uint32 MM_GetStatsInDepth(const char *  tagIn, MM_Stats_CB *array_ptr, uint32 max_nodes)
00839         {
00840             // make sure lock is acquired and freed up upon return
00841             iLock->Lock();
00842 
00843             uint32 result = (_pMM_Audit_Imp->MM_GetStatsInDepth(tagIn, array_ptr, max_nodes));
00844 
00845             iLock->Unlock();
00846             return result;
00847         };
00848 
00854         uint32 MM_GetTreeNodes(const char *  tagIn)
00855         {
00856             // make sure lock is acquired and freed up upon return
00857             iLock->Lock();
00858 
00859             uint32 result = (_pMM_Audit_Imp->MM_GetTreeNodes(tagIn));
00860 
00861             iLock->Unlock();
00862             return result;
00863         };
00864 
00870         bool MM_AddTag(const char * tagIn)
00871         {
00872             return (MM_GetTagNode(tagIn) != NULL);
00873         };
00874 
00881         const OsclMemStatsNode* MM_GetTagNode(const char * tagIn)
00882         {
00883             // make sure lock is acquired and freed up upon return
00884             iLock->Lock();
00885 
00886             const OsclMemStatsNode* result = (_pMM_Audit_Imp->MM_GetTagNode(tagIn));
00887 
00888             iLock->Unlock();
00889             return result;
00890         };
00891 
00892 
00899         const OsclMemStatsNode* MM_GetExistingTag(const char * tagIn)
00900         {
00901             // make sure lock is acquired and freed up upon return
00902             iLock->Lock();
00903 
00904             const OsclMemStatsNode* result = (_pMM_Audit_Imp->MM_GetExistingTag(tagIn));
00905 
00906             iLock->Unlock();
00907             return result;
00908         };
00909 
00910 
00911         const OsclMemStatsNode* MM_GetRootNode()
00912         {
00913             return (_pMM_Audit_Imp->MM_GetRootNode());
00914         };
00915 
00925         uint32 MM_GetAllocNodeInfo(MM_AllocQueryInfo* output_array,
00926                                    uint32 max_array_size, uint32 offset)
00927         {
00928             // make sure lock is acquired and freed up upon return
00929             iLock->Lock();
00930 
00931             uint32 result = (_pMM_Audit_Imp->MM_GetAllocNodeInfo(output_array, max_array_size, offset));
00932 
00933             iLock->Unlock();
00934             return result;
00935         };
00936 
00937         MM_AllocQueryInfo* MM_CreateAllocNodeInfo(uint32 max_array_size)
00938         {
00939             return _pMM_Audit_Imp->MM_CreateAllocNodeInfo(max_array_size);
00940         }
00941         void MM_ReleaseAllocNodeInfo(MM_AllocQueryInfo* info)
00942         {
00943             _pMM_Audit_Imp->MM_ReleaseAllocNodeInfo(info);
00944         }
00945 
00951         bool MM_Validate(const void *ptrIn)
00952         {
00953             // make sure lock is acquired and freed up upon return
00954             iLock->Lock();
00955 
00956             bool result = (_pMM_Audit_Imp->MM_Validate(ptrIn));
00957 
00958             iLock->Unlock();
00959             return result;
00960         };
00961 
00966         uint32 MM_GetAllocNo(void)
00967         {
00968             return (_pMM_Audit_Imp->MM_GetAllocNo());
00969         };
00970 
00975         void MM_GetOverheadStats(MM_AuditOverheadStats& stats)
00976         {
00977             _pMM_Audit_Imp->MM_GetOverheadStats(stats);
00978         };
00979 
00984         uint32 MM_GetNumAllocNodes()
00985         {
00986             return (_pMM_Audit_Imp->MM_GetNumAllocNodes());
00987         };
00988 
00992         uint32 MM_GetMode(void)
00993         {
00994             return (_pMM_Audit_Imp->MM_GetMode());
00995         };
00996 
01001         uint8 MM_GetPrefillPattern(void)
01002         {
01003             return (_pMM_Audit_Imp->MM_GetPrefillPattern());
01004         };
01005 
01010         uint32 MM_GetPostfillPattern(void)
01011         {
01012             return (_pMM_Audit_Imp->MM_GetPostfillPattern());
01013         };
01014 
01018         void MM_SetMode(uint32 inMode)
01019         {
01020             // make sure lock is acquired and freed up upon return
01021             iLock->Lock();
01022 
01023             _pMM_Audit_Imp->MM_SetMode(inMode);
01024 
01025             iLock->Unlock();
01026         };
01027 
01031         void MM_SetPrefillPattern(uint8 pattern)
01032         {
01033             // make sure lock is acquired and freed up upon return
01034             iLock->Lock();
01035 
01036             _pMM_Audit_Imp->MM_SetPrefillPattern(pattern);
01037 
01038             iLock->Unlock();
01039         };
01040 
01044         void MM_SetPostfillPattern(uint8 pattern)
01045         {
01046             // make sure lock is acquired and freed up upon return
01047             iLock->Lock();
01048 
01049             _pMM_Audit_Imp->MM_SetPostfillPattern(pattern);
01050 
01051             iLock->Unlock();
01052         };
01053 
01058         void MM_SetTagLevel(uint32 level)
01059         {
01060             // make sure lock is acquired and freed up upon return
01061             iLock->Lock();
01062 
01063             _pMM_Audit_Imp->MM_SetTagLevel(level);
01064 
01065             iLock->Unlock();
01066         };
01067 
01074         bool MM_SetFailurePoint(const char * tagIn, uint32 alloc_number)
01075         {
01076             // make sure lock is acquired and freed up upon return
01077             iLock->Lock();
01078 
01079             bool result = (_pMM_Audit_Imp->MM_SetFailurePoint(tagIn, alloc_number));
01080 
01081             iLock->Unlock();
01082             return result;
01083         };
01084 
01085 
01090         void MM_UnsetFailurePoint(const char * tagIn)
01091         {
01092             // make sure lock is acquired and freed up upon return
01093             iLock->Lock();
01094 
01095             _pMM_Audit_Imp->MM_UnsetFailurePoint(tagIn);
01096 
01097             iLock->Unlock();
01098         };
01099 
01100         int32 MM_GetRefCount()
01101         {
01102             int32 count;
01103             iLock->Lock();
01104             count = iRefCount;
01105             iLock->Unlock();
01106             return count;
01107         }
01108 
01114         OsclLockBase* GetLock()
01115         {
01116             return iLock;
01117         };
01118 
01119         /*
01120         * The following are private member functions
01121         */
01122 
01123     private:
01127         MM_AllocNode* addAllocNode(void *pMem, uint32 sizeIn, OsclMemStatsNode* pStatsNode,
01128                                    const char *pFileName, uint32 lineNumber)
01129         {
01130             return (_pMM_Audit_Imp->addAllocNode(pMem, sizeIn, pStatsNode, pFileName, lineNumber));
01131         }
01132 
01136         OsclMemStatsNode* removeAllocNode(void *pMemBlockIn, uint32& size)
01137         {
01138             return (_pMM_Audit_Imp->removeAllocNode(pMemBlockIn, size));
01139         }
01140 
01141         void removeALLAllocNodes()
01142         {
01143             _pMM_Audit_Imp->removeALLAllocNodes();
01144         }
01145 
01149         OsclMemStatsNode* createStatsNode(const char *  tagIn)
01150         {
01151             return (_pMM_Audit_Imp->createStatsNode(tagIn));
01152         }
01153 
01157         bool updateStatsNode(OsclMemStatsNode *pCurrStatsNode,
01158                              const MM_Stats_t& pDelta, bool bAdd)
01159         {
01160             return (_pMM_Audit_Imp->updateStatsNode(pCurrStatsNode, pDelta, bAdd));
01161         }
01162 
01166         bool updateStatsNodeInFailure(const char * tagIn)
01167         {
01168             return (_pMM_Audit_Imp->updateStatsNodeInFailure(tagIn));
01169         }
01170 
01171         bool updateStatsNodeInFailure(OsclMemStatsNode * pStatsNode)
01172         {
01173             return (_pMM_Audit_Imp->updateStatsNodeInFailure(pStatsNode));
01174         }
01175 
01179         bool pruneSubtree(OsclMemStatsNode *pNode)
01180         {
01181             return (_pMM_Audit_Imp->pruneSubtree(pNode));
01182         }
01183 
01184         bool pruneSubtree(const char * tagIn)
01185         {
01186             return (_pMM_Audit_Imp->pruneSubtree(tagIn));
01187         }
01188 
01189         void retrieveParentTag(char *tag)
01190         {
01191             (_pMM_Audit_Imp->retrieveParentTag(tag));
01192         }
01193 
01197         int32 retrieveParentTagLength(const char *tag, int32 bound)
01198         {
01199             return (_pMM_Audit_Imp->retrieveParentTagLength(tag, bound));
01200         }
01201 
01205         void makeValidTag(const char * tagIn, MMAuditCharAutoPtr& autoptr)
01206         {
01207             (_pMM_Audit_Imp->makeValidTag(tagIn, autoptr));
01208         }
01209 
01213         uint32 getTagActualSize(const char * tagIn)
01214         {
01215             return (_pMM_Audit_Imp->getTagActualSize(tagIn));
01216         }
01217 
01221         bool isSetFailure(const char * tagIn)
01222         {
01223             return (_pMM_Audit_Imp->isSetFailure(tagIn));
01224         }
01225 
01226         bool isSetFailure(OsclMemStatsNode * statsNode)
01227         {
01228             return (_pMM_Audit_Imp->isSetFailure(statsNode));
01229         }
01230 
01234         bool validate(void *ptrIn)
01235         {
01236             return (_pMM_Audit_Imp->validate(ptrIn));
01237         }
01238 
01242         bool validate_all_heap()
01243         {
01244             return (_pMM_Audit_Imp->validate_all_heap());
01245         }
01246 
01247 
01248     private:
01249 
01250         /*
01251         * The following are private data members
01252         */
01253 
01254         MM_Audit_Imp *_pMM_Audit_Imp;
01255         OsclLockBase *iLock;
01256 
01260         _OsclBasicLock iSingletonLock;
01261         int32 iRefCount;
01262         friend class OsclMemGlobalAuditObject;
01263 
01264 };
01265 #endif
01266 
01267 #endif //OSCL_MEM_AUDIT_H_INCLUDED
01268 

OSCL API
Posting Version: CORE_8.000.1.1_RC4