1 //===--------- EHFrameSupport.h - JITLink eh-frame utils --------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 // EHFrame registration support for JITLink.
11 //===----------------------------------------------------------------------===//
13 #ifndef LLVM_EXECUTIONENGINE_JITLINK_EHFRAMESUPPORT_H
14 #define LLVM_EXECUTIONENGINE_JITLINK_EHFRAMESUPPORT_H
16 #include "llvm/ADT/Triple.h"
17 #include "llvm/ExecutionEngine/JITLink/JITLink.h"
18 #include "llvm/ExecutionEngine/JITSymbol.h"
19 #include "llvm/Support/Error.h"
24 /// Registers all FDEs in the given eh-frame section with the current process.
25 Error
registerEHFrameSection(const void *EHFrameSectionAddr
,
26 size_t EHFrameSectionSize
);
28 /// Deregisters all FDEs in the given eh-frame section with the current process.
29 Error
deregisterEHFrameSection(const void *EHFrameSectionAddr
,
30 size_t EHFrameSectionSize
);
32 /// Supports registration/deregistration of EH-frames in a target process.
33 class EHFrameRegistrar
{
35 virtual ~EHFrameRegistrar();
36 virtual Error
registerEHFrames(JITTargetAddress EHFrameSectionAddr
,
37 size_t EHFrameSectionSize
) = 0;
38 virtual Error
deregisterEHFrames(JITTargetAddress EHFrameSectionAddr
,
39 size_t EHFrameSectionSize
) = 0;
42 /// Registers / Deregisters EH-frames in the current process.
43 class InProcessEHFrameRegistrar final
: public EHFrameRegistrar
{
45 /// Get a reference to the InProcessEHFrameRegistrar singleton.
46 static InProcessEHFrameRegistrar
&getInstance();
48 InProcessEHFrameRegistrar(const InProcessEHFrameRegistrar
&) = delete;
49 InProcessEHFrameRegistrar
&
50 operator=(const InProcessEHFrameRegistrar
&) = delete;
52 InProcessEHFrameRegistrar(InProcessEHFrameRegistrar
&&) = delete;
53 InProcessEHFrameRegistrar
&operator=(InProcessEHFrameRegistrar
&&) = delete;
55 Error
registerEHFrames(JITTargetAddress EHFrameSectionAddr
,
56 size_t EHFrameSectionSize
) override
{
57 return registerEHFrameSection(
58 jitTargetAddressToPointer
<void *>(EHFrameSectionAddr
),
62 Error
deregisterEHFrames(JITTargetAddress EHFrameSectionAddr
,
63 size_t EHFrameSectionSize
) override
{
64 return deregisterEHFrameSection(
65 jitTargetAddressToPointer
<void *>(EHFrameSectionAddr
),
70 InProcessEHFrameRegistrar();
73 using StoreFrameRangeFunction
=
74 std::function
<void(JITTargetAddress EHFrameSectionAddr
,
75 size_t EHFrameSectionSize
)>;
77 /// Creates a pass that records the address and size of the EH frame section.
78 /// If no eh-frame section is found then the address and size will both be given
81 /// Authors of JITLinkContexts can use this function to register a post-fixup
82 /// pass that records the range of the eh-frame section. This range can
83 /// be used after finalization to register and deregister the frame.
85 createEHFrameRecorderPass(const Triple
&TT
,
86 StoreFrameRangeFunction StoreFrameRange
);
88 } // end namespace jitlink
89 } // end namespace llvm
91 #endif // LLVM_EXECUTIONENGINE_JITLINK_EHFRAMESUPPORT_H