1 //===-- llvm/CodeGen/ReturnProtectorLowering.h ------------------*- 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 // A class to insert and lower the return protector instrumentation 11 // 12 //===----------------------------------------------------------------------===// 13 14 #ifndef LLVM_CODEGEN_RETURNPROTECTORLOWERING_H 15 #define LLVM_CODEGEN_RETURNPROTECTORLOWERING_H 16 17 #include "llvm/ADT/SmallVector.h" 18 19 #include <utility> 20 #include <vector> 21 22 namespace llvm { 23 class CalleeSavedInfo; 24 class GlobalVariable; 25 class MachineBasicBlock; 26 class MachineFunction; 27 class MachineInstr; 28 29 class ReturnProtectorLowering { 30 public: ~ReturnProtectorLowering()31 virtual ~ReturnProtectorLowering() {} 32 /// Subclass interface - subclasses need to implement these functions. 33 34 /// insertReturnProtectorPrologue/Epilogue - insert return protector 35 /// instrumentation in prologue or epilogue. insertReturnProtectorPrologue(MachineFunction & MF,MachineBasicBlock & MBB,GlobalVariable * cookie)36 virtual void insertReturnProtectorPrologue(MachineFunction &MF, 37 MachineBasicBlock &MBB, 38 GlobalVariable *cookie) const {} insertReturnProtectorEpilogue(MachineFunction & MF,MachineInstr & MI,GlobalVariable * cookie)39 virtual void insertReturnProtectorEpilogue(MachineFunction &MF, 40 MachineInstr &MI, 41 GlobalVariable *cookie) const {} 42 43 /// opcodeIsReturn - Reuturn true is the given opcode is a return 44 /// instruction needing return protection, false otherwise. opcodeIsReturn(unsigned opcode)45 virtual bool opcodeIsReturn(unsigned opcode) const { return false; } 46 47 /// fillTempRegisters - Fill the list of available temp registers we can 48 /// use as a CalculationRegister. fillTempRegisters(MachineFunction & MF,std::vector<unsigned> & TempRegs)49 virtual void fillTempRegisters(MachineFunction &MF, 50 std::vector<unsigned> &TempRegs) const {} 51 52 /// Generic public interface used by llvm 53 54 /// setupReturnProtector - Checks the function for ROP friendly return 55 /// instructions and sets ReturnProtectorNeeded in the frame if found. 56 virtual void setupReturnProtector(MachineFunction &MF) const; 57 58 /// saveReturnProtectorRegister - Allows the target to save the 59 /// CalculationRegister in the CalleeSavedInfo vector if needed. 60 virtual void 61 saveReturnProtectorRegister(MachineFunction &MF, 62 std::vector<CalleeSavedInfo> &CSI) const; 63 64 /// determineReturnProtectorTempRegister - Find a register that can be used 65 /// during function prologue / epilogue to store the return protector cookie. 66 /// Returns false if a register is needed but could not be found, 67 /// otherwise returns true. 68 virtual bool determineReturnProtectorRegister( 69 MachineFunction &MF, 70 const SmallVector<MachineBasicBlock *, 4> &SaveBlocks, 71 const SmallVector<MachineBasicBlock *, 4> &RestoreBlocks) const; 72 73 /// insertReturnProtectors - insert return protector instrumentation. 74 virtual void insertReturnProtectors(MachineFunction &MF) const; 75 }; 76 77 } // namespace llvm 78 79 #endif 80