1 //===--------- EHFrameSupport.h - JITLink eh-frame utils --------*- 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 // EHFrame registration support for JITLink.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #ifndef LLVM_EXECUTIONENGINE_JITLINK_EHFRAMESUPPORT_H
14 #define LLVM_EXECUTIONENGINE_JITLINK_EHFRAMESUPPORT_H
15 
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"
20 
21 namespace llvm {
22 namespace jitlink {
23 
24 /// Supports registration/deregistration of EH-frames in a target process.
25 class EHFrameRegistrar {
26 public:
27   virtual ~EHFrameRegistrar();
28   virtual Error registerEHFrames(JITTargetAddress EHFrameSectionAddr,
29                                  size_t EHFrameSectionSize) = 0;
30   virtual Error deregisterEHFrames(JITTargetAddress EHFrameSectionAddr,
31                                    size_t EHFrameSectionSize) = 0;
32 };
33 
34 /// Registers / Deregisters EH-frames in the current process.
35 class InProcessEHFrameRegistrar final : public EHFrameRegistrar {
36 public:
37   Error registerEHFrames(JITTargetAddress EHFrameSectionAddr,
38                          size_t EHFrameSectionSize) override;
39 
40   Error deregisterEHFrames(JITTargetAddress EHFrameSectionAddr,
41                            size_t EHFrameSectionSize) override;
42 };
43 
44 using StoreFrameRangeFunction =
45   std::function<void(JITTargetAddress EHFrameSectionAddr,
46                      size_t EHFrameSectionSize)>;
47 
48 /// Creates a pass that records the address and size of the EH frame section.
49 /// If no eh-frame section is found then the address and size will both be given
50 /// as zero.
51 ///
52 /// Authors of JITLinkContexts can use this function to register a post-fixup
53 /// pass that records the range of the eh-frame section. This range can
54 /// be used after finalization to register and deregister the frame.
55 LinkGraphPassFunction
56 createEHFrameRecorderPass(const Triple &TT,
57                           StoreFrameRangeFunction StoreFrameRange);
58 
59 } // end namespace jitlink
60 } // end namespace llvm
61 
62 #endif // LLVM_EXECUTIONENGINE_JITLINK_EHFRAMESUPPORT_H
63