|
2 | 2 |
|
3 | 3 | #include "MiriInterface.hpp"
|
4 | 4 |
|
| 5 | +// GenMC headers: |
| 6 | +#include "Static/ModuleID.hpp" |
| 7 | + |
5 | 8 | // CXX.rs generated headers:
|
6 | 9 | #include "genmc-sys/src/lib.rs.h"
|
7 | 10 |
|
|
10 | 13 |
|
11 | 14 | auto MiriGenmcShim::handle_mutex_lock(ThreadId thread_id, uint64_t address, uint64_t size)
|
12 | 15 | -> MutexLockResult {
|
13 |
| - // FIXME(genmc,multithreading): ensure this annotation id is unique even if Miri runs GenMC mode |
14 |
| - // multithreaded. We cannot use the address directly, since it is 64 bits, and `ID` is an |
15 |
| - // `unsigned int`. |
16 |
| - ModuleID::ID annot_id; |
17 |
| - auto [it, inserted] = annotation_id.try_emplace(address, annotation_id_counter); |
18 |
| - if (inserted) { |
19 |
| - annot_id = annotation_id_counter++; |
20 |
| - } else { |
21 |
| - annot_id = it->second; |
22 |
| - } |
| 16 | + // This annotation informs GenMC about the condition required to make this lock call succeed. |
| 17 | + // It stands for `value_read_by_load != MUTEX_LOCKED`. |
23 | 18 | const auto size_bits = size * 8;
|
24 | 19 | const auto annot = std::move(Annotation(
|
25 | 20 | AssumeType::Spinloop,
|
26 |
| - Annotation::ExprVP(NeExpr<AnnotID>::create( |
27 |
| - RegisterExpr<AnnotID>::create(size_bits, annot_id), |
28 |
| - ConcreteExpr<AnnotID>::create(size_bits, MUTEX_LOCKED) |
| 21 | + Annotation::ExprVP( |
| 22 | + NeExpr<ModuleID::ID>::create( |
| 23 | + // `RegisterExpr` marks the value of the current expression, i.e., the loaded value. |
| 24 | + // The id is zero, since this annotation only uses one input variable. |
| 25 | + RegisterExpr<ModuleID::ID>::create(size_bits, /* id */ 0), |
| 26 | + ConcreteExpr<ModuleID::ID>::create(size_bits, MUTEX_LOCKED) |
| 27 | + ) |
| 28 | + .release() |
29 | 29 | )
|
30 |
| - .release()) |
31 | 30 | ));
|
32 | 31 |
|
33 | 32 | // Mutex starts out unlocked, so we always say the previous value is "unlocked".
|
|
0 commit comments