| MEMFD_CREATE(2) | System Calls Manual | MEMFD_CREATE(2) |
memfd_create —
create anonymous files
Standard C Library (libc, -lc)
#include
<sys/mman.h>
int
memfd_create(const
char *name, unsigned int
flags);
The
memfd_create()
system call returns a file descriptor to a file named
name backed only by RAM. Initially, the size of the
file is zero.
The length of name must not exceed
NAME_MAX-6 characters in length, to allow for the
prefix “memfd:” to be added. But since the file descriptor
does not live on disk, name does not have to be
unique. name is only intended to be used for debugging
purposes and commands like
fstat(1).
Additionally, any of the following may be specified as the flags:
MFD_CLOEXECMFD_CLOFORKMFD_ALLOW_SEALINGF_ADD_SEALS command.Otherwise, the returned file descriptor behaves the same as a regular file, including the ability to be mapped by mmap(2).
If successful, the memfd_create() system
call returns a non-negative integer. On failure -1 is returned and
errno is set to indicate the error.
memfd_create() will fail if:
EFAULT]NULL or
points to invalid memory.EINVAL]MFD_CLOEXEC, MFD_CLOFORK,
or MFD_ALLOW_SEALING.ENAMETOOLONG]NAME_MAX.ENFILE]memfd_create() is compatible with the
Linux system call of the same name that first appeared in Linux 3.17. It was
added in NetBSD 11.0.
| November 14, 2025 | NetBSD 11.0 |