This repository has been archived by the owner on Feb 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodel0116.tmpl
227 lines (187 loc) · 5.4 KB
/
model0116.tmpl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
[% PROCESS rerouter.tmpl ~%]
before: file ("$this")
{
#include <verifier/rcv.h>
extern void ldv_irq_disable_inc( void );
extern void ldv_irq_disable_dec( void );
#include <linux/kernel.h>
#include <linux/spinlock.h>
extern void __ldv_check_all(spinlock_t *lock);
extern void __ldv_check_interrupt(spinlock_t *lock);
[% # Generate model function prototypes.
FOREACH sign = signs; PROCESS make_human_sign %]
extern void ldv_lock_in_process[% sign_id %](void);
extern void ldv_lock_in_interrupt[% sign_id %](void);
[% END %]
}
around: define( local_irq_disable() )
{
ldv_irq_disable_inc()
}
around: define( local_irq_enable() )
{
ldv_irq_disable_dec()
}
around: define( local_irq_save(flags) )
{
ldv_irq_disable_inc()
}
around: define( local_irq_restore(flags) )
{
ldv_irq_disable_dec()
}
around: call( static inline void spin_unlock_irqrestore(..) )
{
ldv_irq_disable_dec();
}
around: call( static inline void spin_unlock_irq(..) )
{
ldv_irq_disable_dec();
}
around: call( static inline void spin_lock(..) )
|| call( static inline void spin_lock_bh(..) )
{
ldv_lock_in_interrupt[% arg_sign(1) %]();
ldv_lock_in_process[% arg_sign(1) %]();
}
around: call( static inline void spin_lock_irq(..) )
{
ldv_lock_in_interrupt[% arg_sign(1) %]();
ldv_irq_disable_inc();
}
around: call( static inline int spin_trylock(..) )
|| call( static inline int spin_trylock_bh(..) )
{
if ( ldv_undef_int() > 0 ) {
ldv_lock_in_interrupt[% arg_sign(1) %]();
ldv_lock_in_process[% arg_sign(1) %]();
return 1;
} else {
return 0;
}
}
around: call( static inline int spin_trylock_irq(..) )
{
if ( ldv_undef_int() > 0 ) {
ldv_lock_in_interrupt[% arg_sign(1) %]();
ldv_irq_disable_inc();
return 1;
} else {
return 0;
}
}
after: call( void __ldv_check_all(..) )
{
ldv_lock_in_interrupt[% arg_sign(1) %]();
ldv_lock_in_process[% arg_sign(1) %]();
}
after: call( void __ldv_check_interrupt(..) )
{
ldv_lock_in_interrupt[% arg_sign(1) %]();
}
around: define( spin_lock_irqsave(lock, flags) )
{
({
__ldv_check_interrupt(lock);
ldv_irq_disable_inc();
})
}
around: define( spin_lock_irqsave_nested(lock, flags, subclass) )
{
({
__ldv_check_interrupt(lock);
ldv_irq_disable_inc();
})
}
around: define( spin_lock_nest_lock(lock, nest_lock) )
{
__ldv_check_all(lock)
}
around: define( spin_lock_nested(lock, subclass) )
{
__ldv_check_all(lock)
}
around: define( spin_trylock_irqsave(lock, flags) )
{
({
if ( ldv_undef_int() > 0 ) {
__ldv_check_interrupt(lock);
ldv_irq_disable_inc();
1;
} else {
0;
}
})
}
around: define( atomic_dec_and_lock(atomic, lock) )
{
({
--atomic;
if ( atomic == 0 ) {
__ldv_check_all(lock);
1;
} else {
0;
}
})
}
new: file(LDV_COMMON_MODEL)
{
#include <verifier/rcv.h>
extern int LDV_IN_INTERRUPT;
/* LDV_COMMENT_MODEL_STATE Indicates whether interrupts disabled or enabled.*/
int ldv_irq_disable_nesting = 0;
/* LDV_COMMENT_MODEL_FUNCTION_DEFINITION(name='ldv_irq_disable_inc') Entry in irq_disable/irq_enable section.*/
void
ldv_irq_disable_inc( void )
{
/* LDV_COMMENT_CHANGE_STATE Increments the level of irq_disable nesting.*/
++ldv_irq_disable_nesting;
}
/* LDV_COMMENT_MODEL_FUNCTION_DEFINITION(name='ldv_irq_disable_dec') Exit from irq_disable/irq_enable section.*/
void
ldv_irq_disable_dec( void )
{
/* LDV_COMMENT_CHANGE_STATE Decrements the level of irq_disable nesting.*/
--ldv_irq_disable_nesting;
}
[% # Generate model state variables and functions.
FOREACH sign = signs; PROCESS make_human_sign %]
static int ldv_lock_in_process_flag[% sign_id %];
static int ldv_lock_in_interrupt_flag[% sign_id %];
/* LDV_COMMENT_MODEL_FUNCTION_DEFINITION(name='ldv_lock_in_interrupt[% sign_id %]') Checks for interrupt context.*/
void ldv_lock_in_interrupt[% sign_id %](void)
{
if ( LDV_IN_INTERRUPT == 2 ) {
/* LDV_COMMENT_CHANGE_STATE usage of the lock in interrupt context.*/
++ldv_lock_in_interrupt_flag[% sign_id %];
}
}
/* LDV_COMMENT_MODEL_FUNCTION_DEFINITION(name='ldv_lock_in_process[% sign_id %]') Checks for process context.*/
void ldv_lock_in_process[% sign_id %](void)
{
if ( ( LDV_IN_INTERRUPT == 1 ) && ( ldv_irq_disable_nesting <= 0 ) ) {
/* LDV_COMMENT_CHANGE_STATE usage of the lock in process context with enabled interrupts.*/
++ldv_lock_in_process_flag[% sign_id %];
}
}
[% END %]
/* LDV_COMMENT_MODEL_FUNCTION_DEFINITION(name='ldv_check_final_state') Checks for usage of the same lock in different contexts.*/
void ldv_check_final_state(void)
{
[% # Initialize all model state variables at the beginning.
FOREACH sign = signs; PROCESS make_human_sign %]
/* LDV_COMMENT_ASSERT If you use same lock in interrupt context (e.g. interrupt handler) and in process context, then in the latter case interrupts (maybe just one line) should be disabled.*/
ldv_assert( ( ldv_lock_in_interrupt_flag[% sign_id %] == 0 ) || ( ldv_lock_in_process_flag[% sign_id%] == 0 ) );
[% END %]
}
/* LDV_COMMENT_MODEL_FUNCTION_DEFINITION(name='ldv_initialize') Initialization of lock variables.*/
void ldv_initialize(void)
{
[% # Initialize all model state variables at the beginning.
FOREACH sign = signs; PROCESS make_human_sign %]
ldv_lock_in_process_flag[% sign_id %] = 0;
ldv_lock_in_interrupt_flag[% sign_id %] = 0;
[% END %]
}
}