Skip to content

Commit 88a905b

Browse files
committed
Remove Mutex handling, do cleanup.
1 parent 0f5cd40 commit 88a905b

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
@@ -224,15 +224,6 @@ void MiriGenMCShim::handleThreadFinish(ThreadId thread_id, uint64_t ret_val)
224224
GenMCDriver::handleThreadFinish(std::move(eLab));
225225
}
226226

227-
/**** Blocking instructions ****/
228-
229-
void MiriGenMCShim::handleUserBlock(ThreadId thread_id)
230-
{
231-
auto pos = incPos(thread_id);
232-
auto bLab = UserBlockLabel::create(pos);
233-
GenMCDriver::handleBlock(std::move(bLab));
234-
}
235-
236227
/**** Memory access handling ****/
237228

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

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)