Skip to content

Commit 9467220

Browse files
refactor(ASPISValues): Enhanced ASPIS values
- Created `ASPISValue` to store original and duplicate of a generic `llvm::Value` - Create the specialization `ASPISGLobalVariable` - Create the specialization `ASPISInstr` - Now the passes can be built
1 parent fdffa7b commit 9467220

7 files changed

Lines changed: 267 additions & 215 deletions

File tree

passes/ASPIS.h

Lines changed: 129 additions & 127 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
1-
#ifndef ASPIS_H
2-
#define ASPIS_H
1+
#pragma once
32

4-
#include "llvm/IR/PassManager.h"
5-
#include "llvm/IR/IRBuilder.h"
6-
#include "llvm/Pass.h"
73
#include <llvm/IR/Instructions.h>
4+
85
#include <map>
96
#include <set>
10-
#include "Duplication/ASPISInstr.h"
7+
8+
#include "Duplication/ASPISValues.h"
9+
#include "llvm/IR/IRBuilder.h"
10+
#include "llvm/IR/PassManager.h"
11+
#include "llvm/Pass.h"
1112

1213
using namespace llvm;
1314

1415
/**
1516
* - 0: Disabled
1617
* - 1: Enabled
17-
*/
18+
*/
1819
#define LOG_COMPILED_FUNCS 1
1920

2021
// DATA PROTECTION
@@ -29,67 +30,70 @@ using namespace llvm;
2930
static bool isRequired() { return true; }
3031
}; */
3132

32-
class EDDI : public PassInfoMixin<EDDI> {
33-
private:
34-
std::set<Value*> SphereOfReplication;
35-
std::set<Value*> SphereOfDuplication;
36-
std::set<Value*> SphereOfExclusion;
37-
38-
std::map<Value*,ASPISInstr*> ValuesToASPISInstr;
39-
40-
BasicBlock *ErrBB;
41-
42-
/**
43-
* This function performs the following operations:
44-
* - Resolves aliases.
45-
* - Gathers annotations.
46-
* - Defines spheres.
47-
*/
48-
void PreprocessModule(Module &Md);
49-
50-
/**
51-
* Transforms functions with a return value into functions where the return
52-
* value is passed by reference as a parameter.
53-
*/
54-
void FuncRetToRef(Module &Md);
55-
56-
/**
57-
* Duplicates the global variables of the module in the SOR.
58-
*/
59-
void DuplicateGlobals(Module &Md);
60-
61-
/**
62-
* Creates the signatures for the _dup functions in the SOR.
63-
*/
64-
void CreateDupFunctions(Module &Md);
65-
66-
/**
67-
* Create the skeleton of the ErrBB.
68-
*/
69-
void CreateErrBB(Module &Md);
33+
class ASPISValue;
7034

71-
public:
72-
std::set<Value*> *getSOR() {return &SphereOfReplication;}
73-
std::set<Value*> *getSOD() {return &SphereOfReplication;}
74-
std::set<Value*> *getSOE() {return &SphereOfExclusion;}
75-
std::map<Value*, ASPISInstr*> *getValuesToASPISInstr() {return &ValuesToASPISInstr;}
76-
BasicBlock *getErrBB() {return ErrBB;}
77-
78-
79-
PreservedAnalyses run(Module &M,
80-
ModuleAnalysisManager &);
81-
82-
static bool isRequired() { return true; }
35+
class EDDI : public PassInfoMixin<EDDI> {
36+
private:
37+
std::set<Value *> SphereOfReplication;
38+
std::set<Value *> SphereOfDuplication;
39+
std::set<Value *> SphereOfExclusion;
40+
41+
std::map<Value *, ASPISValue *> ValuesToASPISValues;
42+
43+
BasicBlock *ErrBB;
44+
45+
/**
46+
* This function performs the following operations:
47+
* - Resolves aliases.
48+
* - Gathers annotations.
49+
* - Defines spheres.
50+
*/
51+
void PreprocessModule(Module &Md);
52+
53+
/**
54+
* Transforms functions with a return value into functions where the return
55+
* value is passed by reference as a parameter.
56+
*/
57+
void FuncRetToRef(Module &Md);
58+
59+
/**
60+
* Duplicates the global variables of the module in the SOR.
61+
*/
62+
void DuplicateGlobals(Module &Md);
63+
64+
/**
65+
* Creates the signatures for the _dup functions in the SOR.
66+
*/
67+
void CreateDupFunctions(Module &Md);
68+
69+
/**
70+
* Create the skeleton of the ErrBB.
71+
*/
72+
void CreateErrBB(Module &Md);
73+
74+
public:
75+
const std::set<Value *> *getSOR() const { return &SphereOfReplication; }
76+
const std::set<Value *> *getSOD() const { return &SphereOfReplication; }
77+
const std::set<Value *> *getSOE() const { return &SphereOfExclusion; }
78+
const std::map<Value *, ASPISValue *> *getValuesToASPISValues() const {
79+
return &ValuesToASPISValues;
80+
}
81+
const BasicBlock *getErrBB() const { return ErrBB; }
82+
83+
PreservedAnalyses run(Module &M, ModuleAnalysisManager &);
84+
85+
static bool isRequired() { return true; }
8386
};
8487

8588
/* class DuplicateGlobals : public PassInfoMixin<DuplicateGlobals> {
86-
private:
89+
private:
8790
std::map<GlobalVariable*, GlobalVariable*> DuplicatedGlobals;
8891
89-
void getFunctionsToNotModify(std::string Filename, std::set<std::string> &FunctionsToNotModify);
90-
GlobalVariable* getDuplicatedGlobal(Module &Md, GlobalVariable &GV);
91-
void duplicateCall(Module &Md, CallBase* UCall, Value* Original, Value* Copy);
92-
void replaceCallsWithOriginalCalls(Module &Md, std::set<std::string> &FunctionsToNotModify);
92+
void getFunctionsToNotModify(std::string Filename, std::set<std::string>
93+
&FunctionsToNotModify); GlobalVariable* getDuplicatedGlobal(Module &Md,
94+
GlobalVariable &GV); void duplicateCall(Module &Md, CallBase* UCall, Value*
95+
Original, Value* Copy); void replaceCallsWithOriginalCalls(Module &Md,
96+
std::set<std::string> &FunctionsToNotModify);
9397
9498
public:
9599
PreservedAnalyses run(Module &M,
@@ -99,82 +103,80 @@ class EDDI : public PassInfoMixin<EDDI> {
99103
}; */
100104

101105
class ASPISCheckProfiler : public PassInfoMixin<ASPISCheckProfiler> {
102-
private:
103-
std::map<Value*, StringRef> FuncAnnotations;
106+
private:
107+
std::map<Value *, StringRef> FuncAnnotations;
104108

105-
public:
106-
PreservedAnalyses run(Module &M,
107-
ModuleAnalysisManager &);
109+
public:
110+
PreservedAnalyses run(Module &M, ModuleAnalysisManager &);
108111

109-
static bool isRequired() { return true; }
112+
static bool isRequired() { return true; }
110113
};
111114

115+
class ASPISInsertCheckProfiler
116+
: public PassInfoMixin<ASPISInsertCheckProfiler> {
117+
private:
118+
std::map<Value *, StringRef> FuncAnnotations;
112119

113-
class ASPISInsertCheckProfiler : public PassInfoMixin<ASPISInsertCheckProfiler> {
114-
private:
115-
std::map<Value*, StringRef> FuncAnnotations;
116-
117-
public:
118-
PreservedAnalyses run(Module &M,
119-
ModuleAnalysisManager &);
120+
public:
121+
PreservedAnalyses run(Module &M, ModuleAnalysisManager &);
120122

121-
static bool isRequired() { return true; }
123+
static bool isRequired() { return true; }
122124
};
123125

124126
// CONTROL-FLOW CHECKING
125127
class CFCSS : public PassInfoMixin<CFCSS> {
126-
private:
127-
std::map<Value*, StringRef> FuncAnnotations;
128-
129-
#if (LOG_COMPILED_FUNCS == 1)
130-
std::set<Function*> CompiledFuncs;
131-
#endif
132-
133-
void initializeBlocksSignatures(Module &Md, std::map<BasicBlock*, int> &BBSigs);
134-
BasicBlock* getFirstPredecessor(BasicBlock &BB, const std::map<BasicBlock*, int> &BBSigs);
135-
int getNeighborSig(BasicBlock &BB, const std::map<BasicBlock*, int> &BBSigs);
136-
bool hasNPredecessorsOrMore(BasicBlock &BB, int N, const std::map<BasicBlock*, int> &BBSigs);
137-
void sortBasicBlocks(const std::map<BasicBlock *, int> &BBSigs, const std::map<int, BasicBlock *> &NewBBs, const std::map<Function*, BasicBlock*> &FuncErrBBs);
138-
void createCFGVerificationBB (BasicBlock &BB,
139-
const std::map<BasicBlock *, int> &BBSigs,
140-
std::map<int, BasicBlock *> *NewBBs,
141-
BasicBlock &ErrBB,
142-
Value *G, Value *D);
143-
144-
public:
145-
PreservedAnalyses run(Module &M,
146-
ModuleAnalysisManager &);
147-
148-
static bool isRequired() { return true; }
128+
private:
129+
std::map<Value *, StringRef> FuncAnnotations;
130+
131+
#if (LOG_COMPILED_FUNCS == 1)
132+
std::set<Function *> CompiledFuncs;
133+
#endif
134+
135+
void initializeBlocksSignatures(Module &Md,
136+
std::map<BasicBlock *, int> &BBSigs);
137+
BasicBlock *getFirstPredecessor(BasicBlock &BB,
138+
const std::map<BasicBlock *, int> &BBSigs);
139+
int getNeighborSig(BasicBlock &BB, const std::map<BasicBlock *, int> &BBSigs);
140+
bool hasNPredecessorsOrMore(BasicBlock &BB, int N,
141+
const std::map<BasicBlock *, int> &BBSigs);
142+
void sortBasicBlocks(const std::map<BasicBlock *, int> &BBSigs,
143+
const std::map<int, BasicBlock *> &NewBBs,
144+
const std::map<Function *, BasicBlock *> &FuncErrBBs);
145+
void createCFGVerificationBB(BasicBlock &BB,
146+
const std::map<BasicBlock *, int> &BBSigs,
147+
std::map<int, BasicBlock *> *NewBBs,
148+
BasicBlock &ErrBB, Value *G, Value *D);
149+
150+
public:
151+
PreservedAnalyses run(Module &M, ModuleAnalysisManager &);
152+
153+
static bool isRequired() { return true; }
149154
};
150155

151156
class RASM : public PassInfoMixin<RASM> {
152-
private:
153-
std::map<Value*, StringRef> FuncAnnotations;
154-
std::map<BasicBlock*, BasicBlock*> NewBBs;
155-
156-
#if (LOG_COMPILED_FUNCS == 1)
157-
std::set<Function*> CompiledFuncs;
158-
#endif
159-
160-
void initializeBlocksSignatures(Module &Md, std::map<BasicBlock*, int> &RandomNumberBBs, std::map<BasicBlock*, int> &SubRanPrevVals);
161-
void splitBBsAtCalls(Module &Md);
162-
CallBase *isCallBB (BasicBlock &BB);
163-
void initializeEntryBlocksMap(Module &Md);
164-
Value *getCondition(Instruction &I);
165-
void createCFGVerificationBB ( BasicBlock &BB,
166-
std::map<BasicBlock*, int> &RandomNumberBBs,
167-
std::map<BasicBlock*, int> &SubRanPrevVals,
168-
Value &RuntimeSig,
169-
Value &RetSig,
170-
BasicBlock &ErrBB);
171-
172-
public:
173-
PreservedAnalyses run(Module &M,
174-
ModuleAnalysisManager &);
175-
176-
static bool isRequired() { return true; }
177-
157+
private:
158+
std::map<Value *, StringRef> FuncAnnotations;
159+
std::map<BasicBlock *, BasicBlock *> NewBBs;
160+
161+
#if (LOG_COMPILED_FUNCS == 1)
162+
std::set<Function *> CompiledFuncs;
163+
#endif
164+
165+
void initializeBlocksSignatures(Module &Md,
166+
std::map<BasicBlock *, int> &RandomNumberBBs,
167+
std::map<BasicBlock *, int> &SubRanPrevVals);
168+
void splitBBsAtCalls(Module &Md);
169+
CallBase *isCallBB(BasicBlock &BB);
170+
void initializeEntryBlocksMap(Module &Md);
171+
Value *getCondition(Instruction &I);
172+
void createCFGVerificationBB(BasicBlock &BB,
173+
std::map<BasicBlock *, int> &RandomNumberBBs,
174+
std::map<BasicBlock *, int> &SubRanPrevVals,
175+
Value &RuntimeSig, Value &RetSig,
176+
BasicBlock &ErrBB);
177+
178+
public:
179+
PreservedAnalyses run(Module &M, ModuleAnalysisManager &);
180+
181+
static bool isRequired() { return true; }
178182
};
179-
180-
#endif

passes/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ add_subdirectory(Utils Utils)
33
# DataProtection
44
add_library(DataProtection SHARED
55
EDDI.cpp
6-
Duplication/ASPISInstr.cpp
6+
Duplication/ASPISValues.cpp
77
Utils/Utils.cpp
88
)
99

passes/Duplication/ASPISInstr.h

Lines changed: 0 additions & 51 deletions
This file was deleted.

0 commit comments

Comments
 (0)