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 <stddef.h>
12 
13 #ifdef __cplusplus
14 extern "C" {
15 #endif
16 /**
17  * @brief Linkable loadable extension symbol
18  * @defgroup llext_symbols LLEXT symbols
19  * @ingroup llext
20  * @{
21  */
22 
23 /**
24  * @brief Constant symbols are unchangeable named memory addresses
25  *
26  * Symbols may be named function or global objects that have been exported
27  * for linking. These constant symbols are useful in the base image
28  * as they may be placed in ROM.
29  */
30 struct llext_const_symbol {
31 	/** Name of symbol */
32 	const char *const name;
33 
34 	/** Address of symbol */
35 	const void *const addr;
36 };
37 
38 /**
39  * @brief Symbols are named memory addresses
40  *
41  * Symbols may be named function or global objects that have been exported
42  * for linking. These are mutable and should come from extensions where
43  * the location may need updating depending on where memory is placed.
44  */
45 struct llext_symbol {
46 	/** Name of symbol */
47 	char *name;
48 
49 	/** Address of symbol */
50 	void *addr;
51 };
52 
53 
54 /**
55  * @brief A symbol table
56  *
57  * An array of symbols
58  */
59 struct llext_symtable {
60 	/** Number of symbols in the table */
61 	size_t sym_cnt;
62 
63 	/** Array of symbols */
64 	struct llext_symbol *syms;
65 };
66 
67 
68 /**
69  * @brief Export a constant symbol to a table of symbols
70  *
71  * Takes a symbol (function or object) by symbolic name and adds the name
72  * and address of the symbol to a table of symbols that may be used for linking.
73  *
74  * @param x Symbol to export
75  */
76 #define EXPORT_SYMBOL(x)							\
77 	static const STRUCT_SECTION_ITERABLE(llext_const_symbol, x ## _sym) = {	\
78 		.name = STRINGIFY(x), .addr = x,				\
79 	}
80 
81 /**
82  * @}
83  */
84 
85 #ifdef __cplusplus
86 }
87 #endif
88 
89 
90 #endif /* ZEPHYR_LLEXT_SYMBOL_H */
91