1 /* 2 * FreeRTOS Kernel V11.1.0 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 uxTaskGetStackHighWaterMark MPU_uxTaskGetStackHighWaterMark 61 #define uxTaskGetStackHighWaterMark2 MPU_uxTaskGetStackHighWaterMark2 62 #define vTaskSetApplicationTaskTag MPU_vTaskSetApplicationTaskTag 63 #define xTaskGetApplicationTaskTag MPU_xTaskGetApplicationTaskTag 64 #define vTaskSetThreadLocalStoragePointer MPU_vTaskSetThreadLocalStoragePointer 65 #define pvTaskGetThreadLocalStoragePointer MPU_pvTaskGetThreadLocalStoragePointer 66 #define xTaskGetIdleTaskHandle MPU_xTaskGetIdleTaskHandle 67 #define uxTaskGetSystemState MPU_uxTaskGetSystemState 68 #define ulTaskGetIdleRunTimeCounter MPU_ulTaskGetIdleRunTimeCounter 69 #define ulTaskGetIdleRunTimePercent MPU_ulTaskGetIdleRunTimePercent 70 #define xTaskGenericNotify MPU_xTaskGenericNotify 71 #define xTaskGenericNotifyWait MPU_xTaskGenericNotifyWait 72 #define ulTaskGenericNotifyTake MPU_ulTaskGenericNotifyTake 73 #define xTaskGenericNotifyStateClear MPU_xTaskGenericNotifyStateClear 74 #define ulTaskGenericNotifyValueClear MPU_ulTaskGenericNotifyValueClear 75 #define vTaskSetTimeOutState MPU_vTaskSetTimeOutState 76 #define xTaskCheckForTimeOut MPU_xTaskCheckForTimeOut 77 #define xTaskGetCurrentTaskHandle MPU_xTaskGetCurrentTaskHandle 78 #define xTaskGetSchedulerState MPU_xTaskGetSchedulerState 79 80 #if ( configUSE_MPU_WRAPPERS_V1 == 0 ) 81 #define ulTaskGetRunTimeCounter MPU_ulTaskGetRunTimeCounter 82 #define ulTaskGetRunTimePercent MPU_ulTaskGetRunTimePercent 83 #endif /* #if ( configUSE_MPU_WRAPPERS_V1 == 0 ) */ 84 85 /* Privileged only wrappers for Task APIs. These are needed so that 86 * the application can use opaque handles maintained in mpu_wrappers.c 87 * with all the APIs. */ 88 #define xTaskCreate MPU_xTaskCreate 89 #define xTaskCreateStatic MPU_xTaskCreateStatic 90 #define vTaskDelete MPU_vTaskDelete 91 #define vTaskPrioritySet MPU_vTaskPrioritySet 92 #define xTaskGetHandle MPU_xTaskGetHandle 93 #define xTaskCallApplicationTaskHook MPU_xTaskCallApplicationTaskHook 94 95 #if ( configUSE_MPU_WRAPPERS_V1 == 0 ) 96 #define pcTaskGetName MPU_pcTaskGetName 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 uxTaskBasePriorityGet MPU_uxTaskBasePriorityGet 103 #define uxTaskBasePriorityGetFromISR MPU_uxTaskBasePriorityGetFromISR 104 #define xTaskResumeFromISR MPU_xTaskResumeFromISR 105 #define xTaskGetApplicationTaskTagFromISR MPU_xTaskGetApplicationTaskTagFromISR 106 #define xTaskGenericNotifyFromISR MPU_xTaskGenericNotifyFromISR 107 #define vTaskGenericNotifyGiveFromISR MPU_vTaskGenericNotifyGiveFromISR 108 #endif /* #if ( configUSE_MPU_WRAPPERS_V1 == 0 ) */ 109 110 /* Map standard queue.h API functions to the MPU equivalents. */ 111 #define xQueueGenericSend MPU_xQueueGenericSend 112 #define xQueueReceive MPU_xQueueReceive 113 #define xQueuePeek MPU_xQueuePeek 114 #define xQueueSemaphoreTake MPU_xQueueSemaphoreTake 115 #define uxQueueMessagesWaiting MPU_uxQueueMessagesWaiting 116 #define uxQueueSpacesAvailable MPU_uxQueueSpacesAvailable 117 #define xQueueGetMutexHolder MPU_xQueueGetMutexHolder 118 #define xQueueTakeMutexRecursive MPU_xQueueTakeMutexRecursive 119 #define xQueueGiveMutexRecursive MPU_xQueueGiveMutexRecursive 120 #define xQueueAddToSet MPU_xQueueAddToSet 121 #define xQueueSelectFromSet MPU_xQueueSelectFromSet 122 123 #if ( configQUEUE_REGISTRY_SIZE > 0 ) 124 #define vQueueAddToRegistry MPU_vQueueAddToRegistry 125 #define vQueueUnregisterQueue MPU_vQueueUnregisterQueue 126 #define pcQueueGetName MPU_pcQueueGetName 127 #endif /* #if ( configQUEUE_REGISTRY_SIZE > 0 ) */ 128 129 /* Privileged only wrappers for Queue APIs. These are needed so that 130 * the application can use opaque handles maintained in mpu_wrappers.c 131 * with all the APIs. */ 132 #define vQueueDelete MPU_vQueueDelete 133 #define xQueueCreateMutex MPU_xQueueCreateMutex 134 #define xQueueCreateMutexStatic MPU_xQueueCreateMutexStatic 135 #define xQueueCreateCountingSemaphore MPU_xQueueCreateCountingSemaphore 136 #define xQueueCreateCountingSemaphoreStatic MPU_xQueueCreateCountingSemaphoreStatic 137 #define xQueueGenericCreate MPU_xQueueGenericCreate 138 #define xQueueGenericCreateStatic MPU_xQueueGenericCreateStatic 139 #define xQueueGenericReset MPU_xQueueGenericReset 140 #define xQueueCreateSet MPU_xQueueCreateSet 141 #define xQueueRemoveFromSet MPU_xQueueRemoveFromSet 142 143 #if ( configUSE_MPU_WRAPPERS_V1 == 0 ) 144 #define xQueueGenericGetStaticBuffers MPU_xQueueGenericGetStaticBuffers 145 #define xQueueGenericSendFromISR MPU_xQueueGenericSendFromISR 146 #define xQueueGiveFromISR MPU_xQueueGiveFromISR 147 #define xQueuePeekFromISR MPU_xQueuePeekFromISR 148 #define xQueueReceiveFromISR MPU_xQueueReceiveFromISR 149 #define xQueueIsQueueEmptyFromISR MPU_xQueueIsQueueEmptyFromISR 150 #define xQueueIsQueueFullFromISR MPU_xQueueIsQueueFullFromISR 151 #define uxQueueMessagesWaitingFromISR MPU_uxQueueMessagesWaitingFromISR 152 #define xQueueGetMutexHolderFromISR MPU_xQueueGetMutexHolderFromISR 153 #define xQueueSelectFromSetFromISR MPU_xQueueSelectFromSetFromISR 154 #endif /* if ( configUSE_MPU_WRAPPERS_V1 == 0 ) */ 155 156 /* Map standard timer.h API functions to the MPU equivalents. */ 157 #define pvTimerGetTimerID MPU_pvTimerGetTimerID 158 #define vTimerSetTimerID MPU_vTimerSetTimerID 159 #define xTimerIsTimerActive MPU_xTimerIsTimerActive 160 #define xTimerGetTimerDaemonTaskHandle MPU_xTimerGetTimerDaemonTaskHandle 161 #define xTimerGenericCommandFromTask MPU_xTimerGenericCommandFromTask 162 #define pcTimerGetName MPU_pcTimerGetName 163 #define vTimerSetReloadMode MPU_vTimerSetReloadMode 164 #define uxTimerGetReloadMode MPU_uxTimerGetReloadMode 165 #define xTimerGetPeriod MPU_xTimerGetPeriod 166 #define xTimerGetExpiryTime MPU_xTimerGetExpiryTime 167 168 /* Privileged only wrappers for Timer APIs. These are needed so that 169 * the application can use opaque handles maintained in mpu_wrappers.c 170 * with all the APIs. */ 171 #if ( configUSE_MPU_WRAPPERS_V1 == 0 ) 172 #define xTimerGetReloadMode MPU_xTimerGetReloadMode 173 #define xTimerCreate MPU_xTimerCreate 174 #define xTimerCreateStatic MPU_xTimerCreateStatic 175 #define xTimerGetStaticBuffer MPU_xTimerGetStaticBuffer 176 #define xTimerGenericCommandFromISR MPU_xTimerGenericCommandFromISR 177 #endif /* #if ( configUSE_MPU_WRAPPERS_V1 == 0 ) */ 178 179 /* Map standard event_group.h API functions to the MPU equivalents. */ 180 #define xEventGroupWaitBits MPU_xEventGroupWaitBits 181 #define xEventGroupClearBits MPU_xEventGroupClearBits 182 #define xEventGroupSetBits MPU_xEventGroupSetBits 183 #define xEventGroupSync MPU_xEventGroupSync 184 185 #if ( ( configUSE_TRACE_FACILITY == 1 ) && ( configUSE_MPU_WRAPPERS_V1 == 0 ) ) 186 #define uxEventGroupGetNumber MPU_uxEventGroupGetNumber 187 #define vEventGroupSetNumber MPU_vEventGroupSetNumber 188 #endif /* #if ( ( configUSE_TRACE_FACILITY == 1 ) && ( configUSE_MPU_WRAPPERS_V1 == 0 ) ) */ 189 190 /* Privileged only wrappers for Event Group APIs. These are needed so that 191 * the application can use opaque handles maintained in mpu_wrappers.c 192 * with all the APIs. */ 193 #define xEventGroupCreate MPU_xEventGroupCreate 194 #define xEventGroupCreateStatic MPU_xEventGroupCreateStatic 195 #define vEventGroupDelete MPU_vEventGroupDelete 196 197 #if ( configUSE_MPU_WRAPPERS_V1 == 0 ) 198 #define xEventGroupGetStaticBuffer MPU_xEventGroupGetStaticBuffer 199 #define xEventGroupClearBitsFromISR MPU_xEventGroupClearBitsFromISR 200 #define xEventGroupSetBitsFromISR MPU_xEventGroupSetBitsFromISR 201 #define xEventGroupGetBitsFromISR MPU_xEventGroupGetBitsFromISR 202 #endif /* #if ( configUSE_MPU_WRAPPERS_V1 == 0 ) */ 203 204 /* Map standard message/stream_buffer.h API functions to the MPU 205 * equivalents. */ 206 #define xStreamBufferSend MPU_xStreamBufferSend 207 #define xStreamBufferReceive MPU_xStreamBufferReceive 208 #define xStreamBufferIsFull MPU_xStreamBufferIsFull 209 #define xStreamBufferIsEmpty MPU_xStreamBufferIsEmpty 210 #define xStreamBufferSpacesAvailable MPU_xStreamBufferSpacesAvailable 211 #define xStreamBufferBytesAvailable MPU_xStreamBufferBytesAvailable 212 #define xStreamBufferSetTriggerLevel MPU_xStreamBufferSetTriggerLevel 213 #define xStreamBufferNextMessageLengthBytes MPU_xStreamBufferNextMessageLengthBytes 214 215 /* Privileged only wrappers for Stream Buffer APIs. These are needed so that 216 * the application can use opaque handles maintained in mpu_wrappers.c 217 * with all the APIs. */ 218 219 #define xStreamBufferGenericCreate MPU_xStreamBufferGenericCreate 220 #define xStreamBufferGenericCreateStatic MPU_xStreamBufferGenericCreateStatic 221 #define vStreamBufferDelete MPU_vStreamBufferDelete 222 #define xStreamBufferReset MPU_xStreamBufferReset 223 224 #if ( configUSE_MPU_WRAPPERS_V1 == 0 ) 225 #define xStreamBufferGetStaticBuffers MPU_xStreamBufferGetStaticBuffers 226 #define xStreamBufferSendFromISR MPU_xStreamBufferSendFromISR 227 #define xStreamBufferReceiveFromISR MPU_xStreamBufferReceiveFromISR 228 #define xStreamBufferSendCompletedFromISR MPU_xStreamBufferSendCompletedFromISR 229 #define xStreamBufferReceiveCompletedFromISR MPU_xStreamBufferReceiveCompletedFromISR 230 #define xStreamBufferResetFromISR MPU_xStreamBufferResetFromISR 231 #endif /* #if ( configUSE_MPU_WRAPPERS_V1 == 0 ) */ 232 233 #if ( ( configUSE_MPU_WRAPPERS_V1 == 0 ) && ( configENABLE_ACCESS_CONTROL_LIST == 1 ) ) 234 235 #define vGrantAccessToTask( xTask, xTaskToGrantAccess ) vGrantAccessToKernelObject( ( xTask ), ( int32_t ) ( xTaskToGrantAccess ) ) 236 #define vRevokeAccessToTask( xTask, xTaskToRevokeAccess ) vRevokeAccessToKernelObject( ( xTask ), ( int32_t ) ( xTaskToRevokeAccess ) ) 237 238 #define vGrantAccessToSemaphore( xTask, xSemaphoreToGrantAccess ) vGrantAccessToKernelObject( ( xTask ), ( int32_t ) ( xSemaphoreToGrantAccess ) ) 239 #define vRevokeAccessToSemaphore( xTask, xSemaphoreToRevokeAccess ) vRevokeAccessToKernelObject( ( xTask ), ( int32_t ) ( xSemaphoreToRevokeAccess ) ) 240 241 #define vGrantAccessToQueue( xTask, xQueueToGrantAccess ) vGrantAccessToKernelObject( ( xTask ), ( int32_t ) ( xQueueToGrantAccess ) ) 242 #define vRevokeAccessToQueue( xTask, xQueueToRevokeAccess ) vRevokeAccessToKernelObject( ( xTask ), ( int32_t ) ( xQueueToRevokeAccess ) ) 243 244 #define vGrantAccessToQueueSet( xTask, xQueueSetToGrantAccess ) vGrantAccessToKernelObject( ( xTask ), ( int32_t ) ( xQueueSetToGrantAccess ) ) 245 #define vRevokeAccessToQueueSet( xTask, xQueueSetToRevokeAccess ) vRevokeAccessToKernelObject( ( xTask ), ( int32_t ) ( xQueueSetToRevokeAccess ) ) 246 247 #define vGrantAccessToEventGroup( xTask, xEventGroupToGrantAccess ) vGrantAccessToKernelObject( ( xTask ), ( int32_t ) ( xEventGroupToGrantAccess ) ) 248 #define vRevokeAccessToEventGroup( xTask, xEventGroupToRevokeAccess ) vRevokeAccessToKernelObject( ( xTask ), ( int32_t ) ( xEventGroupToRevokeAccess ) ) 249 250 #define vGrantAccessToStreamBuffer( xTask, xStreamBufferToGrantAccess ) vGrantAccessToKernelObject( ( xTask ), ( int32_t ) ( xStreamBufferToGrantAccess ) ) 251 #define vRevokeAccessToStreamBuffer( xTask, xStreamBufferToRevokeAccess ) vRevokeAccessToKernelObject( ( xTask ), ( int32_t ) ( xStreamBufferToRevokeAccess ) ) 252 253 #define vGrantAccessToMessageBuffer( xTask, xMessageBufferToGrantAccess ) vGrantAccessToKernelObject( ( xTask ), ( int32_t ) ( xMessageBufferToGrantAccess ) ) 254 #define vRevokeAccessToMessageBuffer( xTask, xMessageBufferToRevokeAccess ) vRevokeAccessToKernelObject( ( xTask ), ( int32_t ) ( xMessageBufferToRevokeAccess ) ) 255 256 #define vGrantAccessToTimer( xTask, xTimerToGrantAccess ) vGrantAccessToKernelObject( ( xTask ), ( int32_t ) ( xTimerToGrantAccess ) ) 257 #define vRevokeAccessToTimer( xTask, xTimerToRevokeAccess ) vRevokeAccessToKernelObject( ( xTask ), ( int32_t ) ( xTimerToRevokeAccess ) ) 258 259 #endif /* #if ( ( configUSE_MPU_WRAPPERS_V1 == 0 ) && ( configENABLE_ACCESS_CONTROL_LIST == 1 ) ) */ 260 261 #endif /* MPU_WRAPPERS_INCLUDED_FROM_API_FILE */ 262 263 #define PRIVILEGED_FUNCTION __attribute__( ( section( "privileged_functions" ) ) ) 264 #define PRIVILEGED_DATA __attribute__( ( section( "privileged_data" ) ) ) 265 #define FREERTOS_SYSTEM_CALL __attribute__( ( section( "freertos_system_calls" ) ) ) 266 267 #else /* portUSING_MPU_WRAPPERS */ 268 269 #define PRIVILEGED_FUNCTION 270 #define PRIVILEGED_DATA 271 #define FREERTOS_SYSTEM_CALL 272 273 #endif /* portUSING_MPU_WRAPPERS */ 274 275 276 #endif /* MPU_WRAPPERS_H */ 277