]> git.proxmox.com Git - mirror_lxcfs.git/commitdiff
tree-wide: add and use syscall_numbers.h
authorChristian Brauner <christian.brauner@ubuntu.com>
Fri, 20 Mar 2020 17:42:37 +0000 (18:42 +0100)
committerChristian Brauner <christian.brauner@ubuntu.com>
Fri, 20 Mar 2020 17:43:51 +0000 (18:43 +0100)
The same thing that I did for LXC.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
src/Makefile.am
src/bindings.c
src/cgroups/cgroup2_devices.h
src/syscall_numbers.h [new file with mode: 0644]
src/utils.h

index 84c65286ade441dcad486d674302b1971d266541..030d6b5ebd3332ab4021fa44957a59bf5e2b0eb2 100644 (file)
@@ -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
 
index 115ea1fc117bbfb801fa990f38a3953519707c0a..6c3c818f00de36c4f74ed7b1af4b87dab24419ca 100644 (file)
@@ -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);
index 3ba81ab581087ebb9f9552ca0fd5a8e2dbc26318..f7cc0ba735c7c4cff49d8ae20fbee2a3e9cb72f4 100644 (file)
 #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 (file)
index 0000000..41eb5dc
--- /dev/null
@@ -0,0 +1,118 @@
+/* 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 <sched.h>
+#include <stdint.h>
+#include <sys/syscall.h>
+#include <sys/types.h>
+#include <unistd.h>
+
+#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 */
index 29c87dc73f070b6cef1ab1b6fe5d334bc0772820..9b8d8673a7bc923c7f4c01685603ffd18c0bf891 100644 (file)
@@ -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