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
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
|
--- spack-src/src/mtcp/restore_libc.c.bak 2019-08-15 03:32:13.000000000 +0900
+++ spack-src/src/mtcp/restore_libc.c 2020-10-09 12:45:40.911253793 +0900
@@ -356,7 +356,17 @@
struct user_desc gdtentrytls[2];
gdtentrytls[0].entry_number = get_tls_segreg() / 8;
- if (tls_get_thread_area(&gdtentrytls[0], &gdtentrytls[1]) == -1) {
+
+#if defined(__i386__) || defined(__x86_64__)
+ if (tls_get_thread_area(&gdtentrytls[0], &gdtentrytls[1]) == -1)
+#elif defined(__arm__) || defined(__aarch64__)
+ // FIXME: ARM uses tls_get_thread_area with incompatible syntax,
+ // setting global variable myinfo_gs. Fix this to work
+ // for per-thread storage (multiple threads).
+ // See commit 591a1631 (2.6.0), 7d02a2e0 (3.0): PR #609
+ if (tls_get_thread_area(&gdtentrytls[0], myinfo_gs) == -1)
+#endif
+ {
PRINTF("Error getting GDT TLS entry: %d\n", errno);
_exit(0);
}
@@ -573,7 +583,18 @@
*/
i = tlsInfo->TLSSEGREG / 8;
tlsInfo->gdtentrytls[0].entry_number = i;
- if (tls_get_thread_area (&(tlsInfo->gdtentrytls[0]), &(tlsInfo->gdtentrytls[1])) == -1) {
+
+#if defined(__i386__) || defined(__x86_64__)
+ if (tls_get_thread_area(&(tlsInfo->gdtentrytls[0]),
+ &(tlsInfo->gdtentrytls[1])) == -1)
+#elif defined(__arm__) || defined(__aarch64__)
+ // FIXME: ARM uses tls_get_thread_area with incompatible syntax,
+ // setting global variable myinfo_gs. Fix this to work
+ // for per-thread storage (multiple threads).
+ // See commit 591a1631 (2.6.0), 7d02a2e0 (3.0): PR #609
+ if (tls_get_thread_area (&(tlsInfo->gdtentrytls[0]), myinfo_gs) == -1)
+#endif
+ {
PRINTF("Error saving GDT TLS entry: %d\n", errno);
_exit(0);
}
@@ -611,9 +632,14 @@
}
/* Now pass this to the kernel, so it can adjust the segment descriptors:
- * tls_set_thread_areaa() uses arg1 for fs and arg2 for gs.
- * This will make different kernel calls according to the CPU architecture. */
- if (tls_set_thread_area (&(tlsInfo->gdtentrytls[0]), &(tlsInfo->gdtentrytls[1])) != 0) {
+ * i386, x86_64: tls_set_thread_areaa() uses arg1 for fs and arg2 for gs.
+ * This will make different kernel calls according to the CPU architecture. */#if defined(__i386__) || defined(__x86_64__)
+ if (tls_set_thread_area(&(tlsInfo->gdtentrytls[0]),
+ &(tlsInfo->gdtentrytls[1])) != 0)
+#elif defined(__arm__) || defined(__aarch64__)
+ if (tls_set_thread_area (&(tlsInfo->gdtentrytls[0]), myinfo_gs) != 0)
+#endif
+ {
PRINTF("Error restoring GDT TLS entry: %d\n", errno);
mtcp_abort();
}
--- spack-src/src/mtcp/mtcp_restart.c.bak 2019-08-15 03:32:13.000000000 +0900
+++ spack-src/src/mtcp/mtcp_restart.c 2020-10-09 13:07:13.231130185 +0900
@@ -462,8 +462,14 @@
CLEAN_FOR_64_BIT(sub %0, %%ebp; )
: : "r" (rinfo.stack_offset) : "memory");
-#elif defined(__arm__) || defined(__aarch64__)
- asm volatile ("sub sp, sp, %0; mov fp, fp, %0 \n\t"
+#elif defined(__arm__)
+ asm volatile ("sub sp, sp, %0"
+ : : "r" (rinfo.stack_offset) : "memory");
+
+#elif defined(__aarch64__)
+ // Use x29 instead of fp because GCC's inline assembler does not recognize fp.
+ asm volatile ("sub sp, sp, %0\n\t"
+ "sub x29, x29, %0"
: : "r" (rinfo.stack_offset) : "memory");
#else /* if defined(__i386__) || defined(__x86_64__) */
@@ -1118,9 +1124,19 @@
}
/* Now pass this to the kernel, so it can adjust the segment descriptor.
- * tls_set_thread_areaa() uses arg1 for fs and arg2 for gs.
+ * i386, x86_65: tls_set_thread_areaa() uses arg1 for fs and arg2 for gs.
* This will make different kernel calls according to the CPU architecture. */
- if (tls_set_thread_area (&(tlsInfo->gdtentrytls[0]), &(tlsInfo->gdtentrytls[1])) != 0) {
+#if defined(__i386__) || defined(__x86_64__)
+ if (tls_set_thread_area(&(tlsInfo->gdtentrytls[0]),
+ &(tlsInfo->gdtentrytls[1])) != 0)
+#elif defined(__arm__) || defined(__aarch64__)
+ // FIXME: ARM uses tls_get_thread_area with incompatible syntax,
+ // setting global variable myinfo_gs. Fix this to work
+ // for per-thread storage (multiple threads).
+ // See commit 591a1631 (2.6.0), 7d02a2e0 (3.0): PR #609
+ if (tls_set_thread_area (&(tlsInfo->gdtentrytls[0]), myinfo_gs) != 0)
+#endif
+ {
MTCP_PRINTF("Error restoring GDT TLS entry; errno: %d\n", mtcp_sys_errno);
mtcp_abort();
}
--- spack-src/src/plugin/pid/pid_miscwrappers.cpp.bak 2019-08-15 03:32:13.000000000 +0900
+++ spack-src/src/plugin/pid/pid_miscwrappers.cpp 2020-10-09 13:21:00.221078403 +0900
@@ -21,14 +21,6 @@
#include <semaphore.h>
#include <sys/syscall.h>
-#ifdef __aarch64__
-# define __ARCH_WANT_SYSCALL_DEPRECATED
-// SYS_getpgrp is a deprecated kernel call in aarch64, but in favor of what?
-# include <asm-generic/unistd.h>
-// SYS_getpgrp undefined in aarch64, but add extra insurance
-# undef SYS_getpgrp
-# define SYS_getpgrp __NR_getpgrp
-#endif
#include <linux/version.h>
#include "config.h" // for HAS_CMA
@@ -355,11 +347,16 @@
break;
}
- case SYS_getpgrp:
- {
- ret = getpgrp();
- break;
- }
+// SYS_getpgrp undefined in aarch64.
+// Presumably, it's handled by libc, and is not a kernel call
+// in AARCH64 (e.g., v5.01).
+#ifndef __aarch64__
+ case SYS_getpgrp:
+ {
+ ret = getpgrp();
+ break;
+ }
+#endif
case SYS_getpgid:
{
--- spack-src/src/miscwrappers.cpp.bak 2019-08-15 03:32:13.000000000 +0900
+++ spack-src/src/miscwrappers.cpp 2020-10-09 13:51:30.611006815 +0900
@@ -41,26 +41,28 @@
#endif
#ifdef __aarch64__
+
// We must support all deprecated syscalls in case the end user code uses it.
# define __ARCH_WANT_SYSCALL_DEPRECATED
# define __ARCH_WANT_SYSCALL_NO_AT
# define __ARCH_WANT_SYSCALL_NO_FLAGS
+
// SYS_fork is a deprecated kernel call in aarch64; in favor of SYS_clone?
# include <asm-generic/unistd.h>
-// SYS_fork undefined in aarch64, but add extra insurance
-# undef SYS_fork
-# undef SYS_open
-# undef SYS_pipe
-# undef SYS_poll
-# define SYS_fork __NR_fork
-# define SYS_open __NR_open
-# define SYS_pipe __NR_pipe
-# define SYS_poll __NR_poll
-// These kernel calls are not deprecated. But SYS_XXX is not defined for them.
-# define SYS_epoll_create __NR_epoll_create
-# define SYS_inotify_init __NR_inotify_init
-# define SYS_signalfd __NR_signalfd
-# define SYS_eventfd __NR_eventfd
+
+// SYS_fork, etc., are undefined in aarch64
+// Presumably, libc translates the POSIX syscalls into later kernel calls.
+// # define SYS_fork __NR_fork
+// # define SYS_open __NR_open
+// # define SYS_pipe __NR_pipe
+// # define SYS_poll __NR_poll
+
+// These kernel calls are now often gone on aarch64. SYS_XXX should not be
+// defined for them.
+// # define SYS_epoll_create __NR_epoll_create
+// # define SYS_inotify_init __NR_inotify_init
+// # define SYS_signalfd __NR_signalfd
+// # define SYS_eventfd __NR_eventfd
#endif
using namespace dmtcp;
@@ -321,23 +323,27 @@
break;
}
+# ifndef __aarch64__
case SYS_fork:
{
ret = fork();
break;
}
+# endif // ifndef __aarch64__
case SYS_exit:
{
SYSCALL_GET_ARG(int,status);
exit(status);
break;
}
+# ifndef __aarch64__
case SYS_open:
{
SYSCALL_GET_ARGS_3(const char*,pathname,int,flags,mode_t,mode);
ret = open(pathname, flags, mode);
break;
}
+# endif // ifndef __aarch64__
case SYS_close:
{
SYSCALL_GET_ARG(int,fd);
@@ -443,12 +449,14 @@
}
#endif
+# ifndef __aarch64__
case SYS_pipe:
{
SYSCALL_GET_ARG(int*,fds);
ret = pipe(fds);
break;
}
+# endif // ifdef __aarch64__
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,27)) && __GLIBC_PREREQ(2,9)
case SYS_pipe2:
{
@@ -498,33 +506,44 @@
}
# endif
#endif
+# ifndef __aarch64__
case SYS_poll:
{
SYSCALL_GET_ARGS_3(struct pollfd *,fds,nfds_t,nfds,int,timeout);
ret = poll(fds, nfds, timeout);
break;
}
+# endif // ifdef __aarch64__
+# ifndef __aarch64__
case SYS_epoll_create:
{
SYSCALL_GET_ARG(int,size);
ret = epoll_create(size);
break;
}
+# endif // ifdef __aarch64__
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,13) && __GLIBC_PREREQ(2,4)
+# ifndef __aarch64__
case SYS_inotify_init:
{
ret = inotify_init();
break;
}
-#endif
+#endif // ifdef __aarch64__
+#endif // if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 13) && __GLIBC_PREREQ(2,
+ // 4)
+
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22) && __GLIBC_PREREQ(2,8)
+# ifndef __aarch64__
case SYS_signalfd:
{
SYSCALL_GET_ARGS_3(int,fd,sigset_t *,mask,int,flags);
ret = signalfd(fd, mask, flags);
break;
}
-#endif
+#endif // ifndef __aarch64__
+#endif // if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 22) && __GLIBC_PREREQ(2,
+ // 8)
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,27) && __GLIBC_PREREQ(2,8)
case SYS_signalfd4:
{
@@ -534,13 +553,16 @@
}
#endif
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22) && __GLIBC_PREREQ(2,8)
+# ifndef __aarch64__
case SYS_eventfd:
{
SYSCALL_GET_ARGS_2(unsigned int,initval,int,flags);
ret = eventfd(initval, flags);
break;
}
-#endif
+#endif // ifndef __aarch64__
+#endif // if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 22) && __GLIBC_PREREQ(2,
+ // 8)
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,27) && __GLIBC_PREREQ(2,8)
case SYS_eventfd2:
{
--- spack-src/src/execwrappers.cpp.bak 2019-08-15 03:32:13.000000000 +0900
+++ spack-src/src/execwrappers.cpp 2020-10-09 14:01:25.910998477 +0900
@@ -20,14 +20,6 @@
****************************************************************************/
#include <sys/syscall.h>
-#ifdef __aarch64__
-# define __ARCH_WANT_SYSCALL_DEPRECATED
-// SYS_fork is a deprecated kernel call in aarch64; in favor of SYS_clone?
-# include <asm-generic/unistd.h>
-// SYS_fork undefined in aarch64, but add extra insurance
-# undef SYS_fork
-# define SYS_fork __NR_fork
-#endif
#include "constants.h"
#include "uniquepid.h"
#include "dmtcpworker.h"
@@ -168,7 +160,11 @@
* resuming to run under dmtcp
*/
(dmtcp_delay_resume_blocked != NULL && dmtcp_delay_resume_blocked())) {
+#ifndef __aarch64__
return _real_syscall(SYS_fork);
+#else
+ return _real_fork();
+#endif
}
/* Acquire the wrapperExeution lock to prevent checkpoint to happen while
|