21typedef enum : uint32_t {
62 return (uint16_t)((uint16_t)bytes[0] | ((uint16_t)bytes[1] << 8U));
80 return (uint32_t)bytes[0] | ((uint32_t)bytes[1] << 8U) | ((uint32_t)bytes[2] << 16U) |
140 const uint64_t table_bytes = (uint64_t)decoded.
entry_size * decoded.
count;
171 const uint64_t offset = (uint64_t)sections->
offset + ((uint64_t)index * sections->
entry_size);
203 (link >= sections->
count) || ((uint64_t)symbol_off > elf->
length) ||
204 ((uint64_t)symbol_sz > (elf->
length - symbol_off))) {
213 if (((uint64_t)string_off > elf->
length) || ((uint64_t)string_sz > (elf->
length - string_off))) {
217 .symbol_offset = symbol_off,
218 .symbol_count = symbol_sz / entry_sz,
219 .entry_size = entry_sz,
220 .string_offset = string_off,
221 .string_size = string_sz,
250 for (uint32_t index = 0U; index < table->
symbol_count; index++) {
261 .name_offset = (uint64_t)table->
string_offset + relative_name,
267 if (!fn(&symbol, ctx)) {
276 if ((elf ==
nullptr) || (fn ==
nullptr)) {
283 uint32_t visited = 0U;
284 for (uint32_t index = 0U; index < sections.
count; index++) {
303 if ((elf ==
nullptr) || (fn ==
nullptr) || ((uint64_t)offset >= elf->
length)) {
307 uint64_t cursor = offset;
308 while (cursor < elf->length) {
309 const uint64_t remaining = elf->
length - cursor;
310 const size_t chunk = (remaining <
sizeof(bytes)) ? (
size_t)remaining :
sizeof(bytes);
314 const uint8_t*
const end = (
const uint8_t*)
memchr(bytes, 0, chunk);
315 const size_t length = (end ==
nullptr) ? chunk : (size_t)(end - bytes);
316 if ((length > 0U) && !fn((
const char*)bytes, length, ctx)) {
319 if (end !=
nullptr) {
356 match->
equal =
false;
391 const bool complete =
403 if (size_out !=
nullptr) {
406 if ((elf ==
nullptr) || (name ==
nullptr)) {
411 if ((lookup.
address != 0U) && (size_out !=
nullptr)) {
412 *size_out = lookup.
size;
@ k_elf_data_offset
ELF identification data-byte offset.
@ k_elf_word_high_shift
Shift of byte three in a word.
ELF32 image services for the board emulator (load / symbols / vectors).
bool(* emu_elf_string_fn)(const char *bytes, size_t length, void *ctx)
Callback receiving one non-empty chunk of an ELF string.
@ k_elf_shentsize_min
ELF32 section-header entry size.
@ k_elf_sh_entsize_off
sh_entsize in a section header.
@ k_elf_sym_info_off
st_info in a symbol-table entry.
@ k_elf_sh_link_off
sh_link in a section header.
@ k_elf_ehdr_size
ELF32 file-header size.
@ k_elf_sh_size_off
sh_size in a section header.
bool(* emu_elf_symbol_fn)(const emu_elf_symbol_t *symbol, void *ctx)
Callback invoked for each bounds-checked ELF symbol entry.
@ k_emu_elf_io_ok
The complete operation succeeded.
Private raw-descriptor ELF source operations.
emu_elf_io_result_t priv_emu_elf_read(const emu_elf_source_t *source, uint64_t offset, size_t required_bytes, void *scratch, size_t supplied_bytes, emu_elf_view_t *view)
Read one exact source range into caller-owned bounded scratch.
bool elf_string_foreach(const emu_elf_source_t *elf, uint64_t offset, emu_elf_string_fn fn, void *ctx)
Stream one NUL-terminated ELF string through bounded stack chunks.
static RA8_INTERNAL bool internal_section_table(const emu_elf_source_t *elf, emu_elf_section_table_t *table)
Decode and validate section-header table geometry.
static RA8_INTERNAL bool internal_symbol_walk(const emu_elf_source_t *elf, const emu_elf_symbol_table_t *table, emu_elf_symbol_fn fn, void *ctx, uint32_t *visited)
Walk every entry of one validated symbol table.
static RA8_INTERNAL bool internal_lookup_symbol(const emu_elf_symbol_t *symbol, void *opaque)
Compare one symbol name and stop on an exact hit.
uint32_t elf_sym_addr(const emu_elf_source_t *elf, const char *name, uint32_t *size_out)
Resolve a function symbol's entry address from the ELF .symtab.
static RA8_INTERNAL bool internal_section_read(const emu_elf_source_t *elf, const emu_elf_section_table_t *sections, uint32_t index, uint8_t bytes[k_elf_shentsize_min])
Read one section header from validated table geometry.
emu_elf_symbol_limit_t
Fixed bytes consumed from section and symbol entries.
@ k_elf_string_chunk
Transient streamed-name bytes.
@ k_elf_symbol_entry_min
ELF32 symbol bytes consumed.
@ k_elf_section_count_offset
Section-count header offset.
@ k_elf_sht_symtab
SHT_SYMTAB section type.
@ k_elf_shentsize_offset
Section-entry-size header offset.
static RA8_INTERNAL uint16_t internal_symbol_u16(const uint8_t *bytes)
Decode one little-endian 16-bit field.
static RA8_INTERNAL bool internal_symbol_table(const emu_elf_source_t *elf, const emu_elf_section_table_t *sections, const uint8_t bytes[k_elf_shentsize_min], emu_elf_symbol_table_t *table)
Decode one SHT_SYMTAB and its linked string-table bounds.
uint32_t elf_foreach_symbol(const emu_elf_source_t *elf, emu_elf_symbol_fn fn, void *ctx)
Walk every symbol in every usable SHT_SYMTAB section.
static RA8_INTERNAL uint32_t internal_symbol_u32(const uint8_t *bytes)
Decode one little-endian 32-bit field without alignment assumptions.
static RA8_INTERNAL bool internal_name_chunk(const char *bytes, size_t length, void *opaque)
Compare one streamed source-name chunk with the expected suffix.
static RA8_INTERNAL bool internal_symbol_read(const emu_elf_source_t *elf, uint64_t offset, uint8_t *bytes, size_t length)
Read one fixed-size source object into supplied scratch.
#define RA8_INTERNAL
Marker that a function is intended to be static (file-local).
void * memchr(const void *s, int c, size_t n)
Locate a byte in a memory area.
int memcmp(const void *a, const void *b, size_t n)
Compare bytes in two memory areas.
size_t strlen(const char *s)
Calculate string length.
emu_elf_io_status_t status
Semantic completion status.
Symbol-address lookup callback state.
size_t length
Expected name length.
const char * name
Expected symbol name.
uint32_t size
Resolved symbol size.
uint32_t address
Resolved Thumb-cleared value.
const emu_elf_source_t * source
Open source for name streaming.
Incremental exact string comparison state.
const char * expected
Expected NUL-terminated name.
size_t compared
Bytes compared so far.
bool equal
Sticky exact-prefix equality.
size_t length
Expected length excluding NUL.
Decoded section-header table geometry.
uint16_t count
Section-header entry count.
uint32_t offset
First section-header file offset.
uint16_t entry_size
Bytes per section-header entry.
One independently owned immutable raw-descriptor ELF source.
uint64_t length
Stat-derived parsing bound.
One bounds-checked symbol-table entry plus its string offset.
uint64_t name_offset
Absolute source offset of the NUL-terminated name.
uint32_t size
Symbol byte extent.
uint32_t value
Symbol value.
Decoded usable symbol/string table pair.
uint32_t string_offset
Linked string-table file offset.
uint32_t symbol_count
Number of whole symbol entries.
uint32_t entry_size
Bytes per symbol entry.
uint32_t string_size
Linked string-table byte count.
uint32_t symbol_offset
First symbol entry file offset.
Transient view into caller-owned bounded scratch.