blob: 494a153b05babe2ee767cec6fd2b548e89618c45 [file] [log] [blame]
Adrian McCarthydb2736d2018-01-09 23:49:30 +00001//===-- WinCFGuard.h - Windows Control Flow Guard Handling ----*- C++ -*--===//
2//
Chandler Carruth2946cd72019-01-19 08:50:56 +00003// 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
Adrian McCarthydb2736d2018-01-09 23:49:30 +00006//
7//===----------------------------------------------------------------------===//
8//
Andrew Paverdd157a9b2019-10-28 13:22:19 +00009// This file contains support for writing the metadata for Windows Control Flow
10// Guard, including address-taken functions, and valid longjmp targets.
Adrian McCarthydb2736d2018-01-09 23:49:30 +000011//
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_LIB_CODEGEN_ASMPRINTER_WINCFGUARD_H
15#define LLVM_LIB_CODEGEN_ASMPRINTER_WINCFGUARD_H
16
Yonghong Song61b189e2018-12-18 23:10:17 +000017#include "llvm/CodeGen/AsmPrinterHandler.h"
Adrian McCarthydb2736d2018-01-09 23:49:30 +000018#include "llvm/Support/Compiler.h"
Andrew Paverdd157a9b2019-10-28 13:22:19 +000019#include <vector>
Adrian McCarthydb2736d2018-01-09 23:49:30 +000020
21namespace llvm {
22
23class LLVM_LIBRARY_VISIBILITY WinCFGuard : public AsmPrinterHandler {
24 /// Target of directive emission.
25 AsmPrinter *Asm;
Andrew Paverdd157a9b2019-10-28 13:22:19 +000026 std::vector<const MCSymbol *> LongjmpTargets;
Adrian McCarthydb2736d2018-01-09 23:49:30 +000027
28public:
29 WinCFGuard(AsmPrinter *A);
30 ~WinCFGuard() override;
31
32 void setSymbolSize(const MCSymbol *Sym, uint64_t Size) override {}
33
Andrew Paverdd157a9b2019-10-28 13:22:19 +000034 /// Emit the Control Flow Guard function ID table.
Adrian McCarthydb2736d2018-01-09 23:49:30 +000035 void endModule() override;
36
Adrian Prantl5f8f34e42018-05-01 15:54:18 +000037 /// Gather pre-function debug information.
Adrian McCarthydb2736d2018-01-09 23:49:30 +000038 /// Every beginFunction(MF) call should be followed by an endFunction(MF)
39 /// call.
40 void beginFunction(const MachineFunction *MF) override {}
41
Adrian Prantl5f8f34e42018-05-01 15:54:18 +000042 /// Gather post-function debug information.
Adrian McCarthydb2736d2018-01-09 23:49:30 +000043 /// Please note that some AsmPrinter implementations may not call
44 /// beginFunction at all.
Andrew Paverdd157a9b2019-10-28 13:22:19 +000045 void endFunction(const MachineFunction *MF) override;
Adrian McCarthydb2736d2018-01-09 23:49:30 +000046
Adrian Prantl5f8f34e42018-05-01 15:54:18 +000047 /// Process beginning of an instruction.
Adrian McCarthydb2736d2018-01-09 23:49:30 +000048 void beginInstruction(const MachineInstr *MI) override {}
49
Adrian Prantl5f8f34e42018-05-01 15:54:18 +000050 /// Process end of an instruction.
Adrian McCarthydb2736d2018-01-09 23:49:30 +000051 void endInstruction() override {}
52};
53
54} // namespace llvm
55
56#endif