Hi there,
pxReadyTasksLists is an array bound by configMAX_PRIORITIES.
There are cases in which uxTopReadyPriority (which is used as an index into pxReadyTasksLists) exceeds configMAX_PRIORITIES, causing taskSELECT_HIGHEST_PRIORITY_TASK to accessing undefined memory. The control path is this (configUSE_PORT_OPTIMISED_TASK_SELECTION set)*:
#define taskSELECT_HIGHEST_PRIORITY_TASK() \
{ \
UBaseType_t uxTopPriority; \
/* Find the highest priority queue that contains ready tasks.*/ \
portGET_HIGHEST_PRIORITY( uxTopPriority, uxTopReadyPriority); \
configASSERT( listCURRENT_LIST_LENGTH( &( pxReadyTasksLists[ uxTopPriority ] ) ) > 0 ); \
listGET_OWNER_OF_NEXT_ENTRY( pxCurrentTCB, &( pxReadyTasksLists[ uxTopPriority ] ) ); \
} /* taskSELECT_HIGHEST_PRIORITY_TASK() */
where
#define portGET_HIGHEST_PRIORITY( uxTopPriority, uxReadyPriorities ) uxTopPriority = ( 31 - ucPortCountLeadingZeros( ( uxReadyPriorities ) ) )
(Cortex port).
It’s obvious why the macro does what it does; it tries to map the numeric priority to its MSB aligned representation conforming to the ARM interrupt architecture. Yet this value shouldn’t be used as an index into pxReadyTasksLists, right?
I’m obviously missing something because this code has been around for a very long time, so it should have been noticed before. What am I missing?
Thanks!
*Sorry, I couldn’t figure out how to format code reasonably in this forum software