| 1 | //===- X86MCLFIRewriter.h ---------------------------------------*- 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 | // |
| 9 | // This file declares the X86MCLFIRewriter class, the X86 specific |
| 10 | // subclass of MCLFIRewriter. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | #ifndef LLVM_LIB_TARGET_X86_MCTARGETDESC_X86MCLFIREWRITER_H |
| 14 | #define LLVM_LIB_TARGET_X86_MCTARGETDESC_X86MCLFIREWRITER_H |
| 15 | |
| 16 | #include "llvm/MC/MCInstrInfo.h" |
| 17 | #include "llvm/MC/MCLFIRewriter.h" |
| 18 | #include "llvm/MC/MCRegisterInfo.h" |
| 19 | |
| 20 | namespace llvm { |
| 21 | class MCContext; |
| 22 | class MCInst; |
| 23 | class MCStreamer; |
| 24 | class MCSubtargetInfo; |
| 25 | |
| 26 | namespace X86 { |
| 27 | |
| 28 | constexpr unsigned LFIBundleSize = 32; |
| 29 | |
| 30 | class X86MCLFIRewriter : public MCLFIRewriter { |
| 31 | public: |
| 32 | X86MCLFIRewriter(MCContext &Ctx, std::unique_ptr<MCRegisterInfo> &&RI, |
| 33 | std::unique_ptr<MCInstrInfo> &&II) |
| 34 | : MCLFIRewriter(Ctx, std::move(RI), std::move(II)) {} |
| 35 | |
| 36 | bool rewriteInst(const MCInst &Inst, MCStreamer &Out, |
| 37 | const MCSubtargetInfo &STI) override; |
| 38 | |
| 39 | private: |
| 40 | /// Recursion guard to prevent infinite loops when emitting instructions. |
| 41 | bool Guard = false; |
| 42 | |
| 43 | void doRewriteInst(const MCInst &Inst, MCStreamer &Out, |
| 44 | const MCSubtargetInfo &STI); |
| 45 | |
| 46 | void rewriteSyscall(const MCInst &Inst, MCStreamer &Out, |
| 47 | const MCSubtargetInfo &STI); |
| 48 | |
| 49 | /// Emit the mask sequence that turns an arbitrary value in Reg into a |
| 50 | /// bundle-aligned address inside the sandbox. |
| 51 | void emitSandboxBranchReg(MCRegister Reg, MCStreamer &Out, |
| 52 | const MCSubtargetInfo &STI); |
| 53 | |
| 54 | void rewriteIndirectBranch(const MCInst &Inst, MCStreamer &Out, |
| 55 | const MCSubtargetInfo &STI); |
| 56 | void rewriteDirectCall(const MCInst &Inst, MCStreamer &Out, |
| 57 | const MCSubtargetInfo &STI); |
| 58 | void rewriteReturn(const MCInst &Inst, MCStreamer &Out, |
| 59 | const MCSubtargetInfo &STI); |
| 60 | |
| 61 | bool isFSAccess(const MCInst &Inst); |
| 62 | void rewriteFSAccess(const MCInst &Inst, MCStreamer &Out, |
| 63 | const MCSubtargetInfo &STI); |
| 64 | }; |
| 65 | |
| 66 | } // namespace X86 |
| 67 | } // namespace llvm |
| 68 | #endif // LLVM_LIB_TARGET_X86_MCTARGETDESC_X86MCLFIREWRITER_H |
| 69 | |