Implement support for module symbols (#475)

* **New Features**
  - Adds module symbol support and per-module symbol tables, including LVGL symbol exports moved into a dedicated table.
* **API**
  - Adds symbol-resolution APIs and an accessor to enable dynamic lookup between modules.
* **Bug Fixes / Chores**
  - Explicitly initializes module symbol pointers across device and platform modules to avoid uninitialized state.
* **Tests**
  - Updates tests to account for symbol pointer initialization.
This commit is contained in:
Ken Van Hoeylandt
2026-02-02 07:50:43 +01:00
committed by GitHub
parent 9f721e6655
commit 1f9e7f82fd
55 changed files with 563 additions and 357 deletions
+42 -3
View File
@@ -1,16 +1,28 @@
// SPDX-License-Identifier: Apache-2.0
#pragma once
#include "error.h"
#include <stdbool.h>
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
#include "error.h"
#include <stdbool.h>
struct ModuleParent;
struct ModuleParentPrivate;
#define MODULE_SYMBOL_TERMINATOR { NULL, NULL }
#define DEFINE_MODULE_SYMBOL(symbol) { #symbol, (void*)&symbol }
/** A binary symbol like a function or a variable. */
struct ModuleSymbol {
/** The name of the symbol. */
const char* name;
/** The address of the symbol. */
const void* symbol;
};
/**
* A module is a collection of drivers or other functionality that can be loaded and unloaded at runtime.
*/
@@ -38,6 +50,13 @@ struct Module {
*/
error_t (*stop)(void);
/**
* A list of symbols exported by the module.
* Should be terminated by MODULE_SYMBOL_TERMINATOR.
* Can be a NULL value.
*/
const struct ModuleSymbol* symbols;
struct {
bool started;
struct ModuleParent* parent;
@@ -69,6 +88,16 @@ error_t module_parent_construct(struct ModuleParent* parent);
*/
error_t module_parent_destruct(struct ModuleParent* parent);
/**
* @brief Resolve a symbol from the module parent.
* @details This function iterates through all started modules in the parent and attempts to resolve the symbol.
* @param parent parent module
* @param symbol_name name of the symbol to resolve
* @param symbol_address pointer to store the address of the resolved symbol
* @return true if the symbol was found, false otherwise
*/
bool module_parent_resolve_symbol(struct ModuleParent* parent, const char* symbol_name, uintptr_t* symbol_address);
/**
* @brief Set the parent of the module.
* @warning must call before module_start()
@@ -99,6 +128,16 @@ bool module_is_started(struct Module* module);
*/
error_t module_stop(struct Module* module);
/**
* @brief Resolve a symbol from the module.
* @details The module must be started for symbol resolution to succeed.
* @param module module
* @param symbol_name name of the symbol to resolve
* @param symbol_address pointer to store the address of the resolved symbol
* @return true if the symbol was found and the module is started, false otherwise
*/
bool module_resolve_symbol(struct Module* module, const char* symbol_name, uintptr_t* symbol_address);
#ifdef __cplusplus
}
#endif