-#if 0
-T2kMeamLeakInfo gMemLeakInfo[T2K_MEM_LEAK_INFO_TABLE_SIZE];
-U32 getT2kMemLeakIndex(U32 address)
-{
-#if 0
- /*
- 1 2 3 4 5 6 7
-
- XOR 7 with 3 and remove 7
- XOR 1 with 5 and remove 1
- */
-
- address -= T2K_MEM_LEAK_START_ADDR;
-
- U8 Nib7 = address & 0x0000000f;
- U8 Nib1 = (address & 0x0f000000) >>24;
- U8 Nib3 = (address & 0x000f0000) >> 16;
- U8 Nib5 = (address & 0x00000f00) >> 8;
-
- /* store 8 ^ 3 in 8Nib */
- Nib7 = Nib7 ^ Nib3;
- /* store 1 ^ 6 in 6Nib */
- Nib5 = Nib5 ^ Nib1;
-
- return(((address & 0x000fff00) | (Nib7 << 20) | (Nib5 << 4)) >> 4);
-
-#endif
- return ((address - T2K_MEM_LEAK_START_ADDR) >> 8);
-}
-
-static U32 t2kMemAllocTick;
-static U32 smallTick;
-
-void InsertToT2kMemLeakInfo(U32 address, U32 size, U32 lineNo, char* fileName)
-{
- U32 index = getT2kMemLeakIndex(address);
-
- if(((U32)(address - T2K_MEM_LEAK_START_ADDR) & 0xff) !=0)
- {
- printf("address in InsertToT2kMemLeakInfo is %x size = %d file is %s line is %d \n", address, size, fileName, lineNo);
- }
-
- if(gMemLeakInfo[index].address == 0)
- {
- gMemLeakInfo[index].address = address;
- gMemLeakInfo[index].size = size;
- gMemLeakInfo[index].lineNo = lineNo;
- gMemLeakInfo[index].fileName = fileName;
- gMemLeakInfo[index].age = t2kMemAllocTick;
- gMemLeakInfo[index].prevRemLineNo = 0;
- gMemLeakInfo[index].prevRemFileName = '\0';
-
- if(smallTick++ == 4096)
- {
- smallTick = 0;
- gMemLeakInfo[index].age = (++t2kMemAllocTick);
- }
- }
- else
- {
- printf("Something is wrong, trying to insert %x index = %d file is %s line is %d \n",address, index, fileName, lineNo);
- printf("Address present :%x, from File:%s, Line:%d, Size:%d, Age:%d",
- gMemLeakInfo[index].address, gMemLeakInfo[index].fileName,
- gMemLeakInfo[index].lineNo, gMemLeakInfo[index].size,
- gMemLeakInfo[index].age);
-#if 0
- /* Try inserting into some other location */
- int i;
- int lastIndex = index + 1;
- Bool inserted = FALSE;
- for(i = 2; lastIndex < T2K_MEM_LEAK_INFO_TABLE_SIZE && i < 30; i++)
- {
- if(gMemLeakInfo[lastIndex].address == 0)
- {
- gMemLeakInfo[lastIndex].address = address;
- gMemLeakInfo[lastIndex].size = size;
- gMemLeakInfo[lastIndex].lineNo = lineNo;
- gMemLeakInfo[lastIndex].fileName = fileName;
- gMemLeakInfo[lastIndex].age = (++t2kMemAllocTick) >> 14; /*For every 16384 memory block allocations,Alloc Tick is incremented by 1*/
- inserted = TRUE;
- break;
- }
- lastIndex = index + (i * i * i);
- }
-#if 1
- if(!inserted)
- {
- printf("Something is wrong, trying to insert %x index = %d no free i = %d\n",address, index, i);
- }
-#endif
-#endif
- }
-}
-
-
-void RemoveFromT2kMemLeakInfo(U32 address, char *file, U32 line)
-{
- U32 index = getT2kMemLeakIndex(address);
-
- if(index >= T2K_MEM_LEAK_INFO_TABLE_SIZE)
- {
- printf("Index out of range = %d address is %x file = %s line = %d. We are going to crash!!!\n",
- index,
- address,
- file,
- line);
- }
- if(gMemLeakInfo[index].address == address)
- {
- gMemLeakInfo[index].address = 0;
- gMemLeakInfo[index].age = 0;
- gMemLeakInfo[index].prevRemLineNo = gMemLeakInfo[index].lineNo;
- gMemLeakInfo[index].prevRemFileName = gMemLeakInfo[index].fileName;
-
- /*printf("Something is wrong, Trying to double free Address = %x, Index = %d \n",address,index);*/
- }
- else
- {
- printf("Something is wrong, trying to remove %x index = %d from File=%s, line=%d address present is %x\n",address, index, file,line,
- gMemLeakInfo[index].address);
- if(gMemLeakInfo[index].prevRemFileName != NULLP)
- {
- printf("Previous File:%s, Previous Line:%d\n",
- gMemLeakInfo[index].prevRemFileName, gMemLeakInfo[index].prevRemLineNo);
- }
-#if 0
- /* Try removing from some other location where it might have been stored*/
- int i;
- int lastIndex = index + 1;
- Bool removed = FALSE;
- for(i = 2; lastIndex < T2K_MEM_LEAK_INFO_TABLE_SIZE && i < 30; i++)
- {
- if(gMemLeakInfo[lastIndex].address == address)
- {
- gMemLeakInfo[lastIndex].address = 0;
- gMemLeakInfo[lastIndex].size = 0;
- gMemLeakInfo[lastIndex].lineNo = 0;
- gMemLeakInfo[lastIndex].fileName = 0;
- gMemLeakInfo[lastIndex].age = 0; /*For every 16384 memory block allocations,Alloc Tick is incremented by 1*/
- removed = TRUE;
- break;
- }
- lastIndex = index + (i*i*i);
- }
-#if 1
- if(!removed)
- {
- printf("Something is wrong, trying to remove %x index = %d lastIndex = %d FreeCalled from File=%s, line=%d\n",address, index, lastIndex,file,line);
- }
-#endif
-#endif
- }
-}
-
-void DumpT2kMemLeakInfoToFile()
-{
- int i;
-
- FILE *fp = fopen("memLeakInfo.txt","wb");
-
- if(fp == NULL)
- {
- printf("Could not open file for dumping mem leak info\n");
- return;
- }
-
- for(i = 0; i< T2K_MEM_LEAK_INFO_TABLE_SIZE; i++)
- {
- if(gMemLeakInfo[i].address != 0)
- {
- char* onlyFileName = rindex(gMemLeakInfo[i].fileName,'/');
- if(onlyFileName == NULL)
- {
- onlyFileName = gMemLeakInfo[i].fileName;
- }
-
- fprintf(fp, "%p s=%d a=%d l=%d f=%s\n",gMemLeakInfo[i].address,
- gMemLeakInfo[i].size,
- gMemLeakInfo[i].age,
- gMemLeakInfo[i].lineNo,
- onlyFileName);
- }
- }
-
- fprintf(fp,"Current t2kMemAllocTick = %d\n",t2kMemAllocTick);
-
- fclose(fp);
-}
-#endif
-