ptrace.c 45 KB

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