1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
|
From df17ac417e7baa686e54e391ed4ef049cd7fb63c Mon Sep 17 00:00:00 2001
From: zhaixiaojuan <zhaixiaojuan@loongson.cn>
Date: Thu, 2 Nov 2023 16:14:45 +0800
Subject: [PATCH] Add loongarch64 support
Signed-off-by: zhaixiaojuan <zhaixiaojuan@loongson.cn>
---
README.md | 1 +
config/bash/_lxc.in | 2 +-
src/lxc/confile.c | 57 ++++++++++++++++++++-------------------
src/lxc/seccomp.c | 19 +++++++++++++
src/lxc/syscall_numbers.h | 26 ++++++++++++++++++
src/tests/arch_parse.c | 9 ++++---
6 files changed, 81 insertions(+), 33 deletions(-)
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)
--
2.27.0
|