|
30 | 30 | #include "llvm/IR/Instructions.h" |
31 | 31 | #include "llvm/IR/IRBuilder.h" |
32 | 32 | #include "llvm/IR/Attributes.h" |
33 | | -#include "llvm/Pass.h" |
| 33 | +#include "llvm/IR/PassManager.h" |
| 34 | +#include "llvm/Passes/PassBuilder.h" |
| 35 | +#include "llvm/Passes/PassPlugin.h" |
34 | 36 | #include "llvm/Support/raw_ostream.h" |
35 | 37 | #include "llvm/Support/JSON.h" |
| 38 | +#include "llvm/ADT/SmallVector.h" |
36 | 39 | #include <unordered_map> |
37 | 40 | #include <unordered_set> |
38 | 41 | #include <string> |
@@ -78,6 +81,15 @@ std::string classificationToString(ClassificationLevel Level) { |
78 | 81 | } |
79 | 82 | } |
80 | 83 |
|
| 84 | +struct PairHash { |
| 85 | + template <class T1, class T2> |
| 86 | + std::size_t operator()(const std::pair<T1, T2> &p) const { |
| 87 | + auto h1 = std::hash<T1>{}(p.first); |
| 88 | + auto h2 = std::hash<T2>{}(p.second); |
| 89 | + return h1 ^ (h2 << 1); |
| 90 | + } |
| 91 | +}; |
| 92 | + |
81 | 93 | // Cross-domain transition record |
82 | 94 | struct CrossDomainTransition { |
83 | 95 | Function *Caller; |
@@ -107,15 +119,6 @@ class DsmilCrossDomainPass : public PassInfoMixin<DsmilCrossDomainPass> { |
107 | 119 | unsigned NumUnsafeCalls = 0; |
108 | 120 | unsigned NumGuardsInserted = 0; |
109 | 121 |
|
110 | | - struct PairHash { |
111 | | - template <class T1, class T2> |
112 | | - std::size_t operator()(const std::pair<T1, T2> &p) const { |
113 | | - auto h1 = std::hash<T1>{}(p.first); |
114 | | - auto h2 = std::hash<T2>{}(p.second); |
115 | | - return h1 ^ (h2 << 1); |
116 | | - } |
117 | | - }; |
118 | | - |
119 | 122 | public: |
120 | 123 | PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM); |
121 | 124 |
|
@@ -322,15 +325,16 @@ bool DsmilCrossDomainPass::insertCrossDomainGuards(Module &M) { |
322 | 325 | bool Modified = false; |
323 | 326 |
|
324 | 327 | // Get or create guard runtime function |
325 | | - FunctionType *GuardFT = FunctionType::get( |
326 | | - Type::getInt32Ty(M.getContext()), |
327 | | - {Type::getInt8PtrTy(M.getContext()), // data |
328 | | - Type::getInt64Ty(M.getContext()), // length |
329 | | - Type::getInt8PtrTy(M.getContext()), // from_level |
330 | | - Type::getInt8PtrTy(M.getContext()), // to_level |
331 | | - Type::getInt8PtrTy(M.getContext())}, // policy |
332 | | - false |
333 | | - ); |
| 328 | + auto *I8Ptr = PointerType::get(Type::getInt8Ty(M.getContext()), 0); |
| 329 | + SmallVector<Type *, 5> ParamTys{ |
| 330 | + I8Ptr, // data |
| 331 | + Type::getInt64Ty(M.getContext()), // length |
| 332 | + I8Ptr, // from_level |
| 333 | + I8Ptr, // to_level |
| 334 | + I8Ptr // policy |
| 335 | + }; |
| 336 | + FunctionType *GuardFT = |
| 337 | + FunctionType::get(Type::getInt32Ty(M.getContext()), ParamTys, false); |
334 | 338 |
|
335 | 339 | FunctionCallee GuardFunc = M.getOrInsertFunction( |
336 | 340 | "dsmil_cross_domain_guard", GuardFT); |
|
0 commit comments