From 38f2fa3d0207b8060302129c6464662751d4f2d3 Mon Sep 17 00:00:00 2001 From: Szabolcs Nagy Date: Tue, 19 Jun 2018 20:28:03 +0000 Subject: [PATCH] add memfd_create syscall wrapper memfd_create was added in linux v3.17 and glibc has api for it. --- include/sys/mman.h | 5 +++++ src/linux/memfd_create.c | 8 ++++++++ 2 files changed, 13 insertions(+) create mode 100644 src/linux/memfd_create.c diff --git a/include/sys/mman.h b/include/sys/mman.h index 80e1da75..99d02a2e 100644 --- a/include/sys/mman.h +++ b/include/sys/mman.h @@ -99,6 +99,10 @@ extern "C" { #define MREMAP_FIXED 2 #define MLOCK_ONFAULT 0x01 + +#define MFD_CLOEXEC 0x0001U +#define MFD_ALLOW_SEALING 0x0002U +#define MFD_HUGETLB 0x0004U #endif #include @@ -119,6 +123,7 @@ int munlockall (void); #ifdef _GNU_SOURCE void *mremap (void *, size_t, size_t, int, ...); int remap_file_pages (void *, size_t, int, size_t, int); +int memfd_create (const char *, unsigned); int mlock2 (const void *, size_t, unsigned); #endif diff --git a/src/linux/memfd_create.c b/src/linux/memfd_create.c new file mode 100644 index 00000000..1649fe55 --- /dev/null +++ b/src/linux/memfd_create.c @@ -0,0 +1,8 @@ +#define _GNU_SOURCE 1 +#include +#include "syscall.h" + +int memfd_create(const char *name, unsigned flags) +{ + return syscall(SYS_memfd_create, name, flags); +} -- 2.25.1