sanitizer_common_syscalls.inc 83 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180
  1. //===-- sanitizer_common_syscalls.inc ---------------------------*- C++ -*-===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. //
  9. // Common syscalls handlers for tools like AddressSanitizer,
  10. // ThreadSanitizer, MemorySanitizer, etc.
  11. //
  12. // This file should be included into the tool's interceptor file,
  13. // which has to define it's own macros:
  14. // COMMON_SYSCALL_PRE_READ_RANGE
  15. // Called in prehook for regions that will be read by the kernel and
  16. // must be initialized.
  17. // COMMON_SYSCALL_PRE_WRITE_RANGE
  18. // Called in prehook for regions that will be written to by the kernel
  19. // and must be addressable. The actual write range may be smaller than
  20. // reported in the prehook. See POST_WRITE_RANGE.
  21. // COMMON_SYSCALL_POST_READ_RANGE
  22. // Called in posthook for regions that were read by the kernel. Does
  23. // not make much sense.
  24. // COMMON_SYSCALL_POST_WRITE_RANGE
  25. // Called in posthook for regions that were written to by the kernel
  26. // and are now initialized.
  27. // COMMON_SYSCALL_ACQUIRE(addr)
  28. // Acquire memory visibility from addr.
  29. // COMMON_SYSCALL_RELEASE(addr)
  30. // Release memory visibility to addr.
  31. // COMMON_SYSCALL_FD_CLOSE(fd)
  32. // Called before closing file descriptor fd.
  33. // COMMON_SYSCALL_FD_ACQUIRE(fd)
  34. // Acquire memory visibility from fd.
  35. // COMMON_SYSCALL_FD_RELEASE(fd)
  36. // Release memory visibility to fd.
  37. // COMMON_SYSCALL_PRE_FORK()
  38. // Called before fork syscall.
  39. // COMMON_SYSCALL_POST_FORK(long res)
  40. // Called after fork syscall.
  41. //===----------------------------------------------------------------------===//
  42. #include "sanitizer_platform.h"
  43. #if SANITIZER_LINUX
  44. # include "sanitizer_libc.h"
  45. # define PRE_SYSCALL(name) \
  46. SANITIZER_INTERFACE_ATTRIBUTE void __sanitizer_syscall_pre_impl_##name
  47. # define PRE_READ(p, s) COMMON_SYSCALL_PRE_READ_RANGE(p, s)
  48. # define PRE_WRITE(p, s) COMMON_SYSCALL_PRE_WRITE_RANGE(p, s)
  49. # define POST_SYSCALL(name) \
  50. SANITIZER_INTERFACE_ATTRIBUTE void __sanitizer_syscall_post_impl_##name
  51. # define POST_READ(p, s) COMMON_SYSCALL_POST_READ_RANGE(p, s)
  52. # define POST_WRITE(p, s) COMMON_SYSCALL_POST_WRITE_RANGE(p, s)
  53. # ifndef COMMON_SYSCALL_ACQUIRE
  54. # define COMMON_SYSCALL_ACQUIRE(addr) ((void)(addr))
  55. # endif
  56. # ifndef COMMON_SYSCALL_RELEASE
  57. # define COMMON_SYSCALL_RELEASE(addr) ((void)(addr))
  58. # endif
  59. # ifndef COMMON_SYSCALL_FD_CLOSE
  60. # define COMMON_SYSCALL_FD_CLOSE(fd) ((void)(fd))
  61. # endif
  62. # ifndef COMMON_SYSCALL_FD_ACQUIRE
  63. # define COMMON_SYSCALL_FD_ACQUIRE(fd) ((void)(fd))
  64. # endif
  65. # ifndef COMMON_SYSCALL_FD_RELEASE
  66. # define COMMON_SYSCALL_FD_RELEASE(fd) ((void)(fd))
  67. # endif
  68. # ifndef COMMON_SYSCALL_PRE_FORK
  69. # define COMMON_SYSCALL_PRE_FORK() \
  70. {}
  71. # endif
  72. # ifndef COMMON_SYSCALL_POST_FORK
  73. # define COMMON_SYSCALL_POST_FORK(res) \
  74. {}
  75. # endif
  76. // FIXME: do some kind of PRE_READ for all syscall arguments (int(s) and such).
  77. extern "C" {
  78. struct sanitizer_kernel_iovec {
  79. void *iov_base;
  80. unsigned long iov_len;
  81. };
  82. struct sanitizer_kernel_msghdr {
  83. void *msg_name;
  84. int msg_namelen;
  85. struct sanitizer_kernel_iovec *msg_iov;
  86. unsigned long msg_iovlen;
  87. void *msg_control;
  88. unsigned long msg_controllen;
  89. unsigned msg_flags;
  90. };
  91. struct sanitizer_kernel_mmsghdr {
  92. struct sanitizer_kernel_msghdr msg_hdr;
  93. unsigned msg_len;
  94. };
  95. struct sanitizer_kernel_timespec {
  96. long tv_sec;
  97. long tv_nsec;
  98. };
  99. struct sanitizer_kernel_timeval {
  100. long tv_sec;
  101. long tv_usec;
  102. };
  103. struct sanitizer_kernel_rusage {
  104. struct sanitizer_kernel_timeval ru_timeval[2];
  105. long ru_long[14];
  106. };
  107. struct sanitizer_kernel_sockaddr {
  108. unsigned short sa_family;
  109. char sa_data[14];
  110. };
  111. // Real sigset size is always passed as a syscall argument.
  112. // Declare it "void" to catch sizeof(kernel_sigset_t).
  113. typedef void kernel_sigset_t;
  114. static void kernel_write_iovec(const __sanitizer_iovec *iovec, SIZE_T iovlen,
  115. SIZE_T maxlen) {
  116. for (SIZE_T i = 0; i < iovlen && maxlen; ++i) {
  117. SSIZE_T sz = Min(iovec[i].iov_len, maxlen);
  118. POST_WRITE(iovec[i].iov_base, sz);
  119. maxlen -= sz;
  120. }
  121. }
  122. // This functions uses POST_READ, because it needs to run after syscall to know
  123. // the real read range.
  124. static void kernel_read_iovec(const __sanitizer_iovec *iovec, SIZE_T iovlen,
  125. SIZE_T maxlen) {
  126. POST_READ(iovec, sizeof(*iovec) * iovlen);
  127. for (SIZE_T i = 0; i < iovlen && maxlen; ++i) {
  128. SSIZE_T sz = Min(iovec[i].iov_len, maxlen);
  129. POST_READ(iovec[i].iov_base, sz);
  130. maxlen -= sz;
  131. }
  132. }
  133. PRE_SYSCALL(recvmsg)(long sockfd, sanitizer_kernel_msghdr *msg, long flags) {
  134. PRE_READ(msg, sizeof(*msg));
  135. }
  136. POST_SYSCALL(recvmsg)
  137. (long res, long sockfd, sanitizer_kernel_msghdr *msg, long flags) {
  138. if (res >= 0) {
  139. if (msg) {
  140. for (unsigned long i = 0; i < msg->msg_iovlen; ++i) {
  141. POST_WRITE(msg->msg_iov[i].iov_base, msg->msg_iov[i].iov_len);
  142. }
  143. POST_WRITE(msg->msg_control, msg->msg_controllen);
  144. }
  145. }
  146. }
  147. PRE_SYSCALL(recvmmsg)
  148. (long fd, sanitizer_kernel_mmsghdr *msg, long vlen, long flags, void *timeout) {
  149. PRE_READ(msg, vlen * sizeof(*msg));
  150. }
  151. POST_SYSCALL(recvmmsg)
  152. (long res, long fd, sanitizer_kernel_mmsghdr *msg, long vlen, long flags,
  153. void *timeout) {
  154. if (res >= 0) {
  155. if (msg) {
  156. for (unsigned long i = 0; i < msg->msg_hdr.msg_iovlen; ++i) {
  157. POST_WRITE(msg->msg_hdr.msg_iov[i].iov_base,
  158. msg->msg_hdr.msg_iov[i].iov_len);
  159. }
  160. POST_WRITE(msg->msg_hdr.msg_control, msg->msg_hdr.msg_controllen);
  161. POST_WRITE(&msg->msg_len, sizeof(msg->msg_len));
  162. }
  163. if (timeout)
  164. POST_WRITE(timeout, struct_timespec_sz);
  165. }
  166. }
  167. PRE_SYSCALL(read)(long fd, void *buf, uptr count) {
  168. if (buf) {
  169. PRE_WRITE(buf, count);
  170. }
  171. }
  172. POST_SYSCALL(read)(long res, long fd, void *buf, uptr count) {
  173. if (res > 0 && buf) {
  174. POST_WRITE(buf, res);
  175. }
  176. }
  177. PRE_SYSCALL(time)(void *tloc) {}
  178. POST_SYSCALL(time)(long res, void *tloc) {
  179. if (res >= 0) {
  180. if (tloc)
  181. POST_WRITE(tloc, sizeof(long));
  182. }
  183. }
  184. PRE_SYSCALL(stime)(void *tptr) {}
  185. POST_SYSCALL(stime)(long res, void *tptr) {
  186. if (res >= 0) {
  187. if (tptr)
  188. POST_WRITE(tptr, sizeof(long));
  189. }
  190. }
  191. PRE_SYSCALL(gettimeofday)(void *tv, void *tz) {}
  192. POST_SYSCALL(gettimeofday)(long res, void *tv, void *tz) {
  193. if (res >= 0) {
  194. if (tv)
  195. POST_WRITE(tv, timeval_sz);
  196. if (tz)
  197. POST_WRITE(tz, struct_timezone_sz);
  198. }
  199. }
  200. PRE_SYSCALL(settimeofday)(void *tv, void *tz) {}
  201. POST_SYSCALL(settimeofday)(long res, void *tv, void *tz) {
  202. if (res >= 0) {
  203. if (tv)
  204. POST_WRITE(tv, timeval_sz);
  205. if (tz)
  206. POST_WRITE(tz, struct_timezone_sz);
  207. }
  208. }
  209. # if !SANITIZER_ANDROID
  210. PRE_SYSCALL(adjtimex)(void *txc_p) {}
  211. POST_SYSCALL(adjtimex)(long res, void *txc_p) {
  212. if (res >= 0) {
  213. if (txc_p)
  214. POST_WRITE(txc_p, struct_timex_sz);
  215. }
  216. }
  217. # endif
  218. PRE_SYSCALL(times)(void *tbuf) {}
  219. POST_SYSCALL(times)(long res, void *tbuf) {
  220. if (res >= 0) {
  221. if (tbuf)
  222. POST_WRITE(tbuf, struct_tms_sz);
  223. }
  224. }
  225. PRE_SYSCALL(gettid)() {}
  226. POST_SYSCALL(gettid)(long res) {}
  227. PRE_SYSCALL(nanosleep)(void *rqtp, void *rmtp) {}
  228. POST_SYSCALL(nanosleep)(long res, void *rqtp, void *rmtp) {
  229. if (res >= 0) {
  230. if (rqtp)
  231. POST_WRITE(rqtp, struct_timespec_sz);
  232. if (rmtp)
  233. POST_WRITE(rmtp, struct_timespec_sz);
  234. }
  235. }
  236. PRE_SYSCALL(alarm)(long seconds) {}
  237. POST_SYSCALL(alarm)(long res, long seconds) {}
  238. PRE_SYSCALL(getpid)() {}
  239. POST_SYSCALL(getpid)(long res) {}
  240. PRE_SYSCALL(getppid)() {}
  241. POST_SYSCALL(getppid)(long res) {}
  242. PRE_SYSCALL(getuid)() {}
  243. POST_SYSCALL(getuid)(long res) {}
  244. PRE_SYSCALL(geteuid)() {}
  245. POST_SYSCALL(geteuid)(long res) {}
  246. PRE_SYSCALL(getgid)() {}
  247. POST_SYSCALL(getgid)(long res) {}
  248. PRE_SYSCALL(getegid)() {}
  249. POST_SYSCALL(getegid)(long res) {}
  250. PRE_SYSCALL(getresuid)(void *ruid, void *euid, void *suid) {}
  251. POST_SYSCALL(getresuid)(long res, void *ruid, void *euid, void *suid) {
  252. if (res >= 0) {
  253. if (ruid)
  254. POST_WRITE(ruid, sizeof(unsigned));
  255. if (euid)
  256. POST_WRITE(euid, sizeof(unsigned));
  257. if (suid)
  258. POST_WRITE(suid, sizeof(unsigned));
  259. }
  260. }
  261. PRE_SYSCALL(getresgid)(void *rgid, void *egid, void *sgid) {}
  262. POST_SYSCALL(getresgid)(long res, void *rgid, void *egid, void *sgid) {
  263. if (res >= 0) {
  264. if (rgid)
  265. POST_WRITE(rgid, sizeof(unsigned));
  266. if (egid)
  267. POST_WRITE(egid, sizeof(unsigned));
  268. if (sgid)
  269. POST_WRITE(sgid, sizeof(unsigned));
  270. }
  271. }
  272. PRE_SYSCALL(getpgid)(long pid) {}
  273. POST_SYSCALL(getpgid)(long res, long pid) {}
  274. PRE_SYSCALL(getpgrp)() {}
  275. POST_SYSCALL(getpgrp)(long res) {}
  276. PRE_SYSCALL(getsid)(long pid) {}
  277. POST_SYSCALL(getsid)(long res, long pid) {}
  278. PRE_SYSCALL(getgroups)(long gidsetsize, void *grouplist) {}
  279. POST_SYSCALL(getgroups)
  280. (long res, long gidsetsize, __sanitizer___kernel_gid_t *grouplist) {
  281. if (res >= 0) {
  282. if (grouplist)
  283. POST_WRITE(grouplist, res * sizeof(*grouplist));
  284. }
  285. }
  286. PRE_SYSCALL(setregid)(long rgid, long egid) {}
  287. POST_SYSCALL(setregid)(long res, long rgid, long egid) {}
  288. PRE_SYSCALL(setgid)(long gid) {}
  289. POST_SYSCALL(setgid)(long res, long gid) {}
  290. PRE_SYSCALL(setreuid)(long ruid, long euid) {}
  291. POST_SYSCALL(setreuid)(long res, long ruid, long euid) {}
  292. PRE_SYSCALL(setuid)(long uid) {}
  293. POST_SYSCALL(setuid)(long res, long uid) {}
  294. PRE_SYSCALL(setresuid)(long ruid, long euid, long suid) {}
  295. POST_SYSCALL(setresuid)(long res, long ruid, long euid, long suid) {}
  296. PRE_SYSCALL(setresgid)(long rgid, long egid, long sgid) {}
  297. POST_SYSCALL(setresgid)(long res, long rgid, long egid, long sgid) {}
  298. PRE_SYSCALL(setfsuid)(long uid) {}
  299. POST_SYSCALL(setfsuid)(long res, long uid) {}
  300. PRE_SYSCALL(setfsgid)(long gid) {}
  301. POST_SYSCALL(setfsgid)(long res, long gid) {}
  302. PRE_SYSCALL(setpgid)(long pid, long pgid) {}
  303. POST_SYSCALL(setpgid)(long res, long pid, long pgid) {}
  304. PRE_SYSCALL(setsid)() {}
  305. POST_SYSCALL(setsid)(long res) {}
  306. PRE_SYSCALL(setgroups)(long gidsetsize, __sanitizer___kernel_gid_t *grouplist) {
  307. if (grouplist)
  308. POST_WRITE(grouplist, gidsetsize * sizeof(*grouplist));
  309. }
  310. POST_SYSCALL(setgroups)
  311. (long res, long gidsetsize, __sanitizer___kernel_gid_t *grouplist) {}
  312. PRE_SYSCALL(acct)(const void *name) {
  313. if (name)
  314. PRE_READ(name, __sanitizer::internal_strlen((const char *)name) + 1);
  315. }
  316. POST_SYSCALL(acct)(long res, const void *name) {}
  317. PRE_SYSCALL(capget)(void *header, void *dataptr) {
  318. if (header)
  319. PRE_READ(header, __user_cap_header_struct_sz);
  320. }
  321. POST_SYSCALL(capget)(long res, void *header, void *dataptr) {
  322. if (res >= 0)
  323. if (dataptr)
  324. POST_WRITE(dataptr, __user_cap_data_struct_sz);
  325. }
  326. PRE_SYSCALL(capset)(void *header, const void *data) {
  327. if (header)
  328. PRE_READ(header, __user_cap_header_struct_sz);
  329. if (data)
  330. PRE_READ(data, __user_cap_data_struct_sz);
  331. }
  332. POST_SYSCALL(capset)(long res, void *header, const void *data) {}
  333. PRE_SYSCALL(personality)(long personality) {}
  334. POST_SYSCALL(personality)(long res, long personality) {}
  335. PRE_SYSCALL(sigpending)(void *set) {}
  336. POST_SYSCALL(sigpending)(long res, void *set) {
  337. if (res >= 0) {
  338. if (set)
  339. POST_WRITE(set, old_sigset_t_sz);
  340. }
  341. }
  342. PRE_SYSCALL(sigprocmask)(long how, void *set, void *oset) {}
  343. POST_SYSCALL(sigprocmask)(long res, long how, void *set, void *oset) {
  344. if (res >= 0) {
  345. if (set)
  346. POST_WRITE(set, old_sigset_t_sz);
  347. if (oset)
  348. POST_WRITE(oset, old_sigset_t_sz);
  349. }
  350. }
  351. PRE_SYSCALL(getitimer)(long which, void *value) {}
  352. POST_SYSCALL(getitimer)(long res, long which, void *value) {
  353. if (res >= 0) {
  354. if (value)
  355. POST_WRITE(value, struct_itimerval_sz);
  356. }
  357. }
  358. PRE_SYSCALL(setitimer)(long which, void *value, void *ovalue) {}
  359. POST_SYSCALL(setitimer)(long res, long which, void *value, void *ovalue) {
  360. if (res >= 0) {
  361. if (value)
  362. POST_WRITE(value, struct_itimerval_sz);
  363. if (ovalue)
  364. POST_WRITE(ovalue, struct_itimerval_sz);
  365. }
  366. }
  367. PRE_SYSCALL(timer_create)
  368. (long which_clock, void *timer_event_spec, void *created_timer_id) {}
  369. POST_SYSCALL(timer_create)
  370. (long res, long which_clock, void *timer_event_spec, void *created_timer_id) {
  371. if (res >= 0) {
  372. if (timer_event_spec)
  373. POST_WRITE(timer_event_spec, struct_sigevent_sz);
  374. if (created_timer_id)
  375. POST_WRITE(created_timer_id, sizeof(long));
  376. }
  377. }
  378. PRE_SYSCALL(timer_gettime)(long timer_id, void *setting) {}
  379. POST_SYSCALL(timer_gettime)(long res, long timer_id, void *setting) {
  380. if (res >= 0) {
  381. if (setting)
  382. POST_WRITE(setting, struct_itimerspec_sz);
  383. }
  384. }
  385. PRE_SYSCALL(timer_getoverrun)(long timer_id) {}
  386. POST_SYSCALL(timer_getoverrun)(long res, long timer_id) {}
  387. PRE_SYSCALL(timer_settime)
  388. (long timer_id, long flags, const void *new_setting, void *old_setting) {
  389. if (new_setting)
  390. PRE_READ(new_setting, struct_itimerspec_sz);
  391. }
  392. POST_SYSCALL(timer_settime)
  393. (long res, long timer_id, long flags, const void *new_setting,
  394. void *old_setting) {
  395. if (res >= 0) {
  396. if (old_setting)
  397. POST_WRITE(old_setting, struct_itimerspec_sz);
  398. }
  399. }
  400. PRE_SYSCALL(timer_delete)(long timer_id) {}
  401. POST_SYSCALL(timer_delete)(long res, long timer_id) {}
  402. PRE_SYSCALL(clock_settime)(long which_clock, const void *tp) {
  403. if (tp)
  404. PRE_READ(tp, struct_timespec_sz);
  405. }
  406. POST_SYSCALL(clock_settime)(long res, long which_clock, const void *tp) {}
  407. PRE_SYSCALL(clock_gettime)(long which_clock, void *tp) {}
  408. POST_SYSCALL(clock_gettime)(long res, long which_clock, void *tp) {
  409. if (res >= 0) {
  410. if (tp)
  411. POST_WRITE(tp, struct_timespec_sz);
  412. }
  413. }
  414. # if !SANITIZER_ANDROID
  415. PRE_SYSCALL(clock_adjtime)(long which_clock, void *tx) {}
  416. POST_SYSCALL(clock_adjtime)(long res, long which_clock, void *tx) {
  417. if (res >= 0) {
  418. if (tx)
  419. POST_WRITE(tx, struct_timex_sz);
  420. }
  421. }
  422. # endif
  423. PRE_SYSCALL(clock_getres)(long which_clock, void *tp) {}
  424. POST_SYSCALL(clock_getres)(long res, long which_clock, void *tp) {
  425. if (res >= 0) {
  426. if (tp)
  427. POST_WRITE(tp, struct_timespec_sz);
  428. }
  429. }
  430. PRE_SYSCALL(clock_nanosleep)
  431. (long which_clock, long flags, const void *rqtp, void *rmtp) {
  432. if (rqtp)
  433. PRE_READ(rqtp, struct_timespec_sz);
  434. }
  435. POST_SYSCALL(clock_nanosleep)
  436. (long res, long which_clock, long flags, const void *rqtp, void *rmtp) {
  437. if (res >= 0) {
  438. if (rmtp)
  439. POST_WRITE(rmtp, struct_timespec_sz);
  440. }
  441. }
  442. PRE_SYSCALL(nice)(long increment) {}
  443. POST_SYSCALL(nice)(long res, long increment) {}
  444. PRE_SYSCALL(sched_setscheduler)(long pid, long policy, void *param) {}
  445. POST_SYSCALL(sched_setscheduler)(long res, long pid, long policy, void *param) {
  446. if (res >= 0) {
  447. if (param)
  448. POST_WRITE(param, struct_sched_param_sz);
  449. }
  450. }
  451. PRE_SYSCALL(sched_setparam)(long pid, void *param) {
  452. if (param)
  453. PRE_READ(param, struct_sched_param_sz);
  454. }
  455. POST_SYSCALL(sched_setparam)(long res, long pid, void *param) {}
  456. PRE_SYSCALL(sched_getscheduler)(long pid) {}
  457. POST_SYSCALL(sched_getscheduler)(long res, long pid) {}
  458. PRE_SYSCALL(sched_getparam)(long pid, void *param) {}
  459. POST_SYSCALL(sched_getparam)(long res, long pid, void *param) {
  460. if (res >= 0) {
  461. if (param)
  462. POST_WRITE(param, struct_sched_param_sz);
  463. }
  464. }
  465. PRE_SYSCALL(sched_setaffinity)(long pid, long len, void *user_mask_ptr) {
  466. if (user_mask_ptr)
  467. PRE_READ(user_mask_ptr, len);
  468. }
  469. POST_SYSCALL(sched_setaffinity)
  470. (long res, long pid, long len, void *user_mask_ptr) {}
  471. PRE_SYSCALL(sched_getaffinity)(long pid, long len, void *user_mask_ptr) {}
  472. POST_SYSCALL(sched_getaffinity)
  473. (long res, long pid, long len, void *user_mask_ptr) {
  474. if (res >= 0) {
  475. if (user_mask_ptr)
  476. POST_WRITE(user_mask_ptr, len);
  477. }
  478. }
  479. PRE_SYSCALL(sched_yield)() {}
  480. POST_SYSCALL(sched_yield)(long res) {}
  481. PRE_SYSCALL(sched_get_priority_max)(long policy) {}
  482. POST_SYSCALL(sched_get_priority_max)(long res, long policy) {}
  483. PRE_SYSCALL(sched_get_priority_min)(long policy) {}
  484. POST_SYSCALL(sched_get_priority_min)(long res, long policy) {}
  485. PRE_SYSCALL(sched_rr_get_interval)(long pid, void *interval) {}
  486. POST_SYSCALL(sched_rr_get_interval)(long res, long pid, void *interval) {
  487. if (res >= 0) {
  488. if (interval)
  489. POST_WRITE(interval, struct_timespec_sz);
  490. }
  491. }
  492. PRE_SYSCALL(setpriority)(long which, long who, long niceval) {}
  493. POST_SYSCALL(setpriority)(long res, long which, long who, long niceval) {}
  494. PRE_SYSCALL(getpriority)(long which, long who) {}
  495. POST_SYSCALL(getpriority)(long res, long which, long who) {}
  496. PRE_SYSCALL(shutdown)(long arg0, long arg1) {}
  497. POST_SYSCALL(shutdown)(long res, long arg0, long arg1) {}
  498. PRE_SYSCALL(reboot)(long magic1, long magic2, long cmd, void *arg) {}
  499. POST_SYSCALL(reboot)(long res, long magic1, long magic2, long cmd, void *arg) {}
  500. PRE_SYSCALL(restart_syscall)() {}
  501. POST_SYSCALL(restart_syscall)(long res) {}
  502. PRE_SYSCALL(kexec_load)
  503. (long entry, long nr_segments, void *segments, long flags) {}
  504. POST_SYSCALL(kexec_load)
  505. (long res, long entry, long nr_segments, void *segments, long flags) {
  506. if (res >= 0) {
  507. if (segments)
  508. POST_WRITE(segments, struct_kexec_segment_sz);
  509. }
  510. }
  511. PRE_SYSCALL(exit)(long error_code) {}
  512. POST_SYSCALL(exit)(long res, long error_code) {}
  513. PRE_SYSCALL(exit_group)(long error_code) {}
  514. POST_SYSCALL(exit_group)(long res, long error_code) {}
  515. PRE_SYSCALL(wait4)(long pid, void *stat_addr, long options, void *ru) {}
  516. POST_SYSCALL(wait4)
  517. (long res, long pid, void *stat_addr, long options, void *ru) {
  518. if (res >= 0) {
  519. if (stat_addr)
  520. POST_WRITE(stat_addr, sizeof(int));
  521. if (ru)
  522. POST_WRITE(ru, struct_rusage_sz);
  523. }
  524. }
  525. PRE_SYSCALL(waitid)
  526. (long which, long pid, void *infop, long options, void *ru) {}
  527. POST_SYSCALL(waitid)
  528. (long res, long which, long pid, void *infop, long options, void *ru) {
  529. if (res >= 0) {
  530. if (infop)
  531. POST_WRITE(infop, siginfo_t_sz);
  532. if (ru)
  533. POST_WRITE(ru, struct_rusage_sz);
  534. }
  535. }
  536. PRE_SYSCALL(waitpid)(long pid, void *stat_addr, long options) {}
  537. POST_SYSCALL(waitpid)(long res, long pid, void *stat_addr, long options) {
  538. if (res >= 0) {
  539. if (stat_addr)
  540. POST_WRITE(stat_addr, sizeof(int));
  541. }
  542. }
  543. PRE_SYSCALL(set_tid_address)(void *tidptr) {}
  544. POST_SYSCALL(set_tid_address)(long res, void *tidptr) {
  545. if (res >= 0) {
  546. if (tidptr)
  547. POST_WRITE(tidptr, sizeof(int));
  548. }
  549. }
  550. PRE_SYSCALL(init_module)(void *umod, long len, const void *uargs) {
  551. if (uargs)
  552. PRE_READ(uargs, __sanitizer::internal_strlen((const char *)uargs) + 1);
  553. }
  554. POST_SYSCALL(init_module)(long res, void *umod, long len, const void *uargs) {}
  555. PRE_SYSCALL(delete_module)(const void *name_user, long flags) {
  556. if (name_user)
  557. PRE_READ(name_user,
  558. __sanitizer::internal_strlen((const char *)name_user) + 1);
  559. }
  560. POST_SYSCALL(delete_module)(long res, const void *name_user, long flags) {}
  561. PRE_SYSCALL(rt_sigprocmask)(long how, void *set, void *oset, long sigsetsize) {}
  562. POST_SYSCALL(rt_sigprocmask)
  563. (long res, long how, kernel_sigset_t *set, kernel_sigset_t *oset,
  564. long sigsetsize) {
  565. if (res >= 0) {
  566. if (set)
  567. POST_WRITE(set, sigsetsize);
  568. if (oset)
  569. POST_WRITE(oset, sigsetsize);
  570. }
  571. }
  572. PRE_SYSCALL(rt_sigpending)(void *set, long sigsetsize) {}
  573. POST_SYSCALL(rt_sigpending)(long res, kernel_sigset_t *set, long sigsetsize) {
  574. if (res >= 0) {
  575. if (set)
  576. POST_WRITE(set, sigsetsize);
  577. }
  578. }
  579. PRE_SYSCALL(rt_sigtimedwait)
  580. (const kernel_sigset_t *uthese, void *uinfo, const void *uts, long sigsetsize) {
  581. if (uthese)
  582. PRE_READ(uthese, sigsetsize);
  583. if (uts)
  584. PRE_READ(uts, struct_timespec_sz);
  585. }
  586. POST_SYSCALL(rt_sigtimedwait)
  587. (long res, const void *uthese, void *uinfo, const void *uts, long sigsetsize) {
  588. if (res >= 0) {
  589. if (uinfo)
  590. POST_WRITE(uinfo, siginfo_t_sz);
  591. }
  592. }
  593. PRE_SYSCALL(rt_tgsigqueueinfo)(long tgid, long pid, long sig, void *uinfo) {}
  594. POST_SYSCALL(rt_tgsigqueueinfo)
  595. (long res, long tgid, long pid, long sig, void *uinfo) {
  596. if (res >= 0) {
  597. if (uinfo)
  598. POST_WRITE(uinfo, siginfo_t_sz);
  599. }
  600. }
  601. PRE_SYSCALL(kill)(long pid, long sig) {}
  602. POST_SYSCALL(kill)(long res, long pid, long sig) {}
  603. PRE_SYSCALL(tgkill)(long tgid, long pid, long sig) {}
  604. POST_SYSCALL(tgkill)(long res, long tgid, long pid, long sig) {}
  605. PRE_SYSCALL(tkill)(long pid, long sig) {}
  606. POST_SYSCALL(tkill)(long res, long pid, long sig) {}
  607. PRE_SYSCALL(rt_sigqueueinfo)(long pid, long sig, void *uinfo) {}
  608. POST_SYSCALL(rt_sigqueueinfo)(long res, long pid, long sig, void *uinfo) {
  609. if (res >= 0) {
  610. if (uinfo)
  611. POST_WRITE(uinfo, siginfo_t_sz);
  612. }
  613. }
  614. PRE_SYSCALL(sgetmask)() {}
  615. POST_SYSCALL(sgetmask)(long res) {}
  616. PRE_SYSCALL(ssetmask)(long newmask) {}
  617. POST_SYSCALL(ssetmask)(long res, long newmask) {}
  618. PRE_SYSCALL(signal)(long sig, long handler) {}
  619. POST_SYSCALL(signal)(long res, long sig, long handler) {}
  620. PRE_SYSCALL(pause)() {}
  621. POST_SYSCALL(pause)(long res) {}
  622. PRE_SYSCALL(sync)() {}
  623. POST_SYSCALL(sync)(long res) {}
  624. PRE_SYSCALL(fsync)(long fd) {}
  625. POST_SYSCALL(fsync)(long res, long fd) {}
  626. PRE_SYSCALL(fdatasync)(long fd) {}
  627. POST_SYSCALL(fdatasync)(long res, long fd) {}
  628. PRE_SYSCALL(bdflush)(long func, long data) {}
  629. POST_SYSCALL(bdflush)(long res, long func, long data) {}
  630. PRE_SYSCALL(mount)
  631. (void *dev_name, void *dir_name, void *type, long flags, void *data) {}
  632. POST_SYSCALL(mount)
  633. (long res, void *dev_name, void *dir_name, void *type, long flags, void *data) {
  634. if (res >= 0) {
  635. if (dev_name)
  636. POST_WRITE(dev_name,
  637. __sanitizer::internal_strlen((const char *)dev_name) + 1);
  638. if (dir_name)
  639. POST_WRITE(dir_name,
  640. __sanitizer::internal_strlen((const char *)dir_name) + 1);
  641. if (type)
  642. POST_WRITE(type, __sanitizer::internal_strlen((const char *)type) + 1);
  643. }
  644. }
  645. PRE_SYSCALL(umount)(void *name, long flags) {}
  646. POST_SYSCALL(umount)(long res, void *name, long flags) {
  647. if (res >= 0) {
  648. if (name)
  649. POST_WRITE(name, __sanitizer::internal_strlen((const char *)name) + 1);
  650. }
  651. }
  652. PRE_SYSCALL(oldumount)(void *name) {}
  653. POST_SYSCALL(oldumount)(long res, void *name) {
  654. if (res >= 0) {
  655. if (name)
  656. POST_WRITE(name, __sanitizer::internal_strlen((const char *)name) + 1);
  657. }
  658. }
  659. PRE_SYSCALL(truncate)(const void *path, long length) {
  660. if (path)
  661. PRE_READ(path, __sanitizer::internal_strlen((const char *)path) + 1);
  662. }
  663. POST_SYSCALL(truncate)(long res, const void *path, long length) {}
  664. PRE_SYSCALL(ftruncate)(long fd, long length) {}
  665. POST_SYSCALL(ftruncate)(long res, long fd, long length) {}
  666. PRE_SYSCALL(stat)(const void *filename, void *statbuf) {
  667. if (filename)
  668. PRE_READ(filename,
  669. __sanitizer::internal_strlen((const char *)filename) + 1);
  670. }
  671. POST_SYSCALL(stat)(long res, const void *filename, void *statbuf) {
  672. if (res >= 0) {
  673. if (statbuf)
  674. POST_WRITE(statbuf, struct___old_kernel_stat_sz);
  675. }
  676. }
  677. # if !SANITIZER_ANDROID
  678. PRE_SYSCALL(statfs)(const void *path, void *buf) {
  679. if (path)
  680. PRE_READ(path, __sanitizer::internal_strlen((const char *)path) + 1);
  681. }
  682. POST_SYSCALL(statfs)(long res, const void *path, void *buf) {
  683. if (res >= 0) {
  684. if (buf)
  685. POST_WRITE(buf, struct_statfs_sz);
  686. }
  687. }
  688. PRE_SYSCALL(fstatfs)(long fd, void *buf) {}
  689. POST_SYSCALL(fstatfs)(long res, long fd, void *buf) {
  690. if (res >= 0) {
  691. if (buf)
  692. POST_WRITE(buf, struct_statfs_sz);
  693. }
  694. }
  695. # endif // !SANITIZER_ANDROID
  696. # if SANITIZER_GLIBC
  697. PRE_SYSCALL(statfs64)(const void *path, long sz, void *buf) {
  698. if (path)
  699. PRE_READ(path, __sanitizer::internal_strlen((const char *)path) + 1);
  700. }
  701. POST_SYSCALL(statfs64)(long res, const void *path, long sz, void *buf) {
  702. if (res >= 0) {
  703. if (buf)
  704. POST_WRITE(buf, struct_statfs64_sz);
  705. }
  706. }
  707. PRE_SYSCALL(fstatfs64)(long fd, long sz, void *buf) {}
  708. POST_SYSCALL(fstatfs64)(long res, long fd, long sz, void *buf) {
  709. if (res >= 0) {
  710. if (buf)
  711. POST_WRITE(buf, struct_statfs64_sz);
  712. }
  713. }
  714. # endif // SANITIZER_GLIBC
  715. PRE_SYSCALL(lstat)(const void *filename, void *statbuf) {
  716. if (filename)
  717. PRE_READ(filename,
  718. __sanitizer::internal_strlen((const char *)filename) + 1);
  719. }
  720. POST_SYSCALL(lstat)(long res, const void *filename, void *statbuf) {
  721. if (res >= 0) {
  722. if (statbuf)
  723. POST_WRITE(statbuf, struct___old_kernel_stat_sz);
  724. }
  725. }
  726. PRE_SYSCALL(fstat)(long fd, void *statbuf) {}
  727. POST_SYSCALL(fstat)(long res, long fd, void *statbuf) {
  728. if (res >= 0) {
  729. if (statbuf)
  730. POST_WRITE(statbuf, struct___old_kernel_stat_sz);
  731. }
  732. }
  733. PRE_SYSCALL(newstat)(const void *filename, void *statbuf) {
  734. if (filename)
  735. PRE_READ(filename,
  736. __sanitizer::internal_strlen((const char *)filename) + 1);
  737. }
  738. POST_SYSCALL(newstat)(long res, const void *filename, void *statbuf) {
  739. if (res >= 0) {
  740. if (statbuf)
  741. POST_WRITE(statbuf, struct_kernel_stat_sz);
  742. }
  743. }
  744. PRE_SYSCALL(newlstat)(const void *filename, void *statbuf) {
  745. if (filename)
  746. PRE_READ(filename,
  747. __sanitizer::internal_strlen((const char *)filename) + 1);
  748. }
  749. POST_SYSCALL(newlstat)(long res, const void *filename, void *statbuf) {
  750. if (res >= 0) {
  751. if (statbuf)
  752. POST_WRITE(statbuf, struct_kernel_stat_sz);
  753. }
  754. }
  755. PRE_SYSCALL(newfstat)(long fd, void *statbuf) {}
  756. POST_SYSCALL(newfstat)(long res, long fd, void *statbuf) {
  757. if (res >= 0) {
  758. if (statbuf)
  759. POST_WRITE(statbuf, struct_kernel_stat_sz);
  760. }
  761. }
  762. # if SANITIZER_GLIBC
  763. PRE_SYSCALL(ustat)(long dev, void *ubuf) {}
  764. POST_SYSCALL(ustat)(long res, long dev, void *ubuf) {
  765. if (res >= 0) {
  766. if (ubuf)
  767. POST_WRITE(ubuf, struct_ustat_sz);
  768. }
  769. }
  770. # endif // SANITIZER_GLIBC
  771. PRE_SYSCALL(stat64)(const void *filename, void *statbuf) {
  772. if (filename)
  773. PRE_READ(filename,
  774. __sanitizer::internal_strlen((const char *)filename) + 1);
  775. }
  776. POST_SYSCALL(stat64)(long res, const void *filename, void *statbuf) {
  777. if (res >= 0) {
  778. if (statbuf)
  779. POST_WRITE(statbuf, struct_kernel_stat64_sz);
  780. }
  781. }
  782. PRE_SYSCALL(fstat64)(long fd, void *statbuf) {}
  783. POST_SYSCALL(fstat64)(long res, long fd, void *statbuf) {
  784. if (res >= 0) {
  785. if (statbuf)
  786. POST_WRITE(statbuf, struct_kernel_stat64_sz);
  787. }
  788. }
  789. PRE_SYSCALL(lstat64)(const void *filename, void *statbuf) {
  790. if (filename)
  791. PRE_READ(filename,
  792. __sanitizer::internal_strlen((const char *)filename) + 1);
  793. }
  794. POST_SYSCALL(lstat64)(long res, const void *filename, void *statbuf) {
  795. if (res >= 0) {
  796. if (statbuf)
  797. POST_WRITE(statbuf, struct_kernel_stat64_sz);
  798. }
  799. }
  800. PRE_SYSCALL(setxattr)
  801. (const void *path, const void *name, const void *value, long size, long flags) {
  802. if (path)
  803. PRE_READ(path, __sanitizer::internal_strlen((const char *)path) + 1);
  804. if (name)
  805. PRE_READ(name, __sanitizer::internal_strlen((const char *)name) + 1);
  806. if (value)
  807. PRE_READ(value, size);
  808. }
  809. POST_SYSCALL(setxattr)
  810. (long res, const void *path, const void *name, const void *value, long size,
  811. long flags) {}
  812. PRE_SYSCALL(lsetxattr)
  813. (const void *path, const void *name, const void *value, long size, long flags) {
  814. if (path)
  815. PRE_READ(path, __sanitizer::internal_strlen((const char *)path) + 1);
  816. if (name)
  817. PRE_READ(name, __sanitizer::internal_strlen((const char *)name) + 1);
  818. if (value)
  819. PRE_READ(value, size);
  820. }
  821. POST_SYSCALL(lsetxattr)
  822. (long res, const void *path, const void *name, const void *value, long size,
  823. long flags) {}
  824. PRE_SYSCALL(fsetxattr)
  825. (long fd, const void *name, const void *value, long size, long flags) {
  826. if (name)
  827. PRE_READ(name, __sanitizer::internal_strlen((const char *)name) + 1);
  828. if (value)
  829. PRE_READ(value, size);
  830. }
  831. POST_SYSCALL(fsetxattr)
  832. (long res, long fd, const void *name, const void *value, long size,
  833. long flags) {}
  834. PRE_SYSCALL(getxattr)
  835. (const void *path, const void *name, void *value, long size) {
  836. if (path)
  837. PRE_READ(path, __sanitizer::internal_strlen((const char *)path) + 1);
  838. if (name)
  839. PRE_READ(name, __sanitizer::internal_strlen((const char *)name) + 1);
  840. }
  841. POST_SYSCALL(getxattr)
  842. (long res, const void *path, const void *name, void *value, long size) {
  843. if (size && res > 0) {
  844. if (value)
  845. POST_WRITE(value, res);
  846. }
  847. }
  848. PRE_SYSCALL(lgetxattr)
  849. (const void *path, const void *name, void *value, long size) {
  850. if (path)
  851. PRE_READ(path, __sanitizer::internal_strlen((const char *)path) + 1);
  852. if (name)
  853. PRE_READ(name, __sanitizer::internal_strlen((const char *)name) + 1);
  854. }
  855. POST_SYSCALL(lgetxattr)
  856. (long res, const void *path, const void *name, void *value, long size) {
  857. if (size && res > 0) {
  858. if (value)
  859. POST_WRITE(value, res);
  860. }
  861. }
  862. PRE_SYSCALL(fgetxattr)(long fd, const void *name, void *value, long size) {
  863. if (name)
  864. PRE_READ(name, __sanitizer::internal_strlen((const char *)name) + 1);
  865. }
  866. POST_SYSCALL(fgetxattr)
  867. (long res, long fd, const void *name, void *value, long size) {
  868. if (size && res > 0) {
  869. if (value)
  870. POST_WRITE(value, res);
  871. }
  872. }
  873. PRE_SYSCALL(listxattr)(const void *path, void *list, long size) {
  874. if (path)
  875. PRE_READ(path, __sanitizer::internal_strlen((const char *)path) + 1);
  876. }
  877. POST_SYSCALL(listxattr)(long res, const void *path, void *list, long size) {
  878. if (size && res > 0) {
  879. if (list)
  880. POST_WRITE(list, res);
  881. }
  882. }
  883. PRE_SYSCALL(llistxattr)(const void *path, void *list, long size) {
  884. if (path)
  885. PRE_READ(path, __sanitizer::internal_strlen((const char *)path) + 1);
  886. }
  887. POST_SYSCALL(llistxattr)(long res, const void *path, void *list, long size) {
  888. if (size && res > 0) {
  889. if (list)
  890. POST_WRITE(list, res);
  891. }
  892. }
  893. PRE_SYSCALL(flistxattr)(long fd, void *list, long size) {}
  894. POST_SYSCALL(flistxattr)(long res, long fd, void *list, long size) {
  895. if (size && res > 0) {
  896. if (list)
  897. POST_WRITE(list, res);
  898. }
  899. }
  900. PRE_SYSCALL(removexattr)(const void *path, const void *name) {
  901. if (path)
  902. PRE_READ(path, __sanitizer::internal_strlen((const char *)path) + 1);
  903. if (name)
  904. PRE_READ(name, __sanitizer::internal_strlen((const char *)name) + 1);
  905. }
  906. POST_SYSCALL(removexattr)(long res, const void *path, const void *name) {}
  907. PRE_SYSCALL(lremovexattr)(const void *path, const void *name) {
  908. if (path)
  909. PRE_READ(path, __sanitizer::internal_strlen((const char *)path) + 1);
  910. if (name)
  911. PRE_READ(name, __sanitizer::internal_strlen((const char *)name) + 1);
  912. }
  913. POST_SYSCALL(lremovexattr)(long res, const void *path, const void *name) {}
  914. PRE_SYSCALL(fremovexattr)(long fd, const void *name) {
  915. if (name)
  916. PRE_READ(name, __sanitizer::internal_strlen((const char *)name) + 1);
  917. }
  918. POST_SYSCALL(fremovexattr)(long res, long fd, const void *name) {}
  919. PRE_SYSCALL(brk)(long brk) {}
  920. POST_SYSCALL(brk)(long res, long brk) {}
  921. PRE_SYSCALL(mprotect)(long start, long len, long prot) {}
  922. POST_SYSCALL(mprotect)(long res, long start, long len, long prot) {}
  923. PRE_SYSCALL(mremap)
  924. (long addr, long old_len, long new_len, long flags, long new_addr) {}
  925. POST_SYSCALL(mremap)
  926. (long res, long addr, long old_len, long new_len, long flags, long new_addr) {}
  927. PRE_SYSCALL(remap_file_pages)
  928. (long start, long size, long prot, long pgoff, long flags) {}
  929. POST_SYSCALL(remap_file_pages)
  930. (long res, long start, long size, long prot, long pgoff, long flags) {}
  931. PRE_SYSCALL(msync)(long start, long len, long flags) {}
  932. POST_SYSCALL(msync)(long res, long start, long len, long flags) {}
  933. PRE_SYSCALL(munmap)(long addr, long len) {}
  934. POST_SYSCALL(munmap)(long res, long addr, long len) {}
  935. PRE_SYSCALL(mlock)(long start, long len) {}
  936. POST_SYSCALL(mlock)(long res, long start, long len) {}
  937. PRE_SYSCALL(munlock)(long start, long len) {}
  938. POST_SYSCALL(munlock)(long res, long start, long len) {}
  939. PRE_SYSCALL(mlockall)(long flags) {}
  940. POST_SYSCALL(mlockall)(long res, long flags) {}
  941. PRE_SYSCALL(munlockall)() {}
  942. POST_SYSCALL(munlockall)(long res) {}
  943. PRE_SYSCALL(madvise)(long start, long len, long behavior) {}
  944. POST_SYSCALL(madvise)(long res, long start, long len, long behavior) {}
  945. PRE_SYSCALL(mincore)(long start, long len, void *vec) {}
  946. POST_SYSCALL(mincore)(long res, long start, long len, void *vec) {
  947. if (res >= 0) {
  948. if (vec) {
  949. POST_WRITE(vec, (len + GetPageSizeCached() - 1) / GetPageSizeCached());
  950. }
  951. }
  952. }
  953. PRE_SYSCALL(pivot_root)(const void *new_root, const void *put_old) {
  954. if (new_root)
  955. PRE_READ(new_root,
  956. __sanitizer::internal_strlen((const char *)new_root) + 1);
  957. if (put_old)
  958. PRE_READ(put_old, __sanitizer::internal_strlen((const char *)put_old) + 1);
  959. }
  960. POST_SYSCALL(pivot_root)(long res, const void *new_root, const void *put_old) {}
  961. PRE_SYSCALL(chroot)(const void *filename) {
  962. if (filename)
  963. PRE_READ(filename,
  964. __sanitizer::internal_strlen((const char *)filename) + 1);
  965. }
  966. POST_SYSCALL(chroot)(long res, const void *filename) {}
  967. PRE_SYSCALL(mknod)(const void *filename, long mode, long dev) {
  968. if (filename)
  969. PRE_READ(filename,
  970. __sanitizer::internal_strlen((const char *)filename) + 1);
  971. }
  972. POST_SYSCALL(mknod)(long res, const void *filename, long mode, long dev) {}
  973. PRE_SYSCALL(link)(const void *oldname, const void *newname) {
  974. if (oldname)
  975. PRE_READ(oldname, __sanitizer::internal_strlen((const char *)oldname) + 1);
  976. if (newname)
  977. PRE_READ(newname, __sanitizer::internal_strlen((const char *)newname) + 1);
  978. }
  979. POST_SYSCALL(link)(long res, const void *oldname, const void *newname) {}
  980. PRE_SYSCALL(symlink)(const void *old, const void *new_) {
  981. if (old)
  982. PRE_READ(old, __sanitizer::internal_strlen((const char *)old) + 1);
  983. if (new_)
  984. PRE_READ(new_, __sanitizer::internal_strlen((const char *)new_) + 1);
  985. }
  986. POST_SYSCALL(symlink)(long res, const void *old, const void *new_) {}
  987. PRE_SYSCALL(unlink)(const void *pathname) {
  988. if (pathname)
  989. PRE_READ(pathname,
  990. __sanitizer::internal_strlen((const char *)pathname) + 1);
  991. }
  992. POST_SYSCALL(unlink)(long res, const void *pathname) {}
  993. PRE_SYSCALL(rename)(const void *oldname, const void *newname) {
  994. if (oldname)
  995. PRE_READ(oldname, __sanitizer::internal_strlen((const char *)oldname) + 1);
  996. if (newname)
  997. PRE_READ(newname, __sanitizer::internal_strlen((const char *)newname) + 1);
  998. }
  999. POST_SYSCALL(rename)(long res, const void *oldname, const void *newname) {}
  1000. PRE_SYSCALL(chmod)(const void *filename, long mode) {
  1001. if (filename)
  1002. PRE_READ(filename,
  1003. __sanitizer::internal_strlen((const char *)filename) + 1);
  1004. }
  1005. POST_SYSCALL(chmod)(long res, const void *filename, long mode) {}
  1006. PRE_SYSCALL(fchmod)(long fd, long mode) {}
  1007. POST_SYSCALL(fchmod)(long res, long fd, long mode) {}
  1008. PRE_SYSCALL(fcntl)(long fd, long cmd, long arg) {}
  1009. POST_SYSCALL(fcntl)(long res, long fd, long cmd, long arg) {}
  1010. PRE_SYSCALL(fcntl64)(long fd, long cmd, long arg) {}
  1011. POST_SYSCALL(fcntl64)(long res, long fd, long cmd, long arg) {}
  1012. PRE_SYSCALL(pipe)(void *fildes) {}
  1013. POST_SYSCALL(pipe)(long res, void *fildes) {
  1014. if (res >= 0)
  1015. if (fildes)
  1016. POST_WRITE(fildes, sizeof(int) * 2);
  1017. }
  1018. PRE_SYSCALL(pipe2)(void *fildes, long flags) {}
  1019. POST_SYSCALL(pipe2)(long res, void *fildes, long flags) {
  1020. if (res >= 0)
  1021. if (fildes)
  1022. POST_WRITE(fildes, sizeof(int) * 2);
  1023. }
  1024. PRE_SYSCALL(dup)(long fildes) {}
  1025. POST_SYSCALL(dup)(long res, long fildes) {}
  1026. PRE_SYSCALL(dup2)(long oldfd, long newfd) {}
  1027. POST_SYSCALL(dup2)(long res, long oldfd, long newfd) {}
  1028. PRE_SYSCALL(dup3)(long oldfd, long newfd, long flags) {}
  1029. POST_SYSCALL(dup3)(long res, long oldfd, long newfd, long flags) {}
  1030. PRE_SYSCALL(ioperm)(long from, long num, long on) {}
  1031. POST_SYSCALL(ioperm)(long res, long from, long num, long on) {}
  1032. PRE_SYSCALL(ioctl)(long fd, long cmd, long arg) {}
  1033. POST_SYSCALL(ioctl)(long res, long fd, long cmd, long arg) {}
  1034. PRE_SYSCALL(flock)(long fd, long cmd) {}
  1035. POST_SYSCALL(flock)(long res, long fd, long cmd) {}
  1036. PRE_SYSCALL(io_setup)(long nr_reqs, void **ctx) {
  1037. if (ctx)
  1038. PRE_WRITE(ctx, sizeof(*ctx));
  1039. }
  1040. POST_SYSCALL(io_setup)(long res, long nr_reqs, void **ctx) {
  1041. if (res >= 0) {
  1042. if (ctx)
  1043. POST_WRITE(ctx, sizeof(*ctx));
  1044. // (*ctx) is actually a pointer to a kernel mapped page, and there are
  1045. // people out there who are crazy enough to peek into that page's 32-byte
  1046. // header.
  1047. if (*ctx)
  1048. POST_WRITE(*ctx, 32);
  1049. }
  1050. }
  1051. PRE_SYSCALL(io_destroy)(long ctx) {}
  1052. POST_SYSCALL(io_destroy)(long res, long ctx) {}
  1053. PRE_SYSCALL(io_getevents)
  1054. (long ctx_id, long min_nr, long nr, __sanitizer_io_event *ioevpp,
  1055. void *timeout) {
  1056. if (timeout)
  1057. PRE_READ(timeout, struct_timespec_sz);
  1058. }
  1059. POST_SYSCALL(io_getevents)
  1060. (long res, long ctx_id, long min_nr, long nr, __sanitizer_io_event *ioevpp,
  1061. void *timeout) {
  1062. if (res >= 0) {
  1063. if (ioevpp)
  1064. POST_WRITE(ioevpp, res * sizeof(*ioevpp));
  1065. if (timeout)
  1066. POST_WRITE(timeout, struct_timespec_sz);
  1067. }
  1068. for (long i = 0; i < res; i++) {
  1069. // We synchronize io_submit -> io_getevents/io_cancel using the
  1070. // user-provided data context. Data is not necessary a pointer, it can be
  1071. // an int, 0 or whatever; acquire/release will correctly handle this.
  1072. // This scheme can lead to false negatives, e.g. when all operations
  1073. // synchronize on 0. But there does not seem to be a better solution
  1074. // (except wrapping all operations in own context, which is unreliable).
  1075. // We can not reliably extract fildes in io_getevents.
  1076. COMMON_SYSCALL_ACQUIRE((void *)ioevpp[i].data);
  1077. }
  1078. }
  1079. PRE_SYSCALL(io_submit)(long ctx_id, long nr, __sanitizer_iocb **iocbpp) {
  1080. for (long i = 0; i < nr; ++i) {
  1081. uptr op = iocbpp[i]->aio_lio_opcode;
  1082. void *data = (void *)iocbpp[i]->aio_data;
  1083. void *buf = (void *)iocbpp[i]->aio_buf;
  1084. uptr len = (uptr)iocbpp[i]->aio_nbytes;
  1085. if (op == iocb_cmd_pwrite && buf && len) {
  1086. PRE_READ(buf, len);
  1087. } else if (op == iocb_cmd_pread && buf && len) {
  1088. POST_WRITE(buf, len);
  1089. } else if (op == iocb_cmd_pwritev) {
  1090. __sanitizer_iovec *iovec = (__sanitizer_iovec *)buf;
  1091. for (uptr v = 0; v < len; v++)
  1092. PRE_READ(iovec[v].iov_base, iovec[v].iov_len);
  1093. } else if (op == iocb_cmd_preadv) {
  1094. __sanitizer_iovec *iovec = (__sanitizer_iovec *)buf;
  1095. for (uptr v = 0; v < len; v++)
  1096. POST_WRITE(iovec[v].iov_base, iovec[v].iov_len);
  1097. }
  1098. // See comment in io_getevents.
  1099. COMMON_SYSCALL_RELEASE(data);
  1100. }
  1101. }
  1102. POST_SYSCALL(io_submit)
  1103. (long res, long ctx_id, long nr, __sanitizer_iocb **iocbpp) {}
  1104. PRE_SYSCALL(io_cancel)
  1105. (long ctx_id, __sanitizer_iocb *iocb, __sanitizer_io_event *result) {}
  1106. POST_SYSCALL(io_cancel)
  1107. (long res, long ctx_id, __sanitizer_iocb *iocb, __sanitizer_io_event *result) {
  1108. if (res == 0) {
  1109. if (result) {
  1110. // See comment in io_getevents.
  1111. COMMON_SYSCALL_ACQUIRE((void *)result->data);
  1112. POST_WRITE(result, sizeof(*result));
  1113. }
  1114. if (iocb)
  1115. POST_WRITE(iocb, sizeof(*iocb));
  1116. }
  1117. }
  1118. PRE_SYSCALL(sendfile)(long out_fd, long in_fd, void *offset, long count) {}
  1119. POST_SYSCALL(sendfile)
  1120. (long res, long out_fd, long in_fd, __sanitizer___kernel_off_t *offset,
  1121. long count) {
  1122. if (res >= 0) {
  1123. if (offset)
  1124. POST_WRITE(offset, sizeof(*offset));
  1125. }
  1126. }
  1127. PRE_SYSCALL(sendfile64)(long out_fd, long in_fd, void *offset, long count) {}
  1128. POST_SYSCALL(sendfile64)
  1129. (long res, long out_fd, long in_fd, __sanitizer___kernel_loff_t *offset,
  1130. long count) {
  1131. if (res >= 0) {
  1132. if (offset)
  1133. POST_WRITE(offset, sizeof(*offset));
  1134. }
  1135. }
  1136. PRE_SYSCALL(readlink)(const void *path, void *buf, long bufsiz) {
  1137. if (path)
  1138. PRE_READ(path, __sanitizer::internal_strlen((const char *)path) + 1);
  1139. }
  1140. POST_SYSCALL(readlink)(long res, const void *path, void *buf, long bufsiz) {
  1141. if (res >= 0) {
  1142. if (buf)
  1143. POST_WRITE(buf, __sanitizer::internal_strlen((const char *)buf) + 1);
  1144. }
  1145. }
  1146. PRE_SYSCALL(creat)(const void *pathname, long mode) {
  1147. if (pathname)
  1148. PRE_READ(pathname,
  1149. __sanitizer::internal_strlen((const char *)pathname) + 1);
  1150. }
  1151. POST_SYSCALL(creat)(long res, const void *pathname, long mode) {}
  1152. PRE_SYSCALL(open)(const void *filename, long flags, long mode) {
  1153. if (filename)
  1154. PRE_READ(filename,
  1155. __sanitizer::internal_strlen((const char *)filename) + 1);
  1156. }
  1157. POST_SYSCALL(open)(long res, const void *filename, long flags, long mode) {}
  1158. PRE_SYSCALL(close)(long fd) { COMMON_SYSCALL_FD_CLOSE((int)fd); }
  1159. POST_SYSCALL(close)(long res, long fd) {}
  1160. PRE_SYSCALL(access)(const void *filename, long mode) {
  1161. if (filename)
  1162. PRE_READ(filename,
  1163. __sanitizer::internal_strlen((const char *)filename) + 1);
  1164. }
  1165. POST_SYSCALL(access)(long res, const void *filename, long mode) {}
  1166. PRE_SYSCALL(vhangup)() {}
  1167. POST_SYSCALL(vhangup)(long res) {}
  1168. PRE_SYSCALL(chown)(const void *filename, long user, long group) {
  1169. if (filename)
  1170. PRE_READ(filename,
  1171. __sanitizer::internal_strlen((const char *)filename) + 1);
  1172. }
  1173. POST_SYSCALL(chown)(long res, const void *filename, long user, long group) {}
  1174. PRE_SYSCALL(lchown)(const void *filename, long user, long group) {
  1175. if (filename)
  1176. PRE_READ(filename,
  1177. __sanitizer::internal_strlen((const char *)filename) + 1);
  1178. }
  1179. POST_SYSCALL(lchown)(long res, const void *filename, long user, long group) {}
  1180. PRE_SYSCALL(fchown)(long fd, long user, long group) {}
  1181. POST_SYSCALL(fchown)(long res, long fd, long user, long group) {}
  1182. # if SANITIZER_USES_UID16_SYSCALLS
  1183. PRE_SYSCALL(chown16)(const void *filename, long user, long group) {
  1184. if (filename)
  1185. PRE_READ(filename,
  1186. __sanitizer::internal_strlen((const char *)filename) + 1);
  1187. }
  1188. POST_SYSCALL(chown16)(long res, const void *filename, long user, long group) {}
  1189. PRE_SYSCALL(lchown16)(const void *filename, long user, long group) {
  1190. if (filename)
  1191. PRE_READ(filename,
  1192. __sanitizer::internal_strlen((const char *)filename) + 1);
  1193. }
  1194. POST_SYSCALL(lchown16)(long res, const void *filename, long user, long group) {}
  1195. PRE_SYSCALL(fchown16)(long fd, long user, long group) {}
  1196. POST_SYSCALL(fchown16)(long res, long fd, long user, long group) {}
  1197. PRE_SYSCALL(setregid16)(long rgid, long egid) {}
  1198. POST_SYSCALL(setregid16)(long res, long rgid, long egid) {}
  1199. PRE_SYSCALL(setgid16)(long gid) {}
  1200. POST_SYSCALL(setgid16)(long res, long gid) {}
  1201. PRE_SYSCALL(setreuid16)(long ruid, long euid) {}
  1202. POST_SYSCALL(setreuid16)(long res, long ruid, long euid) {}
  1203. PRE_SYSCALL(setuid16)(long uid) {}
  1204. POST_SYSCALL(setuid16)(long res, long uid) {}
  1205. PRE_SYSCALL(setresuid16)(long ruid, long euid, long suid) {}
  1206. POST_SYSCALL(setresuid16)(long res, long ruid, long euid, long suid) {}
  1207. PRE_SYSCALL(getresuid16)(void *ruid, void *euid, void *suid) {}
  1208. POST_SYSCALL(getresuid16)
  1209. (long res, __sanitizer___kernel_old_uid_t *ruid,
  1210. __sanitizer___kernel_old_uid_t *euid, __sanitizer___kernel_old_uid_t *suid) {
  1211. if (res >= 0) {
  1212. if (ruid)
  1213. POST_WRITE(ruid, sizeof(*ruid));
  1214. if (euid)
  1215. POST_WRITE(euid, sizeof(*euid));
  1216. if (suid)
  1217. POST_WRITE(suid, sizeof(*suid));
  1218. }
  1219. }
  1220. PRE_SYSCALL(setresgid16)(long rgid, long egid, long sgid) {}
  1221. POST_SYSCALL(setresgid16)(long res, long rgid, long egid, long sgid) {}
  1222. PRE_SYSCALL(getresgid16)(void *rgid, void *egid, void *sgid) {}
  1223. POST_SYSCALL(getresgid16)
  1224. (long res, __sanitizer___kernel_old_gid_t *rgid,
  1225. __sanitizer___kernel_old_gid_t *egid, __sanitizer___kernel_old_gid_t *sgid) {
  1226. if (res >= 0) {
  1227. if (rgid)
  1228. POST_WRITE(rgid, sizeof(*rgid));
  1229. if (egid)
  1230. POST_WRITE(egid, sizeof(*egid));
  1231. if (sgid)
  1232. POST_WRITE(sgid, sizeof(*sgid));
  1233. }
  1234. }
  1235. PRE_SYSCALL(setfsuid16)(long uid) {}
  1236. POST_SYSCALL(setfsuid16)(long res, long uid) {}
  1237. PRE_SYSCALL(setfsgid16)(long gid) {}
  1238. POST_SYSCALL(setfsgid16)(long res, long gid) {}
  1239. PRE_SYSCALL(getgroups16)
  1240. (long gidsetsize, __sanitizer___kernel_old_gid_t *grouplist) {}
  1241. POST_SYSCALL(getgroups16)
  1242. (long res, long gidsetsize, __sanitizer___kernel_old_gid_t *grouplist) {
  1243. if (res >= 0) {
  1244. if (grouplist)
  1245. POST_WRITE(grouplist, res * sizeof(*grouplist));
  1246. }
  1247. }
  1248. PRE_SYSCALL(setgroups16)
  1249. (long gidsetsize, __sanitizer___kernel_old_gid_t *grouplist) {
  1250. if (grouplist)
  1251. POST_WRITE(grouplist, gidsetsize * sizeof(*grouplist));
  1252. }
  1253. POST_SYSCALL(setgroups16)
  1254. (long res, long gidsetsize, __sanitizer___kernel_old_gid_t *grouplist) {}
  1255. PRE_SYSCALL(getuid16)() {}
  1256. POST_SYSCALL(getuid16)(long res) {}
  1257. PRE_SYSCALL(geteuid16)() {}
  1258. POST_SYSCALL(geteuid16)(long res) {}
  1259. PRE_SYSCALL(getgid16)() {}
  1260. POST_SYSCALL(getgid16)(long res) {}
  1261. PRE_SYSCALL(getegid16)() {}
  1262. POST_SYSCALL(getegid16)(long res) {}
  1263. # endif // SANITIZER_USES_UID16_SYSCALLS
  1264. PRE_SYSCALL(utime)(void *filename, void *times) {}
  1265. POST_SYSCALL(utime)(long res, void *filename, void *times) {
  1266. if (res >= 0) {
  1267. if (filename)
  1268. POST_WRITE(filename,
  1269. __sanitizer::internal_strlen((const char *)filename) + 1);
  1270. if (times)
  1271. POST_WRITE(times, struct_utimbuf_sz);
  1272. }
  1273. }
  1274. PRE_SYSCALL(utimes)(void *filename, void *utimes) {}
  1275. POST_SYSCALL(utimes)(long res, void *filename, void *utimes) {
  1276. if (res >= 0) {
  1277. if (filename)
  1278. POST_WRITE(filename,
  1279. __sanitizer::internal_strlen((const char *)filename) + 1);
  1280. if (utimes)
  1281. POST_WRITE(utimes, timeval_sz);
  1282. }
  1283. }
  1284. PRE_SYSCALL(lseek)(long fd, long offset, long origin) {}
  1285. POST_SYSCALL(lseek)(long res, long fd, long offset, long origin) {}
  1286. PRE_SYSCALL(llseek)
  1287. (long fd, long offset_high, long offset_low, void *result, long origin) {}
  1288. POST_SYSCALL(llseek)
  1289. (long res, long fd, long offset_high, long offset_low, void *result,
  1290. long origin) {
  1291. if (res >= 0) {
  1292. if (result)
  1293. POST_WRITE(result, sizeof(long long));
  1294. }
  1295. }
  1296. PRE_SYSCALL(readv)(long fd, const __sanitizer_iovec *vec, long vlen) {}
  1297. POST_SYSCALL(readv)
  1298. (long res, long fd, const __sanitizer_iovec *vec, long vlen) {
  1299. if (res >= 0) {
  1300. if (vec)
  1301. kernel_write_iovec(vec, vlen, res);
  1302. }
  1303. }
  1304. PRE_SYSCALL(write)(long fd, const void *buf, long count) {
  1305. if (buf)
  1306. PRE_READ(buf, count);
  1307. }
  1308. POST_SYSCALL(write)(long res, long fd, const void *buf, long count) {}
  1309. PRE_SYSCALL(writev)(long fd, const __sanitizer_iovec *vec, long vlen) {}
  1310. POST_SYSCALL(writev)
  1311. (long res, long fd, const __sanitizer_iovec *vec, long vlen) {
  1312. if (res >= 0) {
  1313. if (vec)
  1314. kernel_read_iovec(vec, vlen, res);
  1315. }
  1316. }
  1317. # ifdef _LP64
  1318. PRE_SYSCALL(pread64)(long fd, void *buf, long count, long pos) {}
  1319. POST_SYSCALL(pread64)(long res, long fd, void *buf, long count, long pos) {
  1320. if (res >= 0) {
  1321. if (buf)
  1322. POST_WRITE(buf, res);
  1323. }
  1324. }
  1325. PRE_SYSCALL(pwrite64)(long fd, const void *buf, long count, long pos) {
  1326. if (buf)
  1327. PRE_READ(buf, count);
  1328. }
  1329. POST_SYSCALL(pwrite64)
  1330. (long res, long fd, const void *buf, long count, long pos) {}
  1331. # else
  1332. PRE_SYSCALL(pread64)(long fd, void *buf, long count, long pos0, long pos1) {}
  1333. POST_SYSCALL(pread64)
  1334. (long res, long fd, void *buf, long count, long pos0, long pos1) {
  1335. if (res >= 0) {
  1336. if (buf)
  1337. POST_WRITE(buf, res);
  1338. }
  1339. }
  1340. PRE_SYSCALL(pwrite64)
  1341. (long fd, const void *buf, long count, long pos0, long pos1) {
  1342. if (buf)
  1343. PRE_READ(buf, count);
  1344. }
  1345. POST_SYSCALL(pwrite64)
  1346. (long res, long fd, const void *buf, long count, long pos0, long pos1) {}
  1347. # endif
  1348. PRE_SYSCALL(preadv)
  1349. (long fd, const __sanitizer_iovec *vec, long vlen, long pos_l, long pos_h) {}
  1350. POST_SYSCALL(preadv)
  1351. (long res, long fd, const __sanitizer_iovec *vec, long vlen, long pos_l,
  1352. long pos_h) {
  1353. if (res >= 0) {
  1354. if (vec)
  1355. kernel_write_iovec(vec, vlen, res);
  1356. }
  1357. }
  1358. PRE_SYSCALL(pwritev)
  1359. (long fd, const __sanitizer_iovec *vec, long vlen, long pos_l, long pos_h) {}
  1360. POST_SYSCALL(pwritev)
  1361. (long res, long fd, const __sanitizer_iovec *vec, long vlen, long pos_l,
  1362. long pos_h) {
  1363. if (res >= 0) {
  1364. if (vec)
  1365. kernel_read_iovec(vec, vlen, res);
  1366. }
  1367. }
  1368. PRE_SYSCALL(getcwd)(void *buf, long size) {}
  1369. POST_SYSCALL(getcwd)(long res, void *buf, long size) {
  1370. if (res >= 0) {
  1371. if (buf)
  1372. POST_WRITE(buf, __sanitizer::internal_strlen((const char *)buf) + 1);
  1373. }
  1374. }
  1375. PRE_SYSCALL(mkdir)(const void *pathname, long mode) {
  1376. if (pathname)
  1377. PRE_READ(pathname,
  1378. __sanitizer::internal_strlen((const char *)pathname) + 1);
  1379. }
  1380. POST_SYSCALL(mkdir)(long res, const void *pathname, long mode) {}
  1381. PRE_SYSCALL(chdir)(const void *filename) {
  1382. if (filename)
  1383. PRE_READ(filename,
  1384. __sanitizer::internal_strlen((const char *)filename) + 1);
  1385. }
  1386. POST_SYSCALL(chdir)(long res, const void *filename) {}
  1387. PRE_SYSCALL(fchdir)(long fd) {}
  1388. POST_SYSCALL(fchdir)(long res, long fd) {}
  1389. PRE_SYSCALL(rmdir)(const void *pathname) {
  1390. if (pathname)
  1391. PRE_READ(pathname,
  1392. __sanitizer::internal_strlen((const char *)pathname) + 1);
  1393. }
  1394. POST_SYSCALL(rmdir)(long res, const void *pathname) {}
  1395. PRE_SYSCALL(lookup_dcookie)(u64 cookie64, void *buf, long len) {}
  1396. POST_SYSCALL(lookup_dcookie)(long res, u64 cookie64, void *buf, long len) {
  1397. if (res >= 0) {
  1398. if (buf)
  1399. POST_WRITE(buf, __sanitizer::internal_strlen((const char *)buf) + 1);
  1400. }
  1401. }
  1402. PRE_SYSCALL(quotactl)(long cmd, const void *special, long id, void *addr) {
  1403. if (special)
  1404. PRE_READ(special, __sanitizer::internal_strlen((const char *)special) + 1);
  1405. }
  1406. POST_SYSCALL(quotactl)
  1407. (long res, long cmd, const void *special, long id, void *addr) {}
  1408. PRE_SYSCALL(getdents)(long fd, void *dirent, long count) {}
  1409. POST_SYSCALL(getdents)(long res, long fd, void *dirent, long count) {
  1410. if (res >= 0) {
  1411. if (dirent)
  1412. POST_WRITE(dirent, res);
  1413. }
  1414. }
  1415. PRE_SYSCALL(getdents64)(long fd, void *dirent, long count) {}
  1416. POST_SYSCALL(getdents64)(long res, long fd, void *dirent, long count) {
  1417. if (res >= 0) {
  1418. if (dirent)
  1419. POST_WRITE(dirent, res);
  1420. }
  1421. }
  1422. PRE_SYSCALL(setsockopt)
  1423. (long fd, long level, long optname, void *optval, long optlen) {}
  1424. POST_SYSCALL(setsockopt)
  1425. (long res, long fd, long level, long optname, void *optval, long optlen) {
  1426. if (res >= 0) {
  1427. if (optval)
  1428. POST_WRITE(optval,
  1429. __sanitizer::internal_strlen((const char *)optval) + 1);
  1430. }
  1431. }
  1432. PRE_SYSCALL(getsockopt)
  1433. (long fd, long level, long optname, void *optval, void *optlen) {}
  1434. POST_SYSCALL(getsockopt)
  1435. (long res, long fd, long level, long optname, void *optval, void *optlen) {
  1436. if (res >= 0) {
  1437. if (optval)
  1438. POST_WRITE(optval,
  1439. __sanitizer::internal_strlen((const char *)optval) + 1);
  1440. if (optlen)
  1441. POST_WRITE(optlen, sizeof(int));
  1442. }
  1443. }
  1444. PRE_SYSCALL(bind)(long arg0, sanitizer_kernel_sockaddr *arg1, long arg2) {}
  1445. POST_SYSCALL(bind)
  1446. (long res, long arg0, sanitizer_kernel_sockaddr *arg1, long arg2) {
  1447. if (res >= 0) {
  1448. if (arg1)
  1449. POST_WRITE(arg1, sizeof(*arg1));
  1450. }
  1451. }
  1452. PRE_SYSCALL(connect)(long arg0, sanitizer_kernel_sockaddr *arg1, long arg2) {}
  1453. POST_SYSCALL(connect)
  1454. (long res, long arg0, sanitizer_kernel_sockaddr *arg1, long arg2) {
  1455. if (res >= 0) {
  1456. if (arg1)
  1457. POST_WRITE(arg1, sizeof(*arg1));
  1458. }
  1459. }
  1460. PRE_SYSCALL(accept)(long arg0, sanitizer_kernel_sockaddr *arg1, void *arg2) {}
  1461. POST_SYSCALL(accept)
  1462. (long res, long arg0, sanitizer_kernel_sockaddr *arg1, void *arg2) {
  1463. if (res >= 0) {
  1464. if (arg1)
  1465. POST_WRITE(arg1, sizeof(*arg1));
  1466. if (arg2)
  1467. POST_WRITE(arg2, sizeof(unsigned));
  1468. }
  1469. }
  1470. PRE_SYSCALL(accept4)
  1471. (long arg0, sanitizer_kernel_sockaddr *arg1, void *arg2, long arg3) {}
  1472. POST_SYSCALL(accept4)
  1473. (long res, long arg0, sanitizer_kernel_sockaddr *arg1, void *arg2, long arg3) {
  1474. if (res >= 0) {
  1475. if (arg1)
  1476. POST_WRITE(arg1, sizeof(*arg1));
  1477. if (arg2)
  1478. POST_WRITE(arg2, sizeof(unsigned));
  1479. }
  1480. }
  1481. PRE_SYSCALL(getsockname)
  1482. (long arg0, sanitizer_kernel_sockaddr *arg1, void *arg2) {}
  1483. POST_SYSCALL(getsockname)
  1484. (long res, long arg0, sanitizer_kernel_sockaddr *arg1, void *arg2) {
  1485. if (res >= 0) {
  1486. if (arg1)
  1487. POST_WRITE(arg1, sizeof(*arg1));
  1488. if (arg2)
  1489. POST_WRITE(arg2, sizeof(unsigned));
  1490. }
  1491. }
  1492. PRE_SYSCALL(getpeername)
  1493. (long arg0, sanitizer_kernel_sockaddr *arg1, void *arg2) {}
  1494. POST_SYSCALL(getpeername)
  1495. (long res, long arg0, sanitizer_kernel_sockaddr *arg1, void *arg2) {
  1496. if (res >= 0) {
  1497. if (arg1)
  1498. POST_WRITE(arg1, sizeof(*arg1));
  1499. if (arg2)
  1500. POST_WRITE(arg2, sizeof(unsigned));
  1501. }
  1502. }
  1503. PRE_SYSCALL(send)(long arg0, void *arg1, long arg2, long arg3) {}
  1504. POST_SYSCALL(send)(long res, long arg0, void *arg1, long arg2, long arg3) {
  1505. if (res) {
  1506. if (arg1)
  1507. POST_READ(arg1, res);
  1508. }
  1509. }
  1510. PRE_SYSCALL(sendto)
  1511. (long arg0, void *arg1, long arg2, long arg3, sanitizer_kernel_sockaddr *arg4,
  1512. long arg5) {}
  1513. POST_SYSCALL(sendto)
  1514. (long res, long arg0, void *arg1, long arg2, long arg3,
  1515. sanitizer_kernel_sockaddr *arg4, long arg5) {
  1516. if (res >= 0) {
  1517. if (arg1)
  1518. POST_READ(arg1, res);
  1519. if (arg4)
  1520. POST_WRITE(arg4, sizeof(*arg4));
  1521. }
  1522. }
  1523. PRE_SYSCALL(sendmsg)(long fd, void *msg, long flags) {}
  1524. POST_SYSCALL(sendmsg)(long res, long fd, void *msg, long flags) {
  1525. // FIXME: POST_READ
  1526. }
  1527. PRE_SYSCALL(sendmmsg)(long fd, void *msg, long vlen, long flags) {}
  1528. POST_SYSCALL(sendmmsg)(long res, long fd, void *msg, long vlen, long flags) {
  1529. // FIXME: POST_READ
  1530. }
  1531. PRE_SYSCALL(recv)(long arg0, void *buf, long len, long flags) {}
  1532. POST_SYSCALL(recv)(long res, void *buf, long len, long flags) {
  1533. if (res >= 0) {
  1534. if (buf)
  1535. POST_WRITE(buf, res);
  1536. }
  1537. }
  1538. PRE_SYSCALL(recvfrom)
  1539. (long arg0, void *buf, long len, long flags, sanitizer_kernel_sockaddr *arg4,
  1540. void *arg5) {}
  1541. POST_SYSCALL(recvfrom)
  1542. (long res, long arg0, void *buf, long len, long flags,
  1543. sanitizer_kernel_sockaddr *arg4, void *arg5) {
  1544. if (res >= 0) {
  1545. if (buf)
  1546. POST_WRITE(buf, res);
  1547. if (arg4)
  1548. POST_WRITE(arg4, sizeof(*arg4));
  1549. if (arg5)
  1550. POST_WRITE(arg5, sizeof(int));
  1551. }
  1552. }
  1553. PRE_SYSCALL(socket)(long arg0, long arg1, long arg2) {}
  1554. POST_SYSCALL(socket)(long res, long arg0, long arg1, long arg2) {}
  1555. PRE_SYSCALL(socketpair)(long arg0, long arg1, long arg2, int *sv) {}
  1556. POST_SYSCALL(socketpair)(long res, long arg0, long arg1, long arg2, int *sv) {
  1557. if (res >= 0)
  1558. if (sv)
  1559. POST_WRITE(sv, sizeof(int) * 2);
  1560. }
  1561. PRE_SYSCALL(socketcall)(long call, void *args) {}
  1562. POST_SYSCALL(socketcall)(long res, long call, void *args) {
  1563. if (res >= 0) {
  1564. if (args)
  1565. POST_WRITE(args, sizeof(long));
  1566. }
  1567. }
  1568. PRE_SYSCALL(listen)(long arg0, long arg1) {}
  1569. POST_SYSCALL(listen)(long res, long arg0, long arg1) {}
  1570. PRE_SYSCALL(poll)(void *ufds, long nfds, long timeout) {}
  1571. POST_SYSCALL(poll)
  1572. (long res, __sanitizer_pollfd *ufds, long nfds, long timeout) {
  1573. if (res >= 0) {
  1574. if (ufds)
  1575. POST_WRITE(ufds, nfds * sizeof(*ufds));
  1576. }
  1577. }
  1578. PRE_SYSCALL(select)
  1579. (long n, __sanitizer___kernel_fd_set *inp, __sanitizer___kernel_fd_set *outp,
  1580. __sanitizer___kernel_fd_set *exp, void *tvp) {}
  1581. POST_SYSCALL(select)
  1582. (long res, long n, __sanitizer___kernel_fd_set *inp,
  1583. __sanitizer___kernel_fd_set *outp, __sanitizer___kernel_fd_set *exp,
  1584. void *tvp) {
  1585. if (res >= 0) {
  1586. if (inp)
  1587. POST_WRITE(inp, sizeof(*inp));
  1588. if (outp)
  1589. POST_WRITE(outp, sizeof(*outp));
  1590. if (exp)
  1591. POST_WRITE(exp, sizeof(*exp));
  1592. if (tvp)
  1593. POST_WRITE(tvp, timeval_sz);
  1594. }
  1595. }
  1596. PRE_SYSCALL(old_select)(void *arg) {}
  1597. POST_SYSCALL(old_select)(long res, void *arg) {}
  1598. PRE_SYSCALL(epoll_create)(long size) {}
  1599. POST_SYSCALL(epoll_create)(long res, long size) {}
  1600. PRE_SYSCALL(epoll_create1)(long flags) {}
  1601. POST_SYSCALL(epoll_create1)(long res, long flags) {}
  1602. PRE_SYSCALL(epoll_ctl)(long epfd, long op, long fd, void *event) {}
  1603. POST_SYSCALL(epoll_ctl)(long res, long epfd, long op, long fd, void *event) {
  1604. if (res >= 0) {
  1605. if (event)
  1606. POST_WRITE(event, struct_epoll_event_sz);
  1607. }
  1608. }
  1609. PRE_SYSCALL(epoll_wait)
  1610. (long epfd, void *events, long maxevents, long timeout) {}
  1611. POST_SYSCALL(epoll_wait)
  1612. (long res, long epfd, void *events, long maxevents, long timeout) {
  1613. if (res >= 0) {
  1614. COMMON_SYSCALL_FD_ACQUIRE(epfd);
  1615. if (events)
  1616. POST_WRITE(events, res * struct_epoll_event_sz);
  1617. }
  1618. }
  1619. PRE_SYSCALL(epoll_pwait)
  1620. (long epfd, void *events, long maxevents, long timeout,
  1621. const kernel_sigset_t *sigmask, long sigsetsize) {
  1622. if (sigmask)
  1623. PRE_READ(sigmask, sigsetsize);
  1624. }
  1625. POST_SYSCALL(epoll_pwait)
  1626. (long res, long epfd, void *events, long maxevents, long timeout,
  1627. const void *sigmask, long sigsetsize) {
  1628. if (res >= 0) {
  1629. COMMON_SYSCALL_FD_ACQUIRE(epfd);
  1630. if (events)
  1631. POST_WRITE(events, res * struct_epoll_event_sz);
  1632. }
  1633. }
  1634. PRE_SYSCALL(epoll_pwait2)
  1635. (long epfd, void *events, long maxevents,
  1636. const sanitizer_kernel_timespec *timeout, const kernel_sigset_t *sigmask,
  1637. long sigsetsize) {
  1638. if (timeout)
  1639. PRE_READ(timeout, sizeof(timeout));
  1640. if (sigmask)
  1641. PRE_READ(sigmask, sigsetsize);
  1642. }
  1643. POST_SYSCALL(epoll_pwait2)
  1644. (long res, long epfd, void *events, long maxevents,
  1645. const sanitizer_kernel_timespec *timeout, const void *sigmask,
  1646. long sigsetsize) {
  1647. if (res >= 0) {
  1648. COMMON_SYSCALL_FD_ACQUIRE(epfd);
  1649. if (events)
  1650. POST_WRITE(events, res * struct_epoll_event_sz);
  1651. }
  1652. }
  1653. PRE_SYSCALL(gethostname)(void *name, long len) {}
  1654. POST_SYSCALL(gethostname)(long res, void *name, long len) {
  1655. if (res >= 0) {
  1656. if (name)
  1657. POST_WRITE(name, __sanitizer::internal_strlen((const char *)name) + 1);
  1658. }
  1659. }
  1660. PRE_SYSCALL(sethostname)(void *name, long len) {}
  1661. POST_SYSCALL(sethostname)(long res, void *name, long len) {
  1662. if (res >= 0) {
  1663. if (name)
  1664. POST_WRITE(name, __sanitizer::internal_strlen((const char *)name) + 1);
  1665. }
  1666. }
  1667. PRE_SYSCALL(setdomainname)(void *name, long len) {}
  1668. POST_SYSCALL(setdomainname)(long res, void *name, long len) {
  1669. if (res >= 0) {
  1670. if (name)
  1671. POST_WRITE(name, __sanitizer::internal_strlen((const char *)name) + 1);
  1672. }
  1673. }
  1674. PRE_SYSCALL(newuname)(void *name) {}
  1675. POST_SYSCALL(newuname)(long res, void *name) {
  1676. if (res >= 0) {
  1677. if (name)
  1678. POST_WRITE(name, struct_new_utsname_sz);
  1679. }
  1680. }
  1681. PRE_SYSCALL(uname)(void *arg0) {}
  1682. POST_SYSCALL(uname)(long res, void *arg0) {
  1683. if (res >= 0) {
  1684. if (arg0)
  1685. POST_WRITE(arg0, struct_old_utsname_sz);
  1686. }
  1687. }
  1688. PRE_SYSCALL(olduname)(void *arg0) {}
  1689. POST_SYSCALL(olduname)(long res, void *arg0) {
  1690. if (res >= 0) {
  1691. if (arg0)
  1692. POST_WRITE(arg0, struct_oldold_utsname_sz);
  1693. }
  1694. }
  1695. PRE_SYSCALL(getrlimit)(long resource, void *rlim) {}
  1696. POST_SYSCALL(getrlimit)(long res, long resource, void *rlim) {
  1697. if (res >= 0) {
  1698. if (rlim)
  1699. POST_WRITE(rlim, struct_rlimit_sz);
  1700. }
  1701. }
  1702. PRE_SYSCALL(old_getrlimit)(long resource, void *rlim) {}
  1703. POST_SYSCALL(old_getrlimit)(long res, long resource, void *rlim) {
  1704. if (res >= 0) {
  1705. if (rlim)
  1706. POST_WRITE(rlim, struct_rlimit_sz);
  1707. }
  1708. }
  1709. PRE_SYSCALL(setrlimit)(long resource, void *rlim) {}
  1710. POST_SYSCALL(setrlimit)(long res, long resource, void *rlim) {
  1711. if (res >= 0) {
  1712. if (rlim)
  1713. POST_WRITE(rlim, struct_rlimit_sz);
  1714. }
  1715. }
  1716. # if SANITIZER_GLIBC
  1717. PRE_SYSCALL(prlimit64)
  1718. (long pid, long resource, const void *new_rlim, void *old_rlim) {
  1719. if (new_rlim)
  1720. PRE_READ(new_rlim, struct_rlimit64_sz);
  1721. }
  1722. POST_SYSCALL(prlimit64)
  1723. (long res, long pid, long resource, const void *new_rlim, void *old_rlim) {
  1724. if (res >= 0) {
  1725. if (old_rlim)
  1726. POST_WRITE(old_rlim, struct_rlimit64_sz);
  1727. }
  1728. }
  1729. # endif
  1730. PRE_SYSCALL(getrusage)(long who, void *ru) {}
  1731. POST_SYSCALL(getrusage)(long res, long who, void *ru) {
  1732. if (res >= 0) {
  1733. if (ru)
  1734. POST_WRITE(ru, struct_rusage_sz);
  1735. }
  1736. }
  1737. PRE_SYSCALL(umask)(long mask) {}
  1738. POST_SYSCALL(umask)(long res, long mask) {}
  1739. PRE_SYSCALL(msgget)(long key, long msgflg) {}
  1740. POST_SYSCALL(msgget)(long res, long key, long msgflg) {}
  1741. PRE_SYSCALL(msgsnd)(long msqid, void *msgp, long msgsz, long msgflg) {
  1742. if (msgp)
  1743. PRE_READ(msgp, msgsz);
  1744. }
  1745. POST_SYSCALL(msgsnd)
  1746. (long res, long msqid, void *msgp, long msgsz, long msgflg) {}
  1747. PRE_SYSCALL(msgrcv)
  1748. (long msqid, void *msgp, long msgsz, long msgtyp, long msgflg) {}
  1749. POST_SYSCALL(msgrcv)
  1750. (long res, long msqid, void *msgp, long msgsz, long msgtyp, long msgflg) {
  1751. if (res >= 0) {
  1752. if (msgp)
  1753. POST_WRITE(msgp, res);
  1754. }
  1755. }
  1756. # if !SANITIZER_ANDROID
  1757. PRE_SYSCALL(msgctl)(long msqid, long cmd, void *buf) {}
  1758. POST_SYSCALL(msgctl)(long res, long msqid, long cmd, void *buf) {
  1759. if (res >= 0) {
  1760. if (buf)
  1761. POST_WRITE(buf, struct_msqid_ds_sz);
  1762. }
  1763. }
  1764. # endif
  1765. PRE_SYSCALL(semget)(long key, long nsems, long semflg) {}
  1766. POST_SYSCALL(semget)(long res, long key, long nsems, long semflg) {}
  1767. PRE_SYSCALL(semop)(long semid, void *sops, long nsops) {}
  1768. POST_SYSCALL(semop)(long res, long semid, void *sops, long nsops) {}
  1769. PRE_SYSCALL(semctl)(long semid, long semnum, long cmd, void *arg) {}
  1770. POST_SYSCALL(semctl)(long res, long semid, long semnum, long cmd, void *arg) {}
  1771. PRE_SYSCALL(semtimedop)
  1772. (long semid, void *sops, long nsops, const void *timeout) {
  1773. if (timeout)
  1774. PRE_READ(timeout, struct_timespec_sz);
  1775. }
  1776. POST_SYSCALL(semtimedop)
  1777. (long res, long semid, void *sops, long nsops, const void *timeout) {}
  1778. PRE_SYSCALL(shmat)(long shmid, void *shmaddr, long shmflg) {}
  1779. POST_SYSCALL(shmat)(long res, long shmid, void *shmaddr, long shmflg) {
  1780. if (res >= 0) {
  1781. if (shmaddr)
  1782. POST_WRITE(shmaddr,
  1783. __sanitizer::internal_strlen((const char *)shmaddr) + 1);
  1784. }
  1785. }
  1786. PRE_SYSCALL(shmget)(long key, long size, long flag) {}
  1787. POST_SYSCALL(shmget)(long res, long key, long size, long flag) {}
  1788. PRE_SYSCALL(shmdt)(void *shmaddr) {}
  1789. POST_SYSCALL(shmdt)(long res, void *shmaddr) {
  1790. if (res >= 0) {
  1791. if (shmaddr)
  1792. POST_WRITE(shmaddr,
  1793. __sanitizer::internal_strlen((const char *)shmaddr) + 1);
  1794. }
  1795. }
  1796. PRE_SYSCALL(ipc)
  1797. (long call, long first, long second, long third, void *ptr, long fifth) {}
  1798. POST_SYSCALL(ipc)
  1799. (long res, long call, long first, long second, long third, void *ptr,
  1800. long fifth) {}
  1801. # if !SANITIZER_ANDROID
  1802. PRE_SYSCALL(shmctl)(long shmid, long cmd, void *buf) {}
  1803. POST_SYSCALL(shmctl)(long res, long shmid, long cmd, void *buf) {
  1804. if (res >= 0) {
  1805. if (buf)
  1806. POST_WRITE(buf, sizeof(__sanitizer_shmid_ds));
  1807. }
  1808. }
  1809. PRE_SYSCALL(mq_open)(const void *name, long oflag, long mode, void *attr) {
  1810. if (name)
  1811. PRE_READ(name, __sanitizer::internal_strlen((const char *)name) + 1);
  1812. }
  1813. POST_SYSCALL(mq_open)
  1814. (long res, const void *name, long oflag, long mode, void *attr) {
  1815. if (res >= 0) {
  1816. if (attr)
  1817. POST_WRITE(attr, struct_mq_attr_sz);
  1818. }
  1819. }
  1820. PRE_SYSCALL(mq_unlink)(const void *name) {
  1821. if (name)
  1822. PRE_READ(name, __sanitizer::internal_strlen((const char *)name) + 1);
  1823. }
  1824. POST_SYSCALL(mq_unlink)(long res, const void *name) {}
  1825. PRE_SYSCALL(mq_timedsend)
  1826. (long mqdes, const void *msg_ptr, long msg_len, long msg_prio,
  1827. const void *abs_timeout) {
  1828. if (msg_ptr)
  1829. PRE_READ(msg_ptr, msg_len);
  1830. if (abs_timeout)
  1831. PRE_READ(abs_timeout, struct_timespec_sz);
  1832. }
  1833. POST_SYSCALL(mq_timedsend)
  1834. (long res, long mqdes, const void *msg_ptr, long msg_len, long msg_prio,
  1835. const void *abs_timeout) {}
  1836. PRE_SYSCALL(mq_timedreceive)
  1837. (long mqdes, void *msg_ptr, long msg_len, void *msg_prio,
  1838. const void *abs_timeout) {
  1839. if (abs_timeout)
  1840. PRE_READ(abs_timeout, struct_timespec_sz);
  1841. }
  1842. POST_SYSCALL(mq_timedreceive)
  1843. (long res, long mqdes, void *msg_ptr, long msg_len, int *msg_prio,
  1844. const void *abs_timeout) {
  1845. if (res >= 0) {
  1846. if (msg_ptr)
  1847. POST_WRITE(msg_ptr, res);
  1848. if (msg_prio)
  1849. POST_WRITE(msg_prio, sizeof(*msg_prio));
  1850. }
  1851. }
  1852. PRE_SYSCALL(mq_notify)(long mqdes, const void *notification) {
  1853. if (notification)
  1854. PRE_READ(notification, struct_sigevent_sz);
  1855. }
  1856. POST_SYSCALL(mq_notify)(long res, long mqdes, const void *notification) {}
  1857. PRE_SYSCALL(mq_getsetattr)(long mqdes, const void *mqstat, void *omqstat) {
  1858. if (mqstat)
  1859. PRE_READ(mqstat, struct_mq_attr_sz);
  1860. }
  1861. POST_SYSCALL(mq_getsetattr)
  1862. (long res, long mqdes, const void *mqstat, void *omqstat) {
  1863. if (res >= 0) {
  1864. if (omqstat)
  1865. POST_WRITE(omqstat, struct_mq_attr_sz);
  1866. }
  1867. }
  1868. # endif // SANITIZER_ANDROID
  1869. PRE_SYSCALL(pciconfig_iobase)(long which, long bus, long devfn) {}
  1870. POST_SYSCALL(pciconfig_iobase)(long res, long which, long bus, long devfn) {}
  1871. PRE_SYSCALL(pciconfig_read)
  1872. (long bus, long dfn, long off, long len, void *buf) {}
  1873. POST_SYSCALL(pciconfig_read)
  1874. (long res, long bus, long dfn, long off, long len, void *buf) {}
  1875. PRE_SYSCALL(pciconfig_write)
  1876. (long bus, long dfn, long off, long len, void *buf) {}
  1877. POST_SYSCALL(pciconfig_write)
  1878. (long res, long bus, long dfn, long off, long len, void *buf) {}
  1879. PRE_SYSCALL(swapon)(const void *specialfile, long swap_flags) {
  1880. if (specialfile)
  1881. PRE_READ(specialfile,
  1882. __sanitizer::internal_strlen((const char *)specialfile) + 1);
  1883. }
  1884. POST_SYSCALL(swapon)(long res, const void *specialfile, long swap_flags) {}
  1885. PRE_SYSCALL(swapoff)(const void *specialfile) {
  1886. if (specialfile)
  1887. PRE_READ(specialfile,
  1888. __sanitizer::internal_strlen((const char *)specialfile) + 1);
  1889. }
  1890. POST_SYSCALL(swapoff)(long res, const void *specialfile) {}
  1891. PRE_SYSCALL(sysctl)(__sanitizer___sysctl_args *args) {
  1892. if (args) {
  1893. if (args->name)
  1894. PRE_READ(args->name, args->nlen * sizeof(*args->name));
  1895. if (args->newval)
  1896. PRE_READ(args->name, args->newlen);
  1897. }
  1898. }
  1899. POST_SYSCALL(sysctl)(long res, __sanitizer___sysctl_args *args) {
  1900. if (res >= 0) {
  1901. if (args && args->oldval && args->oldlenp) {
  1902. POST_WRITE(args->oldlenp, sizeof(*args->oldlenp));
  1903. POST_WRITE(args->oldval, *args->oldlenp);
  1904. }
  1905. }
  1906. }
  1907. PRE_SYSCALL(sysinfo)(void *info) {}
  1908. POST_SYSCALL(sysinfo)(long res, void *info) {
  1909. if (res >= 0) {
  1910. if (info)
  1911. POST_WRITE(info, struct_sysinfo_sz);
  1912. }
  1913. }
  1914. PRE_SYSCALL(sysfs)(long option, long arg1, long arg2) {}
  1915. POST_SYSCALL(sysfs)(long res, long option, long arg1, long arg2) {}
  1916. PRE_SYSCALL(syslog)(long type, void *buf, long len) {}
  1917. POST_SYSCALL(syslog)(long res, long type, void *buf, long len) {
  1918. if (res >= 0) {
  1919. if (buf)
  1920. POST_WRITE(buf, __sanitizer::internal_strlen((const char *)buf) + 1);
  1921. }
  1922. }
  1923. PRE_SYSCALL(uselib)(const void *library) {
  1924. if (library)
  1925. PRE_READ(library, __sanitizer::internal_strlen((const char *)library) + 1);
  1926. }
  1927. POST_SYSCALL(uselib)(long res, const void *library) {}
  1928. PRE_SYSCALL(ni_syscall)() {}
  1929. POST_SYSCALL(ni_syscall)(long res) {}
  1930. PRE_SYSCALL(ptrace)(long request, long pid, long addr, long data) {
  1931. # if !SANITIZER_ANDROID && \
  1932. (defined(__i386) || defined(__x86_64) || defined(__mips64) || \
  1933. defined(__powerpc64__) || defined(__aarch64__) || defined(__s390__) || \
  1934. defined(__loongarch__) || SANITIZER_RISCV64)
  1935. if (data) {
  1936. if (request == ptrace_setregs) {
  1937. PRE_READ((void *)data, struct_user_regs_struct_sz);
  1938. } else if (request == ptrace_setfpregs) {
  1939. PRE_READ((void *)data, struct_user_fpregs_struct_sz);
  1940. } else if (request == ptrace_setfpxregs) {
  1941. PRE_READ((void *)data, struct_user_fpxregs_struct_sz);
  1942. } else if (request == ptrace_setsiginfo) {
  1943. PRE_READ((void *)data, siginfo_t_sz);
  1944. } else if (request == ptrace_setregset) {
  1945. __sanitizer_iovec *iov = (__sanitizer_iovec *)data;
  1946. PRE_READ(iov->iov_base, iov->iov_len);
  1947. }
  1948. }
  1949. # endif
  1950. }
  1951. POST_SYSCALL(ptrace)(long res, long request, long pid, long addr, long data) {
  1952. # if !SANITIZER_ANDROID && \
  1953. (defined(__i386) || defined(__x86_64) || defined(__mips64) || \
  1954. defined(__powerpc64__) || defined(__aarch64__) || defined(__s390__) || \
  1955. defined(__loongarch__) || SANITIZER_RISCV64)
  1956. if (res >= 0 && data) {
  1957. // Note that this is different from the interceptor in
  1958. // sanitizer_common_interceptors.inc.
  1959. // PEEK* requests return resulting values through data pointer.
  1960. if (request == ptrace_getregs) {
  1961. POST_WRITE((void *)data, struct_user_regs_struct_sz);
  1962. } else if (request == ptrace_getfpregs) {
  1963. POST_WRITE((void *)data, struct_user_fpregs_struct_sz);
  1964. } else if (request == ptrace_getfpxregs) {
  1965. POST_WRITE((void *)data, struct_user_fpxregs_struct_sz);
  1966. } else if (request == ptrace_getsiginfo) {
  1967. POST_WRITE((void *)data, siginfo_t_sz);
  1968. } else if (request == ptrace_getregset) {
  1969. __sanitizer_iovec *iov = (__sanitizer_iovec *)data;
  1970. POST_WRITE(iov->iov_base, iov->iov_len);
  1971. } else if (request == ptrace_peekdata || request == ptrace_peektext ||
  1972. request == ptrace_peekuser) {
  1973. POST_WRITE((void *)data, sizeof(void *));
  1974. }
  1975. }
  1976. # endif
  1977. }
  1978. PRE_SYSCALL(add_key)
  1979. (const void *_type, const void *_description, const void *_payload, long plen,
  1980. long destringid) {
  1981. if (_type)
  1982. PRE_READ(_type, __sanitizer::internal_strlen((const char *)_type) + 1);
  1983. if (_description)
  1984. PRE_READ(_description,
  1985. __sanitizer::internal_strlen((const char *)_description) + 1);
  1986. }
  1987. POST_SYSCALL(add_key)
  1988. (long res, const void *_type, const void *_description, const void *_payload,
  1989. long plen, long destringid) {}
  1990. PRE_SYSCALL(request_key)
  1991. (const void *_type, const void *_description, const void *_callout_info,
  1992. long destringid) {
  1993. if (_type)
  1994. PRE_READ(_type, __sanitizer::internal_strlen((const char *)_type) + 1);
  1995. if (_description)
  1996. PRE_READ(_description,
  1997. __sanitizer::internal_strlen((const char *)_description) + 1);
  1998. if (_callout_info)
  1999. PRE_READ(_callout_info,
  2000. __sanitizer::internal_strlen((const char *)_callout_info) + 1);
  2001. }
  2002. POST_SYSCALL(request_key)
  2003. (long res, const void *_type, const void *_description,
  2004. const void *_callout_info, long destringid) {}
  2005. PRE_SYSCALL(keyctl)(long cmd, long arg2, long arg3, long arg4, long arg5) {}
  2006. POST_SYSCALL(keyctl)
  2007. (long res, long cmd, long arg2, long arg3, long arg4, long arg5) {}
  2008. PRE_SYSCALL(ioprio_set)(long which, long who, long ioprio) {}
  2009. POST_SYSCALL(ioprio_set)(long res, long which, long who, long ioprio) {}
  2010. PRE_SYSCALL(ioprio_get)(long which, long who) {}
  2011. POST_SYSCALL(ioprio_get)(long res, long which, long who) {}
  2012. PRE_SYSCALL(set_mempolicy)(long mode, void *nmask, long maxnode) {}
  2013. POST_SYSCALL(set_mempolicy)(long res, long mode, void *nmask, long maxnode) {
  2014. if (res >= 0) {
  2015. if (nmask)
  2016. POST_WRITE(nmask, sizeof(long));
  2017. }
  2018. }
  2019. PRE_SYSCALL(migrate_pages)
  2020. (long pid, long maxnode, const void *from, const void *to) {
  2021. if (from)
  2022. PRE_READ(from, sizeof(long));
  2023. if (to)
  2024. PRE_READ(to, sizeof(long));
  2025. }
  2026. POST_SYSCALL(migrate_pages)
  2027. (long res, long pid, long maxnode, const void *from, const void *to) {}
  2028. PRE_SYSCALL(move_pages)
  2029. (long pid, long nr_pages, const void **pages, const int *nodes, int *status,
  2030. long flags) {
  2031. if (pages)
  2032. PRE_READ(pages, nr_pages * sizeof(*pages));
  2033. if (nodes)
  2034. PRE_READ(nodes, nr_pages * sizeof(*nodes));
  2035. }
  2036. POST_SYSCALL(move_pages)
  2037. (long res, long pid, long nr_pages, const void **pages, const int *nodes,
  2038. int *status, long flags) {
  2039. if (res >= 0) {
  2040. if (status)
  2041. POST_WRITE(status, nr_pages * sizeof(*status));
  2042. }
  2043. }
  2044. PRE_SYSCALL(mbind)
  2045. (long start, long len, long mode, void *nmask, long maxnode, long flags) {}
  2046. POST_SYSCALL(mbind)
  2047. (long res, long start, long len, long mode, void *nmask, long maxnode,
  2048. long flags) {
  2049. if (res >= 0) {
  2050. if (nmask)
  2051. POST_WRITE(nmask, sizeof(long));
  2052. }
  2053. }
  2054. PRE_SYSCALL(get_mempolicy)
  2055. (void *policy, void *nmask, long maxnode, long addr, long flags) {}
  2056. POST_SYSCALL(get_mempolicy)
  2057. (long res, void *policy, void *nmask, long maxnode, long addr, long flags) {
  2058. if (res >= 0) {
  2059. if (policy)
  2060. POST_WRITE(policy, sizeof(int));
  2061. if (nmask)
  2062. POST_WRITE(nmask, sizeof(long));
  2063. }
  2064. }
  2065. PRE_SYSCALL(inotify_init)() {}
  2066. POST_SYSCALL(inotify_init)(long res) {}
  2067. PRE_SYSCALL(inotify_init1)(long flags) {}
  2068. POST_SYSCALL(inotify_init1)(long res, long flags) {}
  2069. PRE_SYSCALL(inotify_add_watch)(long fd, const void *path, long mask) {
  2070. if (path)
  2071. PRE_READ(path, __sanitizer::internal_strlen((const char *)path) + 1);
  2072. }
  2073. POST_SYSCALL(inotify_add_watch)
  2074. (long res, long fd, const void *path, long mask) {}
  2075. PRE_SYSCALL(inotify_rm_watch)(long fd, long wd) {}
  2076. POST_SYSCALL(inotify_rm_watch)(long res, long fd, long wd) {}
  2077. PRE_SYSCALL(spu_run)(long fd, void *unpc, void *ustatus) {}
  2078. POST_SYSCALL(spu_run)(long res, long fd, unsigned *unpc, unsigned *ustatus) {
  2079. if (res >= 0) {
  2080. if (unpc)
  2081. POST_WRITE(unpc, sizeof(*unpc));
  2082. if (ustatus)
  2083. POST_WRITE(ustatus, sizeof(*ustatus));
  2084. }
  2085. }
  2086. PRE_SYSCALL(spu_create)(const void *name, long flags, long mode, long fd) {
  2087. if (name)
  2088. PRE_READ(name, __sanitizer::internal_strlen((const char *)name) + 1);
  2089. }
  2090. POST_SYSCALL(spu_create)
  2091. (long res, const void *name, long flags, long mode, long fd) {}
  2092. PRE_SYSCALL(mknodat)(long dfd, const void *filename, long mode, long dev) {
  2093. if (filename)
  2094. PRE_READ(filename,
  2095. __sanitizer::internal_strlen((const char *)filename) + 1);
  2096. }
  2097. POST_SYSCALL(mknodat)
  2098. (long res, long dfd, const void *filename, long mode, long dev) {}
  2099. PRE_SYSCALL(mkdirat)(long dfd, const void *pathname, long mode) {
  2100. if (pathname)
  2101. PRE_READ(pathname,
  2102. __sanitizer::internal_strlen((const char *)pathname) + 1);
  2103. }
  2104. POST_SYSCALL(mkdirat)(long res, long dfd, const void *pathname, long mode) {}
  2105. PRE_SYSCALL(unlinkat)(long dfd, const void *pathname, long flag) {
  2106. if (pathname)
  2107. PRE_READ(pathname,
  2108. __sanitizer::internal_strlen((const char *)pathname) + 1);
  2109. }
  2110. POST_SYSCALL(unlinkat)(long res, long dfd, const void *pathname, long flag) {}
  2111. PRE_SYSCALL(symlinkat)(const void *oldname, long newdfd, const void *newname) {
  2112. if (oldname)
  2113. PRE_READ(oldname, __sanitizer::internal_strlen((const char *)oldname) + 1);
  2114. if (newname)
  2115. PRE_READ(newname, __sanitizer::internal_strlen((const char *)newname) + 1);
  2116. }
  2117. POST_SYSCALL(symlinkat)
  2118. (long res, const void *oldname, long newdfd, const void *newname) {}
  2119. PRE_SYSCALL(linkat)
  2120. (long olddfd, const void *oldname, long newdfd, const void *newname,
  2121. long flags) {
  2122. if (oldname)
  2123. PRE_READ(oldname, __sanitizer::internal_strlen((const char *)oldname) + 1);
  2124. if (newname)
  2125. PRE_READ(newname, __sanitizer::internal_strlen((const char *)newname) + 1);
  2126. }
  2127. POST_SYSCALL(linkat)
  2128. (long res, long olddfd, const void *oldname, long newdfd, const void *newname,
  2129. long flags) {}
  2130. PRE_SYSCALL(renameat)
  2131. (long olddfd, const void *oldname, long newdfd, const void *newname) {
  2132. if (oldname)
  2133. PRE_READ(oldname, __sanitizer::internal_strlen((const char *)oldname) + 1);
  2134. if (newname)
  2135. PRE_READ(newname, __sanitizer::internal_strlen((const char *)newname) + 1);
  2136. }
  2137. POST_SYSCALL(renameat)
  2138. (long res, long olddfd, const void *oldname, long newdfd, const void *newname) {
  2139. }
  2140. PRE_SYSCALL(futimesat)(long dfd, const void *filename, void *utimes) {
  2141. if (filename)
  2142. PRE_READ(filename,
  2143. __sanitizer::internal_strlen((const char *)filename) + 1);
  2144. }
  2145. POST_SYSCALL(futimesat)
  2146. (long res, long dfd, const void *filename, void *utimes) {
  2147. if (res >= 0) {
  2148. if (utimes)
  2149. POST_WRITE(utimes, timeval_sz);
  2150. }
  2151. }
  2152. PRE_SYSCALL(faccessat)(long dfd, const void *filename, long mode) {
  2153. if (filename)
  2154. PRE_READ(filename,
  2155. __sanitizer::internal_strlen((const char *)filename) + 1);
  2156. }
  2157. POST_SYSCALL(faccessat)(long res, long dfd, const void *filename, long mode) {}
  2158. PRE_SYSCALL(fchmodat)(long dfd, const void *filename, long mode) {
  2159. if (filename)
  2160. PRE_READ(filename,
  2161. __sanitizer::internal_strlen((const char *)filename) + 1);
  2162. }
  2163. POST_SYSCALL(fchmodat)(long res, long dfd, const void *filename, long mode) {}
  2164. PRE_SYSCALL(fchownat)
  2165. (long dfd, const void *filename, long user, long group, long flag) {
  2166. if (filename)
  2167. PRE_READ(filename,
  2168. __sanitizer::internal_strlen((const char *)filename) + 1);
  2169. }
  2170. POST_SYSCALL(fchownat)
  2171. (long res, long dfd, const void *filename, long user, long group, long flag) {}
  2172. PRE_SYSCALL(openat)(long dfd, const void *filename, long flags, long mode) {
  2173. if (filename)
  2174. PRE_READ(filename,
  2175. __sanitizer::internal_strlen((const char *)filename) + 1);
  2176. }
  2177. POST_SYSCALL(openat)
  2178. (long res, long dfd, const void *filename, long flags, long mode) {}
  2179. PRE_SYSCALL(newfstatat)
  2180. (long dfd, const void *filename, void *statbuf, long flag) {
  2181. if (filename)
  2182. PRE_READ(filename,
  2183. __sanitizer::internal_strlen((const char *)filename) + 1);
  2184. }
  2185. POST_SYSCALL(newfstatat)
  2186. (long res, long dfd, const void *filename, void *statbuf, long flag) {
  2187. if (res >= 0) {
  2188. if (statbuf)
  2189. POST_WRITE(statbuf, struct_kernel_stat_sz);
  2190. }
  2191. }
  2192. PRE_SYSCALL(fstatat64)
  2193. (long dfd, const void *filename, void *statbuf, long flag) {
  2194. if (filename)
  2195. PRE_READ(filename,
  2196. __sanitizer::internal_strlen((const char *)filename) + 1);
  2197. }
  2198. POST_SYSCALL(fstatat64)
  2199. (long res, long dfd, const void *filename, void *statbuf, long flag) {
  2200. if (res >= 0) {
  2201. if (statbuf)
  2202. POST_WRITE(statbuf, struct_kernel_stat64_sz);
  2203. }
  2204. }
  2205. PRE_SYSCALL(readlinkat)(long dfd, const void *path, void *buf, long bufsiz) {
  2206. if (path)
  2207. PRE_READ(path, __sanitizer::internal_strlen((const char *)path) + 1);
  2208. }
  2209. POST_SYSCALL(readlinkat)
  2210. (long res, long dfd, const void *path, void *buf, long bufsiz) {
  2211. if (res >= 0) {
  2212. if (buf)
  2213. POST_WRITE(buf, __sanitizer::internal_strlen((const char *)buf) + 1);
  2214. }
  2215. }
  2216. PRE_SYSCALL(utimensat)
  2217. (long dfd, const void *filename, void *utimes, long flags) {
  2218. if (filename)
  2219. PRE_READ(filename,
  2220. __sanitizer::internal_strlen((const char *)filename) + 1);
  2221. }
  2222. POST_SYSCALL(utimensat)
  2223. (long res, long dfd, const void *filename, void *utimes, long flags) {
  2224. if (res >= 0) {
  2225. if (utimes)
  2226. POST_WRITE(utimes, struct_timespec_sz);
  2227. }
  2228. }
  2229. PRE_SYSCALL(unshare)(long unshare_flags) {}
  2230. POST_SYSCALL(unshare)(long res, long unshare_flags) {}
  2231. PRE_SYSCALL(splice)
  2232. (long fd_in, void *off_in, long fd_out, void *off_out, long len, long flags) {}
  2233. POST_SYSCALL(splice)
  2234. (long res, long fd_in, void *off_in, long fd_out, void *off_out, long len,
  2235. long flags) {
  2236. if (res >= 0) {
  2237. if (off_in)
  2238. POST_WRITE(off_in, sizeof(long long));
  2239. if (off_out)
  2240. POST_WRITE(off_out, sizeof(long long));
  2241. }
  2242. }
  2243. PRE_SYSCALL(vmsplice)
  2244. (long fd, const __sanitizer_iovec *iov, long nr_segs, long flags) {}
  2245. POST_SYSCALL(vmsplice)
  2246. (long res, long fd, const __sanitizer_iovec *iov, long nr_segs, long flags) {
  2247. if (res >= 0) {
  2248. if (iov)
  2249. kernel_read_iovec(iov, nr_segs, res);
  2250. }
  2251. }
  2252. PRE_SYSCALL(tee)(long fdin, long fdout, long len, long flags) {}
  2253. POST_SYSCALL(tee)(long res, long fdin, long fdout, long len, long flags) {}
  2254. PRE_SYSCALL(get_robust_list)(long pid, void *head_ptr, void *len_ptr) {}
  2255. POST_SYSCALL(get_robust_list)
  2256. (long res, long pid, void *head_ptr, void *len_ptr) {}
  2257. PRE_SYSCALL(set_robust_list)(void *head, long len) {}
  2258. POST_SYSCALL(set_robust_list)(long res, void *head, long len) {}
  2259. PRE_SYSCALL(getcpu)(void *cpu, void *node, void *cache) {}
  2260. POST_SYSCALL(getcpu)(long res, void *cpu, void *node, void *cache) {
  2261. if (res >= 0) {
  2262. if (cpu)
  2263. POST_WRITE(cpu, sizeof(unsigned));
  2264. if (node)
  2265. POST_WRITE(node, sizeof(unsigned));
  2266. // The third argument to this system call is nowadays unused.
  2267. }
  2268. }
  2269. PRE_SYSCALL(signalfd)(long ufd, void *user_mask, long sizemask) {}
  2270. POST_SYSCALL(signalfd)
  2271. (long res, long ufd, kernel_sigset_t *user_mask, long sizemask) {
  2272. if (res >= 0) {
  2273. if (user_mask)
  2274. POST_WRITE(user_mask, sizemask);
  2275. }
  2276. }
  2277. PRE_SYSCALL(signalfd4)(long ufd, void *user_mask, long sizemask, long flags) {}
  2278. POST_SYSCALL(signalfd4)
  2279. (long res, long ufd, kernel_sigset_t *user_mask, long sizemask, long flags) {
  2280. if (res >= 0) {
  2281. if (user_mask)
  2282. POST_WRITE(user_mask, sizemask);
  2283. }
  2284. }
  2285. PRE_SYSCALL(timerfd_create)(long clockid, long flags) {}
  2286. POST_SYSCALL(timerfd_create)(long res, long clockid, long flags) {}
  2287. PRE_SYSCALL(timerfd_settime)
  2288. (long ufd, long flags, const void *utmr, void *otmr) {
  2289. if (utmr)
  2290. PRE_READ(utmr, struct_itimerspec_sz);
  2291. }
  2292. POST_SYSCALL(timerfd_settime)
  2293. (long res, long ufd, long flags, const void *utmr, void *otmr) {
  2294. if (res >= 0) {
  2295. if (otmr)
  2296. POST_WRITE(otmr, struct_itimerspec_sz);
  2297. }
  2298. }
  2299. PRE_SYSCALL(timerfd_gettime)(long ufd, void *otmr) {}
  2300. POST_SYSCALL(timerfd_gettime)(long res, long ufd, void *otmr) {
  2301. if (res >= 0) {
  2302. if (otmr)
  2303. POST_WRITE(otmr, struct_itimerspec_sz);
  2304. }
  2305. }
  2306. PRE_SYSCALL(eventfd)(long count) {}
  2307. POST_SYSCALL(eventfd)(long res, long count) {}
  2308. PRE_SYSCALL(eventfd2)(long count, long flags) {}
  2309. POST_SYSCALL(eventfd2)(long res, long count, long flags) {}
  2310. PRE_SYSCALL(old_readdir)(long arg0, void *arg1, long arg2) {}
  2311. POST_SYSCALL(old_readdir)(long res, long arg0, void *arg1, long arg2) {
  2312. // Missing definition of 'struct old_linux_dirent'.
  2313. }
  2314. PRE_SYSCALL(pselect6)
  2315. (long arg0, __sanitizer___kernel_fd_set *arg1,
  2316. __sanitizer___kernel_fd_set *arg2, __sanitizer___kernel_fd_set *arg3,
  2317. void *arg4, void *arg5) {}
  2318. POST_SYSCALL(pselect6)
  2319. (long res, long arg0, __sanitizer___kernel_fd_set *arg1,
  2320. __sanitizer___kernel_fd_set *arg2, __sanitizer___kernel_fd_set *arg3,
  2321. void *arg4, void *arg5) {
  2322. if (res >= 0) {
  2323. if (arg1)
  2324. POST_WRITE(arg1, sizeof(*arg1));
  2325. if (arg2)
  2326. POST_WRITE(arg2, sizeof(*arg2));
  2327. if (arg3)
  2328. POST_WRITE(arg3, sizeof(*arg3));
  2329. if (arg4)
  2330. POST_WRITE(arg4, struct_timespec_sz);
  2331. }
  2332. }
  2333. PRE_SYSCALL(ppoll)
  2334. (__sanitizer_pollfd *arg0, long arg1, void *arg2, const kernel_sigset_t *arg3,
  2335. long arg4) {
  2336. if (arg3)
  2337. PRE_READ(arg3, arg4);
  2338. }
  2339. POST_SYSCALL(ppoll)
  2340. (long res, __sanitizer_pollfd *arg0, long arg1, void *arg2, const void *arg3,
  2341. long arg4) {
  2342. if (res >= 0) {
  2343. if (arg0)
  2344. POST_WRITE(arg0, sizeof(*arg0));
  2345. if (arg2)
  2346. POST_WRITE(arg2, struct_timespec_sz);
  2347. }
  2348. }
  2349. PRE_SYSCALL(syncfs)(long fd) {}
  2350. POST_SYSCALL(syncfs)(long res, long fd) {}
  2351. PRE_SYSCALL(perf_event_open)
  2352. (__sanitizer_perf_event_attr *attr_uptr, long pid, long cpu, long group_fd,
  2353. long flags) {
  2354. if (attr_uptr)
  2355. PRE_READ(attr_uptr, attr_uptr->size);
  2356. }
  2357. POST_SYSCALL(perf_event_open)
  2358. (long res, __sanitizer_perf_event_attr *attr_uptr, long pid, long cpu,
  2359. long group_fd, long flags) {}
  2360. PRE_SYSCALL(mmap_pgoff)
  2361. (long addr, long len, long prot, long flags, long fd, long pgoff) {}
  2362. POST_SYSCALL(mmap_pgoff)
  2363. (long res, long addr, long len, long prot, long flags, long fd, long pgoff) {}
  2364. PRE_SYSCALL(old_mmap)(void *arg) {}
  2365. POST_SYSCALL(old_mmap)(long res, void *arg) {}
  2366. PRE_SYSCALL(name_to_handle_at)
  2367. (long dfd, const void *name, void *handle, void *mnt_id, long flag) {}
  2368. POST_SYSCALL(name_to_handle_at)
  2369. (long res, long dfd, const void *name, void *handle, void *mnt_id, long flag) {}
  2370. PRE_SYSCALL(open_by_handle_at)(long mountdirfd, void *handle, long flags) {}
  2371. POST_SYSCALL(open_by_handle_at)
  2372. (long res, long mountdirfd, void *handle, long flags) {}
  2373. PRE_SYSCALL(setns)(long fd, long nstype) {}
  2374. POST_SYSCALL(setns)(long res, long fd, long nstype) {}
  2375. PRE_SYSCALL(process_vm_readv)
  2376. (long pid, const __sanitizer_iovec *lvec, long liovcnt, const void *rvec,
  2377. long riovcnt, long flags) {}
  2378. POST_SYSCALL(process_vm_readv)
  2379. (long res, long pid, const __sanitizer_iovec *lvec, long liovcnt,
  2380. const void *rvec, long riovcnt, long flags) {
  2381. if (res >= 0) {
  2382. if (lvec)
  2383. kernel_write_iovec(lvec, liovcnt, res);
  2384. }
  2385. }
  2386. PRE_SYSCALL(process_vm_writev)
  2387. (long pid, const __sanitizer_iovec *lvec, long liovcnt, const void *rvec,
  2388. long riovcnt, long flags) {}
  2389. POST_SYSCALL(process_vm_writev)
  2390. (long res, long pid, const __sanitizer_iovec *lvec, long liovcnt,
  2391. const void *rvec, long riovcnt, long flags) {
  2392. if (res >= 0) {
  2393. if (lvec)
  2394. kernel_read_iovec(lvec, liovcnt, res);
  2395. }
  2396. }
  2397. PRE_SYSCALL(fork)() { COMMON_SYSCALL_PRE_FORK(); }
  2398. POST_SYSCALL(fork)(long res) { COMMON_SYSCALL_POST_FORK(res); }
  2399. PRE_SYSCALL(vfork)() { COMMON_SYSCALL_PRE_FORK(); }
  2400. POST_SYSCALL(vfork)(long res) { COMMON_SYSCALL_POST_FORK(res); }
  2401. PRE_SYSCALL(sigaction)
  2402. (long signum, const __sanitizer_kernel_sigaction_t *act,
  2403. __sanitizer_kernel_sigaction_t *oldact) {
  2404. if (act) {
  2405. PRE_READ(&act->sigaction, sizeof(act->sigaction));
  2406. PRE_READ(&act->sa_flags, sizeof(act->sa_flags));
  2407. PRE_READ(&act->sa_mask, sizeof(act->sa_mask));
  2408. }
  2409. }
  2410. POST_SYSCALL(sigaction)
  2411. (long res, long signum, const __sanitizer_kernel_sigaction_t *act,
  2412. __sanitizer_kernel_sigaction_t *oldact) {
  2413. if (res >= 0 && oldact)
  2414. POST_WRITE(oldact, sizeof(*oldact));
  2415. }
  2416. PRE_SYSCALL(rt_sigaction)
  2417. (long signum, const __sanitizer_kernel_sigaction_t *act,
  2418. __sanitizer_kernel_sigaction_t *oldact, SIZE_T sz) {
  2419. if (act) {
  2420. PRE_READ(&act->sigaction, sizeof(act->sigaction));
  2421. PRE_READ(&act->sa_flags, sizeof(act->sa_flags));
  2422. PRE_READ(&act->sa_mask, sz);
  2423. }
  2424. }
  2425. POST_SYSCALL(rt_sigaction)
  2426. (long res, long signum, const __sanitizer_kernel_sigaction_t *act,
  2427. __sanitizer_kernel_sigaction_t *oldact, SIZE_T sz) {
  2428. if (res >= 0 && oldact) {
  2429. SIZE_T oldact_sz = ((char *)&oldact->sa_mask) - ((char *)oldact) + sz;
  2430. POST_WRITE(oldact, oldact_sz);
  2431. }
  2432. }
  2433. PRE_SYSCALL(getrandom)(void *buf, uptr count, long flags) {
  2434. if (buf) {
  2435. PRE_WRITE(buf, count);
  2436. }
  2437. }
  2438. POST_SYSCALL(getrandom)(long res, void *buf, uptr count, long flags) {
  2439. if (res > 0 && buf) {
  2440. POST_WRITE(buf, res);
  2441. }
  2442. }
  2443. PRE_SYSCALL(sigaltstack)(const void *ss, void *oss) {
  2444. if (ss != nullptr) {
  2445. PRE_READ(ss, struct_stack_t_sz);
  2446. }
  2447. if (oss != nullptr) {
  2448. PRE_WRITE(oss, struct_stack_t_sz);
  2449. }
  2450. }
  2451. POST_SYSCALL(sigaltstack)(long res, void *ss, void *oss) {
  2452. if (res == 0) {
  2453. if (oss != nullptr) {
  2454. POST_WRITE(oss, struct_stack_t_sz);
  2455. }
  2456. }
  2457. }
  2458. } // extern "C"
  2459. # undef PRE_SYSCALL
  2460. # undef PRE_READ
  2461. # undef PRE_WRITE
  2462. # undef POST_SYSCALL
  2463. # undef POST_READ
  2464. # undef POST_WRITE
  2465. #endif // SANITIZER_LINUX