From: zhaixiaojuan Date: Thu, 2 Nov 2023 08:14:45 +0000 (+0800) Subject: Add loongarch64 support X-Git-Tag: v6.0.0~28^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=df17ac417e7baa686e54e391ed4ef049cd7fb63c;p=thirdparty%2Flxc.git Add loongarch64 support Signed-off-by: zhaixiaojuan --- diff --git a/README.md b/README.md index 4ddb1c5cd..dd02b3eae 100644 --- 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: diff --git a/config/bash/_lxc.in b/config/bash/_lxc.in index 6672bf02d..8a7ce16af 100644 --- a/config/bash/_lxc.in +++ b/config/bash/_lxc.in @@ -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 ) diff --git a/src/lxc/confile.c b/src/lxc/confile.c index 7a8a53418..bccc54f1a 100644 --- a/src/lxc/confile.c +++ b/src/lxc/confile.c @@ -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++) { diff --git a/src/lxc/seccomp.c b/src/lxc/seccomp.c index cefa18d0a..3ba54331d 100644 --- a/src/lxc/seccomp.c +++ b/src/lxc/seccomp.c @@ -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; diff --git a/src/lxc/syscall_numbers.h b/src/lxc/syscall_numbers.h index ae5fdd064..58840a598 100644 --- a/src/lxc/syscall_numbers.h +++ b/src/lxc/syscall_numbers.h @@ -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" @@ -122,6 +126,8 @@ #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" @@ -157,6 +163,8 @@ #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" @@ -192,6 +200,8 @@ #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" @@ -259,6 +269,8 @@ #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" @@ -294,6 +306,8 @@ #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" @@ -329,6 +343,8 @@ #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" @@ -364,6 +380,8 @@ #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" @@ -419,6 +437,8 @@ #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" @@ -454,6 +474,8 @@ #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" @@ -493,6 +515,8 @@ #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" @@ -732,6 +756,8 @@ #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" diff --git a/src/tests/arch_parse.c b/src/tests/arch_parse.c index 6d72d664d..f8b4d8a0a 100644 --- a/src/tests/arch_parse.c +++ b/src/tests/arch_parse.c @@ -37,10 +37,11 @@ #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)