1 /* 2 * Copyright (c) 2023 Intel Corporation 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 */ 6 7 #ifndef ZEPHYR_LLEXT_SYMBOL_H 8 #define ZEPHYR_LLEXT_SYMBOL_H 9 10 #include <zephyr/sys/iterable_sections.h> 11 #include <zephyr/toolchain.h> 12 #include <stddef.h> 13 14 #ifdef __cplusplus 15 extern "C" { 16 #endif 17 /** 18 * @brief Linkable loadable extension symbol 19 * @defgroup llext_symbols LLEXT symbols 20 * @ingroup llext 21 * @{ 22 */ 23 24 /** 25 * @brief Constant symbols are unchangeable named memory addresses 26 * 27 * Symbols may be named function or global objects that have been exported 28 * for linking. These constant symbols are useful in the base image 29 * as they may be placed in ROM. 30 */ 31 struct llext_const_symbol { 32 /** Name of symbol */ 33 const char *const name; 34 35 /** Address of symbol */ 36 const void *const addr; 37 }; 38 39 /** 40 * @brief Symbols are named memory addresses 41 * 42 * Symbols may be named function or global objects that have been exported 43 * for linking. These are mutable and should come from extensions where 44 * the location may need updating depending on where memory is placed. 45 */ 46 struct llext_symbol { 47 /** Name of symbol */ 48 const char *name; 49 50 /** Address of symbol */ 51 void *addr; 52 }; 53 54 55 /** 56 * @brief A symbol table 57 * 58 * An array of symbols 59 */ 60 struct llext_symtable { 61 /** Number of symbols in the table */ 62 size_t sym_cnt; 63 64 /** Array of symbols */ 65 struct llext_symbol *syms; 66 }; 67 68 69 /** 70 * @brief Export a constant symbol to a table of symbols 71 * 72 * Takes a symbol (function or object) by symbolic name and adds the name 73 * and address of the symbol to a table of symbols that may be used for linking. 74 * 75 * @param x Symbol to export 76 */ 77 #define EXPORT_SYMBOL(x) \ 78 static const STRUCT_SECTION_ITERABLE(llext_const_symbol, x ## _sym) = { \ 79 .name = STRINGIFY(x), .addr = &x, \ 80 } 81 82 #define LL_EXTENSION_SYMBOL(x) \ 83 struct llext_symbol Z_GENERIC_SECTION(".exported_sym") __used \ 84 symbol_##x = {STRINGIFY(x), &x} 85 86 /** 87 * @brief Export a system call to a table of symbols 88 * 89 * Takes a system call name and uses @a EXPORT_SYMBOL() to export the respective 90 * function. 91 * 92 * @param x System call to export 93 */ 94 #define EXPORT_SYSCALL(x) EXPORT_SYMBOL(z_impl_ ## x) 95 96 /** 97 * @} 98 */ 99 100 #ifdef __cplusplus 101 } 102 #endif 103 104 105 #endif /* ZEPHYR_LLEXT_SYMBOL_H */ 106