Change xPortRaisePrivilege and vPortResetPrivilege to macros

This prevents non-kernel code from calling these functions.

Signed-off-by: Gaurav Aggarwal <aggarg@amazon.com>
This commit is contained in:
Gaurav Aggarwal 2021-10-06 18:56:51 -07:00 committed by Gaurav-Aggarwal-AWS
parent 78da9cb261
commit 7a3848753b
6 changed files with 341 additions and 235 deletions

View File

@ -173,6 +173,36 @@
#define PRIVILEGED_DATA __attribute__( ( section( "privileged_data" ) ) ) #define PRIVILEGED_DATA __attribute__( ( section( "privileged_data" ) ) )
#define FREERTOS_SYSTEM_CALL __attribute__( ( section( "freertos_system_calls" ) ) ) #define FREERTOS_SYSTEM_CALL __attribute__( ( section( "freertos_system_calls" ) ) )
/**
* @brief Calls the port specific code to raise the privilege.
*
* Sets xRunningPrivileged to pdFALSE if privilege was raised, else sets
* it to pdTRUE.
*/
#define xPortRaisePrivilege( xRunningPrivileged ) \
{ \
/* Check whether the processor is already privileged. */ \
xRunningPrivileged = portIS_PRIVILEGED(); \
\
/* If the processor is not already privileged, raise privilege. */ \
if( xRunningPrivileged == pdFALSE ) \
{ \
portRAISE_PRIVILEGE(); \
} \
}
/**
* @brief If xRunningPrivileged is not pdTRUE, calls the port specific
* code to reset the privilege, otherwise does nothing.
*/
#define vPortResetPrivilege( xRunningPrivileged ) \
{ \
if( xRunningPrivileged == pdFALSE ) \
{ \
portRESET_PRIVILEGE(); \
} \
}
#endif /* MPU_WRAPPERS_INCLUDED_FROM_API_FILE */ #endif /* MPU_WRAPPERS_INCLUDED_FROM_API_FILE */
#else /* portUSING_MPU_WRAPPERS */ #else /* portUSING_MPU_WRAPPERS */

File diff suppressed because it is too large Load Diff

View File

@ -160,17 +160,14 @@ BaseType_t xIsPrivileged( void ) __attribute__( ( naked ) );
void vResetPrivilege( void ) __attribute__( ( naked ) ); void vResetPrivilege( void ) __attribute__( ( naked ) );
/** /**
* @brief Calls the port specific code to raise the privilege. * @brief Enter critical section.
*
* @return pdFALSE if privilege was raised, pdTRUE otherwise.
*/ */
extern BaseType_t xPortRaisePrivilege( void ); void vPortEnterCritical( void ) FREERTOS_SYSTEM_CALL;
/** /**
* @brief If xRunningPrivileged is not pdTRUE, calls the port specific * @brief Exit from critical section.
* code to reset the privilege, otherwise does nothing.
*/ */
extern void vPortResetPrivilege( BaseType_t xRunningPrivileged ); void vPortExitCritical( void ) FREERTOS_SYSTEM_CALL;
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/
/* Each task maintains its own interrupt status in the critical nesting /* Each task maintains its own interrupt status in the critical nesting
@ -483,7 +480,8 @@ void vPortEndScheduler( void )
void vPortEnterCritical( void ) void vPortEnterCritical( void )
{ {
BaseType_t xRunningPrivileged = xPortRaisePrivilege(); BaseType_t xRunningPrivileged;
xPortRaisePrivilege( xRunningPrivileged );
portDISABLE_INTERRUPTS(); portDISABLE_INTERRUPTS();
uxCriticalNesting++; uxCriticalNesting++;
@ -494,7 +492,8 @@ void vPortEnterCritical( void )
void vPortExitCritical( void ) void vPortExitCritical( void )
{ {
BaseType_t xRunningPrivileged = xPortRaisePrivilege(); BaseType_t xRunningPrivileged;
xPortRaisePrivilege( xRunningPrivileged );
configASSERT( uxCriticalNesting ); configASSERT( uxCriticalNesting );
uxCriticalNesting--; uxCriticalNesting--;

View File

@ -173,17 +173,14 @@ BaseType_t xIsPrivileged( void ) __attribute__( ( naked ) );
void vResetPrivilege( void ) __attribute__( ( naked ) ); void vResetPrivilege( void ) __attribute__( ( naked ) );
/** /**
* @brief Calls the port specific code to raise the privilege. * @brief Enter critical section.
*
* @return pdFALSE if privilege was raised, pdTRUE otherwise.
*/ */
extern BaseType_t xPortRaisePrivilege( void ); void vPortEnterCritical( void ) FREERTOS_SYSTEM_CALL;
/** /**
* @brief If xRunningPrivileged is not pdTRUE, calls the port specific * @brief Exit from critical section.
* code to reset the privilege, otherwise does nothing.
*/ */
extern void vPortResetPrivilege( BaseType_t xRunningPrivileged ); void vPortExitCritical( void ) FREERTOS_SYSTEM_CALL;
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/
/* Each task maintains its own interrupt status in the critical nesting /* Each task maintains its own interrupt status in the critical nesting
@ -519,7 +516,8 @@ void vPortEndScheduler( void )
void vPortEnterCritical( void ) void vPortEnterCritical( void )
{ {
BaseType_t xRunningPrivileged = xPortRaisePrivilege(); BaseType_t xRunningPrivileged;
xPortRaisePrivilege( xRunningPrivileged );
portDISABLE_INTERRUPTS(); portDISABLE_INTERRUPTS();
uxCriticalNesting++; uxCriticalNesting++;
@ -530,7 +528,8 @@ void vPortEnterCritical( void )
void vPortExitCritical( void ) void vPortExitCritical( void )
{ {
BaseType_t xRunningPrivileged = xPortRaisePrivilege(); BaseType_t xRunningPrivileged;
xPortRaisePrivilege( xRunningPrivileged );
configASSERT( uxCriticalNesting ); configASSERT( uxCriticalNesting );
uxCriticalNesting--; uxCriticalNesting--;

View File

@ -186,17 +186,14 @@ void vPortSVCHandler_C( uint32_t * pulParam );
extern void vPortRestoreContextOfFirstTask( void ) PRIVILEGED_FUNCTION; extern void vPortRestoreContextOfFirstTask( void ) PRIVILEGED_FUNCTION;
/** /**
* @brief Calls the port specific code to raise the privilege. * @brief Enter critical section.
*
* @return pdFALSE if privilege was raised, pdTRUE otherwise.
*/ */
extern BaseType_t xPortRaisePrivilege( void ); void vPortEnterCritical( void ) FREERTOS_SYSTEM_CALL;
/** /**
* @brief If xRunningPrivileged is not pdTRUE, calls the port specific * @brief Exit from critical section.
* code to reset the privilege, otherwise does nothing.
*/ */
extern void vPortResetPrivilege( BaseType_t xRunningPrivileged ); void vPortExitCritical( void ) FREERTOS_SYSTEM_CALL;
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/
/* Each task maintains its own interrupt status in the critical nesting /* Each task maintains its own interrupt status in the critical nesting
@ -447,13 +444,12 @@ void vPortEndScheduler( void )
void vPortEnterCritical( void ) void vPortEnterCritical( void )
{ {
BaseType_t xRunningPrivileged = xPortRaisePrivilege(); BaseType_t xRunningPrivileged;
xPortRaisePrivilege( xRunningPrivileged );
portDISABLE_INTERRUPTS(); portDISABLE_INTERRUPTS();
uxCriticalNesting++; uxCriticalNesting++;
vPortResetPrivilege( xRunningPrivileged );
/* This is not the interrupt safe version of the enter critical function so /* This is not the interrupt safe version of the enter critical function so
* assert() if it is being called from an interrupt context. Only API * assert() if it is being called from an interrupt context. Only API
* functions that end in "FromISR" can be used in an interrupt. Only assert if * functions that end in "FromISR" can be used in an interrupt. Only assert if
@ -463,12 +459,15 @@ void vPortEnterCritical( void )
{ {
configASSERT( ( portNVIC_INT_CTRL_REG & portVECTACTIVE_MASK ) == 0 ); configASSERT( ( portNVIC_INT_CTRL_REG & portVECTACTIVE_MASK ) == 0 );
} }
vPortResetPrivilege( xRunningPrivileged );
} }
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/
void vPortExitCritical( void ) void vPortExitCritical( void )
{ {
BaseType_t xRunningPrivileged = xPortRaisePrivilege(); BaseType_t xRunningPrivileged;
xPortRaisePrivilege( xRunningPrivileged );
configASSERT( uxCriticalNesting ); configASSERT( uxCriticalNesting );

View File

@ -187,17 +187,14 @@ BaseType_t xIsPrivileged( void );
void vResetPrivilege( void ); void vResetPrivilege( void );
/** /**
* @brief Calls the port specific code to raise the privilege. * @brief Enter critical section.
*
* @return pdFALSE if privilege was raised, pdTRUE otherwise.
*/ */
extern BaseType_t xPortRaisePrivilege( void ); void vPortEnterCritical( void ) FREERTOS_SYSTEM_CALL;
/** /**
* @brief If xRunningPrivileged is not pdTRUE, calls the port specific * @brief Exit from critical section.
* code to reset the privilege, otherwise does nothing.
*/ */
extern void vPortResetPrivilege( BaseType_t xRunningPrivileged ); void vPortExitCritical( void ) FREERTOS_SYSTEM_CALL;
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/
/* /*
@ -522,7 +519,8 @@ void vPortEndScheduler( void )
void vPortEnterCritical( void ) void vPortEnterCritical( void )
{ {
BaseType_t xRunningPrivileged = xPortRaisePrivilege(); BaseType_t xRunningPrivileged;
xPortRaisePrivilege( xRunningPrivileged );
portDISABLE_INTERRUPTS(); portDISABLE_INTERRUPTS();
uxCriticalNesting++; uxCriticalNesting++;
@ -533,7 +531,8 @@ void vPortEnterCritical( void )
void vPortExitCritical( void ) void vPortExitCritical( void )
{ {
BaseType_t xRunningPrivileged = xPortRaisePrivilege(); BaseType_t xRunningPrivileged;
xPortRaisePrivilege( xRunningPrivileged );
configASSERT( uxCriticalNesting ); configASSERT( uxCriticalNesting );
uxCriticalNesting--; uxCriticalNesting--;