Skip to content

Commit 526be52

Browse files
committed
Change xPortRaisePrivilege and vPortResetPrivilege to macros
This prevents non-kernel code from calling these functions. Signed-off-by: Gaurav Aggarwal <aggarg@amazon.com>
1 parent a030d0a commit 526be52

File tree

6 files changed

+341
-235
lines changed

6 files changed

+341
-235
lines changed

include/mpu_wrappers.h

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,11 +168,41 @@
168168

169169
#else /* MPU_WRAPPERS_INCLUDED_FROM_API_FILE */
170170

171-
/* Ensure API functions go in the privileged execution section. */
171+
/* Ensure API functions go in the privileged execution section. */
172172
#define PRIVILEGED_FUNCTION __attribute__( ( section( "privileged_functions" ) ) )
173173
#define PRIVILEGED_DATA __attribute__( ( section( "privileged_data" ) ) )
174174
#define FREERTOS_SYSTEM_CALL __attribute__( ( section( "freertos_system_calls" ) ) )
175175

176+
/**
177+
* @brief Calls the port specific code to raise the privilege.
178+
*
179+
* Sets xRunningPrivileged to pdFALSE if privilege was raised, else sets
180+
* it to pdTRUE.
181+
*/
182+
#define xPortRaisePrivilege( xRunningPrivileged ) \
183+
{ \
184+
/* Check whether the processor is already privileged. */ \
185+
xRunningPrivileged = portIS_PRIVILEGED(); \
186+
\
187+
/* If the processor is not already privileged, raise privilege. */ \
188+
if( xRunningPrivileged == pdFALSE ) \
189+
{ \
190+
portRAISE_PRIVILEGE(); \
191+
} \
192+
}
193+
194+
/**
195+
* @brief If xRunningPrivileged is not pdTRUE, calls the port specific
196+
* code to reset the privilege, otherwise does nothing.
197+
*/
198+
#define vPortResetPrivilege( xRunningPrivileged ) \
199+
{ \
200+
if( xRunningPrivileged == pdFALSE ) \
201+
{ \
202+
portRESET_PRIVILEGE(); \
203+
} \
204+
}
205+
176206
#endif /* MPU_WRAPPERS_INCLUDED_FROM_API_FILE */
177207

178208
#else /* portUSING_MPU_WRAPPERS */

0 commit comments

Comments
 (0)