1#![allow(clippy::type_complexity)]
27#![warn(
28 clippy::unnecessary_lazy_evaluations,
29 clippy::collapsible_if,
30 clippy::explicit_iter_loop,
31 clippy::manual_assert,
32 clippy::needless_question_mark,
33 clippy::needless_return,
34 clippy::needless_update,
35 clippy::redundant_clone,
36 clippy::redundant_else,
37 clippy::redundant_static_lifetimes
38)]
39#![cfg_attr(not(feature = "std"), no_std)]
40
41extern crate alloc;
42
43#[cfg(all(feature = "std", feature = "use-syscall"))]
44compile_error!("feature \"std\" and feature \"use-syscall\" cannot be enabled at the same time");
45
46pub mod api;
47mod core_impl;
48mod error;
49mod os;
50mod utils;
51
52use bitflags::bitflags;
53
54pub use crate::api::dlsym::{dlsym_default, dlsym_next};
55pub use crate::core_impl::loader::ElfLibrary;
56pub use crate::core_impl::traits::AsFilename;
57pub use crate::error::Error;
58pub use elf_loader::image::Symbol;
59
60#[cfg(not(any(
61 target_arch = "x86_64",
62 target_arch = "aarch64",
63 target_arch = "riscv64",
64)))]
65compile_error!("unsupport arch");
66
67bitflags! {
68 #[derive(Clone, Copy, Debug)]
70 pub struct OpenFlags:u32{
71 const RTLD_LOCAL = 0;
73 const RTLD_LAZY = 1;
75 const RTLD_NOW = 2;
77 const RTLD_NOLOAD = 4;
79 const RTLD_DEEPBIND = 8;
81 const RTLD_GLOBAL = 256;
83 const RTLD_NODELETE = 4096;
85 }
86}
87
88impl OpenFlags {
89 pub(crate) fn is_global(&self) -> bool {
90 self.contains(OpenFlags::RTLD_GLOBAL)
91 }
92
93 pub(crate) fn is_nodelete(&self) -> bool {
94 self.contains(OpenFlags::RTLD_NODELETE)
95 }
96
97 pub(crate) fn is_now(&self) -> bool {
98 self.contains(OpenFlags::RTLD_NOW)
99 }
100
101 pub(crate) fn is_noload(&self) -> bool {
102 self.contains(OpenFlags::RTLD_NOLOAD)
103 }
104
105 pub(crate) fn is_lazy(&self) -> bool {
106 self.contains(OpenFlags::RTLD_LAZY)
107 }
108
109 pub(crate) fn is_deepbind(&self) -> bool {
110 self.contains(OpenFlags::RTLD_DEEPBIND)
111 }
112
113 pub(crate) fn promotable(&self) -> OpenFlags {
114 *self & (OpenFlags::RTLD_GLOBAL | OpenFlags::RTLD_NODELETE)
115 }
116}
117
118pub type Result<T> = core::result::Result<T, Error>;