ELF\_MEMORY(3) Libelf Programmer's Manual ELF\_MEMORY(3)

# [NAME](#NAME)

elf\_memory - create an ELF descriptor from a memory buffer

# [SYNOPSIS](#SYNOPSIS)

```
#include <libelf.h>
Elf * elf_memory(char *" image , size_t size );
```

# [DESCRIPTION](#DESCRIPTION)

The **elf\_memory**() function creates a new ELF descriptor from a memory region containing an ELF object. This function is used when the ELF data is already present in memory rather than being read from a file descriptor.

The memory pointed to by *image* must contain a complete ELF file or archive. The contents must remain valid and unmodified for the lifetime of the resulting ELF descriptor.

The ELF descriptor returned by **elf\_memory**() is opened in read-only mode using ELF\_C\_READ\_MMAP\_PRIVATE (see **elf\_begin**). The underlying memory image should not be directly modified by the application while its ELF descriptor is open. Some libelf functions, such as **elf\_compress**() and **gelf\_update\_\***(), may internally modify the underlying image and therefore require that the underlying image be writable. The use of a read-only image (e.g., memory mapped with **PROT\_READ** only) may result in failures or crashes.

# [PARAMETERS](#PARAMETERS)

[*image*](#image)

A pointer to a memory buffer that contains the complete contents of an ELF file or archive. If NULL, this function fails and returns NULL.

[*size*](#size)

The size in bytes of the memory region pointed to by *image*. Must be at least as much as a full ELF header and should cover the entire ELF object.

# [RETURN VALUE](#RETURN_VALUE)

On success, **elf\_memory**() returns a pointer to an **Elf** descriptor representing the archive or ELF file contained in *image*.

On failure, it returns NULL and sets an error code retrievable by [**elf\_errmsg**(3)](/man/os/elfutils/elf_errmsg.3).

# [SEE ALSO](#SEE_ALSO)

[**elf\_begin**(3)](/man/os/elfutils/elf_begin.3), [**elf\_errmsg**(3)](/man/os/elfutils/elf_errmsg.3), [**libelf**(3)](/man/os/elfutils/libelf.3), [**elf**(5)](/man/os/elfutils/elf.5)

# [ATTRIBUTES](#ATTRIBUTES)

**Interface Attribute Value** elf\_memory () Thread safety MT-Safe

# [REPORTING BUGS](#REPORTING_BUGS)

Report bugs to &lt;elfutils-devel@sourceware.org&gt; or https://sourceware.org/bugzilla/.

2025-06-23 Libelf

---

Document: elf_memory(3) from elfutils 0.197-r0 (Chainguard OS)
Source: https://sourceware.org/git/elfutils.git
