Zephyr API Documentation 4.1.99
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
59
62/* Number of memory partitions used by LLEXT */
63#define LLEXT_MEM_PARTITIONS (LLEXT_MEM_BSS+1)
64
65struct llext_loader;
68/* Maximim number of dependency LLEXTs */
69#define LLEXT_MAX_DEPENDENCIES 8
70
77struct llext {
79 sys_snode_t _llext_list;
80
81#ifdef CONFIG_USERSPACE
82 struct k_mem_partition mem_parts[LLEXT_MEM_PARTITIONS];
83 struct k_mem_domain mem_domain;
84#endif
85
89 char name[16];
90
93
96
99
102
110
117
119 unsigned int use_count;
120
123
125 unsigned int sect_cnt;
126 elf_shdr_t *sect_hdrs;
127 bool sect_hdrs_on_heap;
129};
130
131static inline const elf_shdr_t *llext_section_headers(const struct llext *ext)
132{
133 return ext->sect_hdrs;
134}
135
136static inline unsigned int llext_section_count(const struct llext *ext)
137{
138 return ext->sect_cnt;
139}
140
175
177#define LLEXT_LOAD_PARAM_DEFAULT { .relocate_local = true, }
178
185struct llext *llext_by_name(const char *name);
186
198int llext_iterate(int (*fn)(struct llext *ext, void *arg), void *arg);
199
215int llext_load(struct llext_loader *loader, const char *name, struct llext **ext,
216 const struct llext_load_param *ldr_parm);
217
223int llext_unload(struct llext **ext);
224
236int llext_free_inspection_data(struct llext_loader *ldr, struct llext *ext);
237
239typedef void (*llext_entry_fn_t)(void *user_data);
240
252int llext_bringup(struct llext *ext);
253
266int llext_teardown(struct llext *ext);
267
284void llext_bootstrap(struct llext *ext, llext_entry_fn_t entry_fn, void *user_data);
285
304__syscall ssize_t llext_get_fn_table(struct llext *ext, bool is_init, void *buf, size_t size);
305
318const void *llext_find_sym(const struct llext_symtable *sym_table, const char *sym_name);
319
332int llext_call_fn(struct llext *ext, const char *sym_name);
333
347int llext_add_domain(struct llext *ext, struct k_mem_domain *domain);
348
368int arch_elf_relocate(struct llext_loader *ldr, struct llext *ext, elf_rela_t *rel,
369 const elf_shdr_t *shdr);
370
380ssize_t llext_find_section(struct llext_loader *loader, const char *search_name);
381
395int llext_get_section_header(struct llext_loader *loader, struct llext *ext,
396 const char *search_name, elf_shdr_t *shdr);
397
408void arch_elf_relocate_local(struct llext_loader *loader, struct llext *ext, const elf_rela_t *rel,
409 const elf_sym_t *sym, uint8_t *rel_addr,
410 const struct llext_load_param *ldr_parm);
411
422void arch_elf_relocate_global(struct llext_loader *loader, struct llext *ext, const elf_rela_t *rel,
423 const elf_sym_t *sym, uint8_t *rel_addr, const void *link_addr);
424
429#ifdef __cplusplus
430}
431#endif
432
433#include <zephyr/syscalls/llext.h>
434
435#endif /* ZEPHYR_LLEXT_H */
int llext_bringup(struct llext *ext)
Calls bringup functions for an extension.
#define LLEXT_MAX_DEPENDENCIES
Definition llext.h:69
int llext_load(struct llext_loader *loader, const char *name, struct llext **ext, const struct llext_load_param *ldr_parm)
Load and link an extension.
static unsigned int llext_section_count(const struct llext *ext)
Definition llext.h:136
void(* llext_entry_fn_t)(void *user_data)
Entry point function signature for an extension.
Definition llext.h:239
int llext_iterate(int(*fn)(struct llext *ext, void *arg), void *arg)
Iterate over all loaded extensions.
ssize_t llext_get_fn_table(struct llext *ext, bool is_init, void *buf, size_t size)
Get pointers to setup or cleanup functions for an extension.
static const elf_shdr_t * llext_section_headers(const struct llext *ext)
Definition llext.h:131
int llext_get_section_header(struct llext_loader *loader, struct llext *ext, const char *search_name, elf_shdr_t *shdr)
Extract ELF section header by name.
ssize_t llext_find_section(struct llext_loader *loader, const char *search_name)
Locates an ELF section in the file.
int llext_free_inspection_data(struct llext_loader *ldr, struct llext *ext)
Free any inspection-related memory for the specified loader and extension.
int llext_add_domain(struct llext *ext, struct k_mem_domain *domain)
Add an extension to a memory domain.
void llext_bootstrap(struct llext *ext, llext_entry_fn_t entry_fn, void *user_data)
Bring up, execute, and teardown an extension.
void arch_elf_relocate_global(struct llext_loader *loader, struct llext *ext, const elf_rela_t *rel, const elf_sym_t *sym, uint8_t *rel_addr, const void *link_addr)
Architecture specific function for global binding relocations.
llext_mem
List of memory regions stored or referenced in the LLEXT subsystem.
Definition llext.h:44
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.
int llext_teardown(struct llext *ext)
Calls teardown functions for an extension.
int arch_elf_relocate(struct llext_loader *ldr, struct llext *ext, elf_rela_t *rel, const elf_shdr_t *shdr)
Architecture specific opcode update function.
void arch_elf_relocate_local(struct llext_loader *loader, struct llext *ext, const elf_rela_t *rel, const elf_sym_t *sym, uint8_t *rel_addr, const struct llext_load_param *ldr_parm)
Architecture specific function for local binding relocations.
@ 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_PREINIT
Array of early setup functions.
Definition llext.h:53
@ LLEXT_MEM_BSS
Uninitialized data.
Definition llext.h:48
@ LLEXT_MEM_RODATA
Read-only data.
Definition llext.h:47
@ LLEXT_MEM_INIT
Array of setup functions.
Definition llext.h:54
@ LLEXT_MEM_FINI
Array of cleanup functions.
Definition llext.h:55
@ LLEXT_MEM_COUNT
Number of regions managed by LLEXT.
Definition llext.h:57
@ 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
Data structures and constants defined in the ELF specification.
#define bool
Definition stdbool.h:13
__UINT8_TYPE__ uint8_t
Definition stdint.h:88
Relocation entry for 64-bit ELFs with addend.
Definition elf.h:374
Section Header(64-bit)
Definition elf.h:177
Symbol table entry(64-bit)
Definition elf.h:241
Memory Domain.
Definition mem_domain.h:80
Memory Partition.
Definition mem_domain.h:55
Advanced llext_load parameters.
Definition llext.h:146
bool relocate_local
Perform local relocation.
Definition llext.h:148
bool pre_located
Use the virtual symbol addresses from the ELF, not addresses within the memory buffer,...
Definition llext.h:157
bool keep_section_info
Keep the ELF section data in memory after loading the extension.
Definition llext.h:173
bool(* section_detached)(const elf_shdr_t *shdr)
Extensions can implement custom ELF sections to be loaded in specific memory regions,...
Definition llext.h:164
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:77
size_t mem_size[LLEXT_MEM_COUNT]
Size of each stored region.
Definition llext.h:98
struct llext_symtable sym_tab
Table of all global symbols in the extension; used internally as part of the linking process.
Definition llext.h:109
char name[16]
Name of the llext.
Definition llext.h:89
size_t alloc_size
Total llext allocation size.
Definition llext.h:101
unsigned int use_count
Extension use counter, prevents unloading while in use.
Definition llext.h:119
struct llext * dependency[8]
Array of extensions, whose symbols this extension accesses.
Definition llext.h:122
bool mem_on_heap[LLEXT_MEM_COUNT]
Is the memory for this region allocated on heap?
Definition llext.h:95
struct llext_symtable exp_tab
Table of symbols exported by the llext via LL_EXTENSION_SYMBOL.
Definition llext.h:116
void * mem[LLEXT_MEM_COUNT]
Lookup table of memory regions.
Definition llext.h:92
Linkable loadable extension symbol definitions.