Skip to content
ElfOpenFromMemoryCopy

ElfOpenFromMemoryCopy

Description

Parse an ELF object from an in-memory byte range – R-value / copy form (mirrors VecInsertR).

Parser allocates its own buffer through alloc and MemCopys the caller’s bytes in. The caller’s pointer is never retained: after this call returns, the caller’s buffer is theirs to do anything with (including free, mutate, or hand to another parser).

Parameters

Name Direction Description
out out Populated on success.
data in Raw ELF bytes. Read-only here; caller keeps them.
data_size in Length of data in bytes.
alloc in Allocator for the internal copy and the section / symbol vectors. Must outlive the Elf.

Success

Returns true; out owns an independent copy of data.

Failure

Returns false; logs the failing step. out is left zeroed and the caller’s data is untouched.

Usage example (Cross-references)

Usage examples (Cross-references)
    bool elf_open_from_memory_copy(Elf *out, const u8 *data, size data_size, Allocator *alloc) {
        if (!out || !data || !alloc) {
            LOG_FATAL("ElfOpenFromMemoryCopy: NULL argument (contract violation)");
        }
        Buf copy = BufInit(alloc);
        Buf copy = BufInit(alloc);
        if (!VecReserve(&copy, (u64)data_size)) {
            LOG_ERROR("ElfOpenFromMemoryCopy: allocation failed ({} bytes)", (u64)data_size);
            return false;
        }
Last updated on