sanitizer_common_syscalls.inc 83 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175
  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(statfs64)(const void *path, long sz, void *buf) {
  689. if (path)
  690. PRE_READ(path, __sanitizer::internal_strlen((const char *)path) + 1);
  691. }
  692. POST_SYSCALL(statfs64)(long res, const void *path, long sz, void *buf) {
  693. if (res >= 0) {
  694. if (buf)
  695. POST_WRITE(buf, struct_statfs64_sz);
  696. }
  697. }
  698. PRE_SYSCALL(fstatfs)(long fd, void *buf) {}
  699. POST_SYSCALL(fstatfs)(long res, long fd, void *buf) {
  700. if (res >= 0) {
  701. if (buf)
  702. POST_WRITE(buf, struct_statfs_sz);
  703. }
  704. }
  705. PRE_SYSCALL(fstatfs64)(long fd, long sz, void *buf) {}
  706. POST_SYSCALL(fstatfs64)(long res, long fd, long sz, void *buf) {
  707. if (res >= 0) {
  708. if (buf)
  709. POST_WRITE(buf, struct_statfs64_sz);
  710. }
  711. }
  712. # endif // !SANITIZER_ANDROID
  713. PRE_SYSCALL(lstat)(const void *filename, void *statbuf) {
  714. if (filename)
  715. PRE_READ(filename,
  716. __sanitizer::internal_strlen((const char *)filename) + 1);
  717. }
  718. POST_SYSCALL(lstat)(long res, const void *filename, void *statbuf) {
  719. if (res >= 0) {
  720. if (statbuf)
  721. POST_WRITE(statbuf, struct___old_kernel_stat_sz);
  722. }
  723. }
  724. PRE_SYSCALL(fstat)(long fd, void *statbuf) {}
  725. POST_SYSCALL(fstat)(long res, long fd, void *statbuf) {
  726. if (res >= 0) {
  727. if (statbuf)
  728. POST_WRITE(statbuf, struct___old_kernel_stat_sz);
  729. }
  730. }
  731. PRE_SYSCALL(newstat)(const void *filename, void *statbuf) {
  732. if (filename)
  733. PRE_READ(filename,
  734. __sanitizer::internal_strlen((const char *)filename) + 1);
  735. }
  736. POST_SYSCALL(newstat)(long res, const void *filename, void *statbuf) {
  737. if (res >= 0) {
  738. if (statbuf)
  739. POST_WRITE(statbuf, struct_kernel_stat_sz);
  740. }
  741. }
  742. PRE_SYSCALL(newlstat)(const void *filename, void *statbuf) {
  743. if (filename)
  744. PRE_READ(filename,
  745. __sanitizer::internal_strlen((const char *)filename) + 1);
  746. }
  747. POST_SYSCALL(newlstat)(long res, const void *filename, void *statbuf) {
  748. if (res >= 0) {
  749. if (statbuf)
  750. POST_WRITE(statbuf, struct_kernel_stat_sz);
  751. }
  752. }
  753. PRE_SYSCALL(newfstat)(long fd, void *statbuf) {}
  754. POST_SYSCALL(newfstat)(long res, long fd, void *statbuf) {
  755. if (res >= 0) {
  756. if (statbuf)
  757. POST_WRITE(statbuf, struct_kernel_stat_sz);
  758. }
  759. }
  760. # if !SANITIZER_ANDROID
  761. PRE_SYSCALL(ustat)(long dev, void *ubuf) {}
  762. POST_SYSCALL(ustat)(long res, long dev, void *ubuf) {
  763. if (res >= 0) {
  764. if (ubuf)
  765. POST_WRITE(ubuf, struct_ustat_sz);
  766. }
  767. }
  768. # endif // !SANITIZER_ANDROID
  769. PRE_SYSCALL(stat64)(const void *filename, void *statbuf) {
  770. if (filename)
  771. PRE_READ(filename,
  772. __sanitizer::internal_strlen((const char *)filename) + 1);
  773. }
  774. POST_SYSCALL(stat64)(long res, const void *filename, void *statbuf) {
  775. if (res >= 0) {
  776. if (statbuf)
  777. POST_WRITE(statbuf, struct_kernel_stat64_sz);
  778. }
  779. }
  780. PRE_SYSCALL(fstat64)(long fd, void *statbuf) {}
  781. POST_SYSCALL(fstat64)(long res, long fd, void *statbuf) {
  782. if (res >= 0) {
  783. if (statbuf)
  784. POST_WRITE(statbuf, struct_kernel_stat64_sz);
  785. }
  786. }
  787. PRE_SYSCALL(lstat64)(const void *filename, void *statbuf) {
  788. if (filename)
  789. PRE_READ(filename,
  790. __sanitizer::internal_strlen((const char *)filename) + 1);
  791. }
  792. POST_SYSCALL(lstat64)(long res, const void *filename, void *statbuf) {
  793. if (res >= 0) {
  794. if (statbuf)
  795. POST_WRITE(statbuf, struct_kernel_stat64_sz);
  796. }
  797. }
  798. PRE_SYSCALL(setxattr)
  799. (const void *path, const void *name, const void *value, long size, long flags) {
  800. if (path)
  801. PRE_READ(path, __sanitizer::internal_strlen((const char *)path) + 1);
  802. if (name)
  803. PRE_READ(name, __sanitizer::internal_strlen((const char *)name) + 1);
  804. if (value)
  805. PRE_READ(value, size);
  806. }
  807. POST_SYSCALL(setxattr)
  808. (long res, const void *path, const void *name, const void *value, long size,
  809. long flags) {}
  810. PRE_SYSCALL(lsetxattr)
  811. (const void *path, const void *name, const void *value, long size, long flags) {
  812. if (path)
  813. PRE_READ(path, __sanitizer::internal_strlen((const char *)path) + 1);
  814. if (name)
  815. PRE_READ(name, __sanitizer::internal_strlen((const char *)name) + 1);
  816. if (value)
  817. PRE_READ(value, size);
  818. }
  819. POST_SYSCALL(lsetxattr)
  820. (long res, const void *path, const void *name, const void *value, long size,
  821. long flags) {}
  822. PRE_SYSCALL(fsetxattr)
  823. (long fd, const void *name, const void *value, long size, long flags) {
  824. if (name)
  825. PRE_READ(name, __sanitizer::internal_strlen((const char *)name) + 1);
  826. if (value)
  827. PRE_READ(value, size);
  828. }
  829. POST_SYSCALL(fsetxattr)
  830. (long res, long fd, const void *name, const void *value, long size,
  831. long flags) {}
  832. PRE_SYSCALL(getxattr)
  833. (const void *path, const void *name, void *value, long size) {
  834. if (path)
  835. PRE_READ(path, __sanitizer::internal_strlen((const char *)path) + 1);
  836. if (name)
  837. PRE_READ(name, __sanitizer::internal_strlen((const char *)name) + 1);
  838. }
  839. POST_SYSCALL(getxattr)
  840. (long res, const void *path, const void *name, void *value, long size) {
  841. if (size && res > 0) {
  842. if (value)
  843. POST_WRITE(value, res);
  844. }
  845. }
  846. PRE_SYSCALL(lgetxattr)
  847. (const void *path, const void *name, void *value, long size) {
  848. if (path)
  849. PRE_READ(path, __sanitizer::internal_strlen((const char *)path) + 1);
  850. if (name)
  851. PRE_READ(name, __sanitizer::internal_strlen((const char *)name) + 1);
  852. }
  853. POST_SYSCALL(lgetxattr)
  854. (long res, const void *path, const void *name, void *value, long size) {
  855. if (size && res > 0) {
  856. if (value)
  857. POST_WRITE(value, res);
  858. }
  859. }
  860. PRE_SYSCALL(fgetxattr)(long fd, const void *name, void *value, long size) {
  861. if (name)
  862. PRE_READ(name, __sanitizer::internal_strlen((const char *)name) + 1);
  863. }
  864. POST_SYSCALL(fgetxattr)
  865. (long res, long fd, const void *name, void *value, long size) {
  866. if (size && res > 0) {
  867. if (value)
  868. POST_WRITE(value, res);
  869. }
  870. }
  871. PRE_SYSCALL(listxattr)(const void *path, void *list, long size) {
  872. if (path)
  873. PRE_READ(path, __sanitizer::internal_strlen((const char *)path) + 1);
  874. }
  875. POST_SYSCALL(listxattr)(long res, const void *path, void *list, long size) {
  876. if (size && res > 0) {
  877. if (list)
  878. POST_WRITE(list, res);
  879. }
  880. }
  881. PRE_SYSCALL(llistxattr)(const void *path, void *list, long size) {
  882. if (path)
  883. PRE_READ(path, __sanitizer::internal_strlen((const char *)path) + 1);
  884. }
  885. POST_SYSCALL(llistxattr)(long res, const void *path, void *list, long size) {
  886. if (size && res > 0) {
  887. if (list)
  888. POST_WRITE(list, res);
  889. }
  890. }
  891. PRE_SYSCALL(flistxattr)(long fd, void *list, long size) {}
  892. POST_SYSCALL(flistxattr)(long res, long fd, void *list, long size) {
  893. if (size && res > 0) {
  894. if (list)
  895. POST_WRITE(list, res);
  896. }
  897. }
  898. PRE_SYSCALL(removexattr)(const void *path, const void *name) {
  899. if (path)
  900. PRE_READ(path, __sanitizer::internal_strlen((const char *)path) + 1);
  901. if (name)
  902. PRE_READ(name, __sanitizer::internal_strlen((const char *)name) + 1);
  903. }
  904. POST_SYSCALL(removexattr)(long res, const void *path, const void *name) {}
  905. PRE_SYSCALL(lremovexattr)(const void *path, const void *name) {
  906. if (path)
  907. PRE_READ(path, __sanitizer::internal_strlen((const char *)path) + 1);
  908. if (name)
  909. PRE_READ(name, __sanitizer::internal_strlen((const char *)name) + 1);
  910. }
  911. POST_SYSCALL(lremovexattr)(long res, const void *path, const void *name) {}
  912. PRE_SYSCALL(fremovexattr)(long fd, const void *name) {
  913. if (name)
  914. PRE_READ(name, __sanitizer::internal_strlen((const char *)name) + 1);
  915. }
  916. POST_SYSCALL(fremovexattr)(long res, long fd, const void *name) {}
  917. PRE_SYSCALL(brk)(long brk) {}
  918. POST_SYSCALL(brk)(long res, long brk) {}
  919. PRE_SYSCALL(mprotect)(long start, long len, long prot) {}
  920. POST_SYSCALL(mprotect)(long res, long start, long len, long prot) {}
  921. PRE_SYSCALL(mremap)
  922. (long addr, long old_len, long new_len, long flags, long new_addr) {}
  923. POST_SYSCALL(mremap)
  924. (long res, long addr, long old_len, long new_len, long flags, long new_addr) {}
  925. PRE_SYSCALL(remap_file_pages)
  926. (long start, long size, long prot, long pgoff, long flags) {}
  927. POST_SYSCALL(remap_file_pages)
  928. (long res, long start, long size, long prot, long pgoff, long flags) {}
  929. PRE_SYSCALL(msync)(long start, long len, long flags) {}
  930. POST_SYSCALL(msync)(long res, long start, long len, long flags) {}
  931. PRE_SYSCALL(munmap)(long addr, long len) {}
  932. POST_SYSCALL(munmap)(long res, long addr, long len) {}
  933. PRE_SYSCALL(mlock)(long start, long len) {}
  934. POST_SYSCALL(mlock)(long res, long start, long len) {}
  935. PRE_SYSCALL(munlock)(long start, long len) {}
  936. POST_SYSCALL(munlock)(long res, long start, long len) {}
  937. PRE_SYSCALL(mlockall)(long flags) {}
  938. POST_SYSCALL(mlockall)(long res, long flags) {}
  939. PRE_SYSCALL(munlockall)() {}
  940. POST_SYSCALL(munlockall)(long res) {}
  941. PRE_SYSCALL(madvise)(long start, long len, long behavior) {}
  942. POST_SYSCALL(madvise)(long res, long start, long len, long behavior) {}
  943. PRE_SYSCALL(mincore)(long start, long len, void *vec) {}
  944. POST_SYSCALL(mincore)(long res, long start, long len, void *vec) {
  945. if (res >= 0) {
  946. if (vec) {
  947. POST_WRITE(vec, (len + GetPageSizeCached() - 1) / GetPageSizeCached());
  948. }
  949. }
  950. }
  951. PRE_SYSCALL(pivot_root)(const void *new_root, const void *put_old) {
  952. if (new_root)
  953. PRE_READ(new_root,
  954. __sanitizer::internal_strlen((const char *)new_root) + 1);
  955. if (put_old)
  956. PRE_READ(put_old, __sanitizer::internal_strlen((const char *)put_old) + 1);
  957. }
  958. POST_SYSCALL(pivot_root)(long res, const void *new_root, const void *put_old) {}
  959. PRE_SYSCALL(chroot)(const void *filename) {
  960. if (filename)
  961. PRE_READ(filename,
  962. __sanitizer::internal_strlen((const char *)filename) + 1);
  963. }
  964. POST_SYSCALL(chroot)(long res, const void *filename) {}
  965. PRE_SYSCALL(mknod)(const void *filename, long mode, long dev) {
  966. if (filename)
  967. PRE_READ(filename,
  968. __sanitizer::internal_strlen((const char *)filename) + 1);
  969. }
  970. POST_SYSCALL(mknod)(long res, const void *filename, long mode, long dev) {}
  971. PRE_SYSCALL(link)(const void *oldname, const void *newname) {
  972. if (oldname)
  973. PRE_READ(oldname, __sanitizer::internal_strlen((const char *)oldname) + 1);
  974. if (newname)
  975. PRE_READ(newname, __sanitizer::internal_strlen((const char *)newname) + 1);
  976. }
  977. POST_SYSCALL(link)(long res, const void *oldname, const void *newname) {}
  978. PRE_SYSCALL(symlink)(const void *old, const void *new_) {
  979. if (old)
  980. PRE_READ(old, __sanitizer::internal_strlen((const char *)old) + 1);
  981. if (new_)
  982. PRE_READ(new_, __sanitizer::internal_strlen((const char *)new_) + 1);
  983. }
  984. POST_SYSCALL(symlink)(long res, const void *old, const void *new_) {}
  985. PRE_SYSCALL(unlink)(const void *pathname) {
  986. if (pathname)
  987. PRE_READ(pathname,
  988. __sanitizer::internal_strlen((const char *)pathname) + 1);
  989. }
  990. POST_SYSCALL(unlink)(long res, const void *pathname) {}
  991. PRE_SYSCALL(rename)(const void *oldname, const void *newname) {
  992. if (oldname)
  993. PRE_READ(oldname, __sanitizer::internal_strlen((const char *)oldname) + 1);
  994. if (newname)
  995. PRE_READ(newname, __sanitizer::internal_strlen((const char *)newname) + 1);
  996. }
  997. POST_SYSCALL(rename)(long res, const void *oldname, const void *newname) {}
  998. PRE_SYSCALL(chmod)(const void *filename, long mode) {
  999. if (filename)
  1000. PRE_READ(filename,
  1001. __sanitizer::internal_strlen((const char *)filename) + 1);
  1002. }
  1003. POST_SYSCALL(chmod)(long res, const void *filename, long mode) {}
  1004. PRE_SYSCALL(fchmod)(long fd, long mode) {}
  1005. POST_SYSCALL(fchmod)(long res, long fd, long mode) {}
  1006. PRE_SYSCALL(fcntl)(long fd, long cmd, long arg) {}
  1007. POST_SYSCALL(fcntl)(long res, long fd, long cmd, long arg) {}
  1008. PRE_SYSCALL(fcntl64)(long fd, long cmd, long arg) {}
  1009. POST_SYSCALL(fcntl64)(long res, long fd, long cmd, long arg) {}
  1010. PRE_SYSCALL(pipe)(void *fildes) {}
  1011. POST_SYSCALL(pipe)(long res, void *fildes) {
  1012. if (res >= 0)
  1013. if (fildes)
  1014. POST_WRITE(fildes, sizeof(int) * 2);
  1015. }
  1016. PRE_SYSCALL(pipe2)(void *fildes, long flags) {}
  1017. POST_SYSCALL(pipe2)(long res, void *fildes, long flags) {
  1018. if (res >= 0)
  1019. if (fildes)
  1020. POST_WRITE(fildes, sizeof(int) * 2);
  1021. }
  1022. PRE_SYSCALL(dup)(long fildes) {}
  1023. POST_SYSCALL(dup)(long res, long fildes) {}
  1024. PRE_SYSCALL(dup2)(long oldfd, long newfd) {}
  1025. POST_SYSCALL(dup2)(long res, long oldfd, long newfd) {}
  1026. PRE_SYSCALL(dup3)(long oldfd, long newfd, long flags) {}
  1027. POST_SYSCALL(dup3)(long res, long oldfd, long newfd, long flags) {}
  1028. PRE_SYSCALL(ioperm)(long from, long num, long on) {}
  1029. POST_SYSCALL(ioperm)(long res, long from, long num, long on) {}
  1030. PRE_SYSCALL(ioctl)(long fd, long cmd, long arg) {}
  1031. POST_SYSCALL(ioctl)(long res, long fd, long cmd, long arg) {}
  1032. PRE_SYSCALL(flock)(long fd, long cmd) {}
  1033. POST_SYSCALL(flock)(long res, long fd, long cmd) {}
  1034. PRE_SYSCALL(io_setup)(long nr_reqs, void **ctx) {
  1035. if (ctx)
  1036. PRE_WRITE(ctx, sizeof(*ctx));
  1037. }
  1038. POST_SYSCALL(io_setup)(long res, long nr_reqs, void **ctx) {
  1039. if (res >= 0) {
  1040. if (ctx)
  1041. POST_WRITE(ctx, sizeof(*ctx));
  1042. // (*ctx) is actually a pointer to a kernel mapped page, and there are
  1043. // people out there who are crazy enough to peek into that page's 32-byte
  1044. // header.
  1045. if (*ctx)
  1046. POST_WRITE(*ctx, 32);
  1047. }
  1048. }
  1049. PRE_SYSCALL(io_destroy)(long ctx) {}
  1050. POST_SYSCALL(io_destroy)(long res, long ctx) {}
  1051. PRE_SYSCALL(io_getevents)
  1052. (long ctx_id, long min_nr, long nr, __sanitizer_io_event *ioevpp,
  1053. void *timeout) {
  1054. if (timeout)
  1055. PRE_READ(timeout, struct_timespec_sz);
  1056. }
  1057. POST_SYSCALL(io_getevents)
  1058. (long res, long ctx_id, long min_nr, long nr, __sanitizer_io_event *ioevpp,
  1059. void *timeout) {
  1060. if (res >= 0) {
  1061. if (ioevpp)
  1062. POST_WRITE(ioevpp, res * sizeof(*ioevpp));
  1063. if (timeout)
  1064. POST_WRITE(timeout, struct_timespec_sz);
  1065. }
  1066. for (long i = 0; i < res; i++) {
  1067. // We synchronize io_submit -> io_getevents/io_cancel using the
  1068. // user-provided data context. Data is not necessary a pointer, it can be
  1069. // an int, 0 or whatever; acquire/release will correctly handle this.
  1070. // This scheme can lead to false negatives, e.g. when all operations
  1071. // synchronize on 0. But there does not seem to be a better solution
  1072. // (except wrapping all operations in own context, which is unreliable).
  1073. // We can not reliably extract fildes in io_getevents.
  1074. COMMON_SYSCALL_ACQUIRE((void *)ioevpp[i].data);
  1075. }
  1076. }
  1077. PRE_SYSCALL(io_submit)(long ctx_id, long nr, __sanitizer_iocb **iocbpp) {
  1078. for (long i = 0; i < nr; ++i) {
  1079. uptr op = iocbpp[i]->aio_lio_opcode;
  1080. void *data = (void *)iocbpp[i]->aio_data;
  1081. void *buf = (void *)iocbpp[i]->aio_buf;
  1082. uptr len = (uptr)iocbpp[i]->aio_nbytes;
  1083. if (op == iocb_cmd_pwrite && buf && len) {
  1084. PRE_READ(buf, len);
  1085. } else if (op == iocb_cmd_pread && buf && len) {
  1086. POST_WRITE(buf, len);
  1087. } else if (op == iocb_cmd_pwritev) {
  1088. __sanitizer_iovec *iovec = (__sanitizer_iovec *)buf;
  1089. for (uptr v = 0; v < len; v++)
  1090. PRE_READ(iovec[v].iov_base, iovec[v].iov_len);
  1091. } else if (op == iocb_cmd_preadv) {
  1092. __sanitizer_iovec *iovec = (__sanitizer_iovec *)buf;
  1093. for (uptr v = 0; v < len; v++)
  1094. POST_WRITE(iovec[v].iov_base, iovec[v].iov_len);
  1095. }
  1096. // See comment in io_getevents.
  1097. COMMON_SYSCALL_RELEASE(data);
  1098. }
  1099. }
  1100. POST_SYSCALL(io_submit)
  1101. (long res, long ctx_id, long nr, __sanitizer_iocb **iocbpp) {}
  1102. PRE_SYSCALL(io_cancel)
  1103. (long ctx_id, __sanitizer_iocb *iocb, __sanitizer_io_event *result) {}
  1104. POST_SYSCALL(io_cancel)
  1105. (long res, long ctx_id, __sanitizer_iocb *iocb, __sanitizer_io_event *result) {
  1106. if (res == 0) {
  1107. if (result) {
  1108. // See comment in io_getevents.
  1109. COMMON_SYSCALL_ACQUIRE((void *)result->data);
  1110. POST_WRITE(result, sizeof(*result));
  1111. }
  1112. if (iocb)
  1113. POST_WRITE(iocb, sizeof(*iocb));
  1114. }
  1115. }
  1116. PRE_SYSCALL(sendfile)(long out_fd, long in_fd, void *offset, long count) {}
  1117. POST_SYSCALL(sendfile)
  1118. (long res, long out_fd, long in_fd, __sanitizer___kernel_off_t *offset,
  1119. long count) {
  1120. if (res >= 0) {
  1121. if (offset)
  1122. POST_WRITE(offset, sizeof(*offset));
  1123. }
  1124. }
  1125. PRE_SYSCALL(sendfile64)(long out_fd, long in_fd, void *offset, long count) {}
  1126. POST_SYSCALL(sendfile64)
  1127. (long res, long out_fd, long in_fd, __sanitizer___kernel_loff_t *offset,
  1128. long count) {
  1129. if (res >= 0) {
  1130. if (offset)
  1131. POST_WRITE(offset, sizeof(*offset));
  1132. }
  1133. }
  1134. PRE_SYSCALL(readlink)(const void *path, void *buf, long bufsiz) {
  1135. if (path)
  1136. PRE_READ(path, __sanitizer::internal_strlen((const char *)path) + 1);
  1137. }
  1138. POST_SYSCALL(readlink)(long res, const void *path, void *buf, long bufsiz) {
  1139. if (res >= 0) {
  1140. if (buf)
  1141. POST_WRITE(buf, __sanitizer::internal_strlen((const char *)buf) + 1);
  1142. }
  1143. }
  1144. PRE_SYSCALL(creat)(const void *pathname, long mode) {
  1145. if (pathname)
  1146. PRE_READ(pathname,
  1147. __sanitizer::internal_strlen((const char *)pathname) + 1);
  1148. }
  1149. POST_SYSCALL(creat)(long res, const void *pathname, long mode) {}
  1150. PRE_SYSCALL(open)(const void *filename, long flags, long mode) {
  1151. if (filename)
  1152. PRE_READ(filename,
  1153. __sanitizer::internal_strlen((const char *)filename) + 1);
  1154. }
  1155. POST_SYSCALL(open)(long res, const void *filename, long flags, long mode) {}
  1156. PRE_SYSCALL(close)(long fd) { COMMON_SYSCALL_FD_CLOSE((int)fd); }
  1157. POST_SYSCALL(close)(long res, long fd) {}
  1158. PRE_SYSCALL(access)(const void *filename, long mode) {
  1159. if (filename)
  1160. PRE_READ(filename,
  1161. __sanitizer::internal_strlen((const char *)filename) + 1);
  1162. }
  1163. POST_SYSCALL(access)(long res, const void *filename, long mode) {}
  1164. PRE_SYSCALL(vhangup)() {}
  1165. POST_SYSCALL(vhangup)(long res) {}
  1166. PRE_SYSCALL(chown)(const void *filename, long user, long group) {
  1167. if (filename)
  1168. PRE_READ(filename,
  1169. __sanitizer::internal_strlen((const char *)filename) + 1);
  1170. }
  1171. POST_SYSCALL(chown)(long res, const void *filename, long user, long group) {}
  1172. PRE_SYSCALL(lchown)(const void *filename, long user, long group) {
  1173. if (filename)
  1174. PRE_READ(filename,
  1175. __sanitizer::internal_strlen((const char *)filename) + 1);
  1176. }
  1177. POST_SYSCALL(lchown)(long res, const void *filename, long user, long group) {}
  1178. PRE_SYSCALL(fchown)(long fd, long user, long group) {}
  1179. POST_SYSCALL(fchown)(long res, long fd, long user, long group) {}
  1180. # if SANITIZER_USES_UID16_SYSCALLS
  1181. PRE_SYSCALL(chown16)(const void *filename, long user, long group) {
  1182. if (filename)
  1183. PRE_READ(filename,
  1184. __sanitizer::internal_strlen((const char *)filename) + 1);
  1185. }
  1186. POST_SYSCALL(chown16)(long res, const void *filename, long user, long group) {}
  1187. PRE_SYSCALL(lchown16)(const void *filename, long user, long group) {
  1188. if (filename)
  1189. PRE_READ(filename,
  1190. __sanitizer::internal_strlen((const char *)filename) + 1);
  1191. }
  1192. POST_SYSCALL(lchown16)(long res, const void *filename, long user, long group) {}
  1193. PRE_SYSCALL(fchown16)(long fd, long user, long group) {}
  1194. POST_SYSCALL(fchown16)(long res, long fd, long user, long group) {}
  1195. PRE_SYSCALL(setregid16)(long rgid, long egid) {}
  1196. POST_SYSCALL(setregid16)(long res, long rgid, long egid) {}
  1197. PRE_SYSCALL(setgid16)(long gid) {}
  1198. POST_SYSCALL(setgid16)(long res, long gid) {}
  1199. PRE_SYSCALL(setreuid16)(long ruid, long euid) {}
  1200. POST_SYSCALL(setreuid16)(long res, long ruid, long euid) {}
  1201. PRE_SYSCALL(setuid16)(long uid) {}
  1202. POST_SYSCALL(setuid16)(long res, long uid) {}
  1203. PRE_SYSCALL(setresuid16)(long ruid, long euid, long suid) {}
  1204. POST_SYSCALL(setresuid16)(long res, long ruid, long euid, long suid) {}
  1205. PRE_SYSCALL(getresuid16)(void *ruid, void *euid, void *suid) {}
  1206. POST_SYSCALL(getresuid16)
  1207. (long res, __sanitizer___kernel_old_uid_t *ruid,
  1208. __sanitizer___kernel_old_uid_t *euid, __sanitizer___kernel_old_uid_t *suid) {
  1209. if (res >= 0) {
  1210. if (ruid)
  1211. POST_WRITE(ruid, sizeof(*ruid));
  1212. if (euid)
  1213. POST_WRITE(euid, sizeof(*euid));
  1214. if (suid)
  1215. POST_WRITE(suid, sizeof(*suid));
  1216. }
  1217. }
  1218. PRE_SYSCALL(setresgid16)(long rgid, long egid, long sgid) {}
  1219. POST_SYSCALL(setresgid16)(long res, long rgid, long egid, long sgid) {}
  1220. PRE_SYSCALL(getresgid16)(void *rgid, void *egid, void *sgid) {}
  1221. POST_SYSCALL(getresgid16)
  1222. (long res, __sanitizer___kernel_old_gid_t *rgid,
  1223. __sanitizer___kernel_old_gid_t *egid, __sanitizer___kernel_old_gid_t *sgid) {
  1224. if (res >= 0) {
  1225. if (rgid)
  1226. POST_WRITE(rgid, sizeof(*rgid));
  1227. if (egid)
  1228. POST_WRITE(egid, sizeof(*egid));
  1229. if (sgid)
  1230. POST_WRITE(sgid, sizeof(*sgid));
  1231. }
  1232. }
  1233. PRE_SYSCALL(setfsuid16)(long uid) {}
  1234. POST_SYSCALL(setfsuid16)(long res, long uid) {}
  1235. PRE_SYSCALL(setfsgid16)(long gid) {}
  1236. POST_SYSCALL(setfsgid16)(long res, long gid) {}
  1237. PRE_SYSCALL(getgroups16)
  1238. (long gidsetsize, __sanitizer___kernel_old_gid_t *grouplist) {}
  1239. POST_SYSCALL(getgroups16)
  1240. (long res, long gidsetsize, __sanitizer___kernel_old_gid_t *grouplist) {
  1241. if (res >= 0) {
  1242. if (grouplist)
  1243. POST_WRITE(grouplist, res * sizeof(*grouplist));
  1244. }
  1245. }
  1246. PRE_SYSCALL(setgroups16)
  1247. (long gidsetsize, __sanitizer___kernel_old_gid_t *grouplist) {
  1248. if (grouplist)
  1249. POST_WRITE(grouplist, gidsetsize * sizeof(*grouplist));
  1250. }
  1251. POST_SYSCALL(setgroups16)
  1252. (long res, long gidsetsize, __sanitizer___kernel_old_gid_t *grouplist) {}
  1253. PRE_SYSCALL(getuid16)() {}
  1254. POST_SYSCALL(getuid16)(long res) {}
  1255. PRE_SYSCALL(geteuid16)() {}
  1256. POST_SYSCALL(geteuid16)(long res) {}
  1257. PRE_SYSCALL(getgid16)() {}
  1258. POST_SYSCALL(getgid16)(long res) {}
  1259. PRE_SYSCALL(getegid16)() {}
  1260. POST_SYSCALL(getegid16)(long res) {}
  1261. # endif // SANITIZER_USES_UID16_SYSCALLS
  1262. PRE_SYSCALL(utime)(void *filename, void *times) {}
  1263. POST_SYSCALL(utime)(long res, void *filename, void *times) {
  1264. if (res >= 0) {
  1265. if (filename)
  1266. POST_WRITE(filename,
  1267. __sanitizer::internal_strlen((const char *)filename) + 1);
  1268. if (times)
  1269. POST_WRITE(times, struct_utimbuf_sz);
  1270. }
  1271. }
  1272. PRE_SYSCALL(utimes)(void *filename, void *utimes) {}
  1273. POST_SYSCALL(utimes)(long res, void *filename, void *utimes) {
  1274. if (res >= 0) {
  1275. if (filename)
  1276. POST_WRITE(filename,
  1277. __sanitizer::internal_strlen((const char *)filename) + 1);
  1278. if (utimes)
  1279. POST_WRITE(utimes, timeval_sz);
  1280. }
  1281. }
  1282. PRE_SYSCALL(lseek)(long fd, long offset, long origin) {}
  1283. POST_SYSCALL(lseek)(long res, long fd, long offset, long origin) {}
  1284. PRE_SYSCALL(llseek)
  1285. (long fd, long offset_high, long offset_low, void *result, long origin) {}
  1286. POST_SYSCALL(llseek)
  1287. (long res, long fd, long offset_high, long offset_low, void *result,
  1288. long origin) {
  1289. if (res >= 0) {
  1290. if (result)
  1291. POST_WRITE(result, sizeof(long long));
  1292. }
  1293. }
  1294. PRE_SYSCALL(readv)(long fd, const __sanitizer_iovec *vec, long vlen) {}
  1295. POST_SYSCALL(readv)
  1296. (long res, long fd, const __sanitizer_iovec *vec, long vlen) {
  1297. if (res >= 0) {
  1298. if (vec)
  1299. kernel_write_iovec(vec, vlen, res);
  1300. }
  1301. }
  1302. PRE_SYSCALL(write)(long fd, const void *buf, long count) {
  1303. if (buf)
  1304. PRE_READ(buf, count);
  1305. }
  1306. POST_SYSCALL(write)(long res, long fd, const void *buf, long count) {}
  1307. PRE_SYSCALL(writev)(long fd, const __sanitizer_iovec *vec, long vlen) {}
  1308. POST_SYSCALL(writev)
  1309. (long res, long fd, const __sanitizer_iovec *vec, long vlen) {
  1310. if (res >= 0) {
  1311. if (vec)
  1312. kernel_read_iovec(vec, vlen, res);
  1313. }
  1314. }
  1315. # ifdef _LP64
  1316. PRE_SYSCALL(pread64)(long fd, void *buf, long count, long pos) {}
  1317. POST_SYSCALL(pread64)(long res, long fd, void *buf, long count, long pos) {
  1318. if (res >= 0) {
  1319. if (buf)
  1320. POST_WRITE(buf, res);
  1321. }
  1322. }
  1323. PRE_SYSCALL(pwrite64)(long fd, const void *buf, long count, long pos) {
  1324. if (buf)
  1325. PRE_READ(buf, count);
  1326. }
  1327. POST_SYSCALL(pwrite64)
  1328. (long res, long fd, const void *buf, long count, long pos) {}
  1329. # else
  1330. PRE_SYSCALL(pread64)(long fd, void *buf, long count, long pos0, long pos1) {}
  1331. POST_SYSCALL(pread64)
  1332. (long res, long fd, void *buf, long count, long pos0, long pos1) {
  1333. if (res >= 0) {
  1334. if (buf)
  1335. POST_WRITE(buf, res);
  1336. }
  1337. }
  1338. PRE_SYSCALL(pwrite64)
  1339. (long fd, const void *buf, long count, long pos0, long pos1) {
  1340. if (buf)
  1341. PRE_READ(buf, count);
  1342. }
  1343. POST_SYSCALL(pwrite64)
  1344. (long res, long fd, const void *buf, long count, long pos0, long pos1) {}
  1345. # endif
  1346. PRE_SYSCALL(preadv)
  1347. (long fd, const __sanitizer_iovec *vec, long vlen, long pos_l, long pos_h) {}
  1348. POST_SYSCALL(preadv)
  1349. (long res, long fd, const __sanitizer_iovec *vec, long vlen, long pos_l,
  1350. long pos_h) {
  1351. if (res >= 0) {
  1352. if (vec)
  1353. kernel_write_iovec(vec, vlen, res);
  1354. }
  1355. }
  1356. PRE_SYSCALL(pwritev)
  1357. (long fd, const __sanitizer_iovec *vec, long vlen, long pos_l, long pos_h) {}
  1358. POST_SYSCALL(pwritev)
  1359. (long res, long fd, const __sanitizer_iovec *vec, long vlen, long pos_l,
  1360. long pos_h) {
  1361. if (res >= 0) {
  1362. if (vec)
  1363. kernel_read_iovec(vec, vlen, res);
  1364. }
  1365. }
  1366. PRE_SYSCALL(getcwd)(void *buf, long size) {}
  1367. POST_SYSCALL(getcwd)(long res, void *buf, long size) {
  1368. if (res >= 0) {
  1369. if (buf)
  1370. POST_WRITE(buf, __sanitizer::internal_strlen((const char *)buf) + 1);
  1371. }
  1372. }
  1373. PRE_SYSCALL(mkdir)(const void *pathname, long mode) {
  1374. if (pathname)
  1375. PRE_READ(pathname,
  1376. __sanitizer::internal_strlen((const char *)pathname) + 1);
  1377. }
  1378. POST_SYSCALL(mkdir)(long res, const void *pathname, long mode) {}
  1379. PRE_SYSCALL(chdir)(const void *filename) {
  1380. if (filename)
  1381. PRE_READ(filename,
  1382. __sanitizer::internal_strlen((const char *)filename) + 1);
  1383. }
  1384. POST_SYSCALL(chdir)(long res, const void *filename) {}
  1385. PRE_SYSCALL(fchdir)(long fd) {}
  1386. POST_SYSCALL(fchdir)(long res, long fd) {}
  1387. PRE_SYSCALL(rmdir)(const void *pathname) {
  1388. if (pathname)
  1389. PRE_READ(pathname,
  1390. __sanitizer::internal_strlen((const char *)pathname) + 1);
  1391. }
  1392. POST_SYSCALL(rmdir)(long res, const void *pathname) {}
  1393. PRE_SYSCALL(lookup_dcookie)(u64 cookie64, void *buf, long len) {}
  1394. POST_SYSCALL(lookup_dcookie)(long res, u64 cookie64, void *buf, long len) {
  1395. if (res >= 0) {
  1396. if (buf)
  1397. POST_WRITE(buf, __sanitizer::internal_strlen((const char *)buf) + 1);
  1398. }
  1399. }
  1400. PRE_SYSCALL(quotactl)(long cmd, const void *special, long id, void *addr) {
  1401. if (special)
  1402. PRE_READ(special, __sanitizer::internal_strlen((const char *)special) + 1);
  1403. }
  1404. POST_SYSCALL(quotactl)
  1405. (long res, long cmd, const void *special, long id, void *addr) {}
  1406. PRE_SYSCALL(getdents)(long fd, void *dirent, long count) {}
  1407. POST_SYSCALL(getdents)(long res, long fd, void *dirent, long count) {
  1408. if (res >= 0) {
  1409. if (dirent)
  1410. POST_WRITE(dirent, res);
  1411. }
  1412. }
  1413. PRE_SYSCALL(getdents64)(long fd, void *dirent, long count) {}
  1414. POST_SYSCALL(getdents64)(long res, long fd, void *dirent, long count) {
  1415. if (res >= 0) {
  1416. if (dirent)
  1417. POST_WRITE(dirent, res);
  1418. }
  1419. }
  1420. PRE_SYSCALL(setsockopt)
  1421. (long fd, long level, long optname, void *optval, long optlen) {}
  1422. POST_SYSCALL(setsockopt)
  1423. (long res, long fd, long level, long optname, void *optval, long optlen) {
  1424. if (res >= 0) {
  1425. if (optval)
  1426. POST_WRITE(optval,
  1427. __sanitizer::internal_strlen((const char *)optval) + 1);
  1428. }
  1429. }
  1430. PRE_SYSCALL(getsockopt)
  1431. (long fd, long level, long optname, void *optval, void *optlen) {}
  1432. POST_SYSCALL(getsockopt)
  1433. (long res, long fd, long level, long optname, void *optval, void *optlen) {
  1434. if (res >= 0) {
  1435. if (optval)
  1436. POST_WRITE(optval,
  1437. __sanitizer::internal_strlen((const char *)optval) + 1);
  1438. if (optlen)
  1439. POST_WRITE(optlen, sizeof(int));
  1440. }
  1441. }
  1442. PRE_SYSCALL(bind)(long arg0, sanitizer_kernel_sockaddr *arg1, long arg2) {}
  1443. POST_SYSCALL(bind)
  1444. (long res, long arg0, sanitizer_kernel_sockaddr *arg1, long arg2) {
  1445. if (res >= 0) {
  1446. if (arg1)
  1447. POST_WRITE(arg1, sizeof(*arg1));
  1448. }
  1449. }
  1450. PRE_SYSCALL(connect)(long arg0, sanitizer_kernel_sockaddr *arg1, long arg2) {}
  1451. POST_SYSCALL(connect)
  1452. (long res, long arg0, sanitizer_kernel_sockaddr *arg1, long arg2) {
  1453. if (res >= 0) {
  1454. if (arg1)
  1455. POST_WRITE(arg1, sizeof(*arg1));
  1456. }
  1457. }
  1458. PRE_SYSCALL(accept)(long arg0, sanitizer_kernel_sockaddr *arg1, void *arg2) {}
  1459. POST_SYSCALL(accept)
  1460. (long res, long arg0, sanitizer_kernel_sockaddr *arg1, void *arg2) {
  1461. if (res >= 0) {
  1462. if (arg1)
  1463. POST_WRITE(arg1, sizeof(*arg1));
  1464. if (arg2)
  1465. POST_WRITE(arg2, sizeof(unsigned));
  1466. }
  1467. }
  1468. PRE_SYSCALL(accept4)
  1469. (long arg0, sanitizer_kernel_sockaddr *arg1, void *arg2, long arg3) {}
  1470. POST_SYSCALL(accept4)
  1471. (long res, long arg0, sanitizer_kernel_sockaddr *arg1, void *arg2, long arg3) {
  1472. if (res >= 0) {
  1473. if (arg1)
  1474. POST_WRITE(arg1, sizeof(*arg1));
  1475. if (arg2)
  1476. POST_WRITE(arg2, sizeof(unsigned));
  1477. }
  1478. }
  1479. PRE_SYSCALL(getsockname)
  1480. (long arg0, sanitizer_kernel_sockaddr *arg1, void *arg2) {}
  1481. POST_SYSCALL(getsockname)
  1482. (long res, long arg0, sanitizer_kernel_sockaddr *arg1, void *arg2) {
  1483. if (res >= 0) {
  1484. if (arg1)
  1485. POST_WRITE(arg1, sizeof(*arg1));
  1486. if (arg2)
  1487. POST_WRITE(arg2, sizeof(unsigned));
  1488. }
  1489. }
  1490. PRE_SYSCALL(getpeername)
  1491. (long arg0, sanitizer_kernel_sockaddr *arg1, void *arg2) {}
  1492. POST_SYSCALL(getpeername)
  1493. (long res, long arg0, sanitizer_kernel_sockaddr *arg1, void *arg2) {
  1494. if (res >= 0) {
  1495. if (arg1)
  1496. POST_WRITE(arg1, sizeof(*arg1));
  1497. if (arg2)
  1498. POST_WRITE(arg2, sizeof(unsigned));
  1499. }
  1500. }
  1501. PRE_SYSCALL(send)(long arg0, void *arg1, long arg2, long arg3) {}
  1502. POST_SYSCALL(send)(long res, long arg0, void *arg1, long arg2, long arg3) {
  1503. if (res) {
  1504. if (arg1)
  1505. POST_READ(arg1, res);
  1506. }
  1507. }
  1508. PRE_SYSCALL(sendto)
  1509. (long arg0, void *arg1, long arg2, long arg3, sanitizer_kernel_sockaddr *arg4,
  1510. long arg5) {}
  1511. POST_SYSCALL(sendto)
  1512. (long res, long arg0, void *arg1, long arg2, long arg3,
  1513. sanitizer_kernel_sockaddr *arg4, long arg5) {
  1514. if (res >= 0) {
  1515. if (arg1)
  1516. POST_READ(arg1, res);
  1517. if (arg4)
  1518. POST_WRITE(arg4, sizeof(*arg4));
  1519. }
  1520. }
  1521. PRE_SYSCALL(sendmsg)(long fd, void *msg, long flags) {}
  1522. POST_SYSCALL(sendmsg)(long res, long fd, void *msg, long flags) {
  1523. // FIXME: POST_READ
  1524. }
  1525. PRE_SYSCALL(sendmmsg)(long fd, void *msg, long vlen, long flags) {}
  1526. POST_SYSCALL(sendmmsg)(long res, long fd, void *msg, long vlen, long flags) {
  1527. // FIXME: POST_READ
  1528. }
  1529. PRE_SYSCALL(recv)(long arg0, void *buf, long len, long flags) {}
  1530. POST_SYSCALL(recv)(long res, void *buf, long len, long flags) {
  1531. if (res >= 0) {
  1532. if (buf)
  1533. POST_WRITE(buf, res);
  1534. }
  1535. }
  1536. PRE_SYSCALL(recvfrom)
  1537. (long arg0, void *buf, long len, long flags, sanitizer_kernel_sockaddr *arg4,
  1538. void *arg5) {}
  1539. POST_SYSCALL(recvfrom)
  1540. (long res, long arg0, void *buf, long len, long flags,
  1541. sanitizer_kernel_sockaddr *arg4, void *arg5) {
  1542. if (res >= 0) {
  1543. if (buf)
  1544. POST_WRITE(buf, res);
  1545. if (arg4)
  1546. POST_WRITE(arg4, sizeof(*arg4));
  1547. if (arg5)
  1548. POST_WRITE(arg5, sizeof(int));
  1549. }
  1550. }
  1551. PRE_SYSCALL(socket)(long arg0, long arg1, long arg2) {}
  1552. POST_SYSCALL(socket)(long res, long arg0, long arg1, long arg2) {}
  1553. PRE_SYSCALL(socketpair)(long arg0, long arg1, long arg2, int *sv) {}
  1554. POST_SYSCALL(socketpair)(long res, long arg0, long arg1, long arg2, int *sv) {
  1555. if (res >= 0)
  1556. if (sv)
  1557. POST_WRITE(sv, sizeof(int) * 2);
  1558. }
  1559. PRE_SYSCALL(socketcall)(long call, void *args) {}
  1560. POST_SYSCALL(socketcall)(long res, long call, void *args) {
  1561. if (res >= 0) {
  1562. if (args)
  1563. POST_WRITE(args, sizeof(long));
  1564. }
  1565. }
  1566. PRE_SYSCALL(listen)(long arg0, long arg1) {}
  1567. POST_SYSCALL(listen)(long res, long arg0, long arg1) {}
  1568. PRE_SYSCALL(poll)(void *ufds, long nfds, long timeout) {}
  1569. POST_SYSCALL(poll)
  1570. (long res, __sanitizer_pollfd *ufds, long nfds, long timeout) {
  1571. if (res >= 0) {
  1572. if (ufds)
  1573. POST_WRITE(ufds, nfds * sizeof(*ufds));
  1574. }
  1575. }
  1576. PRE_SYSCALL(select)
  1577. (long n, __sanitizer___kernel_fd_set *inp, __sanitizer___kernel_fd_set *outp,
  1578. __sanitizer___kernel_fd_set *exp, void *tvp) {}
  1579. POST_SYSCALL(select)
  1580. (long res, long n, __sanitizer___kernel_fd_set *inp,
  1581. __sanitizer___kernel_fd_set *outp, __sanitizer___kernel_fd_set *exp,
  1582. void *tvp) {
  1583. if (res >= 0) {
  1584. if (inp)
  1585. POST_WRITE(inp, sizeof(*inp));
  1586. if (outp)
  1587. POST_WRITE(outp, sizeof(*outp));
  1588. if (exp)
  1589. POST_WRITE(exp, sizeof(*exp));
  1590. if (tvp)
  1591. POST_WRITE(tvp, timeval_sz);
  1592. }
  1593. }
  1594. PRE_SYSCALL(old_select)(void *arg) {}
  1595. POST_SYSCALL(old_select)(long res, void *arg) {}
  1596. PRE_SYSCALL(epoll_create)(long size) {}
  1597. POST_SYSCALL(epoll_create)(long res, long size) {}
  1598. PRE_SYSCALL(epoll_create1)(long flags) {}
  1599. POST_SYSCALL(epoll_create1)(long res, long flags) {}
  1600. PRE_SYSCALL(epoll_ctl)(long epfd, long op, long fd, void *event) {}
  1601. POST_SYSCALL(epoll_ctl)(long res, long epfd, long op, long fd, void *event) {
  1602. if (res >= 0) {
  1603. if (event)
  1604. POST_WRITE(event, struct_epoll_event_sz);
  1605. }
  1606. }
  1607. PRE_SYSCALL(epoll_wait)
  1608. (long epfd, void *events, long maxevents, long timeout) {}
  1609. POST_SYSCALL(epoll_wait)
  1610. (long res, long epfd, void *events, long maxevents, long timeout) {
  1611. if (res >= 0) {
  1612. if (events)
  1613. POST_WRITE(events, res * struct_epoll_event_sz);
  1614. }
  1615. }
  1616. PRE_SYSCALL(epoll_pwait)
  1617. (long epfd, void *events, long maxevents, long timeout,
  1618. const kernel_sigset_t *sigmask, long sigsetsize) {
  1619. if (sigmask)
  1620. PRE_READ(sigmask, sigsetsize);
  1621. }
  1622. POST_SYSCALL(epoll_pwait)
  1623. (long res, long epfd, void *events, long maxevents, long timeout,
  1624. const void *sigmask, long sigsetsize) {
  1625. if (res >= 0) {
  1626. if (events)
  1627. POST_WRITE(events, res * struct_epoll_event_sz);
  1628. }
  1629. }
  1630. PRE_SYSCALL(epoll_pwait2)
  1631. (long epfd, void *events, long maxevents,
  1632. const sanitizer_kernel_timespec *timeout, const kernel_sigset_t *sigmask,
  1633. long sigsetsize) {
  1634. if (timeout)
  1635. PRE_READ(timeout, sizeof(timeout));
  1636. if (sigmask)
  1637. PRE_READ(sigmask, sigsetsize);
  1638. }
  1639. POST_SYSCALL(epoll_pwait2)
  1640. (long res, long epfd, void *events, long maxevents,
  1641. const sanitizer_kernel_timespec *timeout, const void *sigmask,
  1642. long sigsetsize) {
  1643. if (res >= 0) {
  1644. if (events)
  1645. POST_WRITE(events, res * struct_epoll_event_sz);
  1646. }
  1647. }
  1648. PRE_SYSCALL(gethostname)(void *name, long len) {}
  1649. POST_SYSCALL(gethostname)(long res, void *name, long len) {
  1650. if (res >= 0) {
  1651. if (name)
  1652. POST_WRITE(name, __sanitizer::internal_strlen((const char *)name) + 1);
  1653. }
  1654. }
  1655. PRE_SYSCALL(sethostname)(void *name, long len) {}
  1656. POST_SYSCALL(sethostname)(long res, void *name, long len) {
  1657. if (res >= 0) {
  1658. if (name)
  1659. POST_WRITE(name, __sanitizer::internal_strlen((const char *)name) + 1);
  1660. }
  1661. }
  1662. PRE_SYSCALL(setdomainname)(void *name, long len) {}
  1663. POST_SYSCALL(setdomainname)(long res, void *name, long len) {
  1664. if (res >= 0) {
  1665. if (name)
  1666. POST_WRITE(name, __sanitizer::internal_strlen((const char *)name) + 1);
  1667. }
  1668. }
  1669. PRE_SYSCALL(newuname)(void *name) {}
  1670. POST_SYSCALL(newuname)(long res, void *name) {
  1671. if (res >= 0) {
  1672. if (name)
  1673. POST_WRITE(name, struct_new_utsname_sz);
  1674. }
  1675. }
  1676. PRE_SYSCALL(uname)(void *arg0) {}
  1677. POST_SYSCALL(uname)(long res, void *arg0) {
  1678. if (res >= 0) {
  1679. if (arg0)
  1680. POST_WRITE(arg0, struct_old_utsname_sz);
  1681. }
  1682. }
  1683. PRE_SYSCALL(olduname)(void *arg0) {}
  1684. POST_SYSCALL(olduname)(long res, void *arg0) {
  1685. if (res >= 0) {
  1686. if (arg0)
  1687. POST_WRITE(arg0, struct_oldold_utsname_sz);
  1688. }
  1689. }
  1690. PRE_SYSCALL(getrlimit)(long resource, void *rlim) {}
  1691. POST_SYSCALL(getrlimit)(long res, long resource, void *rlim) {
  1692. if (res >= 0) {
  1693. if (rlim)
  1694. POST_WRITE(rlim, struct_rlimit_sz);
  1695. }
  1696. }
  1697. PRE_SYSCALL(old_getrlimit)(long resource, void *rlim) {}
  1698. POST_SYSCALL(old_getrlimit)(long res, long resource, void *rlim) {
  1699. if (res >= 0) {
  1700. if (rlim)
  1701. POST_WRITE(rlim, struct_rlimit_sz);
  1702. }
  1703. }
  1704. PRE_SYSCALL(setrlimit)(long resource, void *rlim) {}
  1705. POST_SYSCALL(setrlimit)(long res, long resource, void *rlim) {
  1706. if (res >= 0) {
  1707. if (rlim)
  1708. POST_WRITE(rlim, struct_rlimit_sz);
  1709. }
  1710. }
  1711. # if !SANITIZER_ANDROID
  1712. PRE_SYSCALL(prlimit64)
  1713. (long pid, long resource, const void *new_rlim, void *old_rlim) {
  1714. if (new_rlim)
  1715. PRE_READ(new_rlim, struct_rlimit64_sz);
  1716. }
  1717. POST_SYSCALL(prlimit64)
  1718. (long res, long pid, long resource, const void *new_rlim, void *old_rlim) {
  1719. if (res >= 0) {
  1720. if (old_rlim)
  1721. POST_WRITE(old_rlim, struct_rlimit64_sz);
  1722. }
  1723. }
  1724. # endif
  1725. PRE_SYSCALL(getrusage)(long who, void *ru) {}
  1726. POST_SYSCALL(getrusage)(long res, long who, void *ru) {
  1727. if (res >= 0) {
  1728. if (ru)
  1729. POST_WRITE(ru, struct_rusage_sz);
  1730. }
  1731. }
  1732. PRE_SYSCALL(umask)(long mask) {}
  1733. POST_SYSCALL(umask)(long res, long mask) {}
  1734. PRE_SYSCALL(msgget)(long key, long msgflg) {}
  1735. POST_SYSCALL(msgget)(long res, long key, long msgflg) {}
  1736. PRE_SYSCALL(msgsnd)(long msqid, void *msgp, long msgsz, long msgflg) {
  1737. if (msgp)
  1738. PRE_READ(msgp, msgsz);
  1739. }
  1740. POST_SYSCALL(msgsnd)
  1741. (long res, long msqid, void *msgp, long msgsz, long msgflg) {}
  1742. PRE_SYSCALL(msgrcv)
  1743. (long msqid, void *msgp, long msgsz, long msgtyp, long msgflg) {}
  1744. POST_SYSCALL(msgrcv)
  1745. (long res, long msqid, void *msgp, long msgsz, long msgtyp, long msgflg) {
  1746. if (res >= 0) {
  1747. if (msgp)
  1748. POST_WRITE(msgp, res);
  1749. }
  1750. }
  1751. # if !SANITIZER_ANDROID
  1752. PRE_SYSCALL(msgctl)(long msqid, long cmd, void *buf) {}
  1753. POST_SYSCALL(msgctl)(long res, long msqid, long cmd, void *buf) {
  1754. if (res >= 0) {
  1755. if (buf)
  1756. POST_WRITE(buf, struct_msqid_ds_sz);
  1757. }
  1758. }
  1759. # endif
  1760. PRE_SYSCALL(semget)(long key, long nsems, long semflg) {}
  1761. POST_SYSCALL(semget)(long res, long key, long nsems, long semflg) {}
  1762. PRE_SYSCALL(semop)(long semid, void *sops, long nsops) {}
  1763. POST_SYSCALL(semop)(long res, long semid, void *sops, long nsops) {}
  1764. PRE_SYSCALL(semctl)(long semid, long semnum, long cmd, void *arg) {}
  1765. POST_SYSCALL(semctl)(long res, long semid, long semnum, long cmd, void *arg) {}
  1766. PRE_SYSCALL(semtimedop)
  1767. (long semid, void *sops, long nsops, const void *timeout) {
  1768. if (timeout)
  1769. PRE_READ(timeout, struct_timespec_sz);
  1770. }
  1771. POST_SYSCALL(semtimedop)
  1772. (long res, long semid, void *sops, long nsops, const void *timeout) {}
  1773. PRE_SYSCALL(shmat)(long shmid, void *shmaddr, long shmflg) {}
  1774. POST_SYSCALL(shmat)(long res, long shmid, void *shmaddr, long shmflg) {
  1775. if (res >= 0) {
  1776. if (shmaddr)
  1777. POST_WRITE(shmaddr,
  1778. __sanitizer::internal_strlen((const char *)shmaddr) + 1);
  1779. }
  1780. }
  1781. PRE_SYSCALL(shmget)(long key, long size, long flag) {}
  1782. POST_SYSCALL(shmget)(long res, long key, long size, long flag) {}
  1783. PRE_SYSCALL(shmdt)(void *shmaddr) {}
  1784. POST_SYSCALL(shmdt)(long res, void *shmaddr) {
  1785. if (res >= 0) {
  1786. if (shmaddr)
  1787. POST_WRITE(shmaddr,
  1788. __sanitizer::internal_strlen((const char *)shmaddr) + 1);
  1789. }
  1790. }
  1791. PRE_SYSCALL(ipc)
  1792. (long call, long first, long second, long third, void *ptr, long fifth) {}
  1793. POST_SYSCALL(ipc)
  1794. (long res, long call, long first, long second, long third, void *ptr,
  1795. long fifth) {}
  1796. # if !SANITIZER_ANDROID
  1797. PRE_SYSCALL(shmctl)(long shmid, long cmd, void *buf) {}
  1798. POST_SYSCALL(shmctl)(long res, long shmid, long cmd, void *buf) {
  1799. if (res >= 0) {
  1800. if (buf)
  1801. POST_WRITE(buf, sizeof(__sanitizer_shmid_ds));
  1802. }
  1803. }
  1804. PRE_SYSCALL(mq_open)(const void *name, long oflag, long mode, void *attr) {
  1805. if (name)
  1806. PRE_READ(name, __sanitizer::internal_strlen((const char *)name) + 1);
  1807. }
  1808. POST_SYSCALL(mq_open)
  1809. (long res, const void *name, long oflag, long mode, void *attr) {
  1810. if (res >= 0) {
  1811. if (attr)
  1812. POST_WRITE(attr, struct_mq_attr_sz);
  1813. }
  1814. }
  1815. PRE_SYSCALL(mq_unlink)(const void *name) {
  1816. if (name)
  1817. PRE_READ(name, __sanitizer::internal_strlen((const char *)name) + 1);
  1818. }
  1819. POST_SYSCALL(mq_unlink)(long res, const void *name) {}
  1820. PRE_SYSCALL(mq_timedsend)
  1821. (long mqdes, const void *msg_ptr, long msg_len, long msg_prio,
  1822. const void *abs_timeout) {
  1823. if (msg_ptr)
  1824. PRE_READ(msg_ptr, msg_len);
  1825. if (abs_timeout)
  1826. PRE_READ(abs_timeout, struct_timespec_sz);
  1827. }
  1828. POST_SYSCALL(mq_timedsend)
  1829. (long res, long mqdes, const void *msg_ptr, long msg_len, long msg_prio,
  1830. const void *abs_timeout) {}
  1831. PRE_SYSCALL(mq_timedreceive)
  1832. (long mqdes, void *msg_ptr, long msg_len, void *msg_prio,
  1833. const void *abs_timeout) {
  1834. if (abs_timeout)
  1835. PRE_READ(abs_timeout, struct_timespec_sz);
  1836. }
  1837. POST_SYSCALL(mq_timedreceive)
  1838. (long res, long mqdes, void *msg_ptr, long msg_len, int *msg_prio,
  1839. const void *abs_timeout) {
  1840. if (res >= 0) {
  1841. if (msg_ptr)
  1842. POST_WRITE(msg_ptr, res);
  1843. if (msg_prio)
  1844. POST_WRITE(msg_prio, sizeof(*msg_prio));
  1845. }
  1846. }
  1847. PRE_SYSCALL(mq_notify)(long mqdes, const void *notification) {
  1848. if (notification)
  1849. PRE_READ(notification, struct_sigevent_sz);
  1850. }
  1851. POST_SYSCALL(mq_notify)(long res, long mqdes, const void *notification) {}
  1852. PRE_SYSCALL(mq_getsetattr)(long mqdes, const void *mqstat, void *omqstat) {
  1853. if (mqstat)
  1854. PRE_READ(mqstat, struct_mq_attr_sz);
  1855. }
  1856. POST_SYSCALL(mq_getsetattr)
  1857. (long res, long mqdes, const void *mqstat, void *omqstat) {
  1858. if (res >= 0) {
  1859. if (omqstat)
  1860. POST_WRITE(omqstat, struct_mq_attr_sz);
  1861. }
  1862. }
  1863. # endif // SANITIZER_ANDROID
  1864. PRE_SYSCALL(pciconfig_iobase)(long which, long bus, long devfn) {}
  1865. POST_SYSCALL(pciconfig_iobase)(long res, long which, long bus, long devfn) {}
  1866. PRE_SYSCALL(pciconfig_read)
  1867. (long bus, long dfn, long off, long len, void *buf) {}
  1868. POST_SYSCALL(pciconfig_read)
  1869. (long res, long bus, long dfn, long off, long len, void *buf) {}
  1870. PRE_SYSCALL(pciconfig_write)
  1871. (long bus, long dfn, long off, long len, void *buf) {}
  1872. POST_SYSCALL(pciconfig_write)
  1873. (long res, long bus, long dfn, long off, long len, void *buf) {}
  1874. PRE_SYSCALL(swapon)(const void *specialfile, long swap_flags) {
  1875. if (specialfile)
  1876. PRE_READ(specialfile,
  1877. __sanitizer::internal_strlen((const char *)specialfile) + 1);
  1878. }
  1879. POST_SYSCALL(swapon)(long res, const void *specialfile, long swap_flags) {}
  1880. PRE_SYSCALL(swapoff)(const void *specialfile) {
  1881. if (specialfile)
  1882. PRE_READ(specialfile,
  1883. __sanitizer::internal_strlen((const char *)specialfile) + 1);
  1884. }
  1885. POST_SYSCALL(swapoff)(long res, const void *specialfile) {}
  1886. PRE_SYSCALL(sysctl)(__sanitizer___sysctl_args *args) {
  1887. if (args) {
  1888. if (args->name)
  1889. PRE_READ(args->name, args->nlen * sizeof(*args->name));
  1890. if (args->newval)
  1891. PRE_READ(args->name, args->newlen);
  1892. }
  1893. }
  1894. POST_SYSCALL(sysctl)(long res, __sanitizer___sysctl_args *args) {
  1895. if (res >= 0) {
  1896. if (args && args->oldval && args->oldlenp) {
  1897. POST_WRITE(args->oldlenp, sizeof(*args->oldlenp));
  1898. POST_WRITE(args->oldval, *args->oldlenp);
  1899. }
  1900. }
  1901. }
  1902. PRE_SYSCALL(sysinfo)(void *info) {}
  1903. POST_SYSCALL(sysinfo)(long res, void *info) {
  1904. if (res >= 0) {
  1905. if (info)
  1906. POST_WRITE(info, struct_sysinfo_sz);
  1907. }
  1908. }
  1909. PRE_SYSCALL(sysfs)(long option, long arg1, long arg2) {}
  1910. POST_SYSCALL(sysfs)(long res, long option, long arg1, long arg2) {}
  1911. PRE_SYSCALL(syslog)(long type, void *buf, long len) {}
  1912. POST_SYSCALL(syslog)(long res, long type, void *buf, long len) {
  1913. if (res >= 0) {
  1914. if (buf)
  1915. POST_WRITE(buf, __sanitizer::internal_strlen((const char *)buf) + 1);
  1916. }
  1917. }
  1918. PRE_SYSCALL(uselib)(const void *library) {
  1919. if (library)
  1920. PRE_READ(library, __sanitizer::internal_strlen((const char *)library) + 1);
  1921. }
  1922. POST_SYSCALL(uselib)(long res, const void *library) {}
  1923. PRE_SYSCALL(ni_syscall)() {}
  1924. POST_SYSCALL(ni_syscall)(long res) {}
  1925. PRE_SYSCALL(ptrace)(long request, long pid, long addr, long data) {
  1926. # if !SANITIZER_ANDROID && \
  1927. (defined(__i386) || defined(__x86_64) || defined(__mips64) || \
  1928. defined(__powerpc64__) || defined(__aarch64__) || defined(__s390__) || \
  1929. SANITIZER_RISCV64)
  1930. if (data) {
  1931. if (request == ptrace_setregs) {
  1932. PRE_READ((void *)data, struct_user_regs_struct_sz);
  1933. } else if (request == ptrace_setfpregs) {
  1934. PRE_READ((void *)data, struct_user_fpregs_struct_sz);
  1935. } else if (request == ptrace_setfpxregs) {
  1936. PRE_READ((void *)data, struct_user_fpxregs_struct_sz);
  1937. } else if (request == ptrace_setsiginfo) {
  1938. PRE_READ((void *)data, siginfo_t_sz);
  1939. } else if (request == ptrace_setregset) {
  1940. __sanitizer_iovec *iov = (__sanitizer_iovec *)data;
  1941. PRE_READ(iov->iov_base, iov->iov_len);
  1942. }
  1943. }
  1944. # endif
  1945. }
  1946. POST_SYSCALL(ptrace)(long res, long request, long pid, long addr, long data) {
  1947. # if !SANITIZER_ANDROID && \
  1948. (defined(__i386) || defined(__x86_64) || defined(__mips64) || \
  1949. defined(__powerpc64__) || defined(__aarch64__) || defined(__s390__) || \
  1950. SANITIZER_RISCV64)
  1951. if (res >= 0 && data) {
  1952. // Note that this is different from the interceptor in
  1953. // sanitizer_common_interceptors.inc.
  1954. // PEEK* requests return resulting values through data pointer.
  1955. if (request == ptrace_getregs) {
  1956. POST_WRITE((void *)data, struct_user_regs_struct_sz);
  1957. } else if (request == ptrace_getfpregs) {
  1958. POST_WRITE((void *)data, struct_user_fpregs_struct_sz);
  1959. } else if (request == ptrace_getfpxregs) {
  1960. POST_WRITE((void *)data, struct_user_fpxregs_struct_sz);
  1961. } else if (request == ptrace_getsiginfo) {
  1962. POST_WRITE((void *)data, siginfo_t_sz);
  1963. } else if (request == ptrace_getregset) {
  1964. __sanitizer_iovec *iov = (__sanitizer_iovec *)data;
  1965. POST_WRITE(iov->iov_base, iov->iov_len);
  1966. } else if (request == ptrace_peekdata || request == ptrace_peektext ||
  1967. request == ptrace_peekuser) {
  1968. POST_WRITE((void *)data, sizeof(void *));
  1969. }
  1970. }
  1971. # endif
  1972. }
  1973. PRE_SYSCALL(add_key)
  1974. (const void *_type, const void *_description, const void *_payload, long plen,
  1975. long destringid) {
  1976. if (_type)
  1977. PRE_READ(_type, __sanitizer::internal_strlen((const char *)_type) + 1);
  1978. if (_description)
  1979. PRE_READ(_description,
  1980. __sanitizer::internal_strlen((const char *)_description) + 1);
  1981. }
  1982. POST_SYSCALL(add_key)
  1983. (long res, const void *_type, const void *_description, const void *_payload,
  1984. long plen, long destringid) {}
  1985. PRE_SYSCALL(request_key)
  1986. (const void *_type, const void *_description, const void *_callout_info,
  1987. long destringid) {
  1988. if (_type)
  1989. PRE_READ(_type, __sanitizer::internal_strlen((const char *)_type) + 1);
  1990. if (_description)
  1991. PRE_READ(_description,
  1992. __sanitizer::internal_strlen((const char *)_description) + 1);
  1993. if (_callout_info)
  1994. PRE_READ(_callout_info,
  1995. __sanitizer::internal_strlen((const char *)_callout_info) + 1);
  1996. }
  1997. POST_SYSCALL(request_key)
  1998. (long res, const void *_type, const void *_description,
  1999. const void *_callout_info, long destringid) {}
  2000. PRE_SYSCALL(keyctl)(long cmd, long arg2, long arg3, long arg4, long arg5) {}
  2001. POST_SYSCALL(keyctl)
  2002. (long res, long cmd, long arg2, long arg3, long arg4, long arg5) {}
  2003. PRE_SYSCALL(ioprio_set)(long which, long who, long ioprio) {}
  2004. POST_SYSCALL(ioprio_set)(long res, long which, long who, long ioprio) {}
  2005. PRE_SYSCALL(ioprio_get)(long which, long who) {}
  2006. POST_SYSCALL(ioprio_get)(long res, long which, long who) {}
  2007. PRE_SYSCALL(set_mempolicy)(long mode, void *nmask, long maxnode) {}
  2008. POST_SYSCALL(set_mempolicy)(long res, long mode, void *nmask, long maxnode) {
  2009. if (res >= 0) {
  2010. if (nmask)
  2011. POST_WRITE(nmask, sizeof(long));
  2012. }
  2013. }
  2014. PRE_SYSCALL(migrate_pages)
  2015. (long pid, long maxnode, const void *from, const void *to) {
  2016. if (from)
  2017. PRE_READ(from, sizeof(long));
  2018. if (to)
  2019. PRE_READ(to, sizeof(long));
  2020. }
  2021. POST_SYSCALL(migrate_pages)
  2022. (long res, long pid, long maxnode, const void *from, const void *to) {}
  2023. PRE_SYSCALL(move_pages)
  2024. (long pid, long nr_pages, const void **pages, const int *nodes, int *status,
  2025. long flags) {
  2026. if (pages)
  2027. PRE_READ(pages, nr_pages * sizeof(*pages));
  2028. if (nodes)
  2029. PRE_READ(nodes, nr_pages * sizeof(*nodes));
  2030. }
  2031. POST_SYSCALL(move_pages)
  2032. (long res, long pid, long nr_pages, const void **pages, const int *nodes,
  2033. int *status, long flags) {
  2034. if (res >= 0) {
  2035. if (status)
  2036. POST_WRITE(status, nr_pages * sizeof(*status));
  2037. }
  2038. }
  2039. PRE_SYSCALL(mbind)
  2040. (long start, long len, long mode, void *nmask, long maxnode, long flags) {}
  2041. POST_SYSCALL(mbind)
  2042. (long res, long start, long len, long mode, void *nmask, long maxnode,
  2043. long flags) {
  2044. if (res >= 0) {
  2045. if (nmask)
  2046. POST_WRITE(nmask, sizeof(long));
  2047. }
  2048. }
  2049. PRE_SYSCALL(get_mempolicy)
  2050. (void *policy, void *nmask, long maxnode, long addr, long flags) {}
  2051. POST_SYSCALL(get_mempolicy)
  2052. (long res, void *policy, void *nmask, long maxnode, long addr, long flags) {
  2053. if (res >= 0) {
  2054. if (policy)
  2055. POST_WRITE(policy, sizeof(int));
  2056. if (nmask)
  2057. POST_WRITE(nmask, sizeof(long));
  2058. }
  2059. }
  2060. PRE_SYSCALL(inotify_init)() {}
  2061. POST_SYSCALL(inotify_init)(long res) {}
  2062. PRE_SYSCALL(inotify_init1)(long flags) {}
  2063. POST_SYSCALL(inotify_init1)(long res, long flags) {}
  2064. PRE_SYSCALL(inotify_add_watch)(long fd, const void *path, long mask) {
  2065. if (path)
  2066. PRE_READ(path, __sanitizer::internal_strlen((const char *)path) + 1);
  2067. }
  2068. POST_SYSCALL(inotify_add_watch)
  2069. (long res, long fd, const void *path, long mask) {}
  2070. PRE_SYSCALL(inotify_rm_watch)(long fd, long wd) {}
  2071. POST_SYSCALL(inotify_rm_watch)(long res, long fd, long wd) {}
  2072. PRE_SYSCALL(spu_run)(long fd, void *unpc, void *ustatus) {}
  2073. POST_SYSCALL(spu_run)(long res, long fd, unsigned *unpc, unsigned *ustatus) {
  2074. if (res >= 0) {
  2075. if (unpc)
  2076. POST_WRITE(unpc, sizeof(*unpc));
  2077. if (ustatus)
  2078. POST_WRITE(ustatus, sizeof(*ustatus));
  2079. }
  2080. }
  2081. PRE_SYSCALL(spu_create)(const void *name, long flags, long mode, long fd) {
  2082. if (name)
  2083. PRE_READ(name, __sanitizer::internal_strlen((const char *)name) + 1);
  2084. }
  2085. POST_SYSCALL(spu_create)
  2086. (long res, const void *name, long flags, long mode, long fd) {}
  2087. PRE_SYSCALL(mknodat)(long dfd, const void *filename, long mode, long dev) {
  2088. if (filename)
  2089. PRE_READ(filename,
  2090. __sanitizer::internal_strlen((const char *)filename) + 1);
  2091. }
  2092. POST_SYSCALL(mknodat)
  2093. (long res, long dfd, const void *filename, long mode, long dev) {}
  2094. PRE_SYSCALL(mkdirat)(long dfd, const void *pathname, long mode) {
  2095. if (pathname)
  2096. PRE_READ(pathname,
  2097. __sanitizer::internal_strlen((const char *)pathname) + 1);
  2098. }
  2099. POST_SYSCALL(mkdirat)(long res, long dfd, const void *pathname, long mode) {}
  2100. PRE_SYSCALL(unlinkat)(long dfd, const void *pathname, long flag) {
  2101. if (pathname)
  2102. PRE_READ(pathname,
  2103. __sanitizer::internal_strlen((const char *)pathname) + 1);
  2104. }
  2105. POST_SYSCALL(unlinkat)(long res, long dfd, const void *pathname, long flag) {}
  2106. PRE_SYSCALL(symlinkat)(const void *oldname, long newdfd, const void *newname) {
  2107. if (oldname)
  2108. PRE_READ(oldname, __sanitizer::internal_strlen((const char *)oldname) + 1);
  2109. if (newname)
  2110. PRE_READ(newname, __sanitizer::internal_strlen((const char *)newname) + 1);
  2111. }
  2112. POST_SYSCALL(symlinkat)
  2113. (long res, const void *oldname, long newdfd, const void *newname) {}
  2114. PRE_SYSCALL(linkat)
  2115. (long olddfd, const void *oldname, long newdfd, const void *newname,
  2116. long flags) {
  2117. if (oldname)
  2118. PRE_READ(oldname, __sanitizer::internal_strlen((const char *)oldname) + 1);
  2119. if (newname)
  2120. PRE_READ(newname, __sanitizer::internal_strlen((const char *)newname) + 1);
  2121. }
  2122. POST_SYSCALL(linkat)
  2123. (long res, long olddfd, const void *oldname, long newdfd, const void *newname,
  2124. long flags) {}
  2125. PRE_SYSCALL(renameat)
  2126. (long olddfd, const void *oldname, long newdfd, const void *newname) {
  2127. if (oldname)
  2128. PRE_READ(oldname, __sanitizer::internal_strlen((const char *)oldname) + 1);
  2129. if (newname)
  2130. PRE_READ(newname, __sanitizer::internal_strlen((const char *)newname) + 1);
  2131. }
  2132. POST_SYSCALL(renameat)
  2133. (long res, long olddfd, const void *oldname, long newdfd, const void *newname) {
  2134. }
  2135. PRE_SYSCALL(futimesat)(long dfd, const void *filename, void *utimes) {
  2136. if (filename)
  2137. PRE_READ(filename,
  2138. __sanitizer::internal_strlen((const char *)filename) + 1);
  2139. }
  2140. POST_SYSCALL(futimesat)
  2141. (long res, long dfd, const void *filename, void *utimes) {
  2142. if (res >= 0) {
  2143. if (utimes)
  2144. POST_WRITE(utimes, timeval_sz);
  2145. }
  2146. }
  2147. PRE_SYSCALL(faccessat)(long dfd, const void *filename, long mode) {
  2148. if (filename)
  2149. PRE_READ(filename,
  2150. __sanitizer::internal_strlen((const char *)filename) + 1);
  2151. }
  2152. POST_SYSCALL(faccessat)(long res, long dfd, const void *filename, long mode) {}
  2153. PRE_SYSCALL(fchmodat)(long dfd, const void *filename, long mode) {
  2154. if (filename)
  2155. PRE_READ(filename,
  2156. __sanitizer::internal_strlen((const char *)filename) + 1);
  2157. }
  2158. POST_SYSCALL(fchmodat)(long res, long dfd, const void *filename, long mode) {}
  2159. PRE_SYSCALL(fchownat)
  2160. (long dfd, const void *filename, long user, long group, long flag) {
  2161. if (filename)
  2162. PRE_READ(filename,
  2163. __sanitizer::internal_strlen((const char *)filename) + 1);
  2164. }
  2165. POST_SYSCALL(fchownat)
  2166. (long res, long dfd, const void *filename, long user, long group, long flag) {}
  2167. PRE_SYSCALL(openat)(long dfd, const void *filename, long flags, long mode) {
  2168. if (filename)
  2169. PRE_READ(filename,
  2170. __sanitizer::internal_strlen((const char *)filename) + 1);
  2171. }
  2172. POST_SYSCALL(openat)
  2173. (long res, long dfd, const void *filename, long flags, long mode) {}
  2174. PRE_SYSCALL(newfstatat)
  2175. (long dfd, const void *filename, void *statbuf, long flag) {
  2176. if (filename)
  2177. PRE_READ(filename,
  2178. __sanitizer::internal_strlen((const char *)filename) + 1);
  2179. }
  2180. POST_SYSCALL(newfstatat)
  2181. (long res, long dfd, const void *filename, void *statbuf, long flag) {
  2182. if (res >= 0) {
  2183. if (statbuf)
  2184. POST_WRITE(statbuf, struct_kernel_stat_sz);
  2185. }
  2186. }
  2187. PRE_SYSCALL(fstatat64)
  2188. (long dfd, const void *filename, void *statbuf, long flag) {
  2189. if (filename)
  2190. PRE_READ(filename,
  2191. __sanitizer::internal_strlen((const char *)filename) + 1);
  2192. }
  2193. POST_SYSCALL(fstatat64)
  2194. (long res, long dfd, const void *filename, void *statbuf, long flag) {
  2195. if (res >= 0) {
  2196. if (statbuf)
  2197. POST_WRITE(statbuf, struct_kernel_stat64_sz);
  2198. }
  2199. }
  2200. PRE_SYSCALL(readlinkat)(long dfd, const void *path, void *buf, long bufsiz) {
  2201. if (path)
  2202. PRE_READ(path, __sanitizer::internal_strlen((const char *)path) + 1);
  2203. }
  2204. POST_SYSCALL(readlinkat)
  2205. (long res, long dfd, const void *path, void *buf, long bufsiz) {
  2206. if (res >= 0) {
  2207. if (buf)
  2208. POST_WRITE(buf, __sanitizer::internal_strlen((const char *)buf) + 1);
  2209. }
  2210. }
  2211. PRE_SYSCALL(utimensat)
  2212. (long dfd, const void *filename, void *utimes, long flags) {
  2213. if (filename)
  2214. PRE_READ(filename,
  2215. __sanitizer::internal_strlen((const char *)filename) + 1);
  2216. }
  2217. POST_SYSCALL(utimensat)
  2218. (long res, long dfd, const void *filename, void *utimes, long flags) {
  2219. if (res >= 0) {
  2220. if (utimes)
  2221. POST_WRITE(utimes, struct_timespec_sz);
  2222. }
  2223. }
  2224. PRE_SYSCALL(unshare)(long unshare_flags) {}
  2225. POST_SYSCALL(unshare)(long res, long unshare_flags) {}
  2226. PRE_SYSCALL(splice)
  2227. (long fd_in, void *off_in, long fd_out, void *off_out, long len, long flags) {}
  2228. POST_SYSCALL(splice)
  2229. (long res, long fd_in, void *off_in, long fd_out, void *off_out, long len,
  2230. long flags) {
  2231. if (res >= 0) {
  2232. if (off_in)
  2233. POST_WRITE(off_in, sizeof(long long));
  2234. if (off_out)
  2235. POST_WRITE(off_out, sizeof(long long));
  2236. }
  2237. }
  2238. PRE_SYSCALL(vmsplice)
  2239. (long fd, const __sanitizer_iovec *iov, long nr_segs, long flags) {}
  2240. POST_SYSCALL(vmsplice)
  2241. (long res, long fd, const __sanitizer_iovec *iov, long nr_segs, long flags) {
  2242. if (res >= 0) {
  2243. if (iov)
  2244. kernel_read_iovec(iov, nr_segs, res);
  2245. }
  2246. }
  2247. PRE_SYSCALL(tee)(long fdin, long fdout, long len, long flags) {}
  2248. POST_SYSCALL(tee)(long res, long fdin, long fdout, long len, long flags) {}
  2249. PRE_SYSCALL(get_robust_list)(long pid, void *head_ptr, void *len_ptr) {}
  2250. POST_SYSCALL(get_robust_list)
  2251. (long res, long pid, void *head_ptr, void *len_ptr) {}
  2252. PRE_SYSCALL(set_robust_list)(void *head, long len) {}
  2253. POST_SYSCALL(set_robust_list)(long res, void *head, long len) {}
  2254. PRE_SYSCALL(getcpu)(void *cpu, void *node, void *cache) {}
  2255. POST_SYSCALL(getcpu)(long res, void *cpu, void *node, void *cache) {
  2256. if (res >= 0) {
  2257. if (cpu)
  2258. POST_WRITE(cpu, sizeof(unsigned));
  2259. if (node)
  2260. POST_WRITE(node, sizeof(unsigned));
  2261. // The third argument to this system call is nowadays unused.
  2262. }
  2263. }
  2264. PRE_SYSCALL(signalfd)(long ufd, void *user_mask, long sizemask) {}
  2265. POST_SYSCALL(signalfd)
  2266. (long res, long ufd, kernel_sigset_t *user_mask, long sizemask) {
  2267. if (res >= 0) {
  2268. if (user_mask)
  2269. POST_WRITE(user_mask, sizemask);
  2270. }
  2271. }
  2272. PRE_SYSCALL(signalfd4)(long ufd, void *user_mask, long sizemask, long flags) {}
  2273. POST_SYSCALL(signalfd4)
  2274. (long res, long ufd, kernel_sigset_t *user_mask, long sizemask, long flags) {
  2275. if (res >= 0) {
  2276. if (user_mask)
  2277. POST_WRITE(user_mask, sizemask);
  2278. }
  2279. }
  2280. PRE_SYSCALL(timerfd_create)(long clockid, long flags) {}
  2281. POST_SYSCALL(timerfd_create)(long res, long clockid, long flags) {}
  2282. PRE_SYSCALL(timerfd_settime)
  2283. (long ufd, long flags, const void *utmr, void *otmr) {
  2284. if (utmr)
  2285. PRE_READ(utmr, struct_itimerspec_sz);
  2286. }
  2287. POST_SYSCALL(timerfd_settime)
  2288. (long res, long ufd, long flags, const void *utmr, void *otmr) {
  2289. if (res >= 0) {
  2290. if (otmr)
  2291. POST_WRITE(otmr, struct_itimerspec_sz);
  2292. }
  2293. }
  2294. PRE_SYSCALL(timerfd_gettime)(long ufd, void *otmr) {}
  2295. POST_SYSCALL(timerfd_gettime)(long res, long ufd, void *otmr) {
  2296. if (res >= 0) {
  2297. if (otmr)
  2298. POST_WRITE(otmr, struct_itimerspec_sz);
  2299. }
  2300. }
  2301. PRE_SYSCALL(eventfd)(long count) {}
  2302. POST_SYSCALL(eventfd)(long res, long count) {}
  2303. PRE_SYSCALL(eventfd2)(long count, long flags) {}
  2304. POST_SYSCALL(eventfd2)(long res, long count, long flags) {}
  2305. PRE_SYSCALL(old_readdir)(long arg0, void *arg1, long arg2) {}
  2306. POST_SYSCALL(old_readdir)(long res, long arg0, void *arg1, long arg2) {
  2307. // Missing definition of 'struct old_linux_dirent'.
  2308. }
  2309. PRE_SYSCALL(pselect6)
  2310. (long arg0, __sanitizer___kernel_fd_set *arg1,
  2311. __sanitizer___kernel_fd_set *arg2, __sanitizer___kernel_fd_set *arg3,
  2312. void *arg4, void *arg5) {}
  2313. POST_SYSCALL(pselect6)
  2314. (long res, long arg0, __sanitizer___kernel_fd_set *arg1,
  2315. __sanitizer___kernel_fd_set *arg2, __sanitizer___kernel_fd_set *arg3,
  2316. void *arg4, void *arg5) {
  2317. if (res >= 0) {
  2318. if (arg1)
  2319. POST_WRITE(arg1, sizeof(*arg1));
  2320. if (arg2)
  2321. POST_WRITE(arg2, sizeof(*arg2));
  2322. if (arg3)
  2323. POST_WRITE(arg3, sizeof(*arg3));
  2324. if (arg4)
  2325. POST_WRITE(arg4, struct_timespec_sz);
  2326. }
  2327. }
  2328. PRE_SYSCALL(ppoll)
  2329. (__sanitizer_pollfd *arg0, long arg1, void *arg2, const kernel_sigset_t *arg3,
  2330. long arg4) {
  2331. if (arg3)
  2332. PRE_READ(arg3, arg4);
  2333. }
  2334. POST_SYSCALL(ppoll)
  2335. (long res, __sanitizer_pollfd *arg0, long arg1, void *arg2, const void *arg3,
  2336. long arg4) {
  2337. if (res >= 0) {
  2338. if (arg0)
  2339. POST_WRITE(arg0, sizeof(*arg0));
  2340. if (arg2)
  2341. POST_WRITE(arg2, struct_timespec_sz);
  2342. }
  2343. }
  2344. PRE_SYSCALL(syncfs)(long fd) {}
  2345. POST_SYSCALL(syncfs)(long res, long fd) {}
  2346. PRE_SYSCALL(perf_event_open)
  2347. (__sanitizer_perf_event_attr *attr_uptr, long pid, long cpu, long group_fd,
  2348. long flags) {
  2349. if (attr_uptr)
  2350. PRE_READ(attr_uptr, attr_uptr->size);
  2351. }
  2352. POST_SYSCALL(perf_event_open)
  2353. (long res, __sanitizer_perf_event_attr *attr_uptr, long pid, long cpu,
  2354. long group_fd, long flags) {}
  2355. PRE_SYSCALL(mmap_pgoff)
  2356. (long addr, long len, long prot, long flags, long fd, long pgoff) {}
  2357. POST_SYSCALL(mmap_pgoff)
  2358. (long res, long addr, long len, long prot, long flags, long fd, long pgoff) {}
  2359. PRE_SYSCALL(old_mmap)(void *arg) {}
  2360. POST_SYSCALL(old_mmap)(long res, void *arg) {}
  2361. PRE_SYSCALL(name_to_handle_at)
  2362. (long dfd, const void *name, void *handle, void *mnt_id, long flag) {}
  2363. POST_SYSCALL(name_to_handle_at)
  2364. (long res, long dfd, const void *name, void *handle, void *mnt_id, long flag) {}
  2365. PRE_SYSCALL(open_by_handle_at)(long mountdirfd, void *handle, long flags) {}
  2366. POST_SYSCALL(open_by_handle_at)
  2367. (long res, long mountdirfd, void *handle, long flags) {}
  2368. PRE_SYSCALL(setns)(long fd, long nstype) {}
  2369. POST_SYSCALL(setns)(long res, long fd, long nstype) {}
  2370. PRE_SYSCALL(process_vm_readv)
  2371. (long pid, const __sanitizer_iovec *lvec, long liovcnt, const void *rvec,
  2372. long riovcnt, long flags) {}
  2373. POST_SYSCALL(process_vm_readv)
  2374. (long res, long pid, const __sanitizer_iovec *lvec, long liovcnt,
  2375. const void *rvec, long riovcnt, long flags) {
  2376. if (res >= 0) {
  2377. if (lvec)
  2378. kernel_write_iovec(lvec, liovcnt, res);
  2379. }
  2380. }
  2381. PRE_SYSCALL(process_vm_writev)
  2382. (long pid, const __sanitizer_iovec *lvec, long liovcnt, const void *rvec,
  2383. long riovcnt, long flags) {}
  2384. POST_SYSCALL(process_vm_writev)
  2385. (long res, long pid, const __sanitizer_iovec *lvec, long liovcnt,
  2386. const void *rvec, long riovcnt, long flags) {
  2387. if (res >= 0) {
  2388. if (lvec)
  2389. kernel_read_iovec(lvec, liovcnt, res);
  2390. }
  2391. }
  2392. PRE_SYSCALL(fork)() { COMMON_SYSCALL_PRE_FORK(); }
  2393. POST_SYSCALL(fork)(long res) { COMMON_SYSCALL_POST_FORK(res); }
  2394. PRE_SYSCALL(vfork)() { COMMON_SYSCALL_PRE_FORK(); }
  2395. POST_SYSCALL(vfork)(long res) { COMMON_SYSCALL_POST_FORK(res); }
  2396. PRE_SYSCALL(sigaction)
  2397. (long signum, const __sanitizer_kernel_sigaction_t *act,
  2398. __sanitizer_kernel_sigaction_t *oldact) {
  2399. if (act) {
  2400. PRE_READ(&act->sigaction, sizeof(act->sigaction));
  2401. PRE_READ(&act->sa_flags, sizeof(act->sa_flags));
  2402. PRE_READ(&act->sa_mask, sizeof(act->sa_mask));
  2403. }
  2404. }
  2405. POST_SYSCALL(sigaction)
  2406. (long res, long signum, const __sanitizer_kernel_sigaction_t *act,
  2407. __sanitizer_kernel_sigaction_t *oldact) {
  2408. if (res >= 0 && oldact)
  2409. POST_WRITE(oldact, sizeof(*oldact));
  2410. }
  2411. PRE_SYSCALL(rt_sigaction)
  2412. (long signum, const __sanitizer_kernel_sigaction_t *act,
  2413. __sanitizer_kernel_sigaction_t *oldact, SIZE_T sz) {
  2414. if (act) {
  2415. PRE_READ(&act->sigaction, sizeof(act->sigaction));
  2416. PRE_READ(&act->sa_flags, sizeof(act->sa_flags));
  2417. PRE_READ(&act->sa_mask, sz);
  2418. }
  2419. }
  2420. POST_SYSCALL(rt_sigaction)
  2421. (long res, long signum, const __sanitizer_kernel_sigaction_t *act,
  2422. __sanitizer_kernel_sigaction_t *oldact, SIZE_T sz) {
  2423. if (res >= 0 && oldact) {
  2424. SIZE_T oldact_sz = ((char *)&oldact->sa_mask) - ((char *)oldact) + sz;
  2425. POST_WRITE(oldact, oldact_sz);
  2426. }
  2427. }
  2428. PRE_SYSCALL(getrandom)(void *buf, uptr count, long flags) {
  2429. if (buf) {
  2430. PRE_WRITE(buf, count);
  2431. }
  2432. }
  2433. POST_SYSCALL(getrandom)(long res, void *buf, uptr count, long flags) {
  2434. if (res > 0 && buf) {
  2435. POST_WRITE(buf, res);
  2436. }
  2437. }
  2438. PRE_SYSCALL(sigaltstack)(const void *ss, void *oss) {
  2439. if (ss != nullptr) {
  2440. PRE_READ(ss, struct_stack_t_sz);
  2441. }
  2442. if (oss != nullptr) {
  2443. PRE_WRITE(oss, struct_stack_t_sz);
  2444. }
  2445. }
  2446. POST_SYSCALL(sigaltstack)(long res, void *ss, void *oss) {
  2447. if (res == 0) {
  2448. if (oss != nullptr) {
  2449. POST_WRITE(oss, struct_stack_t_sz);
  2450. }
  2451. }
  2452. }
  2453. } // extern "C"
  2454. # undef PRE_SYSCALL
  2455. # undef PRE_READ
  2456. # undef PRE_WRITE
  2457. # undef POST_SYSCALL
  2458. # undef POST_READ
  2459. # undef POST_WRITE
  2460. #endif // SANITIZER_LINUX