Zephyr API Documentation 4.4.99
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_LLEXT_INTERNAL_H
8#define ZEPHYR_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};
28
29const void *llext_loaded_sect_ptr(struct llext_loader *ldr, struct llext *ext, unsigned int sh_ndx);
30
31
32static inline const char *llext_string(const struct llext_loader *ldr, const struct llext *ext,
33 enum llext_mem mem_idx, unsigned int idx)
34{
35 if (idx >= ext->mem_size[mem_idx]) {
36 return NULL;
37 }
38
39 return (const char *)ext->mem[mem_idx] + idx;
40}
41
42static inline uintptr_t llext_get_reloc_instruction_location(struct llext_loader *ldr,
43 struct llext *ext,
44 int shndx,
45 const elf_rela_t *rela)
46{
47 return (uintptr_t) llext_loaded_sect_ptr(ldr, ext, shndx) + rela->r_offset;
48}
49
50static inline const char *llext_section_name(const struct llext_loader *ldr,
51 const struct llext *ext,
52 const elf_shdr_t *shdr)
53{
54 return llext_string(ldr, ext, LLEXT_MEM_SHSTRTAB, shdr->sh_name);
55}
56
57static inline const char *llext_symbol_name(const struct llext_loader *ldr,
58 const struct llext *ext,
59 const elf_sym_t *sym)
60{
61 if (ELF_ST_TYPE(sym->st_info) == STT_SECTION) {
62 if (sym->st_shndx >= ext->sect_cnt) {
63 return NULL;
64 }
65 return llext_section_name(ldr, ext, ext->sect_hdrs + sym->st_shndx);
66 } else {
67 return llext_string(ldr, ext, LLEXT_MEM_STRTAB, sym->st_name);
68 }
69}
70
71/*
72 * Determine address of a symbol.
73 */
74int llext_lookup_symbol(struct llext_loader *ldr, struct llext *ext, uintptr_t *link_addr,
75 const elf_rela_t *rel, const elf_sym_t *sym, const char *name,
76 const elf_shdr_t *shdr);
77
78/*
79 * Read the symbol entry corresponding to a relocation from the binary.
80 */
81int llext_read_symbol(struct llext_loader *ldr, struct llext *ext, const elf_rela_t *rel,
82 elf_sym_t *sym);
83
85
97int arch_elf_veneer_init(struct llext_loader *ldr, struct llext *ext);
98
110int arch_elf_relocate_local(struct llext_loader *loader, struct llext *ext, const elf_rela_t *rel,
111 const elf_sym_t *sym, uint8_t *rel_addr,
112 const struct llext_load_param *ldr_parm);
113
125int arch_elf_relocate_global(struct llext_loader *loader, struct llext *ext, const elf_rela_t *rel,
126 const elf_sym_t *sym, uint8_t *rel_addr, const void *link_addr);
127
128#ifdef __cplusplus
129}
130#endif
131
132#endif /* ZEPHYR_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:477
#define ELF_ST_TYPE
Machine sized macro alias for obtaining a symbol type.
Definition elf.h:485
#define STT_SECTION
Section.
Definition elf.h:269
struct elf64_shdr elf_shdr_t
Machine sized section header structure.
Definition elf.h:463
struct elf64_rela elf_rela_t
Machine sized relocation struct with addend.
Definition elf.h:475
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:378
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:251
unsigned char st_info
Symbol binding and type information.
Definition elf.h:247
elf64_word st_name
Name of the symbol as an index into the symbol string table.
Definition elf.h:245
Advanced llext_load parameters.
Definition llext.h:185
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