1 # FreeRTOS VeriFast Proof Signoff
3 Verification tool: VeriFast (code-level proof)
5 Proofs: `queue/` and `list`
7 Implementation: Kernel queue data structure (`queue.c`) and list data structure (`list.c`)
9 Specification / Properties:
10 - *Memory safety*: the implementation only accesses valid memory. In the case
11 of the queue, this is true under any arbitrary number of tasks or ISRs.
12 - *Thread safety*: in the case of the queue, tasks and ISRs only update
13 objects that they own via proper synchronization.
14 - *Functional correctness*: the queue and list implementations behave like an
15 abstract queue and list. In the case of the queue, this is true under any
16 arbitrary number of tasks or ISRs.
18 ## Queue proof assumptions
20 Generally, we assume well-behaved clients; the correctness of underlying
21 primitives (memory allocation, task scheduling, scheduler suspension); and
22 assumptions about the system.
24 - Well-behaved client: all client tasks and ISRs use the queue API in a
25 manner that adheres to the specification. A badly-behaved client can
26 invalidate the proven properties. For example, a client that reads or
27 writes to the queue storage directly, without masking interrupts, is racy
28 and no longer thread safe. The specification forbids this behavior by
29 the definition of `queuehandle`, which is a handle to acquire ownership of
30 the queue through interrupt masking, but we cannot, in general, enforce
31 this behavior since we do not verify client code.
33 - Memory safety, thread safety and function contracts for the following
34 primitives. For the list and task functions we give a contract that is
35 maximal in terms of the queue objects that can be updated, but we do not
36 model their function effect (e.g., task blocking and the moving of task
37 control blocks between scheduler lists).
43 xTaskRemoveFromEventList
46 vTaskInternalSetTimeOutState
49 - We assume interrupt masking gives strong isolation between tasks and ISRs.
50 See Appendix. We further assume the system is configured as required by
51 `configASSERT`. For example, interrupts with a priority greater than the
52 maximum system call priority must not call queue API functions, otherwise
53 the strong isolation guarantee is not maintained.
55 ## List proof assumptions
57 The list proofs are sequential. We assume the caller of the list API functions
58 has taken appropriate synchronization steps to avoid races.
62 A list of changes to the source code required for the proofs can be generated:
68 A side-by-side diff with respect to the source code can be generated. See
69 .
71 The main queue changes are:
73 - merge cTxLock and cRxLock critical regions: under approximate queue
74 unlock behavior to atomically set `cTxLock` and `cRxLock` to unlocked in a
75 single critical region instead of two separate critical regions. In
76 practice, this is not an issue since no ISR function reads-from both
78 - model single malloc of struct and buffer: split the single malloc of the
79 queue struct and storage into two separate mallocs.
80 - xQueueGenericReset happens-before concurrent behavior: assume that queue
81 initialisation is not concurrent.
82 - do not model pxIndex and xListEnd of xLIST struct: ignore these fields in
83 the list structs of the queue implementation
85 The main list changes are:
87 - change `MiniList_t` to `ListItem_t`: simplifying assumption on the list
89 - over-approximate list insert loop: replace a loop in the insert function
90 that finds the insertion point with an over-approximating function call.
92 The following minor changes due to the stricter typing and parser of VeriFast:
94 - replacing a union declaration with a struct
95 - const pointer declaration
97 - void cast of unused return value
98 - void cast of unused var
100 The following minor changes due to the modeling of interrupts and scheduler
101 suspension in the proofs as ghost state.
104 - leak ghost state on deletion
108 We do not verify across the full configuration space of FreeRTOS. In
109 particular, the queue proofs do not apply when the following options are
112 - `configUSE_QUEUE_SETS`
113 - `configSUPPORT_STATIC_ALLOCATION`
115 For both the queue and list proofs we assume that coverage and tracing
118 ## Trusted computing base
120 - Soundness of verification tools: VeriFast, Redux prover
121 - C Compiler, because the verification is at the C code-level and the
122 properties proved may not be preserved by compilation.
126 [N1570] ISO/IEC. Programming languages – C. International standard 9899:201x,
131 Assumption on strong isolation induced by interrupt masking and scheduler
132 suspension for queue proofs. Informally, we need the following:
135 // Initially *data == 0
143 r0 = *data; //< guaranteed to read 0 or 2, never 1