Skip to main content

extract_module_info

Function extract_module_info 

Source
pub unsafe fn extract_module_info(ptr: *const u8) -> ModuleInfoResult<String>
Expand description

Extract a single module-info field from a linker-script-placed symbol.

Reads a JSON string value ("...") starting at ptr, terminated by NUL, and returns the bytes between the first two " characters.

Prefer the get_module_info! macro: it declares the matching extern static and forwards its address here, so the caller never holds a raw pointer.

§Safety

ptr must point to a valid, properly aligned, null-terminated byte sequence inside the read-only .note.package payload (i.e. the address of one of the module_info_* symbols emitted by the linker script). The memory must remain valid for the duration of the call. Passing any other pointer is undefined behavior. The internal scan is bounded by MAX_JSON_SIZE + NOTE_ALIGN, so a missing/corrupted section produces MalformedJson rather than reading off the end.

§Errors

  • ModuleInfoError::NullPointer if ptr is null
  • ModuleInfoError::Utf8Error if the bytes are not valid UTF-8
  • ModuleInfoError::MalformedJson if the section is missing/stripped or the value is not surrounded by " characters
  • ModuleInfoError::NotAvailable on non-Linux targets

§Example

use module_info::{get_module_info, ModuleInfoField, ModuleInfoResult};
let binary: ModuleInfoResult<String> = get_module_info!(ModuleInfoField::Binary);

Available only when the embed-module-info feature is enabled on Linux.