1 /* 2 * Copyright (c) 2023 Intel Corporation 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 */ 6 7 #ifndef ZEPHYR_LLEXT_BUF_LOADER_H 8 #define ZEPHYR_LLEXT_BUF_LOADER_H 9 10 #include <zephyr/llext/loader.h> 11 12 #ifdef __cplusplus 13 extern "C" { 14 #endif 15 16 /** 17 * @file 18 * @brief LLEXT buffer loader implementation. 19 * 20 * @addtogroup llext_loader_apis 21 * @{ 22 */ 23 24 /** 25 * @brief Implementation of @ref llext_loader that reads from a memory buffer. 26 */ 27 struct llext_buf_loader { 28 /** Extension loader */ 29 struct llext_loader loader; 30 31 /** @cond ignore */ 32 const uint8_t *buf; 33 size_t len; 34 size_t pos; 35 /** @endcond */ 36 }; 37 38 /** @cond ignore */ 39 int llext_buf_read(struct llext_loader *ldr, void *buf, size_t len); 40 int llext_buf_seek(struct llext_loader *ldr, size_t pos); 41 void *llext_buf_peek(struct llext_loader *ldr, size_t pos); 42 /** @endcond */ 43 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) \ 51 { \ 52 .loader = { \ 53 .read = llext_buf_read, \ 54 .seek = llext_buf_seek, \ 55 .peek = llext_buf_peek, \ 56 }, \ 57 .buf = (_buf), \ 58 .len = (_buf_len), \ 59 .pos = 0 \ 60 } 61 62 /** 63 * @} 64 */ 65 66 #ifdef __cplusplus 67 } 68 #endif 69 70 #endif /* ZEPHYR_LLEXT_BUF_LOADER_H */ 71