Commit 0a332542 authored by Maeva Ramarjiaona's avatar Maeva Ramarjiaona

added the overapproxiamted analysis

parent 63d5e2b1
......@@ -9,6 +9,9 @@ set(SOURCES "src/lrusecurity.cpp"
"src/Prev/lrusecurity_ExistHitPrevAnalysis.cpp"
"src/Prev/lrusecurity_ExistHitPrevDomain.cpp"
"src/Prev/lrusecurity_ExistHitPrevAdapter.cpp"
"src/Prev_Over/lrusecurity_ExistHitPrevOAnalysis.cpp"
"src/Prev_Over/lrusecurity_ExistHitPrevOAdapter.cpp"
"src/Prev_Over/lrusecurity_ExistHitPrevODomain.cpp"
"src/lrusecurity_Displayer.cpp"
)
......
......@@ -27,9 +27,9 @@ bool ExistHitPrevDomain::equals(const t& acss, const t& bcss) const
return false;
return true;
}
void ExistHitPrevDomain::join(t& dcss, const t& scss)
void ExistHitPrevDomain::join(t& dcss, const t& scss)
{
for (int i = 0; i < _n; i++){
for (int i = 0; i < _n; i++){
int newsize = dcss[i].size()+scss[i].size();
Bag<Address> newbag = Bag<Address>(newsize);
for (int j = 0; j < newsize; j++) {
......
#ifndef LRUSECURITY_EXIST_HIT_PREV_ADAPTER_O_H_
#define LRUSECURITY_EXIST_HIT_PREV_ADAPTER_O_H_
#include <otawa/ai/ArrayStore.h>
#include <otawa/icat3/features.h>
#include <otawa/cfg/CompositeCFG.h>
#include <otawa/cfg/features.h>
#include <lrupreanalysis/features.h>
#include "ExistHitPrevODomain.h"
namespace lrusecurity
{
class ExistHitPrevOAdapter
{
public:
using domain_t = ExistHitPrevODomain;
using t = typename domain_t::t;
using graph_t = otawa::CompositeCFG;
using store_t = otawa::ai::ArrayStore<domain_t, graph_t>;
ExistHitPrevOAdapter(int set, const t* init, const otawa::icat3::LBlockCollection& coll, const otawa::CFGCollection& cfgs, otawa::WorkSpace* ws);
inline domain_t& domain(void) { return _domain; }
inline graph_t& graph(void) { return _graph; }
inline store_t& store(void) { return _store; }
void update(const otawa::Bag<otawa::icache::Access>& accs, t& d);
void update(otawa::Block *v, t& d);
private:
lrumc::ACSManager _mayManager;
domain_t _domain;
graph_t _graph;
store_t _store;
};
} // namespace lrusecurity
#endif // LRUSECURITY_EXIST_HIT_ADAPTER_O_H_
#ifndef LRUSECURITY_EXIST_HIT_ANALYSIS_O_H_
#define LRUSECURITY_EXIST_HIT_ANALYSIS_O_H_
#include <otawa/proc/Processor.h>
#include <otawa/icat3/features.h>
#include <otawa/cfg/features.h>
#include <lrusecurity/ACSSecurity.h>
namespace lrusecurity
{
class ExistHitPrevOAnalysis: public otawa::Processor
{
public:
static otawa::p::declare reg;
ExistHitPrevOAnalysis(otawa::p::declare& r = reg);
protected:
void configure(const otawa::PropList& props) override;
void setup(otawa::WorkSpace* ws) override;
void processWorkSpace(otawa::WorkSpace* ws) override;
void destroy(otawa::WorkSpace* ws) override;
private:
void processSet(int i, otawa::WorkSpace* ws);
const otawa::icat3::Container<ACSSecurity>* _initExistHitPrevO;
const otawa::icat3::LBlockCollection* _coll;
const otawa::CFGCollection* _cfgs;
};
/**
* Perform the ACS analysis for the Exist-Hit domain. For cache block, it associates an upper bound on block age that holds on at least on path
* @par Properties
* @li @ref EXIST_HIT_PREV_IN
*
* @par Configuraiton
* @li @ref EXIST_HIT_PREV_INIT
*
* @par Implementation
* @li @ref ExistHitPrevOAnalysis
*
* @ingroup lrusecurity
*/
extern otawa::p::feature EXIST_HIT_PREV_O_ANALYSIS_FEATURE;
/**
* ACSSecurity for the Exist-Hit analysis at the entry of the corresponding block or edge.
*
* @par Feature
* @li @ref EXIST_HIT_ANALYSIS_PREV_FEATURE
*
* @par Hooks
* @li @ref Block
* @li @ref Edge
*
* @ingroup lrusecurity
*/
extern otawa::p::id<otawa::icat3::Container<ACSSecurity> > EXIST_HIT_PREV_IN;
/**
* Initial state for Exist-Miss instruction cache analysis.
*
* @par Hook
* @li Feature configuration.
*
* @par Feature
* @li @ref EXIST_HIT_ANALYSIS_PREV_FEATURE
*
* @ingroup lrusecurity
*/
extern otawa::p::id<otawa::icat3::Container<ACSSecurity> > EXIST_HIT_PREV_INIT;
}; // namespace lrusecurity
#endif // LRUSECURITY_EXIST_HIT_ANALYSIS_H_
#ifndef LRUSECURITY_EXIST_HIT_DOMAIN_O_H_
#define LRUSECURITY_EXIST_HIT_DOMAIN_O_H_
#include <otawa/icat3/features.h>
#include <otawa/icache/features.h>
#include <elm/io/Output.h>
#include <lrumc/features.h>
#include <lrumc/ACSManager.h>
#include <lrupreanalysis/features.h>
#include <lrusecurity/ACSSecurity.h>
namespace lrusecurity
{
class ExistHitPrevODomain {
public:
using t = ACSSecurity;
ExistHitPrevODomain(const otawa::icat3::LBlockCollection& coll, int set, const t* init);
inline const t& bot(void) const { return _bot; }
inline const t& top(void) const { return _top; }
inline const t& init(void) const { return _init; }
inline void print(const t& a, otawa::io::Output& out) const { a.print(_set, _coll, out); }
inline elm::io::Printable<t, ExistHitPrevODomain> print(const t& a) const { return elm::io::p(a, *this); }
inline bool contains(const t& a, int i) { return(a[i] !=otawa::Bag< otawa::Address>()); }
inline void copy(t& d, const t& s) { d.copy(s); }
bool equals(const t& a, const t& b) const;
void join(t& d, const t& s);
void fetch(t& a, const otawa::icache::Access& ac, lrumc::ACSManager& mayManager);
void update(const otawa::icache::Access& access, t& a, lrumc::ACSManager& mayManager);
private:
int _n;
t _bot, _top;
otawa::hard::Cache::set_t _set;
const otawa::icat3::LBlockCollection& _coll;
int _A;
const t& _init;
t _tmp;
};
} // namespace lrusecurity
#endif // LRUSECURITY_EXIST_HIT_DOMAIN_O_H_
#include "ExistHitPrevOAdapter.h"
using namespace otawa;
namespace lrusecurity
{
ExistHitPrevOAdapter::ExistHitPrevOAdapter(
int set,
const t* init,
const icat3::LBlockCollection& coll,
const CFGCollection& cfgs,
otawa::WorkSpace* ws) :
_mayManager(ws),
_domain(coll, set, init),
_graph(cfgs),
_store(_domain, _graph)
{
}
void ExistHitPrevOAdapter::update(const Bag<icache::Access>& accs, t& d)
{
for(int i = 0; i < accs.count(); i++) {
_domain.update(accs[i], d, _mayManager);
_mayManager.update(accs[i]);
}
}
void ExistHitPrevOAdapter::update(Block *v, t& d)
{
_domain.copy(d, _domain.bot());
t s;
// update and join along edges
for(auto e = _graph.preds(v); e; e++) {
Block *w = e->source();
_domain.copy(s, _store.get(w));
_mayManager.start(w);
// apply block
{
const Bag<icache::Access>& accs = icache::ACCESSES(w);
if(accs.count() > 0)
update(accs, s);
}
// apply edge
{
const Bag<icache::Access>& accs = icache::ACCESSES(e);
if(accs.count() > 0)
update(accs, s);
}
// merge result
_domain.join(d, s);
}
}
} // namespace lrusecurity
#include "ExistHitPrevOAnalysis.h"
#include <chrono>
#include <otawa/ai/ArrayStore.h>
#include <otawa/ai/SimpleAI.h>
#include <otawa/icache/features.h>
#include <otawa/icat3/features.h>
#include <lrusecurity/features.h>
#include "ExistHitPrevOAdapter.h"
#include "ExistHitPrevODomain.h"
using namespace otawa;
namespace lrusecurity
{
ExistHitPrevOAnalysis::ExistHitPrevOAnalysis(p::declare& r) :
Processor(r),
_initExistHitPrevO(nullptr),
_coll(nullptr),
_cfgs(nullptr)
{
}
void ExistHitPrevOAnalysis::configure(const PropList& props)
{
Processor::configure(props);
if(props.hasProp(EXIST_HIT_PREV_INIT))
_initExistHitPrevO = &EXIST_HIT_PREV_INIT(props);
}
void ExistHitPrevOAnalysis::setup(WorkSpace* ws)
{
_coll = icat3::LBLOCKS(ws);
ASSERT(_coll != nullptr);
_cfgs = INVOLVED_CFGS(ws);
ASSERT(_cfgs != nullptr);
}
void ExistHitPrevOAnalysis::processWorkSpace(WorkSpace* ws) //changer les ACS en ACSSecurity
{
auto start = std::chrono::system_clock::now();
// prepare containers
for(CFGCollection::BlockIter b(_cfgs); b; b++)
(*EXIST_HIT_PREV_IN(b)).configure(*_coll);
// compute ACS
for(int i = 0; i < _coll->cache()->setCount(); i++) {
if((*_coll)[i].count()) {
if(logFor(LOG_FUN))
log << "\tanalyzing set " << i << io::endl;
processSet(i, ws);
}
}
auto end = std::chrono::system_clock::now();
auto elapsed = std::chrono::duration_cast<std::chrono::seconds>(end - start);
if(logFor(LOG_FUN))
log << "\tExist Hit Prev Analysis running time: " << elapsed.count() << " s" << io::endl;
}
void ExistHitPrevOAnalysis::destroy(WorkSpace*)
{
for(CFGCollection::BlockIter b(_cfgs); b; b++)
EXIST_HIT_PREV_IN(b).remove();
}
void ExistHitPrevOAnalysis::processSet(int set, WorkSpace* ws)
{
// perform the analysis
ExistHitPrevOAdapter ada(set, _initExistHitPrevO ? &_initExistHitPrevO->get(set) : nullptr, *_coll, *_cfgs, ws);
ai::SimpleAI<ExistHitPrevOAdapter> ana(ada);
ana.run();
// store the results
for(CFGCollection::BlockIter b(_cfgs); b; b++)
if(b->isBasic()) {
ada.domain().copy((*EXIST_HIT_PREV_IN(b))[set], ada.store().get(b));
if(logFor(LOG_BLOCK))
log << "\t\t\t" << *b << ": " << ada.domain().print(ada.store().get(b)) << io::endl;
}
}
p::declare ExistHitPrevOAnalysis::reg = p::init("lrusecurity::ExistHitPrevOAnalysis", Version(1, 0, 0))
.require(icat3::LBLOCKS_FEATURE)
.require(COLLECTED_CFG_FEATURE)
.require(icat3::MUST_PERS_ANALYSIS_FEATURE)
.require(icat3::CATEGORY_FEATURE)
.require(lrumc::EXIST_HIT_ANALYSIS_FEATURE)
.provide(EXIST_HIT_PREV_O_ANALYSIS_FEATURE)
.make<ExistHitPrevOAnalysis>();
p::feature EXIST_HIT_PREV_O_ANALYSIS_FEATURE("lrusecurity::EXIST_HIT_PREV_ANALYSIS_O_FEATURE", p::make<ExistHitPrevOAnalysis>());
}; // namespace lrusecurity
#include "ExistHitPrevODomain.h"
using namespace otawa;
namespace lrusecurity
{
ExistHitPrevODomain::ExistHitPrevODomain(
const icat3::LBlockCollection& coll,
int set,
const t *init) :
_n(coll[set].count()),
_bot(_n),
_top(_n, Address(0x0)),//TO CHANGE
_set(set),
_coll(coll),
_A(coll.A()),
_init(init ? *init : _top),
_tmp(_n)
{
}
bool ExistHitPrevODomain::equals(const t& acss, const t& bcss) const
{
for (int i = 0; i < _n; i++)
if (acss[i] != bcss[i])
return false;
return true;
}
void ExistHitPrevODomain::join(t& dcss, const t& scss)
{
for (int i = 0; i < _n; i++){
int newsize = dcss[i].size()+scss[i].size();
Bag<Address> newbag = Bag<Address>(newsize);
for (int j = 0; j < newsize; j++) {
if (j < dcss[i].size())
newbag[j]=dcss[i][j];
else
newbag[j]=scss[i][j - dcss[i].size()];
}
dcss[i] = Bag<Address>(newbag);
}
}
void ExistHitPrevODomain::fetch(t& acss, const icache::Access& access, lrumc::ACSManager& mayManager)
{
icat3::LBlock *lb = icat3::LBLOCK(access);
int b = lb->index();
for (int i = 0; i < _n; i++){
if (i == b){
Address smol[] = {access.address()};
acss[i] = Bag<Address>(1,smol);}
else if (mayManager.mayAge(lb) == _A)
acss[i] = Bag<Address>();
}
}
void ExistHitPrevODomain::update(const icache::Access& access, t& a, lrumc::ACSManager& mayManager)
{
switch(access.kind()) {
case icache::FETCH:
if(_coll.cache()->set(access.address()) == _set)
fetch(a, access, mayManager);
break;
case icache::PREFETCH:
if(_coll.cache()->set(access.address()) == _set) {
copy(_tmp, a);
fetch(a, access, mayManager);
join(a, _tmp);
}
break;
case icache::NONE:
break;
default:
ASSERT(false);
}
}
} // namespace lrusecurity
......@@ -6,6 +6,7 @@
#include <otawa/proc/BBProcessor.h>
#include <otawa/prog/Process.h>
#include <lrumc/features.h>
#include "SecCFGOutput.h"
using namespace otawa;
namespace lrusecurity
......@@ -103,10 +104,6 @@ protected:
case otawa::icache::PREFETCH: _out << "PREFETCH\t"; break;
}
_out << "UNSAFE ";
if (lrumc::REFINEMENT_CATEGORY(*access) == lrumc::RefinementCategory::CLASSIFIED)
_out << "classified";
else
_out << "unclassified";
int set = otawa::icat3::LBLOCK(access)->set();
if (bb->hasProp(EXIST_HIT_PREV_IN)) {
ACSSecurity prev = (*EXIST_HIT_PREV_IN(bb))[set];
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment