Debian Codegraph @

docs/misra/C-runtime-failures.rst

raw
1 .. SPDX-License-Identifier: CC-BY-4.0
2
3 ===================================================================
4 Measures taken towards the minimization of Run-time failures in Xen
5 ===================================================================
6
7 This document specifies which procedures and techinques are used troughout the
8 Xen codebase to prevent or minimize the impact of certain classes of run-time
9 errors that can occurr in the execution of a C program, due to the very minimal
10 built-in checks that are present in the language.
11
12 The presence of such documentation is requested by MISRA C:2012 Directive 4.1,
13 whose headline states: "Run-time failures shall be minimized".
14
15 The ECLAIR checker for MISRA C:2012 Directive 4.1 requires the documentation
16 to be supplied using the following format:
17
18 ``Documentation for MISRA C:2012 Dir 4.1: <category> <description>``
19
20 The matched categories are the ones listed below (e.g., ``overflow`` and
21 ``unexpected wrapping``). The content of the description is not checked and can
22 span multiple lines.
23
24 Documentation for MISRA C:2012 Dir 4.1: overflow
25 ________________________________________________
26
27 Pervasive use of assertions and extensive test suite.
28
29
30 Documentation for MISRA C:2012 Dir 4.1: unexpected wrapping
31 ___________________________________________________________
32
33 The only wrapping that is present in the code concerns
34 unsigned integers and they are all expected.
35
36
37 Documentation for MISRA C:2012 Dir 4.1: invalid shift
38 _____________________________________________________
39
40 Pervasive use of assertions and extensive test suite.
41
42
43 Documentation for MISRA C:2012 Dir 4.1: division/remainder by zero
44 __________________________________________________________________
45
46 The division or remainder operations in the project code ensure that
47 their second argument is never zero.
48
49
50 Documentation for MISRA C:2012 Dir 4.1: unsequenced side effects
51 ________________________________________________________________
52
53 Code executed in interrupt handlers uses spinlocks or disables interrupts
54 at the right locations to avoid unsequenced side effects.
55
56
57 Documentation for MISRA C:2012 Dir 4.1: read from uninitialized automatic object
58 ________________________________________________________________________________
59
60 The amount of dynamically allocated objects is limited at runtime in
61 static configurations. We make sure to initialize dynamically allocated
62 objects before reading them, and we utilize static analysis tools to
63 help check for that.
64
65
66 Documentation for MISRA C:2012 Dir 4.1: read from uninitialized allocated object
67 ________________________________________________________________________________
68
69 Dynamically allocated storage is used in a controlled manner, to prevent the
70 access to uninitialized allocated storage.
71
72
73 Documentation for MISRA C:2012 Dir 4.1: write to string literal or const object
74 _______________________________________________________________________________
75
76 The toolchain puts every string literal and const object into a read-only
77 section of memory. The hardware exception raised when a write is attempted
78 on such a memory section is correctly handled.
79
80
81 Documentation for MISRA C:2012 Dir 4.1: non-volatile access to volatile object
82 ______________________________________________________________________________
83
84 Volatile access is limited to registers that are always accessed
85 through macros or inline functions, or by limited code chunks that are only used
86 to access a register.
87
88
89 Documentation for MISRA C:2012 Dir 4.1: access to dead allocated object
90 _______________________________________________________________________
91
92 Although dynamically allocated storage is used in the project, in safety
93 configurations its usage is very limited at runtime (it is "almost" only used
94 at boot time). Coverity is regularly used to scan the code to detect non-freed
95 allocated objects.
96
97
98 Documentation for MISRA C:2012 Dir 4.1: access to dead automatic object
99 _______________________________________________________________________
100
101 Pointers to automatic variables are never returned, nor stored in
102 wider-scoped objects. No function does the same on any pointer
103 received as a parameter.
104
105
106 Documentation for MISRA C:2012 Dir 4.1: access to dead thread object
107 ____________________________________________________________________
108
109 The program does not use per-thread variables.
110
111
112 Documentation for MISRA C:2012 Dir 4.1: access using null pointer
113 _________________________________________________________________
114
115 All possibly null pointers are checked before access.
116
117
118 Documentation for MISRA C:2012 Dir 4.1: access using invalid pointer
119 ____________________________________________________________________
120
121 Usage of pointers is limited. Pointers passed as parameters are
122 always checked for validity.
123
124
125 Documentation for MISRA C:2012 Dir 4.1: access using out-of-bounds pointer
126 __________________________________________________________________________
127
128 Pointers are never used to access arrays without checking for the array size
129 first.
130
131
132 Documentation for MISRA C:2012 Dir 4.1: access using unaligned pointer
133 ______________________________________________________________________
134
135 Pointer conversion that may result in unaligned pointers are never used.
136
137
138 Documentation for MISRA C:2012 Dir 4.1: mistyped access to object
139 _________________________________________________________________
140
141 Pointer conversions that may result in mistyped accesses to objects
142 are never used.
143
144
145 Documentation for MISRA C:2012 Dir 4.1: mistyped access to function
146 ___________________________________________________________________
147
148 This behaviour can arise, for instance, from:
149
150 - incongruent declarations;
151 - functions having no prototypes;
152 - casts on function pointers.
153
154 The project has adopted various compiler flags and MISRA rules to lessen the
155 likelihood of this event.
156
157
158 Documentation for MISRA C:2012 Dir 4.1: invalid pointer arithmetic
159 __________________________________________________________________
160
161 Pointer arithmetic is never used without checking object boundaries.
162
163
164 Documentation for MISRA C:2012 Dir 4.1: invalid pointer comparison
165 __________________________________________________________________
166
167 Pointers to different objects are never compared (except for pointers that are
168 actually linker symbols, but those cases are deviated with a justification).
169
170
171 Documentation for MISRA C:2012 Dir 4.1: overlapping copy
172 ________________________________________________________
173
174 The code never uses memcpy() to copy overlapping objects. The instances of
175 assignments involving overlapping objects are very limited and motivated.
176
177
178 Documentation for MISRA C:2012 Dir 4.1: invalid arguments to function
179 _____________________________________________________________________
180
181 Many parameters to functions are checked for validity; there is ongoing work to
182 make this true for all parameters.
183
184
185 Documentation for MISRA C:2012 Dir 4.1: returned function error
186 _______________________________________________________________
187
188 Many functions that may produce an error, do return a suitable status code
189 that is checked at each call site. There is ongoing work to make this true for
190 all such functions.
191
192
193 Documentation for MISRA C:2012 Dir 4.1: tainted input
194 _____________________________________________________
195
196 All parameters of all functions in the extenal ABI are checked before being
197 used.
198
199
200 Documentation for MISRA C:2012 Dir 4.1: data race
201 _________________________________________________
202
203 Data that can be accessed concurrently from multiple threads and code executed
204 by interrupt handlers is protected using spinlocks and other forms of locking,
205 as appropriate.
206
207
208 Documentation for MISRA C:2012 Dir 4.1: invariant violation
209 ___________________________________________________________
210
211 The extensive checks in the code ensure that any violation of a compile-time
212 invariant will be detected prior to release builds, and violation of run-time
213 invariants is extensively tested. In release builds the number of invariants
214 is greatly reduced.
215
216
217 Documentation for MISRA C:2012 Dir 4.1: communication error
218 ___________________________________________________________
219
220 This project does not involve any external communication.