Skip to content

Commit

Permalink
Fix nasa#651, Use resource ID for memory pools
Browse files Browse the repository at this point in the history
Instead of identifying a memory pool by its memory address,
use a resource ID.  IDs are a constant size, regardless of
whether the host machine is 32 or 64 bits.

- IDs can be put into commands/telemetry and maintain a more
  consistent format with consistent alignment requirements.
- IDs can be independently verified without dereferencing
  memory.  Previously the only way to validate a memory pool
  was to read the address pointed to, which results in a SEGV
  if the address was bad.
  • Loading branch information
jphickey committed Sep 29, 2020
1 parent 8a7dc8f commit 69e129e
Show file tree
Hide file tree
Showing 20 changed files with 2,539 additions and 1,028 deletions.
35 changes: 35 additions & 0 deletions fsw/cfe-core/src/es/cfe_es_apps.c
Original file line number Diff line number Diff line change
Expand Up @@ -1088,6 +1088,8 @@ int32 CFE_ES_CleanUpApp(CFE_ES_AppRecord_t *AppRecPtr)
CFE_ES_ResourceID_t CurrTaskId;
int32 ReturnCode = CFE_SUCCESS;
CFE_ES_TaskRecord_t *TaskRecPtr;
CFE_ES_MemPoolRecord_t *MemPoolRecPtr;
CFE_ES_ResourceID_t PoolId;
CFE_ES_ResourceID_t AppId;

/*
Expand Down Expand Up @@ -1171,6 +1173,7 @@ int32 CFE_ES_CleanUpApp(CFE_ES_AppRecord_t *AppRecPtr)

}


/*
** Remove the app from the AppTable
*/
Expand All @@ -1191,6 +1194,38 @@ int32 CFE_ES_CleanUpApp(CFE_ES_AppRecord_t *AppRecPtr)

CFE_ES_AppRecordSetFree(AppRecPtr);

/*
** Delete any memory pools associated with this app
*/
MemPoolRecPtr = CFE_ES_Global.MemPoolTable;
for ( i = 0; i < CFE_PLATFORM_ES_MAX_MEMORY_POOLS; i++ )
{
if ( CFE_ES_MemPoolRecordIsUsed(MemPoolRecPtr) &&
CFE_ES_ResourceID_Equal(MemPoolRecPtr->OwnerAppID, AppId))
{
PoolId = CFE_ES_MemPoolRecordGetID(MemPoolRecPtr);

/*
* This needs to release the lock first because
* CFE_ES_MemPoolDelete acquires the lock.
*/
CFE_ES_UnlockSharedData(__func__, __LINE__);
Status = CFE_ES_MemPoolDelete(PoolId);
CFE_ES_LockSharedData(__func__, __LINE__);

if ( Status != CFE_SUCCESS )
{
CFE_ES_SysLogWrite_Unsync("CFE_ES_MemPoolCleanupApp: delete pool %lu returned Error: 0x%08X\n",
CFE_ES_ResourceID_ToInteger(PoolId), (unsigned int)Status);
ReturnCode = CFE_ES_APP_CLEANUP_ERR;
}
}

++MemPoolRecPtr;
} /* end for */



CFE_ES_UnlockSharedData(__func__,__LINE__);

return(ReturnCode);
Expand Down
Loading

0 comments on commit 69e129e

Please sign in to comment.