Updated: 2022/Sep/29

Please read Privacy Policy. It's for your privacy.


MEMFD_CREATE(2)               System Calls Manual              MEMFD_CREATE(2)

NAME
     memfd_create - create anonymous files

LIBRARY
     Standard C Library (libc, -lc)

SYNOPSIS
     #include <sys/mman.h>

     int
     memfd_create(const char *name, unsigned int flags);

DESCRIPTION
     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_CLOEXEC        Set the close(2) on exec(3) flag.

     MFD_ALLOW_SEALING  Allow adding seals to the file descriptor using the
                        fcntl(2) F_ADD_SEALS command.

     Otherwise, the returned file descriptor behaves the same as a regular
     file, including the ability to be mapped by mmap(2).

RETURN VALUES
     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.

ERRORS
     memfd_create() will fail if:

     [EFAULT]           The argument name is NULL or points to invalid memory.

     [EINVAL]           The argument flags has any bits set other than
                        MFD_CLOEXEC or MFD_ALLOW_SEALING.

     [ENAMETOOLONG]     The length of name appended with the prefix "memfd:"
                        would exceed NAME_MAX.

     [ENFILE]           The system file table is full.

SEE ALSO
     fcntl(2), mmap(2), shmget(2), shm_open(3)

HISTORY
     memfd_create() is compatible with the Linux system call of the same name
     that first appeared in Linux 3.17.

NetBSD 10.99                     July 5, 2023                     NetBSD 10.99