LLVM
23.0.0git
lib
Target
AArch64
MCTargetDesc
AArch64MCLFIRewriter.h
Go to the documentation of this file.
1
//===- AArch64MCLFIRewriter.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 AArch64MCLFIRewriter class, the AArch64 specific
10
// subclass of MCLFIRewriter.
11
//
12
//===----------------------------------------------------------------------===//
13
#ifndef LLVM_LIB_TARGET_AARCH64_MCTARGETDESC_AARCH64MCLFIREWRITER_H
14
#define LLVM_LIB_TARGET_AARCH64_MCTARGETDESC_AARCH64MCLFIREWRITER_H
15
16
#include "
llvm/MC/MCInstrInfo.h
"
17
#include "
llvm/MC/MCLFIRewriter.h
"
18
#include "
llvm/MC/MCRegister.h
"
19
#include "
llvm/MC/MCRegisterInfo.h
"
20
21
namespace
llvm
{
22
class
MCContext
;
23
class
MCInst
;
24
class
MCStreamer
;
25
class
MCSubtargetInfo
;
26
27
/// Rewrites AArch64 instructions for LFI sandboxing.
28
///
29
/// This class implements the LFI (Lightweight Fault Isolation) rewriting
30
/// for AArch64 instructions. It transforms instructions to ensure memory
31
/// accesses and control flow are confined within the sandbox region.
32
///
33
/// Reserved registers:
34
/// - X27: Sandbox base address (always holds the base)
35
/// - X28: Safe address register (always within sandbox)
36
/// - X26: Scratch register for intermediate calculations
37
/// - X25: context register (points to thread-local runtime data)
38
/// - SP: Stack pointer (always within sandbox)
39
/// - X30: Link register (always within sandbox)
40
class
AArch64MCLFIRewriter
:
public
MCLFIRewriter
{
41
public
:
42
AArch64MCLFIRewriter
(
MCContext
&Ctx, std::unique_ptr<MCRegisterInfo> &&RI,
43
std::unique_ptr<MCInstrInfo> &&
II
)
44
:
MCLFIRewriter
(Ctx,
std
::
move
(RI),
std
::
move
(
II
)) {}
45
46
bool
rewriteInst
(
const
MCInst
&Inst,
MCStreamer
&Out,
47
const
MCSubtargetInfo
&STI)
override
;
48
49
private
:
50
/// Recursion guard to prevent infinite loops when emitting instructions.
51
bool
Guard =
false
;
52
53
// Instruction classification. Returns the reserved register that may be
54
// modified, or an invalid register if no reserved register is touched.
55
MCRegister
mayModifyReserved(
const
MCInst
&Inst)
const
;
56
57
// Instruction emission.
58
void
emitInst(
const
MCInst
&Inst,
MCStreamer
&Out,
59
const
MCSubtargetInfo
&STI);
60
void
emitAddMask(
MCRegister
Dest,
MCRegister
Src,
MCStreamer
&Out,
61
const
MCSubtargetInfo
&STI);
62
void
emitBranch(
unsigned
Opcode,
MCRegister
Target
,
MCStreamer
&Out,
63
const
MCSubtargetInfo
&STI);
64
void
emitMov(
MCRegister
Dest,
MCRegister
Src,
MCStreamer
&Out,
65
const
MCSubtargetInfo
&STI);
66
67
// Rewriting logic.
68
void
doRewriteInst(
const
MCInst
&Inst,
MCStreamer
&Out,
69
const
MCSubtargetInfo
&STI);
70
71
// Control flow.
72
void
rewriteIndirectBranch(
const
MCInst
&Inst,
MCStreamer
&Out,
73
const
MCSubtargetInfo
&STI);
74
void
rewriteReturn(
const
MCInst
&Inst,
MCStreamer
&Out,
75
const
MCSubtargetInfo
&STI);
76
77
// Link register modification.
78
void
rewriteLRModification(
const
MCInst
&Inst,
MCStreamer
&Out,
79
const
MCSubtargetInfo
&STI);
80
81
// System instructions.
82
void
rewriteSyscall(
const
MCInst
&Inst,
MCStreamer
&Out,
83
const
MCSubtargetInfo
&STI);
84
void
rewriteTPRead(
const
MCInst
&Inst,
MCStreamer
&Out,
85
const
MCSubtargetInfo
&STI);
86
void
rewriteTPWrite(
const
MCInst
&Inst,
MCStreamer
&Out,
87
const
MCSubtargetInfo
&STI);
88
};
89
90
}
// namespace llvm
91
92
#endif
// LLVM_LIB_TARGET_AARCH64_MCTARGETDESC_AARCH64MCLFIREWRITER_H
MCInstrInfo.h
MCLFIRewriter.h
This file declares the MCLFIRewriter class, an abstract class that encapsulates the rewriting logic f...
MCRegisterInfo.h
MCRegister.h
II
uint64_t IntrinsicInst * II
Definition
NVVMIntrRange.cpp:46
llvm::AArch64MCLFIRewriter::AArch64MCLFIRewriter
AArch64MCLFIRewriter(MCContext &Ctx, std::unique_ptr< MCRegisterInfo > &&RI, std::unique_ptr< MCInstrInfo > &&II)
Definition
AArch64MCLFIRewriter.h:42
llvm::AArch64MCLFIRewriter::rewriteInst
bool rewriteInst(const MCInst &Inst, MCStreamer &Out, const MCSubtargetInfo &STI) override
Definition
AArch64MCLFIRewriter.cpp:259
llvm::MCContext
Context object for machine code objects.
Definition
MCContext.h:83
llvm::MCInst
Instances of this class represent a single low-level machine instruction.
Definition
MCInst.h:188
llvm::MCLFIRewriter::MCLFIRewriter
MCLFIRewriter(MCContext &Ctx, std::unique_ptr< MCRegisterInfo > &&RI, std::unique_ptr< MCInstrInfo > &&II)
Definition
MCLFIRewriter.h:40
llvm::MCRegister
Wrapper class representing physical registers. Should be passed by value.
Definition
MCRegister.h:41
llvm::MCStreamer
Streaming machine code generation interface.
Definition
MCStreamer.h:222
llvm::MCSubtargetInfo
Generic base class for all target subtargets.
Definition
MCSubtargetInfo.h:77
llvm::Target
Target - Wrapper for Target specific information.
Definition
TargetRegistry.h:148
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition
FunctionInfo.h:25
llvm::move
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
Definition
STLExtras.h:1916
std
Implement std::hash so that hash_code can be used in STL containers.
Definition
BitVector.h:874
Generated on
for LLVM by
1.14.0