]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
Add loongarch64 support 4363/head
authorzhaixiaojuan <zhaixiaojuan@loongson.cn>
Thu, 2 Nov 2023 08:14:45 +0000 (16:14 +0800)
committerzhaixiaojuan <zhaixiaojuan@loongson.cn>
Thu, 21 Dec 2023 08:19:15 +0000 (16:19 +0800)
Signed-off-by: zhaixiaojuan <zhaixiaojuan@loongson.cn>
README.md
config/bash/_lxc.in
src/lxc/confile.c
src/lxc/seccomp.c
src/lxc/syscall_numbers.h
src/tests/arch_parse.c

index 4ddb1c5cd5b01754a427e6301a2efdad5175041f..dd02b3eae994ab0866d119e35690c6251d0905a3 100644 (file)
--- a/README.md
+++ b/README.md
@@ -110,6 +110,7 @@ features. This includes (but isn't limited to):
 - riscv64
 - s390x
 - armvl7, arm64
+- loongarch64
 
 LXC also supports at least the following C standard libraries:
 
index 6672bf02d99b9367f7fa77edcb6235ac447b3bab..8a7ce16af862767d9f0c5ec681cde12e473ddc4a 100644 (file)
@@ -285,7 +285,7 @@ _lxc_attach() {
             ;;
         --arch | -a )
             # https://github.com/lxc/lxc/blob/stable-4.0/src/tests/arch_parse.c#L37
-            COMPREPLY=( $( compgen -W 'arm armel armhf armv7l athlon i386 i486 i586 i686 linux32 mips mipsel ppc powerpc x86 aarch64 amd64 arm64 linux64 mips64 mips64el ppc64 ppc64el ppc64le powerpc64 riscv64 s390x x86_64' -- "${cur}" ) )
+            COMPREPLY=( $( compgen -W 'arm armel armhf armv7l athlon i386 i486 i586 i686 linux32 mips mipsel ppc powerpc x86 aarch64 amd64 arm64 linux64 loongarch64 mips64 mips64el ppc64 ppc64el ppc64le powerpc64 riscv64 s390x x86_64' -- "${cur}" ) )
             return
             ;;
         --elevated-privileges | -e )
index 7a8a53418660fdbe59bc4d1481469619b255051d..bccc54f1a2d91a119022aabcdbeef6e4e08c67db 100644 (file)
@@ -3254,34 +3254,35 @@ int lxc_config_parse_arch(const char *arch, signed long *persona)
                char *name;
                unsigned long per;
        } pername[] = {
-               { "arm",       PER_LINUX32 },
-               { "armel",     PER_LINUX32 },
-               { "armhf",     PER_LINUX32 },
-               { "armv7l",    PER_LINUX32 },
-               { "athlon",    PER_LINUX32 },
-               { "i386",      PER_LINUX32 },
-               { "i486",      PER_LINUX32 },
-               { "i586",      PER_LINUX32 },
-               { "i686",      PER_LINUX32 },
-               { "linux32",   PER_LINUX32 },
-               { "mips",      PER_LINUX32 },
-               { "mipsel",    PER_LINUX32 },
-               { "ppc",       PER_LINUX32 },
-               { "powerpc",   PER_LINUX32 },
-               { "x86",       PER_LINUX32 },
-               { "aarch64",   PER_LINUX   },
-               { "amd64",     PER_LINUX   },
-               { "arm64",     PER_LINUX   },
-               { "linux64",   PER_LINUX   },
-               { "mips64",    PER_LINUX   },
-               { "mips64el",  PER_LINUX   },
-               { "ppc64",     PER_LINUX   },
-               { "ppc64el",   PER_LINUX   },
-               { "ppc64le",   PER_LINUX   },
-               { "powerpc64", PER_LINUX   },
-               { "riscv64",   PER_LINUX   },
-               { "s390x",     PER_LINUX   },
-               { "x86_64",    PER_LINUX   },
+               { "arm",           PER_LINUX32 },
+               { "armel",         PER_LINUX32 },
+               { "armhf",         PER_LINUX32 },
+               { "armv7l",        PER_LINUX32 },
+               { "athlon",        PER_LINUX32 },
+               { "i386",          PER_LINUX32 },
+               { "i486",          PER_LINUX32 },
+               { "i586",          PER_LINUX32 },
+               { "i686",          PER_LINUX32 },
+               { "linux32",       PER_LINUX32 },
+               { "mips",          PER_LINUX32 },
+               { "mipsel",        PER_LINUX32 },
+               { "ppc",           PER_LINUX32 },
+               { "powerpc",       PER_LINUX32 },
+               { "x86",           PER_LINUX32 },
+               { "aarch64",       PER_LINUX   },
+               { "amd64",         PER_LINUX   },
+               { "arm64",         PER_LINUX   },
+               { "linux64",       PER_LINUX   },
+               { "loongarch64",   PER_LINUX   },
+               { "mips64",        PER_LINUX   },
+               { "mips64el",      PER_LINUX   },
+               { "ppc64",         PER_LINUX   },
+               { "ppc64el",       PER_LINUX   },
+               { "ppc64le",       PER_LINUX   },
+               { "powerpc64",     PER_LINUX   },
+               { "riscv64",       PER_LINUX   },
+               { "s390x",         PER_LINUX   },
+               { "x86_64",        PER_LINUX   },
        };
 
        for (size_t i = 0; i < ARRAY_SIZE(pername); i++) {
index cefa18d0ab4e69d82ff7f4c3068b7fff2e00948a..3ba54331d01e5248f0c7ce5b2098e60599b1b2bb 100644 (file)
@@ -315,6 +315,7 @@ enum lxc_hostarch_t {
        lxc_seccomp_arch_mipsel64n32,
        lxc_seccomp_arch_s390x,
        lxc_seccomp_arch_s390,
+       lxc_seccomp_arch_loongarch64,
        lxc_seccomp_arch_unknown = 999,
 };
 
@@ -349,6 +350,8 @@ static int get_hostarch(void)
                return lxc_seccomp_arch_s390x;
        else if (strnequal(uts.machine, "s390", 4))
                return lxc_seccomp_arch_s390;
+       else if (strnequal(uts.machine, "loongarch64", 11))
+               return lxc_seccomp_arch_loongarch64;
        return lxc_seccomp_arch_unknown;
 }
 
@@ -421,6 +424,11 @@ static scmp_filter_ctx get_new_ctx(enum lxc_hostarch_t n_arch, uint32_t default_
        case lxc_seccomp_arch_s390:
                arch = SCMP_ARCH_S390;
                break;
+#endif
+#ifdef SCMP_ARCH_LOONGARCH64
+       case lxc_seccomp_arch_loongarch64:
+               arch = SCMP_ARCH_LOONGARCH64;
+               break;
 #endif
        default:
                return NULL;
@@ -967,6 +975,17 @@ static int parse_config_v2(FILE *f, char *line, size_t *line_bufsz, struct lxc_c
 
                                cur_rule_arch = lxc_seccomp_arch_s390;
                        }
+#endif
+#ifdef SCMP_ARCH_LOONGARCH64
+                        else if (strequal(line, "[loongarch64]") ||
+                                 strequal(line, "[LOONGARCH64]")) {
+                                if (native_arch != lxc_seccomp_arch_loongarch64) {
+                                        cur_rule_arch = lxc_seccomp_arch_unknown;
+                                        continue;
+                                }
+
+                                cur_rule_arch = lxc_seccomp_arch_loongarch64;
+                        }
 #endif
                        else {
                                goto bad_arch;
index ae5fdd0641c64d562a911636d9823d5237ff4748..58840a5981aa3df5f810b1fcb2a15ddba5554264 100644 (file)
@@ -50,6 +50,8 @@
                #if _MIPS_SIM == _MIPS_SIM_ABI64        /* n64 */
                        #define __NR_keyctl 5241
                #endif
+       #elif defined __loongarch64
+               #define __NR_keyctl 219
        #else
                #define -1
                #warning "__NR_keyctl not defined for your architecture"
@@ -87,6 +89,8 @@
                #if _MIPS_SIM == _MIPS_SIM_ABI64
                        #define __NR_memfd_create 5314
                #endif
+       #elif defined __loongarch64
+               #define __NR_memfd_create 279
        #else
                #define -1
                #warning "__NR_memfd_create not defined for your architecture"
                #if _MIPS_SIM == _MIPS_SIM_ABI64        /* n64 */
                        #define __NR_pivot_root 5151
                #endif
+       #elif defined __loongarch64
+               #define __NR_pivot_root 41
        #else
                #define -1
                #warning "__NR_pivot_root not defined for your architecture"
                #if _MIPS_SIM == _MIPS_SIM_ABI64        /* n64 */
                        #define __NR_setns 5303
                #endif
+       #elif defined __loongarch64
+               #define __NR_setns 268
        #else
                #define -1
                #warning "__NR_setns not defined for your architecture"
                #if _MIPS_SIM == _MIPS_SIM_ABI64        /* n64 */
                        #define __NR_sethostname 5165
                #endif
+       #elif defined __loongarch64
+               #define __NR_sethostname 161
        #else
                #define -1
                #warning "__NR_sethostname not defined for your architecture"
                #if _MIPS_SIM == _MIPS_SIM_ABI64        /* n64 */
                        #define __NR_signalfd4 5283
                #endif
+       #elif defined __loongarch64
+               #define __NR_signalfd4 74
        #else
                #define -1
                #warning "__NR_signalfd4 not defined for your architecture"
                #if _MIPS_SIM == _MIPS_SIM_ABI64        /* n64 */
                        #define __NR_unshare 5262
                #endif
+       #elif defined __loongarch64
+               #define __NR_unshare 97
        #else
                #define -1
                #warning "__NR_unshare not defined for your architecture"
                #if _MIPS_SIM == _MIPS_SIM_ABI64        /* n64 */
                        #define __NR_bpf 5315
                #endif
+       #elif defined __loongarch64
+               #define __NR_bpf 280
        #else
                #define -1
                #warning "__NR_bpf not defined for your architecture"
                #if _MIPS_SIM == _MIPS_SIM_ABI64        /* n64 */
                        #define __NR_faccessat 5259
                #endif
+       #elif defined __loongarch64
+               #define __NR_faccessat 48
        #else
                #define -1
                #warning "__NR_faccessat not defined for your architecture"
                #if _MIPS_SIM == _MIPS_SIM_ABI64        /* n64 */
                        #define __NR_seccomp 5312
                #endif
+       #elif defined __loongarch64
+               #define __NR_seccomp 277
        #else
                #define -1
                #warning "__NR_seccomp not defined for your architecture"
                #if _MIPS_SIM == _MIPS_SIM_ABI64        /* n64 */
                        #define __NR_gettid 5178
                #endif
+       #elif defined __loongarch64
+               #define __NR_gettid 178
        #else
                #define -1
                #warning "__NR_gettid not defined for your architecture"
                #if _MIPS_SIM == _MIPS_SIM_ABI64        /* n64 */
                        #define __NR_execveat 5316
                #endif
+       #elif defined __loongarch64
+               #define __NR_execveat 281
        #else
                #define -1
                #warning "__NR_execveat not defined for your architecture"
                #if _MIPS_SIM == _MIPS_SIM_ABI64        /* n64 */
                        #define __NR_personality (132 + 5000)
                #endif
+       #elif defined __loongarch64
+               #define __NR_personality 92
        #else
                #define -1
                #warning "__NR_personality not defined for your architecture"
index 6d72d664de32d6f723564128bc7c83faf6b4ddfa..f8b4d8a0a157f18d84b12e1774918d2ed6c00522 100644 (file)
 #endif
 
 static const char *const arches[] = {
-    "arm",   "armel",  "armhf",   "armv7l",    "athlon",  "i386",   "i486",
-    "i586",  "i686",   "linux32", "mips",      "mipsel",  "ppc",    "powerpc",
-    "x86",   "aarch64", "amd64",   "arm64",    "linux64", "mips64", "mips64el",
-    "ppc64", "ppc64el", "ppc64le", "powerpc64", "riscv64", "s390x",  "x86_64",
+    "arm",       "armel",    "armhf",    "armv7l",   "athlon",     "i386",         "i486",
+    "i586",      "i686",     "linux32",  "mips",     "mipsel",     "ppc",          "powerpc",
+    "x86",       "aarch64",  "amd64",    "arm64",    "linux64",    "loongarch64",  "mips64",
+    "mips64el",  "ppc64",    "ppc64el",  "ppc64le",  "powerpc64",  "riscv64",      "s390x",
+    "x86_64",
 };
 
 static bool parse_valid_architectures(void)