1 /* 2 * FreeRTOS Kernel V10.6.2 3 * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. 4 * 5 * SPDX-License-Identifier: MIT 6 * 7 * Permission is hereby granted, free of charge, to any person obtaining a copy of 8 * this software and associated documentation files (the "Software"), to deal in 9 * the Software without restriction, including without limitation the rights to 10 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 11 * the Software, and to permit persons to whom the Software is furnished to do so, 12 * subject to the following conditions: 13 * 14 * The above copyright notice and this permission notice shall be included in all 15 * copies or substantial portions of the Software. 16 * 17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 19 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 20 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 21 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 * 24 * https://www.FreeRTOS.org 25 * https://github.com/FreeRTOS 26 * 27 */ 28 29 #ifndef MPU_WRAPPERS_H 30 #define MPU_WRAPPERS_H 31 32 /* This file redefines API functions to be called through a wrapper macro, but 33 * only for ports that are using the MPU. */ 34 #if ( portUSING_MPU_WRAPPERS == 1 ) 35 36 /* MPU_WRAPPERS_INCLUDED_FROM_API_FILE will be defined when this file is 37 * included from queue.c or task.c to prevent it from having an effect within 38 * those files. */ 39 #ifndef MPU_WRAPPERS_INCLUDED_FROM_API_FILE 40 41 /* 42 * Map standard (non MPU) API functions to equivalents that start 43 * "MPU_". This will cause the application code to call the MPU_ 44 * version, which wraps the non-MPU version with privilege promoting 45 * then demoting code, so the kernel code always runs will full 46 * privileges. 47 */ 48 49 /* Map standard task.h API functions to the MPU equivalents. */ 50 #define vTaskDelay MPU_vTaskDelay 51 #define xTaskDelayUntil MPU_xTaskDelayUntil 52 #define xTaskAbortDelay MPU_xTaskAbortDelay 53 #define uxTaskPriorityGet MPU_uxTaskPriorityGet 54 #define eTaskGetState MPU_eTaskGetState 55 #define vTaskGetInfo MPU_vTaskGetInfo 56 #define vTaskSuspend MPU_vTaskSuspend 57 #define vTaskResume MPU_vTaskResume 58 #define xTaskGetTickCount MPU_xTaskGetTickCount 59 #define uxTaskGetNumberOfTasks MPU_uxTaskGetNumberOfTasks 60 #define pcTaskGetName MPU_pcTaskGetName 61 #define uxTaskGetStackHighWaterMark MPU_uxTaskGetStackHighWaterMark 62 #define uxTaskGetStackHighWaterMark2 MPU_uxTaskGetStackHighWaterMark2 63 #define vTaskSetApplicationTaskTag MPU_vTaskSetApplicationTaskTag 64 #define xTaskGetApplicationTaskTag MPU_xTaskGetApplicationTaskTag 65 #define vTaskSetThreadLocalStoragePointer MPU_vTaskSetThreadLocalStoragePointer 66 #define pvTaskGetThreadLocalStoragePointer MPU_pvTaskGetThreadLocalStoragePointer 67 #define xTaskGetIdleTaskHandle MPU_xTaskGetIdleTaskHandle 68 #define uxTaskGetSystemState MPU_uxTaskGetSystemState 69 #define ulTaskGetIdleRunTimeCounter MPU_ulTaskGetIdleRunTimeCounter 70 #define ulTaskGetIdleRunTimePercent MPU_ulTaskGetIdleRunTimePercent 71 #define xTaskGenericNotify MPU_xTaskGenericNotify 72 #define xTaskGenericNotifyWait MPU_xTaskGenericNotifyWait 73 #define ulTaskGenericNotifyTake MPU_ulTaskGenericNotifyTake 74 #define xTaskGenericNotifyStateClear MPU_xTaskGenericNotifyStateClear 75 #define ulTaskGenericNotifyValueClear MPU_ulTaskGenericNotifyValueClear 76 #define vTaskSetTimeOutState MPU_vTaskSetTimeOutState 77 #define xTaskCheckForTimeOut MPU_xTaskCheckForTimeOut 78 #define xTaskGetCurrentTaskHandle MPU_xTaskGetCurrentTaskHandle 79 #define xTaskGetSchedulerState MPU_xTaskGetSchedulerState 80 81 #if ( configUSE_MPU_WRAPPERS_V1 == 0 ) 82 #define ulTaskGetRunTimeCounter MPU_ulTaskGetRunTimeCounter 83 #define ulTaskGetRunTimePercent MPU_ulTaskGetRunTimePercent 84 #endif /* #if ( configUSE_MPU_WRAPPERS_V1 == 0 ) */ 85 86 /* Privileged only wrappers for Task APIs. These are needed so that 87 * the application can use opaque handles maintained in mpu_wrappers.c 88 * with all the APIs. */ 89 #define xTaskCreate MPU_xTaskCreate 90 #define xTaskCreateStatic MPU_xTaskCreateStatic 91 #define vTaskDelete MPU_vTaskDelete 92 #define vTaskPrioritySet MPU_vTaskPrioritySet 93 #define xTaskGetHandle MPU_xTaskGetHandle 94 #define xTaskCallApplicationTaskHook MPU_xTaskCallApplicationTaskHook 95 96 #if ( configUSE_MPU_WRAPPERS_V1 == 0 ) 97 #define xTaskCreateRestricted MPU_xTaskCreateRestricted 98 #define xTaskCreateRestrictedStatic MPU_xTaskCreateRestrictedStatic 99 #define vTaskAllocateMPURegions MPU_vTaskAllocateMPURegions 100 #define xTaskGetStaticBuffers MPU_xTaskGetStaticBuffers 101 #define uxTaskPriorityGetFromISR MPU_uxTaskPriorityGetFromISR 102 #define xTaskResumeFromISR MPU_xTaskResumeFromISR 103 #define xTaskGetApplicationTaskTagFromISR MPU_xTaskGetApplicationTaskTagFromISR 104 #define xTaskGenericNotifyFromISR MPU_xTaskGenericNotifyFromISR 105 #define vTaskGenericNotifyGiveFromISR MPU_vTaskGenericNotifyGiveFromISR 106 #endif /* #if ( configUSE_MPU_WRAPPERS_V1 == 0 ) */ 107 108 /* Map standard queue.h API functions to the MPU equivalents. */ 109 #define xQueueGenericSend MPU_xQueueGenericSend 110 #define xQueueReceive MPU_xQueueReceive 111 #define xQueuePeek MPU_xQueuePeek 112 #define xQueueSemaphoreTake MPU_xQueueSemaphoreTake 113 #define uxQueueMessagesWaiting MPU_uxQueueMessagesWaiting 114 #define uxQueueSpacesAvailable MPU_uxQueueSpacesAvailable 115 #define xQueueGetMutexHolder MPU_xQueueGetMutexHolder 116 #define xQueueTakeMutexRecursive MPU_xQueueTakeMutexRecursive 117 #define xQueueGiveMutexRecursive MPU_xQueueGiveMutexRecursive 118 #define xQueueAddToSet MPU_xQueueAddToSet 119 #define xQueueSelectFromSet MPU_xQueueSelectFromSet 120 121 #if ( configQUEUE_REGISTRY_SIZE > 0 ) 122 #define vQueueAddToRegistry MPU_vQueueAddToRegistry 123 #define vQueueUnregisterQueue MPU_vQueueUnregisterQueue 124 #define pcQueueGetName MPU_pcQueueGetName 125 #endif /* #if ( configQUEUE_REGISTRY_SIZE > 0 ) */ 126 127 /* Privileged only wrappers for Queue APIs. These are needed so that 128 * the application can use opaque handles maintained in mpu_wrappers.c 129 * with all the APIs. */ 130 #define vQueueDelete MPU_vQueueDelete 131 #define xQueueCreateMutex MPU_xQueueCreateMutex 132 #define xQueueCreateMutexStatic MPU_xQueueCreateMutexStatic 133 #define xQueueCreateCountingSemaphore MPU_xQueueCreateCountingSemaphore 134 #define xQueueCreateCountingSemaphoreStatic MPU_xQueueCreateCountingSemaphoreStatic 135 #define xQueueGenericCreate MPU_xQueueGenericCreate 136 #define xQueueGenericCreateStatic MPU_xQueueGenericCreateStatic 137 #define xQueueGenericReset MPU_xQueueGenericReset 138 #define xQueueCreateSet MPU_xQueueCreateSet 139 #define xQueueRemoveFromSet MPU_xQueueRemoveFromSet 140 141 #if ( configUSE_MPU_WRAPPERS_V1 == 0 ) 142 #define xQueueGenericGetStaticBuffers MPU_xQueueGenericGetStaticBuffers 143 #define xQueueGenericSendFromISR MPU_xQueueGenericSendFromISR 144 #define xQueueGiveFromISR MPU_xQueueGiveFromISR 145 #define xQueuePeekFromISR MPU_xQueuePeekFromISR 146 #define xQueueReceiveFromISR MPU_xQueueReceiveFromISR 147 #define xQueueIsQueueEmptyFromISR MPU_xQueueIsQueueEmptyFromISR 148 #define xQueueIsQueueFullFromISR MPU_xQueueIsQueueFullFromISR 149 #define uxQueueMessagesWaitingFromISR MPU_uxQueueMessagesWaitingFromISR 150 #define xQueueGetMutexHolderFromISR MPU_xQueueGetMutexHolderFromISR 151 #define xQueueSelectFromSetFromISR MPU_xQueueSelectFromSetFromISR 152 #endif /* if ( configUSE_MPU_WRAPPERS_V1 == 0 ) */ 153 154 /* Map standard timer.h API functions to the MPU equivalents. */ 155 #define pvTimerGetTimerID MPU_pvTimerGetTimerID 156 #define vTimerSetTimerID MPU_vTimerSetTimerID 157 #define xTimerIsTimerActive MPU_xTimerIsTimerActive 158 #define xTimerGetTimerDaemonTaskHandle MPU_xTimerGetTimerDaemonTaskHandle 159 #define xTimerGenericCommand MPU_xTimerGenericCommand 160 #define pcTimerGetName MPU_pcTimerGetName 161 #define vTimerSetReloadMode MPU_vTimerSetReloadMode 162 #define uxTimerGetReloadMode MPU_uxTimerGetReloadMode 163 #define xTimerGetPeriod MPU_xTimerGetPeriod 164 #define xTimerGetExpiryTime MPU_xTimerGetExpiryTime 165 166 /* Privileged only wrappers for Timer APIs. These are needed so that 167 * the application can use opaque handles maintained in mpu_wrappers.c 168 * with all the APIs. */ 169 #if ( configUSE_MPU_WRAPPERS_V1 == 0 ) 170 #define xTimerGetReloadMode MPU_xTimerGetReloadMode 171 #define xTimerCreate MPU_xTimerCreate 172 #define xTimerCreateStatic MPU_xTimerCreateStatic 173 #define xTimerGetStaticBuffer MPU_xTimerGetStaticBuffer 174 #endif /* #if ( configUSE_MPU_WRAPPERS_V1 == 0 ) */ 175 176 /* Map standard event_group.h API functions to the MPU equivalents. */ 177 #define xEventGroupWaitBits MPU_xEventGroupWaitBits 178 #define xEventGroupClearBits MPU_xEventGroupClearBits 179 #define xEventGroupSetBits MPU_xEventGroupSetBits 180 #define xEventGroupSync MPU_xEventGroupSync 181 182 #if ( ( configUSE_TRACE_FACILITY == 1 ) && ( configUSE_MPU_WRAPPERS_V1 == 0 ) ) 183 #define uxEventGroupGetNumber MPU_uxEventGroupGetNumber 184 #define vEventGroupSetNumber MPU_vEventGroupSetNumber 185 #endif /* #if ( ( configUSE_TRACE_FACILITY == 1 ) && ( configUSE_MPU_WRAPPERS_V1 == 0 ) ) */ 186 187 /* Privileged only wrappers for Event Group APIs. These are needed so that 188 * the application can use opaque handles maintained in mpu_wrappers.c 189 * with all the APIs. */ 190 #define xEventGroupCreate MPU_xEventGroupCreate 191 #define xEventGroupCreateStatic MPU_xEventGroupCreateStatic 192 #define vEventGroupDelete MPU_vEventGroupDelete 193 194 #if ( configUSE_MPU_WRAPPERS_V1 == 0 ) 195 #define xEventGroupGetStaticBuffer MPU_xEventGroupGetStaticBuffer 196 #define xEventGroupClearBitsFromISR MPU_xEventGroupClearBitsFromISR 197 #define xEventGroupSetBitsFromISR MPU_xEventGroupSetBitsFromISR 198 #define xEventGroupGetBitsFromISR MPU_xEventGroupGetBitsFromISR 199 #endif /* #if ( configUSE_MPU_WRAPPERS_V1 == 0 ) */ 200 201 /* Map standard message/stream_buffer.h API functions to the MPU 202 * equivalents. */ 203 #define xStreamBufferSend MPU_xStreamBufferSend 204 #define xStreamBufferReceive MPU_xStreamBufferReceive 205 #define xStreamBufferIsFull MPU_xStreamBufferIsFull 206 #define xStreamBufferIsEmpty MPU_xStreamBufferIsEmpty 207 #define xStreamBufferSpacesAvailable MPU_xStreamBufferSpacesAvailable 208 #define xStreamBufferBytesAvailable MPU_xStreamBufferBytesAvailable 209 #define xStreamBufferSetTriggerLevel MPU_xStreamBufferSetTriggerLevel 210 #define xStreamBufferNextMessageLengthBytes MPU_xStreamBufferNextMessageLengthBytes 211 212 /* Privileged only wrappers for Stream Buffer APIs. These are needed so that 213 * the application can use opaque handles maintained in mpu_wrappers.c 214 * with all the APIs. */ 215 216 #define xStreamBufferGenericCreate MPU_xStreamBufferGenericCreate 217 #define xStreamBufferGenericCreateStatic MPU_xStreamBufferGenericCreateStatic 218 #define vStreamBufferDelete MPU_vStreamBufferDelete 219 #define xStreamBufferReset MPU_xStreamBufferReset 220 221 #if ( configUSE_MPU_WRAPPERS_V1 == 0 ) 222 #define xStreamBufferGetStaticBuffers MPU_xStreamBufferGetStaticBuffers 223 #define xStreamBufferSendFromISR MPU_xStreamBufferSendFromISR 224 #define xStreamBufferReceiveFromISR MPU_xStreamBufferReceiveFromISR 225 #define xStreamBufferSendCompletedFromISR MPU_xStreamBufferSendCompletedFromISR 226 #define xStreamBufferReceiveCompletedFromISR MPU_xStreamBufferReceiveCompletedFromISR 227 #endif /* #if ( configUSE_MPU_WRAPPERS_V1 == 0 ) */ 228 229 /* Remove the privileged function macro, but keep the PRIVILEGED_DATA 230 * macro so applications can place data in privileged access sections 231 * (useful when using statically allocated objects). */ 232 #define PRIVILEGED_FUNCTION 233 #define PRIVILEGED_DATA __attribute__( ( section( "privileged_data" ) ) ) 234 #define FREERTOS_SYSTEM_CALL 235 236 237 #if ( ( configUSE_MPU_WRAPPERS_V1 == 0 ) && ( configENABLE_ACCESS_CONTROL_LIST == 1 ) ) 238 239 #define vGrantAccessToTask( xTask, xTaskToGrantAccess ) vGrantAccessToKernelObject( ( xTask ), ( int32_t ) ( xTaskToGrantAccess ) ) 240 #define vRevokeAccessToTask( xTask, xTaskToRevokeAccess ) vRevokeAccessToKernelObject( ( xTask ), ( int32_t ) ( xTaskToRevokeAccess ) ) 241 242 #define vGrantAccessToSemaphore( xTask, xSemaphoreToGrantAccess ) vGrantAccessToKernelObject( ( xTask ), ( int32_t ) ( xSemaphoreToGrantAccess ) ) 243 #define vRevokeAccessToSemaphore( xTask, xSemaphoreToRevokeAccess ) vRevokeAccessToKernelObject( ( xTask ), ( int32_t ) ( xSemaphoreToRevokeAccess ) ) 244 245 #define vGrantAccessToQueue( xTask, xQueueToGrantAccess ) vGrantAccessToKernelObject( ( xTask ), ( int32_t ) ( xQueueToGrantAccess ) ) 246 #define vRevokeAccessToQueue( xTask, xQueueToRevokeAccess ) vRevokeAccessToKernelObject( ( xTask ), ( int32_t ) ( xQueueToRevokeAccess ) ) 247 248 #define vGrantAccessToQueueSet( xTask, xQueueSetToGrantAccess ) vGrantAccessToKernelObject( ( xTask ), ( int32_t ) ( xQueueSetToGrantAccess ) ) 249 #define vRevokeAccessToQueueSet( xTask, xQueueSetToRevokeAccess ) vRevokeAccessToKernelObject( ( xTask ), ( int32_t ) ( xQueueSetToRevokeAccess ) ) 250 251 #define vGrantAccessToEventGroup( xTask, xEventGroupToGrantAccess ) vGrantAccessToKernelObject( ( xTask ), ( int32_t ) ( xEventGroupToGrantAccess ) ) 252 #define vRevokeAccessToEventGroup( xTask, xEventGroupToRevokeAccess ) vRevokeAccessToKernelObject( ( xTask ), ( int32_t ) ( xEventGroupToRevokeAccess ) ) 253 254 #define vGrantAccessToStreamBuffer( xTask, xStreamBufferToGrantAccess ) vGrantAccessToKernelObject( ( xTask ), ( int32_t ) ( xStreamBufferToGrantAccess ) ) 255 #define vRevokeAccessToStreamBuffer( xTask, xStreamBufferToRevokeAccess ) vRevokeAccessToKernelObject( ( xTask ), ( int32_t ) ( xStreamBufferToRevokeAccess ) ) 256 257 #define vGrantAccessToMessageBuffer( xTask, xMessageBufferToGrantAccess ) vGrantAccessToKernelObject( ( xTask ), ( int32_t ) ( xMessageBufferToGrantAccess ) ) 258 #define vRevokeAccessToMessageBuffer( xTask, xMessageBufferToRevokeAccess ) vRevokeAccessToKernelObject( ( xTask ), ( int32_t ) ( xMessageBufferToRevokeAccess ) ) 259 260 #define vGrantAccessToTimer( xTask, xTimerToGrantAccess ) vGrantAccessToKernelObject( ( xTask ), ( int32_t ) ( xTimerToGrantAccess ) ) 261 #define vRevokeAccessToTimer( xTask, xTimerToRevokeAccess ) vRevokeAccessToKernelObject( ( xTask ), ( int32_t ) ( xTimerToRevokeAccess ) ) 262 263 #endif /* #if ( ( configUSE_MPU_WRAPPERS_V1 == 0 ) && ( configENABLE_ACCESS_CONTROL_LIST == 1 ) ) */ 264 265 #else /* MPU_WRAPPERS_INCLUDED_FROM_API_FILE */ 266 267 /* Ensure API functions go in the privileged execution section. */ 268 #define PRIVILEGED_FUNCTION __attribute__( ( section( "privileged_functions" ) ) ) 269 #define PRIVILEGED_DATA __attribute__( ( section( "privileged_data" ) ) ) 270 #define FREERTOS_SYSTEM_CALL __attribute__( ( section( "freertos_system_calls" ) ) ) 271 272 #endif /* MPU_WRAPPERS_INCLUDED_FROM_API_FILE */ 273 274 #else /* portUSING_MPU_WRAPPERS */ 275 276 #define PRIVILEGED_FUNCTION 277 #define PRIVILEGED_DATA 278 #define FREERTOS_SYSTEM_CALL 279 280 #endif /* portUSING_MPU_WRAPPERS */ 281 282 283 #endif /* MPU_WRAPPERS_H */ 284