| 1 | //===- elfnix_platform.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 | // ORC Runtime support for dynamic loading features on ELF-based platforms. |
| 10 | // |
| 11 | //===----------------------------------------------------------------------===// |
| 12 | |
| 13 | #ifndef ORC_RT_ELFNIX_PLATFORM_H |
| 14 | #define ORC_RT_ELFNIX_PLATFORM_H |
| 15 | |
| 16 | #include "common.h" |
| 17 | #include "executor_address.h" |
| 18 | |
| 19 | // Atexit functions. |
| 20 | ORC_RT_INTERFACE int __orc_rt_elfnix_cxa_atexit(void (*func)(void *), void *arg, |
| 21 | void *dso_handle); |
| 22 | ORC_RT_INTERFACE int __orc_rt_elfnix_atexit(void (*func)(void *)); |
| 23 | ORC_RT_INTERFACE void __orc_rt_elfnix_cxa_finalize(void *dso_handle); |
| 24 | |
| 25 | // dlfcn functions. |
| 26 | ORC_RT_INTERFACE const char *__orc_rt_elfnix_jit_dlerror(); |
| 27 | ORC_RT_INTERFACE void *__orc_rt_elfnix_jit_dlopen(const char *path, int mode); |
| 28 | ORC_RT_INTERFACE int __orc_rt_elfnix_jit_dlupdate(void *dso_handle); |
| 29 | ORC_RT_INTERFACE int __orc_rt_elfnix_jit_dlclose(void *dso_handle); |
| 30 | ORC_RT_INTERFACE void *__orc_rt_elfnix_jit_dlsym(void *dso_handle, |
| 31 | const char *symbol); |
| 32 | |
| 33 | namespace orc_rt { |
| 34 | namespace elfnix { |
| 35 | |
| 36 | struct ELFNixPerObjectSectionsToRegister { |
| 37 | ExecutorAddrRange EHFrameSection; |
| 38 | ExecutorAddrRange ThreadDataSection; |
| 39 | }; |
| 40 | |
| 41 | using ELFNixJITDylibDepInfo = std::vector<ExecutorAddr>; |
| 42 | |
| 43 | using ELFNixJITDylibDepInfoMap = |
| 44 | std::unordered_map<ExecutorAddr, ELFNixJITDylibDepInfo>; |
| 45 | |
| 46 | enum dlopen_mode : int { |
| 47 | ORC_RT_RTLD_LAZY = 0x1, |
| 48 | ORC_RT_RTLD_NOW = 0x2, |
| 49 | ORC_RT_RTLD_LOCAL = 0x4, |
| 50 | ORC_RT_RTLD_GLOBAL = 0x8 |
| 51 | }; |
| 52 | |
| 53 | } // namespace elfnix |
| 54 | |
| 55 | using SPSELFNixPerObjectSectionsToRegister = |
| 56 | SPSTuple<SPSExecutorAddrRange, SPSExecutorAddrRange>; |
| 57 | |
| 58 | template <> |
| 59 | class SPSSerializationTraits<SPSELFNixPerObjectSectionsToRegister, |
| 60 | elfnix::ELFNixPerObjectSectionsToRegister> { |
| 61 | |
| 62 | public: |
| 63 | static size_t size(const elfnix::ELFNixPerObjectSectionsToRegister &MOPOSR) { |
| 64 | return SPSELFNixPerObjectSectionsToRegister::AsArgList::size( |
| 65 | Arg: MOPOSR.EHFrameSection, Args: MOPOSR.ThreadDataSection); |
| 66 | } |
| 67 | |
| 68 | static bool |
| 69 | serialize(SPSOutputBuffer &OB, |
| 70 | const elfnix::ELFNixPerObjectSectionsToRegister &MOPOSR) { |
| 71 | return SPSELFNixPerObjectSectionsToRegister::AsArgList::serialize( |
| 72 | OB, Arg: MOPOSR.EHFrameSection, Args: MOPOSR.ThreadDataSection); |
| 73 | } |
| 74 | |
| 75 | static bool deserialize(SPSInputBuffer &IB, |
| 76 | elfnix::ELFNixPerObjectSectionsToRegister &MOPOSR) { |
| 77 | return SPSELFNixPerObjectSectionsToRegister::AsArgList::deserialize( |
| 78 | IB, Arg&: MOPOSR.EHFrameSection, Args&: MOPOSR.ThreadDataSection); |
| 79 | } |
| 80 | }; |
| 81 | |
| 82 | using SPSELFNixJITDylibDepInfo = SPSSequence<SPSExecutorAddr>; |
| 83 | using SPSELFNixJITDylibDepInfoMap = |
| 84 | SPSSequence<SPSTuple<SPSExecutorAddr, SPSELFNixJITDylibDepInfo>>; |
| 85 | |
| 86 | } // namespace orc_rt |
| 87 | |
| 88 | #endif // ORC_RT_ELFNIX_PLATFORM_H |
| 89 | |