The following pull request was submitted through Github.
It can be accessed and reviewed at: https://github.com/lxc/lxcfs/pull/383

This e-mail was sent by the LXC bot, direct replies will not reach the author
unless they happen to be subscribed to this list.

=== Description (from pull-request) ===
The same thing that I did for LXC.

Signed-off-by: Christian Brauner <christian.brau...@ubuntu.com>
From cb36caa4cf6dbb1ac1471650e17d34f8e9d144cf Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brau...@ubuntu.com>
Date: Fri, 20 Mar 2020 18:42:37 +0100
Subject: [PATCH] tree-wide: add and use syscall_numbers.h

The same thing that I did for LXC.

Signed-off-by: Christian Brauner <christian.brau...@ubuntu.com>
---
 src/Makefile.am               |   3 +
 src/bindings.c                |   6 +-
 src/cgroups/cgroup2_devices.h |  38 ++--------
 src/syscall_numbers.h         | 127 ++++++++++++++++++++++++++++++++++
 src/utils.h                   |   9 +--
 5 files changed, 138 insertions(+), 45 deletions(-)
 create mode 100644 src/syscall_numbers.h

diff --git a/src/Makefile.am b/src/Makefile.am
index 84c6528..030d6b5 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -20,6 +20,7 @@ liblxcfs_la_SOURCES = api_extensions.h \
                      proc_cpuview.c proc_cpuview.h \
                      proc_fuse.c proc_fuse.h \
                      proc_loadavg.c proc_loadavg.h \
+                     syscall_numbers.h \
                      sysfs_fuse.c sysfs_fuse.h \
                      utils.c utils.h
 liblxcfs_la_CFLAGS = $(AM_CFLAGS)
@@ -48,6 +49,7 @@ liblxcfstest_la_SOURCES = api_extensions.h \
                          proc_cpuview.c proc_cpuview.h \
                          proc_fuse.c proc_fuse.h \
                          proc_loadavg.c proc_loadavg.h \
+                         syscall_numbers.h \
                          sysfs_fuse.c sysfs_fuse.h \
                          utils.c utils.h
 liblxcfstest_la_CFLAGS = $(AM_CFLAGS) -DRELOADTEST
@@ -75,6 +77,7 @@ noinst_HEADERS = api_extensions.h \
                 proc_cpuview.h \
                 proc_fuse.h \
                 proc_loadavg.h \
+                syscall_numbers.h \
                 sysfs_fuse.h \
                 utils.h
 
diff --git a/src/bindings.c b/src/bindings.c
index 115ea1f..6c3c818 100644
--- a/src/bindings.c
+++ b/src/bindings.c
@@ -46,6 +46,7 @@
 #include "config.h"
 #include "memory_utils.h"
 #include "proc_cpuview.h"
+#include "syscall_numbers.h"
 #include "utils.h"
 
 static bool can_use_pidfd;
@@ -61,12 +62,7 @@ bool liblxcfs_functional(void)
 #ifndef HAVE_PIVOT_ROOT
 static int pivot_root(const char *new_root, const char *put_old)
 {
-#ifdef __NR_pivot_root
        return syscall(__NR_pivot_root, new_root, put_old);
-#else
-       errno = ENOSYS;
-       return -1;
-#endif
 }
 #else
 extern int pivot_root(const char *new_root, const char *put_old);
diff --git a/src/cgroups/cgroup2_devices.h b/src/cgroups/cgroup2_devices.h
index 3ba81ab..f7cc0ba 100644
--- a/src/cgroups/cgroup2_devices.h
+++ b/src/cgroups/cgroup2_devices.h
@@ -30,40 +30,15 @@
 #include <linux/filter.h>
 #endif
 
+#include "syscall_numbers.h"
+
 #if !HAVE_BPF
-#if !(defined __NR_bpf && __NR_bpf > 0)
-#if defined __NR_bpf
-#undef __NR_bpf
-#endif
-#if defined __i386__
-#define __NR_bpf 357
-#elif defined __x86_64__
-#define __NR_bpf 321
-#elif defined __aarch64__
-#define __NR_bpf 280
-#elif defined __arm__
-#define __NR_bpf 386
-#elif defined __sparc__
-#define __NR_bpf 349
-#elif defined __s390__
-#define __NR_bpf 351
-#elif defined __tilegx__
-#define __NR_bpf 280
-#else
-#warning "__NR_bpf not defined for your architecture"
-#endif
-#endif
 
 union bpf_attr;
 
 static inline int missing_bpf(int cmd, union bpf_attr *attr, size_t size)
 {
-#ifdef __NR_bpf
        return (int)syscall(__NR_bpf, cmd, attr, size);
-#else
-       errno = ENOSYS;
-       return -1;
-#endif
 }
 
 #define bpf missing_bpf
@@ -77,7 +52,7 @@ struct bpf_program {
        size_t n_instructions;
 #ifdef HAVE_STRUCT_BPF_CGROUP_DEV_CTX
        struct bpf_insn *instructions;
-#endif
+#endif /* HAVE_STRUCT_BPF_CGROUP_DEV_CTX */
 
        char *attached_path;
        int attached_type;
@@ -102,7 +77,7 @@ static inline void __auto_bpf_program_free__(struct 
bpf_program **prog)
                *prog = NULL;
        }
 }
-#else
+#else /* HAVE_STRUCT_BPF_CGROUP_DEV_CTX */
 static inline struct bpf_program *bpf_program_new(uint32_t prog_type)
 {
        errno = ENOSYS;
@@ -156,9 +131,8 @@ static inline void __auto_bpf_program_free__(struct 
bpf_program **prog)
 {
 }
 
-#endif
+#endif /* HAVE_BPF */
 
-#define __do_bpf_program_free \
-       __attribute__((__cleanup__(__auto_bpf_program_free__)))
+define_cleanup_function(struct bpf_program *, bpf_program_free);
 
 #endif /* __LXC_CGROUP2_DEVICES_H */
diff --git a/src/syscall_numbers.h b/src/syscall_numbers.h
new file mode 100644
index 0000000..1c1b29b
--- /dev/null
+++ b/src/syscall_numbers.h
@@ -0,0 +1,127 @@
+/* SPDX-License-Identifier: LGPL-2.1+ */
+#ifndef __LXCFS_SYSCALL_NUMBERS_H
+#define __LXCFS_SYSCALL_NUMBERS_H
+
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE 1
+#endif
+#include <asm/unistd.h>
+#include <errno.h>
+#include <linux/keyctl.h>
+#include <sched.h>
+#include <stdint.h>
+#include <sys/syscall.h>
+#include <sys/types.h>
+#include <unistd.h>
+
+#ifdef HAVE_LINUX_MEMFD_H
+#include <linux/memfd.h>
+#endif
+
+#ifdef HAVE_SYS_SIGNALFD_H
+#include <sys/signalfd.h>
+#endif
+
+#ifndef __NR_pivot_root
+       #if defined __i386__
+               #define __NR_pivot_root 217
+       #elif defined __x86_64__
+               #define __NR_pivot_root 155
+       #elif defined __arm__
+               #define __NR_pivot_root 218
+       #elif defined __aarch64__
+               #define __NR_pivot_root 218
+       #elif defined __s390__
+               #define __NR_pivot_root 217
+       #elif defined __powerpc__
+               #define __NR_pivot_root 203
+       #elif defined __sparc__
+               #define __NR_pivot_root 146
+       #elif defined __ia64__
+               #define __NR_pivot_root 183
+       #elif defined _MIPS_SIM
+               #if _MIPS_SIM == _MIPS_SIM_ABI32        /* o32 */
+                       #define __NR_pivot_root 4216
+               #endif
+               #if _MIPS_SIM == _MIPS_SIM_NABI32       /* n32 */
+                       #define __NR_pivot_root 6151
+               #endif
+               #if _MIPS_SIM == _MIPS_SIM_ABI64        /* n64 */
+                       #define __NR_pivot_root 5151
+               #endif
+       #else
+               #define -1
+               #warning "__NR_pivot_root not defined for your architecture"
+       #endif
+#endif
+
+#ifndef __NR_bpf
+       #if defined __i386__
+               #define __NR_bpf 357
+       #elif defined __x86_64__
+               #define __NR_bpf 321
+       #elif defined __arm__
+               #define __NR_bpf 386
+       #elif defined __aarch64__
+               #define __NR_bpf 386
+       #elif defined __s390__
+               #define __NR_bpf 351
+       #elif defined __powerpc__
+               #define __NR_bpf 361
+       #elif defined __sparc__
+               #define __NR_bpf 349
+       #elif defined __ia64__
+               #define __NR_bpf 317
+       #elif defined _MIPS_SIM
+               #if _MIPS_SIM == _MIPS_SIM_ABI32        /* o32 */
+                       #define __NR_bpf 4355
+               #endif
+               #if _MIPS_SIM == _MIPS_SIM_NABI32       /* n32 */
+                       #define __NR_bpf 6319
+               #endif
+               #if _MIPS_SIM == _MIPS_SIM_ABI64        /* n64 */
+                       #define __NR_bpf 5315
+               #endif
+       #else
+               #define -1
+               #warning "__NR_bpf not defined for your architecture"
+       #endif
+#endif
+
+#ifndef __NR_pidfd_send_signal
+       #if defined __alpha__
+               #define __NR_pidfd_send_signal 534
+       #elif defined _MIPS_SIM
+               #if _MIPS_SIM == _MIPS_SIM_ABI32        /* o32 */
+                       #define __NR_pidfd_send_signal 4424
+               #endif
+               #if _MIPS_SIM == _MIPS_SIM_NABI32       /* n32 */
+                       #define __NR_pidfd_send_signal 6424
+               #endif
+               #if _MIPS_SIM == _MIPS_SIM_ABI64        /* n64 */
+                       #define __NR_pidfd_send_signal 5424
+               #endif
+       #else
+               #define __NR_pidfd_send_signal 424
+       #endif
+#endif
+
+#ifndef __NR_pidfd_open
+       #if defined __alpha__
+               #define __NR_pidfd_open 544
+       #elif defined _MIPS_SIM
+               #if _MIPS_SIM == _MIPS_SIM_ABI32        /* o32 */
+                       #define __NR_pidfd_open 4434
+               #endif
+               #if _MIPS_SIM == _MIPS_SIM_NABI32       /* n32 */
+                       #define __NR_pidfd_open 6434
+               #endif
+               #if _MIPS_SIM == _MIPS_SIM_ABI64        /* n64 */
+                       #define __NR_pidfd_open 5434
+               #endif
+       #else
+               #define __NR_pidfd_open 434
+       #endif
+#endif
+
+#endif /* __LXCFS_SYSCALL_NUMBERS_H */
diff --git a/src/utils.h b/src/utils.h
index 29c87dc..9b8d867 100644
--- a/src/utils.h
+++ b/src/utils.h
@@ -24,6 +24,7 @@
 
 #include "config.h"
 #include "macro.h"
+#include "syscall_numbers.h"
 
 /* Reserve buffer size to account for file size changes. */
 #define BUF_RESERVE_SIZE 512
@@ -51,11 +52,7 @@ extern int wait_for_pid(pid_t pid);
 #ifndef HAVE_PIDFD_OPEN
 static inline int pidfd_open(pid_t pid, unsigned int flags)
 {
-#ifdef __NR_pidfd_open
        return syscall(__NR_pidfd_open, pid, flags);
-#else
-       return ret_errno(ENOSYS);
-#endif
 }
 #endif
 
@@ -63,11 +60,7 @@ static inline int pidfd_open(pid_t pid, unsigned int flags)
 static inline int pidfd_send_signal(int pidfd, int sig, siginfo_t *info,
                                    unsigned int flags)
 {
-#ifdef __NR_pidfd_send_signal
        return syscall(__NR_pidfd_send_signal, pidfd, sig, info, flags);
-#else
-       return ret_errno(ENOSYS);
-#endif
 }
 #endif
 
_______________________________________________
lxc-devel mailing list
lxc-devel@lists.linuxcontainers.org
http://lists.linuxcontainers.org/listinfo/lxc-devel

Reply via email to