/* ##C_FILE#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ FILE : CpaMmg.c DESCRIPTION : this file contain all functions used to allocate memory : Initialisation of the module Initialisation of a static bloc switch between dynamic and static mode Allocate/ReAllocate/Free Memory Check function for debugging Destroy a static bloc Destroy the module VERSION : 5.1.0/Pierrick Crepy/Creation ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ /* ##INCLUDE#---------------------------------------------------------------------------- Includes Files ---------------------------------------------------------------------------------------*/ #ifdef U64 #include "ultra.h" #endif/*U64*/ #ifdef WIN32 #include #include #endif /*WIN32*/ #if defined(U64) #include /*for Critical Section : Msg management*/ #elif defined(PSX) #include "PSX.h" #else #include /*for Critical Section*/ #endif /*U64*/ #include "ERM.h" #define __DeclareGlobalVariableErrMmg_h__ #include "MMG/ErrMmg.h" #undef __DeclareGlobalVariableErrMmg_h__ #define __DeclareGlobalVariableInCpaMmg_h__ #include "MMG/CpaMmg.h" #undef __DeclareGlobalVariableInCpaMmg_h__ #include "PrivMmg.h" #include "MMG/RastMmg.h" #if !defined(RETAIL) && !defined(U64) /* This boolean tells if we must fill an allocated bloc */ /* with 0s at each allocation.*/ /* It is set by SNA when making binary datas*/ #include "acp_base.h" ACP_tdxBool MMG_g_bResetMemOnAllocation = FALSE; #endif #ifdef WIN32 #ifdef __DEBUG_MALLOC_MODE__ #include #endif /*__DEBUG_MALLOC_MODE__*/ #endif /*WIN32*/ /*ANNECY CT 21/1/98 {*/ /*XB*/ #if !defined(U64) /*End XB*/ #define malloc(size) GlobalAlloc(GMEM_FIXED,size) #define free(ptr) GlobalFree(ptr) /*XB*/ #endif /* U64*/ /*End XB*/ /*ENDANNECY CT}*/ #ifdef U64 #include "RastMem.h" #include "DesMem.h" #endif /* U64 */ /*///////////// PSX //////////////*/ #ifdef PSX #define malloc malloc3 #define free free3 #define realloc realloc3 /*To resolve a cast problem*/ #define memmove(a,b,c) memmove((unsigned char *)a, (unsigned char *)b, c) /*Undefined prototypes*/ void MMG_PSX_fn_vInitLibrary(); #endif /*PSX*/ /*///////////// PSX //////////////*/ #ifndef M_CheckPointer #define M_CheckPointer(a) #endif /* M_CheckPointer */ /* ##FUNCDEF#---------------------------------------------------------------------------- Functions definition ---------------------------------------------------------------------------------------*/ void * fn_p_vDynAlloc (unsigned long ulSize, unsigned char ucChannel); void fn_vDynFree (void *p_vMemBlock, unsigned char ucChannel); void * fn_p_vDynRealloc (void *p_vMemBlock, unsigned long ulSize, unsigned char ucChannel); void * fn_p_vStaAlloc (unsigned long ulSize, unsigned char ucChannel); void fn_vStaFree (void *p_vMemBlock, unsigned char ucChannel); void * fn_p_vStaRealloc (void *p_vMemBlock, unsigned long ulSize, unsigned char ucChannel); void fn_vSortMallocInfoTable (tdstMallocInfo * p_stMyMallocInfo, unsigned long ulSizeTable); /* ##-########################### ## General Management ############################## */ /* ##F#=================================================================================== NAME : Mmg_fn_cCheckAlignmentValidity DESCRIPTION : check if alignement constant are valide ========================================================================================= CREATION : 06-11-97/Pierrick Crepy =======================================================================================*/ void Mmg_fn_cCheckAlignmentValidity () { #ifdef __DEBUG_MALLOC_MODE__ #ifdef __FATAL_ERR_MMG__ assert((sizeof(unitAlloc)== C_uwAllocSize) && ((1<p_cBeginBlock != C_p_cBlockNotValidKey){ #ifdef __ERROR_STRINGS__ sprintf (szErrTxt, "You have called 'Mmg_fn_vInitBlock' function\nfor the block #%d in [", _ucBlockId); Erm_M_GetModuleInformation(szErrTxt+strlen(szErrTxt), _ucModuleId); sprintf (szErrTxt+strlen(szErrTxt), "].\nBut the 'p_cBeginBlock' field is equal to 0X%X (and not 0X%X like expected)\n", p_stMyBlockInfo->p_cBeginBlock, C_p_cBlockNotValidKey); sprintf (szErrTxt+strlen(szErrTxt), "Do you try to initialized again a block for the second time ?!\n"); #endif /*__ERROR_STRINGS__*/ Mmg_M_UpdateLastError(E_uwMmgPbInvalidBlock, szErrTxt); } #endif /*__FATAL_ERR_MMG__*/ p_stMyBlockInfo->ulMaxNbStaticMalloc = _ulMaxNbStaticMalloc; p_stMyBlockInfo->d_stMallocInfo = (tdstMallocInfo *) malloc (sizeof (tdstMallocInfo)*_ulMaxNbStaticMalloc); if (p_stMyBlockInfo->d_stMallocInfo == NULL){ #ifdef __ERROR_STRINGS__ sprintf (szErrTxt, "The d_stMallocInfo of the BlockInfo for the block #%d of the module #%d [", _ucBlockId, _ucModuleId); Erm_M_GetModuleInformation(szErrTxt+strlen(szErrTxt), _ucModuleId); sprintf (szErrTxt+strlen(szErrTxt), "] is not allocated"); Mmg_M_UpdateLastError(E_uwMmgPbInInitBlock, szErrTxt); #else /*__ERROR_STRINGS__*/ Mmg_M_UpdateLastError(E_uwMmgPbInInitBlock, NULL); #endif /*__ERROR_STRINGS__*/ } #endif /*__DEBUG_MALLOC_MODE__*/ Mmg_M_BigBoundSize (_ulSize, ucAlignment); #ifdef __ADD_PLACE_FOR_DEBUG_INFORMATION__ if (!(_ucMode & C_BlockWithFreeFlag)){/*C_BlockWithFreeFlag*/ ulI = (_ulMaxNbStaticMalloc*(C_ucDebugInformationLoss<p_cBeginBlock = p_cBegin; /*osSyncPrintf("p_stMyBlockInfo->p_cEndBlock : %x ; p_stMyBlockInfo->p_cBeginBlock : %x \n", p_stMyBlockInfo->p_cEndBlock, p_stMyBlockInfo->p_cBeginBlock);*/ /*osSyncPrintf("_ulSize : %d\n", _ulSize);*/ p_stMyBlockInfo->p_cEndBlock = p_cBegin + _ulSize - 1;/*lint !e613 : Possible use of null pointer*/ if (!(_ucMode & C_BlockWithoutFreeFlag)){/*C_BlockWithFreeFlag*/ p_stMyBlockInfo->p_cFirstFree = p_cBegin; p_stMyBlockInfo->p_cMaxMem = p_cBegin; /* init the free list Information in the block.*/ /*----------------------------------------------*/ p_uaPtr = (unitAlloc *) p_cBegin ; *p_uaPtr = (unitAlloc) (_ulSize >> C_uwShiftAllocSize ); /*lint !e613 : Possible use of null pointer */ /* size of the free = size of the block*/ *(p_uaPtr+1) = (unitAlloc) 0;/*lint !e613 : Possible use of null pointer*/ /* there is no sucessor in the free list.*/ #ifdef __DEBUG_MALLOC_MODE__ p_stMyBlockInfo->ulCountMallocBeforeMaxMem = 0; p_stMyBlockInfo->ulCountFreeBeforeMaxMem = 0; p_stMyBlockInfo->ulNbMalloc = 0; p_stMyBlockInfo->ulNbTotalMalloc = 0; p_stMyBlockInfo->uwNbFree = 0; p_stMyBlockInfo->ulNbTotalFree = 0; p_stMyBlockInfo->ulNbTotalRealloc = 0; /* initialisation of the block with the value 0xAA. */ /*-------------------------------------------------*/ /*Remark the bytes of Header of the free are not affected because there are yet well set with free Information*/ for (p_uaPtr = ((unitAlloc*) (p_cBegin)) +C_ucFreeHeaderSize , _ulSize -= (ucAlignment<<1); _ulSize > 0; _ulSize= _ulSize - ucAlignment,p_uaPtr++)/*lint !e613*/{ *p_uaPtr = C_uaCleanKey; } #else if (_ucMode & C_FillTheBlockWithCleanKeyFlag){ for (p_uaPtr = ((unitAlloc*) (p_cBegin)) +C_ucFreeHeaderSize , _ulSize -= (ucAlignment<<1); _ulSize > 0; _ulSize= _ulSize - ucAlignment,p_uaPtr++)/*lint !e613*/{ *p_uaPtr = C_uaCleanKey; } } #endif /*__DEBUG_MALLOC_MODE__*/ }/*C_BlockWithFreeFlag*/ else{/*C_BlockWithoutFreeFlag*/ #ifdef D_CheckSystemForBlockWithoutFree /*YB 21 avril 1998 {*/ unsigned long lTemporaryValue; /*locale variable for after*/ tdstInformationHeaderOfBolckWithoutFree *p_stInfoBlockHeader; p_stMyBlockInfo->p_cMaxMem = p_cBegin+sizeof(tdstInformationHeaderOfBolckWithoutFree); lTemporaryValue = (unsigned long)p_stMyBlockInfo->p_cMaxMem; Mmg_M_BigBoundSize (lTemporaryValue, ucAlignment); p_stMyBlockInfo->p_cMaxMem = (char*)lTemporaryValue; /*YB 21 avril 1998 }*/ p_stMyBlockInfo->p_cMaxMem-=1; #else D_CheckSystemForBlockWithoutFree p_stMyBlockInfo->p_cMaxMem = p_cBegin-1; #endif /*D_CheckSystemForBlockWithoutFree*/ p_stMyBlockInfo->p_cFirstFree = C_FirstFreeValueForBlockWithoutFree; if (_ucMode & C_FillTheBlockWithCleanKeyFlag){ for (p_cBegin = p_stMyBlockInfo->p_cMaxMem+1; p_cBegin <= p_stMyBlockInfo->p_cEndBlock; p_cBegin++){ *p_cBegin = (char)C_uaCleanKeyForBlockWithoutFree; } } #ifdef D_CheckSystemForBlockWithoutFree p_stInfoBlockHeader = (tdstInformationHeaderOfBolckWithoutFree*) p_stMyBlockInfo->p_cBeginBlock; ulI = sizeof(tdstInformationHeaderOfBolckWithoutFree); Mmg_M_BigBoundSize (ulI, ucAlignment); p_stInfoBlockHeader->ucBoundededHeaderSize = (unsigned char) ulI; p_stInfoBlockHeader->ucAlignment = ucAlignment; p_stInfoBlockHeader->ucMode = _ucMode; /*put the OverflowCheckKey*/ if ((p_stMyBlockInfo->p_cEndBlock - p_stMyBlockInfo->p_cMaxMem)>= sizeof (C_TypeOfOverflowCheckKeyForBlockWithoutFree)){/*there is enought space to store the OverflowCheckKey*/ Mmg_fn_vWriteOverflowCheckKey(p_stMyBlockInfo->p_cMaxMem+1); } #endif /*D_CheckSystemForBlockWithoutFree*/ }/*C_BlockWithoutFreeFlag*/ #ifdef __WARNING3_ERR_MMG__ } #endif /* __WARNING3_ERR_MMG__*/ }/*Mmg_fn_vInitSpecificBlock */ /* ##F#=================================================================================== NAME : Mmg_fn_vFreeBlock DESCRIPTION : Re-init bloc variables to free all allocation in the block INPUT : Block Id Module Id Block Structure ========================================================================================= CREATION : 06-11-97/Pierrick Crepy =======================================================================================*/ void Mmg_fn_vFreeBlock (unsigned char ucBlockId, unsigned char ucModuleId, struct tdstBlockInfoPriv_ *p_stMyBlocksInfo){ char * p_cBegin; unitAlloc * p_uaPtr; struct tdstBlockInfoPriv_ *p_stMyBlockInfo = p_stMyBlocksInfo+ucBlockId; #ifdef __DEBUG_MALLOC_MODE__ unsigned long ulSize; #endif /*__DEBUG_MALLOC_MODE__*/ p_cBegin = p_stMyBlockInfo->p_cBeginBlock; #ifdef __DEBUG_MALLOC_MODE__ #ifdef __FATAL_ERR_MMG__ if (p_cBegin == C_p_cBlockNotValidKey){ #ifdef __ERROR_STRINGS__ char szErrTxt[C_ucSizeOfErrTxt]; sprintf (szErrTxt, "You have called 'Mmg_fn_vFreeBlock' function\nfor the block #%d in [", ucBlockId); Erm_M_GetModuleInformation(szErrTxt+strlen(szErrTxt), ucModuleId); sprintf (szErrTxt+strlen(szErrTxt), "].\nAre you sure to have well call 'Mmg_fn_vInitblock' for it ?\n"); Mmg_M_UpdateLastError(E_uwMmgPbInvalidBlock, szErrTxt); #else /*__ERROR_STRINGS__*/ Mmg_M_UpdateLastError(E_uwMmgPbInvalidBlock, NULL); #endif /*__ERROR_STRINGS__*/ } #endif /*__FATAL_ERR_MMG__*/ #endif /*__DEBUG_MALLOC_MODE__*/ if (p_stMyBlockInfo->p_cFirstFree != C_FirstFreeValueForBlockWithoutFree){/*BlockWithFree*/ /* init the free list Information in the block.*/ /*----------------------------------------------*/ p_uaPtr = (unitAlloc *) p_cBegin ; *p_uaPtr = (unitAlloc) (((unitAlloc)(p_stMyBlockInfo->p_cEndBlock - p_cBegin + 1))>> C_uwShiftAllocSize ); /* size of the free = size of the block*/ p_uaPtr ++; *p_uaPtr = (unitAlloc) 0;/* there is no sucessor in the free list.*/ /* record block infomations*/ /*--------------------------*/ p_stMyBlockInfo->p_cFirstFree = p_cBegin; p_stMyBlockInfo->p_cMaxMem = p_cBegin-1; #ifdef __DEBUG_MALLOC_MODE__ p_stMyBlockInfo->ulNbMalloc = 0; p_stMyBlockInfo->ulNbTotalMalloc = 0; p_stMyBlockInfo->uwNbFree = 0;/*added in the MMG V5.0.5*/ p_stMyBlockInfo->ulNbTotalFree = 0; p_stMyBlockInfo->ulNbTotalRealloc = 0; /*added in the MMG V5.0.5*/ /*Remark the first 2 group of C_uwAllocSize bytes (the size of the free & the adresse of the next free) are not affected because there are yet well set with free Information*/ /* !! not already tested*/ ulSize = (unsigned long) ((p_stMyBlockInfo->p_cEndBlock - p_cBegin +1) -(2< 0; ulSize= ulSize - C_uwAllocSize,p_uaPtr++){ *p_uaPtr = C_uaCleanKey; } #endif /*__DEBUG_MALLOC_MODE__*/ }/*BlockWithFree*/ else/* BlockWithoutFree*/ { #ifdef D_CheckSystemForBlockWithoutFree tdstInformationHeaderOfBolckWithoutFree *p_stInfoBlockHeader; p_stInfoBlockHeader = (tdstInformationHeaderOfBolckWithoutFree*) p_cBegin; p_stMyBlockInfo->p_cMaxMem = p_cBegin + p_stInfoBlockHeader->ucBoundededHeaderSize-1; if (p_stInfoBlockHeader->ucMode & C_FillTheBlockWithCleanKeyFlag){ for (p_cBegin = p_stMyBlockInfo->p_cMaxMem+1; p_cBegin <= p_stMyBlockInfo->p_cEndBlock; p_cBegin++){ *p_cBegin = (char) C_uaCleanKeyForBlockWithoutFree; } } /*put the OverflowCheckKey*/ if ((p_stInfoBlockHeader->ucMode & C_Check_OverflowFlag) && (p_stMyBlockInfo->p_cEndBlock - p_stMyBlockInfo->p_cMaxMem)>= sizeof (C_TypeOfOverflowCheckKeyForBlockWithoutFree)){/*there is enought space to store the OverflowCheckKey*/ Mmg_fn_vWriteOverflowCheckKey(p_stMyBlockInfo->p_cMaxMem+1); } #else /*D_CheckSystemForBlockWithoutFree*/ p_stMyBlockInfo->p_cMaxMem = p_cBegin-1; #endif /*D_CheckSystemForBlockWithoutFree*/ } }/*Mmg_fn_vFreeBlock*/ /* ##F#=================================================================================== NAME : Mmg_fn_vDeleteBlock DESCRIPTION : Free Memory and invalidate the block INPUT : Block Id Module Id Block Structure ========================================================================================= CREATION : 06-11-97/Pierrick Crepy =======================================================================================*/ void Mmg_fn_vDeleteBlock (unsigned char ucBlockId, unsigned char ucModuleId, struct tdstBlockInfoPriv_ *p_stMyBlocksInfo){ struct tdstBlockInfoPriv_ *p_stMyBlockInfo = p_stMyBlocksInfo+ucBlockId; #ifdef __DEBUG_MALLOC_MODE__ #ifdef __FATAL_ERR_MMG__ if (p_stMyBlockInfo->p_cBeginBlock == C_p_cBlockNotValidKey){ #ifdef __ERROR_STRINGS__ char szErrTxt[C_ucSizeOfErrTxt]; sprintf (szErrTxt, "You have called 'Mmg_fn_vDeleteBlock' function\nfor the block #%d in [", ucBlockId); Erm_M_GetModuleInformation(szErrTxt+strlen(szErrTxt), ucModuleId); sprintf (szErrTxt+strlen(szErrTxt), "].\nAre you sure to have well call 'Mmg_fn_vInitblock' for it ?\n"); Mmg_M_UpdateLastError(E_uwMmgPbInvalidBlock, szErrTxt); #else /*__ERROR_STRINGS__*/ Mmg_M_UpdateLastError(E_uwMmgPbInvalidBlock, NULL); #endif /*__ERROR_STRINGS__*/ } #endif /*__FATAL_ERR_MMG__*/ #endif /*__DEBUG_MALLOC_MODE__*/ free (p_stMyBlockInfo->p_cBeginBlock); #ifdef __DEBUG_MALLOC_MODE__ free (p_stMyBlockInfo->d_stMallocInfo); p_stMyBlockInfo->d_stMallocInfo = NULL; #endif /*__DEBUG_MALLOC_MODE__*/ p_stMyBlockInfo->p_cBeginBlock = C_p_cBlockNotValidKey; }/*Mmg_fn_vDeleteBlock*/ /* ##-########################### ## DYNAMIC MODE ## kernel of allocation, reallocation & free ############################## */ #ifdef __DYNAMIC_MALLOC_ALLOWED__ /*General*/ /* ##F#=================================================================================== NAME : fn_p_vDynAlloc DESCRIPTION : Allocate a zone (with alignement) on a specif channel Just using malloc function INPUT : Size to allocate Channel Id OUTPUT : Pointer on the allocated zone ========================================================================================= CREATION : 06-11-97/Pierrick Crepy =======================================================================================*/ void * fn_p_vDynAlloc (unsigned long ulSize, unsigned char ucChannel){ #ifdef __DYNAMIC_MALLOC_ALLOWED__ unitAlloc *p_uaMalloc; #ifdef __DEBUG_MALLOC_MODE__ unitAlloc *p_uaPtr; tdstMallocInfo *p_stMyMallocInfo; tdstDynInfo *p_stMyDynInfo = (tdstDynInfo *) g_d_stCurrentModeInfo[ucChannel].p_vTdstBlockInfoOrTdstDynInfo; #endif/* __DEBUG_MALLOC_MODE__*/ #if (defined(__FATAL_ERR_MMG__)||defined (__DEBUG_MALLOC_MODE__)) && (defined(__ERROR_STRINGS__)) char szErrTxt[C_ucSizeOfErrTxt]; #endif /*(defined(__FATAL_ERR_MMG__)||defined (__DEBUG_MALLOC_MODE__)) && (defined(__ERROR_STRINGS__))*/ unsigned long ulMalloc; #if defined(U64) M_PrintfStopErrorN64(("Dynamic Allocation not allowed\n")); #endif /* U64 */ #ifdef _DEBUG #ifdef __FATAL_ERR_MMG__ if (g_ucBLockedAllocation == C_ucTrue){ Mmg_M_UpdateLastErrorWithCurrentModeInfo(E_uwMmgPbAccessMemoryDenied, "Dynamic Allocation : -> denied <-", ucChannel); } #endif /*__FATAL_ERR_MMG__*/ #endif _DEBUG if (ulSize == 0){ /*#ifdef __WARNING3_ERR_MMG__ Mmg_M_UpdateLastErrorWithCurrentModeInfo (E_uwMmgPbSizeOfAllocIs0, NULL, ucChannel); #endif Mmg_MLeaveCriticalSection();*/ return NULL; } Mmg_MEnterCriticalSection(); Mmg_M_BigBoundSize (ulSize, C_uwAllocSize); ulSize >>= C_uwShiftAllocSize; ulSize += (C_ucMallocHeaderSize + C_ucMallocFooterSize); /* place for information(s) to manage the allocation place*/ /* allocation of the Malloc*/ /*-------------------------*/ p_uaMalloc = (unitAlloc *) malloc (ulSize<d_stDynamicMallocInfo + (p_stMyDynInfo->ulNbDynamicMalloc++); if (p_stMyDynInfo->ulNbDynamicMalloc > p_stMyDynInfo->ulMaxNbDynamicMalloc) { #ifdef __ERROR_STRINGS__ sprintf(szErrTxt, "ulNbDynamicMalloc(%d) > ulMaxNbDynamicMalloc (%d)\n", p_stMyDynInfo->ulNbDynamicMalloc, p_stMyDynInfo->ulMaxNbDynamicMalloc); Mmg_M_UpdateLastErrorWithCurrentModeInfo (E_uwMmgPbTooManyAllacation, szErrTxt, ucChannel); #else /*__ERROR_STRINGS__*/ Mmg_M_UpdateLastErrorWithCurrentModeInfo (E_uwMmgPbTooManyAllacation, NULL, ucChannel); #endif /*__ERROR_STRINGS__*/ } p_stMyDynInfo->ulNbTotalDynamicMalloc++; p_stMyMallocInfo->p_cBeginMalloc = (char *) (p_uaMalloc + C_ucMallocHeaderSize); p_stMyMallocInfo->p_cEndMalloc = ((char *) (p_uaMalloc + ulSize - C_ucMallocFooterSize)) - 1; /* initialisation of the malloc with the value 0xAA. */ /*-------------------------------------------------*/ /*Remark the bytes of Header of the free are not affected because there are yet well set with free Information*/ ulSize-= C_ucMallocHeaderSize + C_ucMallocFooterSize; for (p_uaPtr = p_uaMalloc + C_ucMallocHeaderSize; ulSize > 0; ulSize--,p_uaPtr++){ *p_uaPtr = C_uaCleanKey; } #endif /* __DEBUG_MALLOC_MODE__*/ /* return the Alloc adresse*/ /*--------------------------*/ Mmg_MLeaveCriticalSection(); return ( (void *) (p_uaMalloc + C_ucMallocHeaderSize) ); #endif /*__DYNAMIC_MALLOC_ALLOWED__*/ }/*fn_p_cDynAlloc */ /* ================*/ /* ##F#=================================================================================== NAME : fn_vDynFree DESCRIPTION : Free a zone allocated witn dynamic allocation on a specific channel Just using free function INPUT : Pointer on an allocated zone Channel Id ========================================================================================= CREATION : 06-11-97/Pierrick Crepy =======================================================================================*/ void fn_vDynFree (void *p_vMemBlock, unsigned char ucChannel){ #ifdef __DYNAMIC_MALLOC_ALLOWED__ #ifdef __DEBUG_MALLOC_MODE__ tdstMallocInfo *p_stMallocInfo; unsigned char b_ucFound = C_ucFalse; tdstDynInfo *p_stMyDynInfo = (tdstDynInfo *) g_d_stCurrentModeInfo[ucChannel].p_vTdstBlockInfoOrTdstDynInfo; #endif /*__DEBUG_MALLOC_MODE__ */ #if defined(U64) M_PrintfStopErrorN64(("Dynamic DeAllocation not allowed\n")); #endif /* U64 */ #ifdef _DEBUG #ifdef __FATAL_ERR_MMG__ if (g_ucBLockedAllocation == C_ucTrue){ Mmg_M_UpdateLastErrorWithCurrentModeInfo (E_uwMmgPbAccessMemoryDenied, "Dynamic Free : -> denied <-", ucChannel); } #endif /*__FATAL_ERR_MMG__*/ #endif /*_DEBUG*/ Mmg_MEnterCriticalSection(); #ifdef __DEBUG_MALLOC_MODE__ #ifdef __WARNING3_ERR_MMG__ if (p_vMemBlock==NULL){ Mmg_M_UpdateLastErrorWithCurrentModeInfo (E_uwMmgPbFreeofNULL, NULL, ucChannel); } else #endif /*__WARNING3_ERR_MMG__*/ {/* of the else : p_vMemBlock!=NULL*/ /* verification of the validity of the request*/ /*---------------------------------------------*/ /* find the good malloc */ p_stMallocInfo = p_stMyDynInfo->d_stDynamicMallocInfo; while ((p_stMallocInfo < (p_stMyDynInfo->d_stDynamicMallocInfo) + p_stMyDynInfo->ulNbDynamicMalloc) && !b_ucFound){ if (p_stMallocInfo->p_cBeginMalloc == (char *)p_vMemBlock) b_ucFound=C_ucTrue; else p_stMallocInfo ++; } #ifdef __WARNING3_ERR_MMG__ if (!b_ucFound){ #ifdef __ERROR_STRINGS__ char szErrTxt[C_ucSizeOfErrTxt]; sprintf(szErrTxt,"With fn_vDynFree(0X%X)\n", p_vMemBlock); Mmg_M_UpdateLastErrorWithCurrentModeInfo (E_uwMmgPbDynAddressNotValid, szErrTxt, ucChannel); #else /*__ERROR_STRINGS__*/ Mmg_M_UpdateLastErrorWithCurrentModeInfo (E_uwMmgPbDynAddressNotValid, NULL, ucChannel); #endif /*__ERROR_STRINGS__*/ } else #endif /*__WARNING3_ERR_MMG__*/ #endif /*__DEBUG_MALLOC_MODE__ */ {/* of the else: b_ucFound is set*/ /* ==> optimized Free<==*/ /* Free the space*/ /*----------------- */ free (((unitAlloc *)p_vMemBlock) - C_ucMallocHeaderSize); /* if (!VirtualFree (((unitAlloc *)p_vMemBlock) - C_ucMallocHeaderSize, 0, MEM_RELEASE)){ #ifdef __WARNING2_ERR_MMG__ Mmg_M_UpdateLastErrorWithCurrentModeInfo (E_uwMmgPbDynamicFree, NULL, ucChannel); #else ; #endif __WARNING2_ERR_MMG__ } */ /* ==> End of the optimized free<==*/ #ifdef __DEBUG_MALLOC_MODE__ (p_stMyDynInfo->ulNbTotalDynamicFree)++; /* move up all the mallocs remainded*/ /*-----------------------------------*/ for (p_stMallocInfo ++; (p_stMallocInfo < (p_stMyDynInfo->d_stDynamicMallocInfo) + p_stMyDynInfo->ulNbDynamicMalloc); p_stMallocInfo ++){ *(p_stMallocInfo-1) = *p_stMallocInfo; } (p_stMyDynInfo->ulNbDynamicMalloc)--; #endif /*__DEBUG_MALLOC_MODE__*/ }/* of the else: b_ucFound is set*/ #ifdef __DEBUG_MALLOC_MODE__ }/* of the else : p_vMemBlock!=NULL*/ #endif /*__DEBUG_MALLOC_MODE__*/ Mmg_MLeaveCriticalSection(); #endif /*__DYNAMIC_MALLOC_ALLOWED__*/ }/*fn_vDynFree */ /* ===========*/ /* ##F#=================================================================================== NAME : fn_p_vDynRealloc DESCRIPTION : Reallcated a zone allocated witn dynamic allocation on a specific channel Just using realloc function INPUT : Pointer on an allocated zone New Size Channel Id ========================================================================================= CREATION : 06-11-97/Pierrick Crepy =======================================================================================*/ void * fn_p_vDynRealloc (void *p_vMemBlock, unsigned long ulSize, unsigned char ucChannel){ #ifdef __DYNAMIC_MALLOC_ALLOWED__ unitAlloc *p_uaTmp, *p_uaSizeMalloc; long lDiffSize; #ifdef __DEBUG_MALLOC_MODE__ tdstMallocInfo * p_stMyMallocInfo; tdstMallocInfo *p_stMallocInfo; unsigned char b_ucFound = C_ucFalse; tdstDynInfo *p_stMyDynInfo = (tdstDynInfo *) g_d_stCurrentModeInfo[ucChannel].p_vTdstBlockInfoOrTdstDynInfo; #endif /*__DEBUG_MALLOC_MODE__ */ #ifdef _DEBUG #ifdef __FATAL_ERR_MMG__ if (g_ucBLockedAllocation == C_ucTrue){ Mmg_M_UpdateLastErrorWithCurrentModeInfo (E_uwMmgPbAccessMemoryDenied, "Dynamic Reallocation : -> denied <-", ucChannel); } #endif /*__FATAL_ERR_MMG__*/ #endif /*_DEBUG*/ Mmg_MEnterCriticalSection(); #ifdef __DEBUG_MALLOC_MODE__ /* verification of the validity of the request*/ /*---------------------------------------------*/ /* find the good malloc */ p_stMallocInfo = p_stMyDynInfo->d_stDynamicMallocInfo; while ((p_stMallocInfo < (p_stMyDynInfo->d_stDynamicMallocInfo) + (p_stMyDynInfo->ulNbDynamicMalloc)) && !b_ucFound){ if (p_stMallocInfo->p_cBeginMalloc == (char *)p_vMemBlock) b_ucFound=C_ucTrue; else p_stMallocInfo ++; } #ifdef __WARNING3_ERR_MMG__ if (!b_ucFound){ #ifdef __ERROR_STRINGS__ char szErrTxt[C_ucSizeOfErrTxt]; sprintf(szErrTxt,"With fn_p_vDynRealloc(0X%X)\n", p_vMemBlock); Mmg_M_UpdateLastErrorWithCurrentModeInfo (E_uwMmgPbDynAddressNotValid, szErrTxt, ucChannel); #else /*__ERROR_STRINGS__*/ Mmg_M_UpdateLastErrorWithCurrentModeInfo (E_uwMmgPbDynAddressNotValid, NULL, ucChannel); #endif /*__ERROR_STRINGS__*/ } else #endif /*__WARNING3_ERR_MMG__*/ #endif /*__DEBUG_MALLOC_MODE__ */ { /* of the else: b_ucFound is set*/ if (ulSize == 0){ /*it is a free command */ #ifdef __DEBUG_MALLOC_MODE__ (p_stMyDynInfo->ulNbTotalDynamicFree)--;/* this is not a real free requested, then we don't have to increase the counter.*/ #endif /*__DEBUG_MALLOC_MODE__*/ fn_vDynFree (p_vMemBlock, ucChannel); Mmg_MLeaveCriticalSection(); return ((void * )0); } /* here ulsize != 0*/ Mmg_M_BigBoundSize (ulSize, C_uwAllocSize); ulSize >>= C_uwShiftAllocSize; ulSize += (C_ucMallocHeaderSize + C_ucMallocFooterSize); /* place for information(s) to manage the allocation place*/ #ifdef __DEBUG_MALLOC_MODE__ p_stMallocInfo = p_stMyDynInfo->d_stDynamicMallocInfo; #endif /*__DEBUG_MALLOC_MODE__*/ p_uaSizeMalloc = ((unitAlloc *) p_vMemBlock) - C_ucMallocHeaderSize; /* pointer of the real begining (before the header) of the malloc place*/ lDiffSize = (long)(*p_uaSizeMalloc - ulSize); if (lDiffSize == 0){ /* we do not change the size*/ /* ---------- */ Mmg_MLeaveCriticalSection(); return (p_vMemBlock); } else if (lDiffSize >0){ /* we want to reduce the size*/ /* ------*/ ulSize -= (C_ucMallocHeaderSize + C_ucMallocFooterSize); /* place for information(s) to manage the allocation place*/ ulSize <<= C_uwShiftAllocSize; #ifdef __DEBUG_MALLOC_MODE__ (p_stMyDynInfo->ulNbTotalDynamicMalloc)--;/* this is not a real malloc requested, then we don't have to increase the counter.*/ #endif /*__DEBUG_MALLOC_MODE__*/ p_uaTmp = (unitAlloc *) fn_p_vDynAlloc ((ulSize -(C_ucMallocHeaderSize + C_ucMallocFooterSize))<ulNbTotalDynamicFree)--;/* this is not a real free requested, then we don't have to increase the counter.*/ #endif /*__DEBUG_MALLOC_MODE__*/ fn_vDynFree (p_vMemBlock, ucChannel); #ifdef __DEBUG_MALLOC_MODE__ /* store malloc Information*/ /*--------------------------*/ p_uaSizeMalloc = p_uaTmp - C_ucMallocHeaderSize; p_stMyMallocInfo = p_stMyDynInfo->d_stDynamicMallocInfo + p_stMyDynInfo->ulNbDynamicMalloc-1; (p_stMyDynInfo->ulNbTotalDynamicMalloc)++; p_stMyMallocInfo->p_cBeginMalloc = (char *) p_uaTmp; p_stMyMallocInfo->p_cEndMalloc = ((char *) (p_uaSizeMalloc + ulSize - C_ucMallocFooterSize)) - 1; #endif /* __DEBUG_MALLOC_MODE__*/ Mmg_MLeaveCriticalSection(); return ((void *) p_uaTmp); }/* we reduce*/ else { /* we want to increase*/ /* --------*/ lDiffSize = -lDiffSize;/* in order to have a posive value meaning the increasing requested*/ #ifdef __DEBUG_MALLOC_MODE__ (p_stMyDynInfo->ulNbTotalDynamicMalloc)--;/* this is not a real malloc requested, then we don't have to increase the counter.*/ #endif /*__DEBUG_MALLOC_MODE__*/ p_uaTmp = (unitAlloc *) fn_p_vDynAlloc ((ulSize -(C_ucMallocHeaderSize + C_ucMallocFooterSize))<ulNbTotalDynamicFree)--;/* this is not a real free requested, then we don't have to increase the counter.*/ #endif /*__DEBUG_MALLOC_MODE__*/ fn_vDynFree (p_vMemBlock, ucChannel); #ifdef __DEBUG_MALLOC_MODE__ /* store malloc Information*/ /*-------------------------- */ p_uaSizeMalloc = p_uaTmp - C_ucMallocHeaderSize; p_stMyMallocInfo = (p_stMyDynInfo->d_stDynamicMallocInfo) + (p_stMyDynInfo->ulNbDynamicMalloc)-1; (p_stMyDynInfo->ulNbTotalDynamicRealloc)++; p_stMyMallocInfo->p_cBeginMalloc = (char *) p_uaTmp; p_stMyMallocInfo->p_cEndMalloc = ((char *) (p_uaSizeMalloc + ulSize - C_ucMallocFooterSize)) - 1; #endif /* __DEBUG_MALLOC_MODE__*/ Mmg_MLeaveCriticalSection(); return ((void *) p_uaTmp); }/* we increase */ }/* of the else: b_ucFound is set*/ #endif /*__DYNAMIC_MALLOC_ALLOWED__*/ }/*fn_p_vDynRealloc */ /* ================*/ #endif /*__DYNAMIC_MALLOC_ALLOWED__*/ /* ##-########################### ## STATIC MODE ## kernel of allocation, reallocation & free ############################## */ /* ##F#=================================================================================== NAME : fn_p_vStaAlloc DESCRIPTION : Allocate a memory zone in the block specified in the channel Get the first suitable place INPUT : New Size Channel Id OUTPUT : Pointer on the allocated zone ========================================================================================= CREATION : 06-11-97/Pierrick Crepy =======================================================================================*/ void * fn_p_vStaAlloc (unsigned long ulSize, unsigned char ucChannel){ tdstBlockInfoPriv * p_stMyBlockInfo = (tdstBlockInfoPriv *) g_d_stCurrentModeInfo[ucChannel].p_vTdstBlockInfoOrTdstDynInfo; #ifdef __DEBUG_MALLOC_MODE__ tdstMallocInfo *p_stMyMallocInfo; tdstCurrentModeInfo stCurrentModeInfo = g_d_stCurrentModeInfo[ucChannel]; #endif /*__DEBUG_MALLOC_MODE__*/ #ifdef __ERROR_STRINGS__ #if defined(__WARNING3_ERR_MMG__) || defined (__DEBUG_MALLOC_MODE__) char szErrTxt[C_ucSizeOfErrTxt]; #endif/*defined(__WARNING3_ERR_MMG__) || defined (__DEBUG_MALLOC_MODE__)*/ #endif /*__ERROR_STRINGS__*/ #ifdef _DEBUG #ifdef __FATAL_ERR_MMG__ if (g_ucBLockedAllocation == C_ucTrue){ Mmg_M_UpdateLastErrorWithCurrentModeInfo (E_uwMmgPbAccessMemoryDenied, "Static Allocation : -> denied <-", ucChannel); } #endif /*__FATAL_ERR_MMG__*/ #endif /*_DEBUG*/ if (ulSize == 0){ /*#ifdef __WARNING3_ERR_MMG__ Mmg_M_UpdateLastErrorWithCurrentModeInfo (E_uwMmgPbSizeOfAllocIs0, NULL, ucChannel); #endif Mmg_MLeaveCriticalSection();*/ return NULL; } Mmg_MEnterCriticalSection(); /*XB*/ M_CheckPointer(p_stMyBlockInfo); /*End XB*/ if (p_stMyBlockInfo->p_cFirstFree != C_FirstFreeValueForBlockWithoutFree){/*BlockWithFree*/ unitAlloc *p_uaMyFreeSpace; unitAlloc *p_uaBeforeMyFreeSpace; unsigned char b_ucFound = C_ucFalse; Mmg_M_BigBoundSize (ulSize, C_uwAllocSize); ulSize >>= C_uwShiftAllocSize; ulSize += (C_ucMallocHeaderSize + C_ucMallocFooterSize); /* place for information(s) to manage the allocation place*/ /* find the first free enought big.*/ /*---------------------------------*/ p_uaMyFreeSpace = (unitAlloc *) p_stMyBlockInfo->p_cFirstFree; p_uaBeforeMyFreeSpace = p_uaMyFreeSpace; while ((p_uaMyFreeSpace != (unitAlloc *) 0 ) && !b_ucFound){ if ((*p_uaMyFreeSpace)>=(unitAlloc) ulSize){ b_ucFound = C_ucTrue; } else {/* not enought place*/ p_uaBeforeMyFreeSpace = p_uaMyFreeSpace; p_uaMyFreeSpace = (unitAlloc *) *(p_uaMyFreeSpace+1);/* go to next*/ } } if (b_ucFound){ #ifdef __DEBUG_MALLOC_MODE__ #ifdef __ADD_PLACE_FOR_DEBUG_INFORMATION__ #ifdef __WARNING3_ERR_MMG__ /* test of overflow on a block*/ if ( (char *) ( p_uaMyFreeSpace+ (ulSize - ( (p_stMyBlockInfo->ulNbMalloc+1/*+1 pour le courant*/) * C_ucDebugInformationLoss )/* memMax - the place for debug information of all the allocation.*/ ) )-1 > (p_stMyBlockInfo->p_cEndBlock - (p_stMyBlockInfo->ulMaxNbStaticMalloc*(C_ucDebugInformationLoss<ulMaxNbStaticMalloc*C_ucDebugInformationLoss)- ( p_stMyBlockInfo->ulNbMalloc * C_ucDebugInformationLoss))) << C_uwShiftAllocSize, C_szMmgLogFileName); Mmg_M_UpdateLastErrorWithCurrentModeInfo (E_uwMmgPbBLockFull, szErrTxt, ucChannel); #else /*__ERROR_STRINGS__*/ Mmg_M_UpdateLastErrorWithCurrentModeInfo (E_uwMmgPbBLockFull, NULL, ucChannel); #endif /*__ERROR_STRINGS__*/ /*end of the completion of explaination of erors*/ Mmg_MLeaveCriticalSection(); return (NULL); } #endif/*__WARNING3_ERR_MMG__*/ #endif /*__ADD_PLACE_FOR_DEBUG_INFORMATION__*/ #endif /*__DEBUG_MALLOC_MODE__*/ /* use the free place (pointed by p_uaMyFreeSpace)& management of the free list*/ /*------------------------------------------------------------------------------*/ *p_uaMyFreeSpace -= ((unitAlloc) ulSize);/*lint !e613: Possible use of null pointer (p_uaMyFreeSpace)*/ /* the content of the size field is equal of the remain (not used for the allocation)*/ if (*p_uaMyFreeSpace < (unitAlloc) C_ucFreeHeaderSize) /*lint !e613 : Possible use of null pointer (p_uaMyFreeSpace)*/ {/*The remain of the free place is not enougth big to be managned*/ /* we affect all the place of the free to the malloc */ ulSize += (*p_uaMyFreeSpace);/*lint !e613 : Possible use of null pointer (p_uaMyFreeSpace)*/ #ifdef __DEBUG_MALLOC_MODE__ if ((unitAlloc *)(*(p_uaMyFreeSpace + 1))!= (unitAlloc *) 0)/*lint !e613 : Possible use of null pointer (p_uaMyFreeSpace)*/ {/* if it's not the last free (remain)*/ p_stMyBlockInfo->uwNbFree--; /*we have one less free*/ } #endif /* __DEBUG_MALLOC_MODE__*/ /* management of the first free*/ if (p_uaMyFreeSpace == p_uaBeforeMyFreeSpace){/* My free space is the first free*/ p_stMyBlockInfo->p_cFirstFree = (char *) *(p_uaMyFreeSpace + 1);/*lint !e613 : Possible use of null pointer (p_uaMyFreeSpace)*/ } else {/*commom case*/ /* the 'old' free place will become empty (everything is used for the malloc)*/ /* Management of the Free list : the 'next' field of the free place before the free place used, will be affect to the contents of the 'next' field of the free place used */ *(p_uaBeforeMyFreeSpace + 1) = *(p_uaMyFreeSpace + 1);/*lint !e613 : Possible use of null pointer (p_uaMyFreeSpace)*/ } } else {/* management of the remained place after the new alloction.*/ *(p_uaMyFreeSpace+ulSize)= *p_uaMyFreeSpace;/*lint !e613: Possible use of null pointer (p_uaMyFreeSpace)*//* set the 'size' field of remained place*/ /* the 'next' field of the remain is equal to the old next field of the free space used*/ *(p_uaMyFreeSpace+ulSize+1)= *(p_uaMyFreeSpace+1);/*lint !e613: Possible use of null pointer (p_uaMyFreeSpace)*/ /* management of the first free*/ if (p_uaMyFreeSpace == (unitAlloc *) p_stMyBlockInfo->p_cFirstFree)/*lint !e613: Possible use of null pointer (p_uaMyFreeSpace)*/ { p_stMyBlockInfo->p_cFirstFree = (char *) (p_uaMyFreeSpace+ulSize);/*lint !e613: Possible use of null pointer (p_uaMyFreeSpace)*/ } else {/* common case*/ /* the 'next' field of the free place before the free place used, will be affect to the content of the remain of the free place used */ *(p_uaBeforeMyFreeSpace + 1) = (unitAlloc) (p_uaMyFreeSpace + ulSize);/*lint !e613: Possible use of null pointer (p_uaMyFreeSpace)*/ } } /* store malloc Information*/ /*--------------------------*/ *p_uaMyFreeSpace = (unitAlloc)ulSize;/*lint !e613: Possible use of null pointer (p_uaMyFreeSpace)*/ #ifdef __DEBUG_MALLOC_MODE__ *(p_uaMyFreeSpace + 1) = C_uaBeginKey;/*lint !e613: Possible use of null pointer (p_uaMyFreeSpace)*/ *(p_uaMyFreeSpace + ulSize -1) = C_uaEndKey;/*lint !e613: Possible use of null pointer (p_uaMyFreeSpace)*/ p_stMyMallocInfo = p_stMyBlockInfo->d_stMallocInfo + (p_stMyBlockInfo->ulNbMalloc)++; if (p_stMyBlockInfo->ulNbMalloc > p_stMyBlockInfo->ulMaxNbStaticMalloc) { #ifdef __ERROR_STRINGS__ sprintf(szErrTxt, "ulNbMalloc(%d) > ulMaxNbStaticMalloc (%d)\n", p_stMyBlockInfo->ulNbMalloc, p_stMyBlockInfo->ulMaxNbStaticMalloc); Mmg_M_UpdateLastErrorWithCurrentModeInfo (E_uwMmgPbTooManyAllacation, szErrTxt, ucChannel); #else /*__ERROR_STRINGS__*/ Mmg_M_UpdateLastErrorWithCurrentModeInfo (E_uwMmgPbTooManyAllacation, NULL, ucChannel); #endif /*__ERROR_STRINGS__*/ } p_stMyMallocInfo->p_cBeginMalloc = (char *) (p_uaMyFreeSpace + C_ucMallocHeaderSize);/*lint !e613: Possible use of null pointer (p_uaMyFreeSpace)*/ p_stMyMallocInfo->p_cEndMalloc = ((char *) (p_uaMyFreeSpace + ulSize - C_ucMallocFooterSize)) - 1;/*lint !e613: Possible use of null pointer (p_uaMyFreeSpace)*/ #endif /* __DEBUG_MALLOC_MODE__*/ if ((char *)(p_uaMyFreeSpace+ *p_uaMyFreeSpace) -1 >=p_stMyBlockInfo->p_cMaxMem)/*lint !e613: Possible use of null pointer (p_uaMyFreeSpace)*/ { /* Managemement of the mem max information in order to be able to compute an estination of the optimzed version*/ p_stMyBlockInfo->p_cMaxMem=(char *)(p_uaMyFreeSpace+ *p_uaMyFreeSpace)-1;/*lint !e613: Possible use of null pointer (p_uaMyFreeSpace)*/ #ifdef __DEBUG_MALLOC_MODE__ p_stMyBlockInfo->ulCountMallocBeforeMaxMem = p_stMyBlockInfo->ulNbMalloc; p_stMyBlockInfo->ulCountFreeBeforeMaxMem = p_stMyBlockInfo->uwNbFree; #endif /* __DEBUG_MALLOC_MODE__ */ #ifdef __ADD_PLACE_FOR_DEBUG_INFORMATION__ #ifdef __WARNING3_ERR_MMG__ if ( ( p_stMyBlockInfo->ulNbMalloc ) > p_stMyBlockInfo->ulMaxNbStaticMalloc ) { #ifdef __ERROR_STRINGS__ sprintf(szErrTxt, "ulNbMalloc(%d) > ulMaxNbStaticMalloc (%d)\n", p_stMyBlockInfo->ulNbMalloc, p_stMyBlockInfo->ulMaxNbStaticMalloc); Mmg_M_UpdateLastErrorWithCurrentModeInfo (E_uwMmgPbSpaceForDebugInformationIsFull, szErrTxt, ucChannel); #else /*__ERROR_STRINGS__*/ Mmg_M_UpdateLastErrorWithCurrentModeInfo (E_uwMmgPbSpaceForDebugInformationIsFull, NULL, ucChannel); #endif /*__ERROR_STRINGS__*/ } #endif /*__WARNING3_ERR_MMG__*/ #endif /*__ADD_PLACE_FOR_DEBUG_INFORMATION__*/ }/* Managemement of the mem max information */ #ifdef __DEBUG_MALLOC_MODE__ p_stMyBlockInfo->ulNbTotalMalloc++; #endif /* __DEBUG_MALLOC_MODE__*/ /* return the Alloc adresse*/ /*--------------------------*/ Mmg_MLeaveCriticalSection(); return ( (void *) (p_uaMyFreeSpace + C_ucMallocHeaderSize) );/*lint !e613: Possible use of null pointer (p_uaMyFreeSpace)*/ } else{ #ifdef __WARNING3_ERR_MMG__ #ifdef __DEBUG_MALLOC_MODE__ #ifdef __ERROR_STRINGS__ sprintf (szErrTxt, "there is no free space enougth big (i.e. %db)\n,even with the 'added debug information' memory\n", (ulSize - C_ucDebugInformationLoss)<p_cBeginBlock; /*#define Mmg_M_BigBoundSize(ulSize, ucAlignment)*/ /* if ( (ulSize) & (unsigned long)((p_stInfoHeaderBolck->ucAlignment)-1)) { (ulSize) = ((ulSize) & (~((unsigned long)((p_stInfoHeaderBolck->ucAlignment)-1)))) + (p_stInfoHeaderBolck->ucAlignment); }*/ Mmg_M_BigBoundSize (ulSize, p_stInfoHeaderBolck->ucAlignment);/* added to be shure that the alignment is Ok*/ #endif /*D_CheckSystemForBlockWithoutFree*/ /* compute the real remain;*/ ulI = p_stMyBlockInfo->p_cEndBlock-p_stMyBlockInfo->p_cMaxMem; if (ulSize > ulI) { #ifdef __WARNING3_ERR_MMG__ #ifdef __ERROR_STRINGS__ sprintf(szErrTxt, "the is not enought memory(%db) for the allocation size requested (%d)\n", ulI, ulSize); Mmg_M_UpdateLastErrorWithCurrentModeInfo (E_uwMmgPbBLockFull, szErrTxt, ucChannel); #else /*__ERROR_STRINGS__*/ Mmg_M_UpdateLastErrorWithCurrentModeInfo (E_uwMmgPbBLockFull, NULL, ucChannel); #endif /*__ERROR_STRINGS__*/ #endif /*__WARNING3_ERR_MMG__*/ Mmg_MLeaveCriticalSection(); return (NULL); } #ifdef D_CheckSystemForBlockWithoutFree /* the check overflow key just after the p_cMaxMem*/ if ((p_stInfoHeaderBolck->ucMode & C_Check_OverflowFlag) && (ulI >= sizeof (C_TypeOfOverflowCheckKeyForBlockWithoutFree)) && /*there is enought space to store the remain*/ (!Mmg_fn_b_cIsItEqualToOverflowCheckKey(p_stMyBlockInfo->p_cMaxMem+1)) ) { #ifdef U64 M_PrintfN64(("E_uwMmgPbOverFlowBeforeOnTheRemainTag: p_cMaxMem+1=0X%X\n", p_stMyBlockInfo->p_cMaxMem+1)); #endif /*U64*/ #ifdef __ERROR_STRINGS__ sprintf(szErrTxt, "The key expexted should be 0X%X, but we have 0X%X\n",C_ulOverflowCheckKey, (*(C_TypeOfOverflowCheckKeyForBlockWithoutFree *)(p_stMyBlockInfo->p_cMaxMem+1))); Mmg_M_UpdateLastErrorWithCurrentModeInfo (E_uwMmgPbOverFlowBeforeOnTheRemainTag, szErrTxt, ucChannel); #else /*__ERROR_STRINGS__*/ Mmg_M_UpdateLastErrorWithCurrentModeInfo (E_uwMmgPbOverFlowBeforeOnTheRemainTag, NULL, ucChannel); #endif /*__ERROR_STRINGS__*/ } /* if needed (C_FillTheBlockWithCleanKeyFlag), erase the old key by */ if (p_stInfoHeaderBolck->ucMode & C_FillTheBlockWithCleanKeyFlag){ char * p_cTmp; for (p_cTmp = p_stMyBlockInfo->p_cMaxMem+1; (p_cTmp <= p_stMyBlockInfo->p_cMaxMem+sizeof(C_TypeOfOverflowCheckKeyForBlockWithoutFree)) && (p_cTmp <= p_stMyBlockInfo->p_cEndBlock); p_cTmp++){ *p_cTmp = (char)C_uaCleanKeyForBlockWithoutFree; } } /* check the alignment*/ if (p_stInfoHeaderBolck->ucMode & C_Check_AlignementFlag){ ulI = ulSize; Mmg_M_BigBoundSize (ulSize, p_stInfoHeaderBolck->ucAlignment); if (ulI != ulSize) { #ifdef U64 M_PrintfN64(("E_uwMmgPbAlignmentAllocationRequested: %d [%d]--> %d\n", ulI, p_stInfoHeaderBolck->ucAlignment, ulSize)); #endif /*U64*/ #ifdef __ERROR_STRINGS__ sprintf(szErrTxt, "the size requested (%d) is not a multiple of the alignment(%d)\n", ulI, p_stInfoHeaderBolck->ucAlignment); Mmg_M_UpdateLastErrorWithCurrentModeInfo (E_uwMmgPbAlignmentAllocationRequested, szErrTxt, ucChannel); #else /*__ERROR_STRINGS__*/ Mmg_M_UpdateLastErrorWithCurrentModeInfo (E_uwMmgPbAlignmentAllocationRequested, NULL, ucChannel); #endif /*__ERROR_STRINGS__*/ } }/*C_Check_AlignementFlag*/ #endif /*D_CheckSystemForBlockWithoutFree*/ /*save the adresse of the return pointer in ulI*/ ulI = (unsigned long) p_stMyBlockInfo->p_cMaxMem + 1; p_stMyBlockInfo->p_cMaxMem += ulSize; #ifdef D_CheckSystemForBlockWithoutFree /*Store the overflow key check*/ if ((p_stMyBlockInfo->p_cEndBlock - p_stMyBlockInfo->p_cMaxMem) >= sizeof(C_TypeOfOverflowCheckKeyForBlockWithoutFree)){/*there is enought space to store the OverflowCheckKey*/ Mmg_fn_vWriteOverflowCheckKey(p_stMyBlockInfo->p_cMaxMem+1); } #endif /*D_CheckSystemForBlockWithoutFree*/ Mmg_MLeaveCriticalSection(); return ((void*) ulI); /* return (NULL);*/ }/*BlockWithoutFree*/ }/*fn_p_cStaAlloc */ /* ================*/ /* ##F#=================================================================================== NAME : fn_vStaFree DESCRIPTION : Free a memory zone in the block specified in the channel append with the previous and next zone if possible INPUT : Pointer on an allocated zone Channel Id ========================================================================================= CREATION : 06-11-97/Pierrick Crepy =======================================================================================*/ void fn_vStaFree (void *p_vMemBlock, unsigned char ucChannel){ /* ===========*/ #ifdef __DEBUG_MALLOC_MODE__ unsigned char b_ucFound = C_ucFalse; tdstMallocInfo * p_stMallocInfo; unsigned short uwNbCreatedFree = 1;/*the common case (without any join), we create 1 new free*/ #endif/*__DEBUG_MALLOC_MODE__*/ tdstBlockInfoPriv * p_stMyBlockInfo = (tdstBlockInfoPriv *) g_d_stCurrentModeInfo[ucChannel].p_vTdstBlockInfoOrTdstDynInfo; unitAlloc * p_uaNextFree; unitAlloc * p_uaSizeMalloc; unitAlloc *p_uaAfterFreeSpace; unitAlloc *p_uaBeforeFreeSpace; /* Oliv' - Portage v15 - Blindage pour éviter les trucs genre GAM_Malloc -> TMP_Free !!*/ #ifndef RETAIL if (((char*)p_vMemBlock) < p_stMyBlockInfo->p_cBeginBlock || ((char*)p_vMemBlock)>p_stMyBlockInfo->p_cEndBlock) { Mmg_M_UpdateLastErrorWithCurrentModeInfo (E_uwMmgPbStaAddressNotValid, NULL, ucChannel); #ifdef U64 M_PrintfStopErrorN64(("Deallocating memory not in the right block !!!\n")); #endif } #endif /*RETAIL*/ /* EndOfOliv'*/ #ifdef _DEBUG #ifdef __FATAL_ERR_MMG__ if (g_ucBLockedAllocation == C_ucTrue){ Mmg_M_UpdateLastErrorWithCurrentModeInfo (E_uwMmgPbAccessMemoryDenied, "Static Free : -> denied <-", ucChannel); } #endif /*__FATAL_ERR_MMG__*/ #endif /*_DEBUG*/ #ifdef D_CheckSystemForBlockWithoutFree if (p_stMyBlockInfo->p_cFirstFree == C_FirstFreeValueForBlockWithoutFree){ Mmg_M_UpdateLastError(E_uwMmgPbNoAvailableFunctionForBlockWithoutFree, NULL) } #endif /*D_CheckSystemForBlockWithoutFree*/ Mmg_MEnterCriticalSection(); #ifdef __DEBUG_MALLOC_MODE__ #ifdef __WARNING3_ERR_MMG__ if (p_vMemBlock==NULL){ Mmg_M_UpdateLastErrorWithCurrentModeInfo (E_uwMmgPbFreeofNULL, NULL, ucChannel); } else #endif /*__WARNING3_ERR_MMG__*/ {/* of the else : p_vMemBlock!=NULL*/ p_stMallocInfo = p_stMyBlockInfo->d_stMallocInfo; /* verification of the validity of the request*/ /*---------------------------------------------*/ /* find the good malloc */ while ((p_stMallocInfo < p_stMyBlockInfo->d_stMallocInfo + (p_stMyBlockInfo->ulNbMalloc)) && !b_ucFound){ if (p_stMallocInfo->p_cBeginMalloc == (char *)p_vMemBlock) b_ucFound=C_ucTrue; else p_stMallocInfo ++; } #ifdef __WARNING3_ERR_MMG__ if (!b_ucFound){ #ifdef __ERROR_STRINGS__ char szErrTxt[C_ucSizeOfErrTxt]; sprintf (szErrTxt, "With fn_vStaFree(0X%X)\n", p_vMemBlock); Mmg_M_UpdateLastErrorWithCurrentModeInfo (E_uwMmgPbStaAddressNotValid, szErrTxt, ucChannel); #else /*__ERROR_STRINGS__*/ Mmg_M_UpdateLastErrorWithCurrentModeInfo (E_uwMmgPbStaAddressNotValid, NULL, ucChannel); #endif /*__ERROR_STRINGS__*/ } else #endif /* __WARNING3_ERR_MMG__*/ {/* ofthe else : b_ucfound is set*/ #endif /*__DEBUG_MALLOC_MODE__*/ /* Management of the free list*/ /*-----------------------------*/ /* Goal: We want the sort list of free, then we insert the new free space between the (2) contiguous free space.*/ /* look for the rigth place.*/ p_uaBeforeFreeSpace = p_uaAfterFreeSpace = (unitAlloc *) p_stMyBlockInfo->p_cFirstFree; while ((p_uaAfterFreeSpace != (unitAlloc *) 0 ) && (p_uaAfterFreeSpace < (unitAlloc *) p_vMemBlock) ){ p_uaBeforeFreeSpace = p_uaAfterFreeSpace; #ifdef CHECK_MEMORY if(p_uaAfterFreeSpace==((unitAlloc *) p_vMemBlock) - C_ucMallocHeaderSize) { osSyncPrintf("Bouclage : always a Free de %x\n",(unsigned long)p_vMemBlock); fn_vDebug(); } if(p_uaAfterFreeSpace==(unitAlloc *) *(p_uaAfterFreeSpace+1)) { osSyncPrintf("Bouclage : Free de %x\n",(unsigned long)p_vMemBlock); fn_vDebug(); } #endif p_uaAfterFreeSpace = (unitAlloc *) *(p_uaAfterFreeSpace+1);/* go to next*/ } /* here p_uaAfterFreeSpace point at the free space just after & p_uaBeforeFreeSpace that is just before*/ /* general case:*/ /* | Free | (...) | allocation | (...) | Free |*/ /* ^-- p_uaBeforeFreeSpace ^-- p_vMemBlock ^-- p_uaAfterFreeSpace*/ /* set information for the new free space*/ /* size of the free block is the same that the size of malloc block at the begining at adresse [ ((unitAlloc) p_vMemBlock) - C_ucMallocHeaderSize ]*/ /* mamnagement of the next field of the list */ /*p_uaNextFree points at the 'next' field of my new free place*/ p_uaNextFree = ((unitAlloc *) p_vMemBlock) - C_ucMallocHeaderSize + 1;/*1 to junp the size field (of the free place) in order point at the next field*/ p_uaSizeMalloc = ((unitAlloc *) p_vMemBlock) - C_ucMallocHeaderSize; /* ptr of the real begining (before the header) of the malloc place*/ if (p_uaBeforeFreeSpace == p_uaAfterFreeSpace) {/*my new free space will become the first element of the free list*/ /* Management of joining with the old first free space after my new free*/ if ( (p_uaSizeMalloc + *p_uaSizeMalloc) == p_uaAfterFreeSpace ){ /*my new free space and the old first free space have to be joined with thz free space just after because the end of my new free space =begining of the first free space */ /* ----------- ---------------- */ *(p_uaNextFree-1) = *(p_uaNextFree-1) + *p_uaAfterFreeSpace;/*lint !e613: Possible use of null pointer (p_uaMyFreeSpace)*/ /*the 'size' field of my new free space must be added with the content of 'size' field of my joined free space */ *p_uaNextFree = *(p_uaAfterFreeSpace + 1);/*lint !e613: Possible use of null pointer (p_uaMyFreeSpace)*/ /* the 'next' field of my new free space is equal to the 'next' field of my old first free space*/ #ifdef __DEBUG_MALLOC_MODE__ /* clean the area of the old free, i.e. the Header of the Free just after*/ *p_uaAfterFreeSpace = C_uaCleanKey;/*lint !e613: Possible use of null pointer (p_uaMyFreeSpace)*/ /* the FreeSize field*/ *(p_uaAfterFreeSpace+1) = C_uaCleanKey;/*lint !e613: Possible use of null pointer (p_uaMyFreeSpace)*//* the field of the adress of the next free*/ uwNbCreatedFree--;/*we have join 2 free together*/ #endif /*__DEBUG_MALLOC_MODE__ */ } else{ /* common case : no need to join*/ *p_uaNextFree = (unitAlloc) p_uaAfterFreeSpace; } /*The begining of the new free space.*/ p_stMyBlockInfo->p_cFirstFree = (char *) (((unitAlloc *) p_vMemBlock) - C_ucMallocHeaderSize); } else {/* common case: insert the new fre space between p_uaBeforeFreeSpace & p_uaAfterFreeSpace.*/ /* Management of joining with the free space just after my new free space*/ if ( (p_uaSizeMalloc + *p_uaSizeMalloc) == p_uaAfterFreeSpace ){/*my new free space and the free space just after have to be joined because the end of my new free space = begining of the free space after*/ *(p_uaNextFree-1) = *(p_uaNextFree-1) + *p_uaAfterFreeSpace;/*lint !e613: Possible use of null pointer (p_uaMyFreeSpace)*/ /*the 'size' field of my new free space must be added with the content of 'size' field of my joined free space */ *p_uaNextFree = *(p_uaAfterFreeSpace + 1);/*lint !e613: Possible use of null pointer (p_uaMyFreeSpace)*/ /* the 'next' field of my new free space is equal to the 'next' field of the free space just after*/ #ifdef __DEBUG_MALLOC_MODE__ /* clean the area of the old free, i.e. the Header of the Free just after*/ *p_uaAfterFreeSpace = C_uaCleanKey;/*lint !e613: Possible use of null pointer (p_uaMyFreeSpace)*/ /* the FreeSize field*/ *(p_uaAfterFreeSpace+1) = C_uaCleanKey;/*lint !e613: Possible use of null pointer (p_uaMyFreeSpace)*/ /* the field of the adress of the next free*/ uwNbCreatedFree--;/*we have join 2 free together*/ #endif /*__DEBUG_MALLOC_MODE__ */ } else {/* no need to join my free space with the free space just after*/ *p_uaNextFree = *(p_uaBeforeFreeSpace +1);/*the 'next' field of my free space is equal to the contents of the next field of the fre space just before it*/ } /* Management of joining with the free space just before my new free space*/ if ( (p_uaBeforeFreeSpace + *p_uaBeforeFreeSpace) == p_uaSizeMalloc ){/*my new free space and the free space just before have to be joined because the end of the free space before = begining of my new free space*/ *(p_uaBeforeFreeSpace) =*(p_uaBeforeFreeSpace) + *(p_uaNextFree-1);/*the 'size' field of the free space just before must be added with the content of 'size' field of my new free space */ *(p_uaBeforeFreeSpace +1) = *p_uaNextFree;/* the 'next' field of the free space just before is equal to the 'next' field of my new free space*/ #ifdef __DEBUG_MALLOC_MODE__ /* clean the area the Header of the new Free located at the old allocation*/ *p_uaSizeMalloc = C_uaCleanKey;/* the FreeSize field*/ *(p_uaSizeMalloc+1) = C_uaCleanKey;/* the field of the adress of the next free*/ uwNbCreatedFree--;/*we have join 2 free together*/ /* code only used for clean the new free area.*/ /* this is the only case where the begining of the new free space change (not equal to p_vMemBlock), then we have to set p_vMemblock in order to point on the right place*/ /* a supprimer p_vMemBlock = (void *) (p_uaBeforeFreeSpace + C_ucMallocHeaderSize);*/ #endif /*__DEBUG_MALLOC_MODE__*/ } else{/* no need to join my free space with the free space just before*/ *(p_uaBeforeFreeSpace +1) = (unitAlloc)(((unitAlloc*) p_vMemBlock) - C_ucMallocHeaderSize);/*the contents of the next field just before my new free space must be equal to the adresse of my new free space.*/ } } #ifdef __DEBUG_MALLOC_MODE__ /* clean the area of the new free. we use the variable p_uaNextFree for scan the memory & p_uaAfterfreespace for the end of the free area.*/ for ( p_uaNextFree = ((unitAlloc *) p_stMallocInfo->p_cBeginMalloc); p_uaNextFree < ((unitAlloc *) p_stMallocInfo->p_cEndMalloc) + 1 /*for the ending key*/; p_uaNextFree++ ){ *p_uaNextFree = C_uaCleanKey; } /* move up all the mallocs remainded*/ /*-----------------------------------*/ for (p_stMallocInfo ++; (p_stMallocInfo < p_stMyBlockInfo->d_stMallocInfo + (p_stMyBlockInfo->ulNbMalloc)); p_stMallocInfo ++){ *(p_stMallocInfo-1) = *p_stMallocInfo; } (p_stMyBlockInfo->ulNbMalloc) --; p_stMyBlockInfo->ulNbTotalFree++; p_stMyBlockInfo->uwNbFree+= uwNbCreatedFree; }/* ofthe else : b_ucfound is set*/ }/* of the else : p_vMemBlock!=NULL*/ #endif /*__DEBUG_MALLOC_MODE__ */ Mmg_MLeaveCriticalSection(); }/* fn_vStaFree */ /* ===========*/ /* ##F#=================================================================================== NAME : fn_p_vStaRealloc DESCRIPTION : Realloc a memory zone in the block specified in the channel always try to allocated at a lower address INPUT : Pointer on an allocated zone New Size Channel Id OUTPUT : Pointeur on the new zone ========================================================================================= CREATION : 06-11-97/Pierrick Crepy =======================================================================================*/ void * fn_p_vStaRealloc (void *p_vMemBlock, unsigned long ulSize, unsigned char ucChannel){ /* ================*/ #ifdef __DEBUG_MALLOC_MODE__ tdstMallocInfo * p_stMallocInfo; tdstMallocInfo *p_stMyMallocInfo; unsigned long ulMyNbMalloc; tdstCurrentModeInfo stCurrentModeInfo = g_d_stCurrentModeInfo[ucChannel]; #ifdef __ERROR_STRINGS__ char szErrTxt[C_ucSizeOfErrTxt]; #endif /*__ERROR_STRINGS__*/ #endif/*__DEBUG_MALLOC_MODE__*/ tdstBlockInfoPriv * p_stMyBlockInfo = (tdstBlockInfoPriv *) g_d_stCurrentModeInfo[ucChannel].p_vTdstBlockInfoOrTdstDynInfo; unitAlloc * p_uaTmp;/*temporary pointer: if we reduce the allocation p_uaTmp=pointer at the new free space. // !! voir a renomer*/ unitAlloc * p_uaSizeMalloc; unitAlloc *p_uaBeforeBeforeFreeSpace; unitAlloc *p_uaBeforeFreeSpace; unitAlloc *p_uaAfterFreeSpace; unitAlloc *p_uaAfterAfterFreeSpace; unitAlloc uaBeforeFreeSize, uaAfterFreeSize;/* size of the free space just before & after the allocation. 0 meaning there are not adjacent to the malloc*/ long lDiffSize;/* difference between the actual size and the size requested (ulSize) */ unsigned char b_ucFound = C_ucFalse; #ifdef _DEBUG #ifdef __FATAL_ERR_MMG__ if (g_ucBLockedAllocation == C_ucTrue){ Mmg_M_UpdateLastErrorWithCurrentModeInfo (E_uwMmgPbAccessMemoryDenied, "Static Reallocation : -> denied <-", ucChannel); } #endif /*__FATAL_ERR_MMG__*/ #endif /*_DEBUG*/ #ifdef D_CheckSystemForBlockWithoutFree if (p_stMyBlockInfo->p_cFirstFree == C_FirstFreeValueForBlockWithoutFree){ Mmg_M_UpdateLastError(E_uwMmgPbNoAvailableFunctionForBlockWithoutFree, NULL) } #endif /*D_CheckSystemForBlockWithoutFree*/ Mmg_MEnterCriticalSection(); #ifdef __DEBUG_MALLOC_MODE__ p_stMallocInfo = p_stMyBlockInfo->d_stMallocInfo; /* verification of the validity of the request & find the ulMyNbMalloc*/ /*---------------------------------------------------------------------*/ /* find the good malloc ulMyNbMalloc*/ ulMyNbMalloc = 0; while ((p_stMallocInfo < p_stMyBlockInfo->d_stMallocInfo + (p_stMyBlockInfo->ulNbMalloc)) && !b_ucFound){ if (p_stMallocInfo->p_cBeginMalloc == (char *)p_vMemBlock) b_ucFound=C_ucTrue; else { p_stMallocInfo ++; ulMyNbMalloc++; } } #ifdef __WARNING3_ERR_MMG__ if (!b_ucFound){ #ifdef __ERROR_STRINGS__ sprintf (szErrTxt, "With fn_vStaRealloc(0X%X)\n", p_vMemBlock); Mmg_M_UpdateLastErrorWithCurrentModeInfo (E_uwMmgPbStaAddressNotValid, szErrTxt, ucChannel); #else /*__ERROR_STRINGS__*/ Mmg_M_UpdateLastErrorWithCurrentModeInfo (E_uwMmgPbStaAddressNotValid, NULL, ucChannel); #endif /*__ERROR_STRINGS__*/ } else #endif /* __WARNING3_ERR_MMG__*/ #endif /*__DEBUG_MALLOC_MODE__*/ {/* of the else b_ucFound is set*/ if (ulSize == 0){ /*it is a free command */ #ifdef __DEBUG_MALLOC_MODE__ (p_stMyBlockInfo->ulNbTotalFree)--;/* this is not a real free requested, then we don't have to increase the counter. */ #endif /*__DEBUG_MALLOC_MODE__*/ fn_vStaFree (p_vMemBlock, ucChannel); Mmg_MLeaveCriticalSection(); return ((void * )0); } Mmg_M_BigBoundSize (ulSize, C_uwAllocSize); ulSize >>= C_uwShiftAllocSize; ulSize += (C_ucMallocHeaderSize + C_ucMallocFooterSize); /* place for information(s) to manage the allocation place*/ p_uaSizeMalloc = ((unitAlloc *) p_vMemBlock) - C_ucMallocHeaderSize; /* pointer of the real begining (before the header) of the malloc place*/ lDiffSize = (long)(*p_uaSizeMalloc - ulSize); /*check if there is a space enought big to receive the allocation before p_vMemblock*/ /*----- ----------------- ------------------*/ p_uaBeforeBeforeFreeSpace = p_uaBeforeFreeSpace = (unitAlloc *) p_stMyBlockInfo->p_cFirstFree; b_ucFound = C_ucFalse; while ((p_uaBeforeFreeSpace != (unitAlloc *) 0 ) && (p_uaBeforeFreeSpace < p_uaSizeMalloc) && !b_ucFound ){ if ((*p_uaBeforeFreeSpace)>=(unitAlloc) ulSize){ b_ucFound = C_ucTrue; } else {/* not enought place*/ p_uaBeforeBeforeFreeSpace = p_uaBeforeFreeSpace; p_uaBeforeFreeSpace = (unitAlloc *) *(p_uaBeforeFreeSpace+1);/* go to next*/ } } if (b_ucFound){ /* we can move up */ /* -------*/ ulSize -= (C_ucMallocHeaderSize + C_ucMallocFooterSize); /* place for information(s) to manage the allocation place*/ ulSize <<= C_uwShiftAllocSize; #ifdef __DEBUG_MALLOC_MODE__ p_stMyBlockInfo->ulNbTotalMalloc--;/* this is not a real malloc requested, then we don't have to increase the counter.*/ #endif /*__DEBUG_MALLOC_MODE__*/ p_uaTmp = (unitAlloc *) fn_p_vStaAlloc (ulSize, ucChannel); memcpy ((void *) p_uaTmp, p_vMemBlock, ulSize); #ifdef __DEBUG_MALLOC_MODE__ p_stMyBlockInfo->ulNbTotalFree--;/* this is not a real free requested, then we don't have to increase the counter.*/ #endif /*__DEBUG_MALLOC_MODE__*/ fn_vStaFree (p_vMemBlock, ucChannel); #ifdef __DEBUG_MALLOC_MODE__ /* the free have move up all the elt after the freed malloc of the Malloc info Table*/ /* then we have to use the last elt of the malloc info table*/ ulMyNbMalloc= (unsigned short) (p_stMyBlockInfo->ulNbMalloc -1); #endif /*__DEBUG_MALLOC_MODE__*/ #ifdef __DEBUG_MALLOC_MODE__ p_stMyBlockInfo->ulNbTotalRealloc++; p_vMemBlock = p_uaTmp; #endif /* __DEBUG_MALLOC_MODE__*/ p_uaSizeMalloc = p_uaTmp - C_ucMallocHeaderSize; if ((char*)(p_uaSizeMalloc + *p_uaSizeMalloc)-1>=p_stMyBlockInfo->p_cMaxMem){ /* Managemement of the mem max information i order to be able to compute an estination of the optimzed version*/ p_stMyBlockInfo->p_cMaxMem=(char*)(p_uaSizeMalloc + *p_uaSizeMalloc)-1; #ifdef __DEBUG_MALLOC_MODE__ p_stMyBlockInfo->ulCountMallocBeforeMaxMem = p_stMyBlockInfo->ulNbMalloc; p_stMyBlockInfo->ulCountFreeBeforeMaxMem = p_stMyBlockInfo->uwNbFree; #endif /* __DEBUG_MALLOC_MODE__*/ } /* not necessary #ifdef __DEBUG_MALLOC_MODE__ // count the real number of free p_uaTmp = (unitAlloc*)p_stMyBlockInfo->p_cFirstFree; for (uwI=0; *(p_uaTmp+1) != (unitAlloc)0; uwI++, p_uaTmp = (unitAlloc *) *(p_uaTmp+1)); p_stMyBlockInfo->uwNbFree = uwI; p_uaTmp = p_vMemBlock; #endif __DEBUG_MALLOC_MODE__ */ Mmg_MLeaveCriticalSection(); return ((void *) p_uaTmp); /* -------*/ }/* end of move up*/ /* inplice else because there is an return just before in the if*/ /* common algorithm */ /* Verify if there is any free space just after or before the actual malloc*/ /* ------ ---- --------------------- */ p_uaBeforeBeforeFreeSpace = p_uaBeforeFreeSpace = p_uaAfterFreeSpace = (unitAlloc *) p_stMyBlockInfo->p_cFirstFree; while ((p_uaAfterFreeSpace != (unitAlloc *) 0 ) && (p_uaAfterFreeSpace < (unitAlloc *) p_vMemBlock) ){ p_uaBeforeBeforeFreeSpace = p_uaBeforeFreeSpace; p_uaBeforeFreeSpace = p_uaAfterFreeSpace; p_uaAfterFreeSpace = (unitAlloc *) *(p_uaAfterFreeSpace+1);/* go to next*/ } /* here p_uaAfterFreeSpace point at the free space just after & p_uaBeforeFreeSpace that is just before & *(p_uaBeforeBefore+1) = p_uaBeforeFree*/ /* general case:*/ /* | Free | ... | Free | (...) | allocation | (...) | Free |*/ /* ^-- p_uaBeforeBeforeFree ^-- p_uaBeforeFree ^-- p_vMemBlock ^-- p_uaAfterFree*/ if ((lDiffSize == 0) && ((p_uaBeforeFreeSpace != (unitAlloc *) 0) && (p_uaBeforeFreeSpace + *p_uaBeforeFreeSpace == p_uaSizeMalloc))){ /* we want to 'move up' just before the malloc with the same size. Because there is a free space just before my malloc */ /* ---------------------*/ /* Yes there is a free space just before my malloc */ /* ------*/ /*==> We will move the malloc to the beginig of the free, in order to have the new free space after.*/ /* general case:*/ /* | Free | ... | Free || allocation | (...) | Free |*/ /* ^-- p_uaBeforeBeforeFree ^-- p_uaBeforeFree ^-- p_vMemBlock ^-- p_uaAfterFree*/ /* definition of my new free space after : p_uaTmp*/ /* -------*/ p_uaTmp = p_uaSizeMalloc + *p_uaSizeMalloc - *p_uaBeforeFreeSpace;/* point at the begining of the new free space. Just after the end of the allocation.*/ /*we have to move the begining of the allocation to p_uaSizeMalloc + lDiffSize*/ memmove (p_uaBeforeFreeSpace, p_uaSizeMalloc, (*p_uaSizeMalloc - (unsigned long)lDiffSize - C_ucMallocFooterSize)<< C_uwShiftAllocSize ); *(p_uaTmp+1) = (unitAlloc) p_uaAfterFreeSpace; /*restore the real 'next field'*/ *p_uaTmp = (unitAlloc) (((unitAlloc *)p_vMemBlock) - p_uaBeforeFreeSpace - C_ucMallocHeaderSize);/* restore the 'size' field for my free space.*/ /* general case:*/ /* | Free | ... | allocation || Free | (...) | Free |*/ /* ^-- p_uaBeforeBeforeFree ^-- p_uaBeforeFree ^--p_uaTmp ^-- p_uaAfterFree*/ p_vMemBlock = (void *) (p_uaBeforeFreeSpace + C_ucMallocHeaderSize);/* the new return value*/ p_uaSizeMalloc = p_uaBeforeFreeSpace; /*Management of the free list*/ if (p_uaBeforeBeforeFreeSpace == p_uaBeforeFreeSpace){/*first elt of the free list*/ p_stMyBlockInfo->p_cFirstFree = (char *) p_uaTmp; } else {/* commom case*/ *(p_uaBeforeBeforeFreeSpace +1) = (unitAlloc) p_uaTmp;/*the 'next' field of my free before the free space used have contain the value of the begining of my new free space*/ } /* test if we have to join my new space free with the after free space.*/ if ((p_uaTmp + *p_uaTmp)== p_uaAfterFreeSpace){/*My new free is adjacent to the free space after. Then we have to join both.*/ /* general case:*/ /* | Free | ... | allocation || Free || Free | (...) |Free|*/ /* ^-- p_uaBeforeBeforeFree ^-- p_uaBeforeFree ^--p_uaTmp ^-- p_uaAfterFree*/ *p_uaTmp = *p_uaTmp + *p_uaAfterFreeSpace;/*lint !e613: Possible use of null pointer (p_uaAfterFreeSpace)*/ /*the 'size' field of my new free space must be added with the content of 'size' field of my free space joined with*/ *(p_uaTmp+1) = *(p_uaAfterFreeSpace + 1);/*lint !e613: Possible use of null pointer (p_uaAfterFreeSpace)*/ /* the 'next' field of my new free space is equal to the 'next' field of my old free space after*/ /* general case:*/ /* | Free | ... | allocation || new joined free | (...) |Free|*/ /* ^-- p_uaBeforeBeforeFree ^-- p_uaBeforeFree ^--p_uaTmp */ #ifdef __DEBUG_MALLOC_MODE__ p_stMyBlockInfo->uwNbFree --; /*there is one less free*/ #endif /*__DEBUG_MALLOC_MODE__ */ } /* store malloc Information:*/ /*--------------------------*/ *p_uaSizeMalloc = (unitAlloc)ulSize; p_vMemBlock = (void *)(p_uaSizeMalloc + C_ucMallocHeaderSize); #ifdef __DEBUG_MALLOC_MODE__ *(p_uaSizeMalloc + ulSize - C_ucMallocFooterSize) = C_uaEndKey; p_stMyBlockInfo->ulNbTotalRealloc++; p_stMyMallocInfo = p_stMyBlockInfo->d_stMallocInfo + ulMyNbMalloc; p_stMyMallocInfo->p_cBeginMalloc = (char *) p_vMemBlock; p_stMyMallocInfo->p_cEndMalloc = ((char *) (p_uaSizeMalloc + ulSize - C_ucMallocFooterSize)) - 1; #endif /* __DEBUG_MALLOC_MODE__*/ if ((char*)(p_uaSizeMalloc + *p_uaSizeMalloc)-1>=p_stMyBlockInfo->p_cMaxMem){ /* Managemement of the mem max information i order to be able to compute an estination of the optimzed version*/ p_stMyBlockInfo->p_cMaxMem=(char*)(p_uaSizeMalloc + *p_uaSizeMalloc)-1; #ifdef __DEBUG_MALLOC_MODE__ p_stMyBlockInfo->ulCountMallocBeforeMaxMem = p_stMyBlockInfo->ulNbMalloc; p_stMyBlockInfo->ulCountFreeBeforeMaxMem = p_stMyBlockInfo->uwNbFree; #endif /* __DEBUG_MALLOC_MODE__*/ } #ifdef __DEBUG_MALLOC_MODE__ /* clean the area of the new free. we use the variable p_uaBeforeSpaceFree for scan the memory & p_uaAfterfreespace for the end of the free area.*/ for ( p_uaBeforeFreeSpace = p_uaTmp + C_ucFreeHeaderSize, p_uaAfterFreeSpace = p_uaBeforeFreeSpace + *p_uaTmp - C_ucFreeHeaderSize; p_uaBeforeFreeSpace < p_uaAfterFreeSpace; p_uaBeforeFreeSpace++ ){ *p_uaBeforeFreeSpace = C_uaCleanKey; } #endif /* __DEBUG_MALLOC_MODE__*/ /* not necessary #ifdef __DEBUG_MALLOC_MODE__ // counte the real number of free p_uaTmp = (unitAlloc*)p_stMyBlockInfo->p_cFirstFree; for (uwI=0; *(p_uaTmp+1) != (unitAlloc)0; uwI++, p_uaTmp = (unitAlloc*) *(p_uaTmp+1)); p_stMyBlockInfo->uwNbFree = uwI; #endif __DEBUG_MALLOC_MODE__ */ Mmg_MLeaveCriticalSection(); return (p_vMemBlock); }/* end of "we want to 'move up' just before the malloc with the same size because there is a free space just before my malloc "*/ else if (lDiffSize > 0){ /* we want to reduce the malloc */ /* ------*/ if ((p_uaBeforeFreeSpace != (unitAlloc *) 0) && (p_uaBeforeFreeSpace + *p_uaBeforeFreeSpace == p_uaSizeMalloc)){ /* Yes there is a free space just before my malloc */ /* ------*/ /*==> We will move the malloc to the beginig of the free, in order to have the new free space after.*/ /* general case:*/ /* | Free | ... | Free || allocation | (...) | Free |*/ /* ^-- p_uaBeforeBeforeFree ^-- p_uaBeforeFree ^-- p_vMemBlock ^-- p_uaAfterFree*/ /* definition of my new free space after : p_uaTmp*/ /* -------*/ p_uaTmp = p_uaSizeMalloc + *p_uaSizeMalloc - lDiffSize - *p_uaBeforeFreeSpace;/* point at the begining of the new free space. Just after the end of the allocation.*/ /*we have to move the begining of the allocation to p_uaSizeMalloc + lDiffSize*/ memmove (p_uaBeforeFreeSpace, p_uaSizeMalloc, (*p_uaSizeMalloc - (unsigned long)lDiffSize - C_ucMallocFooterSize)<< C_uwShiftAllocSize ); *(p_uaTmp+1) = (unitAlloc) p_uaAfterFreeSpace; *p_uaTmp = (unitAlloc)(((unitAlloc *)p_vMemBlock) - p_uaBeforeFreeSpace - C_ucMallocHeaderSize + lDiffSize);/* restore the 'size' field for my free space.*/ /* general case:*/ /* | Free | ... | allocation || Free | (...) | Free |*/ /* ^-- p_uaBeforeBeforeFree ^-- p_uaBeforeFree ^--p_uaTmp ^-- p_uaAfterFree*/ p_vMemBlock = (void *) (p_uaBeforeFreeSpace + C_ucMallocHeaderSize);/* the new return value*/ p_uaSizeMalloc = p_uaBeforeFreeSpace; /*Management of the free list*/ if (p_uaBeforeBeforeFreeSpace == p_uaBeforeFreeSpace){/*first elt of the free list*/ p_stMyBlockInfo->p_cFirstFree = (char *) p_uaTmp; } else {/* commom case*/ *(p_uaBeforeBeforeFreeSpace +1) = (unitAlloc) p_uaTmp;/*the 'next' field of my free before the free space used have contain the value of the begining of my new free space*/ } /* test if we have to join my new space free with the after free space.*/ if ((p_uaTmp + *p_uaTmp)== p_uaAfterFreeSpace){/*My new free is adjacent to the free space after. Then we have to join both.*/ /* general case:*/ /* | Free | ... | allocation || Free || Free | (...) |Free|*/ /* ^-- p_uaBeforeBeforeFree ^-- p_uaBeforeFree ^--p_uaTmp ^-- p_uaAfterFree*/ *p_uaTmp = *p_uaTmp + *p_uaAfterFreeSpace;/*lint !e613: Possible use of null pointer*/ /*the 'size' field of my new free space must be added with the content of 'size' field of my free space joined with*/ *(p_uaTmp+1) = *(p_uaAfterFreeSpace + 1);/*lint !e613: Possible use of null pointer*/ /* the 'next' field of my new free space is equal to the 'next' field of my old free space after*/ /* general case:*/ /* | Free | ... | allocation || New joined free | (...) |Free|*/ /* ^-- p_uaBeforeBeforeFree ^-- p_uaBeforeFree ^--p_uaTmp */ #ifdef __DEBUG_MALLOC_MODE__ p_stMyBlockInfo->uwNbFree --; /*there is one less free*/ #endif /*__DEBUG_MALLOC_MODE__ */ } }/*there is a free space just before my malloc */ else if (p_uaSizeMalloc + *p_uaSizeMalloc == p_uaAfterFreeSpace ){ /* Yes there is a free space just after my malloc ==> then we joined those 2 free spaces*/ /* -----*/ /* general case:*/ /* | Free | ... | Free | ... | allocation || Free | ... |Free|*/ /* ^-- p_uaBeforeBeforeFree ^-- p_uaBeforeFree ^-- p_vMemBlock ^-- p_uaAfterFree*/ /* definition of my new free space : p_uaTmp*/ /* -------*/ p_uaTmp = p_uaSizeMalloc + *p_uaSizeMalloc - lDiffSize;/* point at the begining of the new free space*/ /* general case:*/ /* | Free | ... | Free | ... | allocation || Free | ... |Free|*/ /* ^-- p_uaBeforeBeforeFree ^-- p_uaBeforeFree ^-- p_vMemBlock ^-- p_uaTmp*/ *p_uaTmp = (unitAlloc)lDiffSize + *p_uaAfterFreeSpace;/*lint !e613: Possible use of null pointer*/ /* like my new space is joined to the free just after we have to increase the 'size' field with the space joined*/ *(p_uaTmp+1) = *(p_uaAfterFreeSpace+1);/*lint !e613: Possible use of null pointer*/ /* the 'next' field of my new space must have the address contained in the next field of my old first free space*/ if (p_uaAfterFreeSpace == p_uaBeforeFreeSpace ){/* this is the first free space*/ p_stMyBlockInfo->p_cFirstFree = (char *) p_uaTmp;/*The begining of the new free space.*/ } else {/* common case this is not the fisrt free space*/ *(p_uaBeforeFreeSpace + 1) = (unitAlloc) p_uaTmp;/*lint !e613: Possible use of null pointer*/ /* the 'next' field of my free space just before my point at my new free space*/ } }/*there is a free space just after my malloc*/ else if (lDiffSize >= (long)C_ucFreeHeaderSize){ /* there isn't a free space just after or before my malloc and we can manage the free space poduced in the list of frees*/ /* we will generate a new free space*/ /* general case:*/ /* | Free | ... | Free | (...) | allocation | (...) | Free |*/ /* ^-- p_uaBeforeBeforeFree ^-- p_uaBeforeFree ^-- p_vMemBlock ^-- p_uaAfterFree*/ /* definition of my new free space : p_uaTmp*/ /* -------*/ p_uaTmp = p_uaSizeMalloc + *p_uaSizeMalloc - lDiffSize;/* point at the begining of the new free space*/ /* general case:*/ /* | Free | ... | Free | (...) | allocation || New Free | (...) | Free |*/ /* ^-- p_uaBeforeBeforeFree ^-- p_uaBeforeFree ^-- p_vMemBlock ^--P_uaTmp ^-- p_uaAfterFree*/ #ifdef __DEBUG_MALLOC_MODE__ p_stMyBlockInfo->uwNbFree ++; /*there is one more free*/ #endif /*__DEBUG_MALLOC_MODE__ */ *p_uaTmp = (unitAlloc)lDiffSize;/* the 'size' field of my new free space*/ *(p_uaTmp+1) = (unitAlloc) p_uaAfterFreeSpace; /*The 'next' field of my new free space will contain the adresse of my old first elt free list*/ if (p_uaBeforeFreeSpace == p_uaAfterFreeSpace){/* My new free space is the first elt of the free list.*/ p_stMyBlockInfo->p_cFirstFree = (char *) p_uaTmp;/*The begining of the new free space.*/ } else {/* commom case: My new free space will be between p_uaBeforeFreeSpace & p_uaAfterFreeSpace*/ *(p_uaBeforeFreeSpace + 1) = (unitAlloc) p_uaTmp;/*lint !e613: Possible use of null pointer*/ /* the 'next' field of my free space just before my point at my new free space*/ } } else { Mmg_MLeaveCriticalSection(); return (p_vMemBlock);/* no change because, the lDiffSize is to little to be managed*/ } /* store malloc Information:*/ /*--------------------------*/ *p_uaSizeMalloc = (unitAlloc)ulSize; p_vMemBlock = (void *)(p_uaSizeMalloc + C_ucMallocHeaderSize); #ifdef __DEBUG_MALLOC_MODE__ *(p_uaSizeMalloc + ulSize - C_ucMallocFooterSize) = C_uaEndKey; p_stMyBlockInfo->ulNbTotalRealloc++; p_stMyMallocInfo = p_stMyBlockInfo->d_stMallocInfo + ulMyNbMalloc; p_stMyMallocInfo->p_cBeginMalloc = (char *) p_vMemBlock; p_stMyMallocInfo->p_cEndMalloc = ((char *) (p_uaSizeMalloc + ulSize - C_ucMallocFooterSize)) -1; #endif /* __DEBUG_MALLOC_MODE__*/ if ((char*)(p_uaSizeMalloc + *p_uaSizeMalloc)-1>=p_stMyBlockInfo->p_cMaxMem){ /* Managemement of the mem max information i order to be able to compute an estination of the optimzed version*/ p_stMyBlockInfo->p_cMaxMem=(char*)(p_uaSizeMalloc + *p_uaSizeMalloc)-1; #ifdef __DEBUG_MALLOC_MODE__ p_stMyBlockInfo->ulCountMallocBeforeMaxMem = p_stMyBlockInfo->ulNbMalloc; p_stMyBlockInfo->ulCountFreeBeforeMaxMem = p_stMyBlockInfo->uwNbFree; #endif /* __DEBUG_MALLOC_MODE__*/ } #ifdef __DEBUG_MALLOC_MODE__ /* clean the area of the new free. we use the variable p_uaBeforeSpaceFree for scan the memory & p_uaAfterfreespace for the end of the free area.*/ for ( p_uaBeforeFreeSpace = p_uaTmp + C_ucFreeHeaderSize, p_uaAfterFreeSpace = p_uaBeforeFreeSpace + *p_uaTmp - C_ucFreeHeaderSize;/*lint !e644: p_uaTmp may not have been initialized*/ p_uaBeforeFreeSpace < p_uaAfterFreeSpace; p_uaBeforeFreeSpace++ ){ *p_uaBeforeFreeSpace = C_uaCleanKey; } #endif /* __DEBUG_MALLOC_MODE__*/ /*not necessary #ifdef __DEBUG_MALLOC_MODE__ // count the real number of free p_uaTmp = (unitAlloc*)p_stMyBlockInfo->p_cFirstFree; for (uwI=0; *(p_uaTmp+1) != (unitAlloc)0; uwI++, p_uaTmp = (unitAlloc*) *(p_uaTmp+1)); p_stMyBlockInfo->uwNbFree = uwI; #endif __DEBUG_MALLOC_MODE__ */ Mmg_MLeaveCriticalSection(); return (p_vMemBlock); }/* end of the if we reduce the allocation*/ else if (lDiffSize < 0){ /* we want to increase the allocation*/ /* --------*/ lDiffSize = -lDiffSize;/* in order to have a posive value meaning the increasing requested*/ if ( ( (p_uaBeforeFreeSpace +(*p_uaBeforeFreeSpace)) == p_uaSizeMalloc ) && ((uaBeforeFreeSize = *p_uaBeforeFreeSpace) >= (unitAlloc)lDiffSize) )/*lint !e613: Possible use of null pointer (p_uaBeforeFreeSpace)*/ { /* ^------- : size of the free space just before*/ /* we have enought space just before the allocation, with the free space begining at p_uaBeforeFreeSpace.*/ /* ------------- ------*/ /*==> We will move the malloc to the beginig of the free, in order to have the new free space after.*/ #ifdef __DEBUG_MALLOC_MODE__ #ifdef __ADD_PLACE_FOR_DEBUG_INFORMATION__ #ifdef __WARNING3_ERR_MMG__ /* test of overflow on a block*/ if ( ((char *) ( p_uaBeforeFreeSpace +ulSize - ( p_stMyBlockInfo->ulNbMalloc) * C_ucDebugInformationLoss )/* memMax - the place for debug information of all the allocation.*/ )-1 > (p_stMyBlockInfo->p_cEndBlock - (p_stMyBlockInfo->ulMaxNbStaticMalloc*(C_ucDebugInformationLoss<ulMaxNbStaticMalloc*C_ucDebugInformationLoss)- ( p_stMyBlockInfo->ulNbMalloc * C_ucDebugInformationLoss)) + uaBeforeFreeSize) << C_uwShiftAllocSize, C_szMmgLogFileName); Mmg_M_UpdateLastErrorWithCurrentModeInfo (E_uwMmgPbBLockFull, szErrTxt, ucChannel); #else /*__ERROR_STRINGS__*/ Mmg_M_UpdateLastErrorWithCurrentModeInfo (E_uwMmgPbBLockFull, NULL, ucChannel); #endif /*__ERROR_STRINGS__*/ Mmg_MLeaveCriticalSection(); return (NULL); } #endif/*__WARNING3_ERR_MMG__*/ #endif /*__ADD_PLACE_FOR_DEBUG_INFORMATION__*/ #endif /*__DEBUG_MALLOC_MODE__*/ *p_uaBeforeFreeSpace -= ((unitAlloc) lDiffSize);/*lint !e613: Possible use of null pointer (p_uaBeforeFreeSpace)*/ /* the content of the 'size' field is equal of the remain (not used for the allocation)*/ if (*p_uaBeforeFreeSpace < (unitAlloc) C_ucFreeHeaderSize) /*lint !e613: Possible use of null pointer (p_uaBeforeFreeSpace)*/ {/*The remain of the free place is not enougth big to be managned*/ /* we affect all the place to the malloc. The 'old' free place if empty (everything is used for the malloc)*/ ulSize += (*p_uaBeforeFreeSpace);/*lint !e613: Possible use of null pointer (p_uaBeforeFreeSpace)*/ lDiffSize = lDiffSize + (long)(*p_uaBeforeFreeSpace);/*lint !e613: Possible use of null pointer (p_uaBeforeFreeSpace)*/ /* management of the first free*/ if (p_uaBeforeFreeSpace == p_uaBeforeBeforeFreeSpace){/* this is the first elt of the list*/ p_stMyBlockInfo->p_cFirstFree = (char *) p_uaAfterFreeSpace; } else {/*commom case*/ /* the free place before will become empty (everything is used for the malloc)*/ /* Management of the Free list : the 'next' field of the free place before the free place used, will be affect to the contents of the 'next' field of the free place used */ *(p_uaBeforeBeforeFreeSpace + 1) = (unitAlloc) p_uaAfterFreeSpace;/* !! a tester*/ } /* general case:*/ /* | Free | ... | Free || allocation | (...) |Free|*/ /* ^--p_uaBeforeBeforeFreespace ^---p_uaBeforeFreeSpace ^--p_uaSizeMalloc ^--p_uaAfterFreeSpace */ /*we have to move the begining of the allocation to p_uaBeforeFreeSpace*/ memmove (p_uaBeforeFreeSpace, p_uaSizeMalloc, (*p_uaSizeMalloc - C_ucMallocFooterSize)<< C_uwShiftAllocSize );/*lint !e668: Possibly passing a null pointer to function*/ /* general case:*/ /* | Free | ... | allocation |++++++++++++++++++++++++| (...) |Free|*/ /* ^--p_uaBeforeBeforeFreespace ^---p_uaBeforeFreeSpace ^--p_uaAfterFreeSpace*/ /* with ++++: meanimg the new space added for the allocation*/ #ifdef __DEBUG_MALLOC_MODE__ p_stMyBlockInfo->uwNbFree --; /*there is one less free*/ #endif /*__DEBUG_MALLOC_MODE__ */ /* store malloc Information (first part)*/ /*----------------------------------------*/ p_uaSizeMalloc = p_uaBeforeFreeSpace; p_vMemBlock = (void *) (p_uaBeforeFreeSpace + C_ucMallocHeaderSize);/*lint !e613: Possible use of null pointer (p_uaBeforeFreeSpace)*/ /* the new adresse of the allocation */ #ifdef __DEBUG_MALLOC_MODE__ /* clean the area of the new allocation. we use the variable p_uaBeforeSpaceFree for scan the memory & p_uaAfterfreespace for the end of the free area.*/ for ( p_uaBeforeFreeSpace = p_uaBeforeFreeSpace + *p_uaBeforeFreeSpace - C_ucMallocFooterSize, p_uaAfterFreeSpace = p_uaBeforeFreeSpace + lDiffSize;/*lint !e613: Possible use of null pointer (p_uaBeforeFreeSpace)*/ p_uaBeforeFreeSpace < p_uaAfterFreeSpace; p_uaBeforeFreeSpace++ ) { *p_uaBeforeFreeSpace = C_uaCleanKey; } #endif /* __DEBUG_MALLOC_MODE__*/ } else {/* management of the remained place after the new alloction.*/ /* general case:*/ /* | Free | ... | Free || allocation | (...) |Free|*/ /* ^--p_uaBeforeBeforeFreespace ^---p_uaBeforeFreeSpace ^--p_uaSizeMalloc ^--p_uaAfterFreeSpace */ /* definition of my new free space after allocation : p_uaTmp*/ /* -------*/ p_uaTmp = p_uaBeforeFreeSpace + *p_uaSizeMalloc + lDiffSize;/*lint !e613: Possible use of null pointer (p_uaBeforeFreeSpace)*/ /* point at the begining of the new free space*/ /*we have to move the begining of the allocation to p_uaBeforeFreeSpace*/ memmove (p_uaBeforeFreeSpace, p_uaSizeMalloc, (*p_uaSizeMalloc - C_ucMallocFooterSize)<< C_uwShiftAllocSize );/*lint !e668: Possibly passing a null pointer to function memmove*/ /* general case:*/ /* | Free | ... | allocation ++++++++|| Free | (...) |Free|*/ /* ^--p_uaBeforeBeforeFreespace ^---p_uaBeforeFreeSpace ^--p_uaTmp ^--p_uaAfterFreeSpace*/ /* with ++++: meanimg the new space added for the allocation*/ /* set information of my new free space*/ *p_uaTmp = (unitAlloc) (uaBeforeFreeSize - (unsigned long)lDiffSize);/* set the 'size' field of the new free space = [size of my old free space just before] - [value of my increaseing allocation].*/ *(p_uaTmp +1) = (unitAlloc) p_uaAfterFreeSpace;/* set the 'next' field of my new free space*/ /*Management of the free list*/ if (p_uaBeforeBeforeFreeSpace == p_uaBeforeFreeSpace){/*first elt of the free list*/ p_stMyBlockInfo->p_cFirstFree = (char *) p_uaTmp; } else {/* commom case*/ *(p_uaBeforeBeforeFreeSpace +1) = (unitAlloc) p_uaTmp;/*the 'next' field of my free before the free space used have contain the value of the begining of my new free space*/ } /* test if we have to join my new space free with the after free space.*/ if ((p_uaTmp + *p_uaTmp)== p_uaAfterFreeSpace){/*My new free is adjacent to the free space after. Then we have to join both.*/ /* general case:*/ /* | Free | ... | allocation ++++++++|| Free ||Free|*/ /* ^--p_uaBeforeBeforeFreespace ^---p_uaBeforeFreeSpace ^--p_uaTmp ^--p_uaAfterFreeSpace*/ #ifdef __DEBUG_MALLOC_MODE__ p_stMyBlockInfo->uwNbFree --; /*there is one less free*/ #endif /*__DEBUG_MALLOC_MODE__ */ *p_uaTmp = *p_uaTmp + *p_uaAfterFreeSpace;/*lint !e613: Possible use of null pointer (p_uaAfterFreeSpace)*/ /*the 'size' field of my new free space must be added with the content of 'size' field of my free space joined with*/ *(p_uaTmp+1) = *(p_uaAfterFreeSpace + 1);/*lint !e613: Possible use of null pointer (p_uaBeforeFreeSpace))*/ /* the 'next' field of my new free space is equal to the 'next' field of my old free space after*/ } /* store malloc Information (first part)*/ /*----------------------------------------*/ p_uaSizeMalloc = p_uaBeforeFreeSpace; p_vMemBlock = (void *) (p_uaBeforeFreeSpace + C_ucMallocHeaderSize);/*lint !e613: Possible use of null pointer (p_uaBeforeFreeSpace)*/ /* the new adresse of the allocation */ #ifdef __DEBUG_MALLOC_MODE__ /* clean the area of the new allocation. we use the variable p_uaBeforeSpaceFree for scan the memory & p_uaAfterfreespace for the end of the free area.*/ for ( p_uaBeforeFreeSpace = p_uaBeforeFreeSpace + *p_uaBeforeFreeSpace - C_ucMallocFooterSize, p_uaAfterFreeSpace = p_uaBeforeFreeSpace + lDiffSize;/*lint !e613: Possible use of null pointer (p_uaBeforeFreeSpace)*/ p_uaBeforeFreeSpace < p_uaAfterFreeSpace; p_uaBeforeFreeSpace++ ){ *p_uaBeforeFreeSpace = C_uaCleanKey; } /* clean the area of the new free. we use the variable p_uaBeforeSpaceFree for scan the memory & p_uaAfterfreespace for the end of the free area.*/ for ( p_uaBeforeFreeSpace = p_uaTmp + C_ucFreeHeaderSize, p_uaAfterFreeSpace = p_uaBeforeFreeSpace + *p_uaTmp - C_ucFreeHeaderSize; p_uaBeforeFreeSpace < p_uaAfterFreeSpace; p_uaBeforeFreeSpace++ ){ *p_uaBeforeFreeSpace = C_uaCleanKey; } #endif /* __DEBUG_MALLOC_MODE__*/ } /* store malloc Information (continued)*/ /*---------------------------------------*/ *p_uaSizeMalloc = (unitAlloc)ulSize;/*lint !e613: Possible use of null pointer (p_uaSizeMalloc)*/ #ifdef __DEBUG_MALLOC_MODE__ *(p_uaSizeMalloc + ulSize -1) = C_uaEndKey;/*lint !e613: Possible use of null pointer (p_uaSizeMalloc)*/ p_stMyBlockInfo->ulNbTotalRealloc++; p_stMyMallocInfo = p_stMyBlockInfo->d_stMallocInfo + ulMyNbMalloc; p_stMyMallocInfo->p_cBeginMalloc = (char *) p_vMemBlock; p_stMyMallocInfo->p_cEndMalloc = ((char *) (p_uaSizeMalloc + ulSize - C_ucMallocFooterSize)) - 1;/*lint !e613: Possible use of null pointer (p_uaSizeMalloc)*/ #endif /* __DEBUG_MALLOC_MODE__*/ if ((char*)(p_uaSizeMalloc + *p_uaSizeMalloc)-1>=p_stMyBlockInfo->p_cMaxMem)/*lint !e613: Possible use of null pointer (p_uaSizeMalloc)*/ { /* Managemement of the mem max information i order to be able to compute an estination of the optimzed version*/ p_stMyBlockInfo->p_cMaxMem=(char*)(p_uaSizeMalloc + *p_uaSizeMalloc)-1;/*lint !e613: Possible use of null pointer (p_uaSizeMalloc)*/ #ifdef __DEBUG_MALLOC_MODE__ p_stMyBlockInfo->ulCountMallocBeforeMaxMem = p_stMyBlockInfo->ulNbMalloc; p_stMyBlockInfo->ulCountFreeBeforeMaxMem = p_stMyBlockInfo->uwNbFree; #endif /* __DEBUG_MALLOC_MODE__*/ } /*not necessary #ifdef __DEBUG_MALLOC_MODE__ // count the real number of free p_uaTmp = (unitAlloc*)p_stMyBlockInfo->p_cFirstFree; for (uwI=0; *(p_uaTmp+1) != (unitAlloc)0; uwI++, p_uaTmp = (unitAlloc*) *(p_uaTmp+1)); p_stMyBlockInfo->uwNbFree = uwI; #endif __DEBUG_MALLOC_MODE__ */ Mmg_MLeaveCriticalSection(); return (p_vMemBlock); }/* end of Yes, we have enought space before the allocation.*/ else if ( ( p_uaSizeMalloc + *p_uaSizeMalloc == p_uaAfterFreeSpace) && ((p_uaBeforeFreeSpace +(*p_uaBeforeFreeSpace)) == p_uaSizeMalloc )&& ((uaBeforeFreeSize + (uaAfterFreeSize = *p_uaAfterFreeSpace)) >= (unitAlloc) lDiffSize) )/*lint !e613: Possible use of null pointer (p_uaBeforeFreeSpace) & (p_uaAfterFreeSpace)*/ { /* ^------- : size of the free space just after*/ /* We have not eougth space with the space just before.*/ /* But The space just before + just after is enougth big*/ /* ------------------------*/ #ifdef __DEBUG_MALLOC_MODE__ #ifdef __ADD_PLACE_FOR_DEBUG_INFORMATION__ #ifdef __WARNING3_ERR_MMG__ /* test of overflow on a block*/ if ( ((char *) ( p_uaBeforeFreeSpace +ulSize - ( p_stMyBlockInfo->ulNbMalloc) * C_ucDebugInformationLoss )/* memMax - the place for debug information of all the allocation.*/ )-1 > (p_stMyBlockInfo->p_cEndBlock - (p_stMyBlockInfo->ulMaxNbStaticMalloc*(C_ucDebugInformationLoss<ulMaxNbStaticMalloc*C_ucDebugInformationLoss)- ( p_stMyBlockInfo->ulNbMalloc * C_ucDebugInformationLoss)) + uaBeforeFreeSize) << C_uwShiftAllocSize, C_szMmgLogFileName); Mmg_M_UpdateLastErrorWithCurrentModeInfo (E_uwMmgPbBLockFull, szErrTxt, ucChannel); #else /*__ERROR_STRINGS__*/ Mmg_M_UpdateLastErrorWithCurrentModeInfo (E_uwMmgPbBLockFull, NULL, ucChannel); #endif /*__ERROR_STRINGS__*/ Mmg_MLeaveCriticalSection(); return (NULL); } #endif/*__WARNING3_ERR_MMG__*/ #endif /*__ADD_PLACE_FOR_DEBUG_INFORMATION__*/ #endif /*__DEBUG_MALLOC_MODE__*/ /* in order to save the adresse of the space free just after the free just after my allocation, the 'next' field of the free before my allocation will containhis adresse*/ p_uaAfterAfterFreeSpace = (unitAlloc *) (*(p_uaAfterFreeSpace+1));/*lint !e613: Possible use of null pointer (p_uaAfterFreeSpace)*/ /* general case:*/ /* | Free |...| Free || allocation || Free | ... |Free|*/ /* ^--p_uaBeforeBeforeFreespace ^---p_uaBeforeFreeSpace ^--p_uaSizeMalloc ^--p_uaAfterFreeSpace ^--P_auAfterAfterSpace*/ *p_uaBeforeFreeSpace = (unitAlloc) (uaBeforeFreeSize + uaAfterFreeSize - (unitAlloc)lDiffSize);/*lint !e613: Possible use of null pointer (p_uaBeforeFreeSpace)*/ /* the content of the 'size' field is equal of the remain (not used for the allocation)*/ if (*p_uaBeforeFreeSpace < (unitAlloc) C_ucFreeHeaderSize) /*lint !e613: Possible use of null pointer (p_uaBeforeFreeSpace)*/ {/*The remain of the free place is not enougth big to be managned*/ /* we affect all the place to the malloc. The 'old' free place if empty (everything is used for the malloc)*/ ulSize += (*p_uaBeforeFreeSpace);/*lint !e613: Possible use of null pointer (p_uaBeforeFreeSpace)*/ lDiffSize = lDiffSize + (long)(*p_uaBeforeFreeSpace);/*lint !e613: Possible use of null pointer (p_uaBeforeFreeSpace)*/ /* management of the first free*/ if (p_uaBeforeBeforeFreeSpace == p_uaBeforeFreeSpace){/* this is the first elt of the list*/ p_stMyBlockInfo->p_cFirstFree = (char *) *(p_uaAfterFreeSpace+1);/*lint !e613: Possible use of null pointer (p_uaAfterFreeSpace)*/ } else {/*commom case*/ /* the free place before will become empty (everything is used for the malloc)*/ /* Management of the Free list : the 'next' field of the free place before the free place used, will be affect to the contents of the 'next' field of the free place used */ *(p_uaBeforeBeforeFreeSpace + 1) = *(p_uaAfterFreeSpace+1);/*lint !e613: Possible use of null pointer (p_uaAfterFreeSpace)*/ } /* general case:*/ /* | Free |...| Free || allocation || Free | ... |Free|*/ /* ^--p_uaBeforeBeforeFreespace ^---p_uaBeforeFreeSpace ^--p_uaSizeMalloc ^--p_uaAfterFreeSpace ^--P_auAfterAfterSpace*/ /*we have to move the begining of the allocation to p_uaBeforeFreeSpace*/ memmove (p_uaBeforeFreeSpace, p_uaSizeMalloc, (*p_uaSizeMalloc - C_ucMallocFooterSize)<< C_uwShiftAllocSize );/*lint !e668: Possibly passing a null pointer to function memmove*/ /* general case:*/ /* | Free |...| allocation |+++++++++++++++++++++++++++++++++++++++++++++| ... |Free|*/ /* ^--p_uaBeforeBeforeFreespace ^---p_uaBeforeFreeSpace ^--P_auAfterAfterSpace*/ /* with ++++: meanimg the new space added for the allocation*/ #ifdef __DEBUG_MALLOC_MODE__ p_stMyBlockInfo->uwNbFree -=2; /*there is two less frees*/ #endif /*__DEBUG_MALLOC_MODE__ */ /* store malloc Information (first part)*/ /*--------------------------------------*/ p_uaSizeMalloc = p_uaBeforeFreeSpace; p_vMemBlock = (void *) (p_uaBeforeFreeSpace + C_ucMallocHeaderSize);/*lint !e613: Possible use of null pointer (p_uaBeforeFreeSpace)*/ /* the new adresse of the allocation */ #ifdef __DEBUG_MALLOC_MODE__ /* clean the area of the new allocation. we use the variable p_uaBeforeSpaceFree for scan the memory & p_uaAfterfreespace for the end of the free area.*/ for ( p_uaBeforeFreeSpace = p_uaBeforeFreeSpace + *p_uaBeforeFreeSpace - C_ucMallocFooterSize, p_uaAfterFreeSpace = p_uaBeforeFreeSpace + lDiffSize;/*lint !e613: Possible use of null pointer (p_uaBeforeFreeSpace)*/ p_uaBeforeFreeSpace < p_uaAfterFreeSpace; p_uaBeforeFreeSpace++ ){ *p_uaBeforeFreeSpace = C_uaCleanKey; } #endif /* __DEBUG_MALLOC_MODE__*/ } else {/* management of the remained place after the new alloction.*/ /* general case:*/ /* | Free |...| Free || allocation || Free | ... |Free|*/ /* ^--p_uaBeforeBeforeFreespace ^---p_uaBeforeFreeSpace ^--p_uaSizeMalloc ^--p_uaAfterFreeSpace ^--P_auAfterAfterSpace*/ /* definition of my new free space after allocation : p_uaTmp*/ /* -------*/ p_uaTmp = p_uaBeforeFreeSpace + *p_uaSizeMalloc + lDiffSize;/*lint !e613: Possible use of null pointer (p_uaBeforeFreeSpace)*/ /* point at the begining of the new free space*/ /*we have to move the begining of the allocation to p_uaBeforeFreeSpace*/ memmove (p_uaBeforeFreeSpace, p_uaSizeMalloc, (*p_uaSizeMalloc - C_ucMallocFooterSize)<< C_uwShiftAllocSize );/*lint !e668: Possibly passing a null pointer to function memmove*/ /* general case:*/ /* | Free |...| allocation |+++++++++++++++++++++++++++++| free remained | ... |Free|*/ /* ^--p_uaBeforeBeforeFreespace ^---p_uaBeforeFreeSpace ^--p_uaTmp ^--P_auAfterAfterSpace*/ /* with ++++: meanimg the new space added for the allocation*/ #ifdef __DEBUG_MALLOC_MODE__ p_stMyBlockInfo->uwNbFree --; /*there is one less free*/ #endif /*__DEBUG_MALLOC_MODE__ */ /* set information of my new free space*/ *p_uaTmp = (unitAlloc) (uaBeforeFreeSize + uaAfterFreeSize - (unitAlloc)lDiffSize);/* set the 'size' field of the new free space = [size of my old free space just before and just after] - [value of my increaseing allocation].*/ *(p_uaTmp +1) = (unitAlloc) p_uaAfterAfterFreeSpace;/* set the 'next' field of my new free space */ /*Management of the free list*/ if (p_uaBeforeBeforeFreeSpace == p_uaBeforeFreeSpace){/*first elt of the free list*/ p_stMyBlockInfo->p_cFirstFree = (char *) p_uaTmp; } else {/* commom case*/ *(p_uaBeforeBeforeFreeSpace +1) = (unitAlloc) p_uaTmp;/*the 'next' field of my free before the free space used have contain the value of the begining of my new free space*/ } /* store malloc Information (first part)*/ /*--------------------------------------*/ p_uaSizeMalloc = p_uaBeforeFreeSpace; p_vMemBlock = (void *) (p_uaBeforeFreeSpace + C_ucMallocHeaderSize);/*lint !e613: Possible use of null pointer (p_uaBeforeFreeSpace)*/ /* the new adresse of the allocation*/ #ifdef __DEBUG_MALLOC_MODE__ /* clean the area of the new allocation. we use the variable p_uaBeforeSpaceFree for scan the memory & p_uaAfterfreespace for the end of the free area.*/ for ( p_uaBeforeFreeSpace = p_uaBeforeFreeSpace + *p_uaBeforeFreeSpace - C_ucMallocFooterSize, p_uaAfterFreeSpace = p_uaBeforeFreeSpace + lDiffSize;/*lint !e613: Possible use of null pointer (p_uaBeforeFreeSpace)*/ p_uaBeforeFreeSpace < p_uaAfterFreeSpace; p_uaBeforeFreeSpace++ ){ *p_uaBeforeFreeSpace = C_uaCleanKey; } /* clean the area of the new free. we use the variable p_uaBeforeSpaceFree for scan the memory & p_uaAfterfreespace for the end of the free area.*/ for ( p_uaBeforeFreeSpace = p_uaTmp + C_ucFreeHeaderSize, p_uaAfterFreeSpace = p_uaBeforeFreeSpace + *p_uaTmp - C_ucFreeHeaderSize; p_uaBeforeFreeSpace < p_uaAfterFreeSpace; p_uaBeforeFreeSpace++ ){ *p_uaBeforeFreeSpace = C_uaCleanKey; } #endif /* __DEBUG_MALLOC_MODE__*/ } /* store malloc Information (continued)*/ /*--------------------------------------*/ *p_uaSizeMalloc = (unitAlloc)ulSize;/*lint !e613: Possible use of null pointer (p_uaSizeMalloc)*/ #ifdef __DEBUG_MALLOC_MODE__ *(p_uaSizeMalloc + ulSize -1) = C_uaEndKey;/*lint !e613: Possible use of null pointer (p_uaSizeMalloc)*/ p_stMyBlockInfo->ulNbTotalRealloc++; p_stMyMallocInfo = p_stMyBlockInfo->d_stMallocInfo + ulMyNbMalloc; p_stMyMallocInfo->p_cBeginMalloc = (char *) p_vMemBlock; p_stMyMallocInfo->p_cEndMalloc = ((char *) (p_uaSizeMalloc + ulSize - C_ucMallocFooterSize)) - 1;/*lint !e613: Possible use of null pointer (p_uaSizeMalloc)*/ #endif /* __DEBUG_MALLOC_MODE__*/ if ((char*)(p_uaSizeMalloc + *p_uaSizeMalloc)-1>=p_stMyBlockInfo->p_cMaxMem)/*lint !e613: Possible use of null pointer (p_uaSizeMalloc)*/ { /* Managemement of the mem max information i order to be able to compute an estination of the optimzed version*/ p_stMyBlockInfo->p_cMaxMem=(char*)(p_uaSizeMalloc + *p_uaSizeMalloc)-1;/*lint !e613: Possible use of null pointer (p_uaSizeMalloc)*/ #ifdef __DEBUG_MALLOC_MODE__ p_stMyBlockInfo->ulCountMallocBeforeMaxMem = p_stMyBlockInfo->ulNbMalloc; p_stMyBlockInfo->ulCountFreeBeforeMaxMem = p_stMyBlockInfo->uwNbFree; #endif /* __DEBUG_MALLOC_MODE__*/ } /* not necessary #ifdef __DEBUG_MALLOC_MODE__ // count the real number of free p_uaTmp = (unitAlloc*)p_stMyBlockInfo->p_cFirstFree; for (uwI=0; *(p_uaTmp+1) != (unitAlloc)0; uwI++, p_uaTmp = (unitAlloc*) *(p_uaTmp+1)); p_stMyBlockInfo->uwNbFree = uwI; #endif __DEBUG_MALLOC_MODE__ */ Mmg_MLeaveCriticalSection(); return (p_vMemBlock); }/* end of Yes there are enougth space just before + just after*/ else if ( ( p_uaSizeMalloc + *p_uaSizeMalloc == p_uaAfterFreeSpace) && ((uaAfterFreeSize = *p_uaAfterFreeSpace) >= (unitAlloc) lDiffSize) )/*lint !e613: Possible use of null pointer (p_uaAfterFreeSpace))*/ { /* we have enought space just after the allocation, with the free space begining at p_uaAfterFreeSpace.*/ /* ------------- -----*/ /* general case:*/ /* | Free | ... | Free | (...) | allocation || Free | (...) |free|*/ /* ^-- p_uaBeforeBeforeFree ^-- p_uaBeforeFree ^-- p_vMemBlock ^-- p_uaAfterFree*/ #ifdef __DEBUG_MALLOC_MODE__ #ifdef __ADD_PLACE_FOR_DEBUG_INFORMATION__ #ifdef __WARNING3_ERR_MMG__ /* test of overflow on a block*/ if ( ((char *) ( p_uaSizeMalloc +ulSize - ( p_stMyBlockInfo->ulNbMalloc ) * C_ucDebugInformationLoss )/* memMax - the place for debug information of all the allocation.*/ )-1 > (p_stMyBlockInfo->p_cEndBlock - (p_stMyBlockInfo->ulMaxNbStaticMalloc*(C_ucDebugInformationLoss<ulMaxNbStaticMalloc*C_ucDebugInformationLoss)- ( p_stMyBlockInfo->ulNbMalloc * C_ucDebugInformationLoss))) << C_uwShiftAllocSize, C_szMmgLogFileName); Mmg_M_UpdateLastErrorWithCurrentModeInfo (E_uwMmgPbBLockFull, szErrTxt, ucChannel); #else /*__ERROR_STRINGS__*/ Mmg_M_UpdateLastErrorWithCurrentModeInfo (E_uwMmgPbBLockFull, NULL, ucChannel); #endif /*__ERROR_STRINGS__*/ Mmg_MLeaveCriticalSection(); return (NULL); } #endif/*__WARNING3_ERR_MMG__*/ #endif/*__ADD_PLACE_FOR_DEBUG_INFORMATION__*/ #endif /*__DEBUG_MALLOC_MODE__*/ *p_uaAfterFreeSpace -= ((unitAlloc) lDiffSize);/*lint !e613: Possible use of null pointer (p_uaAfterFreeSpace)*/ /* the content of the 'size' field is equal of the remain (not used for the allocation)*/ if (*p_uaAfterFreeSpace < (unitAlloc) C_ucFreeHeaderSize) /*lint !e613: Possible use of null pointer (p_uaAfterFreeSpace)*/ {/*The remain of the free place is not enougth big to be managned*/ /* we affect all the place to the malloc. The 'old' free place if empty (everything is used for the malloc)*/ ulSize += (*p_uaAfterFreeSpace);/*lint !e613: Possible use of null pointer (p_uaAfterFreeSpace)*/ lDiffSize = lDiffSize + (long)(*p_uaAfterFreeSpace);/*lint !e613: Possible use of null pointer (p_uaAfterFreeSpace)*/ /* general case:*/ /* | Free | ... | Free | (...) | allocation |+++++++++++++++| (...) |free|*/ /* ^-- p_uaBeforeBeforeFree ^-- p_uaBeforeFree ^-- p_vMemBlock ^-- p_uaAfterFree*/ #ifdef __DEBUG_MALLOC_MODE__ p_stMyBlockInfo->uwNbFree --; /*there is one less free*/ #endif /*__DEBUG_MALLOC_MODE__ */ /* management of the first free*/ if (p_uaAfterFreeSpace == p_uaBeforeFreeSpace){/* this is the first elt of the list*/ p_stMyBlockInfo->p_cFirstFree = (char *) *(p_uaAfterFreeSpace+1);/*lint !e613: Possible use of null pointer (p_uaAfterFreeSpace)*/ } else {/* commom case*/ /* the free place after will become empty (everything is used for the malloc)*/ /* Management of the Free list : the 'next' field of the free place before the free place used, will be affect to the contents of the 'next' field of the free place used */ *(p_uaBeforeFreeSpace + 1) = *(p_uaAfterFreeSpace + 1);/*lint !e613: Possible use of null pointer (p_uaAfterFreeSpace) & (p_uaBeforeFreeSpace)*/ } } else {/* management of the remained place after the new alloction.*/ p_uaTmp = (unitAlloc *) *(p_uaAfterFreeSpace + 1);/*lint !e613: Possible use of null pointer (p_uaAfterFreeSpace)*/ /* save the next field of my old free after my allocation*/ *(p_uaAfterFreeSpace + lDiffSize) = *p_uaAfterFreeSpace;/*lint !e613: Possible use of null pointer (p_uaAfterFreeSpace)*/ /* set the 'size' field of remained space at the rigth place*/ *(p_uaAfterFreeSpace + lDiffSize + 1) = (unitAlloc) p_uaTmp;/*lint !e613: Possible use of null pointer (p_uaAfterFreeSpace)*/ /* set the 'next' field of remained space at the rigth place*/ /* general case:*/ /* | Free | ... | Free | (...) | allocation |+++++| Free | (...) |free|*/ /* ^-- p_uaBeforeBeforeFree ^-- p_uaBeforeFree ^-- p_vMemBlock ^-- p_uaAfterFree*/ /* management of the first free*/ if (p_uaBeforeFreeSpace == p_uaAfterFreeSpace){/* this is the first elt of the list*/ p_stMyBlockInfo->p_cFirstFree = (char *) (p_uaAfterFreeSpace + lDiffSize);/*lint !e613: Possible use of null pointer (p_uaAfterFreeSpace)*/ } else {/* commom case.*/ *(p_uaBeforeFreeSpace+1) = (unitAlloc) (p_uaAfterFreeSpace + lDiffSize);/*lint !e613: Possible use of null pointer (p_uaAfterFreeSpace)*/ /*managment of the free list. The 'next' field of free space just before the allocation have chage.*/ } } /* store malloc Information*/ /*--------------------------*/ *p_uaSizeMalloc = (unitAlloc)ulSize; #ifdef __DEBUG_MALLOC_MODE__ *(p_uaSizeMalloc + ulSize -1) = C_uaEndKey; p_stMyBlockInfo->ulNbTotalRealloc++; p_stMyMallocInfo = p_stMyBlockInfo->d_stMallocInfo + ulMyNbMalloc; p_stMyMallocInfo->p_cEndMalloc = ((char *) (p_uaSizeMalloc + ulSize - C_ucMallocFooterSize)) - 1; #endif /* __DEBUG_MALLOC_MODE__*/ if ((char*)(p_uaSizeMalloc + *p_uaSizeMalloc)-1>=p_stMyBlockInfo->p_cMaxMem) { /* Managemement of the mem max information i order to be able to compute an estination of the optimzed version*/ p_stMyBlockInfo->p_cMaxMem=(char*)(p_uaSizeMalloc + *p_uaSizeMalloc)-1; #ifdef __DEBUG_MALLOC_MODE__ p_stMyBlockInfo->ulCountMallocBeforeMaxMem = p_stMyBlockInfo->ulNbMalloc; p_stMyBlockInfo->ulCountFreeBeforeMaxMem = p_stMyBlockInfo->uwNbFree; #endif /* __DEBUG_MALLOC_MODE__*/ } #ifdef __DEBUG_MALLOC_MODE__ /* clean the area of the new allocation. we use the variable p_uaBeforeSpaceFree for scan the memory & p_uaAfterfreespace for the end of the free area.*/ for ( p_uaBeforeFreeSpace = p_uaAfterFreeSpace - C_ucMallocFooterSize, p_uaAfterFreeSpace = p_uaBeforeFreeSpace + lDiffSize;/*lint !e613: Possible use of null pointer (p_uaAfterFreeSpace)*/ p_uaBeforeFreeSpace < p_uaAfterFreeSpace; p_uaBeforeFreeSpace++ ) { *p_uaBeforeFreeSpace = C_uaCleanKey; } #endif /* __DEBUG_MALLOC_MODE__*/ /*not necessary #ifdef __DEBUG_MALLOC_MODE__ // count the real number of free p_uaTmp = (unitAlloc*)p_stMyBlockInfo->p_cFirstFree; for (uwI=0; *(p_uaTmp+1) != (unitAlloc)0; uwI++, p_uaTmp = (unitAlloc*) *(p_uaTmp+1)); p_stMyBlockInfo->uwNbFree = uwI; #endif __DEBUG_MALLOC_MODE__ */ Mmg_MLeaveCriticalSection(); return (p_vMemBlock); }/* end of Yes, we have enought space after the allocation.*/ else{ /* There are no space around the allocation*/ /* ----------------*/ ulSize -= (C_ucMallocHeaderSize + C_ucMallocFooterSize); /* place for information(s) to manage the allocation place*/ ulSize <<= C_uwShiftAllocSize; #ifdef __DEBUG_MALLOC_MODE__ p_stMyBlockInfo->ulNbTotalMalloc--;/* this is not a real malloc requested, then we don't have to increase the counter.*/ #endif /*__DEBUG_MALLOC_MODE__*/ p_uaTmp = (unitAlloc *) fn_p_vStaAlloc (ulSize, ucChannel); if (p_uaTmp != NULL) { memcpy ((void *) p_uaTmp, p_vMemBlock, (*p_uaSizeMalloc - C_ucMallocFooterSize - C_ucMallocHeaderSize)<< C_uwShiftAllocSize); #ifdef __DEBUG_MALLOC_MODE__ p_stMyBlockInfo->ulNbTotalFree--;/* this is not a real free requested, then we don't have to increase the counter.*/ #endif /*__DEBUG_MALLOC_MODE__*/ fn_vStaFree (p_vMemBlock, ucChannel); #ifdef __DEBUG_MALLOC_MODE__ /* the free have move up all the elt after the freed malloc of the Malloc info Table*/ /* then we have to use the last elt of the malloc info table*/ ulMyNbMalloc= (unsigned short) (p_stMyBlockInfo->ulNbMalloc -1); #endif /*__DEBUG_MALLOC_MODE__*/ /* store malloc Information*/ /*--------------------------*/ #ifdef __DEBUG_MALLOC_MODE__ p_stMyBlockInfo->ulNbTotalRealloc++; p_vMemBlock = p_uaTmp; #endif /* __DEBUG_MALLOC_MODE__*/ p_uaSizeMalloc = p_uaTmp - C_ucMallocHeaderSize; if ((char*)(p_uaSizeMalloc + *p_uaSizeMalloc)-1>=p_stMyBlockInfo->p_cMaxMem) { /* Managemement of the mem max information i order to be able to compute an estination of the optimzed version*/ p_stMyBlockInfo->p_cMaxMem=(char*)(p_uaSizeMalloc + *p_uaSizeMalloc)-1; #ifdef __DEBUG_MALLOC_MODE__ p_stMyBlockInfo->ulCountMallocBeforeMaxMem = p_stMyBlockInfo->ulNbMalloc; p_stMyBlockInfo->ulCountFreeBeforeMaxMem = p_stMyBlockInfo->uwNbFree; #endif /* __DEBUG_MALLOC_MODE__*/ } }/* end of the if(p_uaTmp != NULL)*/ /* not necessary #ifdef __DEBUG_MALLOC_MODE__ // count the real number of free p_uaTmp = (unitAlloc*)p_stMyBlockInfo->p_cFirstFree; for (uwI=0; *(p_uaTmp+1) != (unitAlloc)0; uwI++, p_uaTmp = (unitAlloc*) *(p_uaTmp+1)); p_stMyBlockInfo->uwNbFree = uwI; p_uaTmp = p_vMemBlock; #endif __DEBUG_MALLOC_MODE__ */ Mmg_MLeaveCriticalSection(); return ((void *) p_uaTmp); }/* There are no space around the allocation*/ }/* we want to increase the alocation*/ /* not necessary #ifdef __DEBUG_MALLOC_MODE__ // count the real number of free p_uaTmp = (unitAlloc*)p_stMyBlockInfo->p_cFirstFree; for (uwI=0; *(p_uaTmp+1) != (unitAlloc)0; uwI++, p_uaTmp = (unitAlloc*) *(p_uaTmp+1)); p_stMyBlockInfo->uwNbFree = uwI; #endif __DEBUG_MALLOC_MODE__ */ Mmg_MLeaveCriticalSection(); return (p_vMemBlock); /* nothing done*/ }/* of the elese b_ucFound is set*/ }/*fn_p_vStaRealloc */ /* ================*/ /* ##-########################### ## DYNAMYC & STATIC MODE ## General kernel of allocation, reallocation & free ############################## */ #ifdef __DYNAMIC_MALLOC_ALLOWED__ /* ##F#=================================================================================== NAME : fn_p_vGenAlloc DESCRIPTION : Allocate a memory zone in the channel using the corresponding Mode INPUT : Size Channel Id OUTPUT : Pointeur on the zone allocated ========================================================================================= CREATION : 06-11-97/Pierrick Crepy =======================================================================================*/ void * fn_p_vGenAlloc (unsigned long ulSize, unsigned char ucChannel){ /* ===============*/ #ifdef USE_PROFILER #ifndef U64 MMG_fn_vRegisterMemoryAllocation (ucChannel , ulSize); #endif #endif #if defined(U64) && !defined(RETAIL) if(ulSize<=0) { osSyncPrintf("Try to alloc %ld bytes!!\n",ulSize); ASM_BREAK; } #endif /* U64 && !RETAIL */ if (Mmg_M_ucIsStaticMode(ucChannel)) { #ifdef SHOW_RAST_MEM tdstBlockInfoPriv * p_stMyBlockInfo = (tdstBlockInfoPriv *) g_d_stCurrentModeInfo[ucChannel].p_vTdstBlockInfoOrTdstDynInfo; if(p_stMyBlockInfo->p_cFirstFree != C_FirstFreeValueForBlockWithoutFree) { unsigned long ul=ulSize; Mmg_M_BigBoundSize (ul, C_uwAllocSize); ul >>= C_uwShiftAllocSize; ul += (C_ucMallocHeaderSize + C_ucMallocFooterSize); ul <<= C_uwShiftAllocSize; RM_g_ulRealSize+=ul; #ifdef SHOW_RAST_MEM_FOR_DESIGNER RMFD_g_ulRealSize[RMFD_g_tdeRastMemSuperType]+=ul; #endif /* SHOW_RAST_MEM_FOR_DESIGNER */ } else { unsigned long ul=ulSize; #ifdef D_CheckSystemForBlockWithoutFree tdstInformationHeaderOfBolckWithoutFree *p_stInfoHeaderBolck=(tdstInformationHeaderOfBolckWithoutFree *)p_stMyBlockInfo->p_cBeginBlock; if(p_stInfoHeaderBolck->ucMode & C_Check_AlignementFlag) { Mmg_M_BigBoundSize (ul, p_stInfoHeaderBolck->ucAlignment); } #endif /* D_CheckSystemForBlockWithoutFree */ RM_g_ulRealSize+=ul; #ifdef SHOW_RAST_MEM_FOR_DESIGNER RMFD_g_ulRealSize[RMFD_g_tdeRastMemSuperType]+=ul; #endif /* SHOW_RAST_MEM_FOR_DESIGNER */ } RM_g_ulAskedSize+=ulSize; #ifdef SHOW_RAST_MEM_FOR_DESIGNER RMFD_g_ulAskedSize[RMFD_g_tdeRastMemSuperType]+=ulSize; #endif /* SHOW_RAST_MEM_FOR_DESIGNER */ #endif /* SHOW_RAST_MEM */ #if !defined(RETAIL) && !defined(U64) /* Il we must save binary datas, set the allocated mem to 0,*/ /* to avoid wrong pointer detection */ if( MMG_g_bResetMemOnAllocation ) { char *p_cAllocatedMem = fn_p_vStaAlloc (ulSize, ucChannel); if( p_cAllocatedMem ) { Mmg_M_BigBoundSize (ulSize, C_uwAllocSize); memset( p_cAllocatedMem, 0, ulSize ); } return p_cAllocatedMem; } else #endif /* ! RETAIL && ! U64*/ return (fn_p_vStaAlloc (ulSize, ucChannel)); } else { #ifdef SHOW_RAST_MEM unsigned long ul=ulSize; Mmg_M_BigBoundSize (ul, C_uwAllocSize); ul >>= C_uwShiftAllocSize; ul += (C_ucMallocHeaderSize + C_ucMallocFooterSize); ul <<= C_uwShiftAllocSize; RM_g_ulRealSize+=ul; #ifdef SHOW_RAST_MEM_FOR_DESIGNER RMFD_g_ulRealSize[RMFD_g_tdeRastMemSuperType]+=ul; #endif /* SHOW_RAST_MEM_FOR_DESIGNER */ RM_g_ulAskedSize+=ulSize; #ifdef SHOW_RAST_MEM_FOR_DESIGNER RMFD_g_ulAskedSize[RMFD_g_tdeRastMemSuperType]+=ulSize; #endif /* SHOW_RAST_MEM_FOR_DESIGNER */ #endif /* SHOW_RAST_MEM */ return (fn_p_vDynAlloc (ulSize, ucChannel)); } }/* end of fn_p_vAlloc*/ /* ##F#=================================================================================== NAME : fn_p_vGenFree DESCRIPTION : Free a memory zone in the channel using the corresponding Mode INPUT : Pointer on the zone allocated Channel Id ========================================================================================= CREATION : 06-11-97/Pierrick Crepy =======================================================================================*/ void fn_vGenFree (void *p_vMemBlock, unsigned char ucChannel){ /* ===========*/ #ifdef USE_PROFILER #ifndef U64 MMG_fn_vRegisterMemoryFree (ucChannel , p_vMemBlock); #endif #endif if (Mmg_M_ucIsStaticMode(ucChannel)) fn_vStaFree (p_vMemBlock, ucChannel); else fn_vDynFree (p_vMemBlock, ucChannel); }/*end of fn_vFree */ /* ##F#=================================================================================== NAME : fn_p_vGenRealloc DESCRIPTION : Reallocate a memory zone in the channel using the corresponding Mode INPUT : Pointer on the zone allocated Size Channel Id OUTPUT : Pointeur on the new zone allocated ========================================================================================= CREATION : 06-11-97/Pierrick Crepy =======================================================================================*/ void * fn_p_vGenRealloc (void *p_vMemBlock, unsigned long ulSize, unsigned char ucChannel){ /* ================*/ if (Mmg_M_ucIsStaticMode(ucChannel)) #if !defined(RETAIL) && !defined(U64) /* Il we must save binary datas, set the allocated mem to 0,*/ /* to avoid wrong pointer detection */ if( MMG_g_bResetMemOnAllocation ) { unsigned long ulPrevSize = *((unsigned long *)p_vMemBlock-1); p_vMemBlock = fn_p_vStaRealloc (p_vMemBlock, ulSize, ucChannel); if( p_vMemBlock ) { long lSizeDiff = *((unsigned long *)p_vMemBlock-1) - ulPrevSize; if( lSizeDiff > 0 ) memset( (unsigned long *)p_vMemBlock+ulPrevSize-1, 0, lSizeDiff << C_uwShiftAllocSize ); } return p_vMemBlock; } else #endif /* ! RETAIL && ! U64*/ return (fn_p_vStaRealloc (p_vMemBlock, ulSize, ucChannel)); else return (fn_p_vDynRealloc (p_vMemBlock, ulSize, ucChannel)); }/* end of fn_p_vRealloc*/ #endif /* __DYNAMIC_MALLOC_ALLOWED__*/ /* ##-########################### ## Management of Test ############################## */ /* ##F#=================================================================================== NAME : Mmg_fn_ulmsize DESCRIPTION : return the size in byte used for the allocation of a zone INPUT : Pointer on the allocated zone OUTPUT : Real size of the zone (including the management data) ========================================================================================= CREATION : 06-11-97/Pierrick Crepy =======================================================================================*/ #ifndef _FIRE_DEADCODE_U64_ unsigned long Mmg_fn_ulmsize(void *p_vMemBlock){ unitAlloc * p_uaPtr; #ifdef __DEBUG_MALLOC_MODE__ #if defined(__ERROR_STRINGS__) && defined(__FATAL_ERR_MMG__) char szErrTxt[C_ucSizeOfErrTxt]; #endif /*defined(__ERROR_STRINGS__) && defined(__FATAL_ERR_MMG__)*/ p_uaPtr = (unitAlloc *)p_vMemBlock; p_uaPtr--; #ifdef __FATAL_ERR_MMG__ if (*p_uaPtr != (unitAlloc)C_uaBeginKey){ #ifdef __ERROR_STRINGS__ sprintf(szErrTxt,"Yes,at the address 0X%X there is the value 0X%X\nIt's quite different to the expected 'C_uaBeginKey' value (0X%X)", p_uaPtr, (unitAlloc)*p_uaPtr, C_uaBeginKey); Mmg_M_UpdateLastError (E_uwMmgPbOverflowBefore, szErrTxt); #else /*__ERROR_STRINGS__*/ Mmg_M_UpdateLastError (E_uwMmgPbOverflowBefore, NULL); #endif /*__ERROR_STRINGS__*/ } #endif /*__FATAL_ERR_MMG__*/ p_uaPtr = ((unitAlloc *)p_vMemBlock) + *(p_uaPtr-1)/*size*/ - C_ucMallocHeaderSize - C_ucMallocFooterSize; #ifdef __FATAL_ERR_MMG__ if (*p_uaPtr != (unitAlloc) C_uaEndKey){ #ifdef __ERROR_STRINGS__ sprintf(szErrTxt,"Yes,at the address 0X%X there is the value 0X%X\nIt's quite different to the expected 'C_uaEndKey' value (0X%X)", p_uaPtr, (unitAlloc)*p_uaPtr, C_uaEndKey); Mmg_M_UpdateLastError (E_uwMmgPbOverflowAfter, szErrTxt); #else /*__ERROR_STRINGS__*/ Mmg_M_UpdateLastError (E_uwMmgPbOverflowAfter, NULL); #endif /*__ERROR_STRINGS__*/ } #endif /*__FATAL_ERR_MMG__*/ #endif /*__DEBUG_MALLOC_MODE__*/ p_uaPtr = (unitAlloc *)p_vMemBlock; #ifdef __DEBUG_MALLOC_MODE__ p_uaPtr-=2; #else /*__DEBUG_MALLOC_MODE__*/ p_uaPtr--; #endif /*__DEBUG_MALLOC_MODE__*/ return ((unsigned long) ((*p_uaPtr)<< C_uwShiftAllocSize)); }/* end of Mmg_fn_ulmsize*/ #endif /* _FIRE_DEADCODE_U64_ */ /* ##F#=================================================================================== NAME : Mmg_fn_vTestMallocIntegrityAt DESCRIPTION : Check the integrity of an allocated zone (only in debug mode) INPUT : Pointer on the block structure ========================================================================================= CREATION : 06-11-97/Pierrick Crepy =======================================================================================*/ void Mmg_fn_vTestMallocIntegrityAt(void *p_vMemBlock) { #ifdef __DEBUG_MALLOC_MODE__ unitAlloc * p_uaPtr; #if defined(__ERROR_STRINGS__) && defined(__FATAL_ERR_MMG__) char szErrTxt[C_ucSizeOfErrTxt]; #endif /*defined(__ERROR_STRINGS__) && defined(__FATAL_ERR_MMG__)*/ p_uaPtr = (unitAlloc *)p_vMemBlock; p_uaPtr--; #ifdef __FATAL_ERR_MMG__ if (*p_uaPtr != (unitAlloc)C_uaBeginKey){ #ifdef __ERROR_STRINGS__ sprintf(szErrTxt,"Yes,at the address 0X%X there is the value 0X%X\nIt's quite different to the expected 'C_uaBeginKey' value (0X%X)", p_uaPtr, (unitAlloc)*p_uaPtr, C_uaBeginKey); Mmg_M_UpdateLastError (E_uwMmgPbOverflowBefore, szErrTxt); #else /*__ERROR_STRINGS__*/ Mmg_M_UpdateLastError (E_uwMmgPbOverflowBefore, NULL); #endif /*__ERROR_STRINGS__*/ } #endif /*__FATAL_ERR_MMG__*/ p_uaPtr = ((unitAlloc *)p_vMemBlock) + *(p_uaPtr-1)/*size*/ - C_ucMallocHeaderSize - C_ucMallocFooterSize; #ifdef __FATAL_ERR_MMG__ if (*p_uaPtr != (unitAlloc) C_uaEndKey){ #ifdef __ERROR_STRINGS__ sprintf(szErrTxt,"Yes,at the address 0X%X there is the value 0X%X\nIt's quite different to the expected 'C_uaEndKey' value (0X%X)", p_uaPtr, (unitAlloc)*p_uaPtr, C_uaEndKey); Mmg_M_UpdateLastError (E_uwMmgPbOverflowAfter, szErrTxt); #else /*__ERROR_STRINGS__*/ Mmg_M_UpdateLastError (E_uwMmgPbOverflowAfter, NULL); #endif /*__ERROR_STRINGS__*/ } #endif /*__FATAL_ERR_MMG__*/ #endif /*__DEBUG_MALLOC_MODE__*/ }/* end of Mmg_fn_vTestMallocIntegrityAt*/ /* ##F#=================================================================================== NAME : Mmg_fn_vTestMalloc DESCRIPTION : Check integrity for all allocation (only in debug mode) ========================================================================================= CREATION : 06-11-97/Pierrick Crepy =======================================================================================*/ void Mmg_fn_vTestMalloc() /*///////////////////*/ { #ifdef __DEBUG_MALLOC_MODE__ unsigned char ucBlockId; unsigned char ucModuleId; unsigned long ulNumMalloc; tdstBlockInfoPriv *p_stMyBlockInfo; tdstMallocInfo *p_stMyMallocInfo; unitAlloc * p_uaPtr; tdstBlockInfoPriv *a_stMyBlockInfo; #ifdef __DYNAMIC_MALLOC_ALLOWED__ tdstDynInfo *p_stMyDynInfo; #endif /*__DYNAMIC_MALLOC_ALLOWED__*/ #ifdef __ERROR_STRINGS__ char szErrTxt[C_ucSizeOfErrTxt]; #endif /*__ERROR_STRINGS__*/ #ifdef __DYNAMIC_MALLOC_ALLOWED__ for (ucModuleId=0; ucModuleId < g_ucErmNbOfModule; ucModuleId++){ p_stMyDynInfo = g_d_p_stMmgModuleDynInfo[ucModuleId]; if (p_stMyDynInfo != NULL){ for (ulNumMalloc=0; ulNumMalloc < p_stMyDynInfo->ulNbDynamicMalloc; ulNumMalloc++){ p_stMyMallocInfo = (p_stMyDynInfo->d_stDynamicMallocInfo) + ulNumMalloc; p_uaPtr = (unitAlloc *)(p_stMyMallocInfo->p_cBeginMalloc); p_uaPtr--; #ifdef __FATAL_ERR_MMG__ if (*p_uaPtr != (unitAlloc)C_uaBeginKey){ #ifdef __ERROR_STRINGS__ sprintf(szErrTxt,"Yes,at the address 0X%X there is the value 0X%X\nIt's quite different to the expected 'C_uaBeginKey' value (0X%X)", p_uaPtr, (unitAlloc)*p_uaPtr, C_uaBeginKey); /*Mmg_M_UpdateLastErrorWithCurrentModeInfo (E_uwMmgPbDynOverflowBefore, szErrTxt, ucChannel);*/ Mmg_M_UpdateLastErrorWithModuleIdAnducModeReference(ucModuleId, E_ucDynamic, E_uwMmgPbDynOverflowBefore, szErrTxt); #else /*__ERROR_STRINGS__*/ Mmg_M_UpdateLastErrorWithModuleIdAnducModeReference(ucModuleId, E_ucDynamic, E_uwMmgPbDynOverflowBefore, NULL); #endif /*__ERROR_STRINGS__*/ } #endif /*__FATAL_ERR_MMG__*/ p_uaPtr = (unitAlloc *)(p_stMyMallocInfo->p_cEndMalloc + 1); #ifdef __FATAL_ERR_MMG__ if (*p_uaPtr != (unitAlloc) C_uaEndKey){ #ifdef __ERROR_STRINGS__ sprintf(szErrTxt,"Yes,at the address 0X%X there is the value 0X%X\nIt's quite different to the expected 'C_uaEndKey' value (0X%X)", p_uaPtr, (unitAlloc)*p_uaPtr, C_uaEndKey); /*Mmg_M_UpdateLastErrorWithCurrentModeInfo (E_uwMmgPbDynOverflowAfter, szErrTxt, ucChannel);*/ Mmg_M_UpdateLastErrorWithModuleIdAnducModeReference(ucModuleId, E_ucDynamic, E_uwMmgPbDynOverflowAfter, szErrTxt ); #else /*__ERROR_STRINGS__*/ Mmg_M_UpdateLastErrorWithModuleIdAnducModeReference(ucModuleId, E_ucDynamic, E_uwMmgPbDynOverflowAfter, NULL); #endif /*__ERROR_STRINGS__*/ } #endif /*__FATAL_ERR_MMG__*/ }/* for */ } /*if not NULL*/ }/* end of for module*/ #endif /*__DYNAMIC_MALLOC_ALLOWED__*/ for (ucModuleId=0; ucModuleId < g_ucErmNbOfModule; ucModuleId++){ a_stMyBlockInfo = g_a_p_stMmgModuleBlocksInfo[ucModuleId]; if ((a_stMyBlockInfo == NULL) || (a_stMyBlockInfo->p_cFirstFree == C_FirstFreeValueForBlockWithoutFree )) continue; else{ for (ucBlockId=0; ucBlockIdp_cBeginBlock == C_p_cBlockNotValidKey) break;/* the block is not initialized*/ if ( (p_stMyBlockInfo->p_cBeginBlock == NULL) || (p_stMyBlockInfo->p_cEndBlock == NULL)|| (p_stMyBlockInfo->p_cBeginBlock > p_stMyBlockInfo->p_cEndBlock) ) { #ifdef __ERROR_STRINGS__ if (p_stMyBlockInfo->p_cBeginBlock == NULL) sprintf(szErrTxt, "p_cBeginBlock == NULL\n"); else if(p_stMyBlockInfo->p_cEndBlock == NULL) sprintf(szErrTxt, "p_cEndBlock == NULL\n"); else if (p_stMyBlockInfo->p_cBeginBlock > p_stMyBlockInfo->p_cEndBlock) sprintf(szErrTxt, "p_cBeginBlock > p_cEndBlock\n"); /*Mmg_M_UpdateLastErrorWithCurrentModeInfo (E_uwMmgPbInvalidMallocInfo, szErrTxt, ucChannel);*/ Mmg_M_UpdateLastErrorWithModuleIdAnducModeReference(ucModuleId, ucBlockId, E_uwMmgPbInvalidMallocInfo, szErrTxt); #else /*__ERROR_STRINGS__*/ Mmg_M_UpdateLastErrorWithModuleIdAnducModeReference(ucModuleId, ucBlockId, E_uwMmgPbInvalidMallocInfo, NULL); #endif /*__ERROR_STRINGS__*/ break; } Mmg_fn_vTestNbFree(ucModuleId, ucBlockId, p_stMyBlockInfo);/*!! yob !!a virer just pour tester la validite de uwNbFree !! yob !!*/ /* test of the allocation size*/ #ifdef __ADD_PLACE_FOR_DEBUG_INFORMATION__ #ifdef __WARNING3_ERR_MMG__ if ( (p_stMyBlockInfo->p_cMaxMem - ((( p_stMyBlockInfo->ulCountMallocBeforeMaxMem) * (C_ucDebugInformationLoss< (p_stMyBlockInfo->p_cEndBlock - (p_stMyBlockInfo->ulMaxNbStaticMalloc*(C_ucDebugInformationLoss<p_cMaxMem, p_stMyBlockInfo->ulCountMallocBeforeMaxMem); Mmg_M_UpdateLastErrorWithModuleIdAnducModeReference(ucModuleId, ucBlockId, E_uwMmgPbBLockFull, szErrTxt); #else /*__ERROR_STRINGS__*/ Mmg_M_UpdateLastErrorWithModuleIdAnducModeReference(ucModuleId, ucBlockId, E_uwMmgPbBLockFull, NULL); #endif /*__ERROR_STRINGS__*/ } #endif/*__WARNING3_ERR_MMG__*/ #endif /*__ADD_PLACE_FOR_DEBUG_INFORMATION__*/ for (ulNumMalloc=0; ulNumMalloc < p_stMyBlockInfo->ulNbMalloc; ulNumMalloc++){ p_stMyMallocInfo = (p_stMyBlockInfo->d_stMallocInfo)+ulNumMalloc; p_uaPtr = (unitAlloc *)(p_stMyMallocInfo->p_cBeginMalloc); p_uaPtr--; #ifdef __FATAL_ERR_MMG__ if (*p_uaPtr != (unitAlloc)C_uaBeginKey){ #ifdef __ERROR_STRINGS__ sprintf(szErrTxt,"Yes,at the address 0X%X there is the value 0X%X\nIt's quite different to the expected 'C_uaBeginKey' value (0X%X)", p_uaPtr, (unitAlloc)*p_uaPtr, C_uaBeginKey); /*Mmg_M_UpdateLastErrorWithCurrentModeInfo (E_uwMmgPbStaOverflowBefore, szErrTxt, ucChannel);*/ Mmg_M_UpdateLastErrorWithModuleIdAnducModeReference(ucModuleId, ucBlockId, E_uwMmgPbStaOverflowBefore, szErrTxt); #else /*__ERROR_STRINGS__*/ Mmg_M_UpdateLastErrorWithModuleIdAnducModeReference(ucModuleId, ucBlockId, E_uwMmgPbStaOverflowBefore, NULL); #endif /*__ERROR_STRINGS__*/ } #endif /*__FATAL_ERR_MMG__*/ p_uaPtr = (unitAlloc *)(p_stMyMallocInfo->p_cEndMalloc + 1); #ifdef __FATAL_ERR_MMG__ if (*p_uaPtr != (unitAlloc) C_uaEndKey){ #ifdef __ERROR_STRINGS__ sprintf(szErrTxt,"Yes,at the address 0X%X there is the value 0X%X\nIt's quite different to the expected 'C_uaEndKey' value (0X%X)", p_uaPtr, (unitAlloc)*p_uaPtr, C_uaEndKey); /*Mmg_M_UpdateLastErrorWithCurrentModeInfo (E_uwMmgPbStaOverflowAfter, szErrTxt, ucChannel);*/ Mmg_M_UpdateLastErrorWithModuleIdAnducModeReference(ucModuleId, ucBlockId, E_uwMmgPbStaOverflowAfter, szErrTxt); #else /*__ERROR_STRINGS__*/ Mmg_M_UpdateLastErrorWithModuleIdAnducModeReference(ucModuleId, ucBlockId, E_uwMmgPbStaOverflowAfter, NULL); #endif /*__ERROR_STRINGS__*/ } #endif /*__FATAL_ERR_MMG__*/ } }/* end of for block*/ } }/* end of for module*/ #endif /*__DEBUG_MALLOC_MODE__*/ }/* Mmg_fn_vTestMalloc*/ /*---------*/ /* Debug --*/ /*---------*/ /* ##F#=================================================================================== NAME : fn_vSortMallocInfoTable DESCRIPTION : Sort the malloc info table by block address ascending (only in debug mode) INPUT : Pointer on malloc info structure Table Size ========================================================================================= CREATION : 06-11-97/Pierrick Crepy =======================================================================================*/ #ifndef _FIRE_DEADCODE_U64_ void fn_vSortMallocInfoTable (tdstMallocInfo * p_stMyMallocInfo, unsigned long ulSizeTable){ #ifdef __DEBUG_MALLOC_MODE__ unsigned long ulI, ulJ; tdstMallocInfo stTmp; for (ulI=0; ulI < ulSizeTable-1; ulI++){ for (ulJ=(unsigned short)(ulI+1); ulJ < ulSizeTable; ulJ++){ if ((p_stMyMallocInfo+ulJ)->p_cBeginMalloc < (p_stMyMallocInfo+ulI)->p_cBeginMalloc){ stTmp = *(p_stMyMallocInfo+ulI); *(p_stMyMallocInfo+ulI) = *(p_stMyMallocInfo+ulJ); *(p_stMyMallocInfo+ulJ) = stTmp; } } } #endif /*__DEBUG_MALLOC_MODE__*/ }/*lint !e715: p_stMyMallocInfo & ulSizeTable(line 1836) not referenced*/ #endif /* _FIRE_DEADCODE_U64_ */ /* ##F#=================================================================================== NAME : Mmg_fn_vPrintAllDynamicMalloc DESCRIPTION : Print the map of dynamic allocation for a module (only in debug mode) INPUT : Module Id Pointer on dynamic malloc info structure Flag to indicate that info must be sorted ========================================================================================= CREATION : 06-11-97/Pierrick Crepy =======================================================================================*/ #ifndef _FIRE_DEADCODE_U64_ #ifdef __DYNAMIC_MALLOC_ALLOWED__ #ifdef __DEBUG_MALLOC_MODE__ void Mmg_fn_vPrintAllDynamicMalloc (unsigned char ucModuleId, struct tdstDynInfo_ *p_stMyDynInfo, unsigned char ucSorted){ /* -------------------------*/ tdstMallocInfo * p_stMyMallocInfo; unsigned char ucI; unsigned long ulI; unsigned long ulLength,ulMaxSize=0; char a_cHistoMalloc [C_ucNbColumnForHisto+3];/* +3 for '\n'+('\n'+)'\0'*/ char a_cLine [C_ucNbPrintedColumn], a_cLine2 [C_ucNbPrintedColumn]; p_stMyMallocInfo = p_stMyDynInfo->d_stDynamicMallocInfo; if (ucSorted) fn_vSortMallocInfoTable (p_stMyMallocInfo, p_stMyDynInfo->ulNbDynamicMalloc); /* fill up a_HistoMalloc with '*' */ for (ucI=0; ucI < C_ucNbColumnForHisto+1; ucI++){ a_cHistoMalloc[ucI]= '*'; } /* look for the maximum size*/ for (ulI=0; ulIulNbDynamicMalloc; ulI++, p_stMyMallocInfo++){ ulLength = ((unsigned long)(p_stMyMallocInfo->p_cEndMalloc)) - ((unsigned long)(p_stMyMallocInfo->p_cBeginMalloc)) + 1; if (ulLength>ulMaxSize) ulMaxSize = ulLength; } *a_cLine='\n'; Erm_M_GetModuleInformation(a_cLine+1, ucModuleId); sprintf (a_cLine+strlen(a_cLine),":\n"); Mmg_fn_v_PrintInfoMalloc (a_cLine ); Mmg_fn_v_PrintInfoMalloc (" The list of all Dynamic Mallocs\n"); Mmg_fn_v_PrintInfoMalloc ("---------------------------------\n\n"); /* print the map*/ p_stMyMallocInfo = p_stMyDynInfo->d_stDynamicMallocInfo; for (ulI=0; ulIulNbDynamicMalloc; ulI++, p_stMyMallocInfo++){ /* the malloc*/ ulLength = ((unsigned long)(p_stMyMallocInfo->p_cEndMalloc)) - ((unsigned long) (p_stMyMallocInfo->p_cBeginMalloc)) + 1; sprintf (a_cLine, "Malloc -%d-\t: 0x%X->0x%X\t\t(%db; %.2fKb; %.2fMb)\n", ulI+1, (long)p_stMyMallocInfo->p_cBeginMalloc, (long)p_stMyMallocInfo->p_cEndMalloc, ulLength, (float)ulLength/1024, (float)ulLength/(1024*1024)); if (ulMaxSize) ulLength = ulLength * C_ucNbColumnForHisto / ulMaxSize; else ulLength = 0; if (!ulLength) ulLength = 1; a_cHistoMalloc [ulLength] = '\n'; a_cHistoMalloc [ulLength+1] = '\0'; Mmg_fn_v_PrintInfoMalloc (a_cHistoMalloc); Mmg_fn_v_PrintInfoMalloc (a_cLine ); /*lint -save -e701 : Shift left of signed quantity (int)*/ sprintf (a_cLine2, "Total place\t: 0x%X->0x%X\t\t(%db; %.2fKb; %.2fMb)\n", (unsigned long)(p_stMyMallocInfo->p_cBeginMalloc - (C_ucMallocHeaderSize<p_cEndMalloc + (C_ucMallocFooterSize<p_cBeginMalloc - (C_ucMallocHeaderSize<p_cBeginMalloc - (C_ucMallocHeaderSize<p_cBeginMalloc - (C_ucMallocHeaderSize<p_cFirstFree == C_FirstFreeValueForBlockWithoutFree){ Mmg_M_UpdateLastError(E_uwMmgPbNoAvailableFunctionForBlockWithoutFree, NULL) } #endif /*D_CheckSystemForBlockWithoutFree*/ p_stMyMallocInfo = p_stMyBlockInfo->d_stMallocInfo; if (ucSorted) fn_vSortMallocInfoTable (p_stMyMallocInfo, p_stMyBlockInfo->ulNbMalloc); /* fill up a_HistoMalloc with '*', a_HistoMalloc with 'O' & a_lineEnd with '_'*/ for (ucI=0; ucI < C_ucNbColumnForHisto+1; ucI++){ a_cHistoMalloc[ucI]= '*'; a_cHistoFree[ucI]= 'O'; a_cLineEnd[ucI]='_'; } a_cLineEnd [C_ucNbColumnForHisto]='\0'; /* look for the maximum size*/ for (ulI=0; ulIulNbMalloc; ulI++, p_stMyMallocInfo++){ ulLength = ((unsigned long)(p_stMyMallocInfo->p_cEndMalloc)) - ((unsigned long)(p_stMyMallocInfo->p_cBeginMalloc)) + 1; if (ulLength>ulMaxSize) ulMaxSize = ulLength; } /* max with free*/ for ( p_uaPtr = (unitAlloc *) p_stMyBlockInfo->p_cFirstFree; (p_uaPtr != (unitAlloc *)0) && (*(p_uaPtr +1) != (unitAlloc)0);/* Do not take the last free.*/ p_uaPtr = (unitAlloc *) *(p_uaPtr+1)/*go to next*/){ if (((*p_uaPtr)< (unitAlloc) ulMaxSize) ulMaxSize = (unsigned long) ((*p_uaPtr)<d_stMallocInfo; uwCounterFree = 0; p_uaPtr=(unitAlloc *) p_stMyBlockInfo->p_cFirstFree; for (ulI=0; ulIulNbMalloc; ulI++, p_stMyMallocInfo++){ if ( (*(p_uaPtr+1) != (unitAlloc)0) && ( ((char *) p_uaPtr) < p_stMyMallocInfo->p_cBeginMalloc ) ){ /* we have a free before the malloc*/ uwCounterFree++; ulLength = (unsigned long) ((*p_uaPtr) << C_uwShiftAllocSize) ; sprintf (a_cLine, "Free -%d-\t: 0x%X->0x%X\t\t(%db; %.2fKb; %.2fMb)\n", uwCounterFree, (unsigned long) p_uaPtr, (unsigned long)(((char *)(p_uaPtr+*p_uaPtr)) -1), ulLength, (float)ulLength/1024, (float)ulLength/(1024*1024)); if (ulMaxSize) ulLength = ulLength * C_ucNbColumnForHisto / ulMaxSize; else ulLength = 0; if (!ulLength) ulLength = 1; a_cHistoFree [ulLength] = '\n'; a_cHistoFree [ulLength+1] = '\0'; Mmg_fn_v_PrintInfoMalloc (a_cHistoFree); Mmg_fn_v_PrintInfoMalloc (a_cLine ); a_cHistoFree [ulLength+1] = '\n'; a_cHistoFree [ulLength+2] = '\0'; Mmg_fn_v_PrintInfoMalloc (a_cHistoFree); a_cHistoFree[ulLength++]= 'O';/* reset the Histofgram fill up with 'O' */ a_cHistoFree[ulLength++]= 'O';/* reset the Histofgram fill up with 'O' */ a_cHistoFree[ulLength]= 'O';/* reset the Histofgram fill up with 'O' */ p_uaPtr = (unitAlloc *) *(p_uaPtr +1); /* go to next*/ }/* end of if of my free */ /* the malloc*/ ulLength = ((unsigned long)(p_stMyMallocInfo->p_cEndMalloc)) - ((unsigned long) (p_stMyMallocInfo->p_cBeginMalloc)) + 1; sprintf (a_cLine, "Malloc -%d-\t: 0x%X->0x%X\t\t(%db; %.2fKb; %.2fMb)\n", ulI+1, (unsigned long)(p_stMyMallocInfo->p_cBeginMalloc), (unsigned long)(p_stMyMallocInfo->p_cEndMalloc), ulLength, (float)ulLength/1024, (float)ulLength/(1024*1024)); if (ulMaxSize) ulLength = ulLength * C_ucNbColumnForHisto / ulMaxSize; else ulLength = 0; if (!ulLength) ulLength = 1; a_cHistoMalloc [ulLength] = '\n'; a_cHistoMalloc [ulLength+1] = '\0'; Mmg_fn_v_PrintInfoMalloc (a_cHistoMalloc); Mmg_fn_v_PrintInfoMalloc (a_cLine ); /*lint -save -e790 : Suspicious truncation, integral to float*/ sprintf (a_cLine2, "Total place\t: 0x%X->0x%X\t\t(%db; %.2fKb; %.2fMb)\n", (unsigned long)(p_stMyMallocInfo->p_cBeginMalloc - (C_ucMallocHeaderSize<p_cEndMalloc + (C_ucMallocFooterSize<p_cBeginMalloc - (C_ucMallocHeaderSize<p_cBeginMalloc - (C_ucMallocHeaderSize<p_cBeginMalloc - (C_ucMallocHeaderSize<ulMaxNbStaticMalloc*(C_ucDebugInformationLoss<ulNbMalloc))*(C_ucDebugInformationLoss<ulMaxNbStaticMalloc*(C_ucDebugInformationLoss<ulMaxNbStaticMalloc*(C_ucDebugInformationLoss<ulMaxNbStaticMalloc*(C_ucDebugInformationLoss<0x%X\n", (unsigned long)p_uaPtr, (unsigned long)(((char *)(p_uaPtr+*p_uaPtr)) -1)); Mmg_fn_v_PrintInfoMalloc (a_cLine2); sprintf (a_cLine2, "\t(%db; %.2fKb; %.2fMb)\n", ulLength, (float)ulLength/1024, (float)ulLength/(1024*1024)); Mmg_fn_v_PrintInfoMalloc (a_cLine2); ulLength -= (p_stMyBlockInfo->ulMaxNbStaticMalloc*(C_ucDebugInformationLoss<ulNbMalloc)) * (C_ucDebugInformationLoss<0x%X\n", (unsigned long)p_uaPtr, (unsigned long)(((char *)p_uaPtr)+ulLength-1)); } else{ sprintf (a_cLine2, "(pessimistic)Estimated remain for other allocations ", (unsigned long)p_uaPtr, (unsigned long)(((char *)p_uaPtr)+ulLength-1)); } Mmg_fn_v_PrintInfoMalloc (a_cLine2); sprintf (a_cLine2, "\t(%db; %.2fKb; %.2fMb)\n", ulLength, (float)ulLength/1024, (float)ulLength/(1024*1024)); Mmg_fn_v_PrintInfoMalloc (a_cLine2); sprintf(a_cLine2, "%s\n\n", a_cLineEnd); Mmg_fn_v_PrintInfoMalloc (a_cLine2); } #endif /*__DEBUG_MALLOC_MODE__*/ }/*lint !e715 p_stMyBlockInfo&ucBlockId&szModuleName& (line 1916) not referenced*/ /* end of Mmg_fn_vPrintMapOfBlock*/ /* ##F#=================================================================================== NAME : Mmg_fn_vPrintDebugMapOfBlock DESCRIPTION : Print the map of static allocation for a block (only in debug mode) INPUT : Module Id Pointer on block info structure Block Id ========================================================================================= CREATION : 06-11-97/Pierrick Crepy =======================================================================================*/ /* Modif#5 : new function*/ void Mmg_fn_vPrintDebugMapOfBlock (unsigned char ucModuleId, struct tdstBlockInfoPriv_ *p_stMyBlocksInfo, unsigned char ucBlockId){ /* --------------------*/ #ifdef __DEBUG_MALLOC_MODE__ struct tdstBlockInfoPriv_ *p_stMyBlockInfo = p_stMyBlocksInfo+ucBlockId; unsigned char ucI; unsigned long ulI; unsigned short uwCounterFree; unsigned long ulLength,ulMaxSize=0; char a_cHistoMalloc [C_ucNbColumnForHisto+3];/* +3 for '\n'+('\n'+)'\0'*/ char a_cHistoFree [C_ucNbColumnForHisto+3];/* +3 for '\n'+('\n'+)'\0'*/ char a_cLineEnd [C_ucNbColumnForHisto+2];/* +3 for '\n'+'\0'*/ char a_cLine [C_ucNbPrintedColumn], a_cLine2 [C_ucNbPrintedColumn]; unitAlloc * p_uaPtr; /* fill up a_HistoMalloc with '*', a_HistoMalloc with 'O' & a_lineEnd with '_'*/ for (ucI=0; ucI < C_ucNbColumnForHisto+1; ucI++){ a_cHistoMalloc[ucI]= '*'; a_cHistoFree[ucI]= 'O'; a_cLineEnd[ucI]='_'; } a_cLineEnd [C_ucNbColumnForHisto]='\0'; /* look for the maximum size of malloc or free*/ ulI=0; p_uaPtr=(unitAlloc *)p_stMyBlockInfo->p_cBeginBlock; while (p_uaPtr<(unitAlloc *)p_stMyBlockInfo->p_cEndBlock){ if (*(p_uaPtr+1) == C_uaBeginKey){ /* it's a malloc*/ ulLength = ((*p_uaPtr) - C_ucMallocHeaderSize - C_ucMallocFooterSize); ulLength <<= C_uwShiftAllocSize; if (ulLength>ulMaxSize) ulMaxSize = ulLength; p_uaPtr += (*p_uaPtr); ulI++; } else { /* it's a free*/ if ((p_uaPtr != (unitAlloc *)0) && (*(p_uaPtr +1) != (unitAlloc)0)){/* Do not take the last free.*/ ulLength = (*p_uaPtr); ulLength <<= C_uwShiftAllocSize; if (ulLength > ulMaxSize) ulMaxSize = ulLength; } else { break;/* this is the last free then we go out of the while with p_uaPtr pointed on the last free*/ } p_uaPtr += (*p_uaPtr); } }/*end of while*/ if (ulI != p_stMyBlockInfo->ulNbMalloc){ /*p_uaPtr = (unitAlloc)ulI/0; // just for allowed a breack point*/ } *a_cLine = '\n'; Erm_M_GetModuleInformation(a_cLine+1, ucModuleId); sprintf (a_cLine+strlen(a_cLine),":\n"); Mmg_fn_v_PrintInfoMalloc (a_cLine ); sprintf (a_cLine2, "The Debug list of all Static Mallocs of the block # %d\n", ucBlockId); Mmg_fn_v_PrintInfoMalloc (a_cLine2); Mmg_fn_v_PrintInfoMalloc ("---------------------------------------------------\n\n"); /* print the map*/ uwCounterFree = 0; ulI=0; p_uaPtr=(unitAlloc *)p_stMyBlockInfo->p_cBeginBlock; while (p_uaPtr<(unitAlloc *)p_stMyBlockInfo->p_cEndBlock){ if (*(p_uaPtr+1) == C_uaBeginKey){ /* it's a malloc*/ ulLength = ((*p_uaPtr) - C_ucMallocHeaderSize - C_ucMallocFooterSize)<< C_uwShiftAllocSize; sprintf (a_cLine, "Malloc -%d-\t: 0x%X->0x%X\t\t(%db; %.2fKb; %.2fMb)\n", ulI+1, (unsigned long)(p_uaPtr+C_ucMallocHeaderSize), ((unsigned long)(p_uaPtr+*p_uaPtr-C_ucMallocFooterSize))-1, ulLength, (float)ulLength/1024, (float)ulLength/(1024*1024)); if (ulMaxSize) ulLength = ulLength * C_ucNbColumnForHisto / ulMaxSize; else ulLength = 0; if (!ulLength) ulLength = 1; a_cHistoMalloc [ulLength] = '\n'; a_cHistoMalloc [ulLength+1] = '\0'; Mmg_fn_v_PrintInfoMalloc (a_cHistoMalloc); Mmg_fn_v_PrintInfoMalloc (a_cLine ); /*lint -save -e790 : Suspicious truncation, integral to float*/ sprintf (a_cLine2, "Total place\t: 0x%X->0x%X\t\t(%db; %.2fKb; %.2fMb)\n", (unsigned long)(p_uaPtr), ((unsigned long) (p_uaPtr + *p_uaPtr))-1, (*p_uaPtr)<0x%X\t\t(%db; %.2fKb; %.2fMb)\n", uwCounterFree, (unsigned long) p_uaPtr, (unsigned long)(((char *)(p_uaPtr+*p_uaPtr)) -1), ulLength, (float)ulLength/1024, (float)ulLength/(1024*1024)); if (ulMaxSize) ulLength = ulLength * C_ucNbColumnForHisto / ulMaxSize; else ulLength = 0; if (!ulLength) ulLength = 1; a_cHistoFree [ulLength] = '\n'; a_cHistoFree [ulLength+1] = '\0'; Mmg_fn_v_PrintInfoMalloc (a_cHistoFree); Mmg_fn_v_PrintInfoMalloc (a_cLine ); a_cHistoFree [ulLength+1] = '\n'; a_cHistoFree [ulLength+2] = '\0'; Mmg_fn_v_PrintInfoMalloc (a_cHistoFree); a_cHistoFree[ulLength++]= 'O';/* reset the Histofgram fill up with 'O' */ a_cHistoFree[ulLength++]= 'O';/* reset the Histofgram fill up with 'O' */ a_cHistoFree[ulLength]= 'O';/* reset the Histofgram fill up with 'O' */ } else { break;/* this is the last free then we go out of the while with p_uaPtr pointed on the last free*/ } p_uaPtr += (*p_uaPtr); } }/*end of while*/ #ifdef __ADD_PLACE_FOR_DEBUG_INFORMATION__ sprintf(a_cLine2, "%s\n", a_cLineEnd); Mmg_fn_v_PrintInfoMalloc (a_cLine2); ulLength = (p_stMyBlockInfo->ulMaxNbStaticMalloc*(C_ucDebugInformationLoss<ulNbMalloc))*(C_ucDebugInformationLoss<ulMaxNbStaticMalloc*(C_ucDebugInformationLoss<ulMaxNbStaticMalloc*(C_ucDebugInformationLoss<ulMaxNbStaticMalloc*(C_ucDebugInformationLoss<0x%X\n", (unsigned long)p_uaPtr, (unsigned long)(((char *)(p_uaPtr+*p_uaPtr)) -1)); Mmg_fn_v_PrintInfoMalloc (a_cLine2); sprintf (a_cLine2, "\t(%db; %.2fKb; %.2fMb)\n", ulLength, (float)ulLength/1024, (float)ulLength/(1024*1024)); Mmg_fn_v_PrintInfoMalloc (a_cLine2); ulLength -= (p_stMyBlockInfo->ulMaxNbStaticMalloc*(C_ucDebugInformationLoss<ulNbMalloc)) * (C_ucDebugInformationLoss<0x%X\n", (unsigned long)p_uaPtr, (unsigned long)(((char *)p_uaPtr)+ulLength-1)); } else{ sprintf (a_cLine2, "(pessimistic)Estimated remain for other allocations ", (unsigned long)p_uaPtr, (unsigned long)(((char *)p_uaPtr)+ulLength-1)); } Mmg_fn_v_PrintInfoMalloc (a_cLine2); sprintf (a_cLine2, "\t(%db; %.2fKb; %.2fMb)\n", ulLength, (float)ulLength/1024, (float)ulLength/(1024*1024)); Mmg_fn_v_PrintInfoMalloc (a_cLine2); sprintf(a_cLine2, "%s\n\n", a_cLineEnd); Mmg_fn_v_PrintInfoMalloc (a_cLine2); } #endif /*__DEBUG_MALLOC_MODE__*/ }/*lint !e715 p_stMyBlockInfo&ucBlockId&szModuleName& (line 1916) not referenced*/ /* end of Mmg_fn_vPrintDebugMapOfBlock*/ /* ##-########################### ## Management of Statistic ############################## */ /* ##F#=================================================================================== NAME : Mmg_fn_vPrintBlockStatistic DESCRIPTION : Print statistic on a block (only in debug mode) INPUT : Module Id Pointer on block info structure Block Id ========================================================================================= CREATION : 06-11-97/Pierrick Crepy =======================================================================================*/ void Mmg_fn_vPrintBlockStatistic (unsigned char ucModuleId, struct tdstBlockInfoPriv_ *p_stMyBlocksInfo, unsigned char ucBlockId){ /* -----------------------*/ #ifdef __DEBUG_MALLOC_MODE__ struct tdstBlockInfoPriv_ *p_stMyBlockInfo = p_stMyBlocksInfo+ucBlockId; tdstMallocInfo * p_stMyMallocInfo; unsigned short uwI; unsigned long ulI; unsigned char ucPtr; unsigned long ulLargestMalloc=0, ulSmallestMalloc=0xffffffff, ulLargestFree=0, ulSmallestFree=0xffffffff; unsigned long ulIdLargestMalloc=0xffffffff,ulIdSmallestMalloc=0xffffffff; unsigned char ucPrintedLength; unsigned long ulMaxPrint; unsigned long ulDebugInfoRemain; unsigned short uwCounterFree; unsigned long ulLengthMalloc=0, ulLengthFree=0, ulLength; char a_cMap [C_ucNbColumnForHisto+3];/* +3 for '\n'+(\n)+'\0'*/ char a_cLine [C_ucNbPrintedColumn]; unitAlloc * p_uaPtr;/* used for scan the free space. After scaning the all the free list, p_uaPtr points at the last free*/ #ifdef D_CheckSystemForBlockWithoutFree if (p_stMyBlockInfo->p_cFirstFree == C_FirstFreeValueForBlockWithoutFree){ Mmg_M_UpdateLastError(E_uwMmgPbNoAvailableFunctionForBlockWithoutFree, NULL) } #endif /*D_CheckSystemForBlockWithoutFree*/ /* look for the maximum & mimimum size of all the mallocs*/ p_stMyMallocInfo = p_stMyBlockInfo->d_stMallocInfo; for (ulI=0; ulIulNbMalloc; ulI++, p_stMyMallocInfo++){ ulLength = (unsigned long)(*((unitAlloc *)p_stMyMallocInfo->p_cBeginMalloc - C_ucMallocHeaderSize)); ulLengthMalloc += ulLength; if (ulLength>ulLargestMalloc){ ulLargestMalloc = ulLength; ulIdLargestMalloc = ulI; } if (ulLengthp_cFirstFree; (p_uaPtr != (unitAlloc *)0) && (*(p_uaPtr +1) != (unitAlloc)0);/* Do not take the last free.*/ p_uaPtr = (unitAlloc *) *(p_uaPtr+1)/*go to next*/){ uwCounterFree++; ulLengthFree += (*p_uaPtr); if (*p_uaPtr > (unitAlloc) ulLargestFree) ulLargestFree = (unsigned long) (*p_uaPtr); if (*p_uaPtr < (unitAlloc) ulSmallestFree) ulSmallestFree = (unsigned long) (*p_uaPtr); } #ifdef __ADD_PLACE_FOR_DEBUG_INFORMATION__ ulDebugInfoRemain = (p_stMyBlockInfo->ulMaxNbStaticMalloc*(C_ucDebugInformationLoss<>= C_uwShiftAllocSize;/* convert into unitAlloc*/ if ( ulDebugInfoRemain > (unsigned long)((p_stMyBlockInfo->ulNbMalloc )*C_ucDebugInformationLoss) ){ ulDebugInfoRemain = ulDebugInfoRemain - (unsigned long)((p_stMyBlockInfo->ulNbMalloc )*C_ucDebugInformationLoss); /* ulDebugInfoRemain = remain for debug information in UnitAlloc*/ /* -------------*/ } else ulDebugInfoRemain = 0; #else /*__ADD_PLACE_FOR_DEBUG_INFORMATION__*/ ulDebugInfoRemain = 0; #endif /*__ADD_PLACE_FOR_DEBUG_INFORMATION__*/ /*print the debug map & information*/ ulMaxPrint = ulLengthFree + ulLengthMalloc + (*p_uaPtr)/*the full real last free*/ - ulDebugInfoRemain;/*lint !e613: Possible use of null pointer (p_uaPtr)*/ *a_cLine = '\n'; Erm_M_GetModuleInformation(a_cLine+1, ucModuleId); sprintf (a_cLine+strlen(a_cLine),":\n"); Mmg_fn_v_PrintInfoMalloc (a_cLine ); Mmg_fn_v_PrintInfoMalloc ("=====================================\n"); sprintf (a_cLine," Statistics of the static block #%d:\n", ucBlockId); Mmg_fn_v_PrintInfoMalloc (a_cLine); Mmg_fn_v_PrintInfoMalloc ("=====================================\n"); #ifdef __ADD_PLACE_FOR_DEBUG_INFORMATION__ ulLength = (unsigned long) p_stMyBlockInfo->p_cEndBlock - (unsigned long) p_stMyBlockInfo->p_cBeginBlock + 1 - (p_stMyBlockInfo->ulMaxNbStaticMalloc*(C_ucDebugInformationLoss<0x%X\t(%db; %.2fKb; %.2fMb)\n", (unsigned long)(p_stMyBlockInfo->p_cBeginBlock), (unsigned long)(p_stMyBlockInfo->p_cEndBlock), ulLength, (float)ulLength/1024, (float)ulLength/(1024*1024)); Mmg_fn_v_PrintInfoMalloc (a_cLine); ulLength = (unsigned long) (p_stMyBlockInfo->ulMaxNbStaticMalloc*(C_ucDebugInformationLoss<0x%X\t\t(%db; %.2fKb; %.2fMb)\n", (unsigned long)(p_stMyBlockInfo->p_cBeginBlock), (unsigned long)(p_stMyBlockInfo->p_cEndBlock), ulLength, (float)ulLength/1024, (float)ulLength/(1024*1024)); Mmg_fn_v_PrintInfoMalloc (a_cLine); sprintf (a_cLine, "\t-The 'AddedDebugMemory' correspond to %d allocations\n", p_stMyBlockInfo->ulMaxNbStaticMalloc); Mmg_fn_v_PrintInfoMalloc (a_cLine); sprintf (a_cLine, "\t-There are %d alloactions used now,i.e %.2f%% of the 'AddedDebugMemory'\n", (p_stMyBlockInfo->ulNbMalloc), (float)((p_stMyBlockInfo->ulNbMalloc)*100/ p_stMyBlockInfo->ulMaxNbStaticMalloc) ); Mmg_fn_v_PrintInfoMalloc (a_cLine); #endif /*__ADD_PLACE_FOR_DEBUG_INFORMATION__*/ ulLength = (unsigned long) p_stMyBlockInfo->p_cEndBlock - (unsigned long) p_stMyBlockInfo->p_cBeginBlock + 1; sprintf (a_cLine, "\t-The full size: 0x%X->0x%X\t\t(%db; %.2fKb; %.2fMb)\n", (unsigned long)(p_stMyBlockInfo->p_cBeginBlock), (unsigned long)(p_stMyBlockInfo->p_cEndBlock), ulLength, (float)ulLength/1024, (float)ulLength/(1024*1024)); Mmg_fn_v_PrintInfoMalloc (a_cLine); if ((ulLength-(ulDebugInfoRemain<p_cMaxMem), p_stMyBlockInfo->ulCountMallocBeforeMaxMem, p_stMyBlockInfo->ulCountFreeBeforeMaxMem, (float)((unsigned long) p_stMyBlockInfo->p_cMaxMem - (unsigned long) p_stMyBlockInfo->p_cBeginBlock)*100/(ulLength-(ulDebugInfoRemain<p_cMaxMem), p_stMyBlockInfo->ulCountMallocBeforeMaxMem, p_stMyBlockInfo->ulCountFreeBeforeMaxMem); Mmg_fn_v_PrintInfoMalloc (a_cLine); sprintf (a_cLine, "\t-Address of the first Free Space: 0x%X\n",(unsigned long) (p_stMyBlockInfo->p_cFirstFree)); Mmg_fn_v_PrintInfoMalloc (a_cLine); sprintf (a_cLine, "\t-%d requested reallocations\n",p_stMyBlockInfo->ulNbTotalRealloc); Mmg_fn_v_PrintInfoMalloc (a_cLine); /* compute the general Map */ /* -----------------------*/ /*---------------------------*/ /* the unallocated free space */ /*---------------------------*/ if (ulMaxPrint) ucPrintedLength = (unsigned char) (ulLengthFree * C_ucNbColumnForHisto / ulMaxPrint); else ucPrintedLength = 0; if ((ulLengthFree) && (ucPrintedLength == 0)) ucPrintedLength=1; for (uwI=0; uwI < ucPrintedLength; uwI++){ a_cMap[uwI]='-'; } ucPtr = (unsigned char) uwI; /************************************/ /* the allocated space without loss*/ /************************************/ ulLengthMalloc -= (p_stMyBlockInfo->ulNbMalloc*C_ucDebugInformationLoss); /* loss*/ if (ulMaxPrint){ ucPrintedLength = (unsigned char)( ulLengthMalloc * C_ucNbColumnForHisto / ulMaxPrint); } else ucPrintedLength =0; if ((ulLengthMalloc) && (ucPrintedLength == 0)) ucPrintedLength=1; for (uwI=0; uwI < ucPrintedLength; uwI++){ a_cMap[ucPtr + uwI]='*'; } ucPtr += (unsigned char) uwI; /*+++++++++++++++++++++++++++++*/ /* the loss of allocated & free space*/ /*+++++++++++++++++++++++++++++*/ if (ulMaxPrint){ ucPrintedLength =(unsigned char)((p_stMyBlockInfo->ulNbMalloc )*C_ucDebugInformationLoss /* loss*/ * C_ucNbColumnForHisto / ulMaxPrint); } else ucPrintedLength = 0; if ((ulLengthMalloc) && (ucPrintedLength == 0)) ucPrintedLength=1; for (uwI=0; uwI < ucPrintedLength; uwI++){ a_cMap[ucPtr + uwI]='+'; } ucPtr += (unsigned char) uwI; /*OOOOOOOOOOOOOOOO*/ /* the last first*/ /*OOOOOOOOOOOOOOOO*/ for (uwI=ucPtr; uwI < C_ucNbColumnForHisto; uwI++){ a_cMap[uwI]='O'; } a_cMap[uwI]='\n'; a_cMap[uwI+1]='\0'; /* print the general Map */ #ifdef __ADD_PLACE_FOR_DEBUG_INFORMATION__ Mmg_fn_v_PrintInfoMalloc ("\n===================================================================\n"); Mmg_fn_v_PrintInfoMalloc ("= The General Map of the memory (without any 'AddedDebugMemory'): =\n"); Mmg_fn_v_PrintInfoMalloc ("===================================================================\n\n"); #else /*__ADD_PLACE_FOR_DEBUG_INFORMATION__*/ Mmg_fn_v_PrintInfoMalloc ("\n==================================\n"); Mmg_fn_v_PrintInfoMalloc ("= The General Map of the memory: =\n"); Mmg_fn_v_PrintInfoMalloc ("==================================\n\n"); #endif /*__ADD_PLACE_FOR_DEBUG_INFORMATION__*/ Mmg_fn_v_PrintInfoMalloc (a_cMap); Mmg_fn_v_PrintInfoMalloc (a_cMap); Mmg_fn_v_PrintInfoMalloc (a_cMap); ulMaxPrint = M_Max(ulLengthFree, ulLengthMalloc); ulMaxPrint = M_Max(ulMaxPrint, (*p_uaPtr) - ulDebugInfoRemain);/*lint !e613: Possible use of null pointer (p_uaPtr)*/ Mmg_fn_v_PrintInfoMalloc ("\n=========================\n"); Mmg_fn_v_PrintInfoMalloc ("= Legend & Explanation: =\n"); Mmg_fn_v_PrintInfoMalloc ("=========================\n\n"); /*----------------------------*/ /* the unallocated free space */ /*----------------------------*/ if (ulMaxPrint) ucPrintedLength = (unsigned char)(ulLengthFree * C_ucNbColumnForHisto / ulMaxPrint); else ulLengthFree =0; if (ucPrintedLength == 0) ucPrintedLength=1; for (uwI=0; uwI < ucPrintedLength; uwI++){ a_cMap[uwI]='-'; } a_cMap[uwI]='\n'; a_cMap[uwI+1]='\0'; Mmg_fn_v_PrintInfoMalloc (a_cMap); Mmg_fn_v_PrintInfoMalloc ("Free Unallocated space:\n"); Mmg_fn_v_PrintInfoMalloc (a_cMap); ulLengthFree <<= C_uwShiftAllocSize; sprintf (a_cLine, "\t-Request:%d; current:%d; size : \t%db (%.2fKb; %.2fMb)\n",p_stMyBlockInfo->ulNbTotalFree, uwCounterFree, ulLengthFree, (float)ulLengthFree / 1024, (float)ulLengthFree / (1024*1024)); Mmg_fn_v_PrintInfoMalloc (a_cLine); if (uwCounterFree > 0){/* i.e ulLargestFree > 0*/ ulLargestFree <<= C_uwShiftAllocSize; sprintf (a_cLine, "\t-Size of the largest Free: \t%db (%.2fKb; %.2fMb)\n", ulLargestFree, (float)ulLargestFree/ 1024, (float)ulLargestFree/ (1024*1024)); Mmg_fn_v_PrintInfoMalloc (a_cLine); ulSmallestFree <<= C_uwShiftAllocSize; sprintf (a_cLine, "\t-Size of the smallest Free: \t%db (%.2fKb; %.2fMb)\n", ulSmallestFree, (float)ulSmallestFree/ 1024, (float)ulSmallestFree/ (1024*1024)); Mmg_fn_v_PrintInfoMalloc (a_cLine); if (uwCounterFree){ sprintf (a_cLine, "\t-Average size of Free space: \t%db (%.2fKb; %.2fMb)\n", ulLengthFree/uwCounterFree, ((float)ulLengthFree/(float)uwCounterFree)/ 1024, ((float)ulLengthFree/(float)uwCounterFree)/ (1024*1024)); Mmg_fn_v_PrintInfoMalloc (a_cLine); } } a_cMap[uwI+1]='\n'; a_cMap[uwI+2]='\0'; Mmg_fn_v_PrintInfoMalloc (a_cMap); ulLengthFree >>= C_uwShiftAllocSize; /* restore the unitAlloc unit*/ /************************************/ /* the allocated space without loss*/ /************************************/ if (ulMaxPrint){ ucPrintedLength = (unsigned char)( ulLengthMalloc * C_ucNbColumnForHisto / ulMaxPrint); } else ucPrintedLength = 0; if (ucPrintedLength == 0) ucPrintedLength=1; for (uwI=0; uwI < ucPrintedLength; uwI++){ a_cMap[uwI]='*'; } a_cMap[uwI]='\n'; a_cMap[uwI+1]='\0'; Mmg_fn_v_PrintInfoMalloc (a_cMap); Mmg_fn_v_PrintInfoMalloc ("Allocated space without loss (but with the field 'size of malloc'):\n"); Mmg_fn_v_PrintInfoMalloc (a_cMap); ulLengthMalloc <<= C_uwShiftAllocSize; sprintf (a_cLine, "\t-Request:%d; current:%d; size : \t%db (%.2fKb; %.2fMb)\n",p_stMyBlockInfo->ulNbTotalMalloc, p_stMyBlockInfo->ulNbMalloc, ulLengthMalloc, (float)ulLengthMalloc / 1024, (float)ulLengthMalloc / (1024*1024)); Mmg_fn_v_PrintInfoMalloc (a_cLine); if (ulLargestMalloc > 0){/* i.e p_stMyBlockInfo->ulNbTotalMalloc >0*/ ulLargestMalloc <<= C_uwShiftAllocSize; sprintf (a_cLine, "\t-The Largest Allocation: \t%db (%.2fKb; %.2fMb)\n", ulLargestMalloc, (float)ulLargestMalloc/ 1024, (float)ulLargestMalloc/ (1024*1024)); Mmg_fn_v_PrintInfoMalloc (a_cLine); ulSmallestMalloc <<= C_uwShiftAllocSize; sprintf (a_cLine, "\t-The Smallest Allocation: \t%db (%.2fKb; %.2fMb)\n", ulSmallestMalloc, (float)ulSmallestMalloc/ 1024, (float)ulSmallestMalloc/ (1024*1024)); Mmg_fn_v_PrintInfoMalloc (a_cLine); if (p_stMyBlockInfo->ulNbMalloc){ sprintf (a_cLine, "\t-The average Allocation: \t%db (%.2fKb; %.2fMb)\n", ulLengthMalloc/p_stMyBlockInfo->ulNbMalloc, ((float)ulLengthMalloc/(float)p_stMyBlockInfo->ulNbMalloc)/ 1024, ((float)ulLengthMalloc/(float)p_stMyBlockInfo->ulNbMalloc)/ (1024*1024)); Mmg_fn_v_PrintInfoMalloc (a_cLine); } } a_cMap[uwI+1]='\n'; a_cMap[uwI+2]='\0'; Mmg_fn_v_PrintInfoMalloc (a_cMap); ulLengthMalloc >>= C_uwShiftAllocSize;/* restore the unitAlloc unit*/ /*+++++++++++++++++++++++++++++*/ /* the loss of allocated */ /*+++++++++++++++++++++++++++++*/ if (ulMaxPrint){ ucPrintedLength = (unsigned char)(( ((p_stMyBlockInfo->ulNbMalloc)*C_ucDebugInformationLoss)) /* loss*/ * C_ucNbColumnForHisto / ulMaxPrint); } else ucPrintedLength = 0; if (ucPrintedLength == 0) ucPrintedLength=1; for (uwI=0; uwI < ucPrintedLength; uwI++){ a_cMap[uwI]='+'; } a_cMap[uwI]='\n'; a_cMap[uwI+1]='\0'; Mmg_fn_v_PrintInfoMalloc (a_cMap); Mmg_fn_v_PrintInfoMalloc ("The debug loss of the allocated space:\n"); Mmg_fn_v_PrintInfoMalloc (a_cMap); ulLength = ((p_stMyBlockInfo->ulNbMalloc)*C_ucDebugInformationLoss); /* loss*/ ulLength <<= C_uwShiftAllocSize; if ((unsigned long)p_stMyBlockInfo->p_cEndBlock - (unsigned long)p_stMyBlockInfo->p_cBeginBlock + 1 - (ulDebugInfoRemain<p_cEndBlock - (unsigned long)p_stMyBlockInfo->p_cBeginBlock + 1 - (ulDebugInfoRemain<p_cEndBlock - (unsigned long)p_stMyBlockInfo->p_cBeginBlock + 1 - (ulDebugInfoRemain<p_cEndBlock - (unsigned long)p_stMyBlockInfo->p_cBeginBlock + 1 - (ulDebugInfoRemain<d_stDynamicMallocInfo; for (ulI=0; ulIulNbDynamicMalloc; ulI++, p_stMyMallocInfo++){ ulLength = (unsigned long)(*((unitAlloc *)p_stMyMallocInfo->p_cBeginMalloc - C_ucMallocHeaderSize)); ulLengthMalloc += ulLength; if (ulLength>ulLargestMalloc){ ulLargestMalloc = ulLength; ulIdLargestMalloc = ulI; } if (ulLengthulNbTotalDynamicRealloc); Mmg_fn_v_PrintInfoMalloc (a_cLine); /************************************/ /* the allocated space without loss*/ /************************************/ ulLoss = p_stMyDynInfo->ulNbDynamicMalloc * (C_ucMallocHeaderSize+C_ucMallocFooterSize-C_ucOptimizedMallocHeaderSize-C_ucOptimizedMallocFooterSize); ulMaxPrint = M_Max(ulLoss, ulLengthMalloc);/* why not! ulLoss > ulLengthMalloc ?*/ ulLength = ulLengthMalloc - ulLoss; if (ulMaxPrint){ ucPrintedLength = (unsigned char)( ulLengthMalloc * C_ucNbColumnForHisto / ulMaxPrint); } else ucPrintedLength = 0; if (ucPrintedLength == 0) ucPrintedLength=1; for (ulI=0; ulI < ucPrintedLength; ulI++){ a_cMap[ulI]='*'; } a_cMap[ulI]='\n'; a_cMap[ulI+1]='\0'; Mmg_fn_v_PrintInfoMalloc (a_cMap); Mmg_fn_v_PrintInfoMalloc ("Total allocated space without loss:\n"); Mmg_fn_v_PrintInfoMalloc (a_cMap); ulLengthMalloc <<= C_uwShiftAllocSize; sprintf (a_cLine, "\t-Request:%d; current:%d; size : \t%db (%.2fKb; %.2fMb)\n",p_stMyDynInfo->ulNbTotalDynamicMalloc, p_stMyDynInfo->ulNbDynamicMalloc, ulLengthMalloc, (float)ulLengthMalloc / 1024, (float)ulLengthMalloc / (1024*1024)); Mmg_fn_v_PrintInfoMalloc (a_cLine); ulLargestMalloc <<= C_uwShiftAllocSize; sprintf (a_cLine, "\t-The Largest Allocation: \t%db (%.2fKb; %.2fMb)\n", ulLargestMalloc, (float)ulLargestMalloc/ 1024, (float)ulLargestMalloc/ (1024*1024)); Mmg_fn_v_PrintInfoMalloc (a_cLine); ulSmallestMalloc <<= C_uwShiftAllocSize; sprintf (a_cLine, "\t-The Smallest Allocation: \t%db (%.2fKb; %.2fMb)\n", ulSmallestMalloc, (float)ulSmallestMalloc/ 1024, (float)ulSmallestMalloc/ (1024*1024)); Mmg_fn_v_PrintInfoMalloc (a_cLine); if (p_stMyDynInfo->ulNbDynamicMalloc){ sprintf (a_cLine, "\t-The average Allocation: \t%db (%.2fKb; %.2fMb)\n", ulLengthMalloc/p_stMyDynInfo->ulNbDynamicMalloc, ((float)ulLengthMalloc/(float)p_stMyDynInfo->ulNbDynamicMalloc)/ 1024, ((float)ulLengthMalloc/(float)p_stMyDynInfo->ulNbDynamicMalloc)/ (1024*1024)); Mmg_fn_v_PrintInfoMalloc (a_cLine); } a_cMap[ulI+1]='\n'; a_cMap[ulI+2]='\0'; Mmg_fn_v_PrintInfoMalloc (a_cMap); ulLengthMalloc >>= C_uwShiftAllocSize;/* restore the unitAlloc unit*/ /*+++++++++++++++++++++++++++++*/ /* the loss of allocated space*/ /*+++++++++++++++++++++++++++++*/ if (ulMaxPrint) ucPrintedLength = (unsigned char)(ulLoss * C_ucNbColumnForHisto / ulMaxPrint); else ucPrintedLength = 0; if (ucPrintedLength == 0) ucPrintedLength=1; for (ulI=0; ulI < ucPrintedLength; ulI++){ a_cMap[ulI]='+'; } a_cMap[ulI]='\n'; a_cMap[ulI+1]='\0'; Mmg_fn_v_PrintInfoMalloc (a_cMap); Mmg_fn_v_PrintInfoMalloc ("The debug loss of the allocated space:\n"); Mmg_fn_v_PrintInfoMalloc (a_cMap); ulLength = ulLoss; ulLength <<= C_uwShiftAllocSize; if ((ulLengthMalloc << C_uwShiftAllocSize)+ulLength) sprintf (a_cLine, "\t-Size : %db (%.2fKb; %.2fMb) = %.2f%% of all the allocation space\n", ulLength, (float)ulLength / 1024, (float)ulLength / (1024*1024), (float)ulLength*100/(float)((ulLengthMalloc << C_uwShiftAllocSize)+ulLength));/*lint !e790: Suspicious truncation, integral to float*/ else sprintf (a_cLine, "\t-Size : %db (%.2fKb; %.2fMb)\n", ulLength, (float)ulLength / 1024, (float)ulLength / (1024*1024)); Mmg_fn_v_PrintInfoMalloc (a_cLine); a_cMap[ulI+1]='\n'; a_cMap[ulI+2]='\0'; Mmg_fn_v_PrintInfoMalloc (a_cMap); }/*lint !e715: p_stMyDynInfo&szModuleName (line 2521) not referenced*/ #endif/* __DYNAMIC_MALLOC_ALLOWED__*/ #endif /*__DEBUG_MALLOC_MODE__*/ /* end of Mmg_fn_vPrintDynamicMallocStatistic */ /* ##F#=================================================================================== NAME : Mmg_fn_v_ClearLogFile DESCRIPTION : Clear the log file C_szMmgLogFileName ========================================================================================= CREATION : 06-11-97/Pierrick Crepy =======================================================================================*/ void Mmg_fn_v_ClearLogFile(){ #ifdef __DEBUG_MALLOC_MODE__ FILE *hpMmgLogFile; remove (C_szMmgLogFileName);/*lint !e534*/ hpMmgLogFile = fopen( C_szMmgLogFileName, "w" ); #ifdef _DEBUG if (GetLastError()) { LPVOID lpMsgBuf; FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, NULL, GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), /* Default language*/ (LPTSTR) &lpMsgBuf, 0, NULL );/*lint !e534*/ /* Display the string.*/ Erm_fn_iMessageBox(lpMsgBuf, C_szMmgLogFileName, MB_OK|MB_ICONINFORMATION ); /* Free the buffer.*/ LocalFree( lpMsgBuf ); } #endif /*_DEBUG*/ if (hpMmgLogFile) fclose(hpMmgLogFile); #endif /*__DEBUG_MALLOC_MODE__*/ } /* ##F#=================================================================================== NAME : Mmg_fn_v_PrintInfoMalloc DESCRIPTION : Add a string in the log file C_szMmgLogFileName INPUT : String to print ========================================================================================= CREATION : 06-11-97/Pierrick Crepy =======================================================================================*/ void Mmg_fn_v_PrintInfoMalloc(char *p_cTxt) { #ifdef __DEBUG_MALLOC_MODE__ FILE *hpMmgLogFile; hpMmgLogFile = fopen( C_szMmgLogFileName, "a" ); if (hpMmgLogFile){ fprintf (hpMmgLogFile,"%s", p_cTxt); fclose(hpMmgLogFile); } #endif /*__DEBUG_MALLOC_MODE__*/ } /* ##-########################### ## debug function just for the developper ############################## */ /* ##F#=================================================================================== NAME : Mmg_fn_vTestNbFreeIntheCurentMode DESCRIPTION : Check the validity of nb frre on a channel(only in debug mode) INPUT : Channel Id ========================================================================================= CREATION : 06-11-97/Pierrick Crepy =======================================================================================*/ void Mmg_fn_vTestNbFreeIntheCurentMode(unsigned char ucChannel) /*not use for the moment*/ { #ifdef __DEBUG_MALLOC_MODE__ tdstBlockInfoPriv * p_stMyBlockInfo = (tdstBlockInfoPriv *) g_d_stCurrentModeInfo[ucChannel].p_vTdstBlockInfoOrTdstDynInfo; unitAlloc * p_uaTmp;/*temporary pointer: if we reduce the allocation p_uaTmp=pointer at the new free space. // !! voir a renomer*/ unsigned short uwI; /* count the real number of free*/ p_uaTmp = (unitAlloc*)p_stMyBlockInfo->p_cFirstFree; for (uwI=0; *(p_uaTmp+1) != (unitAlloc)0; uwI++, p_uaTmp = (unitAlloc*) *(p_uaTmp+1));/*lint !e722: Suspicious use of ;*/ if (p_stMyBlockInfo->uwNbFree != uwI){ #ifdef __WARNING3_ERR_MMG__ #ifdef __ERROR_STRINGS__ char szErrTxt[C_ucSizeOfErrTxt]; sprintf(szErrTxt, "uwNbFree(%d) != the real number of actual free(%d)\n", p_stMyBlockInfo->uwNbFree, uwI); Mmg_M_UpdateLastErrorWithCurrentModeInfo (E_uwMmgPbBbFree, szErrTxt, ucChannel); #else /*__ERROR_STRINGS__*/ Mmg_M_UpdateLastErrorWithCurrentModeInfo (E_uwMmgPbBbFree, szErrTxt, NULL); #endif /*__ERROR_STRINGS__*/ #endif /*__WARNING3_ERR_MMG__*/ p_stMyBlockInfo->uwNbFree = uwI; } #endif /* __DEBUG_MALLOC_MODE__*/ } /* ##F#=================================================================================== NAME : Mmg_fn_vTestNbFree DESCRIPTION : Check the validity of nb free in a static bloc (only in debug mode) INPUT : Module Id Block Id Pointer on a block info structure ========================================================================================= CREATION : 06-11-97/Pierrick Crepy =======================================================================================*/ void Mmg_fn_vTestNbFree(unsigned char ucModuleId, unsigned char ucBlockId, struct tdstBlockInfoPriv_ *p_stBlockInfo) { #ifdef __DEBUG_MALLOC_MODE__ unitAlloc * p_uaTmp;/*temporary pointer: if we reduce the allocation p_uaTmp=pointer at the new free space. // !! voir a renomer*/ unsigned short uwI; /* if (p_stBlockInfo->p_cFirstFree != p_stBlockInfo->p_cEndBlock) {*/ /* count the real number of free*/ p_uaTmp = (unitAlloc*)p_stBlockInfo->p_cFirstFree; for (uwI=0; *(p_uaTmp+1) != (unitAlloc)0; uwI++, p_uaTmp = (unitAlloc*) *(p_uaTmp+1));/*lint !e722: Suspicious use of ;*/ if (p_stBlockInfo->uwNbFree != uwI){ #ifdef __WARNING3_ERR_MMG__ #ifdef __ERROR_STRINGS__ char szErrTxt[C_ucSizeOfErrTxt]; sprintf(szErrTxt, "uwNbFree(%d) != the real number of actual free(%d)\n", p_stBlockInfo->uwNbFree, uwI); Mmg_M_UpdateLastErrorWithModuleIdAnducModeReference(ucModuleId, ucBlockId, E_uwMmgPbBbFree, szErrTxt); #else /*__ERROR_STRINGS__*/ Mmg_M_UpdateLastErrorWithModuleIdAnducModeReference(ucModuleId, ucBlockId, E_uwMmgPbBbFree, NULL); #endif /*__ERROR_STRINGS__*/ #endif /*__WARNING3_ERR_MEM__*/ p_stBlockInfo->uwNbFree = uwI; } /* }*/ #endif /* __DEBUG_MALLOC_MODE__*/ }/*lint !e715*/ /* ##F#=================================================================================== NAME : Mmg_fn_vBlockGarbageCollector4Ch DESCRIPTION : Do a garbage collector on a block, beware all pointer that point into the bloc must be pass in parameter (even local pointer in the block) INPUT : Table of pointer (point into the block) Max Malloc in the block Channel Id ========================================================================================= CREATION : 06-11-97/Pierrick Crepy =======================================================================================*/ void Mmg_fn_vBlockGarbageCollector4Ch(void** a_pp_vTab[], unsigned short uwMaxNbMallocInBlock, unsigned char ucChannel){ unsigned short uwI, uwJ; void ** pp_vTmp; char *p_cMyFirstFree = ((tdstBlockInfoPriv *)(g_d_stCurrentModeInfo[ucChannel].p_vTdstBlockInfoOrTdstDynInfo))->p_cFirstFree; #ifdef __DEBUG_MALLOC_MODE__ char szTxt[100]; char * p_vSv; #endif /*__DEBUG_MALLOC_MODE__*/ #ifdef D_CheckSystemForBlockWithoutFree if (p_cMyFirstFree == C_FirstFreeValueForBlockWithoutFree){ Mmg_M_UpdateLastError(E_uwMmgPbNoAvailableFunctionForBlockWithoutFree, NULL) } #endif /*D_CheckSystemForBlockWithoutFree*/ /* sort a_pp_cTab*/ for (uwI=0; uwI < /*C_uwNumberOfMallocMax*/uwMaxNbMallocInBlock-1; uwI++){ for (uwJ=(unsigned short)(uwI+1); uwJ < uwMaxNbMallocInBlock; uwJ++){ if (*(a_pp_vTab[uwJ]) < *(a_pp_vTab[uwI])){ pp_vTmp = a_pp_vTab[uwI]; a_pp_vTab[uwI] = a_pp_vTab[uwJ]; a_pp_vTab[uwJ] = pp_vTmp; } } } for( uwI = 0; uwI < uwMaxNbMallocInBlock; uwI++ ){ if (*(a_pp_vTab[uwI])>(void *) p_cMyFirstFree ){ #ifdef __DEBUG_MALLOC_MODE__ p_vSv = (void *) (*(a_pp_vTab[uwI])); *(a_pp_vTab[uwI]) = (void *) Mmg_fn_p_vRealloc (*(a_pp_vTab[uwI]),((*(((unitAlloc *)(*(a_pp_vTab[uwI]))) - 2)) - (C_ucMallocHeaderSize + C_ucMallocFooterSize))< 0X%X\n", p_vSv, ((*(((unitAlloc *)(*(a_pp_vTab[uwI]))) - 2)) - (C_ucMallocHeaderSize + C_ucMallocFooterSize))<p_cBeginBlock != C_p_cBlockNotValidKey)){ if ((p_vPtr >= (void *)a_stMyBlockInfo->p_cBeginBlock) && (p_vPtr <= (void *)a_stMyBlockInfo->p_cEndBlock)){ *p_uwModuleBlockId = (ucModuleId<<8) | ucBlockId; *pp_vBeginAdr = (void *)a_stMyBlockInfo->p_cBeginBlock; } } } } } #ifdef __FATAL_ERR_MMG__ #ifdef _DEBUG if (*p_uwModuleBlockId == 0xFFFF){ char szTxt[50]; sprintf (szTxt, "In Mmg_fn_vWhereIs(0X%X, ...)\n", p_vPtr); Mmg_M_UpdateLastErrorWithoutMessage(E_uwMmgPbInvalidStaticAddress,szTxt); } #endif /*_DEBUG*/ #endif __FATAL_ERR_MMG__ }/*Mmg_fn_vWhereIs */ /* ##F#=================================================================================== NAME : Mmg_fn_p_vGiveTheBeginingAddress DESCRIPTION : return the beginning address of a block INPUT : Block Id OUTPUT : address of the block beginning ========================================================================================= CREATION : 06-11-97/Pierrick Crepy =======================================================================================*/ void * Mmg_fn_p_vGiveTheBeginingAddress (unsigned short uwModuleBlockId){ unsigned char ucModuleId = uwModuleBlockId>>8; unsigned char ucBlockId = uwModuleBlockId & 0xFF; #if defined(__FATAL_ERR_MMG__) && defined(_DEBUG) #ifdef __ERROR_STRINGS__ char szErrTxt[C_ucSizeOfErrTxt]; #endif /*__ERROR_STRINGS__*/ if (ucModuleId >= g_ucErmNbOfModule){ char szTxt[50]; sprintf (szTxt, "ModuleId = %d, but only %d modules are initialized \n", ucModuleId, g_ucErmNbOfModule); Mmg_M_UpdateLastError(E_uwMmgPbInvalidModuleId,szTxt); } if (g_a_p_stMmgModuleBlocksInfo[ucModuleId]== NULL){ #ifdef __ERROR_STRINGS__ sprintf (szErrTxt, "In Module:["); Erm_M_GetModuleInformation(szErrTxt+strlen(szErrTxt), ucModuleId); sprintf (szErrTxt+strlen(szErrTxt), "]\n"); Mmg_M_UpdateLastError(E_uwMmgPbNoStaticMemory,szErrTxt); #else /*__ERROR_STRINGS__*/ Mmg_M_UpdateLastError(E_uwMmgPbNoStaticMemory,NULL); #endif /*__ERROR_STRINGS__*/ } if (ucBlockId >= g_a_ucBlocksNbInModule[ucModuleId]){ #ifdef __ERROR_STRINGS__ sprintf (szErrTxt, "BlockId = %d, but there are only %d Block\nin the module [", ucBlockId, g_a_ucBlocksNbInModule[ucModuleId]); Erm_M_GetModuleInformation(szErrTxt+strlen(szErrTxt), ucModuleId); sprintf (szErrTxt+strlen(szErrTxt), "]\n"); Mmg_M_UpdateLastError(E_uwMmgPbInvalidBlockId,szErrTxt); #else /*__ERROR_STRINGS__*/ Mmg_M_UpdateLastError(E_uwMmgPbInvalidBlockId,NULL); #endif /*__ERROR_STRINGS__*/ } if ((g_a_p_stMmgModuleBlocksInfo[ucModuleId])[ucBlockId].p_cBeginBlock == C_p_cBlockNotValidKey){ #ifdef __ERROR_STRINGS__ sprintf (szErrTxt, "The Block#%d in the module [", ucBlockId); Erm_M_GetModuleInformation(szErrTxt+strlen(szErrTxt), ucModuleId); sprintf (szErrTxt+strlen(szErrTxt), "] is not valide:\nit's should be not well initialize ! Because :\np_cBeginBlock = C_p_cBlockNotValidKey (0X%X)\n", C_p_cBlockNotValidKey); Mmg_M_UpdateLastError(E_uwMmgPbInvalidBlockId,szErrTxt); #else /*__ERROR_STRINGS__*/ Mmg_M_UpdateLastError(E_uwMmgPbInvalidBlockId,NULL); #endif /*__ERROR_STRINGS__*/ } #endif /*defined(__FATAL_ERR_MMG__) && defined(_DEBUG)*/ return ((g_a_p_stMmgModuleBlocksInfo[ucModuleId])[ucBlockId].p_cBeginBlock); }/*Mmg_fn_p_vGiveTheBeginingAddress*/ #ifdef _DEBUG /* ##F#=================================================================================== NAME : Mmg_fn_vLockAlloaction DESCRIPTION : Allow blocking of all alloc operation ========================================================================================= CREATION : 06-11-97/Pierrick Crepy =======================================================================================*/ void Mmg_fn_vLockAlloaction(){ g_ucBLockedAllocation = C_ucTrue; } /* ##F#=================================================================================== NAME : Mmg_fn_vUnLockAlloaction DESCRIPTION : Allow unblocking of all alloc operation ========================================================================================= CREATION : 06-11-97/Pierrick Crepy =======================================================================================*/ void Mmg_fn_vUnLockAlloaction(){ g_ucBLockedAllocation = C_ucFalse; } #endif _DEBUG /* ##F#=================================================================================== NAME : Mmg_fn_ucGiveChannelId DESCRIPTION : Provide a unique channel identificator for a couple (Thraed,group) BEWARE : always use the default group INPUT : Thraed Id Group Id OUTPUT : Channel Id ========================================================================================= CREATION : 06-11-97/Pierrick Crepy LAST MODIFICATIONS : 25-11-97/Carlos Torres Check group & re-use of release channel =======================================================================================*/ unsigned char Mmg_fn_ucGiveChannelId(unsigned long ulThreadId, unsigned char ucGroupId){ unsigned char ucI= 1;/*1 for jump the defaulf channel*/ unsigned char b_ucFound = C_ucFalse; tdstChannelInfo * p_stChannelInfo = g_stGeneralChannelInfo.d_stTabChannelInfo+1;/*1 for jump the defaulf channel*/ #ifdef __DEBUG_MALLOC_MODE__ /* cannot release channel already release*/ if (ucGroupId != C_ucMmgDefaultGroup) { #ifdef __ERROR_STRINGS__ char szErrTxt[C_ucSizeOfErrTxt]; sprintf (szErrTxt, "You choose the group %d to obtain a channel",ucGroupId); Mmg_M_UpdateLastError(E_uwMmgInvalidGroup, szErrTxt); #else /*__ERROR_STRINGS__*/ Mmg_M_UpdateLastError(E_uwMmgInvalidGroup, NULL); #endif /*__ERROR_STRINGS__*/ } #endif /* try to find an existing channel or a free channel*/ while((ucI < g_stGeneralChannelInfo.ucNbchannelUsed) && (!b_ucFound) && (p_stChannelInfo->ucGroupId == C_ucMmgDefaultGroup)) { if ((p_stChannelInfo->ulThreadId == ulThreadId) && (p_stChannelInfo->ucGroupId == ucGroupId)) { b_ucFound = C_ucTrue; } else { ucI++; p_stChannelInfo++; } } if (b_ucFound) { return ucI; } else {/*! b_ucFound*/ #ifdef __DEBUG_MALLOC_MODE__ if (ucI >= g_stGeneralChannelInfo.ucMAxNbChannel){ #ifdef __ERROR_STRINGS__ char szErrTxt[C_ucSizeOfErrTxt]; sprintf (szErrTxt, "You can only use %d channel(s) available\nPlease check the ucMaxNbChannel parameter when you call Mmg_fn_vFirstInitMmgModule() function", g_stGeneralChannelInfo.ucMAxNbChannel); Mmg_M_UpdateLastError(E_uwMmgPbTooManyChannel, szErrTxt); #else /*__ERROR_STRINGS__*/ Mmg_M_UpdateLastError(E_uwMmgPbTooManyChannel, NULL); #endif /*__ERROR_STRINGS__*/ } #endif /* __DEBUG_MALLOC_MODE__ */ p_stChannelInfo->ulThreadId = ulThreadId; p_stChannelInfo->ucGroupId = ucGroupId; /* set the last channel used*/ if (ucI == g_stGeneralChannelInfo.ucNbchannelUsed) g_stGeneralChannelInfo.ucNbchannelUsed++; return (ucI); } }/*Mmg_fn_ucGiveChannelId*/ /* ##F#=================================================================================== NAME : Mmg_fn_ucGiveChannelId DESCRIPTION : Provide a unique channel identificator for a couple (Thraed,group) BEWARE : always use the default group INPUT : Thraed Id Group Id OUTPUT : Channel Id ========================================================================================= CREATION : 06-11-97/Pierrick Crepy =======================================================================================*/ #ifndef _FIRE_DEADCODE_U64_ void Mmg_fn_vReleaseChannelId(unsigned char ucChannelId) { /* get channel info in the table*/ tdstChannelInfo * p_stChannelInfo = g_stGeneralChannelInfo.d_stTabChannelInfo+ucChannelId; #ifdef __DEBUG_MALLOC_MODE__ /* cannot release default channel*/ if (ucChannelId == C_ucMmgDefaultChannel) { Mmg_M_UpdateLastError(E_uwMmgPbDftChannelCannotBeFree, NULL); return; } /* cannot release channel >= MaxChannel */ if (ucChannelId >= g_stGeneralChannelInfo.ucMAxNbChannel) { #ifdef __ERROR_STRINGS__ char szErrTxt[C_ucSizeOfErrTxt]; sprintf (szErrTxt, "You try to release the channel %d, but you can only use %d channel",ucChannelId, g_stGeneralChannelInfo.ucMAxNbChannel); Mmg_M_UpdateLastError(E_uwMmgPbInvalChannel, szErrTxt); #else /*__ERROR_STRINGS__*/ Mmg_M_UpdateLastError(E_uwMmgPbInvalChannel, NULL); #endif /*__ERROR_STRINGS__*/ return; } /* cannot release channel already release*/ if ((p_stChannelInfo->ucGroupId != C_ucMmgDefaultGroup) || (ucChannelId >= g_stGeneralChannelInfo.ucNbchannelUsed)) { #ifdef __ERROR_STRINGS__ char szErrTxt[C_ucSizeOfErrTxt]; sprintf (szErrTxt, "You try to release the channel %d, but it was already released",ucChannelId); Mmg_M_UpdateLastError(E_uwMmgPbInvalChannel, szErrTxt); #else /*__ERROR_STRINGS__*/ Mmg_M_UpdateLastError(E_uwMmgPbInvalChannel, NULL); #endif /*__ERROR_STRINGS__*/ return; } #endif /* set invalid group*/ p_stChannelInfo->ucGroupId = C_ucMmgInvalidGroup; } #endif /* _FIRE_DEADCODE_U64_ */ /* ##F#=================================================================================== NAME : Mmg_fn_v_SetModeAlloc DESCRIPTION : Set the mode dynamic or static (choosing a block) for a channel INPUT : Module Id New Mode Channel Id ========================================================================================= CREATION : 06-11-97/Pierrick Crepy =======================================================================================*/ void Mmg_fn_v_SetModeAlloc(unsigned char ucModuleId, unsigned char ucNewMode, unsigned char ucChannel) /* ------------------ */ { (g_d_stCurrentModeInfo[ucChannel]).ucMode = (ucNewMode); (g_d_stCurrentModeInfo[ucChannel]).ucModuleId = ucModuleId; if ((ucNewMode) != E_ucDynamic){ (g_d_stCurrentModeInfo[ucChannel]).p_vTdstBlockInfoOrTdstDynInfo = (void *) (g_a_p_stMmgModuleBlocksInfo[ucModuleId]+ucNewMode); } else{ #ifdef __DYNAMIC_MALLOC_ALLOWED__ #ifdef __DEBUG_MALLOC_MODE__ (g_d_stCurrentModeInfo[ucChannel]).p_vTdstBlockInfoOrTdstDynInfo = (void *) g_d_p_stMmgModuleDynInfo[ucModuleId]; #endif /*__DEBUG_MALLOC_MODE__*/ #else /*__DYNAMIC_MALLOC_ALLOWED__*/ (g_d_stCurrentModeInfo[ucChannel]).p_vTdstBlockInfoOrTdstDynInfo = NULL; Mmg_M_UpdateFatalDebugError(E_uwMmgPbCanNotUseDynMode); #endif /*__DYNAMIC_MALLOC_ALLOWED__*/ } }/*Mmg_fn_v_SetModeAlloc*/ /* ##F#=================================================================================== NAME : Mmg_fn_vFirstInitMmgModule DESCRIPTION : Initialization of the Mmg module MUST be use before using MMG functions INPUT : Max number of channel authorized ========================================================================================= CREATION : 06-11-97/Pierrick Crepy =======================================================================================*/ void Mmg_fn_vFirstInitMmgModule (unsigned char ucMaxNbChannel){ unsigned char ucI; #ifdef __DEBUG_MALLOC_MODE__ #ifdef __ERROR_STRINGS__ char szErrTxt[C_ucSizeOfErrTxt]; #endif /*__ERROR_STRINGS__*/ #endif /*__DEBUG_MALLOC_MODE__*/ #ifdef __DEBUG_MALLOC_MODE__ #ifdef __FATAL_ERR_MMG__ if ((ucMaxNbChannel < 1) || (ucMaxNbChannel > C_MaxNbPossibleChannel)) { #ifdef __ERROR_STRINGS__ sprintf (szErrTxt, "The range of ucMaxNbChannel is [1, C_MaxNbPossibleChannel=%d], But Your ucMaxNbChannel =%d", C_MaxNbPossibleChannel, ucMaxNbChannel); Mmg_M_UpdateLastError(E_uwMmgPbInvalNbOfChannel, szErrTxt); #else /*__ERROR_STRINGS__*/ Mmg_M_UpdateLastError(E_uwMmgPbInvalNbOfChannel, NULL); #endif /*__ERROR_STRINGS__*/ } #endif /*__FATAL_ERR_MMG__*/ #endif /*__DEBUG_MALLOC_MODE__*/ g_d_stCurrentModeInfo = (struct tdstCurrentModeInfo_ *) malloc (ucMaxNbChannel * sizeof (struct tdstCurrentModeInfo_)); #ifdef __DEBUG_MALLOC_MODE__ #ifdef __FATAL_ERR_MMG__ if (g_d_stCurrentModeInfo == NULL){ #ifdef __ERROR_STRINGS__ sprintf (szErrTxt, "g_d_stCurrentModeInfo is not allocated"); Mmg_M_UpdateLastError(E_uwMmgPbInFirstInitMmgModule, szErrTxt); #else /*__ERROR_STRINGS__*/ Mmg_M_UpdateLastError(E_uwMmgPbInFirstInitMmgModule, NULL); #endif /*__ERROR_STRINGS__*/ } #endif /*__FATAL_ERR_MMG__*/ #endif /*__DEBUG_MALLOC_MODE__*/ g_stGeneralChannelInfo.d_stTabChannelInfo = (struct tdstChannelInfo_ *) malloc (ucMaxNbChannel * sizeof (struct tdstChannelInfo_ )); #ifdef __DEBUG_MALLOC_MODE__ #ifdef __FATAL_ERR_MMG__ if (g_stGeneralChannelInfo.d_stTabChannelInfo == NULL){ #ifdef __ERROR_STRINGS__ sprintf (szErrTxt, "g_stGeneralChannelInfo.d_stTabChannelInfo is not allocated"); Mmg_M_UpdateLastError(E_uwMmgPbInFirstInitMmgModule, szErrTxt); #else /*__ERROR_STRINGS__*/ Mmg_M_UpdateLastError(E_uwMmgPbInFirstInitMmgModule, NULL); #endif /*__ERROR_STRINGS__*/ } #endif /*__FATAL_ERR_MMG__*/ #endif /*__DEBUG_MALLOC_MODE__*/ g_stGeneralChannelInfo.ucMAxNbChannel = ucMaxNbChannel; g_stGeneralChannelInfo.ucNbchannelUsed = 1; #ifdef __DYNAMIC_MALLOC_ALLOWED__ #ifdef __DEBUG_MALLOC_MODE__ g_d_p_stMmgModuleDynInfo = (struct tdstDynInfo_ **) malloc (sizeof(struct tdstDynInfo_ *) * C_ucNbOfMaxModule); if (g_d_p_stMmgModuleDynInfo == NULL){ #ifdef __ERROR_STRINGS__ sprintf (szErrTxt, "g_d_p_stMmgModuleDynInfo is not allocated"); Mmg_M_UpdateLastError(E_uwMmgPbInFirstInitMmgModule, szErrTxt); #else /*__ERROR_STRINGS__*/ Mmg_M_UpdateLastError(E_uwMmgPbInFirstInitMmgModule, NULL); #endif /*__ERROR_STRINGS__*/ } #endif /*__DEBUG_MALLOC_MODE__*/ #endif /*__DYNAMIC_MALLOC_ALLOWED__*/ for (ucI=0; ucI 0){ g_a_p_stMmgModuleBlocksInfo[ucModuleId] = (tdstBlockInfoPriv *) malloc (sizeof (tdstBlockInfoPriv) * ucMaxBlocksNb); #ifdef __DEBUG_MALLOC_MODE__ if (g_a_p_stMmgModuleBlocksInfo[ucModuleId] == NULL){ #ifdef __ERROR_STRINGS__ sprintf (szErrTxt, "The g_d_p_stMmgModuleDynInfo[%d] (i.e for the module ", ucModuleId); Erm_M_GetModuleInformation(szErrTxt+strlen(szErrTxt), ucModuleId); sprintf (szErrTxt+strlen(szErrTxt), ") is not allocated"); Mmg_M_UpdateLastError(E_uwMmgPbInInitMmg, szErrTxt); #else /*__ERROR_STRINGS__*/ Mmg_M_UpdateLastError(E_uwMmgPbInInitMmg, NULL); #endif /*__ERROR_STRINGS__*/ } #ifdef __DYNAMIC_MALLOC_ALLOWED__ g_d_p_stMmgModuleDynInfo[ucModuleId] = (tdstDynInfo *) malloc (sizeof(tdstDynInfo)); if (g_d_p_stMmgModuleDynInfo[ucModuleId] == NULL){ #ifdef __ERROR_STRINGS__ sprintf (szErrTxt, "The g_d_p_stMmgModuleDynInfo[%d] (i.e for the module ", ucModuleId); Erm_M_GetModuleInformation(szErrTxt+strlen(szErrTxt), ucModuleId); sprintf (szErrTxt+strlen(szErrTxt), ") is not allocated"); Mmg_M_UpdateLastError(E_uwMmgPbInInitMmg, szErrTxt); #else /*__ERROR_STRINGS__*/ Mmg_M_UpdateLastError(E_uwMmgPbInInitMmg, NULL); #endif /*__ERROR_STRINGS__*/ } g_d_p_stMmgModuleDynInfo[ucModuleId]->ulMaxNbDynamicMalloc = ulMaxNbDynamicMalloc; g_d_p_stMmgModuleDynInfo[ucModuleId]->d_stDynamicMallocInfo = malloc (sizeof(tdstMallocInfo) * ulMaxNbDynamicMalloc); if (g_d_p_stMmgModuleDynInfo[ucModuleId]->d_stDynamicMallocInfo == NULL){ #ifdef __ERROR_STRINGS__ sprintf (szErrTxt, "The g_d_p_stMmgModuleDynInfo[%d]->d_stDynamicMallocInfo (i.e for the module ", ucModuleId); Erm_M_GetModuleInformation(szErrTxt+strlen(szErrTxt), ucModuleId); sprintf (szErrTxt+strlen(szErrTxt), ") is not allocated"); Mmg_M_UpdateLastError(E_uwMmgPbInInitMmg, szErrTxt); #else /*__ERROR_STRINGS__*/ Mmg_M_UpdateLastError(E_uwMmgPbInInitMmg, NULL); #endif /*__ERROR_STRINGS__*/ } #endif /*__DYNAMIC_MALLOC_ALLOWED__*/ #endif /*__DEBUG_MALLOC_MODE__*/ for (ucI=0, p_stMyBlockInfo = g_a_p_stMmgModuleBlocksInfo[ucModuleId];ucIp_cBeginBlock = C_p_cBlockNotValidKey; } g_a_ucBlocksNbInModule[ucModuleId] = ucMaxBlocksNb; } #ifdef __DEBUG_MALLOC_MODE__ #ifdef __DYNAMIC_MALLOC_ALLOWED__ Mmg_M_InitDynInfo(g_d_p_stMmgModuleDynInfo[ucModuleId]); #endif /*__DYNAMIC_MALLOC_ALLOWED__*/ #endif /*__DEBUG_MALLOC_MODE__*/ #ifdef __DEBUG_MALLOC_MODE__ } Mmg_fn_v_ClearLogFile(); #endif /*__DEBUG_MALLOC_MODE__*/ }/*Mmg_fn_v_InitMmg*/ /* ##F#=================================================================================== NAME : Mmg_fn_v_InitMmg DESCRIPTION : Destroy all ressource allocated for the management of memory for a module INPUT : Module Id ========================================================================================= CREATION : 06-11-97/Pierrick Crepy =======================================================================================*/ #ifndef _FIRE_DEADCODE_U64_ /* Added by RUC */ void Mmg_fn_v_StopMmg(unsigned char ucModuleId){ unsigned char ucI; if (g_a_p_stMmgModuleBlocksInfo[ucModuleId]!= NULL){ /*delete evey initialized block */ for (ucI=0; ucId_stDynamicMallocInfo); g_d_p_stMmgModuleDynInfo[ucModuleId]->d_stDynamicMallocInfo = NULL; free (g_d_p_stMmgModuleDynInfo[ucModuleId]); g_d_p_stMmgModuleDynInfo[ucModuleId] = NULL; #endif /*__DYNAMIC_MALLOC_ALLOWED__*/ #endif /*__DEBUG_MALLOC_MODE__*/ } } #endif /* _FIRE_DEADCODE_U64_ */ /* Added by RUC */ /* ##F#=================================================================================== NAME : Mmg_fn_v_PrintAllocationsUsedForMmg DESCRIPTION : Print statistic concerning the memory used to manage allocation ========================================================================================= CREATION : 06-11-97/Pierrick Crepy =======================================================================================*/ #ifndef _FIRE_DEADCODE_U64_ void Mmg_fn_v_PrintAllocationsUsedForMmg(){ #ifdef __ERROR_STRINGS__ unsigned char ucI, ucJ, ucNbModuleUsedMmg =0; unsigned long ulSize, ulStaticSubTotal,ulDynamicMemoryUsed = 0, ulStaticMemoryUsed = 0; #ifdef __DEBUG_MALLOC_MODE__ unsigned long ulSizeForTraceOfEachAllocation; #endif /*__DEBUG_MALLOC_MODE__*/ #ifdef __ADD_PLACE_FOR_DEBUG_INFORMATION__ unsigned long ulSize2; #endif /*__ADD_PLACE_FOR_DEBUG_INFORMATION__*/ #if defined(__DEBUG_MALLOC_MODE__) && defined(__DYNAMIC_MALLOC_ALLOWED__) unsigned long ulDynamicSubTotal; #endif /*defined(__DEBUG_MALLOC_MODE__) && defined(__DYNAMIC_MALLOC_ALLOWED__)*/ char szErrTxt[C_ucSizeOfErrTxt]; tdstBlockInfoPriv *p_stMyBlocksInfo; Erm_fn_v_Printsz ("\n|-----------------------------------------|\n"); Erm_fn_v_Printsz ("| Memory Used for the management of Mmg : |\n"); Erm_fn_v_Printsz ("|-----------------------------------------|\n"); for (ucI = 0; ucI < g_ucErmNbOfModule; ucI++){/* scan each module*/ ulStaticSubTotal = 0; #if defined(__DEBUG_MALLOC_MODE__) && defined(__DYNAMIC_MALLOC_ALLOWED__) ulDynamicSubTotal = 0; #endif/* defined(__DEBUG_MALLOC_MODE__) && defined(__DYNAMIC_MALLOC_ALLOWED__)*/ if (Mmg_M_b_ucTheModuleUseStaticMemory(ucI)){/*this module use the static memory and perhaps the dynamic*/ ucNbModuleUsedMmg ++; sprintf (szErrTxt, "=> module (#%d) : ", ucI); Erm_M_GetModuleInformation(szErrTxt+strlen(szErrTxt), ucI); sprintf (szErrTxt+strlen(szErrTxt), "\n"); Erm_fn_v_Printsz (szErrTxt); #if defined(__DEBUG_MALLOC_MODE__) && defined(__DYNAMIC_MALLOC_ALLOWED__) ulSize = (sizeof(struct tdstDynInfo_) * C_ucNbOfMaxModule); ulSize2 = sizeof(tdstMallocInfo) * g_d_p_stMmgModuleDynInfo[ucI]->ulMaxNbDynamicMalloc; ulDynamicSubTotal = ulSize+ulSize2; sprintf (szErrTxt, "\t-> Dynamic Memory : General data (%db)+ Data for %d allocations (%db) = %db (%.2fKb; %.2fMb)\n", ulSize, g_d_p_stMmgModuleDynInfo[ucI]->ulMaxNbDynamicMalloc, ulSize2, ulDynamicSubTotal, (float)ulDynamicSubTotal/1024, (float)ulDynamicSubTotal/(1024*1024)); Erm_fn_v_Printsz (szErrTxt); #endif /*defined (__DEBUG_MALLOC_MODE__) && defined(__DYNAMIC_MALLOC_ALLOWED__)*/ ulSize = (sizeof (tdstBlockInfoPriv) * Mmg_M_ucGetNbOfBlocksUsedInModule(ucI)); ulStaticSubTotal = ulSize; sprintf (szErrTxt,"\t-> Static Memory : General Data for %d Block(s) = %d\n", Mmg_M_ucGetNbOfBlocksUsedInModule(ucI), ulSize); Erm_fn_v_Printsz (szErrTxt); for (ucJ=0, p_stMyBlocksInfo = g_a_p_stMmgModuleBlocksInfo[ucI]; ucJp_cBeginBlock != C_p_cBlockNotValidKey){ #ifdef __ADD_PLACE_FOR_DEBUG_INFORMATION__ ulSize = (long) (p_stMyBlocksInfo->p_cEndBlock - p_stMyBlocksInfo->p_cBeginBlock)+1; ulSize2 = (p_stMyBlocksInfo->ulMaxNbStaticMalloc*(C_ucDebugInformationLoss<ulMaxNbStaticMalloc, ulSize, (float)ulSize/1024, (float)ulSize/(1024*1024)); Erm_fn_v_Printsz (szErrTxt); #else /*__ADD_PLACE_FOR_DEBUG_INFORMATION__*/ ulSize =(long) (p_stMyBlocksInfo->p_cEndBlock - p_stMyBlocksInfo->p_cBeginBlock+1); ulStaticSubTotal += ulSize; sprintf (szErrTxt, "\t\t* Block #%d: %db (%.2fKb; %.2fMb) allocated\n", ucJ, ulSize, (float)ulSize/1024, (float)ulSize/(1024*1024)); Erm_fn_v_Printsz (szErrTxt); #endif /*__ADD_PLACE_FOR_DEBUG_INFORMATION__*/ }/*end of the if p_stMyBlockInfo->p_cBeginBlock != C_p_cBlockNotValidKey*/ }/*end of for*/ #if defined(__DEBUG_MALLOC_MODE__) && defined(__DYNAMIC_MALLOC_ALLOWED__) ulSize = ulDynamicSubTotal + ulStaticSubTotal; sprintf (szErrTxt,"\t-> Total Memory for the module #%d: Dynamic (%db)+ Static (%db) = %db (%.2fKb; %.2fMb)\n", ucI, ulDynamicSubTotal, ulStaticSubTotal, ulSize, (float)ulSize/1024, (float)ulSize/(1024*1024)); Erm_fn_v_Printsz (szErrTxt); #else /*defined(__DEBUG_MALLOC_MODE__) && defined(__DYNAMIC_MALLOC_ALLOWED__)*/ sprintf (szErrTxt,"\t-> Total Static Memory for the module #%d: %db (%.2fKb; %.2fMb)\n", ucI, ulStaticSubTotal, (float)ulStaticSubTotal/1024, (float)ulStaticSubTotal/(1024*1024)); Erm_fn_v_Printsz (szErrTxt); #endif /*defined(__DEBUG_MALLOC_MODE__) && defined(__DYNAMIC_MALLOC_ALLOWED__)*/ }/* end if module used memeory.*/ #if defined(__DEBUG_MALLOC_MODE__) && defined(__DYNAMIC_MALLOC_ALLOWED__) ulDynamicMemoryUsed+=ulDynamicSubTotal; #endif /*defined(__DEBUG_MALLOC_MODE__) && defined(__DYNAMIC_MALLOC_ALLOWED__)*/ ulStaticMemoryUsed+=ulStaticSubTotal; }/*for ucI*/ #if defined(__DEBUG_MALLOC_MODE__) && defined(__DYNAMIC_MALLOC_ALLOWED__) ulSize = ulDynamicMemoryUsed + ulStaticMemoryUsed; sprintf (szErrTxt, "=> Total Memory used for %d Modules/%d : Dynamic (%db)+ Static (%db) = %db (%.2fKb; %.2fMb)\n\n", ucNbModuleUsedMmg, g_ucErmNbOfModule, ulDynamicMemoryUsed, ulStaticMemoryUsed, ulSize, (float)ulSize/1024, (float)ulSize/(1024*1024)); #else /*#if defined(__DEBUG_MALLOC_MODE__) && defined(__DYNAMIC_MALLOC_ALLOWED__)*/ sprintf (szErrTxt, "=> Total Static Memory used for %d Modules/%d : %db (%.2fKb; %.2fMb)\n\n", ucNbModuleUsedMmg, g_ucErmNbOfModule, ulStaticMemoryUsed, (float)ulStaticMemoryUsed/1024, (float)ulStaticMemoryUsed/(1024*1024)); #endif /*defined(__DEBUG_MALLOC_MODE__) && defined(__DYNAMIC_MALLOC_ALLOWED__)*/ Erm_fn_v_Printsz (szErrTxt); #endif /*__ERROR_STRINGS__*/ }/*Mmg_fn_v_PrintAllocationsUsedForMmg*/ /* ##F#=================================================================================== NAME : Mmg_fn_vGiveInformationBlock DESCRIPTION : Give information data on a block -> address of block beginning -> address of block end -> address of the first free -> the maximum address reached (different of the last address used) INPUT : Module Id Block ID pointer on structure of block info ========================================================================================= CREATION : 06-11-97/Pierrick Crepy =======================================================================================*/ void Mmg_fn_vGiveInformationBlock(unsigned char ucModuleId, unsigned char ucBlockId, struct tdstBlockInfo_ *p_stMyBlockInfoForOutside){ struct tdstBlockInfoPriv_ * p_stMyStBlockInfo; #ifdef __DEBUG_MALLOC_MODE__ #ifdef __FATAL_ERR_MMG__ if (ucBlockId >= g_a_ucBlocksNbInModule[ucModuleId]){ #ifdef __ERROR_STRINGS__ char szErrTxt[C_ucSizeOfErrTxt]; sprintf (szErrTxt, "BlockId = %d, but there are only %d Block\nin the module [", ucBlockId, g_a_ucBlocksNbInModule[ucModuleId]); Erm_M_GetModuleInformation(szErrTxt+strlen(szErrTxt), ucModuleId); sprintf (szErrTxt+strlen(szErrTxt), "]\n"); Mmg_M_UpdateLastError(E_uwMmgPbInvalidBlockId,szErrTxt); #else /*__ERROR_STRINGS__*/ Mmg_M_UpdateLastError(E_uwMmgPbInvalidBlockId,NULL); #endif /*__ERROR_STRINGS__*/ } #endif /*__FATAL_ERR_MMG__*/ #endif /*__DEBUG_MALLOC_MODE__*/ /*implicite else with the fatal error*/ p_stMyStBlockInfo = g_a_p_stMmgModuleBlocksInfo[ucModuleId]+ucBlockId; p_stMyBlockInfoForOutside->p_cBeginBlock = p_stMyStBlockInfo->p_cBeginBlock; p_stMyBlockInfoForOutside->p_cEndBlock = p_stMyStBlockInfo->p_cEndBlock; p_stMyBlockInfoForOutside->p_cFirstFree = p_stMyStBlockInfo->p_cFirstFree; p_stMyBlockInfoForOutside->p_cMaxMem = p_stMyStBlockInfo->p_cMaxMem; }/*Mmg_fn_vGiveInformationBlock*/ /* ##F#=================================================================================== NAME : Mmg_fn_vSaveInformationBlock DESCRIPTION : Init a block with the following info structure -> address of block beginning -> address of block end -> address of the first free -> the maximum address reached (different of the last address used) INPUT : Module Id Block ID pointer on structure of block info ========================================================================================= CREATION : 06-11-97/Pierrick Crepy =======================================================================================*/ void Mmg_fn_vSaveInformationBlock(unsigned char ucModuleId, unsigned char ucBlockId, struct tdstBlockInfo_ *p_stMyBlockInfoFromOutside){ struct tdstBlockInfoPriv_ * p_stMyStBlockInfo; #ifdef __DEBUG_MALLOC_MODE__ #ifdef __FATAL_ERR_MMG__ if (ucBlockId >= g_a_ucBlocksNbInModule[ucModuleId]){ #ifdef __ERROR_STRINGS__ char szErrTxt[C_ucSizeOfErrTxt]; sprintf (szErrTxt, "BlockId = %d, but there are only %d Block\nin the module [", ucBlockId, g_a_ucBlocksNbInModule[ucModuleId]); Erm_M_GetModuleInformation(szErrTxt+strlen(szErrTxt), ucModuleId); sprintf (szErrTxt+strlen(szErrTxt), "]\n"); Mmg_M_UpdateLastError(E_uwMmgPbInvalidBlockId,szErrTxt); #else /*__ERROR_STRINGS__*/ Mmg_M_UpdateLastError(E_uwMmgPbInvalidBlockId,NULL); #endif /*__ERROR_STRINGS__*/ } #endif /*__FATAL_ERR_MMG__*/ #endif /*__DEBUG_MALLOC_MODE__*/ /*implicite else with the fatal error*/ p_stMyStBlockInfo = g_a_p_stMmgModuleBlocksInfo[ucModuleId]+ucBlockId; p_stMyStBlockInfo->p_cBeginBlock = p_stMyBlockInfoFromOutside->p_cBeginBlock ; p_stMyStBlockInfo->p_cEndBlock = p_stMyBlockInfoFromOutside->p_cEndBlock; p_stMyStBlockInfo->p_cFirstFree = p_stMyBlockInfoFromOutside->p_cFirstFree; p_stMyStBlockInfo->p_cMaxMem = p_stMyBlockInfoFromOutside->p_cMaxMem; }/*Mmg_fn_vSaveInformationBlock*/ /* ##F#=================================================================================== NAME : Mmg_fn_ulSizeOfUsefullMemory DESCRIPTION : return the size of the usefull memory in a block INPUT : Module Id Block ID OUTPUT : size of usefull memory ========================================================================================= CREATION : 06-11-97/Pierrick Crepy =======================================================================================*/ unsigned long Mmg_fn_ulSizeOfUsefullMemory (unsigned char ucModuleId, unsigned char ucBlockId){ unitAlloc * p_uaLastFree; struct tdstBlockInfoPriv_ * p_stMyStBlockInfo; #ifdef __DEBUG_MALLOC_MODE__ #ifdef __FATAL_ERR_MMG__ if (ucBlockId >= g_a_ucBlocksNbInModule[ucModuleId]){ #ifdef __ERROR_STRINGS__ char szErrTxt[C_ucSizeOfErrTxt]; sprintf (szErrTxt, "BlockId = %d, but there are only %d Block\nin the module [", ucBlockId, g_a_ucBlocksNbInModule[ucModuleId]); Erm_M_GetModuleInformation(szErrTxt+strlen(szErrTxt), ucModuleId); sprintf (szErrTxt+strlen(szErrTxt), "]\n"); Mmg_M_UpdateLastError(E_uwMmgPbInvalidBlockId,szErrTxt); #else /*__ERROR_STRINGS__*/ Mmg_M_UpdateLastError(E_uwMmgPbInvalidBlockId,NULL); #endif /*__ERROR_STRINGS__*/ } #endif /*__FATAL_ERR_MMG__*/ #endif /*__DEBUG_MALLOC_MODE__*/ /*implicite else with the fatal error*/ p_stMyStBlockInfo = g_a_p_stMmgModuleBlocksInfo[ucModuleId]+ucBlockId; if (p_stMyStBlockInfo->p_cFirstFree == C_FirstFreeValueForBlockWithoutFree ){/* Block with free*/ #ifdef D_CheckSystemForBlockWithoutFree return (p_stMyStBlockInfo->p_cMaxMem - p_stMyStBlockInfo->p_cBeginBlock + 1); #else /*D_CheckSystemForBlockWithoutFree*/ return (p_stMyStBlockInfo->p_cMaxMem - p_stMyStBlockInfo->p_cBeginBlock + 1 - (((tdstInformationHeaderOfBolckWithoutFree *)p_stMyStBlockInfo->p_cBeginBlock)->ucBoundededHeaderSize)); #endif /*D_CheckSystemForBlockWithoutFree*/ } else{ /* Block with free*/ p_uaLastFree = (unitAlloc *)p_stMyStBlockInfo->p_cFirstFree; while (((unitAlloc *)p_uaLastFree != NULL) && ((unitAlloc *)*(p_uaLastFree +1) != NULL) ){ p_uaLastFree = (unitAlloc *)*(p_uaLastFree +1); } if ( (p_uaLastFree != NULL) && ((char *)(p_uaLastFree + *(p_uaLastFree)))-1 == p_stMyStBlockInfo->p_cEndBlock ) {/* the block is not full */ return ( ((char *)(p_uaLastFree + C_ucFreeHeaderSize)) - p_stMyStBlockInfo->p_cBeginBlock); } else { /* the block is full */ return (p_stMyStBlockInfo->p_cEndBlock - p_stMyStBlockInfo->p_cBeginBlock + 1); } } }/*Mmg_fn_ulSizeOfUsefullMemory */ #endif /* _FIRE_DEADCODE_U64_ */ #ifdef __ERROR_STRINGS__ /* ##F#=================================================================================== NAME : Mmg_fn_v_UpdateLastErrorWithModuleId DESCRIPTION : raise an error using module Id INPUT : Module Id Error to raise Message to display ========================================================================================= CREATION : 06-11-97/Pierrick Crepy =======================================================================================*/ void Mmg_fn_v_UpdateLastErrorWithModuleId(unsigned char ucModuleId,unsigned short uwMyErr, char *szPersonalTxt) { char szMyRealTxt[C_ucSizeOfErrTxt]; if (szPersonalTxt != NULL){ sprintf (szMyRealTxt, "In ["); Erm_M_GetModuleInformation(szMyRealTxt+strlen(szMyRealTxt), ucModuleId); sprintf (szMyRealTxt+strlen(szMyRealTxt), "]\n%s", szPersonalTxt); } else{ sprintf (szMyRealTxt, "In ["); Erm_M_GetModuleInformation(szMyRealTxt+strlen(szMyRealTxt), ucModuleId); sprintf (szMyRealTxt+strlen(szMyRealTxt), "]\n"); } Erm_M_UpdateLastError (Mmg, C_ucErmDefaultChannel, uwMyErr, C_lErmNoDebugData, C_ucErmOpenInfoWindow, C_ucAllowStopForDebug, szMyRealTxt); } /* ##F#=================================================================================== NAME : Mmg_fn_v_UpdateLastErrorWithCurrentModeInfo DESCRIPTION : raise an error using channel INPUT : Error to raise Message to display Channel Id ========================================================================================= CREATION : 06-11-97/Pierrick Crepy =======================================================================================*/ void Mmg_fn_v_UpdateLastErrorWithCurrentModeInfo(unsigned short uwMyErr,char * szPersonalTxt,unsigned char ucChannel) { tdstCurrentModeInfo stCurrentModeInfo = g_d_stCurrentModeInfo[ucChannel]; char szMyRealTxt[C_ucSizeOfErrTxt]; if (stCurrentModeInfo.ucMode == E_ucDynamic) if (szPersonalTxt != NULL){ sprintf (szMyRealTxt, "In ["); Erm_M_GetModuleInformation(szMyRealTxt+strlen(szMyRealTxt), stCurrentModeInfo.ucModuleId); sprintf (szMyRealTxt+strlen(szMyRealTxt), "], for Dynamic mode\n%s", szPersonalTxt); } else{ sprintf (szMyRealTxt, "In ["); Erm_M_GetModuleInformation(szMyRealTxt+strlen(szMyRealTxt), stCurrentModeInfo.ucModuleId); sprintf (szMyRealTxt+strlen(szMyRealTxt), "], for Dynamic mode\n"); } else if (szPersonalTxt != NULL){ sprintf (szMyRealTxt, "In ["); Erm_M_GetModuleInformation(szMyRealTxt+strlen(szMyRealTxt), stCurrentModeInfo.ucModuleId); sprintf (szMyRealTxt+strlen(szMyRealTxt), "], for Static mode (Block #%d)\n%s", stCurrentModeInfo.ucMode, szPersonalTxt); } else{ sprintf (szMyRealTxt, "In ["); Erm_M_GetModuleInformation(szMyRealTxt+strlen(szMyRealTxt), stCurrentModeInfo.ucModuleId); sprintf (szMyRealTxt+strlen(szMyRealTxt), "], for Static mode (Block #%d)\n", stCurrentModeInfo.ucMode); } Mmg_M_szAddChannelInfoToSzInitTxt(szMyRealTxt, ucChannel); Erm_M_UpdateLastError (Mmg, C_ucErmDefaultChannel, uwMyErr, C_lErmNoDebugData, C_ucErmOpenInfoWindow, C_ucAllowStopForDebug, szMyRealTxt); }/* end of Mmg_fn_v_UpdateLastErrorWithCurrentModeInfo*/ /* ##F#=================================================================================== NAME : Mmg_fn_v_UpdateLastErrorWithModuleIdAnducModeReference DESCRIPTION : raise an error using module id and allocation mode INPUT : Module Id Allocation Mode Error to raise Message to display ========================================================================================= CREATION : 06-11-97/Pierrick Crepy =======================================================================================*/ void Mmg_fn_v_UpdateLastErrorWithModuleIdAnducModeReference(unsigned char ucModuleId, unsigned char ucMode, unsigned short uwMyErr, char *szPersonalTxt) { char szMyRealTxt[C_ucSizeOfErrTxt]; if (ucMode == E_ucDynamic) if (szPersonalTxt != NULL){ sprintf (szMyRealTxt, "In ["); Erm_M_GetModuleInformation(szMyRealTxt+strlen(szMyRealTxt), ucModuleId); sprintf (szMyRealTxt+strlen(szMyRealTxt), "], for Dynamic mode\n%s", szPersonalTxt); } else{ sprintf (szMyRealTxt, "In ["); Erm_M_GetModuleInformation(szMyRealTxt+strlen(szMyRealTxt), ucModuleId); sprintf (szMyRealTxt+strlen(szMyRealTxt), "], for Dynamic mode\n"); } else if (szPersonalTxt != NULL){ sprintf (szMyRealTxt, "In ["); Erm_M_GetModuleInformation(szMyRealTxt+strlen(szMyRealTxt), ucModuleId); sprintf (szMyRealTxt+strlen(szMyRealTxt), "], for Static mode (Block #%d)\n%s", ucMode, szPersonalTxt); } else{ sprintf (szMyRealTxt, "In ["); Erm_M_GetModuleInformation(szMyRealTxt+strlen(szMyRealTxt), ucModuleId); sprintf (szMyRealTxt+strlen(szMyRealTxt), "], for Static mode (Block #%d)\n", ucMode); } Erm_M_UpdateLastError (Mmg, C_ucErmDefaultChannel, uwMyErr, C_lErmNoDebugData, C_ucErmOpenInfoWindow, C_ucAllowStopForDebug, szMyRealTxt); }/*end Mmg_fn_v_UpdateLastErrorWithModuleIdAnducModeReference*/ #endif /*__ERROR_STRINGS__*/