ptrace.c 45 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754
  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. flush_fp_to_thread(child);
  1312. tmp = ((unsigned long *)child->thread.fpr)
  1313. [TS_FPRWIDTH * (index - PT_FPR0)];
  1314. }
  1315. ret = put_user(tmp, datalp);
  1316. break;
  1317. }
  1318. /* write the word at location addr in the USER area */
  1319. case PTRACE_POKEUSR: {
  1320. unsigned long index;
  1321. ret = -EIO;
  1322. /* convert to index and check */
  1323. #ifdef CONFIG_PPC32
  1324. index = addr >> 2;
  1325. if ((addr & 3) || (index > PT_FPSCR)
  1326. || (child->thread.regs == NULL))
  1327. #else
  1328. index = addr >> 3;
  1329. if ((addr & 7) || (index > PT_FPSCR))
  1330. #endif
  1331. break;
  1332. CHECK_FULL_REGS(child->thread.regs);
  1333. if (index < PT_FPR0) {
  1334. ret = ptrace_put_reg(child, index, data);
  1335. } else {
  1336. flush_fp_to_thread(child);
  1337. ((unsigned long *)child->thread.fpr)
  1338. [TS_FPRWIDTH * (index - PT_FPR0)] = data;
  1339. ret = 0;
  1340. }
  1341. break;
  1342. }
  1343. case PPC_PTRACE_GETHWDBGINFO: {
  1344. struct ppc_debug_info dbginfo;
  1345. dbginfo.version = 1;
  1346. #ifdef CONFIG_PPC_ADV_DEBUG_REGS
  1347. dbginfo.num_instruction_bps = CONFIG_PPC_ADV_DEBUG_IACS;
  1348. dbginfo.num_data_bps = CONFIG_PPC_ADV_DEBUG_DACS;
  1349. dbginfo.num_condition_regs = CONFIG_PPC_ADV_DEBUG_DVCS;
  1350. dbginfo.data_bp_alignment = 4;
  1351. dbginfo.sizeof_condition = 4;
  1352. dbginfo.features = PPC_DEBUG_FEATURE_INSN_BP_RANGE |
  1353. PPC_DEBUG_FEATURE_INSN_BP_MASK;
  1354. #ifdef CONFIG_PPC_ADV_DEBUG_DAC_RANGE
  1355. dbginfo.features |=
  1356. PPC_DEBUG_FEATURE_DATA_BP_RANGE |
  1357. PPC_DEBUG_FEATURE_DATA_BP_MASK;
  1358. #endif
  1359. #else /* !CONFIG_PPC_ADV_DEBUG_REGS */
  1360. dbginfo.num_instruction_bps = 0;
  1361. dbginfo.num_data_bps = 1;
  1362. dbginfo.num_condition_regs = 0;
  1363. #ifdef CONFIG_PPC64
  1364. dbginfo.data_bp_alignment = 8;
  1365. #else
  1366. dbginfo.data_bp_alignment = 4;
  1367. #endif
  1368. dbginfo.sizeof_condition = 0;
  1369. dbginfo.features = 0;
  1370. #endif /* CONFIG_PPC_ADV_DEBUG_REGS */
  1371. if (!access_ok(VERIFY_WRITE, datavp,
  1372. sizeof(struct ppc_debug_info)))
  1373. return -EFAULT;
  1374. ret = __copy_to_user(datavp, &dbginfo,
  1375. sizeof(struct ppc_debug_info)) ?
  1376. -EFAULT : 0;
  1377. break;
  1378. }
  1379. case PPC_PTRACE_SETHWDEBUG: {
  1380. struct ppc_hw_breakpoint bp_info;
  1381. if (!access_ok(VERIFY_READ, datavp,
  1382. sizeof(struct ppc_hw_breakpoint)))
  1383. return -EFAULT;
  1384. ret = __copy_from_user(&bp_info, datavp,
  1385. sizeof(struct ppc_hw_breakpoint)) ?
  1386. -EFAULT : 0;
  1387. if (!ret)
  1388. ret = ppc_set_hwdebug(child, &bp_info);
  1389. break;
  1390. }
  1391. case PPC_PTRACE_DELHWDEBUG: {
  1392. ret = ppc_del_hwdebug(child, addr, data);
  1393. break;
  1394. }
  1395. case PTRACE_GET_DEBUGREG: {
  1396. ret = -EINVAL;
  1397. /* We only support one DABR and no IABRS at the moment */
  1398. if (addr > 0)
  1399. break;
  1400. #ifdef CONFIG_PPC_ADV_DEBUG_REGS
  1401. ret = put_user(child->thread.dac1, datalp);
  1402. #else
  1403. ret = put_user(child->thread.dabr, datalp);
  1404. #endif
  1405. break;
  1406. }
  1407. case PTRACE_SET_DEBUGREG:
  1408. ret = ptrace_set_debugreg(child, addr, data);
  1409. break;
  1410. #ifdef CONFIG_PPC64
  1411. case PTRACE_GETREGS64:
  1412. #endif
  1413. case PTRACE_GETREGS: /* Get all pt_regs from the child. */
  1414. return copy_regset_to_user(child, &user_ppc_native_view,
  1415. REGSET_GPR,
  1416. 0, sizeof(struct pt_regs),
  1417. datavp);
  1418. #ifdef CONFIG_PPC64
  1419. case PTRACE_SETREGS64:
  1420. #endif
  1421. case PTRACE_SETREGS: /* Set all gp regs in the child. */
  1422. return copy_regset_from_user(child, &user_ppc_native_view,
  1423. REGSET_GPR,
  1424. 0, sizeof(struct pt_regs),
  1425. datavp);
  1426. case PTRACE_GETFPREGS: /* Get the child FPU state (FPR0...31 + FPSCR) */
  1427. return copy_regset_to_user(child, &user_ppc_native_view,
  1428. REGSET_FPR,
  1429. 0, sizeof(elf_fpregset_t),
  1430. datavp);
  1431. case PTRACE_SETFPREGS: /* Set the child FPU state (FPR0...31 + FPSCR) */
  1432. return copy_regset_from_user(child, &user_ppc_native_view,
  1433. REGSET_FPR,
  1434. 0, sizeof(elf_fpregset_t),
  1435. datavp);
  1436. #ifdef CONFIG_ALTIVEC
  1437. case PTRACE_GETVRREGS:
  1438. return copy_regset_to_user(child, &user_ppc_native_view,
  1439. REGSET_VMX,
  1440. 0, (33 * sizeof(vector128) +
  1441. sizeof(u32)),
  1442. datavp);
  1443. case PTRACE_SETVRREGS:
  1444. return copy_regset_from_user(child, &user_ppc_native_view,
  1445. REGSET_VMX,
  1446. 0, (33 * sizeof(vector128) +
  1447. sizeof(u32)),
  1448. datavp);
  1449. #endif
  1450. #ifdef CONFIG_VSX
  1451. case PTRACE_GETVSRREGS:
  1452. return copy_regset_to_user(child, &user_ppc_native_view,
  1453. REGSET_VSX,
  1454. 0, 32 * sizeof(double),
  1455. datavp);
  1456. case PTRACE_SETVSRREGS:
  1457. return copy_regset_from_user(child, &user_ppc_native_view,
  1458. REGSET_VSX,
  1459. 0, 32 * sizeof(double),
  1460. datavp);
  1461. #endif
  1462. #ifdef CONFIG_SPE
  1463. case PTRACE_GETEVRREGS:
  1464. /* Get the child spe register state. */
  1465. return copy_regset_to_user(child, &user_ppc_native_view,
  1466. REGSET_SPE, 0, 35 * sizeof(u32),
  1467. datavp);
  1468. case PTRACE_SETEVRREGS:
  1469. /* Set the child spe register state. */
  1470. return copy_regset_from_user(child, &user_ppc_native_view,
  1471. REGSET_SPE, 0, 35 * sizeof(u32),
  1472. datavp);
  1473. #endif
  1474. /* Old reverse args ptrace callss */
  1475. case PPC_PTRACE_GETREGS: /* Get GPRs 0 - 31. */
  1476. case PPC_PTRACE_SETREGS: /* Set GPRs 0 - 31. */
  1477. case PPC_PTRACE_GETFPREGS: /* Get FPRs 0 - 31. */
  1478. case PPC_PTRACE_SETFPREGS: /* Get FPRs 0 - 31. */
  1479. ret = arch_ptrace_old(child, request, addr, data);
  1480. break;
  1481. default:
  1482. ret = ptrace_request(child, request, addr, data);
  1483. break;
  1484. }
  1485. return ret;
  1486. }
  1487. /*
  1488. * We must return the syscall number to actually look up in the table.
  1489. * This can be -1L to skip running any syscall at all.
  1490. */
  1491. long do_syscall_trace_enter(struct pt_regs *regs)
  1492. {
  1493. long ret = 0;
  1494. secure_computing(regs->gpr[0]);
  1495. if (test_thread_flag(TIF_SYSCALL_TRACE) &&
  1496. tracehook_report_syscall_entry(regs))
  1497. /*
  1498. * Tracing decided this syscall should not happen.
  1499. * We'll return a bogus call number to get an ENOSYS
  1500. * error, but leave the original number in regs->gpr[0].
  1501. */
  1502. ret = -1L;
  1503. if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
  1504. trace_sys_enter(regs, regs->gpr[0]);
  1505. if (unlikely(current->audit_context)) {
  1506. #ifdef CONFIG_PPC64
  1507. if (!is_32bit_task())
  1508. audit_syscall_entry(AUDIT_ARCH_PPC64,
  1509. regs->gpr[0],
  1510. regs->gpr[3], regs->gpr[4],
  1511. regs->gpr[5], regs->gpr[6]);
  1512. else
  1513. #endif
  1514. audit_syscall_entry(AUDIT_ARCH_PPC,
  1515. regs->gpr[0],
  1516. regs->gpr[3] & 0xffffffff,
  1517. regs->gpr[4] & 0xffffffff,
  1518. regs->gpr[5] & 0xffffffff,
  1519. regs->gpr[6] & 0xffffffff);
  1520. }
  1521. return ret ?: regs->gpr[0];
  1522. }
  1523. void do_syscall_trace_leave(struct pt_regs *regs)
  1524. {
  1525. int step;
  1526. if (unlikely(current->audit_context))
  1527. audit_syscall_exit((regs->ccr&0x10000000)?AUDITSC_FAILURE:AUDITSC_SUCCESS,
  1528. regs->result);
  1529. if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
  1530. trace_sys_exit(regs, regs->result);
  1531. step = test_thread_flag(TIF_SINGLESTEP);
  1532. if (step || test_thread_flag(TIF_SYSCALL_TRACE))
  1533. tracehook_report_syscall_exit(regs, step);
  1534. }