Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:43:52

0001 //===--- UnwindInfoManager.h -- Register unwind info sections ---*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 //
0009 // Utilities for managing eh-frame and compact-unwind registration and lookup
0010 // through libunwind's find_dynamic_unwind_sections mechanism.
0011 //
0012 //===----------------------------------------------------------------------===//
0013 
0014 #ifndef LLVM_EXECUTIONENGINE_ORC_TARGETPROCESS_UNWINDINFOMANAGER_H
0015 #define LLVM_EXECUTIONENGINE_ORC_TARGETPROCESS_UNWINDINFOMANAGER_H
0016 
0017 #include "llvm/ExecutionEngine/Orc/Shared/ExecutorAddress.h"
0018 #include "llvm/Support/Error.h"
0019 #include <map>
0020 #include <mutex>
0021 
0022 namespace llvm::orc {
0023 
0024 class UnwindInfoManager {
0025 public:
0026   // This struct's layout should match the unw_dynamic_unwind_sections struct
0027   // from libunwind/src/libunwid_ext.h.
0028   struct UnwindSections {
0029     uintptr_t dso_base;
0030     uintptr_t dwarf_section;
0031     size_t dwarf_section_length;
0032     uintptr_t compact_unwind_section;
0033     size_t compact_unwind_section_length;
0034   };
0035 
0036   UnwindInfoManager(UnwindInfoManager &&) = delete;
0037   UnwindInfoManager &operator=(UnwindInfoManager &&) = delete;
0038   ~UnwindInfoManager();
0039 
0040   /// If the libunwind find-dynamic-unwind-info callback registration APIs are
0041   /// available then this method will instantiate a global UnwindInfoManager
0042   /// instance suitable for the process and return true. Otherwise it will
0043   /// return false.
0044   static bool TryEnable();
0045 
0046   static void addBootstrapSymbols(StringMap<ExecutorAddr> &M);
0047 
0048   static Error registerSections(ArrayRef<orc::ExecutorAddrRange> CodeRanges,
0049                                 orc::ExecutorAddr DSOBase,
0050                                 orc::ExecutorAddrRange DWARFEHFrame,
0051                                 orc::ExecutorAddrRange CompactUnwind);
0052 
0053   static Error deregisterSections(ArrayRef<orc::ExecutorAddrRange> CodeRanges);
0054 
0055 private:
0056   UnwindInfoManager() = default;
0057 
0058   int findSectionsImpl(uintptr_t Addr, UnwindSections *Info);
0059   static int findSections(uintptr_t Addr, UnwindSections *Info);
0060 
0061   Error registerSectionsImpl(ArrayRef<orc::ExecutorAddrRange> CodeRanges,
0062                              orc::ExecutorAddr DSOBase,
0063                              orc::ExecutorAddrRange DWARFEHFrame,
0064                              orc::ExecutorAddrRange CompactUnwind);
0065 
0066   Error deregisterSectionsImpl(ArrayRef<orc::ExecutorAddrRange> CodeRanges);
0067 
0068   std::mutex M;
0069   std::map<uintptr_t, UnwindSections> UWSecs;
0070 };
0071 
0072 } // namespace llvm::orc
0073 
0074 #endif // LLVM_EXECUTIONENGINE_ORC_TARGETPROCESS_UNWINDINFOMANAGER_H