ptrace.c 48 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813
  1. /*
  2. * Kernel support for the ptrace() and syscall tracing interfaces.
  3. *
  4. * Copyright (C) 1999-2005 Hewlett-Packard Co
  5. * David Mosberger-Tang <davidm@hpl.hp.com>
  6. *
  7. * Derived from the x86 and Alpha versions.
  8. */
  9. #include <linux/kernel.h>
  10. #include <linux/sched.h>
  11. #include <linux/slab.h>
  12. #include <linux/mm.h>
  13. #include <linux/errno.h>
  14. #include <linux/ptrace.h>
  15. #include <linux/smp_lock.h>
  16. #include <linux/user.h>
  17. #include <linux/security.h>
  18. #include <linux/audit.h>
  19. #include <linux/signal.h>
  20. #include <asm/pgtable.h>
  21. #include <asm/processor.h>
  22. #include <asm/ptrace_offsets.h>
  23. #include <asm/rse.h>
  24. #include <asm/system.h>
  25. #include <asm/uaccess.h>
  26. #include <asm/unwind.h>
  27. #ifdef CONFIG_PERFMON
  28. #include <asm/perfmon.h>
  29. #endif
  30. #include "entry.h"
  31. /*
  32. * Bits in the PSR that we allow ptrace() to change:
  33. * be, up, ac, mfl, mfh (the user mask; five bits total)
  34. * db (debug breakpoint fault; one bit)
  35. * id (instruction debug fault disable; one bit)
  36. * dd (data debug fault disable; one bit)
  37. * ri (restart instruction; two bits)
  38. * is (instruction set; one bit)
  39. */
  40. #define IPSR_MASK (IA64_PSR_UM | IA64_PSR_DB | IA64_PSR_IS \
  41. | IA64_PSR_ID | IA64_PSR_DD | IA64_PSR_RI)
  42. #define MASK(nbits) ((1UL << (nbits)) - 1) /* mask with NBITS bits set */
  43. #define PFM_MASK MASK(38)
  44. #define PTRACE_DEBUG 0
  45. #if PTRACE_DEBUG
  46. # define dprintk(format...) printk(format)
  47. # define inline
  48. #else
  49. # define dprintk(format...)
  50. #endif
  51. /* Return TRUE if PT was created due to kernel-entry via a system-call. */
  52. static inline int
  53. in_syscall (struct pt_regs *pt)
  54. {
  55. return (long) pt->cr_ifs >= 0;
  56. }
  57. /*
  58. * Collect the NaT bits for r1-r31 from scratch_unat and return a NaT
  59. * bitset where bit i is set iff the NaT bit of register i is set.
  60. */
  61. unsigned long
  62. ia64_get_scratch_nat_bits (struct pt_regs *pt, unsigned long scratch_unat)
  63. {
  64. # define GET_BITS(first, last, unat) \
  65. ({ \
  66. unsigned long bit = ia64_unat_pos(&pt->r##first); \
  67. unsigned long nbits = (last - first + 1); \
  68. unsigned long mask = MASK(nbits) << first; \
  69. unsigned long dist; \
  70. if (bit < first) \
  71. dist = 64 + bit - first; \
  72. else \
  73. dist = bit - first; \
  74. ia64_rotr(unat, dist) & mask; \
  75. })
  76. unsigned long val;
  77. /*
  78. * Registers that are stored consecutively in struct pt_regs
  79. * can be handled in parallel. If the register order in
  80. * struct_pt_regs changes, this code MUST be updated.
  81. */
  82. val = GET_BITS( 1, 1, scratch_unat);
  83. val |= GET_BITS( 2, 3, scratch_unat);
  84. val |= GET_BITS(12, 13, scratch_unat);
  85. val |= GET_BITS(14, 14, scratch_unat);
  86. val |= GET_BITS(15, 15, scratch_unat);
  87. val |= GET_BITS( 8, 11, scratch_unat);
  88. val |= GET_BITS(16, 31, scratch_unat);
  89. return val;
  90. # undef GET_BITS
  91. }
  92. /*
  93. * Set the NaT bits for the scratch registers according to NAT and
  94. * return the resulting unat (assuming the scratch registers are
  95. * stored in PT).
  96. */
  97. unsigned long
  98. ia64_put_scratch_nat_bits (struct pt_regs *pt, unsigned long nat)
  99. {
  100. # define PUT_BITS(first, last, nat) \
  101. ({ \
  102. unsigned long bit = ia64_unat_pos(&pt->r##first); \
  103. unsigned long nbits = (last - first + 1); \
  104. unsigned long mask = MASK(nbits) << first; \
  105. long dist; \
  106. if (bit < first) \
  107. dist = 64 + bit - first; \
  108. else \
  109. dist = bit - first; \
  110. ia64_rotl(nat & mask, dist); \
  111. })
  112. unsigned long scratch_unat;
  113. /*
  114. * Registers that are stored consecutively in struct pt_regs
  115. * can be handled in parallel. If the register order in
  116. * struct_pt_regs changes, this code MUST be updated.
  117. */
  118. scratch_unat = PUT_BITS( 1, 1, nat);
  119. scratch_unat |= PUT_BITS( 2, 3, nat);
  120. scratch_unat |= PUT_BITS(12, 13, nat);
  121. scratch_unat |= PUT_BITS(14, 14, nat);
  122. scratch_unat |= PUT_BITS(15, 15, nat);
  123. scratch_unat |= PUT_BITS( 8, 11, nat);
  124. scratch_unat |= PUT_BITS(16, 31, nat);
  125. return scratch_unat;
  126. # undef PUT_BITS
  127. }
  128. #define IA64_MLX_TEMPLATE 0x2
  129. #define IA64_MOVL_OPCODE 6
  130. void
  131. ia64_increment_ip (struct pt_regs *regs)
  132. {
  133. unsigned long w0, ri = ia64_psr(regs)->ri + 1;
  134. if (ri > 2) {
  135. ri = 0;
  136. regs->cr_iip += 16;
  137. } else if (ri == 2) {
  138. get_user(w0, (char __user *) regs->cr_iip + 0);
  139. if (((w0 >> 1) & 0xf) == IA64_MLX_TEMPLATE) {
  140. /*
  141. * rfi'ing to slot 2 of an MLX bundle causes
  142. * an illegal operation fault. We don't want
  143. * that to happen...
  144. */
  145. ri = 0;
  146. regs->cr_iip += 16;
  147. }
  148. }
  149. ia64_psr(regs)->ri = ri;
  150. }
  151. void
  152. ia64_decrement_ip (struct pt_regs *regs)
  153. {
  154. unsigned long w0, ri = ia64_psr(regs)->ri - 1;
  155. if (ia64_psr(regs)->ri == 0) {
  156. regs->cr_iip -= 16;
  157. ri = 2;
  158. get_user(w0, (char __user *) regs->cr_iip + 0);
  159. if (((w0 >> 1) & 0xf) == IA64_MLX_TEMPLATE) {
  160. /*
  161. * rfi'ing to slot 2 of an MLX bundle causes
  162. * an illegal operation fault. We don't want
  163. * that to happen...
  164. */
  165. ri = 1;
  166. }
  167. }
  168. ia64_psr(regs)->ri = ri;
  169. }
  170. /*
  171. * This routine is used to read an rnat bits that are stored on the
  172. * kernel backing store. Since, in general, the alignment of the user
  173. * and kernel are different, this is not completely trivial. In
  174. * essence, we need to construct the user RNAT based on up to two
  175. * kernel RNAT values and/or the RNAT value saved in the child's
  176. * pt_regs.
  177. *
  178. * user rbs
  179. *
  180. * +--------+ <-- lowest address
  181. * | slot62 |
  182. * +--------+
  183. * | rnat | 0x....1f8
  184. * +--------+
  185. * | slot00 | \
  186. * +--------+ |
  187. * | slot01 | > child_regs->ar_rnat
  188. * +--------+ |
  189. * | slot02 | / kernel rbs
  190. * +--------+ +--------+
  191. * <- child_regs->ar_bspstore | slot61 | <-- krbs
  192. * +- - - - + +--------+
  193. * | slot62 |
  194. * +- - - - + +--------+
  195. * | rnat |
  196. * +- - - - + +--------+
  197. * vrnat | slot00 |
  198. * +- - - - + +--------+
  199. * = =
  200. * +--------+
  201. * | slot00 | \
  202. * +--------+ |
  203. * | slot01 | > child_stack->ar_rnat
  204. * +--------+ |
  205. * | slot02 | /
  206. * +--------+
  207. * <--- child_stack->ar_bspstore
  208. *
  209. * The way to think of this code is as follows: bit 0 in the user rnat
  210. * corresponds to some bit N (0 <= N <= 62) in one of the kernel rnat
  211. * value. The kernel rnat value holding this bit is stored in
  212. * variable rnat0. rnat1 is loaded with the kernel rnat value that
  213. * form the upper bits of the user rnat value.
  214. *
  215. * Boundary cases:
  216. *
  217. * o when reading the rnat "below" the first rnat slot on the kernel
  218. * backing store, rnat0/rnat1 are set to 0 and the low order bits are
  219. * merged in from pt->ar_rnat.
  220. *
  221. * o when reading the rnat "above" the last rnat slot on the kernel
  222. * backing store, rnat0/rnat1 gets its value from sw->ar_rnat.
  223. */
  224. static unsigned long
  225. get_rnat (struct task_struct *task, struct switch_stack *sw,
  226. unsigned long *krbs, unsigned long *urnat_addr,
  227. unsigned long *urbs_end)
  228. {
  229. unsigned long rnat0 = 0, rnat1 = 0, urnat = 0, *slot0_kaddr;
  230. unsigned long umask = 0, mask, m;
  231. unsigned long *kbsp, *ubspstore, *rnat0_kaddr, *rnat1_kaddr, shift;
  232. long num_regs, nbits;
  233. struct pt_regs *pt;
  234. pt = task_pt_regs(task);
  235. kbsp = (unsigned long *) sw->ar_bspstore;
  236. ubspstore = (unsigned long *) pt->ar_bspstore;
  237. if (urbs_end < urnat_addr)
  238. nbits = ia64_rse_num_regs(urnat_addr - 63, urbs_end);
  239. else
  240. nbits = 63;
  241. mask = MASK(nbits);
  242. /*
  243. * First, figure out which bit number slot 0 in user-land maps
  244. * to in the kernel rnat. Do this by figuring out how many
  245. * register slots we're beyond the user's backingstore and
  246. * then computing the equivalent address in kernel space.
  247. */
  248. num_regs = ia64_rse_num_regs(ubspstore, urnat_addr + 1);
  249. slot0_kaddr = ia64_rse_skip_regs(krbs, num_regs);
  250. shift = ia64_rse_slot_num(slot0_kaddr);
  251. rnat1_kaddr = ia64_rse_rnat_addr(slot0_kaddr);
  252. rnat0_kaddr = rnat1_kaddr - 64;
  253. if (ubspstore + 63 > urnat_addr) {
  254. /* some bits need to be merged in from pt->ar_rnat */
  255. umask = MASK(ia64_rse_slot_num(ubspstore)) & mask;
  256. urnat = (pt->ar_rnat & umask);
  257. mask &= ~umask;
  258. if (!mask)
  259. return urnat;
  260. }
  261. m = mask << shift;
  262. if (rnat0_kaddr >= kbsp)
  263. rnat0 = sw->ar_rnat;
  264. else if (rnat0_kaddr > krbs)
  265. rnat0 = *rnat0_kaddr;
  266. urnat |= (rnat0 & m) >> shift;
  267. m = mask >> (63 - shift);
  268. if (rnat1_kaddr >= kbsp)
  269. rnat1 = sw->ar_rnat;
  270. else if (rnat1_kaddr > krbs)
  271. rnat1 = *rnat1_kaddr;
  272. urnat |= (rnat1 & m) << (63 - shift);
  273. return urnat;
  274. }
  275. /*
  276. * The reverse of get_rnat.
  277. */
  278. static void
  279. put_rnat (struct task_struct *task, struct switch_stack *sw,
  280. unsigned long *krbs, unsigned long *urnat_addr, unsigned long urnat,
  281. unsigned long *urbs_end)
  282. {
  283. unsigned long rnat0 = 0, rnat1 = 0, *slot0_kaddr, umask = 0, mask, m;
  284. unsigned long *kbsp, *ubspstore, *rnat0_kaddr, *rnat1_kaddr, shift;
  285. long num_regs, nbits;
  286. struct pt_regs *pt;
  287. unsigned long cfm, *urbs_kargs;
  288. pt = task_pt_regs(task);
  289. kbsp = (unsigned long *) sw->ar_bspstore;
  290. ubspstore = (unsigned long *) pt->ar_bspstore;
  291. urbs_kargs = urbs_end;
  292. if (in_syscall(pt)) {
  293. /*
  294. * If entered via syscall, don't allow user to set rnat bits
  295. * for syscall args.
  296. */
  297. cfm = pt->cr_ifs;
  298. urbs_kargs = ia64_rse_skip_regs(urbs_end, -(cfm & 0x7f));
  299. }
  300. if (urbs_kargs >= urnat_addr)
  301. nbits = 63;
  302. else {
  303. if ((urnat_addr - 63) >= urbs_kargs)
  304. return;
  305. nbits = ia64_rse_num_regs(urnat_addr - 63, urbs_kargs);
  306. }
  307. mask = MASK(nbits);
  308. /*
  309. * First, figure out which bit number slot 0 in user-land maps
  310. * to in the kernel rnat. Do this by figuring out how many
  311. * register slots we're beyond the user's backingstore and
  312. * then computing the equivalent address in kernel space.
  313. */
  314. num_regs = ia64_rse_num_regs(ubspstore, urnat_addr + 1);
  315. slot0_kaddr = ia64_rse_skip_regs(krbs, num_regs);
  316. shift = ia64_rse_slot_num(slot0_kaddr);
  317. rnat1_kaddr = ia64_rse_rnat_addr(slot0_kaddr);
  318. rnat0_kaddr = rnat1_kaddr - 64;
  319. if (ubspstore + 63 > urnat_addr) {
  320. /* some bits need to be place in pt->ar_rnat: */
  321. umask = MASK(ia64_rse_slot_num(ubspstore)) & mask;
  322. pt->ar_rnat = (pt->ar_rnat & ~umask) | (urnat & umask);
  323. mask &= ~umask;
  324. if (!mask)
  325. return;
  326. }
  327. /*
  328. * Note: Section 11.1 of the EAS guarantees that bit 63 of an
  329. * rnat slot is ignored. so we don't have to clear it here.
  330. */
  331. rnat0 = (urnat << shift);
  332. m = mask << shift;
  333. if (rnat0_kaddr >= kbsp)
  334. sw->ar_rnat = (sw->ar_rnat & ~m) | (rnat0 & m);
  335. else if (rnat0_kaddr > krbs)
  336. *rnat0_kaddr = ((*rnat0_kaddr & ~m) | (rnat0 & m));
  337. rnat1 = (urnat >> (63 - shift));
  338. m = mask >> (63 - shift);
  339. if (rnat1_kaddr >= kbsp)
  340. sw->ar_rnat = (sw->ar_rnat & ~m) | (rnat1 & m);
  341. else if (rnat1_kaddr > krbs)
  342. *rnat1_kaddr = ((*rnat1_kaddr & ~m) | (rnat1 & m));
  343. }
  344. static inline int
  345. on_kernel_rbs (unsigned long addr, unsigned long bspstore,
  346. unsigned long urbs_end)
  347. {
  348. unsigned long *rnat_addr = ia64_rse_rnat_addr((unsigned long *)
  349. urbs_end);
  350. return (addr >= bspstore && addr <= (unsigned long) rnat_addr);
  351. }
  352. /*
  353. * Read a word from the user-level backing store of task CHILD. ADDR
  354. * is the user-level address to read the word from, VAL a pointer to
  355. * the return value, and USER_BSP gives the end of the user-level
  356. * backing store (i.e., it's the address that would be in ar.bsp after
  357. * the user executed a "cover" instruction).
  358. *
  359. * This routine takes care of accessing the kernel register backing
  360. * store for those registers that got spilled there. It also takes
  361. * care of calculating the appropriate RNaT collection words.
  362. */
  363. long
  364. ia64_peek (struct task_struct *child, struct switch_stack *child_stack,
  365. unsigned long user_rbs_end, unsigned long addr, long *val)
  366. {
  367. unsigned long *bspstore, *krbs, regnum, *laddr, *urbs_end, *rnat_addr;
  368. struct pt_regs *child_regs;
  369. size_t copied;
  370. long ret;
  371. urbs_end = (long *) user_rbs_end;
  372. laddr = (unsigned long *) addr;
  373. child_regs = task_pt_regs(child);
  374. bspstore = (unsigned long *) child_regs->ar_bspstore;
  375. krbs = (unsigned long *) child + IA64_RBS_OFFSET/8;
  376. if (on_kernel_rbs(addr, (unsigned long) bspstore,
  377. (unsigned long) urbs_end))
  378. {
  379. /*
  380. * Attempt to read the RBS in an area that's actually
  381. * on the kernel RBS => read the corresponding bits in
  382. * the kernel RBS.
  383. */
  384. rnat_addr = ia64_rse_rnat_addr(laddr);
  385. ret = get_rnat(child, child_stack, krbs, rnat_addr, urbs_end);
  386. if (laddr == rnat_addr) {
  387. /* return NaT collection word itself */
  388. *val = ret;
  389. return 0;
  390. }
  391. if (((1UL << ia64_rse_slot_num(laddr)) & ret) != 0) {
  392. /*
  393. * It is implementation dependent whether the
  394. * data portion of a NaT value gets saved on a
  395. * st8.spill or RSE spill (e.g., see EAS 2.6,
  396. * 4.4.4.6 Register Spill and Fill). To get
  397. * consistent behavior across all possible
  398. * IA-64 implementations, we return zero in
  399. * this case.
  400. */
  401. *val = 0;
  402. return 0;
  403. }
  404. if (laddr < urbs_end) {
  405. /*
  406. * The desired word is on the kernel RBS and
  407. * is not a NaT.
  408. */
  409. regnum = ia64_rse_num_regs(bspstore, laddr);
  410. *val = *ia64_rse_skip_regs(krbs, regnum);
  411. return 0;
  412. }
  413. }
  414. copied = access_process_vm(child, addr, &ret, sizeof(ret), 0);
  415. if (copied != sizeof(ret))
  416. return -EIO;
  417. *val = ret;
  418. return 0;
  419. }
  420. long
  421. ia64_poke (struct task_struct *child, struct switch_stack *child_stack,
  422. unsigned long user_rbs_end, unsigned long addr, long val)
  423. {
  424. unsigned long *bspstore, *krbs, regnum, *laddr;
  425. unsigned long *urbs_end = (long *) user_rbs_end;
  426. struct pt_regs *child_regs;
  427. laddr = (unsigned long *) addr;
  428. child_regs = task_pt_regs(child);
  429. bspstore = (unsigned long *) child_regs->ar_bspstore;
  430. krbs = (unsigned long *) child + IA64_RBS_OFFSET/8;
  431. if (on_kernel_rbs(addr, (unsigned long) bspstore,
  432. (unsigned long) urbs_end))
  433. {
  434. /*
  435. * Attempt to write the RBS in an area that's actually
  436. * on the kernel RBS => write the corresponding bits
  437. * in the kernel RBS.
  438. */
  439. if (ia64_rse_is_rnat_slot(laddr))
  440. put_rnat(child, child_stack, krbs, laddr, val,
  441. urbs_end);
  442. else {
  443. if (laddr < urbs_end) {
  444. regnum = ia64_rse_num_regs(bspstore, laddr);
  445. *ia64_rse_skip_regs(krbs, regnum) = val;
  446. }
  447. }
  448. } else if (access_process_vm(child, addr, &val, sizeof(val), 1)
  449. != sizeof(val))
  450. return -EIO;
  451. return 0;
  452. }
  453. /*
  454. * Calculate the address of the end of the user-level register backing
  455. * store. This is the address that would have been stored in ar.bsp
  456. * if the user had executed a "cover" instruction right before
  457. * entering the kernel. If CFMP is not NULL, it is used to return the
  458. * "current frame mask" that was active at the time the kernel was
  459. * entered.
  460. */
  461. unsigned long
  462. ia64_get_user_rbs_end (struct task_struct *child, struct pt_regs *pt,
  463. unsigned long *cfmp)
  464. {
  465. unsigned long *krbs, *bspstore, cfm = pt->cr_ifs;
  466. long ndirty;
  467. krbs = (unsigned long *) child + IA64_RBS_OFFSET/8;
  468. bspstore = (unsigned long *) pt->ar_bspstore;
  469. ndirty = ia64_rse_num_regs(krbs, krbs + (pt->loadrs >> 19));
  470. if (in_syscall(pt))
  471. ndirty += (cfm & 0x7f);
  472. else
  473. cfm &= ~(1UL << 63); /* clear valid bit */
  474. if (cfmp)
  475. *cfmp = cfm;
  476. return (unsigned long) ia64_rse_skip_regs(bspstore, ndirty);
  477. }
  478. /*
  479. * Synchronize (i.e, write) the RSE backing store living in kernel
  480. * space to the VM of the CHILD task. SW and PT are the pointers to
  481. * the switch_stack and pt_regs structures, respectively.
  482. * USER_RBS_END is the user-level address at which the backing store
  483. * ends.
  484. */
  485. long
  486. ia64_sync_user_rbs (struct task_struct *child, struct switch_stack *sw,
  487. unsigned long user_rbs_start, unsigned long user_rbs_end)
  488. {
  489. unsigned long addr, val;
  490. long ret;
  491. /* now copy word for word from kernel rbs to user rbs: */
  492. for (addr = user_rbs_start; addr < user_rbs_end; addr += 8) {
  493. ret = ia64_peek(child, sw, user_rbs_end, addr, &val);
  494. if (ret < 0)
  495. return ret;
  496. if (access_process_vm(child, addr, &val, sizeof(val), 1)
  497. != sizeof(val))
  498. return -EIO;
  499. }
  500. return 0;
  501. }
  502. static long
  503. ia64_sync_kernel_rbs (struct task_struct *child, struct switch_stack *sw,
  504. unsigned long user_rbs_start, unsigned long user_rbs_end)
  505. {
  506. unsigned long addr, val;
  507. long ret;
  508. /* now copy word for word from user rbs to kernel rbs: */
  509. for (addr = user_rbs_start; addr < user_rbs_end; addr += 8) {
  510. if (access_process_vm(child, addr, &val, sizeof(val), 0)
  511. != sizeof(val))
  512. return -EIO;
  513. ret = ia64_poke(child, sw, user_rbs_end, addr, val);
  514. if (ret < 0)
  515. return ret;
  516. }
  517. return 0;
  518. }
  519. typedef long (*syncfunc_t)(struct task_struct *, struct switch_stack *,
  520. unsigned long, unsigned long);
  521. static void do_sync_rbs(struct unw_frame_info *info, void *arg)
  522. {
  523. struct pt_regs *pt;
  524. unsigned long urbs_end;
  525. syncfunc_t fn = arg;
  526. if (unw_unwind_to_user(info) < 0)
  527. return;
  528. pt = task_pt_regs(info->task);
  529. urbs_end = ia64_get_user_rbs_end(info->task, pt, NULL);
  530. fn(info->task, info->sw, pt->ar_bspstore, urbs_end);
  531. }
  532. /*
  533. * when a thread is stopped (ptraced), debugger might change thread's user
  534. * stack (change memory directly), and we must avoid the RSE stored in kernel
  535. * to override user stack (user space's RSE is newer than kernel's in the
  536. * case). To workaround the issue, we copy kernel RSE to user RSE before the
  537. * task is stopped, so user RSE has updated data. we then copy user RSE to
  538. * kernel after the task is resummed from traced stop and kernel will use the
  539. * newer RSE to return to user. TIF_RESTORE_RSE is the flag to indicate we need
  540. * synchronize user RSE to kernel.
  541. */
  542. void ia64_ptrace_stop(void)
  543. {
  544. if (test_and_set_tsk_thread_flag(current, TIF_RESTORE_RSE))
  545. return;
  546. tsk_set_notify_resume(current);
  547. unw_init_running(do_sync_rbs, ia64_sync_user_rbs);
  548. }
  549. /*
  550. * This is called to read back the register backing store.
  551. */
  552. void ia64_sync_krbs(void)
  553. {
  554. clear_tsk_thread_flag(current, TIF_RESTORE_RSE);
  555. tsk_clear_notify_resume(current);
  556. unw_init_running(do_sync_rbs, ia64_sync_kernel_rbs);
  557. }
  558. /*
  559. * After PTRACE_ATTACH, a thread's register backing store area in user
  560. * space is assumed to contain correct data whenever the thread is
  561. * stopped. arch_ptrace_stop takes care of this on tracing stops.
  562. * But if the child was already stopped for job control when we attach
  563. * to it, then it might not ever get into ptrace_stop by the time we
  564. * want to examine the user memory containing the RBS.
  565. */
  566. void
  567. ptrace_attach_sync_user_rbs (struct task_struct *child)
  568. {
  569. int stopped = 0;
  570. struct unw_frame_info info;
  571. /*
  572. * If the child is in TASK_STOPPED, we need to change that to
  573. * TASK_TRACED momentarily while we operate on it. This ensures
  574. * that the child won't be woken up and return to user mode while
  575. * we are doing the sync. (It can only be woken up for SIGKILL.)
  576. */
  577. read_lock(&tasklist_lock);
  578. if (child->signal) {
  579. spin_lock_irq(&child->sighand->siglock);
  580. if (child->state == TASK_STOPPED &&
  581. !test_and_set_tsk_thread_flag(child, TIF_RESTORE_RSE)) {
  582. tsk_set_notify_resume(child);
  583. child->state = TASK_TRACED;
  584. stopped = 1;
  585. }
  586. spin_unlock_irq(&child->sighand->siglock);
  587. }
  588. read_unlock(&tasklist_lock);
  589. if (!stopped)
  590. return;
  591. unw_init_from_blocked_task(&info, child);
  592. do_sync_rbs(&info, ia64_sync_user_rbs);
  593. /*
  594. * Now move the child back into TASK_STOPPED if it should be in a
  595. * job control stop, so that SIGCONT can be used to wake it up.
  596. */
  597. read_lock(&tasklist_lock);
  598. if (child->signal) {
  599. spin_lock_irq(&child->sighand->siglock);
  600. if (child->state == TASK_TRACED &&
  601. (child->signal->flags & SIGNAL_STOP_STOPPED)) {
  602. child->state = TASK_STOPPED;
  603. }
  604. spin_unlock_irq(&child->sighand->siglock);
  605. }
  606. read_unlock(&tasklist_lock);
  607. }
  608. static inline int
  609. thread_matches (struct task_struct *thread, unsigned long addr)
  610. {
  611. unsigned long thread_rbs_end;
  612. struct pt_regs *thread_regs;
  613. if (ptrace_check_attach(thread, 0) < 0)
  614. /*
  615. * If the thread is not in an attachable state, we'll
  616. * ignore it. The net effect is that if ADDR happens
  617. * to overlap with the portion of the thread's
  618. * register backing store that is currently residing
  619. * on the thread's kernel stack, then ptrace() may end
  620. * up accessing a stale value. But if the thread
  621. * isn't stopped, that's a problem anyhow, so we're
  622. * doing as well as we can...
  623. */
  624. return 0;
  625. thread_regs = task_pt_regs(thread);
  626. thread_rbs_end = ia64_get_user_rbs_end(thread, thread_regs, NULL);
  627. if (!on_kernel_rbs(addr, thread_regs->ar_bspstore, thread_rbs_end))
  628. return 0;
  629. return 1; /* looks like we've got a winner */
  630. }
  631. /*
  632. * GDB apparently wants to be able to read the register-backing store
  633. * of any thread when attached to a given process. If we are peeking
  634. * or poking an address that happens to reside in the kernel-backing
  635. * store of another thread, we need to attach to that thread, because
  636. * otherwise we end up accessing stale data.
  637. *
  638. * task_list_lock must be read-locked before calling this routine!
  639. */
  640. static struct task_struct *
  641. find_thread_for_addr (struct task_struct *child, unsigned long addr)
  642. {
  643. struct task_struct *p;
  644. struct mm_struct *mm;
  645. struct list_head *this, *next;
  646. int mm_users;
  647. if (!(mm = get_task_mm(child)))
  648. return child;
  649. /* -1 because of our get_task_mm(): */
  650. mm_users = atomic_read(&mm->mm_users) - 1;
  651. if (mm_users <= 1)
  652. goto out; /* not multi-threaded */
  653. /*
  654. * Traverse the current process' children list. Every task that
  655. * one attaches to becomes a child. And it is only attached children
  656. * of the debugger that are of interest (ptrace_check_attach checks
  657. * for this).
  658. */
  659. list_for_each_safe(this, next, &current->children) {
  660. p = list_entry(this, struct task_struct, sibling);
  661. if (p->tgid != child->tgid)
  662. continue;
  663. if (thread_matches(p, addr)) {
  664. child = p;
  665. goto out;
  666. }
  667. }
  668. out:
  669. mmput(mm);
  670. return child;
  671. }
  672. /*
  673. * Write f32-f127 back to task->thread.fph if it has been modified.
  674. */
  675. inline void
  676. ia64_flush_fph (struct task_struct *task)
  677. {
  678. struct ia64_psr *psr = ia64_psr(task_pt_regs(task));
  679. /*
  680. * Prevent migrating this task while
  681. * we're fiddling with the FPU state
  682. */
  683. preempt_disable();
  684. if (ia64_is_local_fpu_owner(task) && psr->mfh) {
  685. psr->mfh = 0;
  686. task->thread.flags |= IA64_THREAD_FPH_VALID;
  687. ia64_save_fpu(&task->thread.fph[0]);
  688. }
  689. preempt_enable();
  690. }
  691. /*
  692. * Sync the fph state of the task so that it can be manipulated
  693. * through thread.fph. If necessary, f32-f127 are written back to
  694. * thread.fph or, if the fph state hasn't been used before, thread.fph
  695. * is cleared to zeroes. Also, access to f32-f127 is disabled to
  696. * ensure that the task picks up the state from thread.fph when it
  697. * executes again.
  698. */
  699. void
  700. ia64_sync_fph (struct task_struct *task)
  701. {
  702. struct ia64_psr *psr = ia64_psr(task_pt_regs(task));
  703. ia64_flush_fph(task);
  704. if (!(task->thread.flags & IA64_THREAD_FPH_VALID)) {
  705. task->thread.flags |= IA64_THREAD_FPH_VALID;
  706. memset(&task->thread.fph, 0, sizeof(task->thread.fph));
  707. }
  708. ia64_drop_fpu(task);
  709. psr->dfh = 1;
  710. }
  711. static int
  712. access_fr (struct unw_frame_info *info, int regnum, int hi,
  713. unsigned long *data, int write_access)
  714. {
  715. struct ia64_fpreg fpval;
  716. int ret;
  717. ret = unw_get_fr(info, regnum, &fpval);
  718. if (ret < 0)
  719. return ret;
  720. if (write_access) {
  721. fpval.u.bits[hi] = *data;
  722. ret = unw_set_fr(info, regnum, fpval);
  723. } else
  724. *data = fpval.u.bits[hi];
  725. return ret;
  726. }
  727. /*
  728. * Change the machine-state of CHILD such that it will return via the normal
  729. * kernel exit-path, rather than the syscall-exit path.
  730. */
  731. static void
  732. convert_to_non_syscall (struct task_struct *child, struct pt_regs *pt,
  733. unsigned long cfm)
  734. {
  735. struct unw_frame_info info, prev_info;
  736. unsigned long ip, sp, pr;
  737. unw_init_from_blocked_task(&info, child);
  738. while (1) {
  739. prev_info = info;
  740. if (unw_unwind(&info) < 0)
  741. return;
  742. unw_get_sp(&info, &sp);
  743. if ((long)((unsigned long)child + IA64_STK_OFFSET - sp)
  744. < IA64_PT_REGS_SIZE) {
  745. dprintk("ptrace.%s: ran off the top of the kernel "
  746. "stack\n", __FUNCTION__);
  747. return;
  748. }
  749. if (unw_get_pr (&prev_info, &pr) < 0) {
  750. unw_get_rp(&prev_info, &ip);
  751. dprintk("ptrace.%s: failed to read "
  752. "predicate register (ip=0x%lx)\n",
  753. __FUNCTION__, ip);
  754. return;
  755. }
  756. if (unw_is_intr_frame(&info)
  757. && (pr & (1UL << PRED_USER_STACK)))
  758. break;
  759. }
  760. /*
  761. * Note: at the time of this call, the target task is blocked
  762. * in notify_resume_user() and by clearling PRED_LEAVE_SYSCALL
  763. * (aka, "pLvSys") we redirect execution from
  764. * .work_pending_syscall_end to .work_processed_kernel.
  765. */
  766. unw_get_pr(&prev_info, &pr);
  767. pr &= ~((1UL << PRED_SYSCALL) | (1UL << PRED_LEAVE_SYSCALL));
  768. pr |= (1UL << PRED_NON_SYSCALL);
  769. unw_set_pr(&prev_info, pr);
  770. pt->cr_ifs = (1UL << 63) | cfm;
  771. /*
  772. * Clear the memory that is NOT written on syscall-entry to
  773. * ensure we do not leak kernel-state to user when execution
  774. * resumes.
  775. */
  776. pt->r2 = 0;
  777. pt->r3 = 0;
  778. pt->r14 = 0;
  779. memset(&pt->r16, 0, 16*8); /* clear r16-r31 */
  780. memset(&pt->f6, 0, 6*16); /* clear f6-f11 */
  781. pt->b7 = 0;
  782. pt->ar_ccv = 0;
  783. pt->ar_csd = 0;
  784. pt->ar_ssd = 0;
  785. }
  786. static int
  787. access_nat_bits (struct task_struct *child, struct pt_regs *pt,
  788. struct unw_frame_info *info,
  789. unsigned long *data, int write_access)
  790. {
  791. unsigned long regnum, nat_bits, scratch_unat, dummy = 0;
  792. char nat = 0;
  793. if (write_access) {
  794. nat_bits = *data;
  795. scratch_unat = ia64_put_scratch_nat_bits(pt, nat_bits);
  796. if (unw_set_ar(info, UNW_AR_UNAT, scratch_unat) < 0) {
  797. dprintk("ptrace: failed to set ar.unat\n");
  798. return -1;
  799. }
  800. for (regnum = 4; regnum <= 7; ++regnum) {
  801. unw_get_gr(info, regnum, &dummy, &nat);
  802. unw_set_gr(info, regnum, dummy,
  803. (nat_bits >> regnum) & 1);
  804. }
  805. } else {
  806. if (unw_get_ar(info, UNW_AR_UNAT, &scratch_unat) < 0) {
  807. dprintk("ptrace: failed to read ar.unat\n");
  808. return -1;
  809. }
  810. nat_bits = ia64_get_scratch_nat_bits(pt, scratch_unat);
  811. for (regnum = 4; regnum <= 7; ++regnum) {
  812. unw_get_gr(info, regnum, &dummy, &nat);
  813. nat_bits |= (nat != 0) << regnum;
  814. }
  815. *data = nat_bits;
  816. }
  817. return 0;
  818. }
  819. static int
  820. access_uarea (struct task_struct *child, unsigned long addr,
  821. unsigned long *data, int write_access)
  822. {
  823. unsigned long *ptr, regnum, urbs_end, rnat_addr, cfm;
  824. struct switch_stack *sw;
  825. struct pt_regs *pt;
  826. # define pt_reg_addr(pt, reg) ((void *) \
  827. ((unsigned long) (pt) \
  828. + offsetof(struct pt_regs, reg)))
  829. pt = task_pt_regs(child);
  830. sw = (struct switch_stack *) (child->thread.ksp + 16);
  831. if ((addr & 0x7) != 0) {
  832. dprintk("ptrace: unaligned register address 0x%lx\n", addr);
  833. return -1;
  834. }
  835. if (addr < PT_F127 + 16) {
  836. /* accessing fph */
  837. if (write_access)
  838. ia64_sync_fph(child);
  839. else
  840. ia64_flush_fph(child);
  841. ptr = (unsigned long *)
  842. ((unsigned long) &child->thread.fph + addr);
  843. } else if ((addr >= PT_F10) && (addr < PT_F11 + 16)) {
  844. /* scratch registers untouched by kernel (saved in pt_regs) */
  845. ptr = pt_reg_addr(pt, f10) + (addr - PT_F10);
  846. } else if (addr >= PT_F12 && addr < PT_F15 + 16) {
  847. /*
  848. * Scratch registers untouched by kernel (saved in
  849. * switch_stack).
  850. */
  851. ptr = (unsigned long *) ((long) sw
  852. + (addr - PT_NAT_BITS - 32));
  853. } else if (addr < PT_AR_LC + 8) {
  854. /* preserved state: */
  855. struct unw_frame_info info;
  856. char nat = 0;
  857. int ret;
  858. unw_init_from_blocked_task(&info, child);
  859. if (unw_unwind_to_user(&info) < 0)
  860. return -1;
  861. switch (addr) {
  862. case PT_NAT_BITS:
  863. return access_nat_bits(child, pt, &info,
  864. data, write_access);
  865. case PT_R4: case PT_R5: case PT_R6: case PT_R7:
  866. if (write_access) {
  867. /* read NaT bit first: */
  868. unsigned long dummy;
  869. ret = unw_get_gr(&info, (addr - PT_R4)/8 + 4,
  870. &dummy, &nat);
  871. if (ret < 0)
  872. return ret;
  873. }
  874. return unw_access_gr(&info, (addr - PT_R4)/8 + 4, data,
  875. &nat, write_access);
  876. case PT_B1: case PT_B2: case PT_B3:
  877. case PT_B4: case PT_B5:
  878. return unw_access_br(&info, (addr - PT_B1)/8 + 1, data,
  879. write_access);
  880. case PT_AR_EC:
  881. return unw_access_ar(&info, UNW_AR_EC, data,
  882. write_access);
  883. case PT_AR_LC:
  884. return unw_access_ar(&info, UNW_AR_LC, data,
  885. write_access);
  886. default:
  887. if (addr >= PT_F2 && addr < PT_F5 + 16)
  888. return access_fr(&info, (addr - PT_F2)/16 + 2,
  889. (addr & 8) != 0, data,
  890. write_access);
  891. else if (addr >= PT_F16 && addr < PT_F31 + 16)
  892. return access_fr(&info,
  893. (addr - PT_F16)/16 + 16,
  894. (addr & 8) != 0,
  895. data, write_access);
  896. else {
  897. dprintk("ptrace: rejecting access to register "
  898. "address 0x%lx\n", addr);
  899. return -1;
  900. }
  901. }
  902. } else if (addr < PT_F9+16) {
  903. /* scratch state */
  904. switch (addr) {
  905. case PT_AR_BSP:
  906. /*
  907. * By convention, we use PT_AR_BSP to refer to
  908. * the end of the user-level backing store.
  909. * Use ia64_rse_skip_regs(PT_AR_BSP, -CFM.sof)
  910. * to get the real value of ar.bsp at the time
  911. * the kernel was entered.
  912. *
  913. * Furthermore, when changing the contents of
  914. * PT_AR_BSP (or PT_CFM) we MUST copy any
  915. * users-level stacked registers that are
  916. * stored on the kernel stack back to
  917. * user-space because otherwise, we might end
  918. * up clobbering kernel stacked registers.
  919. * Also, if this happens while the task is
  920. * blocked in a system call, which convert the
  921. * state such that the non-system-call exit
  922. * path is used. This ensures that the proper
  923. * state will be picked up when resuming
  924. * execution. However, it *also* means that
  925. * once we write PT_AR_BSP/PT_CFM, it won't be
  926. * possible to modify the syscall arguments of
  927. * the pending system call any longer. This
  928. * shouldn't be an issue because modifying
  929. * PT_AR_BSP/PT_CFM generally implies that
  930. * we're either abandoning the pending system
  931. * call or that we defer it's re-execution
  932. * (e.g., due to GDB doing an inferior
  933. * function call).
  934. */
  935. urbs_end = ia64_get_user_rbs_end(child, pt, &cfm);
  936. if (write_access) {
  937. if (*data != urbs_end) {
  938. if (ia64_sync_user_rbs(child, sw,
  939. pt->ar_bspstore,
  940. urbs_end) < 0)
  941. return -1;
  942. if (in_syscall(pt))
  943. convert_to_non_syscall(child,
  944. pt,
  945. cfm);
  946. /*
  947. * Simulate user-level write
  948. * of ar.bsp:
  949. */
  950. pt->loadrs = 0;
  951. pt->ar_bspstore = *data;
  952. }
  953. } else
  954. *data = urbs_end;
  955. return 0;
  956. case PT_CFM:
  957. urbs_end = ia64_get_user_rbs_end(child, pt, &cfm);
  958. if (write_access) {
  959. if (((cfm ^ *data) & PFM_MASK) != 0) {
  960. if (ia64_sync_user_rbs(child, sw,
  961. pt->ar_bspstore,
  962. urbs_end) < 0)
  963. return -1;
  964. if (in_syscall(pt))
  965. convert_to_non_syscall(child,
  966. pt,
  967. cfm);
  968. pt->cr_ifs = ((pt->cr_ifs & ~PFM_MASK)
  969. | (*data & PFM_MASK));
  970. }
  971. } else
  972. *data = cfm;
  973. return 0;
  974. case PT_CR_IPSR:
  975. if (write_access) {
  976. unsigned long tmp = *data;
  977. /* psr.ri==3 is a reserved value: SDM 2:25 */
  978. if ((tmp & IA64_PSR_RI) == IA64_PSR_RI)
  979. tmp &= ~IA64_PSR_RI;
  980. pt->cr_ipsr = ((tmp & IPSR_MASK)
  981. | (pt->cr_ipsr & ~IPSR_MASK));
  982. } else
  983. *data = (pt->cr_ipsr & IPSR_MASK);
  984. return 0;
  985. case PT_AR_RSC:
  986. if (write_access)
  987. pt->ar_rsc = *data | (3 << 2); /* force PL3 */
  988. else
  989. *data = pt->ar_rsc;
  990. return 0;
  991. case PT_AR_RNAT:
  992. urbs_end = ia64_get_user_rbs_end(child, pt, NULL);
  993. rnat_addr = (long) ia64_rse_rnat_addr((long *)
  994. urbs_end);
  995. if (write_access)
  996. return ia64_poke(child, sw, urbs_end,
  997. rnat_addr, *data);
  998. else
  999. return ia64_peek(child, sw, urbs_end,
  1000. rnat_addr, data);
  1001. case PT_R1:
  1002. ptr = pt_reg_addr(pt, r1);
  1003. break;
  1004. case PT_R2: case PT_R3:
  1005. ptr = pt_reg_addr(pt, r2) + (addr - PT_R2);
  1006. break;
  1007. case PT_R8: case PT_R9: case PT_R10: case PT_R11:
  1008. ptr = pt_reg_addr(pt, r8) + (addr - PT_R8);
  1009. break;
  1010. case PT_R12: case PT_R13:
  1011. ptr = pt_reg_addr(pt, r12) + (addr - PT_R12);
  1012. break;
  1013. case PT_R14:
  1014. ptr = pt_reg_addr(pt, r14);
  1015. break;
  1016. case PT_R15:
  1017. ptr = pt_reg_addr(pt, r15);
  1018. break;
  1019. case PT_R16: case PT_R17: case PT_R18: case PT_R19:
  1020. case PT_R20: case PT_R21: case PT_R22: case PT_R23:
  1021. case PT_R24: case PT_R25: case PT_R26: case PT_R27:
  1022. case PT_R28: case PT_R29: case PT_R30: case PT_R31:
  1023. ptr = pt_reg_addr(pt, r16) + (addr - PT_R16);
  1024. break;
  1025. case PT_B0:
  1026. ptr = pt_reg_addr(pt, b0);
  1027. break;
  1028. case PT_B6:
  1029. ptr = pt_reg_addr(pt, b6);
  1030. break;
  1031. case PT_B7:
  1032. ptr = pt_reg_addr(pt, b7);
  1033. break;
  1034. case PT_F6: case PT_F6+8: case PT_F7: case PT_F7+8:
  1035. case PT_F8: case PT_F8+8: case PT_F9: case PT_F9+8:
  1036. ptr = pt_reg_addr(pt, f6) + (addr - PT_F6);
  1037. break;
  1038. case PT_AR_BSPSTORE:
  1039. ptr = pt_reg_addr(pt, ar_bspstore);
  1040. break;
  1041. case PT_AR_UNAT:
  1042. ptr = pt_reg_addr(pt, ar_unat);
  1043. break;
  1044. case PT_AR_PFS:
  1045. ptr = pt_reg_addr(pt, ar_pfs);
  1046. break;
  1047. case PT_AR_CCV:
  1048. ptr = pt_reg_addr(pt, ar_ccv);
  1049. break;
  1050. case PT_AR_FPSR:
  1051. ptr = pt_reg_addr(pt, ar_fpsr);
  1052. break;
  1053. case PT_CR_IIP:
  1054. ptr = pt_reg_addr(pt, cr_iip);
  1055. break;
  1056. case PT_PR:
  1057. ptr = pt_reg_addr(pt, pr);
  1058. break;
  1059. /* scratch register */
  1060. default:
  1061. /* disallow accessing anything else... */
  1062. dprintk("ptrace: rejecting access to register "
  1063. "address 0x%lx\n", addr);
  1064. return -1;
  1065. }
  1066. } else if (addr <= PT_AR_SSD) {
  1067. ptr = pt_reg_addr(pt, ar_csd) + (addr - PT_AR_CSD);
  1068. } else {
  1069. /* access debug registers */
  1070. if (addr >= PT_IBR) {
  1071. regnum = (addr - PT_IBR) >> 3;
  1072. ptr = &child->thread.ibr[0];
  1073. } else {
  1074. regnum = (addr - PT_DBR) >> 3;
  1075. ptr = &child->thread.dbr[0];
  1076. }
  1077. if (regnum >= 8) {
  1078. dprintk("ptrace: rejecting access to register "
  1079. "address 0x%lx\n", addr);
  1080. return -1;
  1081. }
  1082. #ifdef CONFIG_PERFMON
  1083. /*
  1084. * Check if debug registers are used by perfmon. This
  1085. * test must be done once we know that we can do the
  1086. * operation, i.e. the arguments are all valid, but
  1087. * before we start modifying the state.
  1088. *
  1089. * Perfmon needs to keep a count of how many processes
  1090. * are trying to modify the debug registers for system
  1091. * wide monitoring sessions.
  1092. *
  1093. * We also include read access here, because they may
  1094. * cause the PMU-installed debug register state
  1095. * (dbr[], ibr[]) to be reset. The two arrays are also
  1096. * used by perfmon, but we do not use
  1097. * IA64_THREAD_DBG_VALID. The registers are restored
  1098. * by the PMU context switch code.
  1099. */
  1100. if (pfm_use_debug_registers(child)) return -1;
  1101. #endif
  1102. if (!(child->thread.flags & IA64_THREAD_DBG_VALID)) {
  1103. child->thread.flags |= IA64_THREAD_DBG_VALID;
  1104. memset(child->thread.dbr, 0,
  1105. sizeof(child->thread.dbr));
  1106. memset(child->thread.ibr, 0,
  1107. sizeof(child->thread.ibr));
  1108. }
  1109. ptr += regnum;
  1110. if ((regnum & 1) && write_access) {
  1111. /* don't let the user set kernel-level breakpoints: */
  1112. *ptr = *data & ~(7UL << 56);
  1113. return 0;
  1114. }
  1115. }
  1116. if (write_access)
  1117. *ptr = *data;
  1118. else
  1119. *data = *ptr;
  1120. return 0;
  1121. }
  1122. static long
  1123. ptrace_getregs (struct task_struct *child, struct pt_all_user_regs __user *ppr)
  1124. {
  1125. unsigned long psr, ec, lc, rnat, bsp, cfm, nat_bits, val;
  1126. struct unw_frame_info info;
  1127. struct ia64_fpreg fpval;
  1128. struct switch_stack *sw;
  1129. struct pt_regs *pt;
  1130. long ret, retval = 0;
  1131. char nat = 0;
  1132. int i;
  1133. if (!access_ok(VERIFY_WRITE, ppr, sizeof(struct pt_all_user_regs)))
  1134. return -EIO;
  1135. pt = task_pt_regs(child);
  1136. sw = (struct switch_stack *) (child->thread.ksp + 16);
  1137. unw_init_from_blocked_task(&info, child);
  1138. if (unw_unwind_to_user(&info) < 0) {
  1139. return -EIO;
  1140. }
  1141. if (((unsigned long) ppr & 0x7) != 0) {
  1142. dprintk("ptrace:unaligned register address %p\n", ppr);
  1143. return -EIO;
  1144. }
  1145. if (access_uarea(child, PT_CR_IPSR, &psr, 0) < 0
  1146. || access_uarea(child, PT_AR_EC, &ec, 0) < 0
  1147. || access_uarea(child, PT_AR_LC, &lc, 0) < 0
  1148. || access_uarea(child, PT_AR_RNAT, &rnat, 0) < 0
  1149. || access_uarea(child, PT_AR_BSP, &bsp, 0) < 0
  1150. || access_uarea(child, PT_CFM, &cfm, 0)
  1151. || access_uarea(child, PT_NAT_BITS, &nat_bits, 0))
  1152. return -EIO;
  1153. /* control regs */
  1154. retval |= __put_user(pt->cr_iip, &ppr->cr_iip);
  1155. retval |= __put_user(psr, &ppr->cr_ipsr);
  1156. /* app regs */
  1157. retval |= __put_user(pt->ar_pfs, &ppr->ar[PT_AUR_PFS]);
  1158. retval |= __put_user(pt->ar_rsc, &ppr->ar[PT_AUR_RSC]);
  1159. retval |= __put_user(pt->ar_bspstore, &ppr->ar[PT_AUR_BSPSTORE]);
  1160. retval |= __put_user(pt->ar_unat, &ppr->ar[PT_AUR_UNAT]);
  1161. retval |= __put_user(pt->ar_ccv, &ppr->ar[PT_AUR_CCV]);
  1162. retval |= __put_user(pt->ar_fpsr, &ppr->ar[PT_AUR_FPSR]);
  1163. retval |= __put_user(ec, &ppr->ar[PT_AUR_EC]);
  1164. retval |= __put_user(lc, &ppr->ar[PT_AUR_LC]);
  1165. retval |= __put_user(rnat, &ppr->ar[PT_AUR_RNAT]);
  1166. retval |= __put_user(bsp, &ppr->ar[PT_AUR_BSP]);
  1167. retval |= __put_user(cfm, &ppr->cfm);
  1168. /* gr1-gr3 */
  1169. retval |= __copy_to_user(&ppr->gr[1], &pt->r1, sizeof(long));
  1170. retval |= __copy_to_user(&ppr->gr[2], &pt->r2, sizeof(long) *2);
  1171. /* gr4-gr7 */
  1172. for (i = 4; i < 8; i++) {
  1173. if (unw_access_gr(&info, i, &val, &nat, 0) < 0)
  1174. return -EIO;
  1175. retval |= __put_user(val, &ppr->gr[i]);
  1176. }
  1177. /* gr8-gr11 */
  1178. retval |= __copy_to_user(&ppr->gr[8], &pt->r8, sizeof(long) * 4);
  1179. /* gr12-gr15 */
  1180. retval |= __copy_to_user(&ppr->gr[12], &pt->r12, sizeof(long) * 2);
  1181. retval |= __copy_to_user(&ppr->gr[14], &pt->r14, sizeof(long));
  1182. retval |= __copy_to_user(&ppr->gr[15], &pt->r15, sizeof(long));
  1183. /* gr16-gr31 */
  1184. retval |= __copy_to_user(&ppr->gr[16], &pt->r16, sizeof(long) * 16);
  1185. /* b0 */
  1186. retval |= __put_user(pt->b0, &ppr->br[0]);
  1187. /* b1-b5 */
  1188. for (i = 1; i < 6; i++) {
  1189. if (unw_access_br(&info, i, &val, 0) < 0)
  1190. return -EIO;
  1191. __put_user(val, &ppr->br[i]);
  1192. }
  1193. /* b6-b7 */
  1194. retval |= __put_user(pt->b6, &ppr->br[6]);
  1195. retval |= __put_user(pt->b7, &ppr->br[7]);
  1196. /* fr2-fr5 */
  1197. for (i = 2; i < 6; i++) {
  1198. if (unw_get_fr(&info, i, &fpval) < 0)
  1199. return -EIO;
  1200. retval |= __copy_to_user(&ppr->fr[i], &fpval, sizeof (fpval));
  1201. }
  1202. /* fr6-fr11 */
  1203. retval |= __copy_to_user(&ppr->fr[6], &pt->f6,
  1204. sizeof(struct ia64_fpreg) * 6);
  1205. /* fp scratch regs(12-15) */
  1206. retval |= __copy_to_user(&ppr->fr[12], &sw->f12,
  1207. sizeof(struct ia64_fpreg) * 4);
  1208. /* fr16-fr31 */
  1209. for (i = 16; i < 32; i++) {
  1210. if (unw_get_fr(&info, i, &fpval) < 0)
  1211. return -EIO;
  1212. retval |= __copy_to_user(&ppr->fr[i], &fpval, sizeof (fpval));
  1213. }
  1214. /* fph */
  1215. ia64_flush_fph(child);
  1216. retval |= __copy_to_user(&ppr->fr[32], &child->thread.fph,
  1217. sizeof(ppr->fr[32]) * 96);
  1218. /* preds */
  1219. retval |= __put_user(pt->pr, &ppr->pr);
  1220. /* nat bits */
  1221. retval |= __put_user(nat_bits, &ppr->nat);
  1222. ret = retval ? -EIO : 0;
  1223. return ret;
  1224. }
  1225. static long
  1226. ptrace_setregs (struct task_struct *child, struct pt_all_user_regs __user *ppr)
  1227. {
  1228. unsigned long psr, rsc, ec, lc, rnat, bsp, cfm, nat_bits, val = 0;
  1229. struct unw_frame_info info;
  1230. struct switch_stack *sw;
  1231. struct ia64_fpreg fpval;
  1232. struct pt_regs *pt;
  1233. long ret, retval = 0;
  1234. int i;
  1235. memset(&fpval, 0, sizeof(fpval));
  1236. if (!access_ok(VERIFY_READ, ppr, sizeof(struct pt_all_user_regs)))
  1237. return -EIO;
  1238. pt = task_pt_regs(child);
  1239. sw = (struct switch_stack *) (child->thread.ksp + 16);
  1240. unw_init_from_blocked_task(&info, child);
  1241. if (unw_unwind_to_user(&info) < 0) {
  1242. return -EIO;
  1243. }
  1244. if (((unsigned long) ppr & 0x7) != 0) {
  1245. dprintk("ptrace:unaligned register address %p\n", ppr);
  1246. return -EIO;
  1247. }
  1248. /* control regs */
  1249. retval |= __get_user(pt->cr_iip, &ppr->cr_iip);
  1250. retval |= __get_user(psr, &ppr->cr_ipsr);
  1251. /* app regs */
  1252. retval |= __get_user(pt->ar_pfs, &ppr->ar[PT_AUR_PFS]);
  1253. retval |= __get_user(rsc, &ppr->ar[PT_AUR_RSC]);
  1254. retval |= __get_user(pt->ar_bspstore, &ppr->ar[PT_AUR_BSPSTORE]);
  1255. retval |= __get_user(pt->ar_unat, &ppr->ar[PT_AUR_UNAT]);
  1256. retval |= __get_user(pt->ar_ccv, &ppr->ar[PT_AUR_CCV]);
  1257. retval |= __get_user(pt->ar_fpsr, &ppr->ar[PT_AUR_FPSR]);
  1258. retval |= __get_user(ec, &ppr->ar[PT_AUR_EC]);
  1259. retval |= __get_user(lc, &ppr->ar[PT_AUR_LC]);
  1260. retval |= __get_user(rnat, &ppr->ar[PT_AUR_RNAT]);
  1261. retval |= __get_user(bsp, &ppr->ar[PT_AUR_BSP]);
  1262. retval |= __get_user(cfm, &ppr->cfm);
  1263. /* gr1-gr3 */
  1264. retval |= __copy_from_user(&pt->r1, &ppr->gr[1], sizeof(long));
  1265. retval |= __copy_from_user(&pt->r2, &ppr->gr[2], sizeof(long) * 2);
  1266. /* gr4-gr7 */
  1267. for (i = 4; i < 8; i++) {
  1268. retval |= __get_user(val, &ppr->gr[i]);
  1269. /* NaT bit will be set via PT_NAT_BITS: */
  1270. if (unw_set_gr(&info, i, val, 0) < 0)
  1271. return -EIO;
  1272. }
  1273. /* gr8-gr11 */
  1274. retval |= __copy_from_user(&pt->r8, &ppr->gr[8], sizeof(long) * 4);
  1275. /* gr12-gr15 */
  1276. retval |= __copy_from_user(&pt->r12, &ppr->gr[12], sizeof(long) * 2);
  1277. retval |= __copy_from_user(&pt->r14, &ppr->gr[14], sizeof(long));
  1278. retval |= __copy_from_user(&pt->r15, &ppr->gr[15], sizeof(long));
  1279. /* gr16-gr31 */
  1280. retval |= __copy_from_user(&pt->r16, &ppr->gr[16], sizeof(long) * 16);
  1281. /* b0 */
  1282. retval |= __get_user(pt->b0, &ppr->br[0]);
  1283. /* b1-b5 */
  1284. for (i = 1; i < 6; i++) {
  1285. retval |= __get_user(val, &ppr->br[i]);
  1286. unw_set_br(&info, i, val);
  1287. }
  1288. /* b6-b7 */
  1289. retval |= __get_user(pt->b6, &ppr->br[6]);
  1290. retval |= __get_user(pt->b7, &ppr->br[7]);
  1291. /* fr2-fr5 */
  1292. for (i = 2; i < 6; i++) {
  1293. retval |= __copy_from_user(&fpval, &ppr->fr[i], sizeof(fpval));
  1294. if (unw_set_fr(&info, i, fpval) < 0)
  1295. return -EIO;
  1296. }
  1297. /* fr6-fr11 */
  1298. retval |= __copy_from_user(&pt->f6, &ppr->fr[6],
  1299. sizeof(ppr->fr[6]) * 6);
  1300. /* fp scratch regs(12-15) */
  1301. retval |= __copy_from_user(&sw->f12, &ppr->fr[12],
  1302. sizeof(ppr->fr[12]) * 4);
  1303. /* fr16-fr31 */
  1304. for (i = 16; i < 32; i++) {
  1305. retval |= __copy_from_user(&fpval, &ppr->fr[i],
  1306. sizeof(fpval));
  1307. if (unw_set_fr(&info, i, fpval) < 0)
  1308. return -EIO;
  1309. }
  1310. /* fph */
  1311. ia64_sync_fph(child);
  1312. retval |= __copy_from_user(&child->thread.fph, &ppr->fr[32],
  1313. sizeof(ppr->fr[32]) * 96);
  1314. /* preds */
  1315. retval |= __get_user(pt->pr, &ppr->pr);
  1316. /* nat bits */
  1317. retval |= __get_user(nat_bits, &ppr->nat);
  1318. retval |= access_uarea(child, PT_CR_IPSR, &psr, 1);
  1319. retval |= access_uarea(child, PT_AR_RSC, &rsc, 1);
  1320. retval |= access_uarea(child, PT_AR_EC, &ec, 1);
  1321. retval |= access_uarea(child, PT_AR_LC, &lc, 1);
  1322. retval |= access_uarea(child, PT_AR_RNAT, &rnat, 1);
  1323. retval |= access_uarea(child, PT_AR_BSP, &bsp, 1);
  1324. retval |= access_uarea(child, PT_CFM, &cfm, 1);
  1325. retval |= access_uarea(child, PT_NAT_BITS, &nat_bits, 1);
  1326. ret = retval ? -EIO : 0;
  1327. return ret;
  1328. }
  1329. /*
  1330. * Called by kernel/ptrace.c when detaching..
  1331. *
  1332. * Make sure the single step bit is not set.
  1333. */
  1334. void
  1335. ptrace_disable (struct task_struct *child)
  1336. {
  1337. struct ia64_psr *child_psr = ia64_psr(task_pt_regs(child));
  1338. /* make sure the single step/taken-branch trap bits are not set: */
  1339. clear_tsk_thread_flag(child, TIF_SINGLESTEP);
  1340. child_psr->ss = 0;
  1341. child_psr->tb = 0;
  1342. }
  1343. asmlinkage long
  1344. sys_ptrace (long request, pid_t pid, unsigned long addr, unsigned long data)
  1345. {
  1346. struct pt_regs *pt;
  1347. unsigned long urbs_end, peek_or_poke;
  1348. struct task_struct *child;
  1349. struct switch_stack *sw;
  1350. long ret;
  1351. struct unw_frame_info info;
  1352. lock_kernel();
  1353. ret = -EPERM;
  1354. if (request == PTRACE_TRACEME) {
  1355. ret = ptrace_traceme();
  1356. goto out;
  1357. }
  1358. peek_or_poke = (request == PTRACE_PEEKTEXT
  1359. || request == PTRACE_PEEKDATA
  1360. || request == PTRACE_POKETEXT
  1361. || request == PTRACE_POKEDATA);
  1362. ret = -ESRCH;
  1363. read_lock(&tasklist_lock);
  1364. {
  1365. child = find_task_by_pid(pid);
  1366. if (child) {
  1367. if (peek_or_poke)
  1368. child = find_thread_for_addr(child, addr);
  1369. get_task_struct(child);
  1370. }
  1371. }
  1372. read_unlock(&tasklist_lock);
  1373. if (!child)
  1374. goto out;
  1375. ret = -EPERM;
  1376. if (pid == 1) /* no messing around with init! */
  1377. goto out_tsk;
  1378. if (request == PTRACE_ATTACH) {
  1379. ret = ptrace_attach(child);
  1380. if (!ret)
  1381. arch_ptrace_attach(child);
  1382. goto out_tsk;
  1383. }
  1384. ret = ptrace_check_attach(child, request == PTRACE_KILL);
  1385. if (ret < 0)
  1386. goto out_tsk;
  1387. pt = task_pt_regs(child);
  1388. sw = (struct switch_stack *) (child->thread.ksp + 16);
  1389. switch (request) {
  1390. case PTRACE_PEEKTEXT:
  1391. case PTRACE_PEEKDATA:
  1392. /* read word at location addr */
  1393. urbs_end = ia64_get_user_rbs_end(child, pt, NULL);
  1394. ret = ia64_peek(child, sw, urbs_end, addr, &data);
  1395. if (ret == 0) {
  1396. ret = data;
  1397. /* ensure "ret" is not mistaken as an error code: */
  1398. force_successful_syscall_return();
  1399. }
  1400. goto out_tsk;
  1401. case PTRACE_POKETEXT:
  1402. case PTRACE_POKEDATA:
  1403. /* write the word at location addr */
  1404. urbs_end = ia64_get_user_rbs_end(child, pt, NULL);
  1405. ret = ia64_poke(child, sw, urbs_end, addr, data);
  1406. /* Make sure user RBS has the latest data */
  1407. unw_init_from_blocked_task(&info, child);
  1408. do_sync_rbs(&info, ia64_sync_user_rbs);
  1409. goto out_tsk;
  1410. case PTRACE_PEEKUSR:
  1411. /* read the word at addr in the USER area */
  1412. if (access_uarea(child, addr, &data, 0) < 0) {
  1413. ret = -EIO;
  1414. goto out_tsk;
  1415. }
  1416. ret = data;
  1417. /* ensure "ret" is not mistaken as an error code */
  1418. force_successful_syscall_return();
  1419. goto out_tsk;
  1420. case PTRACE_POKEUSR:
  1421. /* write the word at addr in the USER area */
  1422. if (access_uarea(child, addr, &data, 1) < 0) {
  1423. ret = -EIO;
  1424. goto out_tsk;
  1425. }
  1426. ret = 0;
  1427. goto out_tsk;
  1428. case PTRACE_OLD_GETSIGINFO:
  1429. /* for backwards-compatibility */
  1430. ret = ptrace_request(child, PTRACE_GETSIGINFO, addr, data);
  1431. goto out_tsk;
  1432. case PTRACE_OLD_SETSIGINFO:
  1433. /* for backwards-compatibility */
  1434. ret = ptrace_request(child, PTRACE_SETSIGINFO, addr, data);
  1435. goto out_tsk;
  1436. case PTRACE_SYSCALL:
  1437. /* continue and stop at next (return from) syscall */
  1438. case PTRACE_CONT:
  1439. /* restart after signal. */
  1440. ret = -EIO;
  1441. if (!valid_signal(data))
  1442. goto out_tsk;
  1443. if (request == PTRACE_SYSCALL)
  1444. set_tsk_thread_flag(child, TIF_SYSCALL_TRACE);
  1445. else
  1446. clear_tsk_thread_flag(child, TIF_SYSCALL_TRACE);
  1447. child->exit_code = data;
  1448. /*
  1449. * Make sure the single step/taken-branch trap bits
  1450. * are not set:
  1451. */
  1452. clear_tsk_thread_flag(child, TIF_SINGLESTEP);
  1453. ia64_psr(pt)->ss = 0;
  1454. ia64_psr(pt)->tb = 0;
  1455. wake_up_process(child);
  1456. ret = 0;
  1457. goto out_tsk;
  1458. case PTRACE_KILL:
  1459. /*
  1460. * Make the child exit. Best I can do is send it a
  1461. * sigkill. Perhaps it should be put in the status
  1462. * that it wants to exit.
  1463. */
  1464. if (child->exit_state == EXIT_ZOMBIE)
  1465. /* already dead */
  1466. goto out_tsk;
  1467. child->exit_code = SIGKILL;
  1468. ptrace_disable(child);
  1469. wake_up_process(child);
  1470. ret = 0;
  1471. goto out_tsk;
  1472. case PTRACE_SINGLESTEP:
  1473. /* let child execute for one instruction */
  1474. case PTRACE_SINGLEBLOCK:
  1475. ret = -EIO;
  1476. if (!valid_signal(data))
  1477. goto out_tsk;
  1478. clear_tsk_thread_flag(child, TIF_SYSCALL_TRACE);
  1479. set_tsk_thread_flag(child, TIF_SINGLESTEP);
  1480. if (request == PTRACE_SINGLESTEP) {
  1481. ia64_psr(pt)->ss = 1;
  1482. } else {
  1483. ia64_psr(pt)->tb = 1;
  1484. }
  1485. child->exit_code = data;
  1486. /* give it a chance to run. */
  1487. wake_up_process(child);
  1488. ret = 0;
  1489. goto out_tsk;
  1490. case PTRACE_DETACH:
  1491. /* detach a process that was attached. */
  1492. ret = ptrace_detach(child, data);
  1493. goto out_tsk;
  1494. case PTRACE_GETREGS:
  1495. ret = ptrace_getregs(child,
  1496. (struct pt_all_user_regs __user *) data);
  1497. goto out_tsk;
  1498. case PTRACE_SETREGS:
  1499. ret = ptrace_setregs(child,
  1500. (struct pt_all_user_regs __user *) data);
  1501. goto out_tsk;
  1502. default:
  1503. ret = ptrace_request(child, request, addr, data);
  1504. goto out_tsk;
  1505. }
  1506. out_tsk:
  1507. put_task_struct(child);
  1508. out:
  1509. unlock_kernel();
  1510. return ret;
  1511. }
  1512. static void
  1513. syscall_trace (void)
  1514. {
  1515. /*
  1516. * The 0x80 provides a way for the tracing parent to
  1517. * distinguish between a syscall stop and SIGTRAP delivery.
  1518. */
  1519. ptrace_notify(SIGTRAP
  1520. | ((current->ptrace & PT_TRACESYSGOOD) ? 0x80 : 0));
  1521. /*
  1522. * This isn't the same as continuing with a signal, but it
  1523. * will do for normal use. strace only continues with a
  1524. * signal if the stopping signal is not SIGTRAP. -brl
  1525. */
  1526. if (current->exit_code) {
  1527. send_sig(current->exit_code, current, 1);
  1528. current->exit_code = 0;
  1529. }
  1530. }
  1531. /* "asmlinkage" so the input arguments are preserved... */
  1532. asmlinkage void
  1533. syscall_trace_enter (long arg0, long arg1, long arg2, long arg3,
  1534. long arg4, long arg5, long arg6, long arg7,
  1535. struct pt_regs regs)
  1536. {
  1537. if (test_thread_flag(TIF_SYSCALL_TRACE)
  1538. && (current->ptrace & PT_PTRACED))
  1539. syscall_trace();
  1540. /* copy user rbs to kernel rbs */
  1541. if (test_thread_flag(TIF_RESTORE_RSE))
  1542. ia64_sync_krbs();
  1543. if (unlikely(current->audit_context)) {
  1544. long syscall;
  1545. int arch;
  1546. if (IS_IA32_PROCESS(&regs)) {
  1547. syscall = regs.r1;
  1548. arch = AUDIT_ARCH_I386;
  1549. } else {
  1550. syscall = regs.r15;
  1551. arch = AUDIT_ARCH_IA64;
  1552. }
  1553. audit_syscall_entry(arch, syscall, arg0, arg1, arg2, arg3);
  1554. }
  1555. }
  1556. /* "asmlinkage" so the input arguments are preserved... */
  1557. asmlinkage void
  1558. syscall_trace_leave (long arg0, long arg1, long arg2, long arg3,
  1559. long arg4, long arg5, long arg6, long arg7,
  1560. struct pt_regs regs)
  1561. {
  1562. if (unlikely(current->audit_context)) {
  1563. int success = AUDITSC_RESULT(regs.r10);
  1564. long result = regs.r8;
  1565. if (success != AUDITSC_SUCCESS)
  1566. result = -result;
  1567. audit_syscall_exit(success, result);
  1568. }
  1569. if ((test_thread_flag(TIF_SYSCALL_TRACE)
  1570. || test_thread_flag(TIF_SINGLESTEP))
  1571. && (current->ptrace & PT_PTRACED))
  1572. syscall_trace();
  1573. /* copy user rbs to kernel rbs */
  1574. if (test_thread_flag(TIF_RESTORE_RSE))
  1575. ia64_sync_krbs();
  1576. }