#external #memory #run-time #proc-macro #getter #lookup #procedural

macro raw_struct_derive

raw_struct is a Rust procedural macro for easily declaring C-style structs that reference local or external memory, based on your memory implementation. It generates appropiate getter methods for easy access.

3 releases

0.1.3 Oct 18, 2024
0.1.2 Oct 16, 2024
0.1.0 Oct 16, 2024

#37 in #getter

Download history 204/week @ 2024-10-11 216/week @ 2024-10-18

420 downloads per month
Used in raw_struct

Custom license

17KB
273 lines

lazy_link   Latest Version License: GPL v3 GitHub build status

lazy_link is a Rust procedural macro crate that allows you to dynamically look up external functions at runtime without any additional boilerplate code. This crate is designed to simplify the process of dynamically linking to external functions as runtime, inclusing support for function name obfuscation and no_std environments.

Features

  • Dynamic Function Lookup: Use the lazy_link attribute to dynamically link external functions at runtime.
  • No Boilerplate Required: No need for additional setup or boilerplate code—just annotate your external blocks.
  • Function Name Obfuscation: Function names can be obfuscated using the obfstr crate, enhancing security by making the function identifiers less readable in binary form.
  • Platform and ABI Agnostic: Works across different platforms and ABIs.
  • no_std Compatible: Full support for no_std environments.

Usage

To use lazy_link, simply add the attribute to your external block declarations:

use lazy_link::lazy_link;

#[lazy_link(resolver = "resolve_externals")]
extern "C" {
    fn external_add(v1: u8, v2: u8) -> u8;
}

Additionally, you have to implement the resolve function, which dynamically resolves the function at runtime. This function takes the function's name (and an optional module) and returns a non-null pointer to the function:

fn resolve_externals(module: Option<&str>, name: &str) -> NonNull<()> {
    // Your resolution logic here, typically using some form of dynamic lookup.
    unimplemented!("Function lookup logic for {}", name)
}

Examples

Examples can be found within the examples directory of this repository. These examples demonstrate how to use lazy_link in various contexts, including platform-specific scenarios.

To run the examples, clone the repository and use the following command:

cargo run --bin <example_name>

Dependencies

~1.5MB
~37K SLoC