.\" <http://www.gnu.org/licenses/>.
.\" %%%LICENSE_END
.\"
-.TH MEMFD_CREATE 2 2016-10-08 Linux "Linux Programmer's Manual"
+.TH MEMFD_CREATE 2 2018-02-02 Linux "Linux Programmer's Manual"
.SH NAME
memfd_create \- create an anonymous file
.SH SYNOPSIS
-.B #include <sys/memfd.h>
+.nf
+.BR "#define _GNU_SOURCE" " /* See feature_test_macros(7) */"
+.B #include <sys/mman.h>
.PP
.BI "int memfd_create(const char *" name ", unsigned int " flags ");"
-.PP
-.IR Note :
-There is no glibc wrapper for this system call; see NOTES.
.SH DESCRIPTION
.BR memfd_create ()
creates an anonymous file and returns a file descriptor that refers to it.
meaning that no other seals can be set on the file.
.\" FIXME Why is the MFD_ALLOW_SEALING behavior not simply the default?
.\" Is it worth adding some text explaining this?
+.TP
+.BR MFD_HUGETLB " (since Linux 4.14)"
+.\" commit 749df87bd7bee5a79cef073f5d032ddb2b211de8
+The anonymous file will be created in the hugetlbfs filesystem using
+huge pages.
+See the Linux kernel source file
+.I Documentation/admin-guide/mm/hugetlbpage.rst
+for more information about hugetlbfs.
+.\" commit 47b9012ecdc747f6936395265e677d41e11a31ff
+Specifying both
+.B MFD_HUGETLB
+and
+.B MFD_ALLOW_SEALING
+in
+.I flags
+is supported since Linux 4.16.
+.TP
+.BR MFD_HUGE_2MB ", " MFD_HUGE_1GB ", " "..."
+Used in conjunction with
+.B MFD_HUGETLB
+to select alternative hugetlb page sizes (respectively, 2\ MB, 1\ GB, ...)
+on systems that support multiple hugetlb page sizes.
+Definitions for known
+huge page sizes are included in the header file
+.I <linux/memfd.h>.
+.IP
+For details on encoding huge page sizes not included in the header file,
+see the discussion of the similarly named constants in
+.BR mmap (2).
.PP
Unused bits in
.I flags
points to invalid memory.
.TP
.B EINVAL
-An unsupported value was specified in one of the arguments:
.I flags
-included unknown bits, or
+included unknown bits.
+.TP
+.B EINVAL
.I name
was too long.
+(The limit is
+.\" NAME_MAX - strlen("memfd:")
+249 bytes, excluding the terminating null byte.)
+.TP
+.B EINVAL
+Both
+.B MFD_HUGETLB
+and
+.B MFD_ALLOW_SEALING
+were specified in
+.IR flags .
.TP
.B EMFILE
The per-process limit on the number of open file descriptors has been reached.
.SH VERSIONS
The
.BR memfd_create ()
-system call first appeared in Linux 3.17.
+system call first appeared in Linux 3.17;
+glibc support was added in version 2.27.
.SH CONFORMING TO
The
.BR memfd_create ()
system call is Linux-specific.
.SH NOTES
-Glibc does not provide a wrapper for this system call; call it using
-.BR syscall (2).
.PP
.\" See also http://lwn.net/Articles/593918/
.\" and http://lwn.net/Articles/594919/ and http://lwn.net/Articles/591108/
file and set some seals on it:
.PP
.in +4n
-.nf
+.EX
$ \fB./t_memfd_create my_memfd_file 4096 sw &\fP
[1] 11775
PID: 11775; fd: 3; /proc/11775/fd/3
-.fi
+.EE
.in
.PP
At this point, the
program to view the seals that have been placed on the file:
.PP
.in +4n
-.nf
+.EX
$ \fBreadlink /proc/11775/fd/3\fP
/memfd:my_memfd_file (deleted)
$ \fB./t_get_seals /proc/11775/fd/3\fP
Existing seals: WRITE SHRINK
-.fi
+.EE
.in
.SS Program source: t_memfd_create.c
\&
-.nf
-#include <sys/memfd.h>
+.EX
+#define _GNU_SOURCE
+#include <sys/mman.h>
#include <fcntl.h>
#include <stdlib.h>
#include <unistd.h>
exit(EXIT_SUCCESS);
}
-.fi
+.EE
.SS Program source: t_get_seals.c
\&
-.nf
-#include <sys/memfd.h>
+.EX
+#define _GNU_SOURCE
+#include <sys/mman.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>
exit(EXIT_SUCCESS);
}
-.fi
+.EE
.SH SEE ALSO
.BR fcntl (2),
.BR ftruncate (2),