ptrace.c 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885
  1. /*
  2. * arch/s390/kernel/ptrace.c
  3. *
  4. * S390 version
  5. * Copyright (C) 1999,2000 IBM Deutschland Entwicklung GmbH, IBM Corporation
  6. * Author(s): Denis Joseph Barrow (djbarrow@de.ibm.com,barrow_dj@yahoo.com),
  7. * Martin Schwidefsky (schwidefsky@de.ibm.com)
  8. *
  9. * Based on PowerPC version
  10. * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org)
  11. *
  12. * Derived from "arch/m68k/kernel/ptrace.c"
  13. * Copyright (C) 1994 by Hamish Macdonald
  14. * Taken from linux/kernel/ptrace.c and modified for M680x0.
  15. * linux/kernel/ptrace.c is by Ross Biro 1/23/92, edited by Linus Torvalds
  16. *
  17. * Modified by Cort Dougan (cort@cs.nmt.edu)
  18. *
  19. *
  20. * This file is subject to the terms and conditions of the GNU General
  21. * Public License. See the file README.legal in the main directory of
  22. * this archive for more details.
  23. */
  24. #include <linux/kernel.h>
  25. #include <linux/sched.h>
  26. #include <linux/mm.h>
  27. #include <linux/smp.h>
  28. #include <linux/smp_lock.h>
  29. #include <linux/errno.h>
  30. #include <linux/ptrace.h>
  31. #include <linux/user.h>
  32. #include <linux/security.h>
  33. #include <linux/audit.h>
  34. #include <linux/signal.h>
  35. #include <linux/elf.h>
  36. #include <linux/regset.h>
  37. #include <asm/segment.h>
  38. #include <asm/page.h>
  39. #include <asm/pgtable.h>
  40. #include <asm/pgalloc.h>
  41. #include <asm/system.h>
  42. #include <asm/uaccess.h>
  43. #include <asm/unistd.h>
  44. #include "entry.h"
  45. #ifdef CONFIG_COMPAT
  46. #include "compat_ptrace.h"
  47. #endif
  48. enum s390_regset {
  49. REGSET_GENERAL,
  50. REGSET_FP,
  51. };
  52. static void
  53. FixPerRegisters(struct task_struct *task)
  54. {
  55. struct pt_regs *regs;
  56. per_struct *per_info;
  57. regs = task_pt_regs(task);
  58. per_info = (per_struct *) &task->thread.per_info;
  59. per_info->control_regs.bits.em_instruction_fetch =
  60. per_info->single_step | per_info->instruction_fetch;
  61. if (per_info->single_step) {
  62. per_info->control_regs.bits.starting_addr = 0;
  63. #ifdef CONFIG_COMPAT
  64. if (test_thread_flag(TIF_31BIT))
  65. per_info->control_regs.bits.ending_addr = 0x7fffffffUL;
  66. else
  67. #endif
  68. per_info->control_regs.bits.ending_addr = PSW_ADDR_INSN;
  69. } else {
  70. per_info->control_regs.bits.starting_addr =
  71. per_info->starting_addr;
  72. per_info->control_regs.bits.ending_addr =
  73. per_info->ending_addr;
  74. }
  75. /*
  76. * if any of the control reg tracing bits are on
  77. * we switch on per in the psw
  78. */
  79. if (per_info->control_regs.words.cr[0] & PER_EM_MASK)
  80. regs->psw.mask |= PSW_MASK_PER;
  81. else
  82. regs->psw.mask &= ~PSW_MASK_PER;
  83. if (per_info->control_regs.bits.em_storage_alteration)
  84. per_info->control_regs.bits.storage_alt_space_ctl = 1;
  85. else
  86. per_info->control_regs.bits.storage_alt_space_ctl = 0;
  87. }
  88. void user_enable_single_step(struct task_struct *task)
  89. {
  90. task->thread.per_info.single_step = 1;
  91. FixPerRegisters(task);
  92. }
  93. void user_disable_single_step(struct task_struct *task)
  94. {
  95. task->thread.per_info.single_step = 0;
  96. FixPerRegisters(task);
  97. }
  98. /*
  99. * Called by kernel/ptrace.c when detaching..
  100. *
  101. * Make sure single step bits etc are not set.
  102. */
  103. void
  104. ptrace_disable(struct task_struct *child)
  105. {
  106. /* make sure the single step bit is not set. */
  107. user_disable_single_step(child);
  108. }
  109. #ifndef CONFIG_64BIT
  110. # define __ADDR_MASK 3
  111. #else
  112. # define __ADDR_MASK 7
  113. #endif
  114. /*
  115. * Read the word at offset addr from the user area of a process. The
  116. * trouble here is that the information is littered over different
  117. * locations. The process registers are found on the kernel stack,
  118. * the floating point stuff and the trace settings are stored in
  119. * the task structure. In addition the different structures in
  120. * struct user contain pad bytes that should be read as zeroes.
  121. * Lovely...
  122. */
  123. static unsigned long __peek_user(struct task_struct *child, addr_t addr)
  124. {
  125. struct user *dummy = NULL;
  126. addr_t offset, tmp;
  127. if (addr < (addr_t) &dummy->regs.acrs) {
  128. /*
  129. * psw and gprs are stored on the stack
  130. */
  131. tmp = *(addr_t *)((addr_t) &task_pt_regs(child)->psw + addr);
  132. if (addr == (addr_t) &dummy->regs.psw.mask)
  133. /* Remove per bit from user psw. */
  134. tmp &= ~PSW_MASK_PER;
  135. } else if (addr < (addr_t) &dummy->regs.orig_gpr2) {
  136. /*
  137. * access registers are stored in the thread structure
  138. */
  139. offset = addr - (addr_t) &dummy->regs.acrs;
  140. #ifdef CONFIG_64BIT
  141. /*
  142. * Very special case: old & broken 64 bit gdb reading
  143. * from acrs[15]. Result is a 64 bit value. Read the
  144. * 32 bit acrs[15] value and shift it by 32. Sick...
  145. */
  146. if (addr == (addr_t) &dummy->regs.acrs[15])
  147. tmp = ((unsigned long) child->thread.acrs[15]) << 32;
  148. else
  149. #endif
  150. tmp = *(addr_t *)((addr_t) &child->thread.acrs + offset);
  151. } else if (addr == (addr_t) &dummy->regs.orig_gpr2) {
  152. /*
  153. * orig_gpr2 is stored on the kernel stack
  154. */
  155. tmp = (addr_t) task_pt_regs(child)->orig_gpr2;
  156. } else if (addr < (addr_t) (&dummy->regs.fp_regs + 1)) {
  157. /*
  158. * floating point regs. are stored in the thread structure
  159. */
  160. offset = addr - (addr_t) &dummy->regs.fp_regs;
  161. tmp = *(addr_t *)((addr_t) &child->thread.fp_regs + offset);
  162. if (addr == (addr_t) &dummy->regs.fp_regs.fpc)
  163. tmp &= (unsigned long) FPC_VALID_MASK
  164. << (BITS_PER_LONG - 32);
  165. } else if (addr < (addr_t) (&dummy->regs.per_info + 1)) {
  166. /*
  167. * per_info is found in the thread structure
  168. */
  169. offset = addr - (addr_t) &dummy->regs.per_info;
  170. tmp = *(addr_t *)((addr_t) &child->thread.per_info + offset);
  171. } else
  172. tmp = 0;
  173. return tmp;
  174. }
  175. static int
  176. peek_user(struct task_struct *child, addr_t addr, addr_t data)
  177. {
  178. struct user *dummy = NULL;
  179. addr_t tmp, mask;
  180. /*
  181. * Stupid gdb peeks/pokes the access registers in 64 bit with
  182. * an alignment of 4. Programmers from hell...
  183. */
  184. mask = __ADDR_MASK;
  185. #ifdef CONFIG_64BIT
  186. if (addr >= (addr_t) &dummy->regs.acrs &&
  187. addr < (addr_t) &dummy->regs.orig_gpr2)
  188. mask = 3;
  189. #endif
  190. if ((addr & mask) || addr > sizeof(struct user) - __ADDR_MASK)
  191. return -EIO;
  192. tmp = __peek_user(child, addr);
  193. return put_user(tmp, (addr_t __user *) data);
  194. }
  195. /*
  196. * Write a word to the user area of a process at location addr. This
  197. * operation does have an additional problem compared to peek_user.
  198. * Stores to the program status word and on the floating point
  199. * control register needs to get checked for validity.
  200. */
  201. static int __poke_user(struct task_struct *child, addr_t addr, addr_t data)
  202. {
  203. struct user *dummy = NULL;
  204. addr_t offset;
  205. if (addr < (addr_t) &dummy->regs.acrs) {
  206. /*
  207. * psw and gprs are stored on the stack
  208. */
  209. if (addr == (addr_t) &dummy->regs.psw.mask &&
  210. #ifdef CONFIG_COMPAT
  211. data != PSW_MASK_MERGE(psw_user32_bits, data) &&
  212. #endif
  213. data != PSW_MASK_MERGE(psw_user_bits, data))
  214. /* Invalid psw mask. */
  215. return -EINVAL;
  216. #ifndef CONFIG_64BIT
  217. if (addr == (addr_t) &dummy->regs.psw.addr)
  218. /* I'd like to reject addresses without the
  219. high order bit but older gdb's rely on it */
  220. data |= PSW_ADDR_AMODE;
  221. #endif
  222. *(addr_t *)((addr_t) &task_pt_regs(child)->psw + addr) = data;
  223. } else if (addr < (addr_t) (&dummy->regs.orig_gpr2)) {
  224. /*
  225. * access registers are stored in the thread structure
  226. */
  227. offset = addr - (addr_t) &dummy->regs.acrs;
  228. #ifdef CONFIG_64BIT
  229. /*
  230. * Very special case: old & broken 64 bit gdb writing
  231. * to acrs[15] with a 64 bit value. Ignore the lower
  232. * half of the value and write the upper 32 bit to
  233. * acrs[15]. Sick...
  234. */
  235. if (addr == (addr_t) &dummy->regs.acrs[15])
  236. child->thread.acrs[15] = (unsigned int) (data >> 32);
  237. else
  238. #endif
  239. *(addr_t *)((addr_t) &child->thread.acrs + offset) = data;
  240. } else if (addr == (addr_t) &dummy->regs.orig_gpr2) {
  241. /*
  242. * orig_gpr2 is stored on the kernel stack
  243. */
  244. task_pt_regs(child)->orig_gpr2 = data;
  245. } else if (addr < (addr_t) (&dummy->regs.fp_regs + 1)) {
  246. /*
  247. * floating point regs. are stored in the thread structure
  248. */
  249. if (addr == (addr_t) &dummy->regs.fp_regs.fpc &&
  250. (data & ~((unsigned long) FPC_VALID_MASK
  251. << (BITS_PER_LONG - 32))) != 0)
  252. return -EINVAL;
  253. offset = addr - (addr_t) &dummy->regs.fp_regs;
  254. *(addr_t *)((addr_t) &child->thread.fp_regs + offset) = data;
  255. } else if (addr < (addr_t) (&dummy->regs.per_info + 1)) {
  256. /*
  257. * per_info is found in the thread structure
  258. */
  259. offset = addr - (addr_t) &dummy->regs.per_info;
  260. *(addr_t *)((addr_t) &child->thread.per_info + offset) = data;
  261. }
  262. FixPerRegisters(child);
  263. return 0;
  264. }
  265. static int
  266. poke_user(struct task_struct *child, addr_t addr, addr_t data)
  267. {
  268. struct user *dummy = NULL;
  269. addr_t mask;
  270. /*
  271. * Stupid gdb peeks/pokes the access registers in 64 bit with
  272. * an alignment of 4. Programmers from hell indeed...
  273. */
  274. mask = __ADDR_MASK;
  275. #ifdef CONFIG_64BIT
  276. if (addr >= (addr_t) &dummy->regs.acrs &&
  277. addr < (addr_t) &dummy->regs.orig_gpr2)
  278. mask = 3;
  279. #endif
  280. if ((addr & mask) || addr > sizeof(struct user) - __ADDR_MASK)
  281. return -EIO;
  282. return __poke_user(child, addr, data);
  283. }
  284. long arch_ptrace(struct task_struct *child, long request, long addr, long data)
  285. {
  286. ptrace_area parea;
  287. int copied, ret;
  288. switch (request) {
  289. case PTRACE_PEEKTEXT:
  290. case PTRACE_PEEKDATA:
  291. /* Remove high order bit from address (only for 31 bit). */
  292. addr &= PSW_ADDR_INSN;
  293. /* read word at location addr. */
  294. return generic_ptrace_peekdata(child, addr, data);
  295. case PTRACE_PEEKUSR:
  296. /* read the word at location addr in the USER area. */
  297. return peek_user(child, addr, data);
  298. case PTRACE_POKETEXT:
  299. case PTRACE_POKEDATA:
  300. /* Remove high order bit from address (only for 31 bit). */
  301. addr &= PSW_ADDR_INSN;
  302. /* write the word at location addr. */
  303. return generic_ptrace_pokedata(child, addr, data);
  304. case PTRACE_POKEUSR:
  305. /* write the word at location addr in the USER area */
  306. return poke_user(child, addr, data);
  307. case PTRACE_PEEKUSR_AREA:
  308. case PTRACE_POKEUSR_AREA:
  309. if (copy_from_user(&parea, (void __force __user *) addr,
  310. sizeof(parea)))
  311. return -EFAULT;
  312. addr = parea.kernel_addr;
  313. data = parea.process_addr;
  314. copied = 0;
  315. while (copied < parea.len) {
  316. if (request == PTRACE_PEEKUSR_AREA)
  317. ret = peek_user(child, addr, data);
  318. else {
  319. addr_t utmp;
  320. if (get_user(utmp,
  321. (addr_t __force __user *) data))
  322. return -EFAULT;
  323. ret = poke_user(child, addr, utmp);
  324. }
  325. if (ret)
  326. return ret;
  327. addr += sizeof(unsigned long);
  328. data += sizeof(unsigned long);
  329. copied += sizeof(unsigned long);
  330. }
  331. return 0;
  332. }
  333. return ptrace_request(child, request, addr, data);
  334. }
  335. #ifdef CONFIG_COMPAT
  336. /*
  337. * Now the fun part starts... a 31 bit program running in the
  338. * 31 bit emulation tracing another program. PTRACE_PEEKTEXT,
  339. * PTRACE_PEEKDATA, PTRACE_POKETEXT and PTRACE_POKEDATA are easy
  340. * to handle, the difference to the 64 bit versions of the requests
  341. * is that the access is done in multiples of 4 byte instead of
  342. * 8 bytes (sizeof(unsigned long) on 31/64 bit).
  343. * The ugly part are PTRACE_PEEKUSR, PTRACE_PEEKUSR_AREA,
  344. * PTRACE_POKEUSR and PTRACE_POKEUSR_AREA. If the traced program
  345. * is a 31 bit program too, the content of struct user can be
  346. * emulated. A 31 bit program peeking into the struct user of
  347. * a 64 bit program is a no-no.
  348. */
  349. /*
  350. * Same as peek_user but for a 31 bit program.
  351. */
  352. static u32 __peek_user_compat(struct task_struct *child, addr_t addr)
  353. {
  354. struct user32 *dummy32 = NULL;
  355. per_struct32 *dummy_per32 = NULL;
  356. addr_t offset;
  357. __u32 tmp;
  358. if (addr < (addr_t) &dummy32->regs.acrs) {
  359. /*
  360. * psw and gprs are stored on the stack
  361. */
  362. if (addr == (addr_t) &dummy32->regs.psw.mask) {
  363. /* Fake a 31 bit psw mask. */
  364. tmp = (__u32)(task_pt_regs(child)->psw.mask >> 32);
  365. tmp = PSW32_MASK_MERGE(psw32_user_bits, tmp);
  366. } else if (addr == (addr_t) &dummy32->regs.psw.addr) {
  367. /* Fake a 31 bit psw address. */
  368. tmp = (__u32) task_pt_regs(child)->psw.addr |
  369. PSW32_ADDR_AMODE31;
  370. } else {
  371. /* gpr 0-15 */
  372. tmp = *(__u32 *)((addr_t) &task_pt_regs(child)->psw +
  373. addr*2 + 4);
  374. }
  375. } else if (addr < (addr_t) (&dummy32->regs.orig_gpr2)) {
  376. /*
  377. * access registers are stored in the thread structure
  378. */
  379. offset = addr - (addr_t) &dummy32->regs.acrs;
  380. tmp = *(__u32*)((addr_t) &child->thread.acrs + offset);
  381. } else if (addr == (addr_t) (&dummy32->regs.orig_gpr2)) {
  382. /*
  383. * orig_gpr2 is stored on the kernel stack
  384. */
  385. tmp = *(__u32*)((addr_t) &task_pt_regs(child)->orig_gpr2 + 4);
  386. } else if (addr < (addr_t) (&dummy32->regs.fp_regs + 1)) {
  387. /*
  388. * floating point regs. are stored in the thread structure
  389. */
  390. offset = addr - (addr_t) &dummy32->regs.fp_regs;
  391. tmp = *(__u32 *)((addr_t) &child->thread.fp_regs + offset);
  392. } else if (addr < (addr_t) (&dummy32->regs.per_info + 1)) {
  393. /*
  394. * per_info is found in the thread structure
  395. */
  396. offset = addr - (addr_t) &dummy32->regs.per_info;
  397. /* This is magic. See per_struct and per_struct32. */
  398. if ((offset >= (addr_t) &dummy_per32->control_regs &&
  399. offset < (addr_t) (&dummy_per32->control_regs + 1)) ||
  400. (offset >= (addr_t) &dummy_per32->starting_addr &&
  401. offset <= (addr_t) &dummy_per32->ending_addr) ||
  402. offset == (addr_t) &dummy_per32->lowcore.words.address)
  403. offset = offset*2 + 4;
  404. else
  405. offset = offset*2;
  406. tmp = *(__u32 *)((addr_t) &child->thread.per_info + offset);
  407. } else
  408. tmp = 0;
  409. return tmp;
  410. }
  411. static int peek_user_compat(struct task_struct *child,
  412. addr_t addr, addr_t data)
  413. {
  414. __u32 tmp;
  415. if (!test_thread_flag(TIF_31BIT) ||
  416. (addr & 3) || addr > sizeof(struct user) - 3)
  417. return -EIO;
  418. tmp = __peek_user_compat(child, addr);
  419. return put_user(tmp, (__u32 __user *) data);
  420. }
  421. /*
  422. * Same as poke_user but for a 31 bit program.
  423. */
  424. static int __poke_user_compat(struct task_struct *child,
  425. addr_t addr, addr_t data)
  426. {
  427. struct user32 *dummy32 = NULL;
  428. per_struct32 *dummy_per32 = NULL;
  429. __u32 tmp = (__u32) data;
  430. addr_t offset;
  431. if (addr < (addr_t) &dummy32->regs.acrs) {
  432. /*
  433. * psw, gprs, acrs and orig_gpr2 are stored on the stack
  434. */
  435. if (addr == (addr_t) &dummy32->regs.psw.mask) {
  436. /* Build a 64 bit psw mask from 31 bit mask. */
  437. if (tmp != PSW32_MASK_MERGE(psw32_user_bits, tmp))
  438. /* Invalid psw mask. */
  439. return -EINVAL;
  440. task_pt_regs(child)->psw.mask =
  441. PSW_MASK_MERGE(psw_user32_bits, (__u64) tmp << 32);
  442. } else if (addr == (addr_t) &dummy32->regs.psw.addr) {
  443. /* Build a 64 bit psw address from 31 bit address. */
  444. task_pt_regs(child)->psw.addr =
  445. (__u64) tmp & PSW32_ADDR_INSN;
  446. } else {
  447. /* gpr 0-15 */
  448. *(__u32*)((addr_t) &task_pt_regs(child)->psw
  449. + addr*2 + 4) = tmp;
  450. }
  451. } else if (addr < (addr_t) (&dummy32->regs.orig_gpr2)) {
  452. /*
  453. * access registers are stored in the thread structure
  454. */
  455. offset = addr - (addr_t) &dummy32->regs.acrs;
  456. *(__u32*)((addr_t) &child->thread.acrs + offset) = tmp;
  457. } else if (addr == (addr_t) (&dummy32->regs.orig_gpr2)) {
  458. /*
  459. * orig_gpr2 is stored on the kernel stack
  460. */
  461. *(__u32*)((addr_t) &task_pt_regs(child)->orig_gpr2 + 4) = tmp;
  462. } else if (addr < (addr_t) (&dummy32->regs.fp_regs + 1)) {
  463. /*
  464. * floating point regs. are stored in the thread structure
  465. */
  466. if (addr == (addr_t) &dummy32->regs.fp_regs.fpc &&
  467. (tmp & ~FPC_VALID_MASK) != 0)
  468. /* Invalid floating point control. */
  469. return -EINVAL;
  470. offset = addr - (addr_t) &dummy32->regs.fp_regs;
  471. *(__u32 *)((addr_t) &child->thread.fp_regs + offset) = tmp;
  472. } else if (addr < (addr_t) (&dummy32->regs.per_info + 1)) {
  473. /*
  474. * per_info is found in the thread structure.
  475. */
  476. offset = addr - (addr_t) &dummy32->regs.per_info;
  477. /*
  478. * This is magic. See per_struct and per_struct32.
  479. * By incident the offsets in per_struct are exactly
  480. * twice the offsets in per_struct32 for all fields.
  481. * The 8 byte fields need special handling though,
  482. * because the second half (bytes 4-7) is needed and
  483. * not the first half.
  484. */
  485. if ((offset >= (addr_t) &dummy_per32->control_regs &&
  486. offset < (addr_t) (&dummy_per32->control_regs + 1)) ||
  487. (offset >= (addr_t) &dummy_per32->starting_addr &&
  488. offset <= (addr_t) &dummy_per32->ending_addr) ||
  489. offset == (addr_t) &dummy_per32->lowcore.words.address)
  490. offset = offset*2 + 4;
  491. else
  492. offset = offset*2;
  493. *(__u32 *)((addr_t) &child->thread.per_info + offset) = tmp;
  494. }
  495. FixPerRegisters(child);
  496. return 0;
  497. }
  498. static int poke_user_compat(struct task_struct *child,
  499. addr_t addr, addr_t data)
  500. {
  501. if (!test_thread_flag(TIF_31BIT) ||
  502. (addr & 3) || addr > sizeof(struct user32) - 3)
  503. return -EIO;
  504. return __poke_user_compat(child, addr, data);
  505. }
  506. long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
  507. compat_ulong_t caddr, compat_ulong_t cdata)
  508. {
  509. unsigned long addr = caddr;
  510. unsigned long data = cdata;
  511. ptrace_area_emu31 parea;
  512. int copied, ret;
  513. switch (request) {
  514. case PTRACE_PEEKUSR:
  515. /* read the word at location addr in the USER area. */
  516. return peek_user_compat(child, addr, data);
  517. case PTRACE_POKEUSR:
  518. /* write the word at location addr in the USER area */
  519. return poke_user_compat(child, addr, data);
  520. case PTRACE_PEEKUSR_AREA:
  521. case PTRACE_POKEUSR_AREA:
  522. if (copy_from_user(&parea, (void __force __user *) addr,
  523. sizeof(parea)))
  524. return -EFAULT;
  525. addr = parea.kernel_addr;
  526. data = parea.process_addr;
  527. copied = 0;
  528. while (copied < parea.len) {
  529. if (request == PTRACE_PEEKUSR_AREA)
  530. ret = peek_user_compat(child, addr, data);
  531. else {
  532. __u32 utmp;
  533. if (get_user(utmp,
  534. (__u32 __force __user *) data))
  535. return -EFAULT;
  536. ret = poke_user_compat(child, addr, utmp);
  537. }
  538. if (ret)
  539. return ret;
  540. addr += sizeof(unsigned int);
  541. data += sizeof(unsigned int);
  542. copied += sizeof(unsigned int);
  543. }
  544. return 0;
  545. }
  546. return compat_ptrace_request(child, request, addr, data);
  547. }
  548. #endif
  549. asmlinkage void
  550. syscall_trace(struct pt_regs *regs, int entryexit)
  551. {
  552. if (unlikely(current->audit_context) && entryexit)
  553. audit_syscall_exit(AUDITSC_RESULT(regs->gprs[2]), regs->gprs[2]);
  554. if (!test_thread_flag(TIF_SYSCALL_TRACE))
  555. goto out;
  556. if (!(current->ptrace & PT_PTRACED))
  557. goto out;
  558. ptrace_notify(SIGTRAP | ((current->ptrace & PT_TRACESYSGOOD)
  559. ? 0x80 : 0));
  560. /*
  561. * If the debuffer has set an invalid system call number,
  562. * we prepare to skip the system call restart handling.
  563. */
  564. if (!entryexit && regs->gprs[2] >= NR_syscalls)
  565. regs->trap = -1;
  566. /*
  567. * this isn't the same as continuing with a signal, but it will do
  568. * for normal use. strace only continues with a signal if the
  569. * stopping signal is not SIGTRAP. -brl
  570. */
  571. if (current->exit_code) {
  572. send_sig(current->exit_code, current, 1);
  573. current->exit_code = 0;
  574. }
  575. out:
  576. if (unlikely(current->audit_context) && !entryexit)
  577. audit_syscall_entry(test_thread_flag(TIF_31BIT)?AUDIT_ARCH_S390:AUDIT_ARCH_S390X,
  578. regs->gprs[2], regs->orig_gpr2, regs->gprs[3],
  579. regs->gprs[4], regs->gprs[5]);
  580. }
  581. /*
  582. * user_regset definitions.
  583. */
  584. static int s390_regs_get(struct task_struct *target,
  585. const struct user_regset *regset,
  586. unsigned int pos, unsigned int count,
  587. void *kbuf, void __user *ubuf)
  588. {
  589. if (target == current)
  590. save_access_regs(target->thread.acrs);
  591. if (kbuf) {
  592. unsigned long *k = kbuf;
  593. while (count > 0) {
  594. *k++ = __peek_user(target, pos);
  595. count -= sizeof(*k);
  596. pos += sizeof(*k);
  597. }
  598. } else {
  599. unsigned long __user *u = ubuf;
  600. while (count > 0) {
  601. if (__put_user(__peek_user(target, pos), u++))
  602. return -EFAULT;
  603. count -= sizeof(*u);
  604. pos += sizeof(*u);
  605. }
  606. }
  607. return 0;
  608. }
  609. static int s390_regs_set(struct task_struct *target,
  610. const struct user_regset *regset,
  611. unsigned int pos, unsigned int count,
  612. const void *kbuf, const void __user *ubuf)
  613. {
  614. int rc = 0;
  615. if (target == current)
  616. save_access_regs(target->thread.acrs);
  617. if (kbuf) {
  618. const unsigned long *k = kbuf;
  619. while (count > 0 && !rc) {
  620. rc = __poke_user(target, pos, *k++);
  621. count -= sizeof(*k);
  622. pos += sizeof(*k);
  623. }
  624. } else {
  625. const unsigned long __user *u = ubuf;
  626. while (count > 0 && !rc) {
  627. unsigned long word;
  628. rc = __get_user(word, u++);
  629. if (rc)
  630. break;
  631. rc = __poke_user(target, pos, word);
  632. count -= sizeof(*u);
  633. pos += sizeof(*u);
  634. }
  635. }
  636. if (rc == 0 && target == current)
  637. restore_access_regs(target->thread.acrs);
  638. return rc;
  639. }
  640. static int s390_fpregs_get(struct task_struct *target,
  641. const struct user_regset *regset, unsigned int pos,
  642. unsigned int count, void *kbuf, void __user *ubuf)
  643. {
  644. if (target == current)
  645. save_fp_regs(&target->thread.fp_regs);
  646. return user_regset_copyout(&pos, &count, &kbuf, &ubuf,
  647. &target->thread.fp_regs, 0, -1);
  648. }
  649. static int s390_fpregs_set(struct task_struct *target,
  650. const struct user_regset *regset, unsigned int pos,
  651. unsigned int count, const void *kbuf,
  652. const void __user *ubuf)
  653. {
  654. int rc = 0;
  655. if (target == current)
  656. save_fp_regs(&target->thread.fp_regs);
  657. /* If setting FPC, must validate it first. */
  658. if (count > 0 && pos < offsetof(s390_fp_regs, fprs)) {
  659. u32 fpc[2] = { target->thread.fp_regs.fpc, 0 };
  660. rc = user_regset_copyin(&pos, &count, &kbuf, &ubuf, &fpc,
  661. 0, offsetof(s390_fp_regs, fprs));
  662. if (rc)
  663. return rc;
  664. if ((fpc[0] & ~FPC_VALID_MASK) != 0 || fpc[1] != 0)
  665. return -EINVAL;
  666. target->thread.fp_regs.fpc = fpc[0];
  667. }
  668. if (rc == 0 && count > 0)
  669. rc = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
  670. target->thread.fp_regs.fprs,
  671. offsetof(s390_fp_regs, fprs), -1);
  672. if (rc == 0 && target == current)
  673. restore_fp_regs(&target->thread.fp_regs);
  674. return rc;
  675. }
  676. static const struct user_regset s390_regsets[] = {
  677. [REGSET_GENERAL] = {
  678. .core_note_type = NT_PRSTATUS,
  679. .n = sizeof(s390_regs) / sizeof(long),
  680. .size = sizeof(long),
  681. .align = sizeof(long),
  682. .get = s390_regs_get,
  683. .set = s390_regs_set,
  684. },
  685. [REGSET_FP] = {
  686. .core_note_type = NT_PRFPREG,
  687. .n = sizeof(s390_fp_regs) / sizeof(long),
  688. .size = sizeof(long),
  689. .align = sizeof(long),
  690. .get = s390_fpregs_get,
  691. .set = s390_fpregs_set,
  692. },
  693. };
  694. static const struct user_regset_view user_s390_view = {
  695. .name = UTS_MACHINE,
  696. .e_machine = EM_S390,
  697. .regsets = s390_regsets,
  698. .n = ARRAY_SIZE(s390_regsets)
  699. };
  700. #ifdef CONFIG_COMPAT
  701. static int s390_compat_regs_get(struct task_struct *target,
  702. const struct user_regset *regset,
  703. unsigned int pos, unsigned int count,
  704. void *kbuf, void __user *ubuf)
  705. {
  706. if (target == current)
  707. save_access_regs(target->thread.acrs);
  708. if (kbuf) {
  709. compat_ulong_t *k = kbuf;
  710. while (count > 0) {
  711. *k++ = __peek_user_compat(target, pos);
  712. count -= sizeof(*k);
  713. pos += sizeof(*k);
  714. }
  715. } else {
  716. compat_ulong_t __user *u = ubuf;
  717. while (count > 0) {
  718. if (__put_user(__peek_user_compat(target, pos), u++))
  719. return -EFAULT;
  720. count -= sizeof(*u);
  721. pos += sizeof(*u);
  722. }
  723. }
  724. return 0;
  725. }
  726. static int s390_compat_regs_set(struct task_struct *target,
  727. const struct user_regset *regset,
  728. unsigned int pos, unsigned int count,
  729. const void *kbuf, const void __user *ubuf)
  730. {
  731. int rc = 0;
  732. if (target == current)
  733. save_access_regs(target->thread.acrs);
  734. if (kbuf) {
  735. const compat_ulong_t *k = kbuf;
  736. while (count > 0 && !rc) {
  737. rc = __poke_user_compat(target, pos, *k++);
  738. count -= sizeof(*k);
  739. pos += sizeof(*k);
  740. }
  741. } else {
  742. const compat_ulong_t __user *u = ubuf;
  743. while (count > 0 && !rc) {
  744. compat_ulong_t word;
  745. rc = __get_user(word, u++);
  746. if (rc)
  747. break;
  748. rc = __poke_user_compat(target, pos, word);
  749. count -= sizeof(*u);
  750. pos += sizeof(*u);
  751. }
  752. }
  753. if (rc == 0 && target == current)
  754. restore_access_regs(target->thread.acrs);
  755. return rc;
  756. }
  757. static const struct user_regset s390_compat_regsets[] = {
  758. [REGSET_GENERAL] = {
  759. .core_note_type = NT_PRSTATUS,
  760. .n = sizeof(s390_compat_regs) / sizeof(compat_long_t),
  761. .size = sizeof(compat_long_t),
  762. .align = sizeof(compat_long_t),
  763. .get = s390_compat_regs_get,
  764. .set = s390_compat_regs_set,
  765. },
  766. [REGSET_FP] = {
  767. .core_note_type = NT_PRFPREG,
  768. .n = sizeof(s390_fp_regs) / sizeof(compat_long_t),
  769. .size = sizeof(compat_long_t),
  770. .align = sizeof(compat_long_t),
  771. .get = s390_fpregs_get,
  772. .set = s390_fpregs_set,
  773. },
  774. };
  775. static const struct user_regset_view user_s390_compat_view = {
  776. .name = "s390",
  777. .e_machine = EM_S390,
  778. .regsets = s390_compat_regsets,
  779. .n = ARRAY_SIZE(s390_compat_regsets)
  780. };
  781. #endif
  782. const struct user_regset_view *task_user_regset_view(struct task_struct *task)
  783. {
  784. #ifdef CONFIG_COMPAT
  785. if (test_tsk_thread_flag(task, TIF_31BIT))
  786. return &user_s390_compat_view;
  787. #endif
  788. return &user_s390_view;
  789. }