Zephyr Project API 4.1.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
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 return (const char *)ext->mem[mem_idx] + idx;
36}
37
38static inline uintptr_t llext_get_reloc_instruction_location(struct llext_loader *ldr,
39 struct llext *ext,
40 int shndx,
41 const elf_rela_t *rela)
42{
43 return (uintptr_t) llext_loaded_sect_ptr(ldr, ext, shndx) + rela->r_offset;
44}
45
46static inline const char *llext_section_name(const struct llext_loader *ldr,
47 const struct llext *ext,
48 const elf_shdr_t *shdr)
49{
50 return llext_string(ldr, ext, LLEXT_MEM_SHSTRTAB, shdr->sh_name);
51}
52
53static inline const char *llext_symbol_name(const struct llext_loader *ldr,
54 const struct llext *ext,
55 const elf_sym_t *sym)
56{
57 if (ELF_ST_TYPE(sym->st_info) == STT_SECTION) {
58 return llext_section_name(ldr, ext, ext->sect_hdrs + sym->st_shndx);
59 } else {
60 return llext_string(ldr, ext, LLEXT_MEM_STRTAB, sym->st_name);
61 }
62}
63
64/*
65 * Determine address of a symbol.
66 */
67int llext_lookup_symbol(struct llext_loader *ldr, struct llext *ext, uintptr_t *link_addr,
68 const elf_rela_t *rel, const elf_sym_t *sym, const char *name,
69 const elf_shdr_t *shdr);
70
71/*
72 * Read the symbol entry corresponding to a relocation from the binary.
73 */
74int llext_read_symbol(struct llext_loader *ldr, struct llext *ext, const elf_rela_t *rel,
75 elf_sym_t *sym);
76
79#ifdef __cplusplus
80}
81#endif
82
83#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:52
@ LLEXT_MEM_STRTAB
Symbol name strings.
Definition llext.h:51
#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
Support for linkable loadable extensions.
__UINTPTR_TYPE__ uintptr_t
Definition stdint.h:105
Relocation entry for 64-bit ELFs with addend.
Definition elf.h:376
elf64_addr r_offset
Offset in the section to perform a relocation.
Definition elf.h:378
Section Header(64-bit)
Definition elf.h:177
elf64_word sh_name
Section header name index in section header string table.
Definition elf.h:179
Symbol table entry(64-bit)
Definition elf.h:243
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
Linkable loadable extension loader context.
Definition loader.h:80
Structure describing a linkable loadable extension.
Definition llext.h:80
void * mem[LLEXT_MEM_COUNT]
Lookup table of memory regions.
Definition llext.h:95