Zephyr Project API 3.7.0
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
llext.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2023 Intel Corporation
3 * Copyright (c) 2024 Schneider Electric
4 *
5 * SPDX-License-Identifier: Apache-2.0
6 */
7
8#ifndef ZEPHYR_LLEXT_H
9#define ZEPHYR_LLEXT_H
10
11#include <zephyr/sys/slist.h>
12#include <zephyr/llext/elf.h>
13#include <zephyr/llext/symbol.h>
14#include <zephyr/kernel.h>
15#include <sys/types.h>
16#include <stdbool.h>
17
18#ifdef __cplusplus
19extern "C" {
20#endif
21
56
59/* Number of memory partitions used by LLEXT */
60#define LLEXT_MEM_PARTITIONS (LLEXT_MEM_BSS+1)
61
62struct llext_loader;
71struct llext {
73 sys_snode_t _llext_list;
74
75#ifdef CONFIG_USERSPACE
76 struct k_mem_partition mem_parts[LLEXT_MEM_PARTITIONS];
77 struct k_mem_domain mem_domain;
78#endif
79
83 char name[16];
84
87
90
93
95 size_t alloc_size;
96
104
111
113 unsigned int use_count;
114};
115
130
132#define LLEXT_LOAD_PARAM_DEFAULT { .relocate_local = true, }
133
140struct llext *llext_by_name(const char *name);
141
153int llext_iterate(int (*fn)(struct llext *ext, void *arg), void *arg);
154
170int llext_load(struct llext_loader *loader, const char *name, struct llext **ext,
171 struct llext_load_param *ldr_parm);
172
178int llext_unload(struct llext **ext);
179
192const void *llext_find_sym(const struct llext_symtable *sym_table, const char *sym_name);
193
206int llext_call_fn(struct llext *ext, const char *sym_name);
207
221int llext_add_domain(struct llext *ext, struct k_mem_domain *domain);
222
242 uintptr_t sym_base_addr, const char *sym_name, uintptr_t load_bias);
243
253ssize_t llext_find_section(struct llext_loader *loader, const char *search_name);
254
264void arch_elf_relocate_local(struct llext_loader *loader, struct llext *ext,
265 const elf_rela_t *rel, const elf_sym_t *sym, size_t got_offset);
266
271#ifdef __cplusplus
272}
273#endif
274
275#endif /* ZEPHYR_LLEXT_H */
Data structures and constants defined in the ELF specification.
int llext_iterate(int(*fn)(struct llext *ext, void *arg), void *arg)
Iterate over all loaded extensions.
int arch_elf_relocate(elf_rela_t *rel, uintptr_t loc, uintptr_t sym_base_addr, const char *sym_name, uintptr_t load_bias)
Architecture specific opcode update function.
ssize_t llext_find_section(struct llext_loader *loader, const char *search_name)
Locates an ELF section in the file.
void arch_elf_relocate_local(struct llext_loader *loader, struct llext *ext, const elf_rela_t *rel, const elf_sym_t *sym, size_t got_offset)
Architecture specific function for updating addresses via relocation table.
int llext_add_domain(struct llext *ext, struct k_mem_domain *domain)
Add an extension to a memory domain.
llext_mem
List of memory regions stored or referenced in the LLEXT subsystem.
Definition llext.h:44
int llext_load(struct llext_loader *loader, const char *name, struct llext **ext, struct llext_load_param *ldr_parm)
Load and link an extension.
struct llext * llext_by_name(const char *name)
Find an llext by name.
const void * llext_find_sym(const struct llext_symtable *sym_table, const char *sym_name)
Find the address for an arbitrary symbol.
int llext_unload(struct llext **ext)
Unload an extension.
int llext_call_fn(struct llext *ext, const char *sym_name)
Call a function by name.
@ LLEXT_MEM_SYMTAB
Symbol table.
Definition llext.h:50
@ LLEXT_MEM_SHSTRTAB
Section name strings.
Definition llext.h:52
@ LLEXT_MEM_TEXT
Executable code.
Definition llext.h:45
@ LLEXT_MEM_DATA
Initialized data.
Definition llext.h:46
@ LLEXT_MEM_BSS
Uninitialized data.
Definition llext.h:48
@ LLEXT_MEM_RODATA
Read-only data.
Definition llext.h:47
@ LLEXT_MEM_COUNT
Number of regions managed by LLEXT.
Definition llext.h:54
@ LLEXT_MEM_STRTAB
Symbol name strings.
Definition llext.h:51
@ LLEXT_MEM_EXPORT
Exported symbol table.
Definition llext.h:49
struct _snode sys_snode_t
Single-linked list node structure.
Definition slist.h:39
Public kernel APIs.
__SIZE_TYPE__ ssize_t
Definition types.h:28
__UINTPTR_TYPE__ uintptr_t
Definition stdint.h:105
Relocation entry for 64-bit ELFs with addend.
Definition elf.h:369
Symbol table entry(64-bit)
Definition elf.h:236
Memory Domain.
Definition mem_domain.h:80
Memory Partition.
Definition mem_domain.h:55
Advanced llext_load parameters.
Definition llext.h:121
bool relocate_local
Perform local relocation.
Definition llext.h:123
bool pre_located
Use the virtual symbol addresses from the ELF, not addresses within the memory buffer,...
Definition llext.h:128
Linkable loadable extension loader context.
Definition loader.h:42
A symbol table.
Definition symbol.h:81
Structure describing a linkable loadable extension.
Definition llext.h:71
size_t mem_size[LLEXT_MEM_COUNT]
Size of each stored region.
Definition llext.h:92
struct llext_symtable sym_tab
Table of all global symbols in the extension; used internally as part of the linking process.
Definition llext.h:103
char name[16]
Name of the llext.
Definition llext.h:83
size_t alloc_size
Total llext allocation size.
Definition llext.h:95
unsigned int use_count
Extension use counter, prevents unloading while in use.
Definition llext.h:113
bool mem_on_heap[LLEXT_MEM_COUNT]
Is the memory for this region allocated on heap?
Definition llext.h:89
struct llext_symtable exp_tab
Table of symbols exported by the llext via LL_EXTENSION_SYMBOL.
Definition llext.h:110
void * mem[LLEXT_MEM_COUNT]
Lookup table of memory regions.
Definition llext.h:86
Linkable loadable extension symbol definitions.