Zephyr Project API 4.5.0-rc2
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
inspect.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2025 Arduino SA
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7#ifndef ZEPHYR_INCLUDE_LLEXT_INSPECT_H_
8#define ZEPHYR_INCLUDE_LLEXT_INSPECT_H_
9
10#ifdef __cplusplus
11extern "C" {
12#endif
13
14#include <stddef.h>
15#include <zephyr/llext/llext.h>
16#include <zephyr/llext/loader.h>
18
31
48static inline int llext_get_region_info(const struct llext_loader *ldr,
49 const struct llext *ext,
50 enum llext_mem region,
51 const elf_shdr_t **hdr,
52 const void **addr, size_t *size)
53{
54 if ((unsigned int)region >= LLEXT_MEM_COUNT) {
55 return -EINVAL;
56 }
57
58 if (hdr) {
59 *hdr = &ldr->sects[region];
60 }
61
62 /* address and size compensated for alignment prepad */
63 if (addr) {
64 *addr = (void *)((uintptr_t)ext->mem[region] + ldr->sects[region].sh_info);
65 }
66 if (size) {
67 *size = ext->mem_size[region] - ldr->sects[region].sh_info;
68 }
69
70 return 0;
71}
72
86int llext_section_shndx(const struct llext_loader *ldr, const struct llext *ext,
87 const char *section_name);
88
110static inline int llext_get_section_info(const struct llext_loader *ldr,
111 const struct llext *ext,
112 unsigned int shndx,
113 const elf_shdr_t **hdr,
114 enum llext_mem *region,
115 size_t *offset)
116{
117 if (shndx < 0 || shndx >= ext->sect_cnt) {
118 return -EINVAL;
119 }
120 if (!ldr->sect_map) {
121 return -ENOTSUP;
122 }
123
124 enum llext_mem mem_idx = ldr->sect_map[shndx].mem_idx;
125
126 if (hdr) {
127 *hdr = &ext->sect_hdrs[shndx];
128 }
129 if (region) {
130 *region = mem_idx;
131 }
132
133 /* offset compensated for alignment prepad */
134 if (offset) {
135 if (ldr->sect_map[shndx].detached) {
136 *offset = (size_t)-1;
137 } else {
138 *offset = ldr->sect_map[shndx].offset - ldr->sects[mem_idx].sh_info;
139 }
140 }
141
142 return 0;
143}
144
148
149#ifdef __cplusplus
150}
151#endif
152
153#endif /* ZEPHYR_INCLUDE_LLEXT_INSPECT_H_ */
llext_mem
List of memory regions stored or referenced in the LLEXT subsystem.
Definition llext.h:44
@ LLEXT_MEM_COUNT
Number of regions managed by LLEXT.
Definition llext.h:62
struct elf64_shdr elf_shdr_t
Machine sized section header structure.
Definition elf.h:465
static int llext_get_section_info(const struct llext_loader *ldr, const struct llext *ext, unsigned int shndx, const elf_shdr_t **hdr, enum llext_mem *region, size_t *offset)
Get information about a section for the specified extension.
Definition inspect.h:110
int llext_section_shndx(const struct llext_loader *ldr, const struct llext *ext, const char *section_name)
Get the index of a section with the specified name.
static int llext_get_region_info(const struct llext_loader *ldr, const struct llext *ext, enum llext_mem region, const elf_shdr_t **hdr, const void **addr, size_t *size)
Get information about a memory region for the specified extension.
Definition inspect.h:48
#define EINVAL
Invalid argument.
Definition errno.h:61
#define ENOTSUP
Unsupported value.
Definition errno.h:115
Support for linkable loadable extensions.
Private header for linkable loadable extensions.
LLEXT ELF loader context types.
__UINTPTR_TYPE__ uintptr_t
Definition stdint.h:105
Linkable loadable extension loader context.
Definition loader.h:80
Structure describing a linkable loadable extension.
Definition llext.h:112
size_t mem_size[LLEXT_MEM_COUNT]
Size of each stored region.
Definition llext.h:136
void * mem[LLEXT_MEM_COUNT]
Lookup table of memory regions.
Definition llext.h:126