Browse Source

add memfd_create syscall wrapper

Waldemar Brodkorb 7 months ago
parent
commit
811cd361e1
36 changed files with 121 additions and 2 deletions
  1. 3 0
      libc/sysdeps/linux/aarch64/bits/fcntl.h
  2. 2 0
      libc/sysdeps/linux/alpha/bits/fcntl.h
  3. 3 0
      libc/sysdeps/linux/arc/bits/fcntl.h
  4. 2 0
      libc/sysdeps/linux/arm/bits/fcntl.h
  5. 3 0
      libc/sysdeps/linux/avr32/bits/fcntl.h
  6. 2 0
      libc/sysdeps/linux/bfin/bits/fcntl.h
  7. 3 0
      libc/sysdeps/linux/c6x/bits/fcntl.h
  8. 1 0
      libc/sysdeps/linux/common/Makefile.in
  9. 34 0
      libc/sysdeps/linux/common/bits/fcntl-linux.h
  10. 0 2
      libc/sysdeps/linux/common/bits/mman-shared.h
  11. 13 0
      libc/sysdeps/linux/common/memfd_create.c
  12. 2 0
      libc/sysdeps/linux/cris/bits/fcntl.h
  13. 2 0
      libc/sysdeps/linux/csky/bits/fcntl.h
  14. 2 0
      libc/sysdeps/linux/frv/bits/fcntl.h
  15. 2 0
      libc/sysdeps/linux/h8300/bits/fcntl.h
  16. 2 0
      libc/sysdeps/linux/hppa/bits/fcntl.h
  17. 2 0
      libc/sysdeps/linux/i386/bits/fcntl.h
  18. 2 0
      libc/sysdeps/linux/ia64/bits/fcntl.h
  19. 3 0
      libc/sysdeps/linux/kvx/bits/fcntl.h
  20. 2 0
      libc/sysdeps/linux/lm32/bits/fcntl.h
  21. 2 0
      libc/sysdeps/linux/m68k/bits/fcntl.h
  22. 2 0
      libc/sysdeps/linux/metag/bits/fcntl.h
  23. 2 0
      libc/sysdeps/linux/microblaze/bits/fcntl.h
  24. 2 0
      libc/sysdeps/linux/mips/bits/fcntl.h
  25. 2 0
      libc/sysdeps/linux/nds32/bits/fcntl.h
  26. 2 0
      libc/sysdeps/linux/nios2/bits/fcntl.h
  27. 3 0
      libc/sysdeps/linux/or1k/bits/fcntl.h
  28. 2 0
      libc/sysdeps/linux/powerpc/bits/fcntl.h
  29. 3 0
      libc/sysdeps/linux/riscv32/bits/fcntl.h
  30. 3 0
      libc/sysdeps/linux/riscv64/bits/fcntl.h
  31. 2 0
      libc/sysdeps/linux/sh/bits/fcntl.h
  32. 2 0
      libc/sysdeps/linux/sparc/bits/fcntl.h
  33. 2 0
      libc/sysdeps/linux/sparc64/bits/fcntl.h
  34. 3 0
      libc/sysdeps/linux/tile/bits/fcntl.h
  35. 2 0
      libc/sysdeps/linux/x86_64/bits/fcntl.h
  36. 2 0
      libc/sysdeps/linux/xtensa/bits/fcntl.h

+ 3 - 0
libc/sysdeps/linux/aarch64/bits/fcntl.h

@@ -289,3 +289,6 @@ extern int fallocate64 (int __fd, int __mode, __off64_t __offset,
 #endif	/* use GNU */
 
 __END_DECLS
+
+/* Include generic Linux declarations.  */
+#include <bits/fcntl-linux.h>

+ 2 - 0
libc/sysdeps/linux/alpha/bits/fcntl.h

@@ -236,3 +236,5 @@ extern ssize_t tee (int __fdin, int __fdout, size_t __len,
 #endif
 __END_DECLS
 
+/* Include generic Linux declarations.  */
+#include <bits/fcntl-linux.h>

+ 3 - 0
libc/sysdeps/linux/arc/bits/fcntl.h

@@ -230,3 +230,6 @@ extern ssize_t tee (int __fdin, int __fdout, size_t __len,
 
 #endif
 __END_DECLS
+
+/* Include generic Linux declarations.  */
+#include <bits/fcntl-linux.h>

+ 2 - 0
libc/sysdeps/linux/arm/bits/fcntl.h

@@ -244,3 +244,5 @@ extern ssize_t tee (int __fdin, int __fdout, size_t __len,
 #endif
 __END_DECLS
 
+/* Include generic Linux declarations.  */
+#include <bits/fcntl-linux.h>

+ 3 - 0
libc/sysdeps/linux/avr32/bits/fcntl.h

@@ -218,3 +218,6 @@ extern ssize_t tee (int __fdin, int __fdout, size_t __len,
 
 __END_DECLS
 #endif
+
+/* Include generic Linux declarations.  */
+#include <bits/fcntl-linux.h>

+ 2 - 0
libc/sysdeps/linux/bfin/bits/fcntl.h

@@ -244,3 +244,5 @@ extern ssize_t tee (int __fdin, int __fdout, size_t __len,
 #endif
 __END_DECLS
 
+/* Include generic Linux declarations.  */
+#include <bits/fcntl-linux.h>

+ 3 - 0
libc/sysdeps/linux/c6x/bits/fcntl.h

@@ -237,3 +237,6 @@ extern ssize_t tee (int __fdin, int __fdout, size_t __len,
 
 #endif
 __END_DECLS
+
+/* Include generic Linux declarations.  */
+#include <bits/fcntl-linux.h>

+ 1 - 0
libc/sysdeps/linux/common/Makefile.in

@@ -30,6 +30,7 @@ CSRC-$(UCLIBC_LINUX_SPECIFIC) += \
 	inotify.c \
 	ioperm.c \
 	iopl.c \
+	memfd_create.c \
 	modify_ldt.c \
 	module.c \
 	name_to_handle_at.c \

+ 34 - 0
libc/sysdeps/linux/common/bits/fcntl-linux.h

@@ -0,0 +1,34 @@
+/* O_*, F_*, FD_* bit values for Linux.
+   Copyright (C) 2001-2024 Free Software Foundation, Inc.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <https://www.gnu.org/licenses/>.  */
+
+#ifndef	_FCNTL_H
+# error "Never use <bits/fcntl-linux.h> directly; include <fcntl.h> instead."
+#endif
+
+#ifdef __USE_GNU
+/* Types of seals.  */
+# define F_SEAL_SEAL	0x0001	/* Prevent further seals from being set.  */
+# define F_SEAL_SHRINK	0x0002	/* Prevent file from shrinking.  */
+# define F_SEAL_GROW	0x0004	/* Prevent file from growing.  */
+# define F_SEAL_WRITE	0x0008	/* Prevent writes.  */
+# define F_SEAL_FUTURE_WRITE	0x0010	/* Prevent future writes while
+					   mapped.  */
+# define F_SEAL_EXEC	0x0020	/* Prevent chmod modifying exec bits. */
+
+# define F_ADD_SEALS	1033	/* Add seals to file.  */
+# define F_GET_SEALS	1034	/* Get seals for file.  */
+#endif

+ 0 - 2
libc/sysdeps/linux/common/bits/mman-shared.h

@@ -40,11 +40,9 @@
 
 __BEGIN_DECLS
 
-#if 0
 /* Create a new memory file descriptor.  NAME is a name for debugging.
    FLAGS is a combination of the MFD_* constants.  */
 int memfd_create (const char *__name, unsigned int __flags) __THROW;
-#endif
 
 /* Lock pages from ADDR (inclusive) to ADDR + LENGTH (exclusive) into
    memory.  FLAGS is a combination of the MLOCK_* flags above.  */

+ 13 - 0
libc/sysdeps/linux/common/memfd_create.c

@@ -0,0 +1,13 @@
+/*
+ * memfd_create() for uClibc-ng
+ *
+ * Copyright (C) 2024 Waldemar Brodkorb <wbx@uclibc-ng.org>
+ *
+ * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
+ */
+
+#include <sys/syscall.h>
+#include <sys/mman.h>
+#if defined(__NR_memfd_create)
+_syscall2(int, memfd_create, const char *, name, unsigned int, flags)
+#endif

+ 2 - 0
libc/sysdeps/linux/cris/bits/fcntl.h

@@ -245,3 +245,5 @@ extern ssize_t tee (int __fdin, int __fdout, size_t __len,
 #endif
 __END_DECLS
 
+/* Include generic Linux declarations.  */
+#include <bits/fcntl-linux.h>

+ 2 - 0
libc/sysdeps/linux/csky/bits/fcntl.h

@@ -232,3 +232,5 @@ extern ssize_t tee (int __fdin, int __fdout, size_t __len,
 #endif
 __END_DECLS
 
+/* Include generic Linux declarations.  */
+#include <bits/fcntl-linux.h>

+ 2 - 0
libc/sysdeps/linux/frv/bits/fcntl.h

@@ -226,3 +226,5 @@ extern ssize_t tee (int __fdin, int __fdout, size_t __len,
 #endif
 __END_DECLS
 
+/* Include generic Linux declarations.  */
+#include <bits/fcntl-linux.h>

+ 2 - 0
libc/sysdeps/linux/h8300/bits/fcntl.h

@@ -244,3 +244,5 @@ extern ssize_t tee (int __fdin, int __fdout, size_t __len,
 #endif
 __END_DECLS
 
+/* Include generic Linux declarations.  */
+#include <bits/fcntl-linux.h>

+ 2 - 0
libc/sysdeps/linux/hppa/bits/fcntl.h

@@ -234,3 +234,5 @@ extern ssize_t tee (int __fdin, int __fdout, size_t __len,
 #endif
 __END_DECLS
 
+/* Include generic Linux declarations.  */
+#include <bits/fcntl-linux.h>

+ 2 - 0
libc/sysdeps/linux/i386/bits/fcntl.h

@@ -245,3 +245,5 @@ extern ssize_t tee (int __fdin, int __fdout, size_t __len,
 #endif
 __END_DECLS
 
+/* Include generic Linux declarations.  */
+#include <bits/fcntl-linux.h>

+ 2 - 0
libc/sysdeps/linux/ia64/bits/fcntl.h

@@ -238,3 +238,5 @@ extern ssize_t tee (int __fdin, int __fdout, size_t __len,
 #endif
 __END_DECLS
 
+/* Include generic Linux declarations.  */
+#include <bits/fcntl-linux.h>

+ 3 - 0
libc/sysdeps/linux/kvx/bits/fcntl.h

@@ -227,3 +227,6 @@ extern ssize_t tee (int __fdin, int __fdout, size_t __len,
 
 #endif
 __END_DECLS
+
+/* Include generic Linux declarations.  */
+#include <bits/fcntl-linux.h>

+ 2 - 0
libc/sysdeps/linux/lm32/bits/fcntl.h

@@ -244,3 +244,5 @@ extern ssize_t tee (int __fdin, int __fdout, size_t __len,
 #endif
 __END_DECLS
 
+/* Include generic Linux declarations.  */
+#include <bits/fcntl-linux.h>

+ 2 - 0
libc/sysdeps/linux/m68k/bits/fcntl.h

@@ -244,3 +244,5 @@ extern ssize_t tee (int __fdin, int __fdout, size_t __len,
 #endif
 __END_DECLS
 
+/* Include generic Linux declarations.  */
+#include <bits/fcntl-linux.h>

+ 2 - 0
libc/sysdeps/linux/metag/bits/fcntl.h

@@ -244,3 +244,5 @@ extern ssize_t tee (int __fdin, int __fdout, size_t __len,
 #endif
 __END_DECLS
 
+/* Include generic Linux declarations.  */
+#include <bits/fcntl-linux.h>

+ 2 - 0
libc/sysdeps/linux/microblaze/bits/fcntl.h

@@ -244,3 +244,5 @@ extern ssize_t tee (int __fdin, int __fdout, size_t __len,
 #endif
 __END_DECLS
 
+/* Include generic Linux declarations.  */
+#include <bits/fcntl-linux.h>

+ 2 - 0
libc/sysdeps/linux/mips/bits/fcntl.h

@@ -268,3 +268,5 @@ extern ssize_t tee (int __fdin, int __fdout, size_t __len,
 #endif
 __END_DECLS
 
+/* Include generic Linux declarations.  */
+#include <bits/fcntl-linux.h>

+ 2 - 0
libc/sysdeps/linux/nds32/bits/fcntl.h

@@ -249,3 +249,5 @@ extern ssize_t tee (int __fdin, int __fdout, size_t __len,
 #endif
 __END_DECLS
 
+/* Include generic Linux declarations.  */
+#include <bits/fcntl-linux.h>

+ 2 - 0
libc/sysdeps/linux/nios2/bits/fcntl.h

@@ -244,3 +244,5 @@ extern ssize_t tee (int __fdin, int __fdout, size_t __len,
 #endif
 __END_DECLS
 
+/* Include generic Linux declarations.  */
+#include <bits/fcntl-linux.h>

+ 3 - 0
libc/sysdeps/linux/or1k/bits/fcntl.h

@@ -244,3 +244,6 @@ extern ssize_t tee (int __fdin, int __fdout, size_t __len,
 
 #endif
 __END_DECLS
+
+/* Include generic Linux declarations.  */
+#include <bits/fcntl-linux.h>

+ 2 - 0
libc/sysdeps/linux/powerpc/bits/fcntl.h

@@ -245,3 +245,5 @@ extern ssize_t tee (int __fdin, int __fdout, size_t __len,
 #endif
 __END_DECLS
 
+/* Include generic Linux declarations.  */
+#include <bits/fcntl-linux.h>

+ 3 - 0
libc/sysdeps/linux/riscv32/bits/fcntl.h

@@ -229,3 +229,6 @@ extern ssize_t tee (int __fdin, int __fdout, size_t __len,
 
 #endif
 __END_DECLS
+
+/* Include generic Linux declarations.  */
+#include <bits/fcntl-linux.h>

+ 3 - 0
libc/sysdeps/linux/riscv64/bits/fcntl.h

@@ -229,3 +229,6 @@ extern ssize_t tee (int __fdin, int __fdout, size_t __len,
 
 #endif
 __END_DECLS
+
+/* Include generic Linux declarations.  */
+#include <bits/fcntl-linux.h>

+ 2 - 0
libc/sysdeps/linux/sh/bits/fcntl.h

@@ -245,3 +245,5 @@ extern ssize_t tee (int __fdin, int __fdout, size_t __len,
 #endif
 __END_DECLS
 
+/* Include generic Linux declarations.  */
+#include <bits/fcntl-linux.h>

+ 2 - 0
libc/sysdeps/linux/sparc/bits/fcntl.h

@@ -252,3 +252,5 @@ extern ssize_t tee (int __fdin, int __fdout, size_t __len,
 #endif
 __END_DECLS
 
+/* Include generic Linux declarations.  */
+#include <bits/fcntl-linux.h>

+ 2 - 0
libc/sysdeps/linux/sparc64/bits/fcntl.h

@@ -248,3 +248,5 @@ extern ssize_t tee (int __fdin, int __fdout, size_t __len,
 #endif
 __END_DECLS
 
+/* Include generic Linux declarations.  */
+#include <bits/fcntl-linux.h>

+ 3 - 0
libc/sysdeps/linux/tile/bits/fcntl.h

@@ -229,3 +229,6 @@ extern ssize_t tee (int __fdin, int __fdout, size_t __len,
 
 #endif
 __END_DECLS
+
+/* Include generic Linux declarations.  */
+#include <bits/fcntl-linux.h>

+ 2 - 0
libc/sysdeps/linux/x86_64/bits/fcntl.h

@@ -259,3 +259,5 @@ extern ssize_t tee (int __fdin, int __fdout, size_t __len,
 #endif
 __END_DECLS
 
+/* Include generic Linux declarations.  */
+#include <bits/fcntl-linux.h>

+ 2 - 0
libc/sysdeps/linux/xtensa/bits/fcntl.h

@@ -245,3 +245,5 @@ extern ssize_t tee (int __fdin, int __fdout, size_t __len,
 #endif
 __END_DECLS
 
+/* Include generic Linux declarations.  */
+#include <bits/fcntl-linux.h>