diff --git a/Cargo.toml b/Cargo.toml index 9421df3..977a37d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,7 +20,7 @@ libc = { version = "0.2.126", optional = true } regex = { version = "1.6.0", optional = true } [features] -default = ["plugin"] +default = ["plugin-ffi"] # Dynamically allocate and populate all memory needed for `--bytes` at runtime instead of streaming in fixed size blocks. # @@ -29,3 +29,6 @@ bytes-dynamic = [] # Allow plugin-loading at runtime with `[@]... ` plugin = ["libc", "bitflags", "lazy_static", "regex"] + +# Allow non-Rust (C interface) plugin symbol resolution. +plugin-ffi = ["plugin"] diff --git a/src/plugin/loader.rs b/src/plugin/loader.rs index 6c85701..8dc6feb 100644 --- a/src/plugin/loader.rs +++ b/src/plugin/loader.rs @@ -1,3 +1,54 @@ -//! Loads dynamic object plugins for `rngcli` +//! Loads dynamic object plugins for `rngcli` and loads the correct symbol entry point for adding the plugin. use super::*; +/// The expected function signatures and ABIs of loader/unloader functions found via symbol lookup. +pub mod signatures { + /// The expected signature of the plugin's loader function symbol. + pub type PluginLoaderFunction = unsafe extern "Rust" fn () -> (); //TODO + /// The expected signature of the plugin's unloader function symbol (if it exists.) + pub type PluginUnloaderFunction = unsafe extern "Rust" fn () -> (); //TODO + #[cfg(feature="plugin-ffi")] pub use super::ffi::signatures::*; +} + +/// Contains C-interface symbols and their corresponding signatures. +#[cfg(feature="plugin-ffi")] +mod ffi { + /// The names of various symbols needed for lookups in a C-interface plugin's executable object. + /// + /// The means of lookup is via `dlsym()`. + pub mod symbols { + /// The C function symbol name to search for if the Rust one was not found which handles registering the plugin. + /// + /// The signature of this function **must** be `ForeignPluginLoaderFunction`. + pub static FFI_PLUGIN_SYMBOL_NAME_ADD: &'static str = "_rngcli_plugin_add_c"; + + /// The C function symbol name to search for if the Rust one was not found which handles unloading the plugin. It is optional to include this (as the Rust one is too.) + /// The signature of this function **must** be `ForeignPluginUnloaderFunction`. + pub static FFI_PLUGIN_SYMBOL_NAME_REMOVE: &'static str = "_rngcli_plugin_remove_c"; + } + /// The expected function signatures of a C-interface plugin's loader/unloader symbols found via symbol lookup. + pub mod signatures { + /// The expected signature of the C-interface plugin's loader function symbol. + pub type ForeignPluginLoaderFunction = unsafe extern "C" fn () -> (); //TODO + /// The expected signature of the C-interface plugin's unloader function symbol (if it exists.) + pub type ForeignPluginUnloaderFunction = unsafe extern "C" fn () -> (); //TODO + } +} + +/// The names of various symbols needed for lookups in a plugin's executable object. +/// +/// The means of the lookup is via `dlsym()`. +pub mod symbols { + /// The Rust function symbol name (non-mangled) to search for in the plugin executable object which handles registering the plugin. + /// + /// The signature of this function **must** be `PluginLoaderFunction`. + pub static RUST_PLUGIN_SYMBOL_NAME_ADD: &'static str = "rngcli_plugin_add"; + /// The (optional) Rust function symbol name (non-mangled) to search for in the plugin which is ran when the plugin is unloaded. + /// + /// The signature of this function **must** be `PluginUnloaderFunction`. + pub static RUST_PLUGIN_SYMBOL_NAME_REMOVE: &'static str = "rngcli_plugin_remove"; + + #[cfg(feature="plugin-ffi")] pub use super::ffi::symbols::*; +} +use signatures::*; +//TODO: Figure out what signature to use. diff --git a/src/plugin/searcher.rs b/src/plugin/searcher.rs index 47eab37..bea6689 100644 --- a/src/plugin/searcher.rs +++ b/src/plugin/searcher.rs @@ -209,9 +209,8 @@ struct PathLookup { impl PathLookup { - #[inline] - pub fn check_valid_path(path: impl AsRef) -> bool + pub fn check_valid_path(path: impl AsRef) -> bool { #[inline(always)] fn regex_builder(pattern: impl AsRef) -> Regex { @@ -282,7 +281,7 @@ impl PathLookup // } // } - let (matcher, checker) = if Trusted { + let (matcher, checker) = if TRUSTED { // Trusted path lookup (match_any(TRUSTED_EXT_REGEX_MAP.iter()), None)//&NoChecker) } else {