glibc-2.19.patch 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918
  1. diff --git a/Makeconfig b/Makeconfig
  2. index 1908f27..cf34ba1 100644
  3. --- a/Makeconfig
  4. +++ b/Makeconfig
  5. @@ -775,7 +775,8 @@ endif # $(+cflags) == ""
  6. # current directory.
  7. +includes = -I$(..)include $(if $(subdir),$(objpfx:%/=-I%)) \
  8. $(+sysdep-includes) $(includes) \
  9. - $(patsubst %/,-I%,$(..)) $(libio-include) -I. $(sysincludes)
  10. + $(patsubst %/,-I%,$(..)) $(libio-include) -I. $(sysincludes) \
  11. + -I$(common-objpfx)../shim/include
  12. # Since libio has several internal header files, we use a -I instead
  13. # of many little headers in the include directory.
  14. diff --git a/Makefile b/Makefile
  15. index 51d4690..d72c4b0 100644
  16. --- a/Makefile
  17. +++ b/Makefile
  18. @@ -177,6 +177,8 @@ $(inst_includedir)/gnu/stubs.h: $(+force)
  19. install-others-nosubdir: $(installed-stubs)
  20. endif
  21. +# For Graphene
  22. +CFLAGS-syscalldb.c = -fPIC
  23. # Since stubs.h is never needed when building the library, we simplify the
  24. # hairy installation process by producing it in place only as the last part
  25. diff --git a/Versions.def b/Versions.def
  26. index 759c754..e1a270e 100644
  27. --- a/Versions.def
  28. +++ b/Versions.def
  29. @@ -135,6 +138,7 @@ ld {
  30. GLIBC_2.3
  31. GLIBC_2.4
  32. GLIBC_PRIVATE
  33. + SHIM
  34. }
  35. libthread_db {
  36. GLIBC_2.1.3
  37. diff --git a/elf/Makefile b/elf/Makefile
  38. index 4c58fc9..0ae2fa8 100644
  39. --- a/elf/Makefile
  40. +++ b/elf/Makefile
  41. @@ -21,7 +21,7 @@ subdir := elf
  42. include ../Makeconfig
  43. -headers = elf.h bits/elfclass.h link.h bits/link.h
  44. +headers = elf.h bits/elfclass.h link.h bits/link.h syscalldb.h
  45. routines = $(dl-routines) dl-support dl-iteratephdr \
  46. dl-addr enbl-secure dl-profstub \
  47. dl-origin dl-libc dl-sym dl-tsd dl-sysdep
  48. @@ -31,7 +31,8 @@ routines = $(dl-routines) dl-support dl-iteratephdr \
  49. dl-routines = $(addprefix dl-,load lookup object reloc deps hwcaps \
  50. runtime error init fini debug misc \
  51. version profile conflict tls origin scope \
  52. - execstack caller open close trampoline)
  53. + execstack caller open close trampoline) \
  54. + syscalldb syscallas
  55. ifeq (yes,$(use-ldconfig))
  56. dl-routines += dl-cache
  57. endif
  58. diff --git a/elf/Versions b/elf/Versions
  59. index 2383992..98687f6 100644
  60. --- a/elf/Versions
  61. +++ b/elf/Versions
  62. @@ -62,4 +65,7 @@ ld {
  63. # Pointer protection.
  64. __pointer_chk_guard;
  65. }
  66. + SHIM {
  67. + syscalldb; glibc_version; glibc_option; register_library;
  68. + }
  69. }
  70. diff --git a/elf/dl-load.c b/elf/dl-load.c
  71. index 1be7a3c..c560ec1 100644
  72. --- a/elf/dl-load.c
  73. +++ b/elf/dl-load.c
  74. @@ -39,6 +39,8 @@
  75. #include <dl-dst.h>
  76. +#include <glibc-version.h>
  77. +
  78. /* On some systems, no flag bits are given to specify file mapping. */
  79. #ifndef MAP_FILE
  80. # define MAP_FILE 0
  81. @@ -1595,6 +1597,9 @@ cannot enable executable stack as shared object requires");
  82. DL_AFTER_LOAD (l);
  83. #endif
  84. + /* register the library to SHIM */
  85. + register_library(l->l_name, l->l_addr);
  86. +
  87. /* Now that the object is fully initialized add it to the object list. */
  88. _dl_add_to_namespace_list (l, nsid);
  89. diff --git a/elf/rtld.c b/elf/rtld.c
  90. index 6dcbabc..c87c773 100644
  91. --- a/elf/rtld.c
  92. +++ b/elf/rtld.c
  93. @@ -356,6 +356,23 @@ _dl_start_final (void *arg, struct dl_start_final_info *info)
  94. return start_addr;
  95. }
  96. +/* For graphene, check if glibc version match to the compatible SHIM
  97. + library. If not, tell the user to update glibc. */
  98. +#include "glibc-version.h"
  99. +
  100. +const unsigned int glibc_version __attribute__((weak)) = GLIBC_VERSION;
  101. +
  102. +static void __attribute__((noinline,optimize("-O0")))
  103. +check_glibc_version (void)
  104. +{
  105. + if (glibc_version != GLIBC_VERSION)
  106. + {
  107. + _dl_fatal_printf ("Warning from Graphene: "
  108. + "Glibc version is incorrect. Please rebuild Glibc.\n");
  109. + _exit (1);
  110. + }
  111. +}
  112. +
  113. static ElfW(Addr) __attribute_used__ internal_function
  114. _dl_start (void *arg)
  115. {
  116. @@ -546,6 +563,9 @@ _dl_start (void *arg)
  117. therefore need not test whether we have to allocate the array
  118. for the relocation results (as done in dl-reloc.c). */
  119. + /* For Graphene, check if the glibc version is correct. */
  120. + check_glibc_version();
  121. +
  122. /* Now life is sane; we can call functions and access global data.
  123. Set up to use the operating system facilities, and find out from
  124. the operating system's program loader where to find the program
  125. diff --git a/nptl/Versions b/nptl/Versions
  126. index bb11277..354149a 100644
  127. diff --git a/nptl/sysdeps/unix/sysv/linux/x86_64/cancellation.S b/nptl/sysdeps/unix/sysv/linux/x86_64/cancellation.S
  128. index 89fda5e..f6963f6 100644
  129. --- a/nptl/sysdeps/unix/sysv/linux/x86_64/cancellation.S
  130. +++ b/nptl/sysdeps/unix/sysv/linux/x86_64/cancellation.S
  131. @@ -111,7 +111,7 @@ ENTRY(__pthread_disable_asynccancel)
  132. xorq %r10, %r10
  133. addq $CANCELHANDLING, %rdi
  134. LOAD_PRIVATE_FUTEX_WAIT (%esi)
  135. - syscall
  136. + SYSCALLDB
  137. movl %fs:CANCELHANDLING, %eax
  138. jmp 3b
  139. END(__pthread_disable_asynccancel)
  140. diff --git a/nptl/sysdeps/unix/sysv/linux/x86_64/lowlevellock.S b/nptl/sysdeps/unix/sysv/linux/x86_64/lowlevellock.S
  141. index f2dca07..0ce7c67 100644
  142. --- a/nptl/sysdeps/unix/sysv/linux/x86_64/lowlevellock.S
  143. +++ b/nptl/sysdeps/unix/sysv/linux/x86_64/lowlevellock.S
  144. @@ -90,7 +90,7 @@ __lll_lock_wait_private:
  145. 1: LIBC_PROBE (lll_lock_wait_private, 1, %rdi)
  146. movl $SYS_futex, %eax
  147. - syscall
  148. + SYSCALLDB
  149. 2: movl %edx, %eax
  150. xchgl %eax, (%rdi) /* NB: lock is implied */
  151. @@ -130,7 +130,7 @@ __lll_lock_wait:
  152. 1: LIBC_PROBE (lll_lock_wait, 2, %rdi, %rsi)
  153. movl $SYS_futex, %eax
  154. - syscall
  155. + SYSCALLDB
  156. 2: movl %edx, %eax
  157. xchgl %eax, (%rdi) /* NB: lock is implied */
  158. @@ -185,7 +185,7 @@ __lll_timedlock_wait:
  159. 1: movl $SYS_futex, %eax
  160. movl $2, %edx
  161. - syscall
  162. + SYSCALLDB
  163. 2: xchgl %edx, (%rdi) /* NB: lock is implied */
  164. @@ -279,7 +279,7 @@ __lll_timedlock_wait:
  165. LOAD_FUTEX_WAIT (%esi)
  166. movq %r12, %rdi
  167. movl $SYS_futex, %eax
  168. - syscall
  169. + SYSCALLDB
  170. /* NB: %edx == 2 */
  171. xchgl %edx, (%r12)
  172. @@ -336,7 +336,7 @@ __lll_unlock_wake_private:
  173. LOAD_PRIVATE_FUTEX_WAKE (%esi)
  174. movl $1, %edx /* Wake one thread. */
  175. movl $SYS_futex, %eax
  176. - syscall
  177. + SYSCALLDB
  178. popq %rdx
  179. cfi_adjust_cfa_offset(-8)
  180. @@ -366,7 +366,7 @@ __lll_unlock_wake:
  181. LOAD_FUTEX_WAKE (%esi)
  182. movl $1, %edx /* Wake one thread. */
  183. movl $SYS_futex, %eax
  184. - syscall
  185. + SYSCALLDB
  186. popq %rdx
  187. cfi_adjust_cfa_offset(-8)
  188. @@ -435,7 +435,7 @@ __lll_timedwait_tid:
  189. #endif
  190. movq %r12, %rdi
  191. movl $SYS_futex, %eax
  192. - syscall
  193. + SYSCALLDB
  194. cmpl $0, (%rdi)
  195. jne 1f
  196. diff --git a/nptl/sysdeps/unix/sysv/linux/x86_64/lowlevellock.h b/nptl/sysdeps/unix/sysv/linux/x86_64/lowlevellock.h
  197. index 0a26739..8aae14a 100644
  198. --- a/nptl/sysdeps/unix/sysv/linux/x86_64/lowlevellock.h
  199. +++ b/nptl/sysdeps/unix/sysv/linux/x86_64/lowlevellock.h
  200. @@ -214,7 +214,7 @@ LLL_STUB_UNWIND_INFO_END
  201. register const struct timespec *__to __asm ("r10") = timeout; \
  202. int __status; \
  203. register __typeof (val) _val __asm ("edx") = (val); \
  204. - __asm __volatile ("syscall" \
  205. + __asm __volatile (SYSCALLDB \
  206. : "=a" (__status) \
  207. : "0" (SYS_futex), "D" (futex), \
  208. "S" (__lll_private_flag (FUTEX_WAIT, private)), \
  209. @@ -229,7 +229,7 @@ LLL_STUB_UNWIND_INFO_END
  210. int __status; \
  211. register __typeof (nr) _nr __asm ("edx") = (nr); \
  212. LIBC_PROBE (lll_futex_wake, 3, futex, nr, private); \
  213. - __asm __volatile ("syscall" \
  214. + __asm __volatile (SYSCALLDB \
  215. : "=a" (__status) \
  216. : "0" (SYS_futex), "D" (futex), \
  217. "S" (__lll_private_flag (FUTEX_WAKE, private)), \
  218. @@ -540,7 +540,7 @@ extern int __lll_timedlock_elision (int *futex, short *adapt_count,
  219. { \
  220. int ignore; \
  221. __asm __volatile (LOCK_INSTR "orl %3, (%2)\n\t" \
  222. - "syscall" \
  223. + SYSCALLDB \
  224. : "=m" (futex), "=a" (ignore) \
  225. : "D" (&(futex)), "i" (FUTEX_OWNER_DIED), \
  226. "S" (__lll_private_flag (FUTEX_WAKE, private)), \
  227. @@ -555,7 +555,7 @@ extern int __lll_timedlock_elision (int *futex, short *adapt_count,
  228. register int __nr_move __asm ("r10") = nr_move; \
  229. register void *__mutex __asm ("r8") = mutex; \
  230. register int __val __asm ("r9") = val; \
  231. - __asm __volatile ("syscall" \
  232. + __asm __volatile (SYSCALLDB \
  233. : "=a" (__res) \
  234. : "0" (__NR_futex), "D" ((void *) ftx), \
  235. "S" (__lll_private_flag (FUTEX_CMP_REQUEUE, \
  236. @@ -581,7 +581,7 @@ extern int __lll_timedlock_elision (int *futex, short *adapt_count,
  237. if (_tid != 0) \
  238. __asm __volatile ("xorq %%r10, %%r10\n\t" \
  239. "1:\tmovq %2, %%rax\n\t" \
  240. - "syscall\n\t" \
  241. + SYSCALLDB \
  242. "cmpl $0, (%%rdi)\n\t" \
  243. "jne 1b" \
  244. : "=&a" (__ignore) \
  245. diff --git a/nptl/sysdeps/unix/sysv/linux/x86_64/lowlevelrobustlock.S b/nptl/sysdeps/unix/sysv/linux/x86_64/lowlevelrobustlock.S
  246. index 990b6f9..b01214d 100644
  247. --- a/nptl/sysdeps/unix/sysv/linux/x86_64/lowlevelrobustlock.S
  248. +++ b/nptl/sysdeps/unix/sysv/linux/x86_64/lowlevelrobustlock.S
  249. @@ -80,7 +80,7 @@ __lll_robust_lock_wait:
  250. jnz 2f
  251. 1: movl $SYS_futex, %eax
  252. - syscall
  253. + SYSCALLDB
  254. movl (%rdi), %eax
  255. @@ -145,7 +145,7 @@ __lll_robust_timedlock_wait:
  256. jnz 6f
  257. 5: movl $SYS_futex, %eax
  258. - syscall
  259. + SYSCALLDB
  260. movl %eax, %ecx
  261. movl (%rdi), %eax
  262. @@ -257,7 +257,7 @@ __lll_robust_timedlock_wait:
  263. LOAD_FUTEX_WAIT (%esi)
  264. movq %r12, %rdi
  265. movl $SYS_futex, %eax
  266. - syscall
  267. + SYSCALLDB
  268. movq %rax, %rcx
  269. movl (%r12), %eax
  270. diff --git a/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_barrier_wait.S b/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_barrier_wait.S
  271. index eec17f2..a350340 100644
  272. --- a/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_barrier_wait.S
  273. +++ b/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_barrier_wait.S
  274. @@ -62,7 +62,7 @@ pthread_barrier_wait:
  275. #endif
  276. xorq %r10, %r10
  277. 8: movl $SYS_futex, %eax
  278. - syscall
  279. + SYSCALLDB
  280. /* Don't return on spurious wakeups. The syscall does not change
  281. any register except %eax so there is no need to reload any of
  282. @@ -109,7 +109,7 @@ pthread_barrier_wait:
  283. movl $FUTEX_WAKE, %esi
  284. orl PRIVATE(%rdi), %esi
  285. movl $SYS_futex, %eax
  286. - syscall
  287. + SYSCALLDB
  288. /* Increment LEFT. If this brings the count back to the
  289. initial count unlock the object. */
  290. diff --git a/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_cond_broadcast.S b/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_cond_broadcast.S
  291. index 985e0f1..d559456 100644
  292. --- a/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_cond_broadcast.S
  293. +++ b/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_cond_broadcast.S
  294. @@ -90,7 +90,7 @@ __pthread_cond_broadcast:
  295. movl $SYS_futex, %eax
  296. movl $1, %edx
  297. movl $0x7fffffff, %r10d
  298. - syscall
  299. + SYSCALLDB
  300. /* For any kind of error, which mainly is EAGAIN, we try again
  301. with WAKE. The general test also covers running on old
  302. @@ -106,7 +106,7 @@ __pthread_cond_broadcast:
  303. movl $SYS_futex, %eax
  304. movl $1, %edx
  305. movl $0x7fffffff, %r10d
  306. - syscall
  307. + SYSCALLDB
  308. /* For any kind of error, which mainly is EAGAIN, we try again
  309. with WAKE. The general test also covers running on old
  310. @@ -172,7 +172,7 @@ __pthread_cond_broadcast:
  311. orl $FUTEX_WAKE, %esi
  312. #endif
  313. movl $SYS_futex, %eax
  314. - syscall
  315. + SYSCALLDB
  316. jmp 10b
  317. .size __pthread_cond_broadcast, .-__pthread_cond_broadcast
  318. versioned_symbol (libpthread, __pthread_cond_broadcast, pthread_cond_broadcast,
  319. diff --git a/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_cond_signal.S b/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_cond_signal.S
  320. index 53d65b6..16df581 100644
  321. --- a/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_cond_signal.S
  322. +++ b/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_cond_signal.S
  323. @@ -82,7 +82,7 @@ __pthread_cond_signal:
  324. addq $cond_lock, %r8
  325. #endif
  326. movl $FUTEX_OP_CLEAR_WAKE_IF_GT_ONE, %r9d
  327. - syscall
  328. + SYSCALLDB
  329. #if cond_lock != 0
  330. subq $cond_lock, %r8
  331. #endif
  332. @@ -99,7 +99,7 @@ __pthread_cond_signal:
  333. movq %rcx, %r8
  334. xorq %r10, %r10
  335. movl (%rdi), %r9d // XXX Can this be right?
  336. - syscall
  337. + SYSCALLDB
  338. leaq -cond_futex(%rdi), %r8
  339. @@ -118,7 +118,7 @@ __pthread_cond_signal:
  340. movl $SYS_futex, %eax
  341. /* %rdx should be 1 already from $FUTEX_WAKE_OP syscall.
  342. movl $1, %edx */
  343. - syscall
  344. + SYSCALLDB
  345. /* Unlock. */
  346. 4: LOCK
  347. diff --git a/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_cond_timedwait.S b/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_cond_timedwait.S
  348. index 0dc2340..8aff242 100644
  349. --- a/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_cond_timedwait.S
  350. +++ b/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_cond_timedwait.S
  351. @@ -188,7 +188,7 @@ __pthread_cond_timedwait:
  352. movq %r12, %rdx
  353. addq $cond_futex, %rdi
  354. movl $SYS_futex, %eax
  355. - syscall
  356. + SYSCALLDB
  357. cmpl $0, %eax
  358. sete %r15b
  359. @@ -234,7 +234,7 @@ __pthread_cond_timedwait:
  360. movq %r12, %rdx
  361. addq $cond_futex, %rdi
  362. movl $SYS_futex, %eax
  363. - syscall
  364. + SYSCALLDB
  365. 62: movq %rax, %r14
  366. movl (%rsp), %edi
  367. @@ -321,7 +321,7 @@ __pthread_cond_timedwait:
  368. orl $FUTEX_WAKE, %esi
  369. #endif
  370. movl $SYS_futex, %eax
  371. - syscall
  372. + SYSCALLDB
  373. subq $cond_nwaiters, %rdi
  374. 55: LOCK
  375. @@ -492,7 +492,7 @@ __pthread_cond_timedwait:
  376. call *%rax
  377. # else
  378. movl $__NR_clock_gettime, %eax
  379. - syscall
  380. + SYSCALLDB
  381. # endif
  382. /* Compute relative timeout. */
  383. @@ -560,7 +553,7 @@ __pthread_cond_timedwait:
  384. # endif
  385. addq $cond_futex, %rdi
  386. movl $SYS_futex, %eax
  387. - syscall
  388. + SYSCALLDB
  389. movq %rax, %r14
  390. movl (%rsp), %edi
  391. @@ -732,7 +725,7 @@ __condvar_cleanup2:
  392. orl $FUTEX_WAKE, %esi
  393. #endif
  394. movl $SYS_futex, %eax
  395. - syscall
  396. + SYSCALLDB
  397. subq $cond_nwaiters, %rdi
  398. movl $1, %r12d
  399. @@ -769,7 +762,7 @@ __condvar_cleanup2:
  400. orl $FUTEX_WAKE, %esi
  401. #endif
  402. movl $SYS_futex, %eax
  403. - syscall
  404. + SYSCALLDB
  405. /* Lock the mutex only if we don't own it already. This only happens
  406. in case of PI mutexes, if we got cancelled after a successful
  407. diff --git a/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_cond_wait.S b/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_cond_wait.S
  408. index 0e61d0a..b4bcc15 100644
  409. --- a/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_cond_wait.S
  410. +++ b/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_cond_wait.S
  411. @@ -138,7 +138,7 @@ __pthread_cond_wait:
  412. movl $(FUTEX_WAIT_REQUEUE_PI|FUTEX_PRIVATE_FLAG), %esi
  413. movl $SYS_futex, %eax
  414. - syscall
  415. + SYSCALLDB
  416. cmpl $0, %eax
  417. sete %r8b
  418. @@ -180,7 +180,7 @@ __pthread_cond_wait:
  419. #endif
  420. 60: xorb %r8b, %r8b
  421. movl $SYS_futex, %eax
  422. - syscall
  423. + SYSCALLDB
  424. 62: movl (%rsp), %edi
  425. callq __pthread_disable_asynccancel
  426. @@ -239,7 +239,7 @@ __pthread_cond_wait:
  427. orl $FUTEX_WAKE, %esi
  428. #endif
  429. movl $SYS_futex, %eax
  430. - syscall
  431. + SYSCALLDB
  432. subq $cond_nwaiters, %rdi
  433. 17: LOCK
  434. @@ -455,7 +455,7 @@ __condvar_cleanup1:
  435. orl $FUTEX_WAKE, %esi
  436. #endif
  437. movl $SYS_futex, %eax
  438. - syscall
  439. + SYSCALLDB
  440. subq $cond_nwaiters, %rdi
  441. movl $1, %ecx
  442. @@ -493,7 +493,7 @@ __condvar_cleanup1:
  443. orl $FUTEX_WAKE, %esi
  444. #endif
  445. movl $SYS_futex, %eax
  446. - syscall
  447. + SYSCALLDB
  448. /* Lock the mutex only if we don't own it already. This only happens
  449. in case of PI mutexes, if we got cancelled after a successful
  450. diff --git a/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_once.S b/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_once.S
  451. index 2cbe2fa..489998a 100644
  452. --- a/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_once.S
  453. +++ b/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_once.S
  454. @@ -90,7 +90,7 @@ __pthread_once:
  455. # endif
  456. #endif
  457. movl $SYS_futex, %eax
  458. - syscall
  459. + SYSCALLDB
  460. jmp 6b
  461. /* Preserve the pointer to the control variable. */
  462. @@ -123,7 +123,7 @@ __pthread_once:
  463. orl %fs:PRIVATE_FUTEX, %esi
  464. #endif
  465. movl $SYS_futex, %eax
  466. - syscall
  467. + SYSCALLDB
  468. 4: addq $8, %rsp
  469. cfi_adjust_cfa_offset(-8)
  470. @@ -152,7 +152,7 @@ clear_once_control:
  471. orl %fs:PRIVATE_FUTEX, %esi
  472. #endif
  473. movl $SYS_futex, %eax
  474. - syscall
  475. + SYSCALLDB
  476. movq %r8, %rdi
  477. .LcallUR:
  478. diff --git a/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_rdlock.S b/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_rdlock.S
  479. index 3bbb4c7..53d5ca6 100644
  480. --- a/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_rdlock.S
  481. +++ b/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_rdlock.S
  482. @@ -82,7 +82,7 @@ __pthread_rwlock_rdlock:
  483. #endif
  484. addq $READERS_WAKEUP, %rdi
  485. movl $SYS_futex, %eax
  486. - syscall
  487. + SYSCALLDB
  488. subq $READERS_WAKEUP, %rdi
  489. diff --git a/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_timedrdlock.S b/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_timedrdlock.S
  490. index 40bcc04..348170e 100644
  491. --- a/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_timedrdlock.S
  492. +++ b/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_timedrdlock.S
  493. @@ -109,7 +109,7 @@ pthread_rwlock_timedrdlock:
  494. #endif
  495. 21: leaq READERS_WAKEUP(%r12), %rdi
  496. movl $SYS_futex, %eax
  497. - syscall
  498. + SYSCALLDB
  499. movq %rax, %rdx
  500. #ifndef __ASSUME_FUTEX_CLOCK_REALTIME
  501. diff --git a/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_timedwrlock.S b/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_timedwrlock.S
  502. index f57ef52..e9ac77f 100644
  503. --- a/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_timedwrlock.S
  504. +++ b/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_timedwrlock.S
  505. @@ -106,7 +106,7 @@ pthread_rwlock_timedwrlock:
  506. #endif
  507. 21: leaq WRITERS_WAKEUP(%r12), %rdi
  508. movl $SYS_futex, %eax
  509. - syscall
  510. + SYSCALLDB
  511. movq %rax, %rdx
  512. #ifndef __ASSUME_FUTEX_CLOCK_REALTIME
  513. diff --git a/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_unlock.S b/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_unlock.S
  514. index d779f7b..849c74f 100644
  515. --- a/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_unlock.S
  516. +++ b/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_unlock.S
  517. @@ -79,7 +79,7 @@ __pthread_rwlock_unlock:
  518. #endif
  519. movl $SYS_futex, %eax
  520. movq %r10, %rdi
  521. - syscall
  522. + SYSCALLDB
  523. xorl %eax, %eax
  524. retq
  525. diff --git a/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_wrlock.S b/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_wrlock.S
  526. index e444def..fd94930 100644
  527. --- a/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_wrlock.S
  528. +++ b/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_wrlock.S
  529. @@ -80,7 +80,7 @@ __pthread_rwlock_wrlock:
  530. #endif
  531. addq $WRITERS_WAKEUP, %rdi
  532. movl $SYS_futex, %eax
  533. - syscall
  534. + SYSCALLDB
  535. subq $WRITERS_WAKEUP, %rdi
  536. diff --git a/nptl/sysdeps/unix/sysv/linux/x86_64/sem_post.S b/nptl/sysdeps/unix/sysv/linux/x86_64/sem_post.S
  537. index 1c11600..bd166cf 100644
  538. --- a/nptl/sysdeps/unix/sysv/linux/x86_64/sem_post.S
  539. +++ b/nptl/sysdeps/unix/sysv/linux/x86_64/sem_post.S
  540. @@ -52,7 +52,7 @@ sem_post:
  541. movl $FUTEX_WAKE, %esi
  542. orl PRIVATE(%rdi), %esi
  543. movl $1, %edx
  544. - syscall
  545. + SYSCALLDB
  546. testq %rax, %rax
  547. js 1f
  548. diff --git a/nptl/sysdeps/unix/sysv/linux/x86_64/sem_timedwait.S b/nptl/sysdeps/unix/sysv/linux/x86_64/sem_timedwait.S
  549. index 880610e..e520049 100644
  550. --- a/nptl/sysdeps/unix/sysv/linux/x86_64/sem_timedwait.S
  551. +++ b/nptl/sysdeps/unix/sysv/linux/x86_64/sem_timedwait.S
  552. @@ -97,7 +97,7 @@ sem_timedwait:
  553. orl PRIVATE(%rdi), %esi
  554. movl $SYS_futex, %eax
  555. xorl %edx, %edx
  556. - syscall
  557. + SYSCALLDB
  558. movq %rax, %r9
  559. #if VALUE != 0
  560. leaq -VALUE(%rdi), %rdi
  561. @@ -233,7 +233,7 @@ sem_timedwait:
  562. # endif
  563. movl $SYS_futex, %eax
  564. xorl %edx, %edx
  565. - syscall
  566. + SYSCALLDB
  567. movq %rax, %r14
  568. movl 16(%rsp), %edi
  569. diff --git a/nptl/sysdeps/unix/sysv/linux/x86_64/sem_wait.S b/nptl/sysdeps/unix/sysv/linux/x86_64/sem_wait.S
  570. index 8f4d068..fe6dfbf 100644
  571. --- a/nptl/sysdeps/unix/sysv/linux/x86_64/sem_wait.S
  572. +++ b/nptl/sysdeps/unix/sysv/linux/x86_64/sem_wait.S
  573. @@ -81,7 +81,7 @@ sem_wait:
  574. orl PRIVATE(%rdi), %esi
  575. #endif
  576. xorl %edx, %edx
  577. - syscall
  578. + SYSCALLDB
  579. movq %rax, %rcx
  580. xchgq %r8, %rdi
  581. diff --git a/nptl/sysdeps/x86_64/pthreaddef.h b/nptl/sysdeps/x86_64/pthreaddef.h
  582. index 18a15a1..f050241 100644
  583. --- a/nptl/sysdeps/x86_64/pthreaddef.h
  584. +++ b/nptl/sysdeps/x86_64/pthreaddef.h
  585. @@ -48,4 +48,4 @@
  586. /* While there is no such syscall. */
  587. #define __exit_thread_inline(val) \
  588. - asm volatile ("syscall" :: "a" (__NR_exit), "D" (val))
  589. + asm volatile (SYSCALLDB :: "a" (__NR_exit), "D" (val))
  590. diff --git a/nptl/sysdeps/x86_64/tls.h b/nptl/sysdeps/x86_64/tls.h
  591. index cbb5e9e..9b87e25 100644
  592. --- a/nptl/sysdeps/x86_64/tls.h
  593. +++ b/nptl/sysdeps/x86_64/tls.h
  594. @@ -28,6 +28,7 @@
  595. # include <sysdep.h>
  596. # include <libc-internal.h>
  597. # include <kernel-features.h>
  598. +# include <syscalldb.h>
  599. /* Replacement type for __m128 since this file is included by ld.so,
  600. which is compiled with -mno-sse. It must not change the alignment
  601. @@ -154,7 +159,7 @@ typedef struct
  602. _head->self = _thrdescr; \
  603. \
  604. /* It is a simple syscall to set the %fs value for the thread. */ \
  605. - asm volatile ("syscall" \
  606. + asm volatile (SYSCALLDB \
  607. : "=a" (_result) \
  608. : "0" ((unsigned long int) __NR_arch_prctl), \
  609. "D" ((unsigned long int) ARCH_SET_FS), \
  610. diff --git a/sysdeps/unix/sysv/linux/_exit.c b/sysdeps/unix/sysv/linux/_exit.c
  611. index 2468228..a9f1cd6 100644
  612. --- a/sysdeps/unix/sysv/linux/_exit.c
  613. +++ b/sysdeps/unix/sysv/linux/_exit.c
  614. @@ -29,9 +29,9 @@ _exit (status)
  615. while (1)
  616. {
  617. #ifdef __NR_exit_group
  618. - INLINE_SYSCALL (exit_group, 1, status);
  619. + INLINE_SYSCALL_ASM (exit_group, 1, status);
  620. #endif
  621. - INLINE_SYSCALL (exit, 1, status);
  622. + INLINE_SYSCALL_ASM (exit, 1, status);
  623. #ifdef ABORT_INSTRUCTION
  624. ABORT_INSTRUCTION;
  625. diff --git a/sysdeps/unix/sysv/linux/x86_64/____longjmp_chk.S b/sysdeps/unix/sysv/linux/x86_64/____longjmp_chk.S
  626. index 49f0384..6b1a975 100644
  627. --- a/sysdeps/unix/sysv/linux/x86_64/____longjmp_chk.S
  628. +++ b/sysdeps/unix/sysv/linux/x86_64/____longjmp_chk.S
  629. @@ -84,7 +84,8 @@ ENTRY(____longjmp_chk)
  630. xorl %edi, %edi
  631. lea -sizeSS(%rsp), %RSI_LP
  632. movl $__NR_sigaltstack, %eax
  633. - syscall
  634. + SYSCALLDB
  635. +
  636. /* Without working sigaltstack we cannot perform the test. */
  637. testl %eax, %eax
  638. jne .Lok2
  639. diff --git a/sysdeps/unix/sysv/linux/x86_64/clone.S b/sysdeps/unix/sysv/linux/x86_64/clone.S
  640. index 0508730..e1b35ec 100644
  641. --- a/sysdeps/unix/sysv/linux/x86_64/clone.S
  642. +++ b/sysdeps/unix/sysv/linux/x86_64/clone.S
  643. @@ -76,5 +80,5 @@ ENTRY (__clone)
  644. /* End FDE now, because in the child the unwind info will be
  645. wrong. */
  646. cfi_endproc;
  647. - syscall
  648. + SYSCALLDB
  649. @@ -99,10 +104,10 @@ L(thread_start):
  650. movl $-1, %eax
  651. jne 2f
  652. movl $SYS_ify(getpid), %eax
  653. - syscall
  654. + SYSCALLDB
  655. 2: movl %eax, %fs:PID
  656. movl %eax, %fs:TID
  657. 1:
  658. #endif
  659. /* Set up arguments for the function call. */
  660. diff --git a/sysdeps/unix/sysv/linux/x86_64/getcontext.S b/sysdeps/unix/sysv/linux/x86_64/getcontext.S
  661. index 140db03..6967f10 100644
  662. --- a/sysdeps/unix/sysv/linux/x86_64/getcontext.S
  663. +++ b/sysdeps/unix/sysv/linux/x86_64/getcontext.S
  664. @@ -75,7 +75,7 @@ ENTRY(__getcontext)
  665. #endif
  666. movl $_NSIG8,%r10d
  667. movl $__NR_rt_sigprocmask, %eax
  668. - syscall
  669. + SYSCALLDB
  670. cmpq $-4095, %rax /* Check %rax for error. */
  671. jae SYSCALL_ERROR_LABEL /* Jump to error handler if error. */
  672. diff --git a/sysdeps/unix/sysv/linux/x86_64/sched_getcpu.S b/sysdeps/unix/sysv/linux/x86_64/sched_getcpu.S
  673. index 0fd47f2..7a82975 100644
  674. --- a/sysdeps/unix/sysv/linux/x86_64/sched_getcpu.S
  675. +++ b/sysdeps/unix/sysv/linux/x86_64/sched_getcpu.S
  676. @@ -44,7 +45,7 @@
  677. #else
  678. # ifdef __NR_getcpu
  679. movl $__NR_getcpu, %eax
  680. - syscall
  681. + SYSCALLDB
  682. # ifndef __ASSUME_GETCPU_SYSCALL
  683. cmpq $-ENOSYS, %rax
  684. jne 1f
  685. diff --git a/sysdeps/unix/sysv/linux/x86_64/setcontext.S b/sysdeps/unix/sysv/linux/x86_64/setcontext.S
  686. index b726fa0..bb3ae34 100644
  687. --- a/sysdeps/unix/sysv/linux/x86_64/setcontext.S
  688. +++ b/sysdeps/unix/sysv/linux/x86_64/setcontext.S
  689. @@ -43,7 +43,7 @@ ENTRY(__setcontext)
  690. movl $SIG_SETMASK, %edi
  691. movl $_NSIG8,%r10d
  692. movl $__NR_rt_sigprocmask, %eax
  693. - syscall
  694. + SYSCALLDB
  695. popq %rdi /* Reload %rdi, adjust stack. */
  696. cfi_adjust_cfa_offset(-8)
  697. cmpq $-4095, %rax /* Check %rax for error. */
  698. diff --git a/sysdeps/unix/sysv/linux/x86_64/sigaction.c b/sysdeps/unix/sysv/linux/x86_64/sigaction.c
  699. index ab23985..38a6b69 100644
  700. --- a/sysdeps/unix/sysv/linux/x86_64/sigaction.c
  701. +++ b/sysdeps/unix/sysv/linux/x86_64/sigaction.c
  702. @@ -129,7 +129,7 @@ asm \
  703. " .type __" #name ",@function\n" \
  704. "__" #name ":\n" \
  705. " movq $" #syscall ", %rax\n" \
  706. - " syscall\n" \
  707. + SYSCALLDB_ASM \
  708. ".LEND_" #name ":\n" \
  709. ".section .eh_frame,\"a\",@progbits\n" \
  710. ".LSTARTFRAME_" #name ":\n" \
  711. diff --git a/sysdeps/unix/sysv/linux/x86_64/swapcontext.S b/sysdeps/unix/sysv/linux/x86_64/swapcontext.S
  712. index b3854fa..6369bfe 100644
  713. --- a/sysdeps/unix/sysv/linux/x86_64/swapcontext.S
  714. +++ b/sysdeps/unix/sysv/linux/x86_64/swapcontext.S
  715. @@ -75,7 +75,7 @@ ENTRY(__swapcontext)
  716. movl $SIG_SETMASK, %edi
  717. movl $_NSIG8,%r10d
  718. movl $__NR_rt_sigprocmask, %eax
  719. - syscall
  720. + SYSCALLDB
  721. cmpq $-4095, %rax /* Check %rax for error. */
  722. jae SYSCALL_ERROR_LABEL /* Jump to error handler if error. */
  723. diff --git a/sysdeps/unix/sysv/linux/x86_64/syscall.S b/sysdeps/unix/sysv/linux/x86_64/syscall.S
  724. index 92c2f5b..e32ebb2 100644
  725. --- a/sysdeps/unix/sysv/linux/x86_64/syscall.S
  726. +++ b/sysdeps/unix/sysv/linux/x86_64/syscall.S
  727. @@ -34,7 +34,7 @@
  728. movq %r8, %r10
  729. movq %r9, %r8
  730. movq 8(%rsp),%r9 /* arg6 is on the stack. */
  731. - syscall /* Do the system call. */
  732. + SYSCALLDB /* Do the system call. */
  733. cmpq $-4095, %rax /* Check %rax for error. */
  734. jae SYSCALL_ERROR_LABEL /* Jump to error handler if error. */
  735. ret /* Return to caller. */
  736. diff --git a/sysdeps/unix/sysv/linux/x86_64/sysdep.h b/sysdeps/unix/sysv/linux/x86_64/sysdep.h
  737. index 4a9a9d9..dc452ed 100644
  738. --- a/sysdeps/unix/sysv/linux/x86_64/sysdep.h
  739. +++ b/sysdeps/unix/sysv/linux/x86_64/sysdep.h
  740. @@ -21,6 +21,7 @@
  741. /* There is some commonality. */
  742. #include <sysdeps/unix/x86_64/sysdep.h>
  743. #include <tls.h>
  744. +#include "syscalldb.h"
  745. #ifdef IS_IN_rtld
  746. # include <dl-sysdep.h> /* Defines RTLD_PRIVATE_ERRNO. */
  747. @@ -176,7 +177,7 @@
  748. # define DO_CALL(syscall_name, args) \
  749. DOARGS_##args \
  750. movl $SYS_ify (syscall_name), %eax; \
  751. - syscall;
  752. + SYSCALLDB;
  753. # define DOARGS_0 /* nothing */
  754. # define DOARGS_1 /* nothing */
  755. @@ -190,9 +191,20 @@
  756. /* Define a macro which expands inline into the wrapper code for a system
  757. call. */
  758. # undef INLINE_SYSCALL
  759. -# define INLINE_SYSCALL(name, nr, args...) \
  760. +# define INLINE_SYSCALL(name, nr_args...) \
  761. ({ \
  762. - unsigned long int resultvar = INTERNAL_SYSCALL (name, , nr, args); \
  763. + unsigned long int resultvar = INTERNAL_SYSCALL (name, , ##nr_args); \
  764. + if (__builtin_expect (INTERNAL_SYSCALL_ERROR_P (resultvar, ), 0)) \
  765. + { \
  766. + __set_errno (INTERNAL_SYSCALL_ERRNO (resultvar, )); \
  767. + resultvar = (unsigned long int) -1; \
  768. + } \
  769. + (long int) resultvar; })
  770. +
  771. +# undef INLINE_SYSCALL_ASM
  772. +# define INLINE_SYSCALL_ASM(name, nr_args...) \
  773. + ({ \
  774. + unsigned long int resultvar = INTERNAL_SYSCALL_ASM (name, , ##nr_args); \
  775. if (__builtin_expect (INTERNAL_SYSCALL_ERROR_P (resultvar, ), 0)) \
  776. { \
  777. __set_errno (INTERNAL_SYSCALL_ERRNO (resultvar, )); \
  778. @@ -204,9 +216,9 @@
  779. into the wrapper code for a system call. It should be used when size
  780. of any argument > size of long int. */
  781. # undef INLINE_SYSCALL_TYPES
  782. -# define INLINE_SYSCALL_TYPES(name, nr, args...) \
  783. +# define INLINE_SYSCALL_TYPES(name, nr_args...) \
  784. ({ \
  785. - unsigned long int resultvar = INTERNAL_SYSCALL_TYPES (name, , nr, args); \
  786. + unsigned long int resultvar = INTERNAL_SYSCALL_TYPES (name, , ##nr_args); \
  787. if (__builtin_expect (INTERNAL_SYSCALL_ERROR_P (resultvar, ), 0)) \
  788. { \
  789. __set_errno (INTERNAL_SYSCALL_ERRNO (resultvar, )); \
  790. @@ -223,13 +235,19 @@
  791. LOAD_ARGS_##nr (args) \
  792. LOAD_REGS_##nr \
  793. asm volatile ( \
  794. - "syscall\n\t" \
  795. + SYSCALLDB \
  796. : "=a" (resultvar) \
  797. : "0" (name) ASM_ARGS_##nr : "memory", "cc", "r11", "cx"); \
  798. (long int) resultvar; })
  799. +# define INTERNAL_SYSCALL_NCS_ASM INTERNAL_SYSCALL_NCS
  800. +
  801. # undef INTERNAL_SYSCALL
  802. -# define INTERNAL_SYSCALL(name, err, nr, args...) \
  803. - INTERNAL_SYSCALL_NCS (__NR_##name, err, nr, ##args)
  804. +# define INTERNAL_SYSCALL(name, err, nr_args...) \
  805. + INTERNAL_SYSCALL_NCS (__NR_##name, err, ##nr_args)
  806. +
  807. +# undef INTERNAL_SYSCALL_ASM
  808. +# define INTERNAL_SYSCALL_ASM(name, err, nr_args...) \
  809. + INTERNAL_SYSCALL_NCS_ASM (__NR_##name, err, ##nr_args)
  810. # define INTERNAL_SYSCALL_NCS_TYPES(name, err, nr, args...) \
  811. ({ \
  812. @@ -237,7 +255,7 @@
  813. LOAD_ARGS_TYPES_##nr (args) \
  814. LOAD_REGS_TYPES_##nr (args) \
  815. asm volatile ( \
  816. - "syscall\n\t" \
  817. + SYSCALLDB \
  818. : "=a" (resultvar) \
  819. : "0" (name) ASM_ARGS_##nr : "memory", "cc", "r11", "cx"); \
  820. (long int) resultvar; })
  821. diff --git a/sysdeps/unix/sysv/linux/x86_64/vfork.S b/sysdeps/unix/sysv/linux/x86_64/vfork.S
  822. index d3b450a..75a63e1 100644
  823. --- a/sysdeps/unix/sysv/linux/x86_64/vfork.S
  824. +++ b/sysdeps/unix/sysv/linux/x86_64/vfork.S
  825. @@ -38,7 +38,7 @@ ENTRY (__vfork)
  826. /* Stuff the syscall number in RAX and enter into the kernel. */
  827. movl $SYS_ify (vfork), %eax
  828. - syscall
  829. + SYSCALLDB
  830. /* Push back the return PC. */
  831. pushq %rdi
  832. diff --git a/sysdeps/x86_64/dl-machine.h b/sysdeps/x86_64/dl-machine.h
  833. index 504c95f..dcfc259 100644
  834. --- a/sysdeps/x86_64/dl-machine.h
  835. +++ b/sysdeps/x86_64/dl-machine.h
  836. @@ -529,7 +529,8 @@ elf_machine_lazy_rel (struct link_map *map,
  837. value = ((ElfW(Addr) (*) (void)) value) ();
  838. *reloc_addr = value;
  839. }
  840. - else
  841. + /* for graphene, get around R_X86_64_NONE */
  842. + else if (__builtin_expect (r_type != R_X86_64_NONE, 1))
  843. _dl_reloc_bad_type (map, r_type, 1);
  844. }