private void InstrumentCurrentLocksetInvariantsInRegion(InstrumentationRegion region) { if (this.EP.IsHoldingLock) { var lockVars = new HashSet <Variable>(); foreach (var variable in base.CurrentLocksetVariables) { if (this.ShouldLock(region, variable)) { lockVars.Add(variable); continue; } base.InstrumentRequiresCandidate(region, variable, true); base.InstrumentEnsuresCandidate(region, variable, true); foreach (var block in region.LoopHeaders()) { base.InstrumentAssertCandidate(block, variable, true); } } foreach (var lockVar in lockVars) { base.InstrumentRequires(region, lockVar, true); base.InstrumentEnsures(region, lockVar, true); foreach (var block in region.LoopHeaders()) { base.InstrumentAssert(block, lockVar, true); } } } else { foreach (var variable in base.CurrentLocksetVariables) { base.InstrumentRequires(region, variable, false); base.InstrumentEnsures(region, variable, false); foreach (var block in region.LoopHeaders()) { base.InstrumentAssert(block, variable, false); } } } }
private void InstrumentWriteAccessInvariantsInEntryPointRegion(InstrumentationRegion region) { foreach (var pair in region.GetResourceAccesses()) { var waVars = base.WriteAccessCheckingVariables.FindAll(val => val.Name.Contains(pair.Key + "_$")); if (this.EP.ForceWriteResource.Contains(pair.Key)) { continue; } if (!this.EP.HasWriteAccess.ContainsKey(pair.Key)) { foreach (var variable in waVars) { base.InstrumentEnsures(region, variable, false); foreach (var block in region.LoopHeaders()) { base.InstrumentAssert(block, variable, false); } } continue; } Expr nonWatchedExpr = null; foreach (var watchedVar in base.AccessWatchdogConstants) { if (!watchedVar.Name.EndsWith(pair.Key)) { continue; } foreach (var access in pair.Value) { var watchedExpr = Expr.Eq(new IdentifierExpr(watchedVar.tok, watchedVar), access); foreach (var variable in waVars) { base.InstrumentImpliesEnsuresCandidate(region, watchedExpr, variable, false, true); foreach (var block in region.LoopHeaders()) { base.InstrumentImpliesAssertCandidate(block, watchedExpr, variable, false, true); } } if (nonWatchedExpr == null) { nonWatchedExpr = Expr.Neq(new IdentifierExpr(watchedVar.tok, watchedVar), access); } else { nonWatchedExpr = Expr.And(nonWatchedExpr, Expr.Neq(new IdentifierExpr(watchedVar.tok, watchedVar), access)); } } } foreach (var variable in waVars) { base.InstrumentImpliesEnsuresCandidate(region, nonWatchedExpr, variable, false, true); foreach (var block in region.LoopHeaders()) { base.InstrumentImpliesAssertCandidate(block, nonWatchedExpr, variable, false, true); } } } }
private void InstrumentMemoryLocksetInvariantsInRegion(InstrumentationRegion region) { foreach (var pair in region.GetResourceAccesses()) { var memLsVars = base.MemoryLocksetVariables.FindAll(val => val.Name.Contains(pair.Key + "_$")); if (this.EP.ForceWriteResource.Contains(pair.Key) || this.EP.ForceReadResource.Contains(pair.Key)) { continue; } if (!this.EP.HasWriteAccess.ContainsKey(pair.Key) && !this.EP.HasReadAccess.ContainsKey(pair.Key)) { foreach (var variable in memLsVars) { base.InstrumentRequires(region, variable, true); base.InstrumentEnsures(region, variable, true); foreach (var block in region.LoopHeaders()) { base.InstrumentAssert(block, variable, true); } } continue; } Expr nonWatchedExpr = null; foreach (var watchedVar in base.AccessWatchdogConstants) { if (!watchedVar.Name.EndsWith(pair.Key)) { continue; } foreach (var access in pair.Value) { var watchedExpr = Expr.Eq(new IdentifierExpr(watchedVar.tok, watchedVar), access); foreach (var variable in memLsVars) { if (this.ShouldLock(region, variable)) { continue; } base.InstrumentImpliesRequiresCandidate(region, watchedExpr, variable, true, true); base.InstrumentImpliesEnsuresCandidate(region, watchedExpr, variable, true, true); foreach (var block in region.LoopHeaders()) { base.InstrumentImpliesAssertCandidate(block, watchedExpr, variable, true, true); } } if (nonWatchedExpr == null) { nonWatchedExpr = Expr.Neq(new IdentifierExpr(watchedVar.tok, watchedVar), access); } else { nonWatchedExpr = Expr.And(nonWatchedExpr, Expr.Neq(new IdentifierExpr(watchedVar.tok, watchedVar), access)); } } } var lockVars = new HashSet <Variable>(); foreach (var variable in memLsVars) { if (this.ShouldLock(region, variable)) { lockVars.Add(variable); continue; } base.InstrumentImpliesRequiresCandidate(region, nonWatchedExpr, variable, true, true); base.InstrumentImpliesEnsuresCandidate(region, nonWatchedExpr, variable, true, true); foreach (var block in region.LoopHeaders()) { base.InstrumentImpliesAssertCandidate(block, nonWatchedExpr, variable, true, true); } } foreach (var lockVar in lockVars) { base.InstrumentRequires(region, lockVar, true); base.InstrumentEnsures(region, lockVar, true); foreach (var block in region.LoopHeaders()) { base.InstrumentAssert(block, lockVar, true); } } } }