ptrace.c 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758
  1. /*
  2. * PowerPC version
  3. * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org)
  4. *
  5. * Derived from "arch/m68k/kernel/ptrace.c"
  6. * Copyright (C) 1994 by Hamish Macdonald
  7. * Taken from linux/kernel/ptrace.c and modified for M680x0.
  8. * linux/kernel/ptrace.c is by Ross Biro 1/23/92, edited by Linus Torvalds
  9. *
  10. * Modified by Cort Dougan (cort@hq.fsmlabs.com)
  11. * and Paul Mackerras (paulus@samba.org).
  12. *
  13. * This file is subject to the terms and conditions of the GNU General
  14. * Public License. See the file README.legal in the main directory of
  15. * this archive for more details.
  16. */
  17. #include <linux/kernel.h>
  18. #include <linux/sched.h>
  19. #include <linux/mm.h>
  20. #include <linux/smp.h>
  21. #include <linux/errno.h>
  22. #include <linux/ptrace.h>
  23. #include <linux/regset.h>
  24. #include <linux/tracehook.h>
  25. #include <linux/elf.h>
  26. #include <linux/user.h>
  27. #include <linux/security.h>
  28. #include <linux/signal.h>
  29. #include <linux/seccomp.h>
  30. #include <linux/audit.h>
  31. #include <trace/syscall.h>
  32. #include <linux/hw_breakpoint.h>
  33. #include <linux/perf_event.h>
  34. #include <asm/uaccess.h>
  35. #include <asm/page.h>
  36. #include <asm/pgtable.h>
  37. #include <asm/switch_to.h>
  38. #define CREATE_TRACE_POINTS
  39. #include <trace/events/syscalls.h>
  40. /*
  41. * The parameter save area on the stack is used to store arguments being passed
  42. * to callee function and is located at fixed offset from stack pointer.
  43. */
  44. #ifdef CONFIG_PPC32
  45. #define PARAMETER_SAVE_AREA_OFFSET 24 /* bytes */
  46. #else /* CONFIG_PPC32 */
  47. #define PARAMETER_SAVE_AREA_OFFSET 48 /* bytes */
  48. #endif
  49. struct pt_regs_offset {
  50. const char *name;
  51. int offset;
  52. };
  53. #define STR(s) #s /* convert to string */
  54. #define REG_OFFSET_NAME(r) {.name = #r, .offset = offsetof(struct pt_regs, r)}
  55. #define GPR_OFFSET_NAME(num) \
  56. {.name = STR(gpr##num), .offset = offsetof(struct pt_regs, gpr[num])}
  57. #define REG_OFFSET_END {.name = NULL, .offset = 0}
  58. static const struct pt_regs_offset regoffset_table[] = {
  59. GPR_OFFSET_NAME(0),
  60. GPR_OFFSET_NAME(1),
  61. GPR_OFFSET_NAME(2),
  62. GPR_OFFSET_NAME(3),
  63. GPR_OFFSET_NAME(4),
  64. GPR_OFFSET_NAME(5),
  65. GPR_OFFSET_NAME(6),
  66. GPR_OFFSET_NAME(7),
  67. GPR_OFFSET_NAME(8),
  68. GPR_OFFSET_NAME(9),
  69. GPR_OFFSET_NAME(10),
  70. GPR_OFFSET_NAME(11),
  71. GPR_OFFSET_NAME(12),
  72. GPR_OFFSET_NAME(13),
  73. GPR_OFFSET_NAME(14),
  74. GPR_OFFSET_NAME(15),
  75. GPR_OFFSET_NAME(16),
  76. GPR_OFFSET_NAME(17),
  77. GPR_OFFSET_NAME(18),
  78. GPR_OFFSET_NAME(19),
  79. GPR_OFFSET_NAME(20),
  80. GPR_OFFSET_NAME(21),
  81. GPR_OFFSET_NAME(22),
  82. GPR_OFFSET_NAME(23),
  83. GPR_OFFSET_NAME(24),
  84. GPR_OFFSET_NAME(25),
  85. GPR_OFFSET_NAME(26),
  86. GPR_OFFSET_NAME(27),
  87. GPR_OFFSET_NAME(28),
  88. GPR_OFFSET_NAME(29),
  89. GPR_OFFSET_NAME(30),
  90. GPR_OFFSET_NAME(31),
  91. REG_OFFSET_NAME(nip),
  92. REG_OFFSET_NAME(msr),
  93. REG_OFFSET_NAME(ctr),
  94. REG_OFFSET_NAME(link),
  95. REG_OFFSET_NAME(xer),
  96. REG_OFFSET_NAME(ccr),
  97. #ifdef CONFIG_PPC64
  98. REG_OFFSET_NAME(softe),
  99. #else
  100. REG_OFFSET_NAME(mq),
  101. #endif
  102. REG_OFFSET_NAME(trap),
  103. REG_OFFSET_NAME(dar),
  104. REG_OFFSET_NAME(dsisr),
  105. REG_OFFSET_END,
  106. };
  107. /**
  108. * regs_query_register_offset() - query register offset from its name
  109. * @name: the name of a register
  110. *
  111. * regs_query_register_offset() returns the offset of a register in struct
  112. * pt_regs from its name. If the name is invalid, this returns -EINVAL;
  113. */
  114. int regs_query_register_offset(const char *name)
  115. {
  116. const struct pt_regs_offset *roff;
  117. for (roff = regoffset_table; roff->name != NULL; roff++)
  118. if (!strcmp(roff->name, name))
  119. return roff->offset;
  120. return -EINVAL;
  121. }
  122. /**
  123. * regs_query_register_name() - query register name from its offset
  124. * @offset: the offset of a register in struct pt_regs.
  125. *
  126. * regs_query_register_name() returns the name of a register from its
  127. * offset in struct pt_regs. If the @offset is invalid, this returns NULL;
  128. */
  129. const char *regs_query_register_name(unsigned int offset)
  130. {
  131. const struct pt_regs_offset *roff;
  132. for (roff = regoffset_table; roff->name != NULL; roff++)
  133. if (roff->offset == offset)
  134. return roff->name;
  135. return NULL;
  136. }
  137. /*
  138. * does not yet catch signals sent when the child dies.
  139. * in exit.c or in signal.c.
  140. */
  141. /*
  142. * Set of msr bits that gdb can change on behalf of a process.
  143. */
  144. #ifdef CONFIG_PPC_ADV_DEBUG_REGS
  145. #define MSR_DEBUGCHANGE 0
  146. #else
  147. #define MSR_DEBUGCHANGE (MSR_SE | MSR_BE)
  148. #endif
  149. /*
  150. * Max register writeable via put_reg
  151. */
  152. #ifdef CONFIG_PPC32
  153. #define PT_MAX_PUT_REG PT_MQ
  154. #else
  155. #define PT_MAX_PUT_REG PT_CCR
  156. #endif
  157. static unsigned long get_user_msr(struct task_struct *task)
  158. {
  159. return task->thread.regs->msr | task->thread.fpexc_mode;
  160. }
  161. static int set_user_msr(struct task_struct *task, unsigned long msr)
  162. {
  163. task->thread.regs->msr &= ~MSR_DEBUGCHANGE;
  164. task->thread.regs->msr |= msr & MSR_DEBUGCHANGE;
  165. return 0;
  166. }
  167. /*
  168. * We prevent mucking around with the reserved area of trap
  169. * which are used internally by the kernel.
  170. */
  171. static int set_user_trap(struct task_struct *task, unsigned long trap)
  172. {
  173. task->thread.regs->trap = trap & 0xfff0;
  174. return 0;
  175. }
  176. /*
  177. * Get contents of register REGNO in task TASK.
  178. */
  179. unsigned long ptrace_get_reg(struct task_struct *task, int regno)
  180. {
  181. if (task->thread.regs == NULL)
  182. return -EIO;
  183. if (regno == PT_MSR)
  184. return get_user_msr(task);
  185. if (regno < (sizeof(struct pt_regs) / sizeof(unsigned long)))
  186. return ((unsigned long *)task->thread.regs)[regno];
  187. return -EIO;
  188. }
  189. /*
  190. * Write contents of register REGNO in task TASK.
  191. */
  192. int ptrace_put_reg(struct task_struct *task, int regno, unsigned long data)
  193. {
  194. if (task->thread.regs == NULL)
  195. return -EIO;
  196. if (regno == PT_MSR)
  197. return set_user_msr(task, data);
  198. if (regno == PT_TRAP)
  199. return set_user_trap(task, data);
  200. if (regno <= PT_MAX_PUT_REG) {
  201. ((unsigned long *)task->thread.regs)[regno] = data;
  202. return 0;
  203. }
  204. return -EIO;
  205. }
  206. static int gpr_get(struct task_struct *target, const struct user_regset *regset,
  207. unsigned int pos, unsigned int count,
  208. void *kbuf, void __user *ubuf)
  209. {
  210. int i, ret;
  211. if (target->thread.regs == NULL)
  212. return -EIO;
  213. if (!FULL_REGS(target->thread.regs)) {
  214. /* We have a partial register set. Fill 14-31 with bogus values */
  215. for (i = 14; i < 32; i++)
  216. target->thread.regs->gpr[i] = NV_REG_POISON;
  217. }
  218. ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
  219. target->thread.regs,
  220. 0, offsetof(struct pt_regs, msr));
  221. if (!ret) {
  222. unsigned long msr = get_user_msr(target);
  223. ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf, &msr,
  224. offsetof(struct pt_regs, msr),
  225. offsetof(struct pt_regs, msr) +
  226. sizeof(msr));
  227. }
  228. BUILD_BUG_ON(offsetof(struct pt_regs, orig_gpr3) !=
  229. offsetof(struct pt_regs, msr) + sizeof(long));
  230. if (!ret)
  231. ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
  232. &target->thread.regs->orig_gpr3,
  233. offsetof(struct pt_regs, orig_gpr3),
  234. sizeof(struct pt_regs));
  235. if (!ret)
  236. ret = user_regset_copyout_zero(&pos, &count, &kbuf, &ubuf,
  237. sizeof(struct pt_regs), -1);
  238. return ret;
  239. }
  240. static int gpr_set(struct task_struct *target, const struct user_regset *regset,
  241. unsigned int pos, unsigned int count,
  242. const void *kbuf, const void __user *ubuf)
  243. {
  244. unsigned long reg;
  245. int ret;
  246. if (target->thread.regs == NULL)
  247. return -EIO;
  248. CHECK_FULL_REGS(target->thread.regs);
  249. ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
  250. target->thread.regs,
  251. 0, PT_MSR * sizeof(reg));
  252. if (!ret && count > 0) {
  253. ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, &reg,
  254. PT_MSR * sizeof(reg),
  255. (PT_MSR + 1) * sizeof(reg));
  256. if (!ret)
  257. ret = set_user_msr(target, reg);
  258. }
  259. BUILD_BUG_ON(offsetof(struct pt_regs, orig_gpr3) !=
  260. offsetof(struct pt_regs, msr) + sizeof(long));
  261. if (!ret)
  262. ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
  263. &target->thread.regs->orig_gpr3,
  264. PT_ORIG_R3 * sizeof(reg),
  265. (PT_MAX_PUT_REG + 1) * sizeof(reg));
  266. if (PT_MAX_PUT_REG + 1 < PT_TRAP && !ret)
  267. ret = user_regset_copyin_ignore(
  268. &pos, &count, &kbuf, &ubuf,
  269. (PT_MAX_PUT_REG + 1) * sizeof(reg),
  270. PT_TRAP * sizeof(reg));
  271. if (!ret && count > 0) {
  272. ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, &reg,
  273. PT_TRAP * sizeof(reg),
  274. (PT_TRAP + 1) * sizeof(reg));
  275. if (!ret)
  276. ret = set_user_trap(target, reg);
  277. }
  278. if (!ret)
  279. ret = user_regset_copyin_ignore(
  280. &pos, &count, &kbuf, &ubuf,
  281. (PT_TRAP + 1) * sizeof(reg), -1);
  282. return ret;
  283. }
  284. static int fpr_get(struct task_struct *target, const struct user_regset *regset,
  285. unsigned int pos, unsigned int count,
  286. void *kbuf, void __user *ubuf)
  287. {
  288. #ifdef CONFIG_VSX
  289. double buf[33];
  290. int i;
  291. #endif
  292. flush_fp_to_thread(target);
  293. #ifdef CONFIG_VSX
  294. /* copy to local buffer then write that out */
  295. for (i = 0; i < 32 ; i++)
  296. buf[i] = target->thread.TS_FPR(i);
  297. memcpy(&buf[32], &target->thread.fpscr, sizeof(double));
  298. return user_regset_copyout(&pos, &count, &kbuf, &ubuf, buf, 0, -1);
  299. #else
  300. BUILD_BUG_ON(offsetof(struct thread_struct, fpscr) !=
  301. offsetof(struct thread_struct, TS_FPR(32)));
  302. return user_regset_copyout(&pos, &count, &kbuf, &ubuf,
  303. &target->thread.fpr, 0, -1);
  304. #endif
  305. }
  306. static int fpr_set(struct task_struct *target, const struct user_regset *regset,
  307. unsigned int pos, unsigned int count,
  308. const void *kbuf, const void __user *ubuf)
  309. {
  310. #ifdef CONFIG_VSX
  311. double buf[33];
  312. int i;
  313. #endif
  314. flush_fp_to_thread(target);
  315. #ifdef CONFIG_VSX
  316. /* copy to local buffer then write that out */
  317. i = user_regset_copyin(&pos, &count, &kbuf, &ubuf, buf, 0, -1);
  318. if (i)
  319. return i;
  320. for (i = 0; i < 32 ; i++)
  321. target->thread.TS_FPR(i) = buf[i];
  322. memcpy(&target->thread.fpscr, &buf[32], sizeof(double));
  323. return 0;
  324. #else
  325. BUILD_BUG_ON(offsetof(struct thread_struct, fpscr) !=
  326. offsetof(struct thread_struct, TS_FPR(32)));
  327. return user_regset_copyin(&pos, &count, &kbuf, &ubuf,
  328. &target->thread.fpr, 0, -1);
  329. #endif
  330. }
  331. #ifdef CONFIG_ALTIVEC
  332. /*
  333. * Get/set all the altivec registers vr0..vr31, vscr, vrsave, in one go.
  334. * The transfer totals 34 quadword. Quadwords 0-31 contain the
  335. * corresponding vector registers. Quadword 32 contains the vscr as the
  336. * last word (offset 12) within that quadword. Quadword 33 contains the
  337. * vrsave as the first word (offset 0) within the quadword.
  338. *
  339. * This definition of the VMX state is compatible with the current PPC32
  340. * ptrace interface. This allows signal handling and ptrace to use the
  341. * same structures. This also simplifies the implementation of a bi-arch
  342. * (combined (32- and 64-bit) gdb.
  343. */
  344. static int vr_active(struct task_struct *target,
  345. const struct user_regset *regset)
  346. {
  347. flush_altivec_to_thread(target);
  348. return target->thread.used_vr ? regset->n : 0;
  349. }
  350. static int vr_get(struct task_struct *target, const struct user_regset *regset,
  351. unsigned int pos, unsigned int count,
  352. void *kbuf, void __user *ubuf)
  353. {
  354. int ret;
  355. flush_altivec_to_thread(target);
  356. BUILD_BUG_ON(offsetof(struct thread_struct, vscr) !=
  357. offsetof(struct thread_struct, vr[32]));
  358. ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
  359. &target->thread.vr, 0,
  360. 33 * sizeof(vector128));
  361. if (!ret) {
  362. /*
  363. * Copy out only the low-order word of vrsave.
  364. */
  365. union {
  366. elf_vrreg_t reg;
  367. u32 word;
  368. } vrsave;
  369. memset(&vrsave, 0, sizeof(vrsave));
  370. vrsave.word = target->thread.vrsave;
  371. ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf, &vrsave,
  372. 33 * sizeof(vector128), -1);
  373. }
  374. return ret;
  375. }
  376. static int vr_set(struct task_struct *target, const struct user_regset *regset,
  377. unsigned int pos, unsigned int count,
  378. const void *kbuf, const void __user *ubuf)
  379. {
  380. int ret;
  381. flush_altivec_to_thread(target);
  382. BUILD_BUG_ON(offsetof(struct thread_struct, vscr) !=
  383. offsetof(struct thread_struct, vr[32]));
  384. ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
  385. &target->thread.vr, 0, 33 * sizeof(vector128));
  386. if (!ret && count > 0) {
  387. /*
  388. * We use only the first word of vrsave.
  389. */
  390. union {
  391. elf_vrreg_t reg;
  392. u32 word;
  393. } vrsave;
  394. memset(&vrsave, 0, sizeof(vrsave));
  395. vrsave.word = target->thread.vrsave;
  396. ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, &vrsave,
  397. 33 * sizeof(vector128), -1);
  398. if (!ret)
  399. target->thread.vrsave = vrsave.word;
  400. }
  401. return ret;
  402. }
  403. #endif /* CONFIG_ALTIVEC */
  404. #ifdef CONFIG_VSX
  405. /*
  406. * Currently to set and and get all the vsx state, you need to call
  407. * the fp and VMX calls as well. This only get/sets the lower 32
  408. * 128bit VSX registers.
  409. */
  410. static int vsr_active(struct task_struct *target,
  411. const struct user_regset *regset)
  412. {
  413. flush_vsx_to_thread(target);
  414. return target->thread.used_vsr ? regset->n : 0;
  415. }
  416. static int vsr_get(struct task_struct *target, const struct user_regset *regset,
  417. unsigned int pos, unsigned int count,
  418. void *kbuf, void __user *ubuf)
  419. {
  420. double buf[32];
  421. int ret, i;
  422. flush_vsx_to_thread(target);
  423. for (i = 0; i < 32 ; i++)
  424. buf[i] = target->thread.fpr[i][TS_VSRLOWOFFSET];
  425. ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
  426. buf, 0, 32 * sizeof(double));
  427. return ret;
  428. }
  429. static int vsr_set(struct task_struct *target, const struct user_regset *regset,
  430. unsigned int pos, unsigned int count,
  431. const void *kbuf, const void __user *ubuf)
  432. {
  433. double buf[32];
  434. int ret,i;
  435. flush_vsx_to_thread(target);
  436. ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
  437. buf, 0, 32 * sizeof(double));
  438. for (i = 0; i < 32 ; i++)
  439. target->thread.fpr[i][TS_VSRLOWOFFSET] = buf[i];
  440. return ret;
  441. }
  442. #endif /* CONFIG_VSX */
  443. #ifdef CONFIG_SPE
  444. /*
  445. * For get_evrregs/set_evrregs functions 'data' has the following layout:
  446. *
  447. * struct {
  448. * u32 evr[32];
  449. * u64 acc;
  450. * u32 spefscr;
  451. * }
  452. */
  453. static int evr_active(struct task_struct *target,
  454. const struct user_regset *regset)
  455. {
  456. flush_spe_to_thread(target);
  457. return target->thread.used_spe ? regset->n : 0;
  458. }
  459. static int evr_get(struct task_struct *target, const struct user_regset *regset,
  460. unsigned int pos, unsigned int count,
  461. void *kbuf, void __user *ubuf)
  462. {
  463. int ret;
  464. flush_spe_to_thread(target);
  465. ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
  466. &target->thread.evr,
  467. 0, sizeof(target->thread.evr));
  468. BUILD_BUG_ON(offsetof(struct thread_struct, acc) + sizeof(u64) !=
  469. offsetof(struct thread_struct, spefscr));
  470. if (!ret)
  471. ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
  472. &target->thread.acc,
  473. sizeof(target->thread.evr), -1);
  474. return ret;
  475. }
  476. static int evr_set(struct task_struct *target, const struct user_regset *regset,
  477. unsigned int pos, unsigned int count,
  478. const void *kbuf, const void __user *ubuf)
  479. {
  480. int ret;
  481. flush_spe_to_thread(target);
  482. ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
  483. &target->thread.evr,
  484. 0, sizeof(target->thread.evr));
  485. BUILD_BUG_ON(offsetof(struct thread_struct, acc) + sizeof(u64) !=
  486. offsetof(struct thread_struct, spefscr));
  487. if (!ret)
  488. ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
  489. &target->thread.acc,
  490. sizeof(target->thread.evr), -1);
  491. return ret;
  492. }
  493. #endif /* CONFIG_SPE */
  494. /*
  495. * These are our native regset flavors.
  496. */
  497. enum powerpc_regset {
  498. REGSET_GPR,
  499. REGSET_FPR,
  500. #ifdef CONFIG_ALTIVEC
  501. REGSET_VMX,
  502. #endif
  503. #ifdef CONFIG_VSX
  504. REGSET_VSX,
  505. #endif
  506. #ifdef CONFIG_SPE
  507. REGSET_SPE,
  508. #endif
  509. };
  510. static const struct user_regset native_regsets[] = {
  511. [REGSET_GPR] = {
  512. .core_note_type = NT_PRSTATUS, .n = ELF_NGREG,
  513. .size = sizeof(long), .align = sizeof(long),
  514. .get = gpr_get, .set = gpr_set
  515. },
  516. [REGSET_FPR] = {
  517. .core_note_type = NT_PRFPREG, .n = ELF_NFPREG,
  518. .size = sizeof(double), .align = sizeof(double),
  519. .get = fpr_get, .set = fpr_set
  520. },
  521. #ifdef CONFIG_ALTIVEC
  522. [REGSET_VMX] = {
  523. .core_note_type = NT_PPC_VMX, .n = 34,
  524. .size = sizeof(vector128), .align = sizeof(vector128),
  525. .active = vr_active, .get = vr_get, .set = vr_set
  526. },
  527. #endif
  528. #ifdef CONFIG_VSX
  529. [REGSET_VSX] = {
  530. .core_note_type = NT_PPC_VSX, .n = 32,
  531. .size = sizeof(double), .align = sizeof(double),
  532. .active = vsr_active, .get = vsr_get, .set = vsr_set
  533. },
  534. #endif
  535. #ifdef CONFIG_SPE
  536. [REGSET_SPE] = {
  537. .n = 35,
  538. .size = sizeof(u32), .align = sizeof(u32),
  539. .active = evr_active, .get = evr_get, .set = evr_set
  540. },
  541. #endif
  542. };
  543. static const struct user_regset_view user_ppc_native_view = {
  544. .name = UTS_MACHINE, .e_machine = ELF_ARCH, .ei_osabi = ELF_OSABI,
  545. .regsets = native_regsets, .n = ARRAY_SIZE(native_regsets)
  546. };
  547. #ifdef CONFIG_PPC64
  548. #include <linux/compat.h>
  549. static int gpr32_get(struct task_struct *target,
  550. const struct user_regset *regset,
  551. unsigned int pos, unsigned int count,
  552. void *kbuf, void __user *ubuf)
  553. {
  554. const unsigned long *regs = &target->thread.regs->gpr[0];
  555. compat_ulong_t *k = kbuf;
  556. compat_ulong_t __user *u = ubuf;
  557. compat_ulong_t reg;
  558. int i;
  559. if (target->thread.regs == NULL)
  560. return -EIO;
  561. if (!FULL_REGS(target->thread.regs)) {
  562. /* We have a partial register set. Fill 14-31 with bogus values */
  563. for (i = 14; i < 32; i++)
  564. target->thread.regs->gpr[i] = NV_REG_POISON;
  565. }
  566. pos /= sizeof(reg);
  567. count /= sizeof(reg);
  568. if (kbuf)
  569. for (; count > 0 && pos < PT_MSR; --count)
  570. *k++ = regs[pos++];
  571. else
  572. for (; count > 0 && pos < PT_MSR; --count)
  573. if (__put_user((compat_ulong_t) regs[pos++], u++))
  574. return -EFAULT;
  575. if (count > 0 && pos == PT_MSR) {
  576. reg = get_user_msr(target);
  577. if (kbuf)
  578. *k++ = reg;
  579. else if (__put_user(reg, u++))
  580. return -EFAULT;
  581. ++pos;
  582. --count;
  583. }
  584. if (kbuf)
  585. for (; count > 0 && pos < PT_REGS_COUNT; --count)
  586. *k++ = regs[pos++];
  587. else
  588. for (; count > 0 && pos < PT_REGS_COUNT; --count)
  589. if (__put_user((compat_ulong_t) regs[pos++], u++))
  590. return -EFAULT;
  591. kbuf = k;
  592. ubuf = u;
  593. pos *= sizeof(reg);
  594. count *= sizeof(reg);
  595. return user_regset_copyout_zero(&pos, &count, &kbuf, &ubuf,
  596. PT_REGS_COUNT * sizeof(reg), -1);
  597. }
  598. static int gpr32_set(struct task_struct *target,
  599. const struct user_regset *regset,
  600. unsigned int pos, unsigned int count,
  601. const void *kbuf, const void __user *ubuf)
  602. {
  603. unsigned long *regs = &target->thread.regs->gpr[0];
  604. const compat_ulong_t *k = kbuf;
  605. const compat_ulong_t __user *u = ubuf;
  606. compat_ulong_t reg;
  607. if (target->thread.regs == NULL)
  608. return -EIO;
  609. CHECK_FULL_REGS(target->thread.regs);
  610. pos /= sizeof(reg);
  611. count /= sizeof(reg);
  612. if (kbuf)
  613. for (; count > 0 && pos < PT_MSR; --count)
  614. regs[pos++] = *k++;
  615. else
  616. for (; count > 0 && pos < PT_MSR; --count) {
  617. if (__get_user(reg, u++))
  618. return -EFAULT;
  619. regs[pos++] = reg;
  620. }
  621. if (count > 0 && pos == PT_MSR) {
  622. if (kbuf)
  623. reg = *k++;
  624. else if (__get_user(reg, u++))
  625. return -EFAULT;
  626. set_user_msr(target, reg);
  627. ++pos;
  628. --count;
  629. }
  630. if (kbuf) {
  631. for (; count > 0 && pos <= PT_MAX_PUT_REG; --count)
  632. regs[pos++] = *k++;
  633. for (; count > 0 && pos < PT_TRAP; --count, ++pos)
  634. ++k;
  635. } else {
  636. for (; count > 0 && pos <= PT_MAX_PUT_REG; --count) {
  637. if (__get_user(reg, u++))
  638. return -EFAULT;
  639. regs[pos++] = reg;
  640. }
  641. for (; count > 0 && pos < PT_TRAP; --count, ++pos)
  642. if (__get_user(reg, u++))
  643. return -EFAULT;
  644. }
  645. if (count > 0 && pos == PT_TRAP) {
  646. if (kbuf)
  647. reg = *k++;
  648. else if (__get_user(reg, u++))
  649. return -EFAULT;
  650. set_user_trap(target, reg);
  651. ++pos;
  652. --count;
  653. }
  654. kbuf = k;
  655. ubuf = u;
  656. pos *= sizeof(reg);
  657. count *= sizeof(reg);
  658. return user_regset_copyin_ignore(&pos, &count, &kbuf, &ubuf,
  659. (PT_TRAP + 1) * sizeof(reg), -1);
  660. }
  661. /*
  662. * These are the regset flavors matching the CONFIG_PPC32 native set.
  663. */
  664. static const struct user_regset compat_regsets[] = {
  665. [REGSET_GPR] = {
  666. .core_note_type = NT_PRSTATUS, .n = ELF_NGREG,
  667. .size = sizeof(compat_long_t), .align = sizeof(compat_long_t),
  668. .get = gpr32_get, .set = gpr32_set
  669. },
  670. [REGSET_FPR] = {
  671. .core_note_type = NT_PRFPREG, .n = ELF_NFPREG,
  672. .size = sizeof(double), .align = sizeof(double),
  673. .get = fpr_get, .set = fpr_set
  674. },
  675. #ifdef CONFIG_ALTIVEC
  676. [REGSET_VMX] = {
  677. .core_note_type = NT_PPC_VMX, .n = 34,
  678. .size = sizeof(vector128), .align = sizeof(vector128),
  679. .active = vr_active, .get = vr_get, .set = vr_set
  680. },
  681. #endif
  682. #ifdef CONFIG_SPE
  683. [REGSET_SPE] = {
  684. .core_note_type = NT_PPC_SPE, .n = 35,
  685. .size = sizeof(u32), .align = sizeof(u32),
  686. .active = evr_active, .get = evr_get, .set = evr_set
  687. },
  688. #endif
  689. };
  690. static const struct user_regset_view user_ppc_compat_view = {
  691. .name = "ppc", .e_machine = EM_PPC, .ei_osabi = ELF_OSABI,
  692. .regsets = compat_regsets, .n = ARRAY_SIZE(compat_regsets)
  693. };
  694. #endif /* CONFIG_PPC64 */
  695. const struct user_regset_view *task_user_regset_view(struct task_struct *task)
  696. {
  697. #ifdef CONFIG_PPC64
  698. if (test_tsk_thread_flag(task, TIF_32BIT))
  699. return &user_ppc_compat_view;
  700. #endif
  701. return &user_ppc_native_view;
  702. }
  703. void user_enable_single_step(struct task_struct *task)
  704. {
  705. struct pt_regs *regs = task->thread.regs;
  706. if (regs != NULL) {
  707. #ifdef CONFIG_PPC_ADV_DEBUG_REGS
  708. task->thread.dbcr0 &= ~DBCR0_BT;
  709. task->thread.dbcr0 |= DBCR0_IDM | DBCR0_IC;
  710. regs->msr |= MSR_DE;
  711. #else
  712. regs->msr &= ~MSR_BE;
  713. regs->msr |= MSR_SE;
  714. #endif
  715. }
  716. set_tsk_thread_flag(task, TIF_SINGLESTEP);
  717. }
  718. void user_enable_block_step(struct task_struct *task)
  719. {
  720. struct pt_regs *regs = task->thread.regs;
  721. if (regs != NULL) {
  722. #ifdef CONFIG_PPC_ADV_DEBUG_REGS
  723. task->thread.dbcr0 &= ~DBCR0_IC;
  724. task->thread.dbcr0 = DBCR0_IDM | DBCR0_BT;
  725. regs->msr |= MSR_DE;
  726. #else
  727. regs->msr &= ~MSR_SE;
  728. regs->msr |= MSR_BE;
  729. #endif
  730. }
  731. set_tsk_thread_flag(task, TIF_SINGLESTEP);
  732. }
  733. void user_disable_single_step(struct task_struct *task)
  734. {
  735. struct pt_regs *regs = task->thread.regs;
  736. if (regs != NULL) {
  737. #ifdef CONFIG_PPC_ADV_DEBUG_REGS
  738. /*
  739. * The logic to disable single stepping should be as
  740. * simple as turning off the Instruction Complete flag.
  741. * And, after doing so, if all debug flags are off, turn
  742. * off DBCR0(IDM) and MSR(DE) .... Torez
  743. */
  744. task->thread.dbcr0 &= ~DBCR0_IC;
  745. /*
  746. * Test to see if any of the DBCR_ACTIVE_EVENTS bits are set.
  747. */
  748. if (!DBCR_ACTIVE_EVENTS(task->thread.dbcr0,
  749. task->thread.dbcr1)) {
  750. /*
  751. * All debug events were off.....
  752. */
  753. task->thread.dbcr0 &= ~DBCR0_IDM;
  754. regs->msr &= ~MSR_DE;
  755. }
  756. #else
  757. regs->msr &= ~(MSR_SE | MSR_BE);
  758. #endif
  759. }
  760. clear_tsk_thread_flag(task, TIF_SINGLESTEP);
  761. }
  762. #ifdef CONFIG_HAVE_HW_BREAKPOINT
  763. void ptrace_triggered(struct perf_event *bp,
  764. struct perf_sample_data *data, struct pt_regs *regs)
  765. {
  766. struct perf_event_attr attr;
  767. /*
  768. * Disable the breakpoint request here since ptrace has defined a
  769. * one-shot behaviour for breakpoint exceptions in PPC64.
  770. * The SIGTRAP signal is generated automatically for us in do_dabr().
  771. * We don't have to do anything about that here
  772. */
  773. attr = bp->attr;
  774. attr.disabled = true;
  775. modify_user_hw_breakpoint(bp, &attr);
  776. }
  777. #endif /* CONFIG_HAVE_HW_BREAKPOINT */
  778. int ptrace_set_debugreg(struct task_struct *task, unsigned long addr,
  779. unsigned long data)
  780. {
  781. #ifdef CONFIG_HAVE_HW_BREAKPOINT
  782. int ret;
  783. struct thread_struct *thread = &(task->thread);
  784. struct perf_event *bp;
  785. struct perf_event_attr attr;
  786. #endif /* CONFIG_HAVE_HW_BREAKPOINT */
  787. /* For ppc64 we support one DABR and no IABR's at the moment (ppc64).
  788. * For embedded processors we support one DAC and no IAC's at the
  789. * moment.
  790. */
  791. if (addr > 0)
  792. return -EINVAL;
  793. /* The bottom 3 bits in dabr are flags */
  794. if ((data & ~0x7UL) >= TASK_SIZE)
  795. return -EIO;
  796. #ifndef CONFIG_PPC_ADV_DEBUG_REGS
  797. /* For processors using DABR (i.e. 970), the bottom 3 bits are flags.
  798. * It was assumed, on previous implementations, that 3 bits were
  799. * passed together with the data address, fitting the design of the
  800. * DABR register, as follows:
  801. *
  802. * bit 0: Read flag
  803. * bit 1: Write flag
  804. * bit 2: Breakpoint translation
  805. *
  806. * Thus, we use them here as so.
  807. */
  808. /* Ensure breakpoint translation bit is set */
  809. if (data && !(data & DABR_TRANSLATION))
  810. return -EIO;
  811. #ifdef CONFIG_HAVE_HW_BREAKPOINT
  812. if (ptrace_get_breakpoints(task) < 0)
  813. return -ESRCH;
  814. bp = thread->ptrace_bps[0];
  815. if ((!data) || !(data & (DABR_DATA_WRITE | DABR_DATA_READ))) {
  816. if (bp) {
  817. unregister_hw_breakpoint(bp);
  818. thread->ptrace_bps[0] = NULL;
  819. }
  820. ptrace_put_breakpoints(task);
  821. return 0;
  822. }
  823. if (bp) {
  824. attr = bp->attr;
  825. attr.bp_addr = data & ~HW_BREAKPOINT_ALIGN;
  826. arch_bp_generic_fields(data &
  827. (DABR_DATA_WRITE | DABR_DATA_READ),
  828. &attr.bp_type);
  829. ret = modify_user_hw_breakpoint(bp, &attr);
  830. if (ret) {
  831. ptrace_put_breakpoints(task);
  832. return ret;
  833. }
  834. thread->ptrace_bps[0] = bp;
  835. ptrace_put_breakpoints(task);
  836. thread->dabr = data;
  837. return 0;
  838. }
  839. /* Create a new breakpoint request if one doesn't exist already */
  840. hw_breakpoint_init(&attr);
  841. attr.bp_addr = data & ~HW_BREAKPOINT_ALIGN;
  842. arch_bp_generic_fields(data & (DABR_DATA_WRITE | DABR_DATA_READ),
  843. &attr.bp_type);
  844. thread->ptrace_bps[0] = bp = register_user_hw_breakpoint(&attr,
  845. ptrace_triggered, NULL, task);
  846. if (IS_ERR(bp)) {
  847. thread->ptrace_bps[0] = NULL;
  848. ptrace_put_breakpoints(task);
  849. return PTR_ERR(bp);
  850. }
  851. ptrace_put_breakpoints(task);
  852. #endif /* CONFIG_HAVE_HW_BREAKPOINT */
  853. /* Move contents to the DABR register */
  854. task->thread.dabr = data;
  855. #else /* CONFIG_PPC_ADV_DEBUG_REGS */
  856. /* As described above, it was assumed 3 bits were passed with the data
  857. * address, but we will assume only the mode bits will be passed
  858. * as to not cause alignment restrictions for DAC-based processors.
  859. */
  860. /* DAC's hold the whole address without any mode flags */
  861. task->thread.dac1 = data & ~0x3UL;
  862. if (task->thread.dac1 == 0) {
  863. dbcr_dac(task) &= ~(DBCR_DAC1R | DBCR_DAC1W);
  864. if (!DBCR_ACTIVE_EVENTS(task->thread.dbcr0,
  865. task->thread.dbcr1)) {
  866. task->thread.regs->msr &= ~MSR_DE;
  867. task->thread.dbcr0 &= ~DBCR0_IDM;
  868. }
  869. return 0;
  870. }
  871. /* Read or Write bits must be set */
  872. if (!(data & 0x3UL))
  873. return -EINVAL;
  874. /* Set the Internal Debugging flag (IDM bit 1) for the DBCR0
  875. register */
  876. task->thread.dbcr0 |= DBCR0_IDM;
  877. /* Check for write and read flags and set DBCR0
  878. accordingly */
  879. dbcr_dac(task) &= ~(DBCR_DAC1R|DBCR_DAC1W);
  880. if (data & 0x1UL)
  881. dbcr_dac(task) |= DBCR_DAC1R;
  882. if (data & 0x2UL)
  883. dbcr_dac(task) |= DBCR_DAC1W;
  884. task->thread.regs->msr |= MSR_DE;
  885. #endif /* CONFIG_PPC_ADV_DEBUG_REGS */
  886. return 0;
  887. }
  888. /*
  889. * Called by kernel/ptrace.c when detaching..
  890. *
  891. * Make sure single step bits etc are not set.
  892. */
  893. void ptrace_disable(struct task_struct *child)
  894. {
  895. /* make sure the single step bit is not set. */
  896. user_disable_single_step(child);
  897. }
  898. #ifdef CONFIG_PPC_ADV_DEBUG_REGS
  899. static long set_intruction_bp(struct task_struct *child,
  900. struct ppc_hw_breakpoint *bp_info)
  901. {
  902. int slot;
  903. int slot1_in_use = ((child->thread.dbcr0 & DBCR0_IAC1) != 0);
  904. int slot2_in_use = ((child->thread.dbcr0 & DBCR0_IAC2) != 0);
  905. int slot3_in_use = ((child->thread.dbcr0 & DBCR0_IAC3) != 0);
  906. int slot4_in_use = ((child->thread.dbcr0 & DBCR0_IAC4) != 0);
  907. if (dbcr_iac_range(child) & DBCR_IAC12MODE)
  908. slot2_in_use = 1;
  909. if (dbcr_iac_range(child) & DBCR_IAC34MODE)
  910. slot4_in_use = 1;
  911. if (bp_info->addr >= TASK_SIZE)
  912. return -EIO;
  913. if (bp_info->addr_mode != PPC_BREAKPOINT_MODE_EXACT) {
  914. /* Make sure range is valid. */
  915. if (bp_info->addr2 >= TASK_SIZE)
  916. return -EIO;
  917. /* We need a pair of IAC regsisters */
  918. if ((!slot1_in_use) && (!slot2_in_use)) {
  919. slot = 1;
  920. child->thread.iac1 = bp_info->addr;
  921. child->thread.iac2 = bp_info->addr2;
  922. child->thread.dbcr0 |= DBCR0_IAC1;
  923. if (bp_info->addr_mode ==
  924. PPC_BREAKPOINT_MODE_RANGE_EXCLUSIVE)
  925. dbcr_iac_range(child) |= DBCR_IAC12X;
  926. else
  927. dbcr_iac_range(child) |= DBCR_IAC12I;
  928. #if CONFIG_PPC_ADV_DEBUG_IACS > 2
  929. } else if ((!slot3_in_use) && (!slot4_in_use)) {
  930. slot = 3;
  931. child->thread.iac3 = bp_info->addr;
  932. child->thread.iac4 = bp_info->addr2;
  933. child->thread.dbcr0 |= DBCR0_IAC3;
  934. if (bp_info->addr_mode ==
  935. PPC_BREAKPOINT_MODE_RANGE_EXCLUSIVE)
  936. dbcr_iac_range(child) |= DBCR_IAC34X;
  937. else
  938. dbcr_iac_range(child) |= DBCR_IAC34I;
  939. #endif
  940. } else
  941. return -ENOSPC;
  942. } else {
  943. /* We only need one. If possible leave a pair free in
  944. * case a range is needed later
  945. */
  946. if (!slot1_in_use) {
  947. /*
  948. * Don't use iac1 if iac1-iac2 are free and either
  949. * iac3 or iac4 (but not both) are free
  950. */
  951. if (slot2_in_use || (slot3_in_use == slot4_in_use)) {
  952. slot = 1;
  953. child->thread.iac1 = bp_info->addr;
  954. child->thread.dbcr0 |= DBCR0_IAC1;
  955. goto out;
  956. }
  957. }
  958. if (!slot2_in_use) {
  959. slot = 2;
  960. child->thread.iac2 = bp_info->addr;
  961. child->thread.dbcr0 |= DBCR0_IAC2;
  962. #if CONFIG_PPC_ADV_DEBUG_IACS > 2
  963. } else if (!slot3_in_use) {
  964. slot = 3;
  965. child->thread.iac3 = bp_info->addr;
  966. child->thread.dbcr0 |= DBCR0_IAC3;
  967. } else if (!slot4_in_use) {
  968. slot = 4;
  969. child->thread.iac4 = bp_info->addr;
  970. child->thread.dbcr0 |= DBCR0_IAC4;
  971. #endif
  972. } else
  973. return -ENOSPC;
  974. }
  975. out:
  976. child->thread.dbcr0 |= DBCR0_IDM;
  977. child->thread.regs->msr |= MSR_DE;
  978. return slot;
  979. }
  980. static int del_instruction_bp(struct task_struct *child, int slot)
  981. {
  982. switch (slot) {
  983. case 1:
  984. if ((child->thread.dbcr0 & DBCR0_IAC1) == 0)
  985. return -ENOENT;
  986. if (dbcr_iac_range(child) & DBCR_IAC12MODE) {
  987. /* address range - clear slots 1 & 2 */
  988. child->thread.iac2 = 0;
  989. dbcr_iac_range(child) &= ~DBCR_IAC12MODE;
  990. }
  991. child->thread.iac1 = 0;
  992. child->thread.dbcr0 &= ~DBCR0_IAC1;
  993. break;
  994. case 2:
  995. if ((child->thread.dbcr0 & DBCR0_IAC2) == 0)
  996. return -ENOENT;
  997. if (dbcr_iac_range(child) & DBCR_IAC12MODE)
  998. /* used in a range */
  999. return -EINVAL;
  1000. child->thread.iac2 = 0;
  1001. child->thread.dbcr0 &= ~DBCR0_IAC2;
  1002. break;
  1003. #if CONFIG_PPC_ADV_DEBUG_IACS > 2
  1004. case 3:
  1005. if ((child->thread.dbcr0 & DBCR0_IAC3) == 0)
  1006. return -ENOENT;
  1007. if (dbcr_iac_range(child) & DBCR_IAC34MODE) {
  1008. /* address range - clear slots 3 & 4 */
  1009. child->thread.iac4 = 0;
  1010. dbcr_iac_range(child) &= ~DBCR_IAC34MODE;
  1011. }
  1012. child->thread.iac3 = 0;
  1013. child->thread.dbcr0 &= ~DBCR0_IAC3;
  1014. break;
  1015. case 4:
  1016. if ((child->thread.dbcr0 & DBCR0_IAC4) == 0)
  1017. return -ENOENT;
  1018. if (dbcr_iac_range(child) & DBCR_IAC34MODE)
  1019. /* Used in a range */
  1020. return -EINVAL;
  1021. child->thread.iac4 = 0;
  1022. child->thread.dbcr0 &= ~DBCR0_IAC4;
  1023. break;
  1024. #endif
  1025. default:
  1026. return -EINVAL;
  1027. }
  1028. return 0;
  1029. }
  1030. static int set_dac(struct task_struct *child, struct ppc_hw_breakpoint *bp_info)
  1031. {
  1032. int byte_enable =
  1033. (bp_info->condition_mode >> PPC_BREAKPOINT_CONDITION_BE_SHIFT)
  1034. & 0xf;
  1035. int condition_mode =
  1036. bp_info->condition_mode & PPC_BREAKPOINT_CONDITION_MODE;
  1037. int slot;
  1038. if (byte_enable && (condition_mode == 0))
  1039. return -EINVAL;
  1040. if (bp_info->addr >= TASK_SIZE)
  1041. return -EIO;
  1042. if ((dbcr_dac(child) & (DBCR_DAC1R | DBCR_DAC1W)) == 0) {
  1043. slot = 1;
  1044. if (bp_info->trigger_type & PPC_BREAKPOINT_TRIGGER_READ)
  1045. dbcr_dac(child) |= DBCR_DAC1R;
  1046. if (bp_info->trigger_type & PPC_BREAKPOINT_TRIGGER_WRITE)
  1047. dbcr_dac(child) |= DBCR_DAC1W;
  1048. child->thread.dac1 = (unsigned long)bp_info->addr;
  1049. #if CONFIG_PPC_ADV_DEBUG_DVCS > 0
  1050. if (byte_enable) {
  1051. child->thread.dvc1 =
  1052. (unsigned long)bp_info->condition_value;
  1053. child->thread.dbcr2 |=
  1054. ((byte_enable << DBCR2_DVC1BE_SHIFT) |
  1055. (condition_mode << DBCR2_DVC1M_SHIFT));
  1056. }
  1057. #endif
  1058. #ifdef CONFIG_PPC_ADV_DEBUG_DAC_RANGE
  1059. } else if (child->thread.dbcr2 & DBCR2_DAC12MODE) {
  1060. /* Both dac1 and dac2 are part of a range */
  1061. return -ENOSPC;
  1062. #endif
  1063. } else if ((dbcr_dac(child) & (DBCR_DAC2R | DBCR_DAC2W)) == 0) {
  1064. slot = 2;
  1065. if (bp_info->trigger_type & PPC_BREAKPOINT_TRIGGER_READ)
  1066. dbcr_dac(child) |= DBCR_DAC2R;
  1067. if (bp_info->trigger_type & PPC_BREAKPOINT_TRIGGER_WRITE)
  1068. dbcr_dac(child) |= DBCR_DAC2W;
  1069. child->thread.dac2 = (unsigned long)bp_info->addr;
  1070. #if CONFIG_PPC_ADV_DEBUG_DVCS > 0
  1071. if (byte_enable) {
  1072. child->thread.dvc2 =
  1073. (unsigned long)bp_info->condition_value;
  1074. child->thread.dbcr2 |=
  1075. ((byte_enable << DBCR2_DVC2BE_SHIFT) |
  1076. (condition_mode << DBCR2_DVC2M_SHIFT));
  1077. }
  1078. #endif
  1079. } else
  1080. return -ENOSPC;
  1081. child->thread.dbcr0 |= DBCR0_IDM;
  1082. child->thread.regs->msr |= MSR_DE;
  1083. return slot + 4;
  1084. }
  1085. static int del_dac(struct task_struct *child, int slot)
  1086. {
  1087. if (slot == 1) {
  1088. if ((dbcr_dac(child) & (DBCR_DAC1R | DBCR_DAC1W)) == 0)
  1089. return -ENOENT;
  1090. child->thread.dac1 = 0;
  1091. dbcr_dac(child) &= ~(DBCR_DAC1R | DBCR_DAC1W);
  1092. #ifdef CONFIG_PPC_ADV_DEBUG_DAC_RANGE
  1093. if (child->thread.dbcr2 & DBCR2_DAC12MODE) {
  1094. child->thread.dac2 = 0;
  1095. child->thread.dbcr2 &= ~DBCR2_DAC12MODE;
  1096. }
  1097. child->thread.dbcr2 &= ~(DBCR2_DVC1M | DBCR2_DVC1BE);
  1098. #endif
  1099. #if CONFIG_PPC_ADV_DEBUG_DVCS > 0
  1100. child->thread.dvc1 = 0;
  1101. #endif
  1102. } else if (slot == 2) {
  1103. if ((dbcr_dac(child) & (DBCR_DAC2R | DBCR_DAC2W)) == 0)
  1104. return -ENOENT;
  1105. #ifdef CONFIG_PPC_ADV_DEBUG_DAC_RANGE
  1106. if (child->thread.dbcr2 & DBCR2_DAC12MODE)
  1107. /* Part of a range */
  1108. return -EINVAL;
  1109. child->thread.dbcr2 &= ~(DBCR2_DVC2M | DBCR2_DVC2BE);
  1110. #endif
  1111. #if CONFIG_PPC_ADV_DEBUG_DVCS > 0
  1112. child->thread.dvc2 = 0;
  1113. #endif
  1114. child->thread.dac2 = 0;
  1115. dbcr_dac(child) &= ~(DBCR_DAC2R | DBCR_DAC2W);
  1116. } else
  1117. return -EINVAL;
  1118. return 0;
  1119. }
  1120. #endif /* CONFIG_PPC_ADV_DEBUG_REGS */
  1121. #ifdef CONFIG_PPC_ADV_DEBUG_DAC_RANGE
  1122. static int set_dac_range(struct task_struct *child,
  1123. struct ppc_hw_breakpoint *bp_info)
  1124. {
  1125. int mode = bp_info->addr_mode & PPC_BREAKPOINT_MODE_MASK;
  1126. /* We don't allow range watchpoints to be used with DVC */
  1127. if (bp_info->condition_mode)
  1128. return -EINVAL;
  1129. /*
  1130. * Best effort to verify the address range. The user/supervisor bits
  1131. * prevent trapping in kernel space, but let's fail on an obvious bad
  1132. * range. The simple test on the mask is not fool-proof, and any
  1133. * exclusive range will spill over into kernel space.
  1134. */
  1135. if (bp_info->addr >= TASK_SIZE)
  1136. return -EIO;
  1137. if (mode == PPC_BREAKPOINT_MODE_MASK) {
  1138. /*
  1139. * dac2 is a bitmask. Don't allow a mask that makes a
  1140. * kernel space address from a valid dac1 value
  1141. */
  1142. if (~((unsigned long)bp_info->addr2) >= TASK_SIZE)
  1143. return -EIO;
  1144. } else {
  1145. /*
  1146. * For range breakpoints, addr2 must also be a valid address
  1147. */
  1148. if (bp_info->addr2 >= TASK_SIZE)
  1149. return -EIO;
  1150. }
  1151. if (child->thread.dbcr0 &
  1152. (DBCR0_DAC1R | DBCR0_DAC1W | DBCR0_DAC2R | DBCR0_DAC2W))
  1153. return -ENOSPC;
  1154. if (bp_info->trigger_type & PPC_BREAKPOINT_TRIGGER_READ)
  1155. child->thread.dbcr0 |= (DBCR0_DAC1R | DBCR0_IDM);
  1156. if (bp_info->trigger_type & PPC_BREAKPOINT_TRIGGER_WRITE)
  1157. child->thread.dbcr0 |= (DBCR0_DAC1W | DBCR0_IDM);
  1158. child->thread.dac1 = bp_info->addr;
  1159. child->thread.dac2 = bp_info->addr2;
  1160. if (mode == PPC_BREAKPOINT_MODE_RANGE_INCLUSIVE)
  1161. child->thread.dbcr2 |= DBCR2_DAC12M;
  1162. else if (mode == PPC_BREAKPOINT_MODE_RANGE_EXCLUSIVE)
  1163. child->thread.dbcr2 |= DBCR2_DAC12MX;
  1164. else /* PPC_BREAKPOINT_MODE_MASK */
  1165. child->thread.dbcr2 |= DBCR2_DAC12MM;
  1166. child->thread.regs->msr |= MSR_DE;
  1167. return 5;
  1168. }
  1169. #endif /* CONFIG_PPC_ADV_DEBUG_DAC_RANGE */
  1170. static long ppc_set_hwdebug(struct task_struct *child,
  1171. struct ppc_hw_breakpoint *bp_info)
  1172. {
  1173. #ifndef CONFIG_PPC_ADV_DEBUG_REGS
  1174. unsigned long dabr;
  1175. #endif
  1176. if (bp_info->version != 1)
  1177. return -ENOTSUPP;
  1178. #ifdef CONFIG_PPC_ADV_DEBUG_REGS
  1179. /*
  1180. * Check for invalid flags and combinations
  1181. */
  1182. if ((bp_info->trigger_type == 0) ||
  1183. (bp_info->trigger_type & ~(PPC_BREAKPOINT_TRIGGER_EXECUTE |
  1184. PPC_BREAKPOINT_TRIGGER_RW)) ||
  1185. (bp_info->addr_mode & ~PPC_BREAKPOINT_MODE_MASK) ||
  1186. (bp_info->condition_mode &
  1187. ~(PPC_BREAKPOINT_CONDITION_MODE |
  1188. PPC_BREAKPOINT_CONDITION_BE_ALL)))
  1189. return -EINVAL;
  1190. #if CONFIG_PPC_ADV_DEBUG_DVCS == 0
  1191. if (bp_info->condition_mode != PPC_BREAKPOINT_CONDITION_NONE)
  1192. return -EINVAL;
  1193. #endif
  1194. if (bp_info->trigger_type & PPC_BREAKPOINT_TRIGGER_EXECUTE) {
  1195. if ((bp_info->trigger_type != PPC_BREAKPOINT_TRIGGER_EXECUTE) ||
  1196. (bp_info->condition_mode != PPC_BREAKPOINT_CONDITION_NONE))
  1197. return -EINVAL;
  1198. return set_intruction_bp(child, bp_info);
  1199. }
  1200. if (bp_info->addr_mode == PPC_BREAKPOINT_MODE_EXACT)
  1201. return set_dac(child, bp_info);
  1202. #ifdef CONFIG_PPC_ADV_DEBUG_DAC_RANGE
  1203. return set_dac_range(child, bp_info);
  1204. #else
  1205. return -EINVAL;
  1206. #endif
  1207. #else /* !CONFIG_PPC_ADV_DEBUG_DVCS */
  1208. /*
  1209. * We only support one data breakpoint
  1210. */
  1211. if ((bp_info->trigger_type & PPC_BREAKPOINT_TRIGGER_RW) == 0 ||
  1212. (bp_info->trigger_type & ~PPC_BREAKPOINT_TRIGGER_RW) != 0 ||
  1213. bp_info->addr_mode != PPC_BREAKPOINT_MODE_EXACT ||
  1214. bp_info->condition_mode != PPC_BREAKPOINT_CONDITION_NONE)
  1215. return -EINVAL;
  1216. if (child->thread.dabr)
  1217. return -ENOSPC;
  1218. if ((unsigned long)bp_info->addr >= TASK_SIZE)
  1219. return -EIO;
  1220. dabr = (unsigned long)bp_info->addr & ~7UL;
  1221. dabr |= DABR_TRANSLATION;
  1222. if (bp_info->trigger_type & PPC_BREAKPOINT_TRIGGER_READ)
  1223. dabr |= DABR_DATA_READ;
  1224. if (bp_info->trigger_type & PPC_BREAKPOINT_TRIGGER_WRITE)
  1225. dabr |= DABR_DATA_WRITE;
  1226. child->thread.dabr = dabr;
  1227. return 1;
  1228. #endif /* !CONFIG_PPC_ADV_DEBUG_DVCS */
  1229. }
  1230. static long ppc_del_hwdebug(struct task_struct *child, long addr, long data)
  1231. {
  1232. #ifdef CONFIG_PPC_ADV_DEBUG_REGS
  1233. int rc;
  1234. if (data <= 4)
  1235. rc = del_instruction_bp(child, (int)data);
  1236. else
  1237. rc = del_dac(child, (int)data - 4);
  1238. if (!rc) {
  1239. if (!DBCR_ACTIVE_EVENTS(child->thread.dbcr0,
  1240. child->thread.dbcr1)) {
  1241. child->thread.dbcr0 &= ~DBCR0_IDM;
  1242. child->thread.regs->msr &= ~MSR_DE;
  1243. }
  1244. }
  1245. return rc;
  1246. #else
  1247. if (data != 1)
  1248. return -EINVAL;
  1249. if (child->thread.dabr == 0)
  1250. return -ENOENT;
  1251. child->thread.dabr = 0;
  1252. return 0;
  1253. #endif
  1254. }
  1255. /*
  1256. * Here are the old "legacy" powerpc specific getregs/setregs ptrace calls,
  1257. * we mark them as obsolete now, they will be removed in a future version
  1258. */
  1259. static long arch_ptrace_old(struct task_struct *child, long request,
  1260. unsigned long addr, unsigned long data)
  1261. {
  1262. void __user *datavp = (void __user *) data;
  1263. switch (request) {
  1264. case PPC_PTRACE_GETREGS: /* Get GPRs 0 - 31. */
  1265. return copy_regset_to_user(child, &user_ppc_native_view,
  1266. REGSET_GPR, 0, 32 * sizeof(long),
  1267. datavp);
  1268. case PPC_PTRACE_SETREGS: /* Set GPRs 0 - 31. */
  1269. return copy_regset_from_user(child, &user_ppc_native_view,
  1270. REGSET_GPR, 0, 32 * sizeof(long),
  1271. datavp);
  1272. case PPC_PTRACE_GETFPREGS: /* Get FPRs 0 - 31. */
  1273. return copy_regset_to_user(child, &user_ppc_native_view,
  1274. REGSET_FPR, 0, 32 * sizeof(double),
  1275. datavp);
  1276. case PPC_PTRACE_SETFPREGS: /* Set FPRs 0 - 31. */
  1277. return copy_regset_from_user(child, &user_ppc_native_view,
  1278. REGSET_FPR, 0, 32 * sizeof(double),
  1279. datavp);
  1280. }
  1281. return -EPERM;
  1282. }
  1283. long arch_ptrace(struct task_struct *child, long request,
  1284. unsigned long addr, unsigned long data)
  1285. {
  1286. int ret = -EPERM;
  1287. void __user *datavp = (void __user *) data;
  1288. unsigned long __user *datalp = datavp;
  1289. switch (request) {
  1290. /* read the word at location addr in the USER area. */
  1291. case PTRACE_PEEKUSR: {
  1292. unsigned long index, tmp;
  1293. ret = -EIO;
  1294. /* convert to index and check */
  1295. #ifdef CONFIG_PPC32
  1296. index = addr >> 2;
  1297. if ((addr & 3) || (index > PT_FPSCR)
  1298. || (child->thread.regs == NULL))
  1299. #else
  1300. index = addr >> 3;
  1301. if ((addr & 7) || (index > PT_FPSCR))
  1302. #endif
  1303. break;
  1304. CHECK_FULL_REGS(child->thread.regs);
  1305. if (index < PT_FPR0) {
  1306. tmp = ptrace_get_reg(child, (int) index);
  1307. } else {
  1308. unsigned int fpidx = index - PT_FPR0;
  1309. flush_fp_to_thread(child);
  1310. if (fpidx < (PT_FPSCR - PT_FPR0))
  1311. tmp = ((unsigned long *)child->thread.fpr)
  1312. [fpidx * TS_FPRWIDTH];
  1313. else
  1314. tmp = child->thread.fpscr.val;
  1315. }
  1316. ret = put_user(tmp, datalp);
  1317. break;
  1318. }
  1319. /* write the word at location addr in the USER area */
  1320. case PTRACE_POKEUSR: {
  1321. unsigned long index;
  1322. ret = -EIO;
  1323. /* convert to index and check */
  1324. #ifdef CONFIG_PPC32
  1325. index = addr >> 2;
  1326. if ((addr & 3) || (index > PT_FPSCR)
  1327. || (child->thread.regs == NULL))
  1328. #else
  1329. index = addr >> 3;
  1330. if ((addr & 7) || (index > PT_FPSCR))
  1331. #endif
  1332. break;
  1333. CHECK_FULL_REGS(child->thread.regs);
  1334. if (index < PT_FPR0) {
  1335. ret = ptrace_put_reg(child, index, data);
  1336. } else {
  1337. unsigned int fpidx = index - PT_FPR0;
  1338. flush_fp_to_thread(child);
  1339. if (fpidx < (PT_FPSCR - PT_FPR0))
  1340. ((unsigned long *)child->thread.fpr)
  1341. [fpidx * TS_FPRWIDTH] = data;
  1342. else
  1343. child->thread.fpscr.val = data;
  1344. ret = 0;
  1345. }
  1346. break;
  1347. }
  1348. case PPC_PTRACE_GETHWDBGINFO: {
  1349. struct ppc_debug_info dbginfo;
  1350. dbginfo.version = 1;
  1351. #ifdef CONFIG_PPC_ADV_DEBUG_REGS
  1352. dbginfo.num_instruction_bps = CONFIG_PPC_ADV_DEBUG_IACS;
  1353. dbginfo.num_data_bps = CONFIG_PPC_ADV_DEBUG_DACS;
  1354. dbginfo.num_condition_regs = CONFIG_PPC_ADV_DEBUG_DVCS;
  1355. dbginfo.data_bp_alignment = 4;
  1356. dbginfo.sizeof_condition = 4;
  1357. dbginfo.features = PPC_DEBUG_FEATURE_INSN_BP_RANGE |
  1358. PPC_DEBUG_FEATURE_INSN_BP_MASK;
  1359. #ifdef CONFIG_PPC_ADV_DEBUG_DAC_RANGE
  1360. dbginfo.features |=
  1361. PPC_DEBUG_FEATURE_DATA_BP_RANGE |
  1362. PPC_DEBUG_FEATURE_DATA_BP_MASK;
  1363. #endif
  1364. #else /* !CONFIG_PPC_ADV_DEBUG_REGS */
  1365. dbginfo.num_instruction_bps = 0;
  1366. dbginfo.num_data_bps = 1;
  1367. dbginfo.num_condition_regs = 0;
  1368. #ifdef CONFIG_PPC64
  1369. dbginfo.data_bp_alignment = 8;
  1370. #else
  1371. dbginfo.data_bp_alignment = 4;
  1372. #endif
  1373. dbginfo.sizeof_condition = 0;
  1374. dbginfo.features = 0;
  1375. #endif /* CONFIG_PPC_ADV_DEBUG_REGS */
  1376. if (!access_ok(VERIFY_WRITE, datavp,
  1377. sizeof(struct ppc_debug_info)))
  1378. return -EFAULT;
  1379. ret = __copy_to_user(datavp, &dbginfo,
  1380. sizeof(struct ppc_debug_info)) ?
  1381. -EFAULT : 0;
  1382. break;
  1383. }
  1384. case PPC_PTRACE_SETHWDEBUG: {
  1385. struct ppc_hw_breakpoint bp_info;
  1386. if (!access_ok(VERIFY_READ, datavp,
  1387. sizeof(struct ppc_hw_breakpoint)))
  1388. return -EFAULT;
  1389. ret = __copy_from_user(&bp_info, datavp,
  1390. sizeof(struct ppc_hw_breakpoint)) ?
  1391. -EFAULT : 0;
  1392. if (!ret)
  1393. ret = ppc_set_hwdebug(child, &bp_info);
  1394. break;
  1395. }
  1396. case PPC_PTRACE_DELHWDEBUG: {
  1397. ret = ppc_del_hwdebug(child, addr, data);
  1398. break;
  1399. }
  1400. case PTRACE_GET_DEBUGREG: {
  1401. ret = -EINVAL;
  1402. /* We only support one DABR and no IABRS at the moment */
  1403. if (addr > 0)
  1404. break;
  1405. #ifdef CONFIG_PPC_ADV_DEBUG_REGS
  1406. ret = put_user(child->thread.dac1, datalp);
  1407. #else
  1408. ret = put_user(child->thread.dabr, datalp);
  1409. #endif
  1410. break;
  1411. }
  1412. case PTRACE_SET_DEBUGREG:
  1413. ret = ptrace_set_debugreg(child, addr, data);
  1414. break;
  1415. #ifdef CONFIG_PPC64
  1416. case PTRACE_GETREGS64:
  1417. #endif
  1418. case PTRACE_GETREGS: /* Get all pt_regs from the child. */
  1419. return copy_regset_to_user(child, &user_ppc_native_view,
  1420. REGSET_GPR,
  1421. 0, sizeof(struct pt_regs),
  1422. datavp);
  1423. #ifdef CONFIG_PPC64
  1424. case PTRACE_SETREGS64:
  1425. #endif
  1426. case PTRACE_SETREGS: /* Set all gp regs in the child. */
  1427. return copy_regset_from_user(child, &user_ppc_native_view,
  1428. REGSET_GPR,
  1429. 0, sizeof(struct pt_regs),
  1430. datavp);
  1431. case PTRACE_GETFPREGS: /* Get the child FPU state (FPR0...31 + FPSCR) */
  1432. return copy_regset_to_user(child, &user_ppc_native_view,
  1433. REGSET_FPR,
  1434. 0, sizeof(elf_fpregset_t),
  1435. datavp);
  1436. case PTRACE_SETFPREGS: /* Set the child FPU state (FPR0...31 + FPSCR) */
  1437. return copy_regset_from_user(child, &user_ppc_native_view,
  1438. REGSET_FPR,
  1439. 0, sizeof(elf_fpregset_t),
  1440. datavp);
  1441. #ifdef CONFIG_ALTIVEC
  1442. case PTRACE_GETVRREGS:
  1443. return copy_regset_to_user(child, &user_ppc_native_view,
  1444. REGSET_VMX,
  1445. 0, (33 * sizeof(vector128) +
  1446. sizeof(u32)),
  1447. datavp);
  1448. case PTRACE_SETVRREGS:
  1449. return copy_regset_from_user(child, &user_ppc_native_view,
  1450. REGSET_VMX,
  1451. 0, (33 * sizeof(vector128) +
  1452. sizeof(u32)),
  1453. datavp);
  1454. #endif
  1455. #ifdef CONFIG_VSX
  1456. case PTRACE_GETVSRREGS:
  1457. return copy_regset_to_user(child, &user_ppc_native_view,
  1458. REGSET_VSX,
  1459. 0, 32 * sizeof(double),
  1460. datavp);
  1461. case PTRACE_SETVSRREGS:
  1462. return copy_regset_from_user(child, &user_ppc_native_view,
  1463. REGSET_VSX,
  1464. 0, 32 * sizeof(double),
  1465. datavp);
  1466. #endif
  1467. #ifdef CONFIG_SPE
  1468. case PTRACE_GETEVRREGS:
  1469. /* Get the child spe register state. */
  1470. return copy_regset_to_user(child, &user_ppc_native_view,
  1471. REGSET_SPE, 0, 35 * sizeof(u32),
  1472. datavp);
  1473. case PTRACE_SETEVRREGS:
  1474. /* Set the child spe register state. */
  1475. return copy_regset_from_user(child, &user_ppc_native_view,
  1476. REGSET_SPE, 0, 35 * sizeof(u32),
  1477. datavp);
  1478. #endif
  1479. /* Old reverse args ptrace callss */
  1480. case PPC_PTRACE_GETREGS: /* Get GPRs 0 - 31. */
  1481. case PPC_PTRACE_SETREGS: /* Set GPRs 0 - 31. */
  1482. case PPC_PTRACE_GETFPREGS: /* Get FPRs 0 - 31. */
  1483. case PPC_PTRACE_SETFPREGS: /* Get FPRs 0 - 31. */
  1484. ret = arch_ptrace_old(child, request, addr, data);
  1485. break;
  1486. default:
  1487. ret = ptrace_request(child, request, addr, data);
  1488. break;
  1489. }
  1490. return ret;
  1491. }
  1492. /*
  1493. * We must return the syscall number to actually look up in the table.
  1494. * This can be -1L to skip running any syscall at all.
  1495. */
  1496. long do_syscall_trace_enter(struct pt_regs *regs)
  1497. {
  1498. long ret = 0;
  1499. secure_computing_strict(regs->gpr[0]);
  1500. if (test_thread_flag(TIF_SYSCALL_TRACE) &&
  1501. tracehook_report_syscall_entry(regs))
  1502. /*
  1503. * Tracing decided this syscall should not happen.
  1504. * We'll return a bogus call number to get an ENOSYS
  1505. * error, but leave the original number in regs->gpr[0].
  1506. */
  1507. ret = -1L;
  1508. if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
  1509. trace_sys_enter(regs, regs->gpr[0]);
  1510. #ifdef CONFIG_PPC64
  1511. if (!is_32bit_task())
  1512. audit_syscall_entry(AUDIT_ARCH_PPC64,
  1513. regs->gpr[0],
  1514. regs->gpr[3], regs->gpr[4],
  1515. regs->gpr[5], regs->gpr[6]);
  1516. else
  1517. #endif
  1518. audit_syscall_entry(AUDIT_ARCH_PPC,
  1519. regs->gpr[0],
  1520. regs->gpr[3] & 0xffffffff,
  1521. regs->gpr[4] & 0xffffffff,
  1522. regs->gpr[5] & 0xffffffff,
  1523. regs->gpr[6] & 0xffffffff);
  1524. return ret ?: regs->gpr[0];
  1525. }
  1526. void do_syscall_trace_leave(struct pt_regs *regs)
  1527. {
  1528. int step;
  1529. audit_syscall_exit(regs);
  1530. if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
  1531. trace_sys_exit(regs, regs->result);
  1532. step = test_thread_flag(TIF_SINGLESTEP);
  1533. if (step || test_thread_flag(TIF_SYSCALL_TRACE))
  1534. tracehook_report_syscall_exit(regs, step);
  1535. }