Zephyr API Documentation  3.6.0
A Scalable Open Source RTOS
3.6.0
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
llext.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2023 Intel Corporation
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7#ifndef ZEPHYR_LLEXT_H
8#define ZEPHYR_LLEXT_H
9
10#include <zephyr/sys/slist.h>
11#include <zephyr/llext/elf.h>
12#include <zephyr/llext/symbol.h>
13#include <zephyr/kernel.h>
14#include <sys/types.h>
15#include <stdbool.h>
16
17#ifdef __cplusplus
18extern "C" {
19#endif
20
40
42};
43
44#define LLEXT_MEM_PARTITIONS (LLEXT_MEM_BSS+1)
45
46struct llext_loader;
47
51struct llext {
53 sys_snode_t _llext_list;
54
55#ifdef CONFIG_USERSPACE
56 struct k_mem_partition mem_parts[LLEXT_MEM_PARTITIONS];
57 struct k_mem_domain mem_domain;
58#endif
59
63 char name[16];
64
67
70
73
75 size_t alloc_size;
76
77 /*
78 * These are all global symbols in the extension, all of them don't
79 * have to be exported to other extensions, but this table is needed for
80 * faster internal linking, e.g. if the extension is built out of
81 * several files, if any symbols are referenced between files, this
82 * table will be used to link them.
83 */
85
88
90 unsigned int use_count;
91};
92
100struct llext *llext_by_name(const char *name);
101
113int llext_iterate(int (*fn)(struct llext *ext, void *arg), void *arg);
114
124};
125
126#define LLEXT_LOAD_PARAM_DEFAULT {.relocate_local = true,}
127
144int llext_load(struct llext_loader *loader, const char *name, struct llext **ext,
145 struct llext_load_param *ldr_parm);
146
152int llext_unload(struct llext **ext);
153
163const void * const llext_find_sym(const struct llext_symtable *sym_table, const char *sym_name);
164
177int llext_call_fn(struct llext *ext, const char *sym_name);
178
191int llext_add_domain(struct llext *ext, struct k_mem_domain *domain);
192
207
215ssize_t llext_find_section(struct llext_loader *loader, const char *search_name);
216
225void arch_elf_relocate_local(struct llext_loader *loader, struct llext *ext,
226 elf_rela_t *rel, size_t got_offset);
227
232#ifdef __cplusplus
233}
234#endif
235
236#endif /* ZEPHYR_LLEXT_H */
int llext_iterate(int(*fn)(struct llext *ext, void *arg), void *arg)
Iterate overall registered llext instances.
const void *const llext_find_sym(const struct llext_symtable *sym_table, const char *sym_name)
Find the address for an arbitrary symbol name.
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, elf_rela_t *rel, 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:44
llext_mem
List of ELF regions that are stored or referenced in the llext.
Definition: llext.h:31
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.
void arch_elf_relocate(elf_rela_t *rel, uintptr_t opaddr, uintptr_t opval)
Architecture specific function for updating op codes given a relocation.
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:37
@ LLEXT_MEM_SHSTRTAB
Definition: llext.h:39
@ LLEXT_MEM_TEXT
Definition: llext.h:32
@ LLEXT_MEM_DATA
Definition: llext.h:33
@ LLEXT_MEM_BSS
Definition: llext.h:35
@ LLEXT_MEM_RODATA
Definition: llext.h:34
@ LLEXT_MEM_COUNT
Definition: llext.h:41
@ LLEXT_MEM_STRTAB
Definition: llext.h:38
@ LLEXT_MEM_EXPORT
Definition: llext.h:36
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:339
Memory Domain.
Definition: mem_domain.h:80
Memory Partition.
Definition: mem_domain.h:55
llext loader parameters
Definition: llext.h:121
bool relocate_local
Should local relocation be performed.
Definition: llext.h:123
Linkable loadable extension loader context.
Definition: loader.h:29
A symbol table.
Definition: symbol.h:60
Linkable loadable extension.
Definition: llext.h:51
size_t mem_size[LLEXT_MEM_COUNT]
Size of each stored section.
Definition: llext.h:72
struct llext_symtable sym_tab
Definition: llext.h:84
char name[16]
Name of the llext.
Definition: llext.h:63
size_t alloc_size
Total llext allocation size.
Definition: llext.h:75
unsigned int use_count
Extension use counter, prevents unloading while in use.
Definition: llext.h:90
bool mem_on_heap[LLEXT_MEM_COUNT]
Is the memory for this section allocated on heap?
Definition: llext.h:69
struct llext_symtable exp_tab
Exported symbols from the llext, may be linked against by other llext.
Definition: llext.h:87
void * mem[LLEXT_MEM_COUNT]
Lookup table of llext memory regions.
Definition: llext.h:66