llext: add llext_peek()
The only way so far to access extension images is via a memory buffer. Since this, supposedly, will also be a rather common method, it makes sense to add a method to access extension data quickly by obtaining a pointer instead of copying data into local buffers. Add a llext_peek() method for that. Signed-off-by: Guennadi Liakhovetski <guennadi.liakhovetski@linux.intel.com>
This commit is contained in:
parent
adc30ff294
commit
ce4cdac3c0
4 changed files with 32 additions and 2 deletions
|
@ -37,6 +37,7 @@ struct llext_buf_loader {
|
||||||
/** @cond ignore */
|
/** @cond ignore */
|
||||||
int llext_buf_read(struct llext_loader *ldr, void *buf, size_t len);
|
int llext_buf_read(struct llext_loader *ldr, void *buf, size_t len);
|
||||||
int llext_buf_seek(struct llext_loader *ldr, size_t pos);
|
int llext_buf_seek(struct llext_loader *ldr, size_t pos);
|
||||||
|
void *llext_buf_peek(struct llext_loader *ldr, size_t pos);
|
||||||
/** @endcond */
|
/** @endcond */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -49,7 +50,8 @@ int llext_buf_seek(struct llext_loader *ldr, size_t pos);
|
||||||
{ \
|
{ \
|
||||||
.loader = { \
|
.loader = { \
|
||||||
.read = llext_buf_read, \
|
.read = llext_buf_read, \
|
||||||
.seek = llext_buf_seek \
|
.seek = llext_buf_seek, \
|
||||||
|
.peek = llext_buf_peek, \
|
||||||
}, \
|
}, \
|
||||||
.buf = (_buf), \
|
.buf = (_buf), \
|
||||||
.len = (_buf_len), \
|
.len = (_buf_len), \
|
||||||
|
|
|
@ -73,7 +73,19 @@ struct llext_loader {
|
||||||
* @retval 0 Success
|
* @retval 0 Success
|
||||||
* @retval -errno Error reading (any errno)
|
* @retval -errno Error reading (any errno)
|
||||||
*/
|
*/
|
||||||
int (*seek)(struct llext_loader *s, size_t pos);
|
int (*seek)(struct llext_loader *ldr, size_t pos);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Peek at an absolute location
|
||||||
|
*
|
||||||
|
* Return a pointer to the buffer at specified offset.
|
||||||
|
*
|
||||||
|
* @param[in] ldr Loader
|
||||||
|
* @param[in] pos Position to obtain a pointer to
|
||||||
|
*
|
||||||
|
* @retval pointer into the buffer
|
||||||
|
*/
|
||||||
|
void *(*peek)(struct llext_loader *ldr, size_t pos);
|
||||||
|
|
||||||
/** @cond ignore */
|
/** @cond ignore */
|
||||||
elf_ehdr_t hdr;
|
elf_ehdr_t hdr;
|
||||||
|
|
|
@ -29,3 +29,10 @@ int llext_buf_seek(struct llext_loader *l, size_t pos)
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void *llext_buf_peek(struct llext_loader *l, size_t pos)
|
||||||
|
{
|
||||||
|
struct llext_buf_loader *buf_l = CONTAINER_OF(l, struct llext_buf_loader, loader);
|
||||||
|
|
||||||
|
return (void *)(buf_l->buf + pos);
|
||||||
|
}
|
||||||
|
|
|
@ -31,6 +31,15 @@ static inline int llext_seek(struct llext_loader *l, size_t pos)
|
||||||
return l->seek(l, pos);
|
return l->seek(l, pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline void *llext_peek(struct llext_loader *l, size_t pos)
|
||||||
|
{
|
||||||
|
if (l->peek) {
|
||||||
|
return l->peek(l, pos);
|
||||||
|
}
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
static sys_slist_t _llext_list = SYS_SLIST_STATIC_INIT(&_llext_list);
|
static sys_slist_t _llext_list = SYS_SLIST_STATIC_INIT(&_llext_list);
|
||||||
|
|
||||||
sys_slist_t *llext_list(void)
|
sys_slist_t *llext_list(void)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue