ELF_MEMORY(3)

πŸ“¦
version 0.197 Β· 2 versions
, in alpine 3.23, alpine 3.24, arch rolling, centos-stream 10, centos-stream 9, fedora 43, fedora 44, nixos 26.05, nixpkgs unstable, ubuntu resolute, ubuntu stonking

🌸 ELF_MEMORY(3) 🌸

okay so bestie, welcome to the Libelf Programmer's Manual πŸ’– this is the page for elf_memory, and it's literally the glow-up your ELF data deserves when it's already chillin' in RAM instead of sitting in a file somewhere.


✨ NAME ✨

elf_memory β€” create an ELF descriptor from a memory buffer 🧚


πŸ¦‹ SYNOPSIS πŸ¦‹

#include <libelf.h>

Elf * elf_memory(char *" image , size_t size );

(yes, that's exactly how it's written up there in the original, no cap, we do not touch the code πŸ’…)


πŸ’œ DESCRIPTION πŸ’œ

So elf_memory() makes you a brand new ELF descriptor, sourced straight from a memory region that's holding an ELF object. You reach for this one when the ELF data is already in memory and you're not about to go read it from a file descriptor like some kind of peasant. Iconic behavior honestly. πŸ‘‘

The memory that image points at must contain a complete ELF file or archive. And β€” this is the important part, bestie, underline it twice β€” those contents have to stay valid and unmodified for the whole lifetime of the resulting ELF descriptor. No take-backs, no sneaky edits, periodt. 🚫

The descriptor you get back from elf_memory() is opened in read-only mode using ELF_C_READ_MMAP_PRIVATE (peep elf_begin for the lore on that). So like, the underlying memory image should not be directly modified by your application while its ELF descriptor is open. Mind the gap. 🫢

⚠️ okay so here's where it gets spicy: some libelf functions, elf_compress() and gelf_update_*() for example, may internally modify the underlying image, which means they need that image to be writable. If you hand them a read-only image (like, say, one memory mapped with PROT_READ only), you can get failures or crashes. Not the cute kind of crash. The bad kind. 😭

πŸŽ€ PARAMETERS πŸŽ€

  • image β€” a pointer to a memory buffer holding the complete contents of an ELF file or archive. If it's NULL, this function fails and returns NULL. Rude but fair. πŸ™ˆ
  • size β€” how big, in bytes, the memory region pointed to by image is. It has to be at least as big as a full ELF header, and honestly it should cover the entire ELF object. Don't be stingy. ✨

🌈 RETURN VALUE 🌈

On success, elf_memory() hands you a pointer to an Elf descriptor representing the archive or ELF file contained in image. Slay. πŸ’…

On failure, it returns NULL and sets an error code you can retrieve with elf_errmsg(3). Go check it, bestie, it'll tell you what went wrong. πŸ”


πŸ‘€ SEE ALSO πŸ‘€


⭐ ATTRIBUTES ⭐

ngl bestie, this section is just… empty in the original. Nothing listed. A little mysterious, a little main character energy, we move on. πŸ’€


πŸ› REPORTING BUGS πŸ›

Found a bug? Spill the tea, they want to hear it:


that's the whole page, bestie β€” go forth and descriptor-ify responsibly πŸ¦‹πŸ’–βœ¨

Libelf Β· dated 2025-06-23 Β· ELF_MEMORY(3) β€” mwah, take care of her πŸŽ€

πŸ“¦ where this page comes from