ptrace.c 32 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325
  1. /*
  2. * This file is subject to the terms and conditions of the GNU General Public
  3. * License. See the file "COPYING" in the main directory of this archive
  4. * for more details.
  5. *
  6. * Copyright (C) 1992 Ross Biro
  7. * Copyright (C) Linus Torvalds
  8. * Copyright (C) 1994, 95, 96, 97, 98, 2000 Ralf Baechle
  9. * Copyright (C) 1996 David S. Miller
  10. * Kevin D. Kissell, kevink@mips.com and Carsten Langgaard, carstenl@mips.com
  11. * Copyright (C) 1999 MIPS Technologies, Inc.
  12. * Copyright (C) 2000 Ulf Carlsson
  13. *
  14. * At this time Linux/MIPS64 only supports syscall tracing, even for 32-bit
  15. * binaries.
  16. */
  17. #include <linux/compiler.h>
  18. #include <linux/context_tracking.h>
  19. #include <linux/elf.h>
  20. #include <linux/kernel.h>
  21. #include <linux/sched.h>
  22. #include <linux/sched/task_stack.h>
  23. #include <linux/mm.h>
  24. #include <linux/errno.h>
  25. #include <linux/ptrace.h>
  26. #include <linux/regset.h>
  27. #include <linux/smp.h>
  28. #include <linux/security.h>
  29. #include <linux/stddef.h>
  30. #include <linux/tracehook.h>
  31. #include <linux/audit.h>
  32. #include <linux/seccomp.h>
  33. #include <linux/ftrace.h>
  34. #include <asm/byteorder.h>
  35. #include <asm/cpu.h>
  36. #include <asm/cpu-info.h>
  37. #include <asm/dsp.h>
  38. #include <asm/fpu.h>
  39. #include <asm/mipsregs.h>
  40. #include <asm/mipsmtregs.h>
  41. #include <asm/pgtable.h>
  42. #include <asm/page.h>
  43. #include <asm/processor.h>
  44. #include <asm/syscall.h>
  45. #include <linux/uaccess.h>
  46. #include <asm/bootinfo.h>
  47. #include <asm/reg.h>
  48. #define CREATE_TRACE_POINTS
  49. #include <trace/events/syscalls.h>
  50. static void init_fp_ctx(struct task_struct *target)
  51. {
  52. /* If FP has been used then the target already has context */
  53. if (tsk_used_math(target))
  54. return;
  55. /* Begin with data registers set to all 1s... */
  56. memset(&target->thread.fpu.fpr, ~0, sizeof(target->thread.fpu.fpr));
  57. /* FCSR has been preset by `mips_set_personality_nan'. */
  58. /*
  59. * Record that the target has "used" math, such that the context
  60. * just initialised, and any modifications made by the caller,
  61. * aren't discarded.
  62. */
  63. set_stopped_child_used_math(target);
  64. }
  65. /*
  66. * Called by kernel/ptrace.c when detaching..
  67. *
  68. * Make sure single step bits etc are not set.
  69. */
  70. void ptrace_disable(struct task_struct *child)
  71. {
  72. /* Don't load the watchpoint registers for the ex-child. */
  73. clear_tsk_thread_flag(child, TIF_LOAD_WATCH);
  74. }
  75. /*
  76. * Poke at FCSR according to its mask. Set the Cause bits even
  77. * if a corresponding Enable bit is set. This will be noticed at
  78. * the time the thread is switched to and SIGFPE thrown accordingly.
  79. */
  80. static void ptrace_setfcr31(struct task_struct *child, u32 value)
  81. {
  82. u32 fcr31;
  83. u32 mask;
  84. fcr31 = child->thread.fpu.fcr31;
  85. mask = boot_cpu_data.fpu_msk31;
  86. child->thread.fpu.fcr31 = (value & ~mask) | (fcr31 & mask);
  87. }
  88. /*
  89. * Read a general register set. We always use the 64-bit format, even
  90. * for 32-bit kernels and for 32-bit processes on a 64-bit kernel.
  91. * Registers are sign extended to fill the available space.
  92. */
  93. int ptrace_getregs(struct task_struct *child, struct user_pt_regs __user *data)
  94. {
  95. struct pt_regs *regs;
  96. int i;
  97. if (!access_ok(VERIFY_WRITE, data, 38 * 8))
  98. return -EIO;
  99. regs = task_pt_regs(child);
  100. for (i = 0; i < 32; i++)
  101. __put_user((long)regs->regs[i], (__s64 __user *)&data->regs[i]);
  102. __put_user((long)regs->lo, (__s64 __user *)&data->lo);
  103. __put_user((long)regs->hi, (__s64 __user *)&data->hi);
  104. __put_user((long)regs->cp0_epc, (__s64 __user *)&data->cp0_epc);
  105. __put_user((long)regs->cp0_badvaddr, (__s64 __user *)&data->cp0_badvaddr);
  106. __put_user((long)regs->cp0_status, (__s64 __user *)&data->cp0_status);
  107. __put_user((long)regs->cp0_cause, (__s64 __user *)&data->cp0_cause);
  108. return 0;
  109. }
  110. /*
  111. * Write a general register set. As for PTRACE_GETREGS, we always use
  112. * the 64-bit format. On a 32-bit kernel only the lower order half
  113. * (according to endianness) will be used.
  114. */
  115. int ptrace_setregs(struct task_struct *child, struct user_pt_regs __user *data)
  116. {
  117. struct pt_regs *regs;
  118. int i;
  119. if (!access_ok(VERIFY_READ, data, 38 * 8))
  120. return -EIO;
  121. regs = task_pt_regs(child);
  122. for (i = 0; i < 32; i++)
  123. __get_user(regs->regs[i], (__s64 __user *)&data->regs[i]);
  124. __get_user(regs->lo, (__s64 __user *)&data->lo);
  125. __get_user(regs->hi, (__s64 __user *)&data->hi);
  126. __get_user(regs->cp0_epc, (__s64 __user *)&data->cp0_epc);
  127. /* badvaddr, status, and cause may not be written. */
  128. /* System call number may have been changed */
  129. mips_syscall_update_nr(child, regs);
  130. return 0;
  131. }
  132. int ptrace_getfpregs(struct task_struct *child, __u32 __user *data)
  133. {
  134. int i;
  135. if (!access_ok(VERIFY_WRITE, data, 33 * 8))
  136. return -EIO;
  137. if (tsk_used_math(child)) {
  138. union fpureg *fregs = get_fpu_regs(child);
  139. for (i = 0; i < 32; i++)
  140. __put_user(get_fpr64(&fregs[i], 0),
  141. i + (__u64 __user *)data);
  142. } else {
  143. for (i = 0; i < 32; i++)
  144. __put_user((__u64) -1, i + (__u64 __user *) data);
  145. }
  146. __put_user(child->thread.fpu.fcr31, data + 64);
  147. __put_user(boot_cpu_data.fpu_id, data + 65);
  148. return 0;
  149. }
  150. int ptrace_setfpregs(struct task_struct *child, __u32 __user *data)
  151. {
  152. union fpureg *fregs;
  153. u64 fpr_val;
  154. u32 value;
  155. int i;
  156. if (!access_ok(VERIFY_READ, data, 33 * 8))
  157. return -EIO;
  158. init_fp_ctx(child);
  159. fregs = get_fpu_regs(child);
  160. for (i = 0; i < 32; i++) {
  161. __get_user(fpr_val, i + (__u64 __user *)data);
  162. set_fpr64(&fregs[i], 0, fpr_val);
  163. }
  164. __get_user(value, data + 64);
  165. ptrace_setfcr31(child, value);
  166. /* FIR may not be written. */
  167. return 0;
  168. }
  169. int ptrace_get_watch_regs(struct task_struct *child,
  170. struct pt_watch_regs __user *addr)
  171. {
  172. enum pt_watch_style style;
  173. int i;
  174. if (!cpu_has_watch || boot_cpu_data.watch_reg_use_cnt == 0)
  175. return -EIO;
  176. if (!access_ok(VERIFY_WRITE, addr, sizeof(struct pt_watch_regs)))
  177. return -EIO;
  178. #ifdef CONFIG_32BIT
  179. style = pt_watch_style_mips32;
  180. #define WATCH_STYLE mips32
  181. #else
  182. style = pt_watch_style_mips64;
  183. #define WATCH_STYLE mips64
  184. #endif
  185. __put_user(style, &addr->style);
  186. __put_user(boot_cpu_data.watch_reg_use_cnt,
  187. &addr->WATCH_STYLE.num_valid);
  188. for (i = 0; i < boot_cpu_data.watch_reg_use_cnt; i++) {
  189. __put_user(child->thread.watch.mips3264.watchlo[i],
  190. &addr->WATCH_STYLE.watchlo[i]);
  191. __put_user(child->thread.watch.mips3264.watchhi[i] &
  192. (MIPS_WATCHHI_MASK | MIPS_WATCHHI_IRW),
  193. &addr->WATCH_STYLE.watchhi[i]);
  194. __put_user(boot_cpu_data.watch_reg_masks[i],
  195. &addr->WATCH_STYLE.watch_masks[i]);
  196. }
  197. for (; i < 8; i++) {
  198. __put_user(0, &addr->WATCH_STYLE.watchlo[i]);
  199. __put_user(0, &addr->WATCH_STYLE.watchhi[i]);
  200. __put_user(0, &addr->WATCH_STYLE.watch_masks[i]);
  201. }
  202. return 0;
  203. }
  204. int ptrace_set_watch_regs(struct task_struct *child,
  205. struct pt_watch_regs __user *addr)
  206. {
  207. int i;
  208. int watch_active = 0;
  209. unsigned long lt[NUM_WATCH_REGS];
  210. u16 ht[NUM_WATCH_REGS];
  211. if (!cpu_has_watch || boot_cpu_data.watch_reg_use_cnt == 0)
  212. return -EIO;
  213. if (!access_ok(VERIFY_READ, addr, sizeof(struct pt_watch_regs)))
  214. return -EIO;
  215. /* Check the values. */
  216. for (i = 0; i < boot_cpu_data.watch_reg_use_cnt; i++) {
  217. __get_user(lt[i], &addr->WATCH_STYLE.watchlo[i]);
  218. #ifdef CONFIG_32BIT
  219. if (lt[i] & __UA_LIMIT)
  220. return -EINVAL;
  221. #else
  222. if (test_tsk_thread_flag(child, TIF_32BIT_ADDR)) {
  223. if (lt[i] & 0xffffffff80000000UL)
  224. return -EINVAL;
  225. } else {
  226. if (lt[i] & __UA_LIMIT)
  227. return -EINVAL;
  228. }
  229. #endif
  230. __get_user(ht[i], &addr->WATCH_STYLE.watchhi[i]);
  231. if (ht[i] & ~MIPS_WATCHHI_MASK)
  232. return -EINVAL;
  233. }
  234. /* Install them. */
  235. for (i = 0; i < boot_cpu_data.watch_reg_use_cnt; i++) {
  236. if (lt[i] & MIPS_WATCHLO_IRW)
  237. watch_active = 1;
  238. child->thread.watch.mips3264.watchlo[i] = lt[i];
  239. /* Set the G bit. */
  240. child->thread.watch.mips3264.watchhi[i] = ht[i];
  241. }
  242. if (watch_active)
  243. set_tsk_thread_flag(child, TIF_LOAD_WATCH);
  244. else
  245. clear_tsk_thread_flag(child, TIF_LOAD_WATCH);
  246. return 0;
  247. }
  248. /* regset get/set implementations */
  249. #if defined(CONFIG_32BIT) || defined(CONFIG_MIPS32_O32)
  250. static int gpr32_get(struct task_struct *target,
  251. const struct user_regset *regset,
  252. unsigned int pos, unsigned int count,
  253. void *kbuf, void __user *ubuf)
  254. {
  255. struct pt_regs *regs = task_pt_regs(target);
  256. u32 uregs[ELF_NGREG] = {};
  257. mips_dump_regs32(uregs, regs);
  258. return user_regset_copyout(&pos, &count, &kbuf, &ubuf, uregs, 0,
  259. sizeof(uregs));
  260. }
  261. static int gpr32_set(struct task_struct *target,
  262. const struct user_regset *regset,
  263. unsigned int pos, unsigned int count,
  264. const void *kbuf, const void __user *ubuf)
  265. {
  266. struct pt_regs *regs = task_pt_regs(target);
  267. u32 uregs[ELF_NGREG];
  268. unsigned start, num_regs, i;
  269. int err;
  270. start = pos / sizeof(u32);
  271. num_regs = count / sizeof(u32);
  272. if (start + num_regs > ELF_NGREG)
  273. return -EIO;
  274. err = user_regset_copyin(&pos, &count, &kbuf, &ubuf, uregs, 0,
  275. sizeof(uregs));
  276. if (err)
  277. return err;
  278. for (i = start; i < num_regs; i++) {
  279. /*
  280. * Cast all values to signed here so that if this is a 64-bit
  281. * kernel, the supplied 32-bit values will be sign extended.
  282. */
  283. switch (i) {
  284. case MIPS32_EF_R1 ... MIPS32_EF_R25:
  285. /* k0/k1 are ignored. */
  286. case MIPS32_EF_R28 ... MIPS32_EF_R31:
  287. regs->regs[i - MIPS32_EF_R0] = (s32)uregs[i];
  288. break;
  289. case MIPS32_EF_LO:
  290. regs->lo = (s32)uregs[i];
  291. break;
  292. case MIPS32_EF_HI:
  293. regs->hi = (s32)uregs[i];
  294. break;
  295. case MIPS32_EF_CP0_EPC:
  296. regs->cp0_epc = (s32)uregs[i];
  297. break;
  298. }
  299. }
  300. /* System call number may have been changed */
  301. mips_syscall_update_nr(target, regs);
  302. return 0;
  303. }
  304. #endif /* CONFIG_32BIT || CONFIG_MIPS32_O32 */
  305. #ifdef CONFIG_64BIT
  306. static int gpr64_get(struct task_struct *target,
  307. const struct user_regset *regset,
  308. unsigned int pos, unsigned int count,
  309. void *kbuf, void __user *ubuf)
  310. {
  311. struct pt_regs *regs = task_pt_regs(target);
  312. u64 uregs[ELF_NGREG] = {};
  313. mips_dump_regs64(uregs, regs);
  314. return user_regset_copyout(&pos, &count, &kbuf, &ubuf, uregs, 0,
  315. sizeof(uregs));
  316. }
  317. static int gpr64_set(struct task_struct *target,
  318. const struct user_regset *regset,
  319. unsigned int pos, unsigned int count,
  320. const void *kbuf, const void __user *ubuf)
  321. {
  322. struct pt_regs *regs = task_pt_regs(target);
  323. u64 uregs[ELF_NGREG];
  324. unsigned start, num_regs, i;
  325. int err;
  326. start = pos / sizeof(u64);
  327. num_regs = count / sizeof(u64);
  328. if (start + num_regs > ELF_NGREG)
  329. return -EIO;
  330. err = user_regset_copyin(&pos, &count, &kbuf, &ubuf, uregs, 0,
  331. sizeof(uregs));
  332. if (err)
  333. return err;
  334. for (i = start; i < num_regs; i++) {
  335. switch (i) {
  336. case MIPS64_EF_R1 ... MIPS64_EF_R25:
  337. /* k0/k1 are ignored. */
  338. case MIPS64_EF_R28 ... MIPS64_EF_R31:
  339. regs->regs[i - MIPS64_EF_R0] = uregs[i];
  340. break;
  341. case MIPS64_EF_LO:
  342. regs->lo = uregs[i];
  343. break;
  344. case MIPS64_EF_HI:
  345. regs->hi = uregs[i];
  346. break;
  347. case MIPS64_EF_CP0_EPC:
  348. regs->cp0_epc = uregs[i];
  349. break;
  350. }
  351. }
  352. /* System call number may have been changed */
  353. mips_syscall_update_nr(target, regs);
  354. return 0;
  355. }
  356. #endif /* CONFIG_64BIT */
  357. /*
  358. * Copy the floating-point context to the supplied NT_PRFPREG buffer,
  359. * !CONFIG_CPU_HAS_MSA variant. FP context's general register slots
  360. * correspond 1:1 to buffer slots. Only general registers are copied.
  361. */
  362. static int fpr_get_fpa(struct task_struct *target,
  363. unsigned int *pos, unsigned int *count,
  364. void **kbuf, void __user **ubuf)
  365. {
  366. return user_regset_copyout(pos, count, kbuf, ubuf,
  367. &target->thread.fpu,
  368. 0, NUM_FPU_REGS * sizeof(elf_fpreg_t));
  369. }
  370. /*
  371. * Copy the floating-point context to the supplied NT_PRFPREG buffer,
  372. * CONFIG_CPU_HAS_MSA variant. Only lower 64 bits of FP context's
  373. * general register slots are copied to buffer slots. Only general
  374. * registers are copied.
  375. */
  376. static int fpr_get_msa(struct task_struct *target,
  377. unsigned int *pos, unsigned int *count,
  378. void **kbuf, void __user **ubuf)
  379. {
  380. unsigned int i;
  381. u64 fpr_val;
  382. int err;
  383. BUILD_BUG_ON(sizeof(fpr_val) != sizeof(elf_fpreg_t));
  384. for (i = 0; i < NUM_FPU_REGS; i++) {
  385. fpr_val = get_fpr64(&target->thread.fpu.fpr[i], 0);
  386. err = user_regset_copyout(pos, count, kbuf, ubuf,
  387. &fpr_val, i * sizeof(elf_fpreg_t),
  388. (i + 1) * sizeof(elf_fpreg_t));
  389. if (err)
  390. return err;
  391. }
  392. return 0;
  393. }
  394. /*
  395. * Copy the floating-point context to the supplied NT_PRFPREG buffer.
  396. * Choose the appropriate helper for general registers, and then copy
  397. * the FCSR and FIR registers separately.
  398. */
  399. static int fpr_get(struct task_struct *target,
  400. const struct user_regset *regset,
  401. unsigned int pos, unsigned int count,
  402. void *kbuf, void __user *ubuf)
  403. {
  404. const int fcr31_pos = NUM_FPU_REGS * sizeof(elf_fpreg_t);
  405. const int fir_pos = fcr31_pos + sizeof(u32);
  406. int err;
  407. if (sizeof(target->thread.fpu.fpr[0]) == sizeof(elf_fpreg_t))
  408. err = fpr_get_fpa(target, &pos, &count, &kbuf, &ubuf);
  409. else
  410. err = fpr_get_msa(target, &pos, &count, &kbuf, &ubuf);
  411. if (err)
  412. return err;
  413. err = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
  414. &target->thread.fpu.fcr31,
  415. fcr31_pos, fcr31_pos + sizeof(u32));
  416. if (err)
  417. return err;
  418. err = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
  419. &boot_cpu_data.fpu_id,
  420. fir_pos, fir_pos + sizeof(u32));
  421. return err;
  422. }
  423. /*
  424. * Copy the supplied NT_PRFPREG buffer to the floating-point context,
  425. * !CONFIG_CPU_HAS_MSA variant. Buffer slots correspond 1:1 to FP
  426. * context's general register slots. Only general registers are copied.
  427. */
  428. static int fpr_set_fpa(struct task_struct *target,
  429. unsigned int *pos, unsigned int *count,
  430. const void **kbuf, const void __user **ubuf)
  431. {
  432. return user_regset_copyin(pos, count, kbuf, ubuf,
  433. &target->thread.fpu,
  434. 0, NUM_FPU_REGS * sizeof(elf_fpreg_t));
  435. }
  436. /*
  437. * Copy the supplied NT_PRFPREG buffer to the floating-point context,
  438. * CONFIG_CPU_HAS_MSA variant. Buffer slots are copied to lower 64
  439. * bits only of FP context's general register slots. Only general
  440. * registers are copied.
  441. */
  442. static int fpr_set_msa(struct task_struct *target,
  443. unsigned int *pos, unsigned int *count,
  444. const void **kbuf, const void __user **ubuf)
  445. {
  446. unsigned int i;
  447. u64 fpr_val;
  448. int err;
  449. BUILD_BUG_ON(sizeof(fpr_val) != sizeof(elf_fpreg_t));
  450. for (i = 0; i < NUM_FPU_REGS && *count > 0; i++) {
  451. err = user_regset_copyin(pos, count, kbuf, ubuf,
  452. &fpr_val, i * sizeof(elf_fpreg_t),
  453. (i + 1) * sizeof(elf_fpreg_t));
  454. if (err)
  455. return err;
  456. set_fpr64(&target->thread.fpu.fpr[i], 0, fpr_val);
  457. }
  458. return 0;
  459. }
  460. /*
  461. * Copy the supplied NT_PRFPREG buffer to the floating-point context.
  462. * Choose the appropriate helper for general registers, and then copy
  463. * the FCSR register separately. Ignore the incoming FIR register
  464. * contents though, as the register is read-only.
  465. *
  466. * We optimize for the case where `count % sizeof(elf_fpreg_t) == 0',
  467. * which is supposed to have been guaranteed by the kernel before
  468. * calling us, e.g. in `ptrace_regset'. We enforce that requirement,
  469. * so that we can safely avoid preinitializing temporaries for
  470. * partial register writes.
  471. */
  472. static int fpr_set(struct task_struct *target,
  473. const struct user_regset *regset,
  474. unsigned int pos, unsigned int count,
  475. const void *kbuf, const void __user *ubuf)
  476. {
  477. const int fcr31_pos = NUM_FPU_REGS * sizeof(elf_fpreg_t);
  478. const int fir_pos = fcr31_pos + sizeof(u32);
  479. u32 fcr31;
  480. int err;
  481. BUG_ON(count % sizeof(elf_fpreg_t));
  482. if (pos + count > sizeof(elf_fpregset_t))
  483. return -EIO;
  484. init_fp_ctx(target);
  485. if (sizeof(target->thread.fpu.fpr[0]) == sizeof(elf_fpreg_t))
  486. err = fpr_set_fpa(target, &pos, &count, &kbuf, &ubuf);
  487. else
  488. err = fpr_set_msa(target, &pos, &count, &kbuf, &ubuf);
  489. if (err)
  490. return err;
  491. if (count > 0) {
  492. err = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
  493. &fcr31,
  494. fcr31_pos, fcr31_pos + sizeof(u32));
  495. if (err)
  496. return err;
  497. ptrace_setfcr31(target, fcr31);
  498. }
  499. if (count > 0)
  500. err = user_regset_copyin_ignore(&pos, &count, &kbuf, &ubuf,
  501. fir_pos,
  502. fir_pos + sizeof(u32));
  503. return err;
  504. }
  505. #if defined(CONFIG_32BIT) || defined(CONFIG_MIPS32_O32)
  506. /*
  507. * Copy the DSP context to the supplied 32-bit NT_MIPS_DSP buffer.
  508. */
  509. static int dsp32_get(struct task_struct *target,
  510. const struct user_regset *regset,
  511. unsigned int pos, unsigned int count,
  512. void *kbuf, void __user *ubuf)
  513. {
  514. unsigned int start, num_regs, i;
  515. u32 dspregs[NUM_DSP_REGS + 1];
  516. BUG_ON(count % sizeof(u32));
  517. if (!cpu_has_dsp)
  518. return -EIO;
  519. start = pos / sizeof(u32);
  520. num_regs = count / sizeof(u32);
  521. if (start + num_regs > NUM_DSP_REGS + 1)
  522. return -EIO;
  523. for (i = start; i < num_regs; i++)
  524. switch (i) {
  525. case 0 ... NUM_DSP_REGS - 1:
  526. dspregs[i] = target->thread.dsp.dspr[i];
  527. break;
  528. case NUM_DSP_REGS:
  529. dspregs[i] = target->thread.dsp.dspcontrol;
  530. break;
  531. }
  532. return user_regset_copyout(&pos, &count, &kbuf, &ubuf, dspregs, 0,
  533. sizeof(dspregs));
  534. }
  535. /*
  536. * Copy the supplied 32-bit NT_MIPS_DSP buffer to the DSP context.
  537. */
  538. static int dsp32_set(struct task_struct *target,
  539. const struct user_regset *regset,
  540. unsigned int pos, unsigned int count,
  541. const void *kbuf, const void __user *ubuf)
  542. {
  543. unsigned int start, num_regs, i;
  544. u32 dspregs[NUM_DSP_REGS + 1];
  545. int err;
  546. BUG_ON(count % sizeof(u32));
  547. if (!cpu_has_dsp)
  548. return -EIO;
  549. start = pos / sizeof(u32);
  550. num_regs = count / sizeof(u32);
  551. if (start + num_regs > NUM_DSP_REGS + 1)
  552. return -EIO;
  553. err = user_regset_copyin(&pos, &count, &kbuf, &ubuf, dspregs, 0,
  554. sizeof(dspregs));
  555. if (err)
  556. return err;
  557. for (i = start; i < num_regs; i++)
  558. switch (i) {
  559. case 0 ... NUM_DSP_REGS - 1:
  560. target->thread.dsp.dspr[i] = (s32)dspregs[i];
  561. break;
  562. case NUM_DSP_REGS:
  563. target->thread.dsp.dspcontrol = (s32)dspregs[i];
  564. break;
  565. }
  566. return 0;
  567. }
  568. #endif /* CONFIG_32BIT || CONFIG_MIPS32_O32 */
  569. #ifdef CONFIG_64BIT
  570. /*
  571. * Copy the DSP context to the supplied 64-bit NT_MIPS_DSP buffer.
  572. */
  573. static int dsp64_get(struct task_struct *target,
  574. const struct user_regset *regset,
  575. unsigned int pos, unsigned int count,
  576. void *kbuf, void __user *ubuf)
  577. {
  578. unsigned int start, num_regs, i;
  579. u64 dspregs[NUM_DSP_REGS + 1];
  580. BUG_ON(count % sizeof(u64));
  581. if (!cpu_has_dsp)
  582. return -EIO;
  583. start = pos / sizeof(u64);
  584. num_regs = count / sizeof(u64);
  585. if (start + num_regs > NUM_DSP_REGS + 1)
  586. return -EIO;
  587. for (i = start; i < num_regs; i++)
  588. switch (i) {
  589. case 0 ... NUM_DSP_REGS - 1:
  590. dspregs[i] = target->thread.dsp.dspr[i];
  591. break;
  592. case NUM_DSP_REGS:
  593. dspregs[i] = target->thread.dsp.dspcontrol;
  594. break;
  595. }
  596. return user_regset_copyout(&pos, &count, &kbuf, &ubuf, dspregs, 0,
  597. sizeof(dspregs));
  598. }
  599. /*
  600. * Copy the supplied 64-bit NT_MIPS_DSP buffer to the DSP context.
  601. */
  602. static int dsp64_set(struct task_struct *target,
  603. const struct user_regset *regset,
  604. unsigned int pos, unsigned int count,
  605. const void *kbuf, const void __user *ubuf)
  606. {
  607. unsigned int start, num_regs, i;
  608. u64 dspregs[NUM_DSP_REGS + 1];
  609. int err;
  610. BUG_ON(count % sizeof(u64));
  611. if (!cpu_has_dsp)
  612. return -EIO;
  613. start = pos / sizeof(u64);
  614. num_regs = count / sizeof(u64);
  615. if (start + num_regs > NUM_DSP_REGS + 1)
  616. return -EIO;
  617. err = user_regset_copyin(&pos, &count, &kbuf, &ubuf, dspregs, 0,
  618. sizeof(dspregs));
  619. if (err)
  620. return err;
  621. for (i = start; i < num_regs; i++)
  622. switch (i) {
  623. case 0 ... NUM_DSP_REGS - 1:
  624. target->thread.dsp.dspr[i] = dspregs[i];
  625. break;
  626. case NUM_DSP_REGS:
  627. target->thread.dsp.dspcontrol = dspregs[i];
  628. break;
  629. }
  630. return 0;
  631. }
  632. #endif /* CONFIG_64BIT */
  633. /*
  634. * Determine whether the DSP context is present.
  635. */
  636. static int dsp_active(struct task_struct *target,
  637. const struct user_regset *regset)
  638. {
  639. return cpu_has_dsp ? NUM_DSP_REGS + 1 : -ENODEV;
  640. }
  641. /* Copy the FP mode setting to the supplied NT_MIPS_FP_MODE buffer. */
  642. static int fp_mode_get(struct task_struct *target,
  643. const struct user_regset *regset,
  644. unsigned int pos, unsigned int count,
  645. void *kbuf, void __user *ubuf)
  646. {
  647. int fp_mode;
  648. fp_mode = mips_get_process_fp_mode(target);
  649. return user_regset_copyout(&pos, &count, &kbuf, &ubuf, &fp_mode, 0,
  650. sizeof(fp_mode));
  651. }
  652. /*
  653. * Copy the supplied NT_MIPS_FP_MODE buffer to the FP mode setting.
  654. *
  655. * We optimize for the case where `count % sizeof(int) == 0', which
  656. * is supposed to have been guaranteed by the kernel before calling
  657. * us, e.g. in `ptrace_regset'. We enforce that requirement, so
  658. * that we can safely avoid preinitializing temporaries for partial
  659. * mode writes.
  660. */
  661. static int fp_mode_set(struct task_struct *target,
  662. const struct user_regset *regset,
  663. unsigned int pos, unsigned int count,
  664. const void *kbuf, const void __user *ubuf)
  665. {
  666. int fp_mode;
  667. int err;
  668. BUG_ON(count % sizeof(int));
  669. if (pos + count > sizeof(fp_mode))
  670. return -EIO;
  671. err = user_regset_copyin(&pos, &count, &kbuf, &ubuf, &fp_mode, 0,
  672. sizeof(fp_mode));
  673. if (err)
  674. return err;
  675. if (count > 0)
  676. err = mips_set_process_fp_mode(target, fp_mode);
  677. return err;
  678. }
  679. enum mips_regset {
  680. REGSET_GPR,
  681. REGSET_FPR,
  682. REGSET_DSP,
  683. REGSET_FP_MODE,
  684. };
  685. struct pt_regs_offset {
  686. const char *name;
  687. int offset;
  688. };
  689. #define REG_OFFSET_NAME(reg, r) { \
  690. .name = #reg, \
  691. .offset = offsetof(struct pt_regs, r) \
  692. }
  693. #define REG_OFFSET_END { \
  694. .name = NULL, \
  695. .offset = 0 \
  696. }
  697. static const struct pt_regs_offset regoffset_table[] = {
  698. REG_OFFSET_NAME(r0, regs[0]),
  699. REG_OFFSET_NAME(r1, regs[1]),
  700. REG_OFFSET_NAME(r2, regs[2]),
  701. REG_OFFSET_NAME(r3, regs[3]),
  702. REG_OFFSET_NAME(r4, regs[4]),
  703. REG_OFFSET_NAME(r5, regs[5]),
  704. REG_OFFSET_NAME(r6, regs[6]),
  705. REG_OFFSET_NAME(r7, regs[7]),
  706. REG_OFFSET_NAME(r8, regs[8]),
  707. REG_OFFSET_NAME(r9, regs[9]),
  708. REG_OFFSET_NAME(r10, regs[10]),
  709. REG_OFFSET_NAME(r11, regs[11]),
  710. REG_OFFSET_NAME(r12, regs[12]),
  711. REG_OFFSET_NAME(r13, regs[13]),
  712. REG_OFFSET_NAME(r14, regs[14]),
  713. REG_OFFSET_NAME(r15, regs[15]),
  714. REG_OFFSET_NAME(r16, regs[16]),
  715. REG_OFFSET_NAME(r17, regs[17]),
  716. REG_OFFSET_NAME(r18, regs[18]),
  717. REG_OFFSET_NAME(r19, regs[19]),
  718. REG_OFFSET_NAME(r20, regs[20]),
  719. REG_OFFSET_NAME(r21, regs[21]),
  720. REG_OFFSET_NAME(r22, regs[22]),
  721. REG_OFFSET_NAME(r23, regs[23]),
  722. REG_OFFSET_NAME(r24, regs[24]),
  723. REG_OFFSET_NAME(r25, regs[25]),
  724. REG_OFFSET_NAME(r26, regs[26]),
  725. REG_OFFSET_NAME(r27, regs[27]),
  726. REG_OFFSET_NAME(r28, regs[28]),
  727. REG_OFFSET_NAME(r29, regs[29]),
  728. REG_OFFSET_NAME(r30, regs[30]),
  729. REG_OFFSET_NAME(r31, regs[31]),
  730. REG_OFFSET_NAME(c0_status, cp0_status),
  731. REG_OFFSET_NAME(hi, hi),
  732. REG_OFFSET_NAME(lo, lo),
  733. #ifdef CONFIG_CPU_HAS_SMARTMIPS
  734. REG_OFFSET_NAME(acx, acx),
  735. #endif
  736. REG_OFFSET_NAME(c0_badvaddr, cp0_badvaddr),
  737. REG_OFFSET_NAME(c0_cause, cp0_cause),
  738. REG_OFFSET_NAME(c0_epc, cp0_epc),
  739. #ifdef CONFIG_CPU_CAVIUM_OCTEON
  740. REG_OFFSET_NAME(mpl0, mpl[0]),
  741. REG_OFFSET_NAME(mpl1, mpl[1]),
  742. REG_OFFSET_NAME(mpl2, mpl[2]),
  743. REG_OFFSET_NAME(mtp0, mtp[0]),
  744. REG_OFFSET_NAME(mtp1, mtp[1]),
  745. REG_OFFSET_NAME(mtp2, mtp[2]),
  746. #endif
  747. REG_OFFSET_END,
  748. };
  749. /**
  750. * regs_query_register_offset() - query register offset from its name
  751. * @name: the name of a register
  752. *
  753. * regs_query_register_offset() returns the offset of a register in struct
  754. * pt_regs from its name. If the name is invalid, this returns -EINVAL;
  755. */
  756. int regs_query_register_offset(const char *name)
  757. {
  758. const struct pt_regs_offset *roff;
  759. for (roff = regoffset_table; roff->name != NULL; roff++)
  760. if (!strcmp(roff->name, name))
  761. return roff->offset;
  762. return -EINVAL;
  763. }
  764. #if defined(CONFIG_32BIT) || defined(CONFIG_MIPS32_O32)
  765. static const struct user_regset mips_regsets[] = {
  766. [REGSET_GPR] = {
  767. .core_note_type = NT_PRSTATUS,
  768. .n = ELF_NGREG,
  769. .size = sizeof(unsigned int),
  770. .align = sizeof(unsigned int),
  771. .get = gpr32_get,
  772. .set = gpr32_set,
  773. },
  774. [REGSET_FPR] = {
  775. .core_note_type = NT_PRFPREG,
  776. .n = ELF_NFPREG,
  777. .size = sizeof(elf_fpreg_t),
  778. .align = sizeof(elf_fpreg_t),
  779. .get = fpr_get,
  780. .set = fpr_set,
  781. },
  782. [REGSET_DSP] = {
  783. .core_note_type = NT_MIPS_DSP,
  784. .n = NUM_DSP_REGS + 1,
  785. .size = sizeof(u32),
  786. .align = sizeof(u32),
  787. .get = dsp32_get,
  788. .set = dsp32_set,
  789. .active = dsp_active,
  790. },
  791. [REGSET_FP_MODE] = {
  792. .core_note_type = NT_MIPS_FP_MODE,
  793. .n = 1,
  794. .size = sizeof(int),
  795. .align = sizeof(int),
  796. .get = fp_mode_get,
  797. .set = fp_mode_set,
  798. },
  799. };
  800. static const struct user_regset_view user_mips_view = {
  801. .name = "mips",
  802. .e_machine = ELF_ARCH,
  803. .ei_osabi = ELF_OSABI,
  804. .regsets = mips_regsets,
  805. .n = ARRAY_SIZE(mips_regsets),
  806. };
  807. #endif /* CONFIG_32BIT || CONFIG_MIPS32_O32 */
  808. #ifdef CONFIG_64BIT
  809. static const struct user_regset mips64_regsets[] = {
  810. [REGSET_GPR] = {
  811. .core_note_type = NT_PRSTATUS,
  812. .n = ELF_NGREG,
  813. .size = sizeof(unsigned long),
  814. .align = sizeof(unsigned long),
  815. .get = gpr64_get,
  816. .set = gpr64_set,
  817. },
  818. [REGSET_FPR] = {
  819. .core_note_type = NT_PRFPREG,
  820. .n = ELF_NFPREG,
  821. .size = sizeof(elf_fpreg_t),
  822. .align = sizeof(elf_fpreg_t),
  823. .get = fpr_get,
  824. .set = fpr_set,
  825. },
  826. [REGSET_DSP] = {
  827. .core_note_type = NT_MIPS_DSP,
  828. .n = NUM_DSP_REGS + 1,
  829. .size = sizeof(u64),
  830. .align = sizeof(u64),
  831. .get = dsp64_get,
  832. .set = dsp64_set,
  833. .active = dsp_active,
  834. },
  835. [REGSET_FP_MODE] = {
  836. .core_note_type = NT_MIPS_FP_MODE,
  837. .n = 1,
  838. .size = sizeof(int),
  839. .align = sizeof(int),
  840. .get = fp_mode_get,
  841. .set = fp_mode_set,
  842. },
  843. };
  844. static const struct user_regset_view user_mips64_view = {
  845. .name = "mips64",
  846. .e_machine = ELF_ARCH,
  847. .ei_osabi = ELF_OSABI,
  848. .regsets = mips64_regsets,
  849. .n = ARRAY_SIZE(mips64_regsets),
  850. };
  851. #ifdef CONFIG_MIPS32_N32
  852. static const struct user_regset_view user_mipsn32_view = {
  853. .name = "mipsn32",
  854. .e_flags = EF_MIPS_ABI2,
  855. .e_machine = ELF_ARCH,
  856. .ei_osabi = ELF_OSABI,
  857. .regsets = mips64_regsets,
  858. .n = ARRAY_SIZE(mips64_regsets),
  859. };
  860. #endif /* CONFIG_MIPS32_N32 */
  861. #endif /* CONFIG_64BIT */
  862. const struct user_regset_view *task_user_regset_view(struct task_struct *task)
  863. {
  864. #ifdef CONFIG_32BIT
  865. return &user_mips_view;
  866. #else
  867. #ifdef CONFIG_MIPS32_O32
  868. if (test_tsk_thread_flag(task, TIF_32BIT_REGS))
  869. return &user_mips_view;
  870. #endif
  871. #ifdef CONFIG_MIPS32_N32
  872. if (test_tsk_thread_flag(task, TIF_32BIT_ADDR))
  873. return &user_mipsn32_view;
  874. #endif
  875. return &user_mips64_view;
  876. #endif
  877. }
  878. long arch_ptrace(struct task_struct *child, long request,
  879. unsigned long addr, unsigned long data)
  880. {
  881. int ret;
  882. void __user *addrp = (void __user *) addr;
  883. void __user *datavp = (void __user *) data;
  884. unsigned long __user *datalp = (void __user *) data;
  885. switch (request) {
  886. /* when I and D space are separate, these will need to be fixed. */
  887. case PTRACE_PEEKTEXT: /* read word at location addr. */
  888. case PTRACE_PEEKDATA:
  889. ret = generic_ptrace_peekdata(child, addr, data);
  890. break;
  891. /* Read the word at location addr in the USER area. */
  892. case PTRACE_PEEKUSR: {
  893. struct pt_regs *regs;
  894. union fpureg *fregs;
  895. unsigned long tmp = 0;
  896. regs = task_pt_regs(child);
  897. ret = 0; /* Default return value. */
  898. switch (addr) {
  899. case 0 ... 31:
  900. tmp = regs->regs[addr];
  901. break;
  902. case FPR_BASE ... FPR_BASE + 31:
  903. if (!tsk_used_math(child)) {
  904. /* FP not yet used */
  905. tmp = -1;
  906. break;
  907. }
  908. fregs = get_fpu_regs(child);
  909. #ifdef CONFIG_32BIT
  910. if (test_tsk_thread_flag(child, TIF_32BIT_FPREGS)) {
  911. /*
  912. * The odd registers are actually the high
  913. * order bits of the values stored in the even
  914. * registers.
  915. */
  916. tmp = get_fpr32(&fregs[(addr & ~1) - FPR_BASE],
  917. addr & 1);
  918. break;
  919. }
  920. #endif
  921. tmp = get_fpr64(&fregs[addr - FPR_BASE], 0);
  922. break;
  923. case PC:
  924. tmp = regs->cp0_epc;
  925. break;
  926. case CAUSE:
  927. tmp = regs->cp0_cause;
  928. break;
  929. case BADVADDR:
  930. tmp = regs->cp0_badvaddr;
  931. break;
  932. case MMHI:
  933. tmp = regs->hi;
  934. break;
  935. case MMLO:
  936. tmp = regs->lo;
  937. break;
  938. #ifdef CONFIG_CPU_HAS_SMARTMIPS
  939. case ACX:
  940. tmp = regs->acx;
  941. break;
  942. #endif
  943. case FPC_CSR:
  944. tmp = child->thread.fpu.fcr31;
  945. break;
  946. case FPC_EIR:
  947. /* implementation / version register */
  948. tmp = boot_cpu_data.fpu_id;
  949. break;
  950. case DSP_BASE ... DSP_BASE + 5: {
  951. dspreg_t *dregs;
  952. if (!cpu_has_dsp) {
  953. tmp = 0;
  954. ret = -EIO;
  955. goto out;
  956. }
  957. dregs = __get_dsp_regs(child);
  958. tmp = dregs[addr - DSP_BASE];
  959. break;
  960. }
  961. case DSP_CONTROL:
  962. if (!cpu_has_dsp) {
  963. tmp = 0;
  964. ret = -EIO;
  965. goto out;
  966. }
  967. tmp = child->thread.dsp.dspcontrol;
  968. break;
  969. default:
  970. tmp = 0;
  971. ret = -EIO;
  972. goto out;
  973. }
  974. ret = put_user(tmp, datalp);
  975. break;
  976. }
  977. /* when I and D space are separate, this will have to be fixed. */
  978. case PTRACE_POKETEXT: /* write the word at location addr. */
  979. case PTRACE_POKEDATA:
  980. ret = generic_ptrace_pokedata(child, addr, data);
  981. break;
  982. case PTRACE_POKEUSR: {
  983. struct pt_regs *regs;
  984. ret = 0;
  985. regs = task_pt_regs(child);
  986. switch (addr) {
  987. case 0 ... 31:
  988. regs->regs[addr] = data;
  989. /* System call number may have been changed */
  990. if (addr == 2)
  991. mips_syscall_update_nr(child, regs);
  992. else if (addr == 4 &&
  993. mips_syscall_is_indirect(child, regs))
  994. mips_syscall_update_nr(child, regs);
  995. break;
  996. case FPR_BASE ... FPR_BASE + 31: {
  997. union fpureg *fregs = get_fpu_regs(child);
  998. init_fp_ctx(child);
  999. #ifdef CONFIG_32BIT
  1000. if (test_tsk_thread_flag(child, TIF_32BIT_FPREGS)) {
  1001. /*
  1002. * The odd registers are actually the high
  1003. * order bits of the values stored in the even
  1004. * registers.
  1005. */
  1006. set_fpr32(&fregs[(addr & ~1) - FPR_BASE],
  1007. addr & 1, data);
  1008. break;
  1009. }
  1010. #endif
  1011. set_fpr64(&fregs[addr - FPR_BASE], 0, data);
  1012. break;
  1013. }
  1014. case PC:
  1015. regs->cp0_epc = data;
  1016. break;
  1017. case MMHI:
  1018. regs->hi = data;
  1019. break;
  1020. case MMLO:
  1021. regs->lo = data;
  1022. break;
  1023. #ifdef CONFIG_CPU_HAS_SMARTMIPS
  1024. case ACX:
  1025. regs->acx = data;
  1026. break;
  1027. #endif
  1028. case FPC_CSR:
  1029. init_fp_ctx(child);
  1030. ptrace_setfcr31(child, data);
  1031. break;
  1032. case DSP_BASE ... DSP_BASE + 5: {
  1033. dspreg_t *dregs;
  1034. if (!cpu_has_dsp) {
  1035. ret = -EIO;
  1036. break;
  1037. }
  1038. dregs = __get_dsp_regs(child);
  1039. dregs[addr - DSP_BASE] = data;
  1040. break;
  1041. }
  1042. case DSP_CONTROL:
  1043. if (!cpu_has_dsp) {
  1044. ret = -EIO;
  1045. break;
  1046. }
  1047. child->thread.dsp.dspcontrol = data;
  1048. break;
  1049. default:
  1050. /* The rest are not allowed. */
  1051. ret = -EIO;
  1052. break;
  1053. }
  1054. break;
  1055. }
  1056. case PTRACE_GETREGS:
  1057. ret = ptrace_getregs(child, datavp);
  1058. break;
  1059. case PTRACE_SETREGS:
  1060. ret = ptrace_setregs(child, datavp);
  1061. break;
  1062. case PTRACE_GETFPREGS:
  1063. ret = ptrace_getfpregs(child, datavp);
  1064. break;
  1065. case PTRACE_SETFPREGS:
  1066. ret = ptrace_setfpregs(child, datavp);
  1067. break;
  1068. case PTRACE_GET_THREAD_AREA:
  1069. ret = put_user(task_thread_info(child)->tp_value, datalp);
  1070. break;
  1071. case PTRACE_GET_WATCH_REGS:
  1072. ret = ptrace_get_watch_regs(child, addrp);
  1073. break;
  1074. case PTRACE_SET_WATCH_REGS:
  1075. ret = ptrace_set_watch_regs(child, addrp);
  1076. break;
  1077. default:
  1078. ret = ptrace_request(child, request, addr, data);
  1079. break;
  1080. }
  1081. out:
  1082. return ret;
  1083. }
  1084. /*
  1085. * Notification of system call entry/exit
  1086. * - triggered by current->work.syscall_trace
  1087. */
  1088. asmlinkage long syscall_trace_enter(struct pt_regs *regs, long syscall)
  1089. {
  1090. user_exit();
  1091. current_thread_info()->syscall = syscall;
  1092. if (test_thread_flag(TIF_SYSCALL_TRACE)) {
  1093. if (tracehook_report_syscall_entry(regs))
  1094. return -1;
  1095. syscall = current_thread_info()->syscall;
  1096. }
  1097. #ifdef CONFIG_SECCOMP
  1098. if (unlikely(test_thread_flag(TIF_SECCOMP))) {
  1099. int ret, i;
  1100. struct seccomp_data sd;
  1101. unsigned long args[6];
  1102. sd.nr = syscall;
  1103. sd.arch = syscall_get_arch();
  1104. syscall_get_arguments(current, regs, 0, 6, args);
  1105. for (i = 0; i < 6; i++)
  1106. sd.args[i] = args[i];
  1107. sd.instruction_pointer = KSTK_EIP(current);
  1108. ret = __secure_computing(&sd);
  1109. if (ret == -1)
  1110. return ret;
  1111. syscall = current_thread_info()->syscall;
  1112. }
  1113. #endif
  1114. if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
  1115. trace_sys_enter(regs, regs->regs[2]);
  1116. audit_syscall_entry(syscall, regs->regs[4], regs->regs[5],
  1117. regs->regs[6], regs->regs[7]);
  1118. /*
  1119. * Negative syscall numbers are mistaken for rejected syscalls, but
  1120. * won't have had the return value set appropriately, so we do so now.
  1121. */
  1122. if (syscall < 0)
  1123. syscall_set_return_value(current, regs, -ENOSYS, 0);
  1124. return syscall;
  1125. }
  1126. /*
  1127. * Notification of system call entry/exit
  1128. * - triggered by current->work.syscall_trace
  1129. */
  1130. asmlinkage void syscall_trace_leave(struct pt_regs *regs)
  1131. {
  1132. /*
  1133. * We may come here right after calling schedule_user()
  1134. * or do_notify_resume(), in which case we can be in RCU
  1135. * user mode.
  1136. */
  1137. user_exit();
  1138. audit_syscall_exit(regs);
  1139. if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
  1140. trace_sys_exit(regs, regs_return_value(regs));
  1141. if (test_thread_flag(TIF_SYSCALL_TRACE))
  1142. tracehook_report_syscall_exit(regs, 0);
  1143. user_enter();
  1144. }