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 11.3: A cast shall not be performed between a pointer to
40 object type and a pointer to a different object type.
43 - This rule prohibits casting a pointer to object into a pointer to a
44 different object because it may result in an incorrectly aligned pointer,
45 leading to undefined behavior. Even if the casting produces a correctly
46 aligned pointer, the behavior may be still undefined if the pointer is
47 used to access an object. FreeRTOS deliberately creates external aliases
48 for all the kernel object types (StaticEventGroup_t, StaticQueue_t,
49 StaticStreamBuffer_t, StaticTimer_t and StaticTask_t) for data hiding
50 purposes. The internal object types and the corresponding external
51 aliases are guaranteed to have the same size and alignment which is
52 checked using configASSERT.
57 MISRA C:2012 Rule 11.5: A conversion should not be performed from pointer to
58 void into pointer to object.
59 This rule prohibits conversion of a pointer to void into a pointer to
60 object because it may result in an incorrectly aligned pointer leading
61 to undefined behavior.
64 - The memory blocks returned by pvPortMalloc() are guaranteed to meet the
65 architecture alignment requirements specified by portBYTE_ALIGNMENT.
66 The casting of the pointer to void returned by pvPortMalloc() is,
67 therefore, safe because it is guaranteed to be aligned.
70 - The conversion from a pointer to void into a pointer to EventGroup_t is
71 safe because it is a pointer to EventGroup_t, which is returned to the
72 application at the time of event group creation for data hiding
76 - The conversion from a pointer to void in list macros for list item owner
77 is safe because the type of the pointer stored and retrieved is the
81 - The conversion from a pointer to void into a pointer to EventGroup_t is
82 safe because it is a pointer to EventGroup_t, which is passed as a
83 parameter to the xTimerPendFunctionCallFromISR API when the callback is
87 - The conversion from a pointer to void into a pointer to uint8_t is safe
88 because data storage buffers are implemented as uint8_t arrays for the
89 ease of sizing, alignment and access.
92 ### MISRA configuration
94 Copy below content to `misra.conf` to run Coverity on FreeRTOS-Kernel.
101 title: "Coverity MISRA Configuration",
103 // Disable the following rules.
105 deviation: "Directive 4.8",
106 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."
109 deviation: "Directive 4.9",
110 reason: "FreeRTOS-Kernel is optimised to work on small micro-controllers. To achieve that, function-like macros are used."
113 deviation: "Rule 1.2",
114 reason: "The __attribute__ tags are used via macros which are defined in port files."
117 deviation: "Rule 3.1",
118 reason: "We post HTTP links in code comments which contain // inside comments blocks."
121 deviation: "Rule 8.7",
122 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."