Skip to main content

TlsResolver

Trait TlsResolver 

Source
pub trait TlsResolver<Arch: RelocationArch>: 'static {
    const OVERRIDE_TLS_GET_ADDR: bool = false;

    // Required methods
    fn register(tls_info: &TlsInfo) -> Result<TlsModuleId>;
    fn register_static(tls_info: &TlsInfo) -> Result<(TlsModuleId, TlsTpOffset)>;
    fn add_static_tls(
        tls_info: &TlsInfo,
        offset: TlsTpOffset,
    ) -> Result<TlsModuleId>;
    fn init_tls(
        source: TlsImageSource,
        mod_id: TlsModuleId,
        offset: Option<TlsTpOffset>,
    ) -> Result<()>;
    fn unregister(mod_id: TlsModuleId);
    fn bind_tls_get_addr() -> Result<VmAddr>;
    fn resolve_tls_addr(ti: TlsIndex) -> Result<VmAddr>;

    // Provided methods
    fn bind_static_tlsdesc(_tpoff: usize) -> Result<TlsDescValue> { ... }
    fn bind_dynamic_tlsdesc(_ti: TlsIndex) -> Result<TlsDescValue> { ... }
    fn bind_undefweak_tlsdesc(_addend: usize) -> Result<TlsDescValue> { ... }
}
Expand description

A trait for resolving TLS (Thread Local Storage) information.

Implement this trait to provide custom TLS module IDs and thread pointer offsets. This is essential for supporting TLS in environments with custom thread management, such as operating system kernels or bare-metal systems.

Provided Associated Constants§

Source

const OVERRIDE_TLS_GET_ADDR: bool = false

Whether this resolver should override __tls_get_addr symbol bindings.

Required Methods§

Source

fn register(tls_info: &TlsInfo) -> Result<TlsModuleId>

Registers a module with dynamic TLS and returns the allocated module ID.

§Errors

Returns an error if the module ID cannot be allocated.

Source

fn register_static(tls_info: &TlsInfo) -> Result<(TlsModuleId, TlsTpOffset)>

Registers a module with static TLS, returning the module ID and its thread pointer offset.

§Errors

Returns an error if space cannot be allocated in the static TLS area.

Source

fn add_static_tls( tls_info: &TlsInfo, offset: TlsTpOffset, ) -> Result<TlsModuleId>

Records an existing static TLS module and returns its allocated module ID.

This is used when the TLS block is already set up and its offset from the thread pointer is known.

Source

fn init_tls( source: TlsImageSource, mod_id: TlsModuleId, offset: Option<TlsTpOffset>, ) -> Result<()>

Initializes a TLS module from a source that can provide the final relocated template on demand.

TLS layout may be assigned before dynamic relocations have been applied. This hook is called once the template bytes are ready for future TLS block initialization. Static resolvers may also copy the template into the current thread’s static TLS area.

Source

fn unregister(mod_id: TlsModuleId)

Releases resources associated with the given module ID.

Source

fn bind_tls_get_addr() -> Result<VmAddr>

Returns the target-visible __tls_get_addr entry point.

Native same-process resolvers can return a host function pointer. Remote or guest runtimes should return an address inside the target runtime.

Source

fn resolve_tls_addr(ti: TlsIndex) -> Result<VmAddr>

Resolves the current thread’s host-visible address for a TLS variable.

This is used by host APIs such as symbol lookup. Unlike bind_tls_get_addr, the returned address must be meaningful to the caller in this process.

Provided Methods§

Source

fn bind_static_tlsdesc(_tpoff: usize) -> Result<TlsDescValue>

Returns the target-visible TLSDESC binding for a static TLS access.

Source

fn bind_dynamic_tlsdesc(_ti: TlsIndex) -> Result<TlsDescValue>

Returns the target-visible TLSDESC binding for a dynamic TLS access.

Source

fn bind_undefweak_tlsdesc(_addend: usize) -> Result<TlsDescValue>

Returns the target-visible TLSDESC binding for an undefined weak TLS symbol.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl<Arch: RelocationArch> TlsResolver<Arch> for ()

Implementors§

Source§

impl TlsResolver<X86_64Arch> for DefaultTlsResolver

Available on crate feature tls only.