Dynamic loading v0.1.0
RTLD_LAZY
pub const RTLD_LAZY: int32 = 1;
RTLD_LAZY: resolve a function symbol the first time it is called rather than at load.
RTLD_NOW
pub const RTLD_NOW: int32 = 2;
RTLD_NOW: resolve every symbol before dlopen returns.
RTLD_GLOBAL
pub const RTLD_GLOBAL: int32 = 256;
RTLD_GLOBAL: make this object's symbols available to objects loaded afterwards.
RTLD_LOCAL
pub const RTLD_LOCAL: int32 = 0;
RTLD_LOCAL: keep this object's symbols to itself, which is the default.
dlopen
pub extern func dlopen(
filename: *char8,
flags: int32
) -> *var opaque
Loads a shared object and returns a handle to it, or null on failure.
A name without a slash is resolved by the loader's own search rules, and one with a slash as a path. A second
call for an object already loaded returns the same handle and raises its reference count rather than loading
it twice. Failure is reported through dlerror, not errno.
See also: https://man.freebsd.org/cgi/man.cgi?query=dlopen
Parameters
| Name | Type | Description |
|---|---|---|
filename | *char8 | a NUL-terminated name or path, or null for the main program |
flags | int32 | RTLD_LAZY or RTLD_NOW, combined with the other RTLD_* flags |
Returns: a handle for dlsym and dlclose, or null with the reason in dlerror
dlsym
pub extern func dlsym(
handle: *var opaque,
symbol: *char8
) -> *var opaque
Finds a symbol in a loaded object and returns its address, or null.
A null return is ambiguous, since a symbol whose address is legitimately zero exists. Clear dlerror by calling
it, then call this, then read dlerror again to tell the two apart.
See also: https://man.freebsd.org/cgi/man.cgi?query=dlsym
Parameters
| Name | Type | Description |
|---|---|---|
handle | *var opaque | a handle from dlopen |
symbol | *char8 | the NUL-terminated symbol name |
Returns: the symbol's address, or null
dlclose
pub extern func dlclose(handle: *var opaque) -> int32
Drops one reference to a loaded object, unloading it when the last one goes.
Every address obtained from the object through dlsym becomes invalid once it is actually unloaded, which this
gives no way to observe.
See also: https://man.freebsd.org/cgi/man.cgi?query=dlclose
Parameters
| Name | Type | Description |
|---|---|---|
handle | *var opaque | a handle from dlopen |
Returns: zero on success, and non-zero with the reason in dlerror
dlerror
pub extern func dlerror() -> *char8
Reports the most recent loader error and clears it, or returns null when there is none. The message points at storage the loader owns and a later call may reuse. Reading it clears the error, so two calls in a row report the second as no error at all.
See also: https://man.freebsd.org/cgi/man.cgi?query=dlerror
Returns: a NUL-terminated message, or null