ElfOpenFromMemory
Description
Parse an ELF object from an in-memory byte range – L-value / ownership-transfer form (mirrors VecInsertL).
Takes the caller’s Buf by pointer. The parser snapshots the Buf internally and zeroes the caller’s *in so any post-call use sees an empty Buf instead of a stale alias. The parser then owns the bytes and the buffer’s allocator; both are released by ElfDeinit. The zero-on-take invariant holds on both success and failure – on parse failure the parser still consumed the Buf, just frees it through the carried allocator before returning.
Parameters
| Name | Direction | Description |
|---|---|---|
out |
out | Populated on success. |
in |
in,out | Pointer to the caller’s Buf. in->data must be non-NULL and in->allocator must be set. After the call, *in is zeroed (success or failure). |
Usage example (from documentation)
Buf buf = BufInit(&alloc);
FileRead(&f, &buf);
ElfOpenFromMemory(&elf, &buf);
// buf is now {NULL, 0, 0, NULL} -- safe to drop on stack.
Success
Returns true; out owns the bytes; *in is zeroed.
Failure
Returns false; the bytes have been freed; *in is zeroed; out is left zeroed.
Usage example (Cross-references)
Usage examples (Cross-references)
- In
Elf.c:433:
// Anything that fails past the snapshot cleans up via ElfDeinit,
// so the buffer never leaks.
bool ElfOpenFromMemory(Elf *out, Buf *in) {
if (!out || !in || !in->data || !in->allocator) {
LOG_FATAL("ElfOpenFromMemory: NULL argument (contract violation)");- In
Elf.c:435:
bool ElfOpenFromMemory(Elf *out, Buf *in) {
if (!out || !in || !in->data || !in->allocator) {
LOG_FATAL("ElfOpenFromMemory: NULL argument (contract violation)");
}
Buf taken = *in;- In
Elf.c:474:
// Hand `©` to the L-form -- it consumes the local and zeros
// it. The local goes out of scope right after.
return ElfOpenFromMemory(out, ©);
}- In
Elf.c:487:
return false;
}
return ElfOpenFromMemory(out, &data);
}
Last updated on