1 //===-- CFGuard.h - CFGuard Transformations ---------------------*- C++ -*-===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===---------------------------------------------------------------------===// 8 // Windows Control Flow Guard passes (/guard:cf). 9 //===---------------------------------------------------------------------===// 10 11 #ifndef LLVM_TRANSFORMS_CFGUARD_H 12 #define LLVM_TRANSFORMS_CFGUARD_H 13 14 #include "llvm/IR/PassManager.h" 15 16 namespace llvm { 17 18 class FunctionPass; 19 class GlobalValue; 20 21 class CFGuardPass : public PassInfoMixin<CFGuardPass> { 22 public: 23 enum class Mechanism { Check, Dispatch }; 24 GuardMechanism(M)25 CFGuardPass(Mechanism M = Mechanism::Check) : GuardMechanism(M) {} 26 PreservedAnalyses run(Function &F, FunctionAnalysisManager &FAM); 27 28 private: 29 Mechanism GuardMechanism; 30 }; 31 32 /// Insert Control FLow Guard checks on indirect function calls. 33 FunctionPass *createCFGuardCheckPass(); 34 35 /// Insert Control FLow Guard dispatches on indirect function calls. 36 FunctionPass *createCFGuardDispatchPass(); 37 38 bool isCFGuardFunction(const GlobalValue *GV); 39 40 } // namespace llvm 41 42 #endif 43