Zephyr Project API 4.5.0-rc2
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
llext_internal.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2024 Intel Corporation
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7#ifndef ZEPHYR_INCLUDE_LLEXT_LLEXT_INTERNAL_H_
8#define ZEPHYR_INCLUDE_LLEXT_LLEXT_INTERNAL_H_
9
10#ifdef __cplusplus
11extern "C" {
12#endif
13
14#include <zephyr/llext/llext.h>
15
20
22
23
24struct llext_elf_sect_map {
25 enum llext_mem mem_idx;
26 size_t offset;
27 bool detached;
28};
29
30const void *llext_loaded_sect_ptr(struct llext_loader *ldr, struct llext *ext, unsigned int sh_ndx);
31
32
33static inline const char *llext_string(const struct llext_loader *ldr, const struct llext *ext,
34 enum llext_mem mem_idx, unsigned int idx)
35{
36 if (idx >= ext->mem_size[mem_idx]) {
37 return NULL;
38 }
39
40 return (const char *)ext->mem[mem_idx] + idx;
41}
42
43static inline uintptr_t llext_get_reloc_instruction_location(struct llext_loader *ldr,
44 struct llext *ext,
45 int shndx,
46 const elf_rela_t *rela)
47{
48 return (uintptr_t) llext_loaded_sect_ptr(ldr, ext, shndx) + rela->r_offset;
49}
50
51static inline const char *llext_section_name(const struct llext_loader *ldr,
52 const struct llext *ext,
53 const elf_shdr_t *shdr)
54{
55 return llext_string(ldr, ext, LLEXT_MEM_SHSTRTAB, shdr->sh_name);
56}
57
58static inline const char *llext_symbol_name(const struct llext_loader *ldr,
59 const struct llext *ext,
60 const elf_sym_t *sym)
61{
62 if (ELF_ST_TYPE(sym->st_info) == STT_SECTION) {
63 if (sym->st_shndx >= ext->sect_cnt) {
64 return NULL;
65 }
66 return llext_section_name(ldr, ext, ext->sect_hdrs + sym->st_shndx);
67 } else {
68 return llext_string(ldr, ext, LLEXT_MEM_STRTAB, sym->st_name);
69 }
70}
71
72/*
73 * Determine address of a symbol.
74 */
75int llext_lookup_symbol(struct llext_loader *ldr, struct llext *ext, uintptr_t *link_addr,
76 const elf_rela_t *rel, const elf_sym_t *sym, const char *name,
77 const elf_shdr_t *shdr);
78
79/*
80 * Read the symbol entry corresponding to a relocation from the binary.
81 */
82int llext_read_symbol(struct llext_loader *ldr, struct llext *ext, const elf_rela_t *rel,
83 elf_sym_t *sym);
84
86
98int arch_elf_veneer_init(struct llext_loader *ldr, struct llext *ext);
99
111int arch_elf_relocate_local(struct llext_loader *loader, struct llext *ext, const elf_rela_t *rel,
112 const elf_sym_t *sym, uint8_t *rel_addr,
113 const struct llext_load_param *ldr_parm);
114
126int arch_elf_relocate_global(struct llext_loader *loader, struct llext *ext, const elf_rela_t *rel,
127 const elf_sym_t *sym, uint8_t *rel_addr, const void *link_addr);
128
129#ifdef __cplusplus
130}
131#endif
132
133#endif /* ZEPHYR_INCLUDE_LLEXT_LLEXT_INTERNAL_H_ */
llext_mem
List of memory regions stored or referenced in the LLEXT subsystem.
Definition llext.h:44
@ LLEXT_MEM_SHSTRTAB
Section name strings.
Definition llext.h:55
@ LLEXT_MEM_STRTAB
Symbol name strings.
Definition llext.h:54
struct elf64_sym elf_sym_t
Machine sized symbol struct.
Definition elf.h:479
#define ELF_ST_TYPE
Machine sized macro alias for obtaining a symbol type.
Definition elf.h:487
#define STT_SECTION
Section.
Definition elf.h:271
struct elf64_shdr elf_shdr_t
Machine sized section header structure.
Definition elf.h:465
struct elf64_rela elf_rela_t
Machine sized relocation struct with addend.
Definition elf.h:477
#define NULL
Definition iar_missing_defs.h:20
Support for linkable loadable extensions.
int 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.
int 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.
int arch_elf_veneer_init(struct llext_loader *ldr, struct llext *ext)
Architecture specific function for initializing the veneer table.
__UINT8_TYPE__ uint8_t
Definition stdint.h:88
__UINTPTR_TYPE__ uintptr_t
Definition stdint.h:105
elf64_addr r_offset
Offset in the section to perform a relocation.
Definition elf.h:380
elf64_word sh_name
Section header name index in section header string table.
Definition elf.h:179
elf64_half st_shndx
Symbols related section given by section header index.
Definition elf.h:253
unsigned char st_info
Symbol binding and type information.
Definition elf.h:249
elf64_word st_name
Name of the symbol as an index into the symbol string table.
Definition elf.h:247
Advanced llext_load parameters.
Definition llext.h:203
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