Skip to content

Commit 39dbff7

Browse files
kar-rahul-awsSkptakaggarg
authored
Allow xPortIsAuthorizedToAccessBuffer() API call only from mpu_wrappers_v2 (#992)
* Add support to call xPortxPortIsAuthorizedToAccessBuffer function only when using latest MPU wrappers * Fix build issue in ARM CM3 MPU port * Code review suggestions Signed-off-by: Gaurav Aggarwal <aggarg@amazon.com> --------- Signed-off-by: Gaurav Aggarwal <aggarg@amazon.com> Co-authored-by: Soren Ptak <ptaksoren@gmail.com> Co-authored-by: Gaurav Aggarwal <aggarg@amazon.com> Co-authored-by: Gaurav-Aggarwal-AWS <33462878+aggarg@users.noreply.github.com>
1 parent a455b86 commit 39dbff7

File tree

25 files changed

+555
-287
lines changed

25 files changed

+555
-287
lines changed

portable/ARMv8M/non_secure/port.c

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -496,14 +496,14 @@ portDONT_DISCARD void vPortSVCHandler_C( uint32_t * pulCallerStackAddress ) PRIV
496496
#endif /* configENABLE_MPU == 1 */
497497
/*-----------------------------------------------------------*/
498498

499-
#if ( ( configENABLE_MPU == 1 ) && ( configUSE_MPU_WRAPPERS_V1 == 0 ) && ( configENABLE_ACCESS_CONTROL_LIST == 1 ) )
499+
#if ( ( configENABLE_MPU == 1 ) && ( configUSE_MPU_WRAPPERS_V1 == 0 ) )
500500

501501
/**
502502
* @brief This variable is set to pdTRUE when the scheduler is started.
503503
*/
504504
PRIVILEGED_DATA static BaseType_t xSchedulerRunning = pdFALSE;
505505

506-
#endif
506+
#endif /* ( configENABLE_MPU == 1 ) && ( configUSE_MPU_WRAPPERS_V1 == 0 ) */
507507

508508
/**
509509
* @brief Each task maintains its own interrupt status in the critical nesting
@@ -555,6 +555,7 @@ PRIVILEGED_DATA static volatile uint32_t ulCriticalNesting = 0xaaaaaaaaUL;
555555
/*-----------------------------------------------------------*/
556556

557557
#if ( configUSE_TICKLESS_IDLE == 1 )
558+
558559
__attribute__( ( weak ) ) void vPortSuppressTicksAndSleep( TickType_t xExpectedIdleTime )
559560
{
560561
uint32_t ulReloadValue, ulCompleteTickPeriods, ulCompletedSysTickDecrements, ulSysTickDecrementsLeft;
@@ -770,6 +771,7 @@ PRIVILEGED_DATA static volatile uint32_t ulCriticalNesting = 0xaaaaaaaaUL;
770771
__asm volatile ( "cpsie i" ::: "memory" );
771772
}
772773
}
774+
773775
#endif /* configUSE_TICKLESS_IDLE */
774776
/*-----------------------------------------------------------*/
775777

@@ -827,6 +829,7 @@ static void prvTaskExitError( void )
827829
/*-----------------------------------------------------------*/
828830

829831
#if ( configENABLE_MPU == 1 )
832+
830833
static uint32_t prvGetRegionAccessPermissions( uint32_t ulRBARValue ) /* PRIVILEGED_FUNCTION */
831834
{
832835
uint32_t ulAccessPermissions = 0;
@@ -843,10 +846,12 @@ static void prvTaskExitError( void )
843846

844847
return ulAccessPermissions;
845848
}
849+
846850
#endif /* configENABLE_MPU */
847851
/*-----------------------------------------------------------*/
848852

849853
#if ( configENABLE_MPU == 1 )
854+
850855
static void prvSetupMPU( void ) /* PRIVILEGED_FUNCTION */
851856
{
852857
#if defined( __ARMCC_VERSION )
@@ -935,10 +940,12 @@ static void prvTaskExitError( void )
935940
portMPU_CTRL_REG |= ( portMPU_PRIV_BACKGROUND_ENABLE_BIT | portMPU_ENABLE_BIT );
936941
}
937942
}
943+
938944
#endif /* configENABLE_MPU */
939945
/*-----------------------------------------------------------*/
940946

941947
#if ( configENABLE_FPU == 1 )
948+
942949
static void prvSetupFPU( void ) /* PRIVILEGED_FUNCTION */
943950
{
944951
#if ( configENABLE_TRUSTZONE == 1 )
@@ -960,6 +967,7 @@ static void prvTaskExitError( void )
960967
* LSPEN = 1 ==> Enable lazy context save of FP state. */
961968
*( portFPCCR ) |= ( portFPCCR_ASPEN_MASK | portFPCCR_LSPEN_MASK );
962969
}
970+
963971
#endif /* configENABLE_FPU */
964972
/*-----------------------------------------------------------*/
965973

@@ -1740,11 +1748,11 @@ BaseType_t xPortStartScheduler( void ) /* PRIVILEGED_FUNCTION */
17401748
/* Initialize the critical nesting count ready for the first task. */
17411749
ulCriticalNesting = 0;
17421750

1743-
#if ( ( configENABLE_MPU == 1 ) && ( configUSE_MPU_WRAPPERS_V1 == 0 ) && ( configENABLE_ACCESS_CONTROL_LIST == 1 ) )
1751+
#if ( ( configENABLE_MPU == 1 ) && ( configUSE_MPU_WRAPPERS_V1 == 0 ) )
17441752
{
17451753
xSchedulerRunning = pdTRUE;
17461754
}
1747-
#endif
1755+
#endif /* ( ( configENABLE_MPU == 1 ) && ( configUSE_MPU_WRAPPERS_V1 == 0 ) ) */
17481756

17491757
/* Start the first task. */
17501758
vStartFirstTask();
@@ -1772,6 +1780,7 @@ void vPortEndScheduler( void ) /* PRIVILEGED_FUNCTION */
17721780
/*-----------------------------------------------------------*/
17731781

17741782
#if ( configENABLE_MPU == 1 )
1783+
17751784
void vPortStoreTaskMPUSettings( xMPU_SETTINGS * xMPUSettings,
17761785
const struct xMEMORY_REGION * const xRegions,
17771786
StackType_t * pxBottomOfStack,
@@ -1893,10 +1902,12 @@ void vPortEndScheduler( void ) /* PRIVILEGED_FUNCTION */
18931902
lIndex++;
18941903
}
18951904
}
1905+
18961906
#endif /* configENABLE_MPU */
18971907
/*-----------------------------------------------------------*/
18981908

1899-
#if ( configENABLE_MPU == 1 )
1909+
#if ( ( configENABLE_MPU == 1 ) && ( configUSE_MPU_WRAPPERS_V1 == 0 ) )
1910+
19001911
BaseType_t xPortIsAuthorizedToAccessBuffer( const void * pvBuffer,
19011912
uint32_t ulBufferLength,
19021913
uint32_t ulAccessRequested ) /* PRIVILEGED_FUNCTION */
@@ -1949,7 +1960,8 @@ void vPortEndScheduler( void ) /* PRIVILEGED_FUNCTION */
19491960

19501961
return xAccessGranted;
19511962
}
1952-
#endif /* configENABLE_MPU */
1963+
1964+
#endif /* #if ( configENABLE_MPU == 1 ) && ( configUSE_MPU_WRAPPERS_V1 == 0 ) */
19531965
/*-----------------------------------------------------------*/
19541966

19551967
BaseType_t xPortIsInsideInterrupt( void )

portable/GCC/ARM_CM23/non_secure/port.c

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -496,14 +496,14 @@ portDONT_DISCARD void vPortSVCHandler_C( uint32_t * pulCallerStackAddress ) PRIV
496496
#endif /* configENABLE_MPU == 1 */
497497
/*-----------------------------------------------------------*/
498498

499-
#if ( ( configENABLE_MPU == 1 ) && ( configUSE_MPU_WRAPPERS_V1 == 0 ) && ( configENABLE_ACCESS_CONTROL_LIST == 1 ) )
499+
#if ( ( configENABLE_MPU == 1 ) && ( configUSE_MPU_WRAPPERS_V1 == 0 ) )
500500

501501
/**
502502
* @brief This variable is set to pdTRUE when the scheduler is started.
503503
*/
504504
PRIVILEGED_DATA static BaseType_t xSchedulerRunning = pdFALSE;
505505

506-
#endif
506+
#endif /* ( configENABLE_MPU == 1 ) && ( configUSE_MPU_WRAPPERS_V1 == 0 ) */
507507

508508
/**
509509
* @brief Each task maintains its own interrupt status in the critical nesting
@@ -555,6 +555,7 @@ PRIVILEGED_DATA static volatile uint32_t ulCriticalNesting = 0xaaaaaaaaUL;
555555
/*-----------------------------------------------------------*/
556556

557557
#if ( configUSE_TICKLESS_IDLE == 1 )
558+
558559
__attribute__( ( weak ) ) void vPortSuppressTicksAndSleep( TickType_t xExpectedIdleTime )
559560
{
560561
uint32_t ulReloadValue, ulCompleteTickPeriods, ulCompletedSysTickDecrements, ulSysTickDecrementsLeft;
@@ -770,6 +771,7 @@ PRIVILEGED_DATA static volatile uint32_t ulCriticalNesting = 0xaaaaaaaaUL;
770771
__asm volatile ( "cpsie i" ::: "memory" );
771772
}
772773
}
774+
773775
#endif /* configUSE_TICKLESS_IDLE */
774776
/*-----------------------------------------------------------*/
775777

@@ -827,6 +829,7 @@ static void prvTaskExitError( void )
827829
/*-----------------------------------------------------------*/
828830

829831
#if ( configENABLE_MPU == 1 )
832+
830833
static uint32_t prvGetRegionAccessPermissions( uint32_t ulRBARValue ) /* PRIVILEGED_FUNCTION */
831834
{
832835
uint32_t ulAccessPermissions = 0;
@@ -843,10 +846,12 @@ static void prvTaskExitError( void )
843846

844847
return ulAccessPermissions;
845848
}
849+
846850
#endif /* configENABLE_MPU */
847851
/*-----------------------------------------------------------*/
848852

849853
#if ( configENABLE_MPU == 1 )
854+
850855
static void prvSetupMPU( void ) /* PRIVILEGED_FUNCTION */
851856
{
852857
#if defined( __ARMCC_VERSION )
@@ -935,10 +940,12 @@ static void prvTaskExitError( void )
935940
portMPU_CTRL_REG |= ( portMPU_PRIV_BACKGROUND_ENABLE_BIT | portMPU_ENABLE_BIT );
936941
}
937942
}
943+
938944
#endif /* configENABLE_MPU */
939945
/*-----------------------------------------------------------*/
940946

941947
#if ( configENABLE_FPU == 1 )
948+
942949
static void prvSetupFPU( void ) /* PRIVILEGED_FUNCTION */
943950
{
944951
#if ( configENABLE_TRUSTZONE == 1 )
@@ -960,6 +967,7 @@ static void prvTaskExitError( void )
960967
* LSPEN = 1 ==> Enable lazy context save of FP state. */
961968
*( portFPCCR ) |= ( portFPCCR_ASPEN_MASK | portFPCCR_LSPEN_MASK );
962969
}
970+
963971
#endif /* configENABLE_FPU */
964972
/*-----------------------------------------------------------*/
965973

@@ -1740,11 +1748,11 @@ BaseType_t xPortStartScheduler( void ) /* PRIVILEGED_FUNCTION */
17401748
/* Initialize the critical nesting count ready for the first task. */
17411749
ulCriticalNesting = 0;
17421750

1743-
#if ( ( configENABLE_MPU == 1 ) && ( configUSE_MPU_WRAPPERS_V1 == 0 ) && ( configENABLE_ACCESS_CONTROL_LIST == 1 ) )
1751+
#if ( ( configENABLE_MPU == 1 ) && ( configUSE_MPU_WRAPPERS_V1 == 0 ) )
17441752
{
17451753
xSchedulerRunning = pdTRUE;
17461754
}
1747-
#endif
1755+
#endif /* ( ( configENABLE_MPU == 1 ) && ( configUSE_MPU_WRAPPERS_V1 == 0 ) ) */
17481756

17491757
/* Start the first task. */
17501758
vStartFirstTask();
@@ -1772,6 +1780,7 @@ void vPortEndScheduler( void ) /* PRIVILEGED_FUNCTION */
17721780
/*-----------------------------------------------------------*/
17731781

17741782
#if ( configENABLE_MPU == 1 )
1783+
17751784
void vPortStoreTaskMPUSettings( xMPU_SETTINGS * xMPUSettings,
17761785
const struct xMEMORY_REGION * const xRegions,
17771786
StackType_t * pxBottomOfStack,
@@ -1893,10 +1902,12 @@ void vPortEndScheduler( void ) /* PRIVILEGED_FUNCTION */
18931902
lIndex++;
18941903
}
18951904
}
1905+
18961906
#endif /* configENABLE_MPU */
18971907
/*-----------------------------------------------------------*/
18981908

1899-
#if ( configENABLE_MPU == 1 )
1909+
#if ( ( configENABLE_MPU == 1 ) && ( configUSE_MPU_WRAPPERS_V1 == 0 ) )
1910+
19001911
BaseType_t xPortIsAuthorizedToAccessBuffer( const void * pvBuffer,
19011912
uint32_t ulBufferLength,
19021913
uint32_t ulAccessRequested ) /* PRIVILEGED_FUNCTION */
@@ -1949,7 +1960,8 @@ void vPortEndScheduler( void ) /* PRIVILEGED_FUNCTION */
19491960

19501961
return xAccessGranted;
19511962
}
1952-
#endif /* configENABLE_MPU */
1963+
1964+
#endif /* #if ( configENABLE_MPU == 1 ) && ( configUSE_MPU_WRAPPERS_V1 == 0 ) */
19531965
/*-----------------------------------------------------------*/
19541966

19551967
BaseType_t xPortIsInsideInterrupt( void )

portable/GCC/ARM_CM23_NTZ/non_secure/port.c

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -496,14 +496,14 @@ portDONT_DISCARD void vPortSVCHandler_C( uint32_t * pulCallerStackAddress ) PRIV
496496
#endif /* configENABLE_MPU == 1 */
497497
/*-----------------------------------------------------------*/
498498

499-
#if ( ( configENABLE_MPU == 1 ) && ( configUSE_MPU_WRAPPERS_V1 == 0 ) && ( configENABLE_ACCESS_CONTROL_LIST == 1 ) )
499+
#if ( ( configENABLE_MPU == 1 ) && ( configUSE_MPU_WRAPPERS_V1 == 0 ) )
500500

501501
/**
502502
* @brief This variable is set to pdTRUE when the scheduler is started.
503503
*/
504504
PRIVILEGED_DATA static BaseType_t xSchedulerRunning = pdFALSE;
505505

506-
#endif
506+
#endif /* ( configENABLE_MPU == 1 ) && ( configUSE_MPU_WRAPPERS_V1 == 0 ) */
507507

508508
/**
509509
* @brief Each task maintains its own interrupt status in the critical nesting
@@ -555,6 +555,7 @@ PRIVILEGED_DATA static volatile uint32_t ulCriticalNesting = 0xaaaaaaaaUL;
555555
/*-----------------------------------------------------------*/
556556

557557
#if ( configUSE_TICKLESS_IDLE == 1 )
558+
558559
__attribute__( ( weak ) ) void vPortSuppressTicksAndSleep( TickType_t xExpectedIdleTime )
559560
{
560561
uint32_t ulReloadValue, ulCompleteTickPeriods, ulCompletedSysTickDecrements, ulSysTickDecrementsLeft;
@@ -770,6 +771,7 @@ PRIVILEGED_DATA static volatile uint32_t ulCriticalNesting = 0xaaaaaaaaUL;
770771
__asm volatile ( "cpsie i" ::: "memory" );
771772
}
772773
}
774+
773775
#endif /* configUSE_TICKLESS_IDLE */
774776
/*-----------------------------------------------------------*/
775777

@@ -827,6 +829,7 @@ static void prvTaskExitError( void )
827829
/*-----------------------------------------------------------*/
828830

829831
#if ( configENABLE_MPU == 1 )
832+
830833
static uint32_t prvGetRegionAccessPermissions( uint32_t ulRBARValue ) /* PRIVILEGED_FUNCTION */
831834
{
832835
uint32_t ulAccessPermissions = 0;
@@ -843,10 +846,12 @@ static void prvTaskExitError( void )
843846

844847
return ulAccessPermissions;
845848
}
849+
846850
#endif /* configENABLE_MPU */
847851
/*-----------------------------------------------------------*/
848852

849853
#if ( configENABLE_MPU == 1 )
854+
850855
static void prvSetupMPU( void ) /* PRIVILEGED_FUNCTION */
851856
{
852857
#if defined( __ARMCC_VERSION )
@@ -935,10 +940,12 @@ static void prvTaskExitError( void )
935940
portMPU_CTRL_REG |= ( portMPU_PRIV_BACKGROUND_ENABLE_BIT | portMPU_ENABLE_BIT );
936941
}
937942
}
943+
938944
#endif /* configENABLE_MPU */
939945
/*-----------------------------------------------------------*/
940946

941947
#if ( configENABLE_FPU == 1 )
948+
942949
static void prvSetupFPU( void ) /* PRIVILEGED_FUNCTION */
943950
{
944951
#if ( configENABLE_TRUSTZONE == 1 )
@@ -960,6 +967,7 @@ static void prvTaskExitError( void )
960967
* LSPEN = 1 ==> Enable lazy context save of FP state. */
961968
*( portFPCCR ) |= ( portFPCCR_ASPEN_MASK | portFPCCR_LSPEN_MASK );
962969
}
970+
963971
#endif /* configENABLE_FPU */
964972
/*-----------------------------------------------------------*/
965973

@@ -1740,11 +1748,11 @@ BaseType_t xPortStartScheduler( void ) /* PRIVILEGED_FUNCTION */
17401748
/* Initialize the critical nesting count ready for the first task. */
17411749
ulCriticalNesting = 0;
17421750

1743-
#if ( ( configENABLE_MPU == 1 ) && ( configUSE_MPU_WRAPPERS_V1 == 0 ) && ( configENABLE_ACCESS_CONTROL_LIST == 1 ) )
1751+
#if ( ( configENABLE_MPU == 1 ) && ( configUSE_MPU_WRAPPERS_V1 == 0 ) )
17441752
{
17451753
xSchedulerRunning = pdTRUE;
17461754
}
1747-
#endif
1755+
#endif /* ( ( configENABLE_MPU == 1 ) && ( configUSE_MPU_WRAPPERS_V1 == 0 ) ) */
17481756

17491757
/* Start the first task. */
17501758
vStartFirstTask();
@@ -1772,6 +1780,7 @@ void vPortEndScheduler( void ) /* PRIVILEGED_FUNCTION */
17721780
/*-----------------------------------------------------------*/
17731781

17741782
#if ( configENABLE_MPU == 1 )
1783+
17751784
void vPortStoreTaskMPUSettings( xMPU_SETTINGS * xMPUSettings,
17761785
const struct xMEMORY_REGION * const xRegions,
17771786
StackType_t * pxBottomOfStack,
@@ -1893,10 +1902,12 @@ void vPortEndScheduler( void ) /* PRIVILEGED_FUNCTION */
18931902
lIndex++;
18941903
}
18951904
}
1905+
18961906
#endif /* configENABLE_MPU */
18971907
/*-----------------------------------------------------------*/
18981908

1899-
#if ( configENABLE_MPU == 1 )
1909+
#if ( ( configENABLE_MPU == 1 ) && ( configUSE_MPU_WRAPPERS_V1 == 0 ) )
1910+
19001911
BaseType_t xPortIsAuthorizedToAccessBuffer( const void * pvBuffer,
19011912
uint32_t ulBufferLength,
19021913
uint32_t ulAccessRequested ) /* PRIVILEGED_FUNCTION */
@@ -1949,7 +1960,8 @@ void vPortEndScheduler( void ) /* PRIVILEGED_FUNCTION */
19491960

19501961
return xAccessGranted;
19511962
}
1952-
#endif /* configENABLE_MPU */
1963+
1964+
#endif /* #if ( configENABLE_MPU == 1 ) && ( configUSE_MPU_WRAPPERS_V1 == 0 ) */
19531965
/*-----------------------------------------------------------*/
19541966

19551967
BaseType_t xPortIsInsideInterrupt( void )

0 commit comments

Comments
 (0)