Skip to content

Commit ba50511

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 628059b commit ba50511

File tree

6 files changed

+337
-233
lines changed

6 files changed

+337
-233
lines changed

include/mpu_wrappers.h

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

166166
#else /* MPU_WRAPPERS_INCLUDED_FROM_API_FILE */
167167

168-
/* Ensure API functions go in the privileged execution section. */
168+
/* Ensure API functions go in the privileged execution section. */
169169
#define PRIVILEGED_FUNCTION __attribute__( ( section( "privileged_functions" ) ) )
170170
#define PRIVILEGED_DATA __attribute__( ( section( "privileged_data" ) ) )
171171
#define FREERTOS_SYSTEM_CALL __attribute__( ( section( "freertos_system_calls" ) ) )
172172

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

175205
#else /* portUSING_MPU_WRAPPERS */

0 commit comments

Comments
 (0)