Skip to content

Commit 05cea12

Browse files
committed
Remove Mutex handling, do cleanup.
1 parent 39d7e57 commit 05cea12

13 files changed

+4
-509
lines changed

genmc-sys/src/lib.rs

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@ impl GenmcScalar {
1717
pub const UNINIT: Self = Self { value: 0, extra: 0, is_init: false };
1818
pub const DUMMY: Self = Self::from_u64(0xDEADBEEF);
1919

20-
pub const MUTEX_LOCKED_STATE: Self = Self::from_u64(1);
21-
pub const MUTEX_UNLOCKED_STATE: Self = Self::from_u64(0);
22-
2320
pub const fn from_u64(value: u64) -> Self {
2421
Self { value, extra: 0, is_init: true }
2522
}
@@ -91,7 +88,6 @@ mod ffi {
9188
Normal,
9289
ReadModifyWrite,
9390
CompareExchange,
94-
MutexUnlockWrite,
9591
}
9692

9793
#[derive(Debug, Clone, Copy)]
@@ -112,13 +108,6 @@ mod ffi {
112108
error: UniquePtr<CxxString>, // TODO GENMC: pass more error info here
113109
}
114110

115-
#[must_use]
116-
#[derive(Debug)]
117-
struct MutexLockResult {
118-
is_lock_acquired: bool,
119-
error: UniquePtr<CxxString>, // TODO GENMC: pass more error info here
120-
}
121-
122111
#[must_use]
123112
#[derive(Debug)]
124113
struct CompareExchangeResult {
@@ -195,7 +184,6 @@ mod ffi {
195184
type StoreResult;
196185
type ReadModifyWriteResult;
197186
type CompareExchangeResult;
198-
type MutexLockResult;
199187
type VerificationError;
200188

201189
type GenmcScalar;
@@ -267,29 +255,6 @@ mod ffi {
267255
fn handleThreadJoin(self: Pin<&mut MiriGenMCShim>, thread_id: i32, child_id: i32);
268256
fn handleThreadFinish(self: Pin<&mut MiriGenMCShim>, thread_id: i32, ret_val: u64);
269257

270-
/**** Blocking instructions ****/
271-
fn handleUserBlock(self: Pin<&mut MiriGenMCShim>, thread_id: i32);
272-
273-
/**** Mutex handling ****/
274-
fn handleMutexLock(
275-
self: Pin<&mut MiriGenMCShim>,
276-
thread_id: i32,
277-
address: u64,
278-
size: u64,
279-
) -> MutexLockResult;
280-
fn handleMutexTryLock(
281-
self: Pin<&mut MiriGenMCShim>,
282-
thread_id: i32,
283-
address: u64,
284-
size: u64,
285-
) -> MutexLockResult;
286-
fn handleMutexUnlock(
287-
self: Pin<&mut MiriGenMCShim>,
288-
thread_id: i32,
289-
address: u64,
290-
size: u64,
291-
) -> StoreResult;
292-
293258
/**** Scheduling ****/
294259
fn scheduleNext(
295260
self: Pin<&mut MiriGenMCShim>,

genmc-sys/src_cpp/MiriInterface.cpp

Lines changed: 0 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -215,15 +215,6 @@ void MiriGenMCShim::handleThreadFinish(ThreadId thread_id, uint64_t ret_val)
215215
GenMCDriver::handleThreadFinish(std::move(eLab));
216216
}
217217

218-
/**** Blocking instructions ****/
219-
220-
void MiriGenMCShim::handleUserBlock(ThreadId thread_id)
221-
{
222-
auto pos = incPos(thread_id);
223-
auto bLab = UserBlockLabel::create(pos);
224-
GenMCDriver::handleBlock(std::move(bLab));
225-
}
226-
227218
/**** Memory access handling ****/
228219

229220
[[nodiscard]] auto MiriGenMCShim::handleLoad(ThreadId thread_id, uint64_t address, uint64_t size,
@@ -356,9 +347,6 @@ void MiriGenMCShim::handleUserBlock(ThreadId thread_id)
356347
case StoreEventType::CompareExchange:
357348
wLab = std::make_unique<CasWriteLabel>(pos, ord, loc, aSize, type, val);
358349
break;
359-
case StoreEventType::MutexUnlockWrite:
360-
wLab = UnlockWriteLabel::create(pos, ord, loc, aSize, AType::Signed, val);
361-
break;
362350
default:
363351
ERROR("Unsupported Store Event Type");
364352
}
@@ -412,94 +400,3 @@ void MiriGenMCShim::handleFree(ThreadId thread_id, uint64_t address, uint64_t si
412400
auto dLab = std::make_unique<FreeLabel>(pos, addr, size);
413401
GenMCDriver::handleFree(std::move(dLab));
414402
}
415-
416-
/**** Mutex handling ****/
417-
418-
auto MiriGenMCShim::handleMutexLock(ThreadId thread_id, uint64_t address, uint64_t size)
419-
-> MutexLockResult
420-
{
421-
// TODO GENMC: this needs to be identical even in multithreading
422-
ModuleID::ID annot_id;
423-
if (annotation_id.contains(address)) {
424-
annot_id = annotation_id.at(address);
425-
} else {
426-
annot_id = annotation_id_counter++;
427-
annotation_id.insert(std::make_pair(address, annot_id));
428-
}
429-
const auto aSize = ASize(size);
430-
auto annot = std::move(Annotation(
431-
AssumeType::Spinloop,
432-
Annotation::ExprVP(NeExpr<AnnotID>::create(
433-
RegisterExpr<AnnotID>::create(aSize.getBits(), annot_id),
434-
ConcreteExpr<AnnotID>::create(aSize.getBits(), SVal(1)))
435-
.release())));
436-
437-
auto &currPos = globalInstructions[thread_id].event;
438-
// auto rLab = LockCasReadLabel::create(++currPos, address, size);
439-
auto rLab = LockCasReadLabel::create(++currPos, address, size, annot);
440-
441-
// Mutex starts out unlocked, so we always say the previous value is "unlocked".
442-
auto oldValSetter = [this](SAddr loc) { this->handleOldVal(loc, SVal(0)); };
443-
LoadResult loadResult = GenMCDriver::handleLoad(std::move(rLab), oldValSetter);
444-
if (loadResult.is_error()) {
445-
--currPos;
446-
return MutexLockResult::fromError(*loadResult.error);
447-
} else if (loadResult.is_read_opt) {
448-
--currPos;
449-
// TODO GENMC: is_read_opt == Mutex is acquired
450-
// None --> Someone else has lock, this thread will be rescheduled later (currently
451-
// block) 0 --> Got the lock 1 --> Someone else has lock, this thread will
452-
// not be rescheduled later (block on Miri side)
453-
return MutexLockResult(false);
454-
}
455-
// TODO GENMC(QUESTION): is the `isBlocked` even needed?
456-
// if (!loadResult.has_value() || getCurThr().isBlocked())
457-
// return;
458-
459-
const bool is_lock_acquired = loadResult.value() == SVal(0);
460-
if (is_lock_acquired) {
461-
auto wLab = LockCasWriteLabel::create(++currPos, address, size);
462-
StoreResult storeResult = GenMCDriver::handleStore(std::move(wLab), oldValSetter);
463-
if (storeResult.is_error())
464-
return MutexLockResult::fromError(*storeResult.error);
465-
466-
} else {
467-
auto bLab = LockNotAcqBlockLabel::create(++currPos);
468-
GenMCDriver::handleBlock(std::move(bLab));
469-
}
470-
471-
return MutexLockResult(is_lock_acquired);
472-
}
473-
474-
auto MiriGenMCShim::handleMutexTryLock(ThreadId thread_id, uint64_t address, uint64_t size)
475-
-> MutexLockResult
476-
{
477-
auto &currPos = globalInstructions[thread_id].event;
478-
auto rLab = TrylockCasReadLabel::create(++currPos, address, size);
479-
// Mutex starts out unlocked, so we always say the previous value is "unlocked".
480-
auto oldValSetter = [this](SAddr loc) { this->handleOldVal(loc, SVal(0)); };
481-
LoadResult loadResult = GenMCDriver::handleLoad(std::move(rLab), oldValSetter);
482-
if (!loadResult.has_value()) {
483-
--currPos;
484-
// TODO GENMC: maybe use std move and make it take a unique_ptr<string> ?
485-
return MutexLockResult::fromError(*loadResult.error);
486-
}
487-
488-
const bool is_lock_acquired = loadResult.value() == SVal(0);
489-
if (!is_lock_acquired)
490-
return MutexLockResult(false); /* Lock already held. */
491-
492-
auto wLab = TrylockCasWriteLabel::create(++currPos, address, size);
493-
StoreResult storeResult = GenMCDriver::handleStore(std::move(wLab), oldValSetter);
494-
if (storeResult.is_error())
495-
return MutexLockResult::fromError(*storeResult.error);
496-
497-
return MutexLockResult(true);
498-
}
499-
500-
auto MiriGenMCShim::handleMutexUnlock(ThreadId thread_id, uint64_t address, uint64_t size)
501-
-> StoreResult
502-
{
503-
return handleStore(thread_id, address, size, SVal(0), SVal(0xDEADBEEF),
504-
MemOrdering::Release, StoreEventType::MutexUnlockWrite);
505-
}

genmc-sys/src_cpp/MiriInterface.hpp

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -28,22 +28,6 @@ enum class StoreEventType : uint8_t {
2828
Normal,
2929
ReadModifyWrite,
3030
CompareExchange,
31-
MutexUnlockWrite,
32-
};
33-
34-
struct MutexLockResult {
35-
bool is_lock_acquired;
36-
std::unique_ptr<ModelCheckerError> error; // TODO GENMC: pass more error info here
37-
38-
MutexLockResult(bool is_lock_acquired) : is_lock_acquired(is_lock_acquired), error(nullptr)
39-
{}
40-
41-
static auto fromError(std::string msg) -> MutexLockResult
42-
{
43-
auto res = MutexLockResult(false);
44-
res.error = std::make_unique<ModelCheckerError>(msg);
45-
return res;
46-
}
4731
};
4832

4933
// TODO GENMC: fix naming conventions
@@ -97,21 +81,8 @@ struct MiriGenMCShim : private GenMCDriver {
9781
void handleThreadJoin(ThreadId thread_id, ThreadId child_id);
9882
void handleThreadFinish(ThreadId thread_id, uint64_t ret_val);
9983

100-
/**** Blocking instructions ****/
101-
102-
void handleUserBlock(ThreadId thread_id);
103-
104-
/**** Mutex handling ****/
105-
auto handleMutexLock(ThreadId thread_id, uint64_t address, uint64_t size)
106-
-> MutexLockResult;
107-
auto handleMutexTryLock(ThreadId thread_id, uint64_t address, uint64_t size)
108-
-> MutexLockResult;
109-
auto handleMutexUnlock(ThreadId thread_id, uint64_t address, uint64_t size) -> StoreResult;
110-
11184
/**** Scheduling queries ****/
11285

113-
// TODO GENMC: implement
114-
11586
auto scheduleNext(const int curr_thread_id, const ActionKind curr_thread_next_instr_kind)
11687
-> int64_t;
11788

src/concurrency/genmc/dummy.rs

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -254,26 +254,6 @@ impl GenmcCtx {
254254
}
255255
}
256256

257-
/// Other functionality not directly related to event handling
258-
impl<'tcx> EvalContextExt<'tcx> for crate::MiriInterpCx<'tcx> {}
259-
pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
260-
fn check_genmc_intercept_function(
261-
&mut self,
262-
_instance: rustc_middle::ty::Instance<'tcx>,
263-
_args: &[rustc_const_eval::interpret::FnArg<'tcx, crate::Provenance>],
264-
_dest: &crate::PlaceTy<'tcx>,
265-
_ret: Option<mir::BasicBlock>,
266-
) -> InterpResult<'tcx, bool> {
267-
unreachable!()
268-
}
269-
270-
/**** Scheduling functionality ****/
271-
272-
fn genmc_schedule_thread(&mut self) -> InterpResult<'tcx, ThreadId> {
273-
unreachable!()
274-
}
275-
}
276-
277257
impl VisitProvenance for GenmcCtx {
278258
fn visit_provenance(&self, _visit: &mut VisitWith<'_>) {
279259
unreachable!()

0 commit comments

Comments
 (0)