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 f6ae2fb
Show file tree
Hide file tree
Showing 21 changed files with 2,638 additions and 1,047 deletions.
34 changes: 34 additions & 0 deletions cmake/sample_defs/cpu1_platform_cfg.h
Original file line number Diff line number Diff line change
Expand Up @@ -1365,6 +1365,40 @@
#define CFE_PLATFORM_ES_MAX_PROCESSOR_RESETS 2


/** \cfeescfg Maximum number of block sizes in pool structures
**
** \par Description:
** The upper limit for the number of block sizes supported in the generic
** pool implementation, which in turn implements the memory pools and CDS.
**
** \par Limits:
** Must be at least one. No specific upper limit, but the number is
** anticipated to be reasonably small (i.e. tens, not hundreds). Large
** values have not been tested.
**
** The ES and CDS block size lists must correlate with this value
*/
#define CFE_PLATFORM_ES_POOL_MAX_BUCKETS 17

/** \cfeescfg Maximum number of memory pools
**
** \par Description:
** The upper limit for the number of memory pools than can concurrently
** exist within the system.
**
** The CFE_SB and CFE_TBL core subsystems each define a memory pool.
**
** Individual applications may also create memory pools, so this value
** should be set sufficiently high enough to support the applications
** being used on this platform.
**
** \par Limits:
** Must be at least 2 to support CFE core - SB and TBL pools. No
** specific upper limit.
*/
#define CFE_PLATFORM_ES_MAX_MEMORY_POOLS 10


/**
** \cfeescfg Define Default ES Memory Pool Block Sizes
**
Expand Down
34 changes: 34 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_MemHandle_t PoolId;
CFE_ES_ResourceID_t AppId;

/*
Expand Down Expand Up @@ -1191,6 +1193,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_PoolDelete acquires the lock.
*/
CFE_ES_UnlockSharedData(__func__, __LINE__);
Status = CFE_ES_PoolDelete(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 f6ae2fb

Please sign in to comment.