3 FreeRTOS-Kernel conforms to [MISRA C:2012](https://www.misra.org.uk/misra-c)
4 guidelines, with the deviations listed below. Compliance is checked with
5 Coverity static analysis. Since the FreeRTOS kernel is designed for
6 small-embedded devices, it needs to have a very small memory footprint and
7 has to be efficient. To achieve that and to increase the performance, it
8 deviates from some MISRA rules. The specific deviations, suppressed inline,
11 Additionally, [MISRA configuration](#misra-configuration) contains project
14 ### Suppressed with Coverity Comments
15 To find the violation references in the source files run grep on the source code
16 with ( Assuming rule 8.4 violation; with justification in point 1 ):
18 grep 'MISRA Ref 8.4.1' . -rI
23 MISRA C:2012 Rule 8.4: A compatible declaration shall be visible when an
24 object or function with external linkage is defined.
27 - pxCurrentTCB(s) is defined with external linkage but it is only referenced
28 from the assembly code in the port files. Therefore, adding a declaration in
29 header file is not useful as the assembly code will still need to declare it
33 - xQueueRegistry is defined with external linkage because it is accessed by the
34 kernel unit tests. It is not meant to be directly accessed by the application
35 and therefore, not declared in a header file.
39 MISRA C:2012 Rule 8.6: An identifier with external linkage shall have exactly
40 one external definition.
43 - This rule prohibits an identifier with external linkage to have multiple
44 definitions or no definition. FreeRTOS hook functions are implemented in
45 the application and therefore, have no definition in the Kernel code.
48 MISRA C:2012 Rule 11.1: Conversions shall not be performed between a pointer to
49 function and any other type.
52 - The pointer to function is casted into void to avoid unused parameter
53 compiler warning when Stream Buffer's Tx and Rx Completed callback feature is
58 MISRA C:2012 Rule 11.3: A cast shall not be performed between a pointer to
59 object type and a pointer to a different object type.
62 - This rule prohibits casting a pointer to object into a pointer to a
63 different object because it may result in an incorrectly aligned pointer,
64 leading to undefined behavior. Even if the casting produces a correctly
65 aligned pointer, the behavior may be still undefined if the pointer is
66 used to access an object. FreeRTOS deliberately creates external aliases
67 for all the kernel object types (StaticEventGroup_t, StaticQueue_t,
68 StaticStreamBuffer_t, StaticTimer_t and StaticTask_t) for data hiding
69 purposes. The internal object types and the corresponding external
70 aliases are guaranteed to have the same size and alignment which is
71 checked using configASSERT.
76 MISRA C:2012 Rule 11.5: A conversion should not be performed from pointer to
77 void into pointer to object.
78 This rule prohibits conversion of a pointer to void into a pointer to
79 object because it may result in an incorrectly aligned pointer leading
80 to undefined behavior.
83 - The memory blocks returned by pvPortMalloc() are guaranteed to meet the
84 architecture alignment requirements specified by portBYTE_ALIGNMENT.
85 The casting of the pointer to void returned by pvPortMalloc() is,
86 therefore, safe because it is guaranteed to be aligned.
89 - The conversion from a pointer to void into a pointer to EventGroup_t is
90 safe because it is a pointer to EventGroup_t, which is returned to the
91 application at the time of event group creation for data hiding
95 - The conversion from a pointer to void in list macros for list item owner
96 is safe because the type of the pointer stored and retrieved is the
100 - The conversion from a pointer to void into a pointer to EventGroup_t is
101 safe because it is a pointer to EventGroup_t, which is passed as a
102 parameter to the xTimerPendFunctionCallFromISR API when the callback is
106 - The conversion from a pointer to void into a pointer to uint8_t is safe
107 because data storage buffers are implemented as uint8_t arrays for the
108 ease of sizing, alignment and access.
111 ### MISRA configuration
113 Copy below content to `misra.conf` to run Coverity on FreeRTOS-Kernel.
116 // MISRA C-2012 Rules
120 title: "Coverity MISRA Configuration",
122 // Disable the following rules.
124 deviation: "Directive 4.8",
125 reason: "HeapRegion_t and HeapStats_t are used only in heap files but declared in portable.h which is included in multiple source files. As a result, these definitions appear in multiple source files where they are not used."
128 deviation: "Directive 4.9",
129 reason: "FreeRTOS-Kernel is optimised to work on small micro-controllers. To achieve that, function-like macros are used."
132 deviation: "Rule 1.2",
133 reason: "The __attribute__ tags are used via macros which are defined in port files."
136 deviation: "Rule 3.1",
137 reason: "We post HTTP links in code comments which contain // inside comments blocks."
140 deviation: "Rule 8.7",
141 reason: "API functions are not used by the library outside of the files they are defined; however, they must be externally visible in order to be used by an application."