@@ -34,6 +34,7 @@ struct SchedulingResult;
34
34
struct LoadResult ;
35
35
struct StoreResult ;
36
36
struct ReadModifyWriteResult ;
37
+ struct CompareExchangeResult ;
37
38
38
39
// GenMC uses `int` for its thread IDs.
39
40
using ThreadId = int ;
@@ -100,6 +101,17 @@ struct MiriGenmcShim : private GenMCDriver {
100
101
GenmcScalar rhs_value,
101
102
GenmcScalar old_val
102
103
);
104
+ [[nodiscard]] CompareExchangeResult handle_compare_exchange (
105
+ ThreadId thread_id,
106
+ uint64_t address,
107
+ uint64_t size,
108
+ GenmcScalar expected_value,
109
+ GenmcScalar new_value,
110
+ GenmcScalar old_val,
111
+ MemOrdering success_ordering,
112
+ MemOrdering fail_load_ordering,
113
+ bool can_fail_spuriously
114
+ );
103
115
[[nodiscard]] StoreResult handle_store (
104
116
ThreadId thread_id,
105
117
uint64_t address,
@@ -231,15 +243,15 @@ constexpr auto get_global_alloc_static_mask() -> uint64_t {
231
243
namespace GenmcScalarExt {
232
244
inline GenmcScalar uninit () {
233
245
return GenmcScalar {
234
- /* value: */ 0 ,
235
- /* is_init: */ false ,
246
+ . value = 0 ,
247
+ . is_init = false ,
236
248
};
237
249
}
238
250
239
251
inline GenmcScalar from_sval (SVal sval) {
240
252
return GenmcScalar {
241
- /* value: */ sval.get (),
242
- /* is_init: */ true ,
253
+ . value = sval.get (),
254
+ . is_init = true ,
243
255
};
244
256
}
245
257
@@ -252,22 +264,22 @@ inline SVal to_sval(GenmcScalar scalar) {
252
264
namespace LoadResultExt {
253
265
inline LoadResult no_value () {
254
266
return LoadResult {
255
- /* error: */ std::unique_ptr<std::string>(nullptr ),
256
- /* has_value: */ false ,
257
- /* read_value: */ GenmcScalarExt::uninit (),
267
+ . error = std::unique_ptr<std::string>(nullptr ),
268
+ . has_value = false ,
269
+ . read_value = GenmcScalarExt::uninit (),
258
270
};
259
271
}
260
272
261
273
inline LoadResult from_value (SVal read_value) {
262
- return LoadResult { /* error: */ std::unique_ptr<std::string>(nullptr ),
263
- /* has_value: */ true ,
264
- /* read_value: */ GenmcScalarExt::from_sval (read_value) };
274
+ return LoadResult { . error = std::unique_ptr<std::string>(nullptr ),
275
+ . has_value = true ,
276
+ . read_value = GenmcScalarExt::from_sval (read_value) };
265
277
}
266
278
267
279
inline LoadResult from_error (std::unique_ptr<std::string> error) {
268
- return LoadResult { /* error: */ std::move (error),
269
- /* has_value: */ false ,
270
- /* read_value: */ GenmcScalarExt::uninit () };
280
+ return LoadResult { . error = std::move (error),
281
+ . has_value = false ,
282
+ . read_value = GenmcScalarExt::uninit () };
271
283
}
272
284
} // namespace LoadResultExt
273
285
@@ -278,26 +290,50 @@ inline StoreResult ok(bool is_coherence_order_maximal_write) {
278
290
}
279
291
280
292
inline StoreResult from_error (std::unique_ptr<std::string> error) {
281
- return StoreResult { /* error: */ std::move (error),
282
- /* is_coherence_order_maximal_write: */ false };
293
+ return StoreResult { .error = std::move (error), .is_coherence_order_maximal_write = false };
283
294
}
284
295
} // namespace StoreResultExt
285
296
286
297
namespace ReadModifyWriteResultExt {
287
298
inline ReadModifyWriteResult
288
299
ok (SVal old_value, SVal new_value, bool is_coherence_order_maximal_write) {
289
- return ReadModifyWriteResult { /* error: */ std::unique_ptr<std::string>(nullptr ),
290
- /* old_value: */ GenmcScalarExt::from_sval (old_value),
291
- /* new_value: */ GenmcScalarExt::from_sval (new_value),
292
- is_coherence_order_maximal_write };
300
+ return ReadModifyWriteResult { .error = std::unique_ptr<std::string>(nullptr ),
301
+ .old_value = GenmcScalarExt::from_sval (old_value),
302
+ .new_value = GenmcScalarExt::from_sval (new_value),
303
+ .is_coherence_order_maximal_write =
304
+ is_coherence_order_maximal_write };
293
305
}
294
306
295
307
inline ReadModifyWriteResult from_error (std::unique_ptr<std::string> error) {
296
- return ReadModifyWriteResult { /* error: */ std::move (error),
297
- /* old_value: */ GenmcScalarExt::uninit (),
298
- /* new_value: */ GenmcScalarExt::uninit (),
299
- /* is_coherence_order_maximal_write: */ false };
308
+ return ReadModifyWriteResult { . error = std::move (error),
309
+ . old_value = GenmcScalarExt::uninit (),
310
+ . new_value = GenmcScalarExt::uninit (),
311
+ . is_coherence_order_maximal_write = false };
300
312
}
301
313
} // namespace ReadModifyWriteResultExt
302
314
315
+ namespace CompareExchangeResultExt {
316
+ inline CompareExchangeResult success (SVal old_value, bool is_coherence_order_maximal_write) {
317
+ return CompareExchangeResult { .error = nullptr ,
318
+ .old_value = GenmcScalarExt::from_sval (old_value),
319
+ .is_success = true ,
320
+ .is_coherence_order_maximal_write =
321
+ is_coherence_order_maximal_write };
322
+ }
323
+
324
+ inline CompareExchangeResult failure (SVal old_value) {
325
+ return CompareExchangeResult { .error = nullptr ,
326
+ .old_value = GenmcScalarExt::from_sval (old_value),
327
+ .is_success = false ,
328
+ .is_coherence_order_maximal_write = false };
329
+ }
330
+
331
+ inline CompareExchangeResult from_error (std::unique_ptr<std::string> error) {
332
+ return CompareExchangeResult { .error = std::move (error),
333
+ .old_value = GenmcScalarExt::uninit (),
334
+ .is_success = false ,
335
+ .is_coherence_order_maximal_write = false };
336
+ }
337
+ } // namespace CompareExchangeResultExt
338
+
303
339
#endif /* GENMC_MIRI_INTERFACE_HPP */
0 commit comments