glibc-2.23.patch 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629
  1. diff -ruNp a/elf/dl-load.c b/elf/dl-load.c
  2. --- a/elf/dl-load.c
  3. +++ b/elf/dl-load.c
  4. @@ -45,6 +45,7 @@
  5. #include <dl-machine-reject-phdr.h>
  6. #include <dl-sysdep-open.h>
  7. +#include <glibc-version.h>
  8. #include <endian.h>
  9. #if BYTE_ORDER == BIG_ENDIAN
  10. @@ -1415,6 +1416,9 @@ cannot enable executable stack as shared
  11. DL_AFTER_LOAD (l);
  12. #endif
  13. + /* register the library to SHIM */
  14. + register_library(l->l_name, l->l_addr);
  15. +
  16. /* Now that the object is fully initialized add it to the object list. */
  17. _dl_add_to_namespace_list (l, nsid);
  18. diff -ruNp a/elf/Makefile b/elf/Makefile
  19. --- a/elf/Makefile
  20. +++ b/elf/Makefile
  21. @@ -21,7 +21,7 @@ subdir := elf
  22. include ../Makeconfig
  23. -headers = elf.h bits/elfclass.h link.h bits/link.h
  24. +headers = elf.h bits/elfclass.h link.h bits/link.h syscalldb.h
  25. routines = $(all-dl-routines) dl-support dl-iteratephdr \
  26. dl-addr enbl-secure dl-profstub \
  27. dl-origin dl-libc dl-sym dl-tsd dl-sysdep
  28. @@ -31,7 +31,8 @@ routines = $(all-dl-routines) dl-support
  29. dl-routines = $(addprefix dl-,load lookup object reloc deps hwcaps \
  30. runtime error init fini debug misc \
  31. version profile conflict tls origin scope \
  32. - execstack caller open close trampoline)
  33. + execstack caller open close trampoline) \
  34. + syscalldb syscallas
  35. ifeq (yes,$(use-ldconfig))
  36. dl-routines += dl-cache
  37. endif
  38. diff -ruNp a/elf/rtld.c b/elf/rtld.c
  39. --- a/elf/rtld.c
  40. +++ b/elf/rtld.c
  41. @@ -332,6 +332,23 @@ _dl_start_final (void *arg, struct dl_st
  42. return start_addr;
  43. }
  44. +/* For graphene, check if glibc version match to the compatible SHIM
  45. + library. If not, tell the user to update glibc. */
  46. +#include "glibc-version.h"
  47. +
  48. +const unsigned int glibc_version __attribute__((weak)) = GLIBC_VERSION;
  49. +
  50. +static void __attribute__((noinline,optimize("-O0")))
  51. +check_glibc_version (void)
  52. +{
  53. + if (glibc_version != GLIBC_VERSION)
  54. + {
  55. + _dl_fatal_printf ("Warning from Graphene: "
  56. + "Glibc version is incorrect. Please rebuild Glibc.\n");
  57. + _exit (1);
  58. + }
  59. +}
  60. +
  61. static ElfW(Addr) __attribute_used__ internal_function
  62. _dl_start (void *arg)
  63. {
  64. @@ -402,6 +419,9 @@ _dl_start (void *arg)
  65. therefore need not test whether we have to allocate the array
  66. for the relocation results (as done in dl-reloc.c). */
  67. + /* For Graphene, check if the glibc version is correct. */
  68. + check_glibc_version();
  69. +
  70. /* Now life is sane; we can call functions and access global data.
  71. Set up to use the operating system facilities, and find out from
  72. the operating system's program loader where to find the program
  73. diff -ruNp a/elf/Versions b/elf/Versions
  74. --- a/elf/Versions
  75. +++ b/elf/Versions
  76. @@ -65,4 +68,7 @@ ld {
  77. # Pointer protection.
  78. __pointer_chk_guard;
  79. }
  80. + SHIM {
  81. + syscalldb; glibc_version; glibc_option; register_library;
  82. + }
  83. }
  84. diff -ruNp a/Makeconfig b/Makeconfig
  85. --- a/Makeconfig
  86. +++ b/Makeconfig
  87. @@ -841,7 +841,8 @@ endif # $(+cflags) == ""
  88. # current directory.
  89. +includes = -I$(..)include $(if $(subdir),$(objpfx:%/=-I%)) \
  90. $(+sysdep-includes) $(includes) \
  91. - $(patsubst %/,-I%,$(..)) $(libio-include) -I. $(sysincludes)
  92. + $(patsubst %/,-I%,$(..)) $(libio-include) -I. $(sysincludes) \
  93. + -I$(common-objpfx)../shim/include
  94. # Since libio has several internal header files, we use a -I instead
  95. # of many little headers in the include directory.
  96. diff -ruNp a/Makefile b/Makefile
  97. --- a/Makefile
  98. +++ b/Makefile
  99. @@ -178,6 +178,8 @@ $(inst_includedir)/gnu/stubs.h: $(+force
  100. install-others-nosubdir: $(installed-stubs)
  101. endif
  102. +# For Graphene
  103. +CFLAGS-syscalldb.c = -fPIC
  104. # Since stubs.h is never needed when building the library, we simplify the
  105. # hairy installation process by producing it in place only as the last part
  106. diff -ruNp a/sysdeps/unix/sysv/linux/_exit.c b/sysdeps/unix/sysv/linux/_exit.c
  107. --- a/sysdeps/unix/sysv/linux/_exit.c
  108. +++ b/sysdeps/unix/sysv/linux/_exit.c
  109. @@ -28,9 +28,9 @@ _exit (int status)
  110. while (1)
  111. {
  112. #ifdef __NR_exit_group
  113. - INLINE_SYSCALL (exit_group, 1, status);
  114. + INLINE_SYSCALL_ASM (exit_group, 1, status);
  115. #endif
  116. - INLINE_SYSCALL (exit, 1, status);
  117. + INLINE_SYSCALL_ASM (exit, 1, status);
  118. #ifdef ABORT_INSTRUCTION
  119. ABORT_INSTRUCTION;
  120. diff -ruNp a/sysdeps/unix/sysv/linux/x86_64/cancellation.S b/sysdeps/unix/sysv/linux/x86_64/cancellation.S
  121. --- a/sysdeps/unix/sysv/linux/x86_64/cancellation.S
  122. +++ b/sysdeps/unix/sysv/linux/x86_64/cancellation.S
  123. @@ -111,7 +111,7 @@ ENTRY(__pthread_disable_asynccancel)
  124. xorq %r10, %r10
  125. addq $CANCELHANDLING, %rdi
  126. LOAD_PRIVATE_FUTEX_WAIT (%esi)
  127. - syscall
  128. + SYSCALLDB
  129. movl %fs:CANCELHANDLING, %eax
  130. jmp 3b
  131. END(__pthread_disable_asynccancel)
  132. diff -ruNp a/sysdeps/unix/sysv/linux/x86_64/clone.S b/sysdeps/unix/sysv/linux/x86_64/clone.S
  133. --- a/sysdeps/unix/sysv/linux/x86_64/clone.S
  134. +++ b/sysdeps/unix/sysv/linux/x86_64/clone.S
  135. @@ -76,7 +76,7 @@ ENTRY (__clone)
  136. /* End FDE now, because in the child the unwind info will be
  137. wrong. */
  138. cfi_endproc;
  139. - syscall
  140. + SYSCALLDB
  141. testq %rax,%rax
  142. jl SYSCALL_ERROR_LABEL
  143. @@ -98,7 +98,7 @@ L(thread_start):
  144. movl $-1, %eax
  145. jne 2f
  146. movl $SYS_ify(getpid), %eax
  147. - syscall
  148. + SYSCALLDB
  149. 2: movl %eax, %fs:PID
  150. movl %eax, %fs:TID
  151. 1:
  152. diff -ruNp a/sysdeps/unix/sysv/linux/x86_64/getcontext.S b/sysdeps/unix/sysv/linux/x86_64/getcontext.S
  153. --- a/sysdeps/unix/sysv/linux/x86_64/getcontext.S
  154. +++ b/sysdeps/unix/sysv/linux/x86_64/getcontext.S
  155. @@ -75,7 +75,7 @@ ENTRY(__getcontext)
  156. #endif
  157. movl $_NSIG8,%r10d
  158. movl $__NR_rt_sigprocmask, %eax
  159. - syscall
  160. + SYSCALLDB
  161. cmpq $-4095, %rax /* Check %rax for error. */
  162. jae SYSCALL_ERROR_LABEL /* Jump to error handler if error. */
  163. diff -ruNp a/sysdeps/unix/sysv/linux/x86_64/____longjmp_chk.S b/sysdeps/unix/sysv/linux/x86_64/____longjmp_chk.S
  164. --- a/sysdeps/unix/sysv/linux/x86_64/____longjmp_chk.S
  165. +++ b/sysdeps/unix/sysv/linux/x86_64/____longjmp_chk.S
  166. @@ -84,7 +84,8 @@ ENTRY(____longjmp_chk)
  167. xorl %edi, %edi
  168. lea -sizeSS(%rsp), %RSI_LP
  169. movl $__NR_sigaltstack, %eax
  170. - syscall
  171. + SYSCALLDB
  172. +
  173. /* Without working sigaltstack we cannot perform the test. */
  174. testl %eax, %eax
  175. jne .Lok2
  176. diff -ruNp a/sysdeps/unix/sysv/linux/x86_64/lowlevellock.S b/sysdeps/unix/sysv/linux/x86_64/lowlevellock.S
  177. --- a/sysdeps/unix/sysv/linux/x86_64/lowlevellock.S
  178. +++ b/sysdeps/unix/sysv/linux/x86_64/lowlevellock.S
  179. @@ -90,7 +90,7 @@ __lll_lock_wait_private:
  180. 1: LIBC_PROBE (lll_lock_wait_private, 1, %rdi)
  181. movl $SYS_futex, %eax
  182. - syscall
  183. + SYSCALLDB
  184. 2: movl %edx, %eax
  185. xchgl %eax, (%rdi) /* NB: lock is implied */
  186. @@ -130,7 +130,7 @@ __lll_lock_wait:
  187. 1: LIBC_PROBE (lll_lock_wait, 2, %rdi, %rsi)
  188. movl $SYS_futex, %eax
  189. - syscall
  190. + SYSCALLDB
  191. 2: movl %edx, %eax
  192. xchgl %eax, (%rdi) /* NB: lock is implied */
  193. @@ -185,7 +185,7 @@ __lll_timedlock_wait:
  194. 1: movl $SYS_futex, %eax
  195. movl $2, %edx
  196. - syscall
  197. + SYSCALLDB
  198. 2: xchgl %edx, (%rdi) /* NB: lock is implied */
  199. @@ -279,7 +279,7 @@ __lll_timedlock_wait:
  200. LOAD_FUTEX_WAIT (%esi)
  201. movq %r12, %rdi
  202. movl $SYS_futex, %eax
  203. - syscall
  204. + SYSCALLDB
  205. /* NB: %edx == 2 */
  206. xchgl %edx, (%r12)
  207. @@ -336,7 +336,7 @@ __lll_unlock_wake_private:
  208. LOAD_PRIVATE_FUTEX_WAKE (%esi)
  209. movl $1, %edx /* Wake one thread. */
  210. movl $SYS_futex, %eax
  211. - syscall
  212. + SYSCALLDB
  213. popq %rdx
  214. cfi_adjust_cfa_offset(-8)
  215. @@ -366,7 +366,7 @@ __lll_unlock_wake:
  216. LOAD_FUTEX_WAKE (%esi)
  217. movl $1, %edx /* Wake one thread. */
  218. movl $SYS_futex, %eax
  219. - syscall
  220. + SYSCALLDB
  221. popq %rdx
  222. cfi_adjust_cfa_offset(-8)
  223. @@ -436,7 +436,7 @@ __lll_timedwait_tid:
  224. #endif
  225. movq %r12, %rdi
  226. movl $SYS_futex, %eax
  227. - syscall
  228. + SYSCALLDB
  229. cmpl $0, (%rdi)
  230. jne 1f
  231. diff -ruNp a/sysdeps/unix/sysv/linux/x86_64/lowlevelrobustlock.S b/sysdeps/unix/sysv/linux/x86_64/lowlevelrobustlock.S
  232. --- a/sysdeps/unix/sysv/linux/x86_64/lowlevelrobustlock.S
  233. +++ b/sysdeps/unix/sysv/linux/x86_64/lowlevelrobustlock.S
  234. @@ -80,7 +80,7 @@ __lll_robust_lock_wait:
  235. jnz 2f
  236. 1: movl $SYS_futex, %eax
  237. - syscall
  238. + SYSCALLDB
  239. movl (%rdi), %eax
  240. @@ -145,7 +145,7 @@ __lll_robust_timedlock_wait:
  241. jnz 6f
  242. 5: movl $SYS_futex, %eax
  243. - syscall
  244. + SYSCALLDB
  245. movl %eax, %ecx
  246. movl (%rdi), %eax
  247. @@ -257,7 +257,7 @@ __lll_robust_timedlock_wait:
  248. LOAD_FUTEX_WAIT (%esi)
  249. movq %r12, %rdi
  250. movl $SYS_futex, %eax
  251. - syscall
  252. + SYSCALLDB
  253. movq %rax, %rcx
  254. movl (%r12), %eax
  255. diff -ruNp a/sysdeps/unix/sysv/linux/x86_64/pthread_cond_broadcast.S b/sysdeps/unix/sysv/linux/x86_64/pthread_cond_broadcast.S
  256. --- a/sysdeps/unix/sysv/linux/x86_64/pthread_cond_broadcast.S
  257. +++ b/sysdeps/unix/sysv/linux/x86_64/pthread_cond_broadcast.S
  258. @@ -87,7 +87,7 @@ ENTRY(__pthread_cond_broadcast)
  259. movl $SYS_futex, %eax
  260. movl $1, %edx
  261. movl $0x7fffffff, %r10d
  262. - syscall
  263. + SYSCALLDB
  264. /* For any kind of error, which mainly is EAGAIN, we try again
  265. with WAKE. The general test also covers running on old
  266. @@ -103,7 +103,7 @@ ENTRY(__pthread_cond_broadcast)
  267. movl $SYS_futex, %eax
  268. movl $1, %edx
  269. movl $0x7fffffff, %r10d
  270. - syscall
  271. + SYSCALLDB
  272. /* For any kind of error, which mainly is EAGAIN, we try again
  273. with WAKE. The general test also covers running on old
  274. @@ -169,7 +169,7 @@ ENTRY(__pthread_cond_broadcast)
  275. orl $FUTEX_WAKE, %esi
  276. #endif
  277. movl $SYS_futex, %eax
  278. - syscall
  279. + SYSCALLDB
  280. jmp 10b
  281. END(__pthread_cond_broadcast)
  282. diff -ruNp a/sysdeps/unix/sysv/linux/x86_64/pthread_cond_signal.S b/sysdeps/unix/sysv/linux/x86_64/pthread_cond_signal.S
  283. --- a/sysdeps/unix/sysv/linux/x86_64/pthread_cond_signal.S
  284. +++ b/sysdeps/unix/sysv/linux/x86_64/pthread_cond_signal.S
  285. @@ -78,7 +78,7 @@ ENTRY(__pthread_cond_signal)
  286. addq $cond_lock, %r8
  287. #endif
  288. movl $FUTEX_OP_CLEAR_WAKE_IF_GT_ONE, %r9d
  289. - syscall
  290. + SYSCALLDB
  291. #if cond_lock != 0
  292. subq $cond_lock, %r8
  293. #endif
  294. @@ -95,7 +95,7 @@ ENTRY(__pthread_cond_signal)
  295. movq %rcx, %r8
  296. xorq %r10, %r10
  297. movl (%rdi), %r9d // XXX Can this be right?
  298. - syscall
  299. + SYSCALLDB
  300. leaq -cond_futex(%rdi), %r8
  301. @@ -114,7 +114,7 @@ ENTRY(__pthread_cond_signal)
  302. movl $SYS_futex, %eax
  303. /* %rdx should be 1 already from $FUTEX_WAKE_OP syscall.
  304. movl $1, %edx */
  305. - syscall
  306. + SYSCALLDB
  307. /* Unlock. */
  308. 4: LOCK
  309. diff -ruNp a/sysdeps/unix/sysv/linux/x86_64/pthread_cond_timedwait.S b/sysdeps/unix/sysv/linux/x86_64/pthread_cond_timedwait.S
  310. --- a/sysdeps/unix/sysv/linux/x86_64/pthread_cond_timedwait.S
  311. +++ b/sysdeps/unix/sysv/linux/x86_64/pthread_cond_timedwait.S
  312. @@ -175,7 +175,7 @@ __pthread_cond_timedwait:
  313. movq %r12, %rdx
  314. addq $cond_futex, %rdi
  315. movl $SYS_futex, %eax
  316. - syscall
  317. + SYSCALLDB
  318. cmpl $0, %eax
  319. sete %r15b
  320. @@ -221,7 +221,7 @@ __pthread_cond_timedwait:
  321. movq %r12, %rdx
  322. addq $cond_futex, %rdi
  323. movl $SYS_futex, %eax
  324. - syscall
  325. + SYSCALLDB
  326. 62: movq %rax, %r14
  327. movl (%rsp), %edi
  328. @@ -308,7 +308,7 @@ __pthread_cond_timedwait:
  329. orl $FUTEX_WAKE, %esi
  330. #endif
  331. movl $SYS_futex, %eax
  332. - syscall
  333. + SYSCALLDB
  334. subq $cond_nwaiters, %rdi
  335. 55: LOCK
  336. @@ -521,7 +521,7 @@ __condvar_cleanup2:
  337. orl $FUTEX_WAKE, %esi
  338. #endif
  339. movl $SYS_futex, %eax
  340. - syscall
  341. + SYSCALLDB
  342. subq $cond_nwaiters, %rdi
  343. movl $1, %r12d
  344. @@ -558,7 +558,7 @@ __condvar_cleanup2:
  345. orl $FUTEX_WAKE, %esi
  346. #endif
  347. movl $SYS_futex, %eax
  348. - syscall
  349. + SYSCALLDB
  350. /* Lock the mutex only if we don't own it already. This only happens
  351. in case of PI mutexes, if we got cancelled after a successful
  352. diff -ruNp a/sysdeps/unix/sysv/linux/x86_64/pthread_cond_wait.S b/sysdeps/unix/sysv/linux/x86_64/pthread_cond_wait.S
  353. --- a/sysdeps/unix/sysv/linux/x86_64/pthread_cond_wait.S
  354. +++ b/sysdeps/unix/sysv/linux/x86_64/pthread_cond_wait.S
  355. @@ -138,7 +138,7 @@ __pthread_cond_wait:
  356. movl $(FUTEX_WAIT_REQUEUE_PI|FUTEX_PRIVATE_FLAG), %esi
  357. movl $SYS_futex, %eax
  358. - syscall
  359. + SYSCALLDB
  360. cmpl $0, %eax
  361. sete %r8b
  362. @@ -180,7 +180,7 @@ __pthread_cond_wait:
  363. #endif
  364. 60: xorb %r8b, %r8b
  365. movl $SYS_futex, %eax
  366. - syscall
  367. + SYSCALLDB
  368. 62: movl (%rsp), %edi
  369. callq __pthread_disable_asynccancel
  370. @@ -239,7 +239,7 @@ __pthread_cond_wait:
  371. orl $FUTEX_WAKE, %esi
  372. #endif
  373. movl $SYS_futex, %eax
  374. - syscall
  375. + SYSCALLDB
  376. subq $cond_nwaiters, %rdi
  377. 17: LOCK
  378. @@ -455,7 +455,7 @@ __condvar_cleanup1:
  379. orl $FUTEX_WAKE, %esi
  380. #endif
  381. movl $SYS_futex, %eax
  382. - syscall
  383. + SYSCALLDB
  384. subq $cond_nwaiters, %rdi
  385. movl $1, %ecx
  386. @@ -493,7 +493,7 @@ __condvar_cleanup1:
  387. orl $FUTEX_WAKE, %esi
  388. #endif
  389. movl $SYS_futex, %eax
  390. - syscall
  391. + SYSCALLDB
  392. /* Lock the mutex only if we don't own it already. This only happens
  393. in case of PI mutexes, if we got cancelled after a successful
  394. diff -ruNp a/sysdeps/unix/sysv/linux/x86_64/setcontext.S b/sysdeps/unix/sysv/linux/x86_64/setcontext.S
  395. --- a/sysdeps/unix/sysv/linux/x86_64/setcontext.S
  396. +++ b/sysdeps/unix/sysv/linux/x86_64/setcontext.S
  397. @@ -43,7 +43,7 @@ ENTRY(__setcontext)
  398. movl $SIG_SETMASK, %edi
  399. movl $_NSIG8,%r10d
  400. movl $__NR_rt_sigprocmask, %eax
  401. - syscall
  402. + SYSCALLDB
  403. popq %rdi /* Reload %rdi, adjust stack. */
  404. cfi_adjust_cfa_offset(-8)
  405. cmpq $-4095, %rax /* Check %rax for error. */
  406. diff -ruNp a/sysdeps/unix/sysv/linux/x86_64/sigaction.c b/sysdeps/unix/sysv/linux/x86_64/sigaction.c
  407. --- a/sysdeps/unix/sysv/linux/x86_64/sigaction.c
  408. +++ b/sysdeps/unix/sysv/linux/x86_64/sigaction.c
  409. @@ -120,7 +120,7 @@ asm \
  410. " .type __" #name ",@function\n" \
  411. "__" #name ":\n" \
  412. " movq $" #syscall ", %rax\n" \
  413. - " syscall\n" \
  414. + SYSCALLDB_ASM \
  415. ".LEND_" #name ":\n" \
  416. ".section .eh_frame,\"a\",@progbits\n" \
  417. ".LSTARTFRAME_" #name ":\n" \
  418. diff -ruNp a/sysdeps/unix/sysv/linux/x86_64/swapcontext.S b/sysdeps/unix/sysv/linux/x86_64/swapcontext.S
  419. --- a/sysdeps/unix/sysv/linux/x86_64/swapcontext.S
  420. +++ b/sysdeps/unix/sysv/linux/x86_64/swapcontext.S
  421. @@ -75,7 +75,7 @@ ENTRY(__swapcontext)
  422. movl $SIG_SETMASK, %edi
  423. movl $_NSIG8,%r10d
  424. movl $__NR_rt_sigprocmask, %eax
  425. - syscall
  426. + SYSCALLDB
  427. cmpq $-4095, %rax /* Check %rax for error. */
  428. jae SYSCALL_ERROR_LABEL /* Jump to error handler if error. */
  429. diff -ruNp a/sysdeps/unix/sysv/linux/x86_64/syscall.S b/sysdeps/unix/sysv/linux/x86_64/syscall.S
  430. --- a/sysdeps/unix/sysv/linux/x86_64/syscall.S
  431. +++ b/sysdeps/unix/sysv/linux/x86_64/syscall.S
  432. @@ -34,7 +34,7 @@ ENTRY (syscall)
  433. movq %r8, %r10
  434. movq %r9, %r8
  435. movq 8(%rsp),%r9 /* arg6 is on the stack. */
  436. - syscall /* Do the system call. */
  437. + SYSCALLDB /* Do the system call. */
  438. cmpq $-4095, %rax /* Check %rax for error. */
  439. jae SYSCALL_ERROR_LABEL /* Jump to error handler if error. */
  440. ret /* Return to caller. */
  441. diff -ruNp a/sysdeps/unix/sysv/linux/x86_64/sysdep.h b/sysdeps/unix/sysv/linux/x86_64/sysdep.h
  442. --- a/sysdeps/unix/sysv/linux/x86_64/sysdep.h
  443. +++ b/sysdeps/unix/sysv/linux/x86_64/sysdep.h
  444. @@ -22,6 +22,7 @@
  445. #include <sysdeps/unix/sysv/linux/sysdep.h>
  446. #include <sysdeps/unix/x86_64/sysdep.h>
  447. #include <tls.h>
  448. +#include "syscalldb.h"
  449. #if IS_IN (rtld)
  450. # include <dl-sysdep.h> /* Defines RTLD_PRIVATE_ERRNO. */
  451. @@ -177,7 +178,7 @@
  452. # define DO_CALL(syscall_name, args) \
  453. DOARGS_##args \
  454. movl $SYS_ify (syscall_name), %eax; \
  455. - syscall;
  456. + SYSCALLDB;
  457. # define DOARGS_0 /* nothing */
  458. # define DOARGS_1 /* nothing */
  459. @@ -191,9 +192,20 @@
  460. /* Define a macro which expands inline into the wrapper code for a system
  461. call. */
  462. # undef INLINE_SYSCALL
  463. -# define INLINE_SYSCALL(name, nr, args...) \
  464. +# define INLINE_SYSCALL(name, nr_args...) \
  465. ({ \
  466. - unsigned long int resultvar = INTERNAL_SYSCALL (name, , nr, args); \
  467. + unsigned long int resultvar = INTERNAL_SYSCALL (name, , ##nr_args); \
  468. + if (__glibc_unlikely (INTERNAL_SYSCALL_ERROR_P (resultvar, ))) \
  469. + { \
  470. + __set_errno (INTERNAL_SYSCALL_ERRNO (resultvar, )); \
  471. + resultvar = (unsigned long int) -1; \
  472. + } \
  473. + (long int) resultvar; })
  474. +
  475. +# undef INLINE_SYSCALL_ASM
  476. +# define INLINE_SYSCALL_ASM(name, nr_args...) \
  477. + ({ \
  478. + unsigned long int resultvar = INTERNAL_SYSCALL_ASM (name, , ##nr_args); \
  479. if (__glibc_unlikely (INTERNAL_SYSCALL_ERROR_P (resultvar, ))) \
  480. { \
  481. __set_errno (INTERNAL_SYSCALL_ERRNO (resultvar, )); \
  482. @@ -205,9 +217,9 @@
  483. into the wrapper code for a system call. It should be used when size
  484. of any argument > size of long int. */
  485. # undef INLINE_SYSCALL_TYPES
  486. -# define INLINE_SYSCALL_TYPES(name, nr, args...) \
  487. +# define INLINE_SYSCALL_TYPES(name, nr_args...) \
  488. ({ \
  489. - unsigned long int resultvar = INTERNAL_SYSCALL_TYPES (name, , nr, args); \
  490. + unsigned long int resultvar = INTERNAL_SYSCALL_TYPES (name, , ##nr_args); \
  491. if (__glibc_unlikely (INTERNAL_SYSCALL_ERROR_P (resultvar, ))) \
  492. { \
  493. __set_errno (INTERNAL_SYSCALL_ERRNO (resultvar, )); \
  494. @@ -227,13 +239,19 @@
  495. LOAD_ARGS_##nr (args) \
  496. LOAD_REGS_##nr \
  497. asm volatile ( \
  498. - "syscall\n\t" \
  499. + SYSCALLDB \
  500. : "=a" (resultvar) \
  501. : "0" (name) ASM_ARGS_##nr : "memory", REGISTERS_CLOBBERED_BY_SYSCALL); \
  502. (long int) resultvar; })
  503. +# define INTERNAL_SYSCALL_NCS_ASM INTERNAL_SYSCALL_NCS
  504. +
  505. # undef INTERNAL_SYSCALL
  506. -# define INTERNAL_SYSCALL(name, err, nr, args...) \
  507. - INTERNAL_SYSCALL_NCS (__NR_##name, err, nr, ##args)
  508. +# define INTERNAL_SYSCALL(name, err, nr_args...) \
  509. + INTERNAL_SYSCALL_NCS (__NR_##name, err, ##nr_args)
  510. +
  511. +# undef INTERNAL_SYSCALL_ASM
  512. +# define INTERNAL_SYSCALL_ASM(name, err, nr_args...) \
  513. + INTERNAL_SYSCALL_NCS_ASM (__NR_##name, err, ##nr_args)
  514. # define INTERNAL_SYSCALL_NCS_TYPES(name, err, nr, args...) \
  515. ({ \
  516. @@ -241,7 +259,7 @@
  517. LOAD_ARGS_TYPES_##nr (args) \
  518. LOAD_REGS_TYPES_##nr (args) \
  519. asm volatile ( \
  520. - "syscall\n\t" \
  521. + SYSCALLDB \
  522. : "=a" (resultvar) \
  523. : "0" (name) ASM_ARGS_##nr : "memory", REGISTERS_CLOBBERED_BY_SYSCALL); \
  524. (long int) resultvar; })
  525. diff -ruNp a/sysdeps/unix/sysv/linux/x86_64/vfork.S b/sysdeps/unix/sysv/linux/x86_64/vfork.S
  526. --- a/sysdeps/unix/sysv/linux/x86_64/vfork.S
  527. +++ b/sysdeps/unix/sysv/linux/x86_64/vfork.S
  528. @@ -46,7 +46,7 @@ ENTRY (__vfork)
  529. /* Stuff the syscall number in RAX and enter into the kernel. */
  530. movl $SYS_ify (vfork), %eax
  531. - syscall
  532. + SYSCALLDB
  533. /* Push back the return PC. */
  534. pushq %rdi
  535. diff -ruNp a/sysdeps/x86_64/dl-machine.h b/sysdeps/x86_64/dl-machine.h
  536. --- a/sysdeps/x86_64/dl-machine.h
  537. +++ b/sysdeps/x86_64/dl-machine.h
  538. @@ -554,7 +554,8 @@ elf_machine_lazy_rel (struct link_map *m
  539. value = ((ElfW(Addr) (*) (void)) value) ();
  540. *reloc_addr = value;
  541. }
  542. - else
  543. + /* for graphene, get around R_X86_64_NONE */
  544. + else if (__builtin_expect (r_type != R_X86_64_NONE, 1))
  545. _dl_reloc_bad_type (map, r_type, 1);
  546. }
  547. diff -ruNp a/sysdeps/x86_64/nptl/tls.h b/sysdeps/x86_64/nptl/tls.h
  548. --- a/sysdeps/x86_64/nptl/tls.h
  549. +++ b/sysdeps/x86_64/nptl/tls.h
  550. @@ -28,6 +28,7 @@
  551. # include <sysdep.h>
  552. # include <libc-internal.h>
  553. # include <kernel-features.h>
  554. +# include <syscalldb.h>
  555. /* Replacement type for __m128 since this file is included by ld.so,
  556. which is compiled with -mno-sse. It must not change the alignment
  557. @@ -138,7 +144,6 @@ typedef struct
  558. # define GET_DTV(descr) \
  559. (((tcbhead_t *) (descr))->dtv)
  560. -
  561. /* Code to initially initialize the thread pointer. This might need
  562. special attention since 'errno' is not yet available and if the
  563. operation can cause a failure 'errno' must not be touched.
  564. @@ -155,7 +160,7 @@ typedef struct
  565. _head->self = _thrdescr; \
  566. \
  567. /* It is a simple syscall to set the %fs value for the thread. */ \
  568. - asm volatile ("syscall" \
  569. + asm volatile (SYSCALLDB \
  570. : "=a" (_result) \
  571. : "0" ((unsigned long int) __NR_arch_prctl), \
  572. "D" ((unsigned long int) ARCH_SET_FS), \