Zephyr API Documentation  3.6.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
43
45};
46
47#define LLEXT_MEM_PARTITIONS (LLEXT_MEM_BSS+1)
48
49struct llext_loader;
50
54struct llext {
56 sys_snode_t _llext_list;
57
58#ifdef CONFIG_USERSPACE
59 struct k_mem_partition mem_parts[LLEXT_MEM_PARTITIONS];
60 struct k_mem_domain mem_domain;
61#endif
62
66 char name[16];
67
70
73
76
78 size_t alloc_size;
79
80 /*
81 * These are all global symbols in the extension, all of them don't
82 * have to be exported to other extensions, but this table is needed for
83 * faster internal linking, e.g. if the extension is built out of
84 * several files, if any symbols are referenced between files, this
85 * table will be used to link them.
86 */
88
91
93 unsigned int use_count;
94};
95
103struct llext *llext_by_name(const char *name);
104
116int llext_iterate(int (*fn)(struct llext *ext, void *arg), void *arg);
117
127};
128
129#define LLEXT_LOAD_PARAM_DEFAULT {.relocate_local = true,}
130
148int llext_load(struct llext_loader *loader, const char *name, struct llext **ext,
149 struct llext_load_param *ldr_parm);
150
156int llext_unload(struct llext **ext);
157
167const void *llext_find_sym(const struct llext_symtable *sym_table, const char *sym_name);
168
181int llext_call_fn(struct llext *ext, const char *sym_name);
182
195int llext_add_domain(struct llext *ext, struct k_mem_domain *domain);
196
215 uintptr_t sym_base_addr, const char *sym_name, uintptr_t load_bias);
223ssize_t llext_find_section(struct llext_loader *loader, const char *search_name);
224
234void arch_elf_relocate_local(struct llext_loader *loader, struct llext *ext,
235 const elf_rela_t *rel, const elf_sym_t *sym, size_t got_offset);
236
241#ifdef __cplusplus
242}
243#endif
244
245#endif /* ZEPHYR_LLEXT_H */
int llext_iterate(int(*fn)(struct llext *ext, void *arg), void *arg)
Iterate overall registered llext instances.
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 function for updating op codes given a relocation.
ssize_t llext_find_section(struct llext_loader *loader, const char *search_name)
Find an ELF section.
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 the known memory partitions of the extension to a memory domain.
#define LLEXT_MEM_PARTITIONS
Definition: llext.h:47
llext_mem
List of ELF regions that are stored or referenced in the llext.
Definition: llext.h:34
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 name.
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
Definition: llext.h:40
@ LLEXT_MEM_SHSTRTAB
Definition: llext.h:42
@ LLEXT_MEM_TEXT
Definition: llext.h:35
@ LLEXT_MEM_DATA
Definition: llext.h:36
@ LLEXT_MEM_BSS
Definition: llext.h:38
@ LLEXT_MEM_RODATA
Definition: llext.h:37
@ LLEXT_MEM_COUNT
Definition: llext.h:44
@ LLEXT_MEM_STRTAB
Definition: llext.h:41
@ LLEXT_MEM_EXPORT
Definition: llext.h:39
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
Definition: elf.h:340
Symbol table entry(64-bit)
Definition: elf.h:232
Memory Domain.
Definition: mem_domain.h:80
Memory Partition.
Definition: mem_domain.h:55
llext loader parameters
Definition: llext.h:124
bool relocate_local
Should local relocation be performed.
Definition: llext.h:126
Linkable loadable extension loader context.
Definition: loader.h:29
A symbol table.
Definition: symbol.h:60
Linkable loadable extension.
Definition: llext.h:54
size_t mem_size[LLEXT_MEM_COUNT]
Size of each stored section.
Definition: llext.h:75
struct llext_symtable sym_tab
Definition: llext.h:87
char name[16]
Name of the llext.
Definition: llext.h:66
size_t alloc_size
Total llext allocation size.
Definition: llext.h:78
unsigned int use_count
Extension use counter, prevents unloading while in use.
Definition: llext.h:93
bool mem_on_heap[LLEXT_MEM_COUNT]
Is the memory for this section allocated on heap?
Definition: llext.h:72
struct llext_symtable exp_tab
Exported symbols from the llext, may be linked against by other llext.
Definition: llext.h:90
void * mem[LLEXT_MEM_COUNT]
Lookup table of llext memory regions.
Definition: llext.h:69