@@ -39,15 +39,8 @@ struct llext_buf_loader {
39
39
int llext_buf_read (struct llext_loader * ldr , void * buf , size_t len );
40
40
int llext_buf_seek (struct llext_loader * ldr , size_t pos );
41
41
void * llext_buf_peek (struct llext_loader * ldr , size_t pos );
42
- /** @endcond */
43
42
44
- /**
45
- * @brief Initializer for an llext_buf_loader structure
46
- *
47
- * @param _buf Buffer containing the ELF binary
48
- * @param _buf_len Buffer length in bytes
49
- */
50
- #define LLEXT_BUF_LOADER (_buf , _buf_len ) \
43
+ #define Z_LLEXT_BUF_LOADER (_buf , _buf_len , _storage ) \
51
44
{ \
52
45
.loader = \
53
46
{ \
@@ -56,14 +49,72 @@ void *llext_buf_peek(struct llext_loader *ldr, size_t pos);
56
49
.seek = llext_buf_seek, \
57
50
.peek = llext_buf_peek, \
58
51
.finalize = NULL, \
59
- .storage = IS_ENABLED(CONFIG_LLEXT_STORAGE_WRITABLE) ? \
60
- LLEXT_STORAGE_WRITABLE : \
61
- LLEXT_STORAGE_PERSISTENT, \
52
+ .storage = _storage, \
62
53
}, \
63
54
.buf = (_buf), \
64
55
.len = (_buf_len), \
65
56
.pos = 0, \
66
57
}
58
+ /** @endcond */
59
+
60
+ /**
61
+ * @brief Initializer for an llext_buf_loader structure
62
+ *
63
+ * The storage type for the provided buffer depends on the value of the
64
+ * @kconfig{CONFIG_LLEXT_STORAGE_WRITABLE} option: if it is defined, the
65
+ * buffer is assumed to be writable; otherwise it is assumed to be persistent.
66
+ *
67
+ * Consider using one of the alternative macros instead.
68
+ *
69
+ * @see LLEXT_TEMPORARY_BUF_LOADER
70
+ * @see LLEXT_PERSISTENT_BUF_LOADER
71
+ * @see LLEXT_WRITABLE_BUF_LOADER
72
+ *
73
+ * @param _buf Buffer containing the ELF binary
74
+ * @param _buf_len Buffer length in bytes
75
+ */
76
+ #define LLEXT_BUF_LOADER (_buf , _buf_len ) \
77
+ Z_LLEXT_BUF_LOADER(_buf, _buf_len, \
78
+ IS_ENABLED(CONFIG_LLEXT_STORAGE_WRITABLE) ? \
79
+ LLEXT_STORAGE_WRITABLE : LLEXT_STORAGE_PERSISTENT)
80
+
81
+ /* @brief Initialize an llext_buf_loader structure for a temporary buffer
82
+ *
83
+ * ELF data from the specified buffer can only be used during llext_load().
84
+ * The LLEXT subsystem will copy all necessary data to internal buffers at load
85
+ * time.
86
+ *
87
+ * @param _buf Buffer containing the ELF binary
88
+ * @param _buf_len Buffer length in bytes
89
+ */
90
+ #define LLEXT_TEMPORARY_BUF_LOADER (_buf , _buf_len ) \
91
+ Z_LLEXT_BUF_LOADER(_buf, _buf_len, LLEXT_STORAGE_TEMPORARY)
92
+
93
+ /**
94
+ * @brief Initialize an llext_buf_loader structure for a persistent, read-only buffer
95
+ *
96
+ * ELF data from the specified buffer is guaranteed to be accessible for as
97
+ * long as the extension is loaded. The LLEXT subsystem may directly access the
98
+ * ELF data, as long as no modification is required during loading.
99
+ *
100
+ * @param _buf Buffer containing the ELF binary
101
+ * @param _buf_len Buffer length in bytes
102
+ */
103
+ #define LLEXT_PERSISTENT_BUF_LOADER (_buf , _buf_len ) \
104
+ Z_LLEXT_BUF_LOADER(_buf, _buf_len, LLEXT_STORAGE_PERSISTENT)
105
+
106
+ /**
107
+ * @brief Initialize an llext_buf_loader structure for a persistent, writable buffer
108
+ *
109
+ * ELF data from the specified buffer is guaranteed to be accessible for as
110
+ * long as the extension is loaded. The LLEXT subsystem may directly access and
111
+ * modify the ELF data.
112
+ *
113
+ * @param _buf Buffer containing the ELF binary
114
+ * @param _buf_len Buffer length in bytes
115
+ */
116
+ #define LLEXT_WRITABLE_BUF_LOADER (_buf , _buf_len ) \
117
+ Z_LLEXT_BUF_LOADER(_buf, _buf_len, LLEXT_STORAGE_WRITABLE)
67
118
68
119
/**
69
120
* @}
0 commit comments