|
infix
A JIT-Powered FFI Library for C
|
Cross-platform functions for loading shared libraries and accessing exported symbols. More...
Functions | |
| INFIX_API INFIX_NODISCARD infix_library_t * | infix_library_open (const char *) |
| Opens a dynamic library and returns a handle to it. | |
| INFIX_API void | infix_library_close (infix_library_t *) |
| Closes a dynamic library handle. | |
| INFIX_API INFIX_NODISCARD void * | infix_library_get_symbol (infix_library_t *, const char *) |
| Retrieves the address of a symbol (function or variable) from a loaded library. | |
| INFIX_API INFIX_NODISCARD infix_status | infix_read_global (infix_library_t *, const char *, const char *, void *, infix_registry_t *) |
| Reads the value of a global variable from a library into a buffer. | |
| INFIX_API INFIX_NODISCARD infix_status | infix_write_global (infix_library_t *, const char *, const char *, void *, infix_registry_t *) |
| Writes data from a buffer into a global variable in a library. | |
Cross-platform functions for loading shared libraries and accessing exported symbols.
| INFIX_API void infix_library_close | ( | infix_library_t * | lib | ) |
Closes a dynamic library handle.
| [in] | lib | The library handle to close. Safe to call with nullptr. |
Closes a dynamic library handle.
This is a cross-platform wrapper around FreeLibrary (Windows) and dlclose (POSIX).
| [in] | lib | The library handle to close. It is safe to call this function with nullptr. |
| INFIX_API INFIX_NODISCARD void * infix_library_get_symbol | ( | infix_library_t * | lib, |
| const char * | symbol_name ) |
Retrieves the address of a symbol (function or variable) from a loaded library.
| [in] | lib | The library handle. |
| [in] | symbol_name | The name of the symbol to look up. |
This is a cross-platform wrapper around GetProcAddress (Windows) and dlsym (POSIX).
| [in] | lib | The library handle. |
| [in] | symbol_name | The name of the symbol to look up (e.g., "my_function"). |
| INFIX_API INFIX_NODISCARD infix_library_t * infix_library_open | ( | const char * | path | ) |
Opens a dynamic library and returns a handle to it.
| [in] | path | The file path to the library (e.g., ./mylib.so, user32.dll). |
This function is a cross-platform wrapper around LoadLibraryA (Windows) and dlopen (POSIX). On failure, it sets the thread-local error state with detailed system-specific information using _infix_set_system_error.
| [in] | path | The file path to the library (e.g., "./mylib.so", "user32.dll"). |
| INFIX_API INFIX_NODISCARD infix_status infix_read_global | ( | infix_library_t * | lib, |
| const char * | symbol_name, | ||
| const char * | type_signature, | ||
| void * | buffer, | ||
| infix_registry_t * | registry ) |
Reads the value of a global variable from a library into a buffer.
Uses the signature parser to determine the size of the variable to ensure the correct number of bytes are copied.
| [in] | lib | The library handle. |
| [in] | symbol_name | The name of the global variable. |
| [in] | type_signature | The infix signature string describing the variable's type. |
| [out] | buffer | A pointer to the destination buffer to receive the data. |
| [in] | registry | An optional registry for resolving named types in the signature. |
Reads the value of a global variable from a library into a buffer.
This function first looks up the symbol's address. It then uses the infix signature parser (infix_type_from_signature) to determine the size of the variable. This ensures that the correct number of bytes are copied from the library's data segment into the user's buffer, preventing buffer overflows.
| [in] | lib | The library handle. |
| [in] | symbol_name | The name of the global variable. |
| [in] | type_signature | The infix signature string describing the variable's type (e.g., "int32", "{double,double}"). |
| [out] | buffer | A pointer to the destination buffer to receive the data. This buffer must be large enough to hold the type described by the signature. |
| [in] | registry | An optional registry for resolving named types in the signature. |
| INFIX_API INFIX_NODISCARD infix_status infix_write_global | ( | infix_library_t * | lib, |
| const char * | symbol_name, | ||
| const char * | type_signature, | ||
| void * | buffer, | ||
| infix_registry_t * | registry ) |
Writes data from a buffer into a global variable in a library.
| [in] | lib | The library handle. |
| [in] | symbol_name | The name of the global variable. |
| [in] | type_signature | The infix signature string describing the variable's type. |
| [in] | buffer | A pointer to the source buffer containing the data to write. |
| [in] | registry | An optional registry for resolving named types in the signature. |
Writes data from a buffer into a global variable in a library.
This function is analogous to infix_read_global. It finds the symbol's address and uses the signature string to determine the correct number of bytes to copy from the source buffer to the library's memory.
| [in] | lib | The library handle. |
| [in] | symbol_name | The name of the global variable. |
| [in] | type_signature | The infix signature string describing the variable's type. |
| [in] | buffer | A pointer to the source buffer containing the data to write. |
| [in] | registry | An optional registry for resolving named types in the signature. |