-
Notifications
You must be signed in to change notification settings - Fork 196
/
gramine-syscall.patch
356 lines (334 loc) · 13.5 KB
/
gramine-syscall.patch
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
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
diff --git a/Makerules b/Makerules
index d1e139d03c1c448e14aee35af3e54ee7abe2180c..3f3d8739d3419804b35d00a69cab5538ec60f74e 100644
--- a/Makerules
+++ b/Makerules
@@ -818,7 +818,7 @@ verbose :=
endif # not -s
ARFLAGS := r$(verbose)
-CREATE_ARFLAGS := cru$(verbose)
+CREATE_ARFLAGS := cr$(verbose)
# This makes all the object files in the parent library archive.
diff --git a/elf/Makefile b/elf/Makefile
index fd77d0c7c8799c336c65278f6f8e939ed8707633..6fc16b46d041f2c80f3995be183644d276e8a294 100644
--- a/elf/Makefile
+++ b/elf/Makefile
@@ -1310,7 +1310,7 @@ $(objpfx)librtld.map: $(objpfx)dl-allobjs.os $(common-objpfx)libc_pic.a
# For lld, skip preceding addresses and values before matching the archive and the member.
$(objpfx)librtld.mk: $(objpfx)librtld.map Makefile
LC_ALL=C \
- sed -n 's@^[0-9a-f ]*$(common-objpfx)\([^(]*\)(\([^)]*\.os\)) *.*$$@\1 \2@p' \
+ sed -n 's@^[0-9a-f ]*$(subst @,\@,$(common-objpfx))\([^(]*\)(\([^)]*\.os\)) *.*$$@\1 \2@p' \
$< | \
while read lib file; do \
case $$lib in \
@@ -1318,7 +1318,7 @@ $(objpfx)librtld.mk: $(objpfx)librtld.map Makefile
LC_ALL=C grep -F -l /$$file \
$(common-objpfx)stamp.os $(common-objpfx)*/stamp.os | \
LC_ALL=C \
- sed 's@^$(common-objpfx)\([^/]*\)/stamp\.os$$@rtld-\1'" +=$$file@"\
+ sed 's@^$(subst @,\@,$(common-objpfx))\([^/]*\)/stamp\.os$$@rtld-\1'" +=$$file@"\
;; \
*/*.a) \
echo rtld-$${lib%%/*} += $$file ;; \
diff --git a/elf/dl-load.c b/elf/dl-load.c
index 1ad0868dad809d56c7ecced65ce482af4982abc9..8c4eae155754d7d9b140fcb838b8b74df6db0368 100644
--- a/elf/dl-load.c
+++ b/elf/dl-load.c
@@ -76,6 +76,8 @@ struct filebuf
#include <dl-prop.h>
#include <not-cancel.h>
+#include "gramine_entry_api.h"
+
#include <endian.h>
#if BYTE_ORDER == BIG_ENDIAN
# define byteorder ELFDATA2MSB
@@ -1490,6 +1492,8 @@ cannot enable executable stack as shared object requires");
DL_AFTER_LOAD (l);
#endif
+ gramine_register_library(l->l_name, l->l_addr);
+
/* Now that the object is fully initialized add it to the object list. */
_dl_add_to_namespace_list (l, nsid);
diff --git a/sysdeps/unix/sysv/linux/x86_64/____longjmp_chk.S b/sysdeps/unix/sysv/linux/x86_64/____longjmp_chk.S
index ffdf4624bf98648e4bc423cbdf1ce9b46ebf5fd2..d8c40f016f1659d64de1e642b665e9b7c8af00b1 100644
--- a/sysdeps/unix/sysv/linux/x86_64/____longjmp_chk.S
+++ b/sysdeps/unix/sysv/linux/x86_64/____longjmp_chk.S
@@ -89,7 +89,7 @@ ENTRY(____longjmp_chk)
xorl %edi, %edi
lea -sizeSS(%rsp), %RSI_LP
movl $__NR_sigaltstack, %eax
- syscall
+ GRAMINE_SYSCALL
/* Without working sigaltstack we cannot perform the test. */
testl %eax, %eax
jne .Lok2
diff --git a/sysdeps/unix/sysv/linux/x86_64/__start_context.S b/sysdeps/unix/sysv/linux/x86_64/__start_context.S
index a524c4d7b7f96008c2d38146418449c71cbe678a..a1a3f5f0803f23474960cd1413bb59adb5acaffe 100644
--- a/sysdeps/unix/sysv/linux/x86_64/__start_context.S
+++ b/sysdeps/unix/sysv/linux/x86_64/__start_context.S
@@ -51,7 +51,7 @@ ENTRY(__push___start_context)
movl $ARCH_CET_ALLOC_SHSTK, %edi
movl $__NR_arch_prctl, %eax
/* The new shadow stack base is returned in __ssp[1]. */
- syscall
+ GRAMINE_SYSCALL
testq %rax, %rax
jne L(hlt) /* This should never happen. */
diff --git a/sysdeps/unix/sysv/linux/x86_64/clone.S b/sysdeps/unix/sysv/linux/x86_64/clone.S
index b6b5cd497ac85be6e84e84da8cec4ec645f605ce..89195e4abe4353a94e5a4086dd2f2aea1947e98f 100644
--- a/sysdeps/unix/sysv/linux/x86_64/clone.S
+++ b/sysdeps/unix/sysv/linux/x86_64/clone.S
@@ -78,7 +78,7 @@ ENTRY (__clone)
/* End FDE now, because in the child the unwind info will be
wrong. */
cfi_endproc;
- syscall
+ GRAMINE_SYSCALL
testq %rax,%rax
jl SYSCALL_ERROR_LABEL
@@ -101,7 +101,7 @@ L(thread_start):
/* Call exit with return value from function call. */
movq %rax, %rdi
movl $SYS_ify(exit), %eax
- syscall
+ GRAMINE_SYSCALL
cfi_endproc;
cfi_startproc;
diff --git a/sysdeps/unix/sysv/linux/x86_64/clone3.S b/sysdeps/unix/sysv/linux/x86_64/clone3.S
index 18fc2ee966a1b748c9234013cc9c3b70c5701b78..9152ef6f0ea145c0d368d3834f0077cef167c005 100644
--- a/sysdeps/unix/sysv/linux/x86_64/clone3.S
+++ b/sysdeps/unix/sysv/linux/x86_64/clone3.S
@@ -57,7 +57,7 @@ ENTRY (__clone3)
/* End FDE now, because in the child the unwind info will be
wrong. */
cfi_endproc
- syscall
+ GRAMINE_SYSCALL
test %RAX_LP, %RAX_LP
jl SYSCALL_ERROR_LABEL
@@ -82,7 +82,7 @@ L(thread_start):
/* Call exit with return value from function call. */
movq %rax, %rdi
movl $SYS_ify(exit), %eax
- syscall
+ GRAMINE_SYSCALL
cfi_endproc
cfi_startproc
diff --git a/sysdeps/unix/sysv/linux/x86_64/getcontext.S b/sysdeps/unix/sysv/linux/x86_64/getcontext.S
index 3fab8de49c5e13240477b19d3e661442d313f01f..14ec8dbe1fb94fbacf0f58e20906b467897c7bbd 100644
--- a/sysdeps/unix/sysv/linux/x86_64/getcontext.S
+++ b/sysdeps/unix/sysv/linux/x86_64/getcontext.S
@@ -72,7 +72,7 @@ ENTRY(__getcontext)
mov %RSP_LP, %RSI_LP
movl $ARCH_CET_STATUS, %edi
movl $__NR_arch_prctl, %eax
- syscall
+ GRAMINE_SYSCALL
testq %rax, %rax
jz L(continue_no_err)
@@ -124,7 +124,7 @@ L(no_shstk):
#endif
movl $_NSIG8,%r10d
movl $__NR_rt_sigprocmask, %eax
- syscall
+ GRAMINE_SYSCALL
cmpq $-4095, %rax /* Check %rax for error. */
jae SYSCALL_ERROR_LABEL /* Jump to error handler if error. */
diff --git a/sysdeps/unix/sysv/linux/x86_64/libc_sigaction.c b/sysdeps/unix/sysv/linux/x86_64/libc_sigaction.c
index e6f9e27247698f8350730de19f58fccca267ee82..a87cbc14aa1d6314722d4b32ef22b8f6f2571e91 100644
--- a/sysdeps/unix/sysv/linux/x86_64/libc_sigaction.c
+++ b/sysdeps/unix/sysv/linux/x86_64/libc_sigaction.c
@@ -78,7 +78,7 @@ asm \
" .type __" #name ",@function\n" \
"__" #name ":\n" \
" movq $" #syscall ", %rax\n" \
- " syscall\n" \
+ " GRAMINE_SYSCALL\n" \
".LEND_" #name ":\n" \
".section .eh_frame,\"a\",@progbits\n" \
".LSTARTFRAME_" #name ":\n" \
diff --git a/sysdeps/unix/sysv/linux/x86_64/setcontext.S b/sysdeps/unix/sysv/linux/x86_64/setcontext.S
index 282c5266e6d00323e02a5472685f836742effedc..9acf0522e7a66fc6c2f1a68f3da9fe4e5c7d84f0 100644
--- a/sysdeps/unix/sysv/linux/x86_64/setcontext.S
+++ b/sysdeps/unix/sysv/linux/x86_64/setcontext.S
@@ -43,7 +43,7 @@ ENTRY(__setcontext)
movl $SIG_SETMASK, %edi
movl $_NSIG8,%r10d
movl $__NR_rt_sigprocmask, %eax
- syscall
+ GRAMINE_SYSCALL
/* Pop the pointer into RDX. The choice is arbitrary, but
leaving RDI and RSI available for use later can avoid
shuffling values. */
diff --git a/sysdeps/unix/sysv/linux/x86_64/swapcontext.S b/sysdeps/unix/sysv/linux/x86_64/swapcontext.S
index b101c70ac806e18f5bcaefabca572ff6e6246d5a..44bd713daf4108efd23f210624d258ee85448b51 100644
--- a/sysdeps/unix/sysv/linux/x86_64/swapcontext.S
+++ b/sysdeps/unix/sysv/linux/x86_64/swapcontext.S
@@ -76,7 +76,7 @@ ENTRY(__swapcontext)
movl $SIG_SETMASK, %edi
movl $_NSIG8,%r10d
movl $__NR_rt_sigprocmask, %eax
- syscall
+ GRAMINE_SYSCALL
cmpq $-4095, %rax /* Check %rax for error. */
jae SYSCALL_ERROR_LABEL /* Jump to error handler if error. */
@@ -116,7 +116,7 @@ ENTRY(__swapcontext)
mov %RSP_LP, %RSI_LP
movl $ARCH_CET_STATUS, %edi
movl $__NR_arch_prctl, %eax
- syscall
+ GRAMINE_SYSCALL
testq %rax, %rax
jz L(continue_no_err)
diff --git a/sysdeps/unix/sysv/linux/x86_64/syscall.S b/sysdeps/unix/sysv/linux/x86_64/syscall.S
index 192455a89883fc815ecb58677c0da6a7bb4583fa..4041fb7d9b73fc9743666f19ed33bb748ce499a0 100644
--- a/sysdeps/unix/sysv/linux/x86_64/syscall.S
+++ b/sysdeps/unix/sysv/linux/x86_64/syscall.S
@@ -34,7 +34,7 @@ ENTRY (syscall)
movq %r8, %r10
movq %r9, %r8
movq 8(%rsp),%r9 /* arg6 is on the stack. */
- syscall /* Do the system call. */
+ GRAMINE_SYSCALL /* Do the system call. */
cmpq $-4095, %rax /* Check %rax for error. */
jae SYSCALL_ERROR_LABEL /* Jump to error handler if error. */
ret /* Return to caller. */
diff --git a/sysdeps/unix/sysv/linux/x86_64/sysdep.h b/sysdeps/unix/sysv/linux/x86_64/sysdep.h
index 740abefcfd3612928bdd42c605ebdcf341d76667..4a675bd1ed886fa0b0c585356a4fb6194c07d2ed 100644
--- a/sysdeps/unix/sysv/linux/x86_64/sysdep.h
+++ b/sysdeps/unix/sysv/linux/x86_64/sysdep.h
@@ -26,6 +26,8 @@
/* Defines RTLD_PRIVATE_ERRNO. */
#include <dl-sysdep.h>
+#include "gramine_entry_api.h"
+
/* For Linux we can use the system call table in the header file
/usr/include/asm/unistd.h
of the kernel. But these symbols do not follow the SYS_* syntax
@@ -197,7 +199,7 @@
ZERO_EXTEND_##ulong_arg_1 \
ZERO_EXTEND_##ulong_arg_2 \
movl $SYS_ify (syscall_name), %eax; \
- syscall;
+ GRAMINE_SYSCALL;
# define DOARGS_0 /* nothing */
# define DOARGS_1 /* nothing */
@@ -243,7 +245,7 @@
({ \
unsigned long int resultvar; \
asm volatile ( \
- "syscall\n\t" \
+ "GRAMINE_SYSCALL\n\t" \
: "=a" (resultvar) \
: "0" (number) \
: "memory", REGISTERS_CLOBBERED_BY_SYSCALL); \
@@ -257,7 +259,7 @@
TYPEFY (arg1, __arg1) = ARGIFY (arg1); \
register TYPEFY (arg1, _a1) asm ("rdi") = __arg1; \
asm volatile ( \
- "syscall\n\t" \
+ "GRAMINE_SYSCALL\n\t" \
: "=a" (resultvar) \
: "0" (number), "r" (_a1) \
: "memory", REGISTERS_CLOBBERED_BY_SYSCALL); \
@@ -273,7 +275,7 @@
register TYPEFY (arg2, _a2) asm ("rsi") = __arg2; \
register TYPEFY (arg1, _a1) asm ("rdi") = __arg1; \
asm volatile ( \
- "syscall\n\t" \
+ "GRAMINE_SYSCALL\n\t" \
: "=a" (resultvar) \
: "0" (number), "r" (_a1), "r" (_a2) \
: "memory", REGISTERS_CLOBBERED_BY_SYSCALL); \
@@ -291,7 +293,7 @@
register TYPEFY (arg2, _a2) asm ("rsi") = __arg2; \
register TYPEFY (arg1, _a1) asm ("rdi") = __arg1; \
asm volatile ( \
- "syscall\n\t" \
+ "GRAMINE_SYSCALL\n\t" \
: "=a" (resultvar) \
: "0" (number), "r" (_a1), "r" (_a2), "r" (_a3) \
: "memory", REGISTERS_CLOBBERED_BY_SYSCALL); \
@@ -311,7 +313,7 @@
register TYPEFY (arg2, _a2) asm ("rsi") = __arg2; \
register TYPEFY (arg1, _a1) asm ("rdi") = __arg1; \
asm volatile ( \
- "syscall\n\t" \
+ "GRAMINE_SYSCALL\n\t" \
: "=a" (resultvar) \
: "0" (number), "r" (_a1), "r" (_a2), "r" (_a3), "r" (_a4) \
: "memory", REGISTERS_CLOBBERED_BY_SYSCALL); \
@@ -333,7 +335,7 @@
register TYPEFY (arg2, _a2) asm ("rsi") = __arg2; \
register TYPEFY (arg1, _a1) asm ("rdi") = __arg1; \
asm volatile ( \
- "syscall\n\t" \
+ "GRAMINE_SYSCALL\n\t" \
: "=a" (resultvar) \
: "0" (number), "r" (_a1), "r" (_a2), "r" (_a3), "r" (_a4), \
"r" (_a5) \
@@ -358,7 +360,7 @@
register TYPEFY (arg2, _a2) asm ("rsi") = __arg2; \
register TYPEFY (arg1, _a1) asm ("rdi") = __arg1; \
asm volatile ( \
- "syscall\n\t" \
+ "GRAMINE_SYSCALL\n\t" \
: "=a" (resultvar) \
: "0" (number), "r" (_a1), "r" (_a2), "r" (_a3), "r" (_a4), \
"r" (_a5), "r" (_a6) \
diff --git a/sysdeps/unix/sysv/linux/x86_64/vfork.S b/sysdeps/unix/sysv/linux/x86_64/vfork.S
index 1a1e3039c72dc2ec66a56f2ad0961bbd83de13dd..ae5b208ab88e0a898ca7fb49361d82846c21f4dc 100644
--- a/sysdeps/unix/sysv/linux/x86_64/vfork.S
+++ b/sysdeps/unix/sysv/linux/x86_64/vfork.S
@@ -35,7 +35,7 @@ ENTRY (__vfork)
/* Stuff the syscall number in RAX and enter into the kernel. */
movl $SYS_ify (vfork), %eax
- syscall
+ GRAMINE_SYSCALL
/* Push back the return PC. */
pushq %rdi
diff --git a/sysdeps/unix/sysv/linux/x86_64/x32/times.c b/sysdeps/unix/sysv/linux/x86_64/x32/times.c
index aea8e8c94989d3686b131866798d7bde4cc69f1f..246e2ae4c749f15af848a9c53bd7810f6dc1c89f 100644
--- a/sysdeps/unix/sysv/linux/x86_64/x32/times.c
+++ b/sysdeps/unix/sysv/linux/x86_64/x32/times.c
@@ -26,7 +26,7 @@
TYPEFY (arg1, __arg1) = ARGIFY (arg1); \
register TYPEFY (arg1, _a1) asm ("rdi") = __arg1; \
asm volatile ( \
- "syscall\n\t" \
+ "GRAMINE_SYSCALL\n\t" \
: "=a" (resultvar) \
: "0" (number), "r" (_a1) \
: "memory", REGISTERS_CLOBBERED_BY_SYSCALL); \
diff --git a/sysdeps/unix/x86_64/sysdep.h b/sysdeps/unix/x86_64/sysdep.h
index 0ec37c62aac020d3cc6b37fb38cb333aae6991a9..f5e6975b364eccb3f57b88a2682e785b54489094 100644
--- a/sysdeps/unix/x86_64/sysdep.h
+++ b/sysdeps/unix/x86_64/sysdep.h
@@ -25,7 +25,7 @@
#define DO_CALL(syscall_name, args) \
lea SYS_ify (syscall_name), %rax; \
- syscall
+ GRAMINE_SYSCALL
#define r0 %rax /* Normal return-value register. */
#define r1 %rbx /* Secondary return-value register. */
diff --git a/sysdeps/x86_64/nptl/tls.h b/sysdeps/x86_64/nptl/tls.h
index 75f80209758aa19cc59c413e4bbd1a565e5b9696..bb72d936679ff73b378c1b8dc2b894e43226fd91 100644
--- a/sysdeps/x86_64/nptl/tls.h
+++ b/sysdeps/x86_64/nptl/tls.h
@@ -30,6 +30,8 @@
# include <kernel-features.h>
# include <dl-dtv.h>
+# include "gramine_entry_api.h"
+
/* Replacement type for __m128 since this file is included by ld.so,
which is compiled with -mno-sse. It must not change the alignment
of rtld_savespace_sse. */
@@ -149,7 +151,7 @@ _Static_assert (offsetof (tcbhead_t, __glibc_unused2) == 0x80,
_head->self = _thrdescr; \
\
/* It is a simple syscall to set the %fs value for the thread. */ \
- asm volatile ("syscall" \
+ asm volatile ("GRAMINE_SYSCALL" \
: "=a" (_result) \
: "0" ((unsigned long int) __NR_arch_prctl), \
"D" ((unsigned long int) ARCH_SET_FS), \