Insert random noops to increase security against ROP attacks (llvm)
[oota-llvm.git] / include / llvm / CodeGen / NoopInsertion.h
1 //===-- NoopInsertion.h - Noop Insertion ------------------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This pass adds fine-grained diversity by displacing code using randomly
11 // placed (optionally target supplied) Noop instructions.
12 //
13 //===----------------------------------------------------------------------===//
14
15 #ifndef LLVM_CODEGEN_NOOPINSERTION_H
16 #define LLVM_CODEGEN_NOOPINSERTION_H
17
18 #include "llvm/CodeGen/MachineFunctionPass.h"
19 #include <random>
20
21 namespace llvm {
22
23 class RandomNumberGenerator;
24
25 class NoopInsertion : public MachineFunctionPass {
26 public:
27   static char ID;
28
29   NoopInsertion();
30
31 private:
32   bool runOnMachineFunction(MachineFunction &MF) override;
33
34   void getAnalysisUsage(AnalysisUsage &AU) const override;
35
36   std::unique_ptr<RandomNumberGenerator> RNG;
37
38   // Uniform real distribution from 0 to 100
39   std::uniform_real_distribution<double> Distribution =
40       std::uniform_real_distribution<double>(0, 100);
41 };
42 }
43
44 #endif // LLVM_CODEGEN_NOOPINSERTION_H