glibc-2.17.patch 55 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675
  1. diff --git a/LibOS/glibc-2.17/Makeconfig b/LibOS/glibc-2.17/Makeconfig
  2. index 70a3d9d..2c543c3 100644
  3. --- a/LibOS/glibc-2.17/Makeconfig
  4. +++ b/LibOS/glibc-2.17/Makeconfig
  5. @@ -718,7 +718,8 @@ endif # $(+cflags) == ""
  6. +sysdep-includes = $(addprefix -I,$(+sysdep_dirs))
  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. @@ -987,7 +988,7 @@ all-subdirs = csu assert ctype locale intl catgets math setjmp signal \
  15. stdlib stdio-common libio malloc string wcsmbs time dirent \
  16. grp pwd posix io termios resource misc socket sysvipc gmon \
  17. gnulib iconv iconvdata wctype manual shadow gshadow po argp \
  18. - crypt nss localedata timezone rt conform debug \
  19. + crypt nss localedata timezone rt conform debug libos \
  20. $(add-on-subdirs) dlfcn elf
  21. ifndef avoid-generated
  22. diff --git a/LibOS/glibc-2.17/Makefile b/LibOS/glibc-2.17/Makefile
  23. index 6c1e392..3df0ac6 100644
  24. --- a/LibOS/glibc-2.17/Makefile
  25. +++ b/LibOS/glibc-2.17/Makefile
  26. @@ -197,6 +197,8 @@ $(inst_includedir)/gnu/stubs.h: $(+force)
  27. install-others-nosubdir: $(installed-stubs)
  28. endif
  29. +# For Graphene
  30. +CFLAGS-syscalldb.c = -fPIC
  31. # Since stubs.h is never needed when building the library, we simplify the
  32. # hairy installation process by producing it in place only as the last part
  33. diff --git a/LibOS/glibc-2.17/Versions.def b/LibOS/glibc-2.17/Versions.def
  34. index 3c9e0ae..034ab2b 100644
  35. --- a/LibOS/glibc-2.17/Versions.def
  36. +++ b/LibOS/glibc-2.17/Versions.def
  37. @@ -39,6 +39,7 @@ libc {
  38. GCC_3.0
  39. %endif
  40. GLIBC_PRIVATE
  41. + SHIM
  42. }
  43. libcrypt {
  44. GLIBC_2.0
  45. @@ -48,6 +49,7 @@ libdl {
  46. GLIBC_2.1
  47. GLIBC_2.3.3
  48. GLIBC_2.3.4
  49. + SHIM
  50. }
  51. libm {
  52. GLIBC_2.0
  53. @@ -100,6 +102,7 @@ libpthread {
  54. GLIBC_2.11
  55. GLIBC_2.12
  56. GLIBC_PRIVATE
  57. + SHIM
  58. }
  59. libresolv {
  60. GLIBC_2.0
  61. @@ -127,6 +130,7 @@ ld {
  62. GLIBC_2.3
  63. GLIBC_2.4
  64. GLIBC_PRIVATE
  65. + SHIM
  66. }
  67. libthread_db {
  68. GLIBC_2.1.3
  69. @@ -140,3 +144,6 @@ libanl {
  70. libcidn {
  71. GLIBC_PRIVATE
  72. }
  73. +liblibos {
  74. + GLIBC_2.12
  75. +}
  76. diff --git a/LibOS/glibc-2.17/dlfcn/Versions b/LibOS/glibc-2.17/dlfcn/Versions
  77. index 97902f0..c1874c1 100644
  78. --- a/LibOS/glibc-2.17/dlfcn/Versions
  79. +++ b/LibOS/glibc-2.17/dlfcn/Versions
  80. @@ -14,4 +14,7 @@ libdl {
  81. GLIBC_PRIVATE {
  82. _dlfcn_hook;
  83. }
  84. + SHIM {
  85. + syscalldb;
  86. + }
  87. }
  88. diff --git a/LibOS/glibc-2.17/elf/Makefile b/LibOS/glibc-2.17/elf/Makefile
  89. index 6c7bc97..b51a799 100644
  90. --- a/LibOS/glibc-2.17/elf/Makefile
  91. +++ b/LibOS/glibc-2.17/elf/Makefile
  92. @@ -21,7 +21,7 @@ subdir := elf
  93. include ../Makeconfig
  94. -headers = elf.h bits/elfclass.h link.h bits/link.h
  95. +headers = elf.h bits/elfclass.h link.h bits/link.h syscalldb.h
  96. routines = $(dl-routines) dl-support dl-iteratephdr \
  97. dl-addr enbl-secure dl-profstub \
  98. dl-origin dl-libc dl-sym dl-tsd dl-sysdep
  99. @@ -31,7 +31,8 @@ routines = $(dl-routines) dl-support dl-iteratephdr \
  100. dl-routines = $(addprefix dl-,load lookup object reloc deps hwcaps \
  101. runtime error init fini debug misc \
  102. version profile conflict tls origin scope \
  103. - execstack caller open close trampoline)
  104. + execstack caller open close trampoline) \
  105. + syscalldb syscallas
  106. ifeq (yes,$(use-ldconfig))
  107. dl-routines += dl-cache
  108. endif
  109. diff --git a/LibOS/glibc-2.17/elf/Versions b/LibOS/glibc-2.17/elf/Versions
  110. index 87e27c5..a0e345b 100644
  111. --- a/LibOS/glibc-2.17/elf/Versions
  112. +++ b/LibOS/glibc-2.17/elf/Versions
  113. @@ -24,14 +24,15 @@ libc {
  114. _dl_open_hook;
  115. __libc_dlopen_mode; __libc_dlsym; __libc_dlclose;
  116. }
  117. + SHIM {
  118. + syscalldb;
  119. + }
  120. }
  121. ld {
  122. GLIBC_2.0 {
  123. # Function from libc.so which must be shared with libc.
  124. calloc; free; malloc; realloc; __libc_memalign;
  125. -
  126. - _r_debug;
  127. }
  128. GLIBC_2.1 {
  129. # functions used in other libraries
  130. @@ -59,8 +60,11 @@ ld {
  131. _dl_tls_setup; _dl_rtld_di_serinfo;
  132. _dl_make_stack_executable;
  133. # Only here for gdb while a better method is developed.
  134. - _dl_debug_state;
  135. + __libc_r_debug; __libc_dl_debug_state;
  136. # Pointer protection.
  137. __pointer_chk_guard;
  138. }
  139. + SHIM {
  140. + syscalldb; glibc_vers_2_17; register_library;
  141. + }
  142. }
  143. diff --git a/LibOS/glibc-2.17/elf/circleload1.c b/LibOS/glibc-2.17/elf/circleload1.c
  144. index 990ff84..ccf92d3 100644
  145. --- a/LibOS/glibc-2.17/elf/circleload1.c
  146. +++ b/LibOS/glibc-2.17/elf/circleload1.c
  147. @@ -5,7 +5,7 @@
  148. #include <stdlib.h>
  149. #include <string.h>
  150. -#define MAPS ((struct link_map *) _r_debug.r_map)
  151. +#define MAPS ((struct link_map *) __libc_r_debug.r_map)
  152. static int
  153. check_loaded_objects (const char **loaded)
  154. diff --git a/LibOS/glibc-2.17/elf/dl-close.c b/LibOS/glibc-2.17/elf/dl-close.c
  155. index cda0e71..580e1e2 100644
  156. --- a/LibOS/glibc-2.17/elf/dl-close.c
  157. +++ b/LibOS/glibc-2.17/elf/dl-close.c
  158. @@ -468,7 +468,7 @@ _dl_close_worker (struct link_map *map)
  159. /* Notify the debugger we are about to remove some loaded objects. */
  160. struct r_debug *r = _dl_debug_initialize (0, nsid);
  161. r->r_state = RT_DELETE;
  162. - _dl_debug_state ();
  163. + __libc_dl_debug_state ();
  164. LIBC_PROBE (unmap_start, 2, nsid, r);
  165. if (unload_global)
  166. @@ -742,7 +742,7 @@ _dl_close_worker (struct link_map *map)
  167. /* Notify the debugger those objects are finalized and gone. */
  168. r->r_state = RT_CONSISTENT;
  169. - _dl_debug_state ();
  170. + __libc_dl_debug_state ();
  171. LIBC_PROBE (unmap_complete, 2, nsid, r);
  172. /* Recheck if we need to retry, release the lock. */
  173. diff --git a/LibOS/glibc-2.17/elf/dl-debug.c b/LibOS/glibc-2.17/elf/dl-debug.c
  174. index 4106e42..b95bd27 100644
  175. --- a/LibOS/glibc-2.17/elf/dl-debug.c
  176. +++ b/LibOS/glibc-2.17/elf/dl-debug.c
  177. @@ -35,7 +35,7 @@ extern const int verify_link_map_members[(VERIFY_MEMBER (l_addr)
  178. normally finds it via the DT_DEBUG entry in the dynamic section, but in
  179. a statically-linked program there is no dynamic section for the debugger
  180. to examine and it looks for this particular symbol name. */
  181. -struct r_debug _r_debug;
  182. +struct r_debug __libc_r_debug __attribute__((weak));
  183. /* Initialize _r_debug if it has not already been done. The argument is
  184. @@ -49,7 +49,7 @@ _dl_debug_initialize (ElfW(Addr) ldbase, Lmid_t ns)
  185. struct r_debug *r;
  186. if (ns == LM_ID_BASE)
  187. - r = &_r_debug;
  188. + r = &__libc_r_debug;
  189. else
  190. r = &GL(dl_ns)[ns]._ns_debug;
  191. @@ -57,9 +57,9 @@ _dl_debug_initialize (ElfW(Addr) ldbase, Lmid_t ns)
  192. {
  193. /* Tell the debugger where to find the map of loaded objects. */
  194. r->r_version = 1 /* R_DEBUG_VERSION XXX */;
  195. - r->r_ldbase = ldbase ?: _r_debug.r_ldbase;
  196. + r->r_ldbase = ldbase ?: __libc_r_debug.r_ldbase;
  197. r->r_map = (void *) GL(dl_ns)[ns]._ns_loaded;
  198. - r->r_brk = (ElfW(Addr)) &_dl_debug_state;
  199. + r->r_brk = (ElfW(Addr)) &__libc_dl_debug_state;
  200. }
  201. return r;
  202. @@ -71,7 +71,7 @@ _dl_debug_initialize (ElfW(Addr) ldbase, Lmid_t ns)
  203. examining the r_brk member of struct r_debug, but GDB 4.15 in fact looks
  204. for this particular symbol name in the PT_INTERP file. */
  205. void
  206. -_dl_debug_state (void)
  207. +__libc_dl_debug_state (void)
  208. {
  209. }
  210. -rtld_hidden_def (_dl_debug_state)
  211. +__attribute__((weak));
  212. diff --git a/LibOS/glibc-2.17/elf/dl-load.c b/LibOS/glibc-2.17/elf/dl-load.c
  213. index 70fe78f..4ec655a 100644
  214. --- a/LibOS/glibc-2.17/elf/dl-load.c
  215. +++ b/LibOS/glibc-2.17/elf/dl-load.c
  216. @@ -39,6 +39,8 @@
  217. #include <dl-dst.h>
  218. +#include <glibc-version.h>
  219. +
  220. /* On some systems, no flag bits are given to specify file mapping. */
  221. #ifndef MAP_FILE
  222. # define MAP_FILE 0
  223. @@ -896,7 +898,7 @@ lose (int code, int fd, const char *name, char *realname, struct link_map *l,
  224. if (r != NULL)
  225. {
  226. r->r_state = RT_CONSISTENT;
  227. - _dl_debug_state ();
  228. + __libc_dl_debug_state ();
  229. LIBC_PROBE (map_failed, 2, nsid, r);
  230. }
  231. @@ -1042,7 +1044,7 @@ _dl_map_object_from_fd (const char *name, int fd, struct filebuf *fbp,
  232. call _dl_debug_initialize in a static program in case dynamic
  233. linking has not been used before. */
  234. r->r_state = RT_ADD;
  235. - _dl_debug_state ();
  236. + __libc_dl_debug_state ();
  237. LIBC_PROBE (map_start, 2, nsid, r);
  238. make_consistent = true;
  239. }
  240. @@ -1585,6 +1587,9 @@ cannot enable executable stack as shared object requires");
  241. DL_AFTER_LOAD (l);
  242. #endif
  243. + /* register the library to SHIM */
  244. + register_library(l->l_name, l->l_addr);
  245. +
  246. /* Now that the object is fully initialized add it to the object list. */
  247. _dl_add_to_namespace_list (l, nsid);
  248. diff --git a/LibOS/glibc-2.17/elf/dl-open.c b/LibOS/glibc-2.17/elf/dl-open.c
  249. index 9c39a34..a21f51e 100644
  250. --- a/LibOS/glibc-2.17/elf/dl-open.c
  251. +++ b/LibOS/glibc-2.17/elf/dl-open.c
  252. @@ -294,7 +294,7 @@ dl_open_worker (void *a)
  253. /* Notify the debugger all new objects are now ready to go. */
  254. struct r_debug *r = _dl_debug_initialize (0, args->nsid);
  255. r->r_state = RT_CONSISTENT;
  256. - _dl_debug_state ();
  257. + __libc_dl_debug_state ();
  258. LIBC_PROBE (map_complete, 3, args->nsid, r, new);
  259. /* Print scope information. */
  260. diff --git a/LibOS/glibc-2.17/elf/link.h b/LibOS/glibc-2.17/elf/link.h
  261. index 11136cc..db5c4e3 100644
  262. --- a/LibOS/glibc-2.17/elf/link.h
  263. +++ b/LibOS/glibc-2.17/elf/link.h
  264. @@ -64,7 +64,7 @@ struct r_debug
  265. };
  266. /* This is the instance of that structure used by the dynamic linker. */
  267. -extern struct r_debug _r_debug;
  268. +extern struct r_debug __libc_r_debug;
  269. /* This symbol refers to the "dynamic structure" in the `.dynamic' section
  270. of whatever module refers to `_DYNAMIC'. So, to find its own
  271. diff --git a/LibOS/glibc-2.17/elf/loadtest.c b/LibOS/glibc-2.17/elf/loadtest.c
  272. index 727469b..568ddef 100644
  273. --- a/LibOS/glibc-2.17/elf/loadtest.c
  274. +++ b/LibOS/glibc-2.17/elf/loadtest.c
  275. @@ -70,7 +70,7 @@ static const struct
  276. #include <include/link.h>
  277. -#define MAPS ((struct link_map *) _r_debug.r_map)
  278. +#define MAPS ((struct link_map *) __libc_r_debug.r_map)
  279. #define OUT \
  280. for (map = MAPS; map != NULL; map = map->l_next) \
  281. diff --git a/LibOS/glibc-2.17/elf/neededtest.c b/LibOS/glibc-2.17/elf/neededtest.c
  282. index 3cea499..e098d48 100644
  283. --- a/LibOS/glibc-2.17/elf/neededtest.c
  284. +++ b/LibOS/glibc-2.17/elf/neededtest.c
  285. @@ -5,7 +5,7 @@
  286. #include <stdlib.h>
  287. #include <string.h>
  288. -#define MAPS ((struct link_map *) _r_debug.r_map)
  289. +#define MAPS ((struct link_map *) __libc_r_debug.r_map)
  290. static int
  291. check_loaded_objects (const char **loaded)
  292. diff --git a/LibOS/glibc-2.17/elf/neededtest2.c b/LibOS/glibc-2.17/elf/neededtest2.c
  293. index 17c75f2..5a73a95 100644
  294. --- a/LibOS/glibc-2.17/elf/neededtest2.c
  295. +++ b/LibOS/glibc-2.17/elf/neededtest2.c
  296. @@ -5,7 +5,7 @@
  297. #include <stdlib.h>
  298. #include <string.h>
  299. -#define MAPS ((struct link_map *) _r_debug.r_map)
  300. +#define MAPS ((struct link_map *) __libc_r_debug.r_map)
  301. static int
  302. check_loaded_objects (const char **loaded)
  303. diff --git a/LibOS/glibc-2.17/elf/neededtest3.c b/LibOS/glibc-2.17/elf/neededtest3.c
  304. index 41970cf..5126615 100644
  305. --- a/LibOS/glibc-2.17/elf/neededtest3.c
  306. +++ b/LibOS/glibc-2.17/elf/neededtest3.c
  307. @@ -5,7 +5,7 @@
  308. #include <stdlib.h>
  309. #include <string.h>
  310. -#define MAPS ((struct link_map *) _r_debug.r_map)
  311. +#define MAPS ((struct link_map *) __libc_r_debug.r_map)
  312. static int
  313. check_loaded_objects (const char **loaded)
  314. diff --git a/LibOS/glibc-2.17/elf/neededtest4.c b/LibOS/glibc-2.17/elf/neededtest4.c
  315. index 0ae0b7f..f883910 100644
  316. --- a/LibOS/glibc-2.17/elf/neededtest4.c
  317. +++ b/LibOS/glibc-2.17/elf/neededtest4.c
  318. @@ -5,7 +5,7 @@
  319. #include <stdlib.h>
  320. #include <string.h>
  321. -#define MAPS ((struct link_map *) _r_debug.r_map)
  322. +#define MAPS ((struct link_map *) __libc_r_debug.r_map)
  323. static int
  324. check_loaded_objects (const char **loaded)
  325. diff --git a/LibOS/glibc-2.17/elf/rtld.c b/LibOS/glibc-2.17/elf/rtld.c
  326. index b0126e5..2fb4fe9 100644
  327. --- a/LibOS/glibc-2.17/elf/rtld.c
  328. +++ b/LibOS/glibc-2.17/elf/rtld.c
  329. @@ -356,6 +356,23 @@ _dl_start_final (void *arg, struct dl_start_final_info *info)
  330. return start_addr;
  331. }
  332. +/* For graphene, check if glibc version match to the compatible SHIM
  333. + library. If not, tell the user to update glibc. */
  334. +#include "glibc-version.h"
  335. +
  336. +volatile const int glibc_vers_2_17 __attribute__((weak)) = GLIBC_VERSION_2_17;
  337. +
  338. +static void __attribute__((noinline,optimize("-O0")))
  339. +check_glibc_version (void)
  340. +{
  341. + if (glibc_vers_2_17 != GLIBC_VERSION_2_17)
  342. + {
  343. + _dl_fatal_printf ("Warning from Graphene: "
  344. + "Glibc version is incorrect. Please rebuild Glibc.\n");
  345. + _exit (1);
  346. + }
  347. +}
  348. +
  349. static ElfW(Addr) __attribute_used__ internal_function
  350. _dl_start (void *arg)
  351. {
  352. @@ -546,6 +563,9 @@ _dl_start (void *arg)
  353. therefore need not test whether we have to allocate the array
  354. for the relocation results (as done in dl-reloc.c). */
  355. + /* For Graphene, check if the glibc version is correct. */
  356. + check_glibc_version();
  357. +
  358. /* Now life is sane; we can call functions and access global data.
  359. Set up to use the operating system facilities, and find out from
  360. the operating system's program loader where to find the program
  361. @@ -1230,9 +1250,20 @@ of this helper program; chances are you did not intend to run this program.\n\
  362. main_map->l_map_end = allocend;
  363. if ((ph->p_flags & PF_X) && allocend > main_map->l_text_end)
  364. main_map->l_text_end = allocend;
  365. +
  366. +#if 0
  367. + ElfW(Addr) mapend = (allocend + GLRO(dl_pagesize) - 1)
  368. + & ~(GLRO(dl_pagesize) - 1);
  369. + int prot = ((ph->p_flags & PF_R) ? PROT_READ : 0)|
  370. + ((ph->p_flags & PF_W) ? PROT_WRITE : 0)|
  371. + ((ph->p_flags & PF_X) ? PROT_EXEC : 0);
  372. + __mmap ((void *) mapstart, mapend - mapstart,
  373. + prot,
  374. + MAP_ANON|MAP_PRIVATE|MAP_FIXED|0x20000000,
  375. + -1, 0);
  376. +#endif
  377. }
  378. break;
  379. -
  380. case PT_TLS:
  381. if (ph->p_memsz > 0)
  382. {
  383. @@ -1378,13 +1409,31 @@ of this helper program; chances are you did not intend to run this program.\n\
  384. /* PT_GNU_RELRO is usually the last phdr. */
  385. size_t cnt = rtld_ehdr->e_phnum;
  386. while (cnt-- > 0)
  387. + {
  388. if (rtld_phdr[cnt].p_type == PT_GNU_RELRO)
  389. {
  390. GL(dl_rtld_map).l_relro_addr = rtld_phdr[cnt].p_vaddr;
  391. GL(dl_rtld_map).l_relro_size = rtld_phdr[cnt].p_memsz;
  392. - break;
  393. }
  394. +#if 0
  395. + if (rtld_phdr[cnt].p_type == PT_LOAD)
  396. + {
  397. + ElfW(Addr) mapstart = rtld_phdr[cnt].p_vaddr & ~(GLRO(dl_pagesize) - 1);
  398. + ElfW(Addr) mapend = (rtld_phdr[cnt].p_vaddr + rtld_phdr[cnt].p_memsz
  399. + + GLRO(dl_pagesize) - 1)
  400. + & ~(GLRO(dl_pagesize) - 1);
  401. + int prot = ((rtld_phdr[cnt].p_flags & PF_R) ? PROT_READ : 0)|
  402. + ((rtld_phdr[cnt].p_flags & PF_W) ? PROT_WRITE : 0)|
  403. + ((rtld_phdr[cnt].p_flags & PF_X) ? PROT_EXEC : 0);
  404. + __mmap ((void *) mapstart, mapend - mapstart,
  405. + prot,
  406. + MAP_ANON|MAP_PRIVATE|MAP_FIXED|0x20000000,
  407. + -1, 0);
  408. + }
  409. +#endif
  410. + }
  411. +
  412. /* Add the dynamic linker to the TLS list if it also uses TLS. */
  413. if (GL(dl_rtld_map).l_tls_blocksize != 0)
  414. /* Assign a module ID. Do this before loading any audit modules. */
  415. @@ -1585,7 +1634,7 @@ ERROR: ld.so: object '%s' cannot be loaded as audit interface: %s; ignored.\n",
  416. /* We start adding objects. */
  417. r->r_state = RT_ADD;
  418. - _dl_debug_state ();
  419. + __libc_dl_debug_state ();
  420. LIBC_PROBE (init_start, 2, LM_ID_BASE, r);
  421. /* Auditing checkpoint: we are ready to signal that the initial map
  422. @@ -2305,7 +2354,7 @@ ERROR: ld.so: object '%s' cannot be loaded as audit interface: %s; ignored.\n",
  423. the address since by now the variable might be in another object. */
  424. r = _dl_debug_initialize (0, LM_ID_BASE);
  425. r->r_state = RT_CONSISTENT;
  426. - _dl_debug_state ();
  427. + __libc_dl_debug_state ();
  428. LIBC_PROBE (init_complete, 2, LM_ID_BASE, r);
  429. #if defined USE_LDCONFIG && !defined MAP_COPY
  430. diff --git a/LibOS/glibc-2.17/elf/unload.c b/LibOS/glibc-2.17/elf/unload.c
  431. index 4566f22..73046de 100644
  432. --- a/LibOS/glibc-2.17/elf/unload.c
  433. +++ b/LibOS/glibc-2.17/elf/unload.c
  434. @@ -9,7 +9,7 @@
  435. #include <stdio.h>
  436. #include <stdlib.h>
  437. -#define MAPS ((struct link_map *) _r_debug.r_map)
  438. +#define MAPS ((struct link_map *) __libc_r_debug.r_map)
  439. #define OUT \
  440. for (map = MAPS; map != NULL; map = map->l_next) \
  441. diff --git a/LibOS/glibc-2.17/elf/unload2.c b/LibOS/glibc-2.17/elf/unload2.c
  442. index eef2bfd..a21d2ac 100644
  443. --- a/LibOS/glibc-2.17/elf/unload2.c
  444. +++ b/LibOS/glibc-2.17/elf/unload2.c
  445. @@ -6,7 +6,7 @@
  446. #include <stdio.h>
  447. #include <stdlib.h>
  448. -#define MAPS ((struct link_map *) _r_debug.r_map)
  449. +#define MAPS ((struct link_map *) __libc_r_debug.r_map)
  450. #define OUT \
  451. for (map = MAPS; map != NULL; map = map->l_next) \
  452. diff --git a/LibOS/glibc-2.17/nptl/Makefile b/LibOS/glibc-2.17/nptl/Makefile
  453. index e33432e..8ec263f 100644
  454. --- a/LibOS/glibc-2.17/nptl/Makefile
  455. +++ b/LibOS/glibc-2.17/nptl/Makefile
  456. @@ -20,7 +20,7 @@
  457. #
  458. subdir := nptl
  459. -headers := pthread.h semaphore.h bits/semaphore.h
  460. +headers := pthread.h semaphore.h bits/semaphore.h syscalldb.h
  461. extra-libs := libpthread
  462. extra-libs-others := $(extra-libs)
  463. diff --git a/LibOS/glibc-2.17/nptl/Versions b/LibOS/glibc-2.17/nptl/Versions
  464. index 6a10375..4a1eb35 100644
  465. --- a/LibOS/glibc-2.17/nptl/Versions
  466. +++ b/LibOS/glibc-2.17/nptl/Versions
  467. @@ -31,6 +31,9 @@ libc {
  468. # Internal libc interface to libpthread
  469. __libc_dl_error_tsd;
  470. }
  471. + SHIM {
  472. + syscalldb;
  473. + }
  474. }
  475. libpthread {
  476. @@ -257,4 +260,8 @@ libpthread {
  477. __pthread_clock_gettime; __pthread_clock_settime;
  478. __pthread_unwind; __pthread_get_minstack;
  479. }
  480. +
  481. + SHIM {
  482. + syscalldb;
  483. + }
  484. }
  485. diff --git a/LibOS/glibc-2.17/nptl/pthread_create.c b/LibOS/glibc-2.17/nptl/pthread_create.c
  486. index 197dfa7..6cf8fa6 100644
  487. --- a/LibOS/glibc-2.17/nptl/pthread_create.c
  488. +++ b/LibOS/glibc-2.17/nptl/pthread_create.c
  489. @@ -398,8 +398,11 @@ start_thread (void *arg)
  490. # error "to do"
  491. #endif
  492. assert (freesize < pd->stackblock_size);
  493. + /* XXX: may not be necessary */
  494. +#if 0
  495. if (freesize > PTHREAD_STACK_MIN)
  496. __madvise (pd->stackblock, freesize - PTHREAD_STACK_MIN, MADV_DONTNEED);
  497. +#endif
  498. /* If the thread is detached free the TCB. */
  499. if (IS_DETACHED (pd))
  500. diff --git a/LibOS/glibc-2.17/nptl/sysdeps/unix/sysv/linux/x86_64/cancellation.S b/LibOS/glibc-2.17/nptl/sysdeps/unix/sysv/linux/x86_64/cancellation.S
  501. index 31bb08b..4729064 100644
  502. --- a/LibOS/glibc-2.17/nptl/sysdeps/unix/sysv/linux/x86_64/cancellation.S
  503. +++ b/LibOS/glibc-2.17/nptl/sysdeps/unix/sysv/linux/x86_64/cancellation.S
  504. @@ -111,7 +111,8 @@ ENTRY(__pthread_disable_asynccancel)
  505. xorq %r10, %r10
  506. addq $CANCELHANDLING, %rdi
  507. LOAD_PRIVATE_FUTEX_WAIT (%esi)
  508. - syscall
  509. + SYSCALL
  510. +
  511. movl %fs:CANCELHANDLING, %eax
  512. jmp 3b
  513. END(__pthread_disable_asynccancel)
  514. diff --git a/LibOS/glibc-2.17/nptl/sysdeps/unix/sysv/linux/x86_64/fork.c b/LibOS/glibc-2.17/nptl/sysdeps/unix/sysv/linux/x86_64/fork.c
  515. index dedbabd..5bd873e 100644
  516. --- a/LibOS/glibc-2.17/nptl/sysdeps/unix/sysv/linux/x86_64/fork.c
  517. +++ b/LibOS/glibc-2.17/nptl/sysdeps/unix/sysv/linux/x86_64/fork.c
  518. @@ -21,10 +21,20 @@
  519. #include <sysdep.h>
  520. #include <tls.h>
  521. -
  522. -#define ARCH_FORK() \
  523. +/* In Graphene, we prefer to call fork system call directly than clone */
  524. +#if USE_clone_FOR_fork
  525. +# define ARCH_FORK() \
  526. INLINE_SYSCALL (clone, 4, \
  527. CLONE_CHILD_SETTID | CLONE_CHILD_CLEARTID | SIGCHLD, 0, \
  528. NULL, &THREAD_SELF->tid)
  529. +#else
  530. +# define ARCH_FORK() \
  531. + ({ unsigned long ret = INLINE_SYSCALL (fork, 0); \
  532. + if (!ret) { \
  533. + pid_t pid = INLINE_SYSCALL (getpid, 0); \
  534. + THREAD_SETMEM (THREAD_SELF, pid, pid); \
  535. + THREAD_SETMEM (THREAD_SELF, tid, pid); \
  536. + } ret; })
  537. +#endif
  538. #include "../fork.c"
  539. diff --git a/LibOS/glibc-2.17/nptl/sysdeps/unix/sysv/linux/x86_64/lowlevellock.S b/LibOS/glibc-2.17/nptl/sysdeps/unix/sysv/linux/x86_64/lowlevellock.S
  540. index dc95421..a772f66 100644
  541. --- a/LibOS/glibc-2.17/nptl/sysdeps/unix/sysv/linux/x86_64/lowlevellock.S
  542. +++ b/LibOS/glibc-2.17/nptl/sysdeps/unix/sysv/linux/x86_64/lowlevellock.S
  543. @@ -90,7 +90,7 @@ __lll_lock_wait_private:
  544. 1: LIBC_PROBE (lll_lock_wait_private, 1, %rdi)
  545. movl $SYS_futex, %eax
  546. - syscall
  547. + SYSCALL
  548. 2: movl %edx, %eax
  549. xchgl %eax, (%rdi) /* NB: lock is implied */
  550. @@ -130,7 +130,7 @@ __lll_lock_wait:
  551. 1: LIBC_PROBE (lll_lock_wait, 2, %rdi, %rsi)
  552. movl $SYS_futex, %eax
  553. - syscall
  554. + SYSCALL
  555. 2: movl %edx, %eax
  556. xchgl %eax, (%rdi) /* NB: lock is implied */
  557. @@ -185,7 +185,7 @@ __lll_timedlock_wait:
  558. 1: movl $SYS_futex, %eax
  559. movl $2, %edx
  560. - syscall
  561. + SYSCALL
  562. 2: xchgl %edx, (%rdi) /* NB: lock is implied */
  563. @@ -279,7 +279,7 @@ __lll_timedlock_wait:
  564. LOAD_FUTEX_WAIT (%esi)
  565. movq %r12, %rdi
  566. movl $SYS_futex, %eax
  567. - syscall
  568. + SYSCALL
  569. /* NB: %edx == 2 */
  570. xchgl %edx, (%r12)
  571. @@ -336,7 +336,7 @@ __lll_unlock_wake_private:
  572. LOAD_PRIVATE_FUTEX_WAKE (%esi)
  573. movl $1, %edx /* Wake one thread. */
  574. movl $SYS_futex, %eax
  575. - syscall
  576. + SYSCALL
  577. popq %rdx
  578. cfi_adjust_cfa_offset(-8)
  579. @@ -366,7 +366,7 @@ __lll_unlock_wake:
  580. LOAD_FUTEX_WAKE (%esi)
  581. movl $1, %edx /* Wake one thread. */
  582. movl $SYS_futex, %eax
  583. - syscall
  584. + SYSCALL
  585. popq %rdx
  586. cfi_adjust_cfa_offset(-8)
  587. @@ -435,7 +435,7 @@ __lll_timedwait_tid:
  588. #endif
  589. movq %r12, %rdi
  590. movl $SYS_futex, %eax
  591. - syscall
  592. + SYSCALL
  593. cmpl $0, (%rdi)
  594. jne 1f
  595. diff --git a/LibOS/glibc-2.17/nptl/sysdeps/unix/sysv/linux/x86_64/lowlevellock.h b/LibOS/glibc-2.17/nptl/sysdeps/unix/sysv/linux/x86_64/lowlevellock.h
  596. index 5a80ddd..bcc8d57 100644
  597. --- a/LibOS/glibc-2.17/nptl/sysdeps/unix/sysv/linux/x86_64/lowlevellock.h
  598. +++ b/LibOS/glibc-2.17/nptl/sysdeps/unix/sysv/linux/x86_64/lowlevellock.h
  599. @@ -214,12 +214,12 @@ LLL_STUB_UNWIND_INFO_END
  600. register const struct timespec *__to __asm ("r10") = timeout; \
  601. int __status; \
  602. register __typeof (val) _val __asm ("edx") = (val); \
  603. - __asm __volatile ("syscall" \
  604. + __asm __volatile (SYSCALLDB \
  605. : "=a" (__status) \
  606. : "0" (SYS_futex), "D" (futex), \
  607. "S" (__lll_private_flag (FUTEX_WAIT, private)), \
  608. "d" (_val), "r" (__to) \
  609. - : "memory", "cc", "r11", "cx"); \
  610. + : "memory", "cc", "r11", "cx", "bx"); \
  611. __status; \
  612. })
  613. @@ -229,12 +229,12 @@ LLL_STUB_UNWIND_INFO_END
  614. int __ignore; \
  615. register __typeof (nr) _nr __asm ("edx") = (nr); \
  616. LIBC_PROBE (lll_futex_wake, 3, futex, nr, private); \
  617. - __asm __volatile ("syscall" \
  618. + __asm __volatile (SYSCALLDB \
  619. : "=a" (__ignore) \
  620. : "0" (SYS_futex), "D" (futex), \
  621. "S" (__lll_private_flag (FUTEX_WAKE, private)), \
  622. "d" (_nr) \
  623. - : "memory", "cc", "r10", "r11", "cx"); \
  624. + : "memory", "cc", "r10", "r11", "cx", "bx"); \
  625. } while (0)
  626. @@ -532,12 +532,12 @@ LLL_STUB_UNWIND_INFO_END
  627. { \
  628. int ignore; \
  629. __asm __volatile (LOCK_INSTR "orl %3, (%2)\n\t" \
  630. - "syscall" \
  631. + SYSCALLDB \
  632. : "=m" (futex), "=a" (ignore) \
  633. : "D" (&(futex)), "i" (FUTEX_OWNER_DIED), \
  634. "S" (__lll_private_flag (FUTEX_WAKE, private)), \
  635. "1" (__NR_futex), "d" (1) \
  636. - : "cx", "r11", "cc", "memory"); \
  637. + : "cx", "bx", "r11", "cc", "memory"); \
  638. } \
  639. while (0)
  640. @@ -547,13 +547,13 @@ LLL_STUB_UNWIND_INFO_END
  641. register int __nr_move __asm ("r10") = nr_move; \
  642. register void *__mutex __asm ("r8") = mutex; \
  643. register int __val __asm ("r9") = val; \
  644. - __asm __volatile ("syscall" \
  645. + __asm __volatile (SYSCALLDB \
  646. : "=a" (__res) \
  647. : "0" (__NR_futex), "D" ((void *) ftx), \
  648. "S" (__lll_private_flag (FUTEX_CMP_REQUEUE, \
  649. private)), "d" (nr_wake), \
  650. "r" (__nr_move), "r" (__mutex), "r" (__val) \
  651. - : "cx", "r11", "cc", "memory"); \
  652. + : "cx", "bx", "r11", "cc", "memory"); \
  653. __res < 0; })
  654. #define lll_islocked(futex) \
  655. @@ -573,13 +573,13 @@ LLL_STUB_UNWIND_INFO_END
  656. if (_tid != 0) \
  657. __asm __volatile ("xorq %%r10, %%r10\n\t" \
  658. "1:\tmovq %2, %%rax\n\t" \
  659. - "syscall\n\t" \
  660. + SYSCALLDB \
  661. "cmpl $0, (%%rdi)\n\t" \
  662. "jne 1b" \
  663. : "=&a" (__ignore) \
  664. : "S" (FUTEX_WAIT), "i" (SYS_futex), "D" (&tid), \
  665. "d" (_tid) \
  666. - : "memory", "cc", "r10", "r11", "cx"); \
  667. + : "memory", "cc", "r10", "r11", "cx", "bx"); \
  668. } while (0)
  669. extern int __lll_timedwait_tid (int *tid, const struct timespec *abstime)
  670. diff --git a/LibOS/glibc-2.17/nptl/sysdeps/unix/sysv/linux/x86_64/lowlevelrobustlock.S b/LibOS/glibc-2.17/nptl/sysdeps/unix/sysv/linux/x86_64/lowlevelrobustlock.S
  671. index 0b4ef71..36c5572 100644
  672. --- a/LibOS/glibc-2.17/nptl/sysdeps/unix/sysv/linux/x86_64/lowlevelrobustlock.S
  673. +++ b/LibOS/glibc-2.17/nptl/sysdeps/unix/sysv/linux/x86_64/lowlevelrobustlock.S
  674. @@ -80,7 +80,7 @@ __lll_robust_lock_wait:
  675. jnz 2f
  676. 1: movl $SYS_futex, %eax
  677. - syscall
  678. + SYSCALL
  679. movl (%rdi), %eax
  680. @@ -145,7 +145,7 @@ __lll_robust_timedlock_wait:
  681. jnz 6f
  682. 5: movl $SYS_futex, %eax
  683. - syscall
  684. + SYSCALL
  685. movl %eax, %ecx
  686. movl (%rdi), %eax
  687. @@ -257,7 +257,7 @@ __lll_robust_timedlock_wait:
  688. LOAD_FUTEX_WAIT (%esi)
  689. movq %r12, %rdi
  690. movl $SYS_futex, %eax
  691. - syscall
  692. + SYSCALL
  693. movq %rax, %rcx
  694. movl (%r12), %eax
  695. diff --git a/LibOS/glibc-2.17/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_barrier_wait.S b/LibOS/glibc-2.17/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_barrier_wait.S
  696. index 61c2f54..e70362c 100644
  697. --- a/LibOS/glibc-2.17/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_barrier_wait.S
  698. +++ b/LibOS/glibc-2.17/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_barrier_wait.S
  699. @@ -62,7 +62,7 @@ pthread_barrier_wait:
  700. #endif
  701. xorq %r10, %r10
  702. 8: movl $SYS_futex, %eax
  703. - syscall
  704. + SYSCALL
  705. /* Don't return on spurious wakeups. The syscall does not change
  706. any register except %eax so there is no need to reload any of
  707. @@ -109,7 +109,7 @@ pthread_barrier_wait:
  708. movl $FUTEX_WAKE, %esi
  709. orl PRIVATE(%rdi), %esi
  710. movl $SYS_futex, %eax
  711. - syscall
  712. + SYSCALL
  713. /* Increment LEFT. If this brings the count back to the
  714. initial count unlock the object. */
  715. diff --git a/LibOS/glibc-2.17/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_cond_broadcast.S b/LibOS/glibc-2.17/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_cond_broadcast.S
  716. index 67ff5fc..a95f808 100644
  717. --- a/LibOS/glibc-2.17/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_cond_broadcast.S
  718. +++ b/LibOS/glibc-2.17/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_cond_broadcast.S
  719. @@ -90,7 +90,7 @@ __pthread_cond_broadcast:
  720. movl $SYS_futex, %eax
  721. movl $1, %edx
  722. movl $0x7fffffff, %r10d
  723. - syscall
  724. + SYSCALL
  725. /* For any kind of error, which mainly is EAGAIN, we try again
  726. with WAKE. The general test also covers running on old
  727. @@ -106,7 +106,7 @@ __pthread_cond_broadcast:
  728. movl $SYS_futex, %eax
  729. movl $1, %edx
  730. movl $0x7fffffff, %r10d
  731. - syscall
  732. + SYSCALL
  733. /* For any kind of error, which mainly is EAGAIN, we try again
  734. with WAKE. The general test also covers running on old
  735. @@ -172,7 +172,7 @@ __pthread_cond_broadcast:
  736. orl $FUTEX_WAKE, %esi
  737. #endif
  738. movl $SYS_futex, %eax
  739. - syscall
  740. + SYSCALL
  741. jmp 10b
  742. .size __pthread_cond_broadcast, .-__pthread_cond_broadcast
  743. versioned_symbol (libpthread, __pthread_cond_broadcast, pthread_cond_broadcast,
  744. diff --git a/LibOS/glibc-2.17/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_cond_signal.S b/LibOS/glibc-2.17/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_cond_signal.S
  745. index 3bff19b..80f4b47 100644
  746. --- a/LibOS/glibc-2.17/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_cond_signal.S
  747. +++ b/LibOS/glibc-2.17/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_cond_signal.S
  748. @@ -82,7 +82,7 @@ __pthread_cond_signal:
  749. addq $cond_lock, %r8
  750. #endif
  751. movl $FUTEX_OP_CLEAR_WAKE_IF_GT_ONE, %r9d
  752. - syscall
  753. + SYSCALL
  754. #if cond_lock != 0
  755. subq $cond_lock, %r8
  756. #endif
  757. @@ -99,7 +99,7 @@ __pthread_cond_signal:
  758. movq %rcx, %r8
  759. xorq %r10, %r10
  760. movl (%rdi), %r9d // XXX Can this be right?
  761. - syscall
  762. + SYSCALL
  763. leaq -cond_futex(%rdi), %r8
  764. @@ -118,7 +118,7 @@ __pthread_cond_signal:
  765. movl $SYS_futex, %eax
  766. /* %rdx should be 1 already from $FUTEX_WAKE_OP syscall.
  767. movl $1, %edx */
  768. - syscall
  769. + SYSCALL
  770. /* Unlock. */
  771. 4: LOCK
  772. diff --git a/LibOS/glibc-2.17/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_cond_timedwait.S b/LibOS/glibc-2.17/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_cond_timedwait.S
  773. index 15e451a..14b768a 100644
  774. --- a/LibOS/glibc-2.17/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_cond_timedwait.S
  775. +++ b/LibOS/glibc-2.17/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_cond_timedwait.S
  776. @@ -188,7 +188,7 @@ __pthread_cond_timedwait:
  777. movq %r12, %rdx
  778. addq $cond_futex, %rdi
  779. movl $SYS_futex, %eax
  780. - syscall
  781. + SYSCALL
  782. cmpl $0, %eax
  783. sete %r15b
  784. @@ -234,7 +234,7 @@ __pthread_cond_timedwait:
  785. movq %r12, %rdx
  786. addq $cond_futex, %rdi
  787. movl $SYS_futex, %eax
  788. - syscall
  789. + SYSCALL
  790. 62: movq %rax, %r14
  791. movl (%rsp), %edi
  792. @@ -321,7 +321,7 @@ __pthread_cond_timedwait:
  793. orl $FUTEX_WAKE, %esi
  794. #endif
  795. movl $SYS_futex, %eax
  796. - syscall
  797. + SYSCALL
  798. subq $cond_nwaiters, %rdi
  799. 55: LOCK
  800. @@ -485,15 +485,8 @@ __pthread_cond_timedwait:
  801. /* Only clocks 0 and 1 are allowed so far. Both are handled in the
  802. kernel. */
  803. leaq 32(%rsp), %rsi
  804. -# ifdef SHARED
  805. - mov __vdso_clock_gettime@GOTPCREL(%rip), %RAX_LP
  806. - mov (%rax), %RAX_LP
  807. - PTR_DEMANGLE (%RAX_LP)
  808. - call *%rax
  809. -# else
  810. movl $__NR_clock_gettime, %eax
  811. - syscall
  812. -# endif
  813. + SYSCALL
  814. /* Compute relative timeout. */
  815. movq (%r13), %rcx
  816. @@ -560,7 +553,7 @@ __pthread_cond_timedwait:
  817. # endif
  818. addq $cond_futex, %rdi
  819. movl $SYS_futex, %eax
  820. - syscall
  821. + SYSCALL
  822. movq %rax, %r14
  823. movl (%rsp), %edi
  824. @@ -732,7 +725,7 @@ __condvar_cleanup2:
  825. orl $FUTEX_WAKE, %esi
  826. #endif
  827. movl $SYS_futex, %eax
  828. - syscall
  829. + SYSCALL
  830. subq $cond_nwaiters, %rdi
  831. movl $1, %r12d
  832. @@ -769,7 +762,7 @@ __condvar_cleanup2:
  833. orl $FUTEX_WAKE, %esi
  834. #endif
  835. movl $SYS_futex, %eax
  836. - syscall
  837. + SYSCALL
  838. /* Lock the mutex only if we don't own it already. This only happens
  839. in case of PI mutexes, if we got cancelled after a successful
  840. diff --git a/LibOS/glibc-2.17/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_cond_wait.S b/LibOS/glibc-2.17/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_cond_wait.S
  841. index 2c6b515..296659c 100644
  842. --- a/LibOS/glibc-2.17/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_cond_wait.S
  843. +++ b/LibOS/glibc-2.17/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_cond_wait.S
  844. @@ -138,7 +138,7 @@ __pthread_cond_wait:
  845. movl $(FUTEX_WAIT_REQUEUE_PI|FUTEX_PRIVATE_FLAG), %esi
  846. movl $SYS_futex, %eax
  847. - syscall
  848. + SYSCALL
  849. cmpl $0, %eax
  850. sete %r8b
  851. @@ -180,7 +180,7 @@ __pthread_cond_wait:
  852. #endif
  853. 60: xorb %r8b, %r8b
  854. movl $SYS_futex, %eax
  855. - syscall
  856. + SYSCALL
  857. 62: movl (%rsp), %edi
  858. callq __pthread_disable_asynccancel
  859. @@ -239,7 +239,7 @@ __pthread_cond_wait:
  860. orl $FUTEX_WAKE, %esi
  861. #endif
  862. movl $SYS_futex, %eax
  863. - syscall
  864. + SYSCALL
  865. subq $cond_nwaiters, %rdi
  866. 17: LOCK
  867. @@ -455,7 +455,7 @@ __condvar_cleanup1:
  868. orl $FUTEX_WAKE, %esi
  869. #endif
  870. movl $SYS_futex, %eax
  871. - syscall
  872. + SYSCALL
  873. subq $cond_nwaiters, %rdi
  874. movl $1, %ecx
  875. @@ -493,7 +493,7 @@ __condvar_cleanup1:
  876. orl $FUTEX_WAKE, %esi
  877. #endif
  878. movl $SYS_futex, %eax
  879. - syscall
  880. + SYSCALL
  881. /* Lock the mutex only if we don't own it already. This only happens
  882. in case of PI mutexes, if we got cancelled after a successful
  883. diff --git a/LibOS/glibc-2.17/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_once.S b/LibOS/glibc-2.17/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_once.S
  884. index 7f5c081..38ecb12 100644
  885. --- a/LibOS/glibc-2.17/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_once.S
  886. +++ b/LibOS/glibc-2.17/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_once.S
  887. @@ -90,7 +90,7 @@ __pthread_once:
  888. # endif
  889. #endif
  890. movl $SYS_futex, %eax
  891. - syscall
  892. + SYSCALL
  893. jmp 6b
  894. /* Preserve the pointer to the control variable. */
  895. @@ -123,7 +123,7 @@ __pthread_once:
  896. orl %fs:PRIVATE_FUTEX, %esi
  897. #endif
  898. movl $SYS_futex, %eax
  899. - syscall
  900. + SYSCALL
  901. 4: addq $8, %rsp
  902. cfi_adjust_cfa_offset(-8)
  903. @@ -152,7 +152,7 @@ clear_once_control:
  904. orl %fs:PRIVATE_FUTEX, %esi
  905. #endif
  906. movl $SYS_futex, %eax
  907. - syscall
  908. + SYSCALL
  909. movq %r8, %rdi
  910. .LcallUR:
  911. diff --git a/LibOS/glibc-2.17/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_rdlock.S b/LibOS/glibc-2.17/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_rdlock.S
  912. index 264ba58..c54f316 100644
  913. --- a/LibOS/glibc-2.17/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_rdlock.S
  914. +++ b/LibOS/glibc-2.17/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_rdlock.S
  915. @@ -82,7 +82,7 @@ __pthread_rwlock_rdlock:
  916. #endif
  917. addq $READERS_WAKEUP, %rdi
  918. movl $SYS_futex, %eax
  919. - syscall
  920. + SYSCALL
  921. subq $READERS_WAKEUP, %rdi
  922. diff --git a/LibOS/glibc-2.17/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_timedrdlock.S b/LibOS/glibc-2.17/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_timedrdlock.S
  923. index f60530e..fb7894a 100644
  924. --- a/LibOS/glibc-2.17/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_timedrdlock.S
  925. +++ b/LibOS/glibc-2.17/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_timedrdlock.S
  926. @@ -109,7 +109,7 @@ pthread_rwlock_timedrdlock:
  927. #endif
  928. 21: leaq READERS_WAKEUP(%r12), %rdi
  929. movl $SYS_futex, %eax
  930. - syscall
  931. + SYSCALL
  932. movq %rax, %rdx
  933. #ifndef __ASSUME_FUTEX_CLOCK_REALTIME
  934. diff --git a/LibOS/glibc-2.17/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_timedwrlock.S b/LibOS/glibc-2.17/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_timedwrlock.S
  935. index 7870733..f9eee96 100644
  936. --- a/LibOS/glibc-2.17/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_timedwrlock.S
  937. +++ b/LibOS/glibc-2.17/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_timedwrlock.S
  938. @@ -107,7 +107,7 @@ pthread_rwlock_timedwrlock:
  939. #endif
  940. 21: leaq WRITERS_WAKEUP(%r12), %rdi
  941. movl $SYS_futex, %eax
  942. - syscall
  943. + SYSCALL
  944. movq %rax, %rdx
  945. #ifndef __ASSUME_FUTEX_CLOCK_REALTIME
  946. diff --git a/LibOS/glibc-2.17/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_unlock.S b/LibOS/glibc-2.17/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_unlock.S
  947. index e971529..bdd1f4d 100644
  948. --- a/LibOS/glibc-2.17/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_unlock.S
  949. +++ b/LibOS/glibc-2.17/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_unlock.S
  950. @@ -79,7 +79,7 @@ __pthread_rwlock_unlock:
  951. #endif
  952. movl $SYS_futex, %eax
  953. movq %r10, %rdi
  954. - syscall
  955. + SYSCALL
  956. xorl %eax, %eax
  957. retq
  958. diff --git a/LibOS/glibc-2.17/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_wrlock.S b/LibOS/glibc-2.17/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_wrlock.S
  959. index ff5392c..1afe769 100644
  960. --- a/LibOS/glibc-2.17/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_wrlock.S
  961. +++ b/LibOS/glibc-2.17/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_wrlock.S
  962. @@ -80,7 +80,7 @@ __pthread_rwlock_wrlock:
  963. #endif
  964. addq $WRITERS_WAKEUP, %rdi
  965. movl $SYS_futex, %eax
  966. - syscall
  967. + SYSCALL
  968. subq $WRITERS_WAKEUP, %rdi
  969. diff --git a/LibOS/glibc-2.17/nptl/sysdeps/unix/sysv/linux/x86_64/sem_post.S b/LibOS/glibc-2.17/nptl/sysdeps/unix/sysv/linux/x86_64/sem_post.S
  970. index 65e715d..7152395 100644
  971. --- a/LibOS/glibc-2.17/nptl/sysdeps/unix/sysv/linux/x86_64/sem_post.S
  972. +++ b/LibOS/glibc-2.17/nptl/sysdeps/unix/sysv/linux/x86_64/sem_post.S
  973. @@ -52,7 +52,7 @@ sem_post:
  974. movl $FUTEX_WAKE, %esi
  975. orl PRIVATE(%rdi), %esi
  976. movl $1, %edx
  977. - syscall
  978. + SYSCALL
  979. testq %rax, %rax
  980. js 1f
  981. diff --git a/LibOS/glibc-2.17/nptl/sysdeps/unix/sysv/linux/x86_64/sem_timedwait.S b/LibOS/glibc-2.17/nptl/sysdeps/unix/sysv/linux/x86_64/sem_timedwait.S
  982. index acb79db..f9db4d1 100644
  983. --- a/LibOS/glibc-2.17/nptl/sysdeps/unix/sysv/linux/x86_64/sem_timedwait.S
  984. +++ b/LibOS/glibc-2.17/nptl/sysdeps/unix/sysv/linux/x86_64/sem_timedwait.S
  985. @@ -97,7 +97,7 @@ sem_timedwait:
  986. orl PRIVATE(%rdi), %esi
  987. movl $SYS_futex, %eax
  988. xorl %edx, %edx
  989. - syscall
  990. + SYSCALL
  991. movq %rax, %r9
  992. #if VALUE != 0
  993. leaq -VALUE(%rdi), %rdi
  994. @@ -233,7 +233,7 @@ sem_timedwait:
  995. # endif
  996. movl $SYS_futex, %eax
  997. xorl %edx, %edx
  998. - syscall
  999. + SYSCALL
  1000. movq %rax, %r14
  1001. movl 16(%rsp), %edi
  1002. diff --git a/LibOS/glibc-2.17/nptl/sysdeps/unix/sysv/linux/x86_64/sem_wait.S b/LibOS/glibc-2.17/nptl/sysdeps/unix/sysv/linux/x86_64/sem_wait.S
  1003. index 7f91148..ac4b8e8 100644
  1004. --- a/LibOS/glibc-2.17/nptl/sysdeps/unix/sysv/linux/x86_64/sem_wait.S
  1005. +++ b/LibOS/glibc-2.17/nptl/sysdeps/unix/sysv/linux/x86_64/sem_wait.S
  1006. @@ -81,7 +81,7 @@ sem_wait:
  1007. orl PRIVATE(%rdi), %esi
  1008. #endif
  1009. xorl %edx, %edx
  1010. - syscall
  1011. + SYSCALL
  1012. movq %rax, %rcx
  1013. xchgq %r8, %rdi
  1014. diff --git a/LibOS/glibc-2.17/nptl/sysdeps/x86_64/pthreaddef.h b/LibOS/glibc-2.17/nptl/sysdeps/x86_64/pthreaddef.h
  1015. index 50587b8..374b553 100644
  1016. --- a/LibOS/glibc-2.17/nptl/sysdeps/x86_64/pthreaddef.h
  1017. +++ b/LibOS/glibc-2.17/nptl/sysdeps/x86_64/pthreaddef.h
  1018. @@ -48,4 +48,5 @@
  1019. /* While there is no such syscall. */
  1020. #define __exit_thread_inline(val) \
  1021. - asm volatile ("syscall" :: "a" (__NR_exit), "D" (val))
  1022. + asm volatile ("pushq %%rbx\n\tmovq syscalldb@GOTPCREL(%%rip), %%rbx\n\t" \
  1023. + "call %%rbx\n\t" :: "a" (__NR_exit), "D" (val) : "bx" )
  1024. diff --git a/LibOS/glibc-2.17/nptl/sysdeps/x86_64/tls.h b/LibOS/glibc-2.17/nptl/sysdeps/x86_64/tls.h
  1025. index f3b7649..b466cb1 100644
  1026. --- a/LibOS/glibc-2.17/nptl/sysdeps/x86_64/tls.h
  1027. +++ b/LibOS/glibc-2.17/nptl/sysdeps/x86_64/tls.h
  1028. @@ -28,6 +28,7 @@
  1029. # include <sysdep.h>
  1030. # include <libc-internal.h>
  1031. # include <kernel-features.h>
  1032. +# include <shim_tls.h>
  1033. /* Replacement type for __m128 since this file is included by ld.so,
  1034. which is compiled with -mno-sse. It must not change the alignment
  1035. @@ -67,6 +68,10 @@ typedef struct
  1036. # else
  1037. int __unused1;
  1038. # endif
  1039. +
  1040. + shim_tcb_t shim_tcb; /* For graphene, we allocate a shim_tcb
  1041. + in the real tcb. */
  1042. +
  1043. int rtld_must_xmm_save;
  1044. /* Reservation of some values for the TM ABI. */
  1045. void *__private_tm[5];
  1046. @@ -135,6 +140,8 @@ typedef struct
  1047. # define GET_DTV(descr) \
  1048. (((tcbhead_t *) (descr))->dtv)
  1049. +/* For Graphene */
  1050. +#define SYSCALLDB "movq syscalldb@GOTPCREL(%%rip), %%rbx\n\tcall %%rbx\n\t"
  1051. /* Code to initially initialize the thread pointer. This might need
  1052. special attention since 'errno' is not yet available and if the
  1053. @@ -152,12 +159,12 @@ typedef struct
  1054. _head->self = _thrdescr; \
  1055. \
  1056. /* It is a simple syscall to set the %fs value for the thread. */ \
  1057. - asm volatile ("syscall" \
  1058. + asm volatile (SYSCALLDB \
  1059. : "=a" (_result) \
  1060. : "0" ((unsigned long int) __NR_arch_prctl), \
  1061. "D" ((unsigned long int) ARCH_SET_FS), \
  1062. "S" (_thrdescr) \
  1063. - : "memory", "cc", "r11", "cx"); \
  1064. + : "memory", "cc", "r11", "cx", "bx"); \
  1065. \
  1066. _result ? "cannot set %fs base address for thread-local storage" : 0; \
  1067. })
  1068. diff --git a/LibOS/glibc-2.17/scripts/mkinstalldirs b/LibOS/glibc-2.17/scripts/mkinstalldirs
  1069. index f945dbf..3c0e48c 100755
  1070. --- a/LibOS/glibc-2.17/scripts/mkinstalldirs
  1071. +++ b/LibOS/glibc-2.17/scripts/mkinstalldirs
  1072. @@ -20,9 +20,9 @@ do
  1073. esac
  1074. if test ! -d "$pathcomp"; then
  1075. - echo "mkdir $pathcomp" 1>&2
  1076. + echo "mkdir -p $pathcomp" 1>&2
  1077. - mkdir "$pathcomp" || lasterr=$?
  1078. + mkdir -p "$pathcomp" || lasterr=$?
  1079. if test ! -d "$pathcomp"; then
  1080. errstatus=$lasterr
  1081. diff --git a/LibOS/glibc-2.17/shlib-versions b/LibOS/glibc-2.17/shlib-versions
  1082. index 9344590..4edb370 100644
  1083. --- a/LibOS/glibc-2.17/shlib-versions
  1084. +++ b/LibOS/glibc-2.17/shlib-versions
  1085. @@ -107,3 +107,5 @@ sparc64.*-.*-.* libBrokenLocale=1 GLIBC_2.2
  1086. # This defines the libgcc soname version this glibc is to load for
  1087. # asynchronous cancellation to work correctly.
  1088. .*-.*-.* libgcc_s=1
  1089. +
  1090. +.*-.*-.* liblibos=1
  1091. diff --git a/LibOS/glibc-2.17/sysdeps/generic/ldsodefs.h b/LibOS/glibc-2.17/sysdeps/generic/ldsodefs.h
  1092. index c667e34..9803b8a 100644
  1093. --- a/LibOS/glibc-2.17/sysdeps/generic/ldsodefs.h
  1094. +++ b/LibOS/glibc-2.17/sysdeps/generic/ldsodefs.h
  1095. @@ -854,8 +854,7 @@ extern void _dl_sort_fini (struct link_map **maps, size_t nmaps, char *used,
  1096. any shared object mappings. The `r_state' member of `struct r_debug'
  1097. says what change is taking place. This function's address is
  1098. the value of the `r_brk' member. */
  1099. -extern void _dl_debug_state (void);
  1100. -rtld_hidden_proto (_dl_debug_state)
  1101. +extern void __libc_dl_debug_state (void) __attribute__((weak));
  1102. /* Initialize `struct r_debug' if it has not already been done. The
  1103. argument is the run-time load address of the dynamic linker, to be put
  1104. diff --git a/LibOS/glibc-2.17/sysdeps/unix/sysv/linux/_exit.c b/LibOS/glibc-2.17/sysdeps/unix/sysv/linux/_exit.c
  1105. index 18c4fce..a21fb32 100644
  1106. --- a/LibOS/glibc-2.17/sysdeps/unix/sysv/linux/_exit.c
  1107. +++ b/LibOS/glibc-2.17/sysdeps/unix/sysv/linux/_exit.c
  1108. @@ -29,9 +29,9 @@ _exit (status)
  1109. while (1)
  1110. {
  1111. #ifdef __NR_exit_group
  1112. - INLINE_SYSCALL (exit_group, 1, status);
  1113. + INLINE_SYSCALL_ASM (exit_group, 1, status);
  1114. #endif
  1115. - INLINE_SYSCALL (exit, 1, status);
  1116. + INLINE_SYSCALL_ASM (exit, 1, status);
  1117. #ifdef ABORT_INSTRUCTION
  1118. ABORT_INSTRUCTION;
  1119. diff --git a/LibOS/glibc-2.17/sysdeps/unix/sysv/linux/x86_64/____longjmp_chk.S b/LibOS/glibc-2.17/sysdeps/unix/sysv/linux/x86_64/____longjmp_chk.S
  1120. index d9bdb67..9719699 100644
  1121. --- a/LibOS/glibc-2.17/sysdeps/unix/sysv/linux/x86_64/____longjmp_chk.S
  1122. +++ b/LibOS/glibc-2.17/sysdeps/unix/sysv/linux/x86_64/____longjmp_chk.S
  1123. @@ -84,7 +84,8 @@ ENTRY(____longjmp_chk)
  1124. xorl %edi, %edi
  1125. lea -sizeSS(%rsp), %RSI_LP
  1126. movl $__NR_sigaltstack, %eax
  1127. - syscall
  1128. + SYSCALL
  1129. +
  1130. /* Without working sigaltstack we cannot perform the test. */
  1131. testl %eax, %eax
  1132. jne .Lok2
  1133. diff --git a/LibOS/glibc-2.17/sysdeps/unix/sysv/linux/x86_64/clock_gettime.c b/LibOS/glibc-2.17/sysdeps/unix/sysv/linux/x86_64/clock_gettime.c
  1134. index f712110..f6bad14 100644
  1135. --- a/LibOS/glibc-2.17/sysdeps/unix/sysv/linux/x86_64/clock_gettime.c
  1136. +++ b/LibOS/glibc-2.17/sysdeps/unix/sysv/linux/x86_64/clock_gettime.c
  1137. @@ -1,5 +1,6 @@
  1138. #include "bits/libc-vdso.h"
  1139. +#if 0 /* in Graphene, disallow VDSO calls */
  1140. #ifdef SHARED
  1141. # define SYSCALL_GETTIME(id, tp) \
  1142. ({ long int (*f) (clockid_t, struct timespec *) = __vdso_clock_gettime; \
  1143. @@ -16,5 +17,6 @@
  1144. PTR_DEMANGLE (f); \
  1145. f (id, tp); })
  1146. #endif
  1147. +#endif
  1148. #include "../clock_gettime.c"
  1149. diff --git a/LibOS/glibc-2.17/sysdeps/unix/sysv/linux/x86_64/clone.S b/LibOS/glibc-2.17/sysdeps/unix/sysv/linux/x86_64/clone.S
  1150. index 53f9fbd..80d28b5 100644
  1151. --- a/LibOS/glibc-2.17/sysdeps/unix/sysv/linux/x86_64/clone.S
  1152. +++ b/LibOS/glibc-2.17/sysdeps/unix/sysv/linux/x86_64/clone.S
  1153. @@ -61,11 +61,15 @@ ENTRY (BP_SYM (__clone))
  1154. jz SYSCALL_ERROR_LABEL
  1155. /* Insert the argument onto the new stack. */
  1156. - subq $16,%rsi
  1157. - movq %rcx,8(%rsi)
  1158. + subq $24,%rsi
  1159. + movq %rcx,16(%rsi)
  1160. /* Save the function pointer. It will be popped off in the
  1161. child in the ebx frobbing below. */
  1162. + movq %rdi,8(%rsi)
  1163. +
  1164. + /* Push an additional pointer as return address into the stack */
  1165. + leaq L(clone_return)(%rip),%rdi
  1166. movq %rdi,0(%rsi)
  1167. /* Do the system call. */
  1168. @@ -78,8 +82,9 @@ ENTRY (BP_SYM (__clone))
  1169. /* End FDE now, because in the child the unwind info will be
  1170. wrong. */
  1171. cfi_endproc;
  1172. - syscall
  1173. + SYSCALL
  1174. +L(clone_return):
  1175. testq %rax,%rax
  1176. jl SYSCALL_ERROR_LABEL
  1177. jz L(thread_start)
  1178. @@ -101,13 +106,14 @@ L(thread_start):
  1179. movl $-1, %eax
  1180. jne 2f
  1181. movl $SYS_ify(getpid), %eax
  1182. - syscall
  1183. + SYSCALL
  1184. 2: movl %eax, %fs:PID
  1185. movl %eax, %fs:TID
  1186. 1:
  1187. #endif
  1188. /* Set up arguments for the function call. */
  1189. + addq $8,%rsp /* Skip the return address */
  1190. popq %rax /* Function to call. */
  1191. popq %rdi /* Argument. */
  1192. call *%rax
  1193. diff --git a/LibOS/glibc-2.17/sysdeps/unix/sysv/linux/x86_64/getcontext.S b/LibOS/glibc-2.17/sysdeps/unix/sysv/linux/x86_64/getcontext.S
  1194. index 5f2b64c..df57736 100644
  1195. --- a/LibOS/glibc-2.17/sysdeps/unix/sysv/linux/x86_64/getcontext.S
  1196. +++ b/LibOS/glibc-2.17/sysdeps/unix/sysv/linux/x86_64/getcontext.S
  1197. @@ -75,7 +75,7 @@ ENTRY(__getcontext)
  1198. #endif
  1199. movl $_NSIG8,%r10d
  1200. movl $__NR_rt_sigprocmask, %eax
  1201. - syscall
  1202. + SYSCALL
  1203. cmpq $-4095, %rax /* Check %rax for error. */
  1204. jae SYSCALL_ERROR_LABEL /* Jump to error handler if error. */
  1205. diff --git a/LibOS/glibc-2.17/sysdeps/unix/sysv/linux/x86_64/gettimeofday.c b/LibOS/glibc-2.17/sysdeps/unix/sysv/linux/x86_64/gettimeofday.c
  1206. index d52f938..d75b502 100644
  1207. --- a/LibOS/glibc-2.17/sysdeps/unix/sysv/linux/x86_64/gettimeofday.c
  1208. +++ b/LibOS/glibc-2.17/sysdeps/unix/sysv/linux/x86_64/gettimeofday.c
  1209. @@ -17,6 +17,7 @@
  1210. #include <sys/time.h>
  1211. +#if 0 /* In graphene, do not use vsyscall or VDSO call */
  1212. #ifdef SHARED
  1213. # include <dl-vdso.h>
  1214. @@ -42,7 +43,8 @@ asm (".type __gettimeofday, %gnu_indirect_function");
  1215. asm (".globl __GI___gettimeofday\n"
  1216. "__GI___gettimeofday = __gettimeofday");
  1217. -#else
  1218. +#endif
  1219. +#endif
  1220. # include <sysdep.h>
  1221. # include <errno.h>
  1222. @@ -54,6 +56,5 @@ __gettimeofday (struct timeval *tv, struct timezone *tz)
  1223. }
  1224. libc_hidden_def (__gettimeofday)
  1225. -#endif
  1226. weak_alias (__gettimeofday, gettimeofday)
  1227. libc_hidden_weak (gettimeofday)
  1228. diff --git a/LibOS/glibc-2.17/sysdeps/unix/sysv/linux/x86_64/sched_getcpu.S b/LibOS/glibc-2.17/sysdeps/unix/sysv/linux/x86_64/sched_getcpu.S
  1229. index 3b319d7..98d8612 100644
  1230. --- a/LibOS/glibc-2.17/sysdeps/unix/sysv/linux/x86_64/sched_getcpu.S
  1231. +++ b/LibOS/glibc-2.17/sysdeps/unix/sysv/linux/x86_64/sched_getcpu.S
  1232. @@ -30,6 +30,7 @@ ENTRY (sched_getcpu)
  1233. sub $0x8, %rsp
  1234. cfi_adjust_cfa_offset(8)
  1235. +#if 0 /* for Graphene, never do VDSO calls */
  1236. movq %rsp, %rdi
  1237. xorl %esi, %esi
  1238. movl $VGETCPU_CACHE_OFFSET, %edx
  1239. @@ -39,16 +40,19 @@ ENTRY (sched_getcpu)
  1240. movq __vdso_getcpu(%rip), %rax
  1241. PTR_DEMANGLE (%rax)
  1242. callq *%rax
  1243. -#else
  1244. -# ifdef __NR_getcpu
  1245. +#endif
  1246. +#endif
  1247. +
  1248. +#ifdef __NR_getcpu
  1249. movl $__NR_getcpu, %eax
  1250. - syscall
  1251. -# ifndef __ASSUME_GETCPU_SYSCALL
  1252. + SYSCALL
  1253. +#endif
  1254. +
  1255. +#if 0 /* for Graphene, never do vsyscall */
  1256. +# ifndef __ASSUME_GETCPU_SYSCALL
  1257. cmpq $-ENOSYS, %rax
  1258. jne 1f
  1259. -# endif
  1260. -# endif
  1261. -# ifndef __ASSUME_GETCPU_SYSCALL
  1262. +
  1263. movq $VSYSCALL_ADDR_vgetcpu, %rax
  1264. callq *%rax
  1265. 1:
  1266. diff --git a/LibOS/glibc-2.17/sysdeps/unix/sysv/linux/x86_64/setcontext.S b/LibOS/glibc-2.17/sysdeps/unix/sysv/linux/x86_64/setcontext.S
  1267. index adcb243..0d662e3 100644
  1268. --- a/LibOS/glibc-2.17/sysdeps/unix/sysv/linux/x86_64/setcontext.S
  1269. +++ b/LibOS/glibc-2.17/sysdeps/unix/sysv/linux/x86_64/setcontext.S
  1270. @@ -43,7 +43,7 @@ ENTRY(__setcontext)
  1271. movl $SIG_SETMASK, %edi
  1272. movl $_NSIG8,%r10d
  1273. movl $__NR_rt_sigprocmask, %eax
  1274. - syscall
  1275. + SYSCALL
  1276. popq %rdi /* Reload %rdi, adjust stack. */
  1277. cfi_adjust_cfa_offset(-8)
  1278. cmpq $-4095, %rax /* Check %rax for error. */
  1279. diff --git a/LibOS/glibc-2.17/sysdeps/unix/sysv/linux/x86_64/sigaction.c b/LibOS/glibc-2.17/sysdeps/unix/sysv/linux/x86_64/sigaction.c
  1280. index 5a3ad18..9ac8b6e 100644
  1281. --- a/LibOS/glibc-2.17/sysdeps/unix/sysv/linux/x86_64/sigaction.c
  1282. +++ b/LibOS/glibc-2.17/sysdeps/unix/sysv/linux/x86_64/sigaction.c
  1283. @@ -129,7 +129,8 @@ asm \
  1284. " .type __" #name ",@function\n" \
  1285. "__" #name ":\n" \
  1286. " movq $" #syscall ", %rax\n" \
  1287. - " syscall\n" \
  1288. + " movq syscalldb@GOTPCREL(%rip), %rbx\n" \
  1289. + " call *%rbx\n" \
  1290. ".LEND_" #name ":\n" \
  1291. ".section .eh_frame,\"a\",@progbits\n" \
  1292. ".LSTARTFRAME_" #name ":\n" \
  1293. diff --git a/LibOS/glibc-2.17/sysdeps/unix/sysv/linux/x86_64/swapcontext.S b/LibOS/glibc-2.17/sysdeps/unix/sysv/linux/x86_64/swapcontext.S
  1294. index 0d04a01..e8483db 100644
  1295. --- a/LibOS/glibc-2.17/sysdeps/unix/sysv/linux/x86_64/swapcontext.S
  1296. +++ b/LibOS/glibc-2.17/sysdeps/unix/sysv/linux/x86_64/swapcontext.S
  1297. @@ -75,7 +75,7 @@ ENTRY(__swapcontext)
  1298. movl $SIG_SETMASK, %edi
  1299. movl $_NSIG8,%r10d
  1300. movl $__NR_rt_sigprocmask, %eax
  1301. - syscall
  1302. + SYSCALL
  1303. cmpq $-4095, %rax /* Check %rax for error. */
  1304. jae SYSCALL_ERROR_LABEL /* Jump to error handler if error. */
  1305. diff --git a/LibOS/glibc-2.17/sysdeps/unix/sysv/linux/x86_64/syscall.S b/LibOS/glibc-2.17/sysdeps/unix/sysv/linux/x86_64/syscall.S
  1306. index 87dfd8c..c144b42 100644
  1307. --- a/LibOS/glibc-2.17/sysdeps/unix/sysv/linux/x86_64/syscall.S
  1308. +++ b/LibOS/glibc-2.17/sysdeps/unix/sysv/linux/x86_64/syscall.S
  1309. @@ -34,7 +34,7 @@ ENTRY (syscall)
  1310. movq %r8, %r10
  1311. movq %r9, %r8
  1312. movq 8(%rsp),%r9 /* arg6 is on the stack. */
  1313. - syscall /* Do the system call. */
  1314. + SYSCALL /* Do the system call. */
  1315. cmpq $-4095, %rax /* Check %rax for error. */
  1316. jae SYSCALL_ERROR_LABEL /* Jump to error handler if error. */
  1317. ret /* Return to caller. */
  1318. diff --git a/LibOS/glibc-2.17/sysdeps/unix/sysv/linux/x86_64/sysdep.h b/LibOS/glibc-2.17/sysdeps/unix/sysv/linux/x86_64/sysdep.h
  1319. index 5323104..d466181 100644
  1320. --- a/LibOS/glibc-2.17/sysdeps/unix/sysv/linux/x86_64/sysdep.h
  1321. +++ b/LibOS/glibc-2.17/sysdeps/unix/sysv/linux/x86_64/sysdep.h
  1322. @@ -23,6 +23,7 @@
  1323. #include <bp-sym.h>
  1324. #include <bp-asm.h>
  1325. #include <tls.h>
  1326. +#include "syscalldb.h"
  1327. #ifdef IS_IN_rtld
  1328. # include <dl-sysdep.h> /* Defines RTLD_PRIVATE_ERRNO. */
  1329. @@ -174,11 +175,18 @@
  1330. Syscalls of more than 6 arguments are not supported. */
  1331. +# undef SYSCALL
  1332. +# define SYSCALL \
  1333. + pushq %rbx; \
  1334. + movq syscalldb@GOTPCREL(%rip), %rbx; \
  1335. + call *%rbx; \
  1336. + popq %rbx;
  1337. +
  1338. # undef DO_CALL
  1339. # define DO_CALL(syscall_name, args) \
  1340. DOARGS_##args \
  1341. movl $SYS_ify (syscall_name), %eax; \
  1342. - syscall;
  1343. + SYSCALL
  1344. # define DOARGS_0 /* nothing */
  1345. # define DOARGS_1 /* nothing */
  1346. @@ -192,9 +200,20 @@
  1347. /* Define a macro which expands inline into the wrapper code for a system
  1348. call. */
  1349. # undef INLINE_SYSCALL
  1350. -# define INLINE_SYSCALL(name, nr, args...) \
  1351. +# define INLINE_SYSCALL(name, nr_args...) \
  1352. + ({ \
  1353. + unsigned long int resultvar = INTERNAL_SYSCALL (name, , ##nr_args); \
  1354. + if (__builtin_expect (INTERNAL_SYSCALL_ERROR_P (resultvar, ), 0)) \
  1355. + { \
  1356. + __set_errno (INTERNAL_SYSCALL_ERRNO (resultvar, )); \
  1357. + resultvar = (unsigned long int) -1; \
  1358. + } \
  1359. + (long int) resultvar; })
  1360. +
  1361. +# undef INLINE_SYSCALL_ASM
  1362. +# define INLINE_SYSCALL_ASM(name, nr_args...) \
  1363. ({ \
  1364. - unsigned long int resultvar = INTERNAL_SYSCALL (name, , nr, args); \
  1365. + unsigned long int resultvar = INTERNAL_SYSCALL_ASM (name, , ##nr_args); \
  1366. if (__builtin_expect (INTERNAL_SYSCALL_ERROR_P (resultvar, ), 0)) \
  1367. { \
  1368. __set_errno (INTERNAL_SYSCALL_ERRNO (resultvar, )); \
  1369. @@ -206,9 +225,9 @@
  1370. into the wrapper code for a system call. It should be used when size
  1371. of any argument > size of long int. */
  1372. # undef INLINE_SYSCALL_TYPES
  1373. -# define INLINE_SYSCALL_TYPES(name, nr, args...) \
  1374. +# define INLINE_SYSCALL_TYPES(name, nr_args...) \
  1375. ({ \
  1376. - unsigned long int resultvar = INTERNAL_SYSCALL_TYPES (name, , nr, args); \
  1377. + unsigned long int resultvar = INTERNAL_SYSCALL_TYPES (name, , ##nr_args); \
  1378. if (__builtin_expect (INTERNAL_SYSCALL_ERROR_P (resultvar, ), 0)) \
  1379. { \
  1380. __set_errno (INTERNAL_SYSCALL_ERRNO (resultvar, )); \
  1381. @@ -225,13 +244,20 @@
  1382. LOAD_ARGS_##nr (args) \
  1383. LOAD_REGS_##nr \
  1384. asm volatile ( \
  1385. - "syscall\n\t" \
  1386. + "movq syscalldb@GOTPCREL(%%rip), %%rbx\n\t" \
  1387. + "call *%%rbx\n\t" \
  1388. : "=a" (resultvar) \
  1389. - : "0" (name) ASM_ARGS_##nr : "memory", "cc", "r11", "cx"); \
  1390. + : "0" (name) ASM_ARGS_##nr : "memory", "cc", "r11", "cx", "bx"); \
  1391. (long int) resultvar; })
  1392. +# define INTERNAL_SYSCALL_NCS_ASM INTERNAL_SYSCALL_NCS
  1393. +
  1394. # undef INTERNAL_SYSCALL
  1395. -# define INTERNAL_SYSCALL(name, err, nr, args...) \
  1396. - INTERNAL_SYSCALL_NCS (__NR_##name, err, nr, ##args)
  1397. +# define INTERNAL_SYSCALL(name, err, nr_args...) \
  1398. + INTERNAL_SYSCALL_NCS (__NR_##name, err, ##nr_args)
  1399. +
  1400. +# undef INTERNAL_SYSCALL_ASM
  1401. +# define INTERNAL_SYSCALL_ASM(name, err, nr_args...) \
  1402. + INTERNAL_SYSCALL_NCS_ASM (__NR_##name, err, ##nr_args)
  1403. # define INTERNAL_SYSCALL_NCS_TYPES(name, err, nr, args...) \
  1404. ({ \
  1405. @@ -239,9 +265,10 @@
  1406. LOAD_ARGS_TYPES_##nr (args) \
  1407. LOAD_REGS_TYPES_##nr (args) \
  1408. asm volatile ( \
  1409. - "syscall\n\t" \
  1410. + "movq syscalldb@GOTPCREL(%%rip), %%rbx\n\t" \
  1411. + "call *%%rbx\n\t" \
  1412. : "=a" (resultvar) \
  1413. - : "0" (name) ASM_ARGS_##nr : "memory", "cc", "r11", "cx"); \
  1414. + : "0" (name) ASM_ARGS_##nr : "memory", "cc", "r11", "cx", "bx"); \
  1415. (long int) resultvar; })
  1416. # undef INTERNAL_SYSCALL_TYPES
  1417. # define INTERNAL_SYSCALL_TYPES(name, err, nr, args...) \
  1418. @@ -254,6 +281,7 @@
  1419. # undef INTERNAL_SYSCALL_ERRNO
  1420. # define INTERNAL_SYSCALL_ERRNO(val, err) (-(val))
  1421. +# if 0 /* for Graphene, never do vsyscall */
  1422. # ifdef SHARED
  1423. # define INLINE_VSYSCALL(name, nr, args...) \
  1424. ({ \
  1425. @@ -302,12 +330,13 @@
  1426. v_ret; \
  1427. })
  1428. -# else
  1429. -# define INLINE_VSYSCALL(name, nr, args...) \
  1430. - INLINE_SYSCALL (name, nr, ##args)
  1431. -# define INTERNAL_VSYSCALL(name, err, nr, args...) \
  1432. - INTERNAL_SYSCALL (name, err, nr, ##args)
  1433. # endif
  1434. +# endif
  1435. +
  1436. +# define INLINE_VSYSCALL(name, nr_args...) \
  1437. + INLINE_SYSCALL (name, ##nr_args)
  1438. +# define INTERNAL_VSYSCALL(name, err, nr_args...) \
  1439. + INTERNAL_SYSCALL (name, err, ##nr_args)
  1440. # define LOAD_ARGS_0()
  1441. # define LOAD_REGS_0
  1442. diff --git a/LibOS/glibc-2.17/sysdeps/unix/sysv/linux/x86_64/time.c b/LibOS/glibc-2.17/sysdeps/unix/sysv/linux/x86_64/time.c
  1443. deleted file mode 100644
  1444. index 65703ca..0000000
  1445. --- a/LibOS/glibc-2.17/sysdeps/unix/sysv/linux/x86_64/time.c
  1446. +++ /dev/null
  1447. @@ -1,60 +0,0 @@
  1448. -/* Copyright (C) 2001,02,2003,2011 Free Software Foundation, Inc.
  1449. - This file is part of the GNU C Library.
  1450. -
  1451. - The GNU C Library is free software; you can redistribute it and/or
  1452. - modify it under the terms of the GNU Lesser General Public
  1453. - License as published by the Free Software Foundation; either
  1454. - version 2.1 of the License, or (at your option) any later version.
  1455. -
  1456. - The GNU C Library is distributed in the hope that it will be useful,
  1457. - but WITHOUT ANY WARRANTY; without even the implied warranty of
  1458. - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  1459. - Lesser General Public License for more details.
  1460. -
  1461. - You should have received a copy of the GNU Lesser General Public
  1462. - License along with the GNU C Library; if not, see
  1463. - <http://www.gnu.org/licenses/>. */
  1464. -
  1465. -#ifdef SHARED
  1466. -/* Redefine time so that the compiler won't complain about the type
  1467. - mismatch with the IFUNC selector in strong_alias, below. */
  1468. -#undef time
  1469. -#define time __redirect_time
  1470. -#include <time.h>
  1471. -
  1472. -#include <dl-vdso.h>
  1473. -
  1474. -#define VSYSCALL_ADDR_vtime 0xffffffffff600400
  1475. -
  1476. -/* Avoid DWARF definition DIE on ifunc symbol so that GDB can handle
  1477. - ifunc symbol properly. */
  1478. -extern __typeof (__redirect_time) __libc_time;
  1479. -void *time_ifunc (void) __asm__ ("__libc_time");
  1480. -
  1481. -void *
  1482. -time_ifunc (void)
  1483. -{
  1484. - PREPARE_VERSION (linux26, "LINUX_2.6", 61765110);
  1485. -
  1486. - /* If the vDSO is not available we fall back on the old vsyscall. */
  1487. - return _dl_vdso_vsym ("__vdso_time", &linux26) ?: (void *) VSYSCALL_ADDR_vtime;
  1488. -}
  1489. -__asm (".type __libc_time, %gnu_indirect_function");
  1490. -
  1491. -#undef time
  1492. -strong_alias (__libc_time, time)
  1493. -libc_hidden_ver (__libc_time, time)
  1494. -
  1495. -#else
  1496. -
  1497. -# include <time.h>
  1498. -# include <sysdep.h>
  1499. -
  1500. -time_t
  1501. -time (time_t *t)
  1502. -{
  1503. - INTERNAL_SYSCALL_DECL (err);
  1504. - return INTERNAL_SYSCALL (time, err, 1, t);
  1505. -}
  1506. -
  1507. -#endif
  1508. diff --git a/LibOS/glibc-2.17/sysdeps/unix/sysv/linux/x86_64/vfork.S b/LibOS/glibc-2.17/sysdeps/unix/sysv/linux/x86_64/vfork.S
  1509. index c28087d..ea4ff9f 100644
  1510. --- a/LibOS/glibc-2.17/sysdeps/unix/sysv/linux/x86_64/vfork.S
  1511. +++ b/LibOS/glibc-2.17/sysdeps/unix/sysv/linux/x86_64/vfork.S
  1512. @@ -38,7 +38,7 @@ ENTRY (__vfork)
  1513. /* Stuff the syscall number in RAX and enter into the kernel. */
  1514. movl $SYS_ify (vfork), %eax
  1515. - syscall
  1516. + SYSCALL
  1517. /* Push back the return PC. */
  1518. pushq %rdi
  1519. diff --git a/LibOS/glibc-2.17/sysdeps/x86_64/dl-machine.h b/LibOS/glibc-2.17/sysdeps/x86_64/dl-machine.h
  1520. index d2654aa..9bd840f 100644
  1521. --- a/LibOS/glibc-2.17/sysdeps/x86_64/dl-machine.h
  1522. +++ b/LibOS/glibc-2.17/sysdeps/x86_64/dl-machine.h
  1523. @@ -511,7 +511,8 @@ elf_machine_lazy_rel (struct link_map *map,
  1524. value = ((ElfW(Addr) (*) (void)) value) ();
  1525. *reloc_addr = value;
  1526. }
  1527. - else
  1528. + /* for graphene, get around R_X86_64_NONE */
  1529. + else if (__builtin_expect (r_type != R_X86_64_NONE, 1))
  1530. _dl_reloc_bad_type (map, r_type, 1);
  1531. }