diff options
author | Tony Ambardar <itugrok@yahoo.com> | 2024-06-11 22:30:48 -0700 |
---|---|---|
committer | Christian Marangi <ansuelsmth@gmail.com> | 2024-06-13 14:16:32 +0200 |
commit | cc6a1e2abcdf32fc829755026f4dcb56d6dcde4a (patch) | |
tree | a99ed46c5c1de8e0ddb3c76a48f8e70158b4de79 | |
parent | 75a76355cb674209589f6a33f116b5424cac2cdc (diff) | |
download | openwrt-cc6a1e2abcdf32fc829755026f4dcb56d6dcde4a.tar.gz openwrt-cc6a1e2abcdf32fc829755026f4dcb56d6dcde4a.tar.bz2 openwrt-cc6a1e2abcdf32fc829755026f4dcb56d6dcde4a.zip |
toolchain/musl: add support for renameat2()
Backport an upstream patch to support the renameat2 syscall, added in Linux
3.15 and supported by glibc since 2.28. It is commonly used in filesystem
or security contexts, and needed building upstream kernel bpf selftests.
Link:
https://inbox.vuxu.org/musl/20240421153640.379015-1-Tony.Ambardar@gmail.com/
Signed-off-by: Tony Ambardar <itugrok@yahoo.com>
Link: https://github.com/openwrt/openwrt/pull/15697
Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
-rw-r--r-- | toolchain/musl/patches/610-add-renameat2-linux-syscall-wrapper.patch | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/toolchain/musl/patches/610-add-renameat2-linux-syscall-wrapper.patch b/toolchain/musl/patches/610-add-renameat2-linux-syscall-wrapper.patch new file mode 100644 index 0000000000..167769360e --- /dev/null +++ b/toolchain/musl/patches/610-add-renameat2-linux-syscall-wrapper.patch @@ -0,0 +1,61 @@ +From dc651fe2e6b16087c519c0bd0bf943cb7c53c807 Mon Sep 17 00:00:00 2001 +In-Reply-To: <20240423234355.2414567-1-Tony.Ambardar@gmail.com> +References: <20240423234355.2414567-1-Tony.Ambardar@gmail.com> +From: Tony Ambardar <Tony.Ambardar@gmail.com> +Date: Sat, 20 Apr 2024 21:30:13 -0700 +Subject: [PATCH v3] add renameat2 linux syscall wrapper +To: musl@lists.openwall.com +Cc: Rich Felker <dalias@libc.org> + +This syscall is available since Linux 3.15 and also implemented in glibc +from version 2.28. It is commonly used in filesystem or security contexts. + +Constants RENAME_NOREPLACE, RENAME_EXCHANGE, RENAME_WHITEOUT are guarded by +_GNU_SOURCE as with glibc. + +Signed-off-by: Tony Ambardar <Tony.Ambardar@gmail.com> +--- +v2 -> v3: + * call SYS_renameat first if applicable + * drop unneeded error code handling + +v1 -> v2: + * align related constants + * drop 'int' from 'unsigned int' + * add fallback to SYS_renameat where applicable +--- + include/stdio.h | 7 +++++++ + src/linux/renameat2.c | 11 +++++++++++ + 2 files changed, 18 insertions(+) + create mode 100644 src/linux/renameat2.c + +--- a/include/stdio.h ++++ b/include/stdio.h +@@ -158,6 +158,13 @@ char *ctermid(char *); + #define L_ctermid 20 + #endif + ++#if defined(_GNU_SOURCE) ++#define RENAME_NOREPLACE (1 << 0) ++#define RENAME_EXCHANGE (1 << 1) ++#define RENAME_WHITEOUT (1 << 2) ++ ++int renameat2(int, const char *, int, const char *, unsigned); ++#endif + + #if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \ + || defined(_BSD_SOURCE) +--- /dev/null ++++ b/src/linux/renameat2.c +@@ -0,0 +1,11 @@ ++#define _GNU_SOURCE ++#include <stdio.h> ++#include "syscall.h" ++ ++int renameat2(int oldfd, const char *old, int newfd, const char *new, unsigned flags) ++{ ++#ifdef SYS_renameat ++ if (!flags) return syscall(SYS_renameat, oldfd, old, newfd, new); ++#endif ++ return syscall(SYS_renameat2, oldfd, old, newfd, new, flags); ++} |