]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
syscalls: wrap personality syscall if undefined
authorChristian Brauner <christian.brauner@ubuntu.com>
Tue, 4 May 2021 11:21:28 +0000 (13:21 +0200)
committerChristian Brauner <christian.brauner@ubuntu.com>
Tue, 4 May 2021 13:15:28 +0000 (15:15 +0200)
There's no need to making personality handling conditional as it has
been around for such a long time that only weird systems wouldn't have
support for it. And especially if the user requested a specific
personality to be set but the system doesn't support the personality
syscall we should loudly fail instead of moving on.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
src/lxc/macro.h
src/lxc/syscall_numbers.h
src/lxc/syscall_wrappers.h

index 42f95c23541ef38d7778636e8d2852a260d6bfa2..ab4f989beb9ff1f2f2430b83a2cd5e378c9b0967 100644 (file)
@@ -22,6 +22,7 @@
 #include <unistd.h>
 
 #include "compiler.h"
+#include "config.h"
 
 #ifndef PATH_MAX
 #define PATH_MAX 4096
@@ -741,4 +742,9 @@ enum {
 #define BITS_PER_TYPE(type) (sizeof(type) * 8)
 #define LAST_BIT_PER_TYPE(type) (BITS_PER_TYPE(type) - 1)
 
+#ifndef HAVE_SYS_PERSONALITY_H
+#define PER_LINUX      0x0000
+#define PER_LINUX32    0x0008
+#endif
+
 #endif /* __LXC_MACRO_H */
index 063316de349a1ce5e77ec780759f9451a50d749d..97273b4490bb7fa4c44373a6390cdaa393e5dcfe 100644 (file)
        #endif
 #endif
 
+#ifndef __NR_personality
+       #if defined __alpha__
+               #define __NR_personality 324
+       #elif defined __m68k__
+               #define __NR_personality 136
+       #elif defined __i386__
+               #define __NR_personality 136
+       #elif defined __x86_64__
+               #define __NR_personality 135
+       #elif defined __arm__
+               #define __NR_personality 136
+       #elif defined __aarch64__
+               #define __NR_personality 92
+       #elif defined __s390__
+               #define __NR_personality 136
+       #elif defined __powerpc__
+               #define __NR_personality 136
+       #elif defined __riscv
+               #define __NR_personality -1
+       #elif defined __sparc__
+               #define __NR_personality 191
+       #elif defined __ia64__
+               #define __NR_personality (116 + 1024)
+       #elif defined _MIPS_SIM
+               #if _MIPS_SIM == _MIPS_SIM_ABI32        /* o32 */
+                       #define __NR_personality (136 + 4000)
+               #endif
+               #if _MIPS_SIM == _MIPS_SIM_NABI32       /* n32 */
+                       #define __NR_personality (132 + 6000)
+               #endif
+               #if _MIPS_SIM == _MIPS_SIM_ABI64        /* n64 */
+                       #define __NR_personality (132 + 5000)
+               #endif
+       #else
+               #define -1
+               #warning "__NR_personality not defined for your architecture"
+       #endif
+#endif
+
 #endif /* __LXC_SYSCALL_NUMBERS_H */
index 7188211472c907cd66501fee5cd49b07eda9a890..e340f7f07df5cd453f8ce0c1c0ba1f129c54aed8 100644 (file)
@@ -317,4 +317,11 @@ static inline int close_range(unsigned int fd, unsigned int max_fd, unsigned int
 }
 #endif
 
+#ifndef HAVE_SYS_PERSONALITY_H
+static inline int personality(unsigned long persona)
+{
+       return syscall(__NR_personality, persona);
+}
+#endif
+
 #endif /* __LXC_SYSCALL_WRAPPER_H */