minhook::static_hooks!
[−]
[src]
macro_rules! static_hooks { (@parse_attr ($($args:tt)*) | $(#[$var_attr:meta])* $next:tt $($rest:tt)*) => { ... }; (@parse_pub ($($args:tt)*) | pub impl $($rest:tt)*) => { ... }; (@parse_pub ($($args:tt)*) | impl $($rest:tt)*) => { ... }; (@parse_mod ($($args:tt)*) | $($rest:tt)*) => { ... }; (@parse_name_target ($($args:tt)*) | $var_name:ident for $target_fn_name:tt in $target_mod_name:tt : $($rest:tt)*) => { ... }; (@parse_name_target ($($args:tt)*) | $var_name:ident for $target_path:path : $($rest:tt)*) => { ... }; (@parse_fn_unsafe ($($args:tt)*) | unsafe $($rest:tt)*) => { ... }; (@parse_fn_unsafe ($($args:tt)*) | $($rest:tt)*) => { ... }; (@parse_fn_linkage ($($args:tt)*) ($($fn_mod:tt)*) | extern $linkage:tt fn $($rest:tt)*) => { ... }; (@parse_fn_linkage ($($args:tt)*) ($($fn_mod:tt)*) | extern fn $($rest:tt)*) => { ... }; (@parse_fn_linkage ($($args:tt)*) ($($fn_mod:tt)*) | fn $($rest:tt)*) => { ... }; (@parse_fn_args ($($args:tt)*) | ($($arg_type:ty),*) -> $return_type:ty = $($rest:tt)*) => { ... }; (@parse_fn_args ($($args:tt)*) | ($($arg_type:ty),*) -> $return_type:ty ; $($rest:tt)*) => { ... }; (@parse_fn_args ($($args:tt)*) | ($($arg_type:ty),*) $($rest:tt)*) => { ... }; (@parse_fn_value ($($args:tt)*) | = $value:expr ; $($rest:tt)*) => { ... }; (@parse_fn_value ($($args:tt)*) | ; $($rest:tt)*) => { ... }; (@parse_rest ($($args:tt)*) | $($rest:tt)+) => { ... }; (@parse_rest ($($args:tt)*) | ) => { ... }; (@make ($($var_attr:meta)*) ($($var_mod:tt)*) ($($hook_mod:tt)*) ($var_name:ident) ($target:expr) ($($fn_mod:tt)*) ($guard:tt) ($($arg_type:ty)*) ($return_type:ty) ($value:tt)) => { ... }; (@make_hook_var ($($arg_name:ident)*) ($($var_attr:meta)*) ($($var_mod:tt)*) ($($hook_mod:tt)*) ($var_name:ident) ($target:expr) ($($fn_mod:tt)*) ($guard:tt) ($($arg_type:ty)*) ($return_type:ty) (!) ($fn_type:ty)) => { ... }; (@make_hook_var ($($arg_name:ident)*) ($($var_attr:meta)*) ($($var_mod:tt)*) ($($hook_mod:tt)*) ($var_name:ident) ($target:expr) ($($fn_mod:tt)*) ($guard:tt) ($($arg_type:ty)*) ($return_type:ty) ($value:tt) ($fn_type:ty)) => { ... }; (@make_detour (GUARD) ($var_name:ident) ($($fn_mod:tt)*) ($($arg_name:ident)*) ($($arg_type:ty)*) ($return_type:ty)) => { ... }; (@make_detour (NO_GUARD) ($var_name:ident) ($($fn_mod:tt)*) ($($arg_name:ident)*) ($($arg_type:ty)*) ($return_type:ty)) => { ... }; (@make_item $item:item) => { ... }; (@gen_arg_names ($label:ident) ($($args:tt)*) ($($token:tt)*)) => { ... }; (@gen_arg_names ($label:ident) ($($args:tt)*) ($hd_name:tt $($tl_name:tt)*) ($hd:tt $($tl:tt)*) ($($acc:tt)*) ) => { ... }; (@gen_arg_names ($label:ident) ($($args:tt)*) ($($name:tt)*) () ($($acc:tt)*)) => { ... }; ($($t:tt)+) => { ... }; }
Defines one or more static hooks.
A static_hooks!
block can contain one or more hook definitions of the following forms:
// Creates a `StaticHookWithDefault` #[ATTR]* pub? impl HOOK_VAR_NAME for PATH::TO::TARGET: FN_TYPE = FN_EXPR; #[ATTR]* pub? impl HOOK_VAR_NAME for "FUNCTION" in "MODULE": FN_TYPE = FN_EXPR; // Creates a `StaticHook` #[ATTR]* pub? impl HOOK_VAR_NAME for PATH::TO::TARGET: FN_TYPE; #[ATTR]* pub? impl HOOK_VAR_NAME for "FUNCTION" in "MODULE": FN_TYPE;
All of the above definitions create a static variable with the specified name of
type StaticHook
or StaticHookWithDefault
for a target function of the given
type. If the function signature contains extern
, any panics that happen inside of the
detour Fn
are automatically caught before they can propagate across foreign code boundaries.
See the panic
submodule for more information.
The first two forms create a static hook with a default detour Fn
. This is useful if
the detour Fn
is a closure that does not need to capture any local variables
or if the detour Fn
is just a normal function. See StaticHookWithDefault
.
The last two forms require a Fn
to be supplied at the time of initialization of the
static hook. In this case a closure that captures local variables can be supplied.
See StaticHook
.
The first and third forms are used for hooking functions by their compile-time identifier.
The second and fourth form will try to find the target function by name at initialization instead of at compile time. These forms require the exported function symbol name and its containing module's name to be supplied.
The optional pub
keyword can be used to give the resulting hook variable public
visibility. Any attributes used on a hook definition will be applied to the resulting
hook variable.