ptrace.c 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913
  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) {
  157. /*
  158. * prevent reads of padding hole between
  159. * orig_gpr2 and fp_regs on s390.
  160. */
  161. tmp = 0;
  162. } else if (addr < (addr_t) (&dummy->regs.fp_regs + 1)) {
  163. /*
  164. * floating point regs. are stored in the thread structure
  165. */
  166. offset = addr - (addr_t) &dummy->regs.fp_regs;
  167. tmp = *(addr_t *)((addr_t) &child->thread.fp_regs + offset);
  168. if (addr == (addr_t) &dummy->regs.fp_regs.fpc)
  169. tmp &= (unsigned long) FPC_VALID_MASK
  170. << (BITS_PER_LONG - 32);
  171. } else if (addr < (addr_t) (&dummy->regs.per_info + 1)) {
  172. /*
  173. * per_info is found in the thread structure
  174. */
  175. offset = addr - (addr_t) &dummy->regs.per_info;
  176. tmp = *(addr_t *)((addr_t) &child->thread.per_info + offset);
  177. } else
  178. tmp = 0;
  179. return tmp;
  180. }
  181. static int
  182. peek_user(struct task_struct *child, addr_t addr, addr_t data)
  183. {
  184. struct user *dummy = NULL;
  185. addr_t tmp, mask;
  186. /*
  187. * Stupid gdb peeks/pokes the access registers in 64 bit with
  188. * an alignment of 4. Programmers from hell...
  189. */
  190. mask = __ADDR_MASK;
  191. #ifdef CONFIG_64BIT
  192. if (addr >= (addr_t) &dummy->regs.acrs &&
  193. addr < (addr_t) &dummy->regs.orig_gpr2)
  194. mask = 3;
  195. #endif
  196. if ((addr & mask) || addr > sizeof(struct user) - __ADDR_MASK)
  197. return -EIO;
  198. tmp = __peek_user(child, addr);
  199. return put_user(tmp, (addr_t __user *) data);
  200. }
  201. /*
  202. * Write a word to the user area of a process at location addr. This
  203. * operation does have an additional problem compared to peek_user.
  204. * Stores to the program status word and on the floating point
  205. * control register needs to get checked for validity.
  206. */
  207. static int __poke_user(struct task_struct *child, addr_t addr, addr_t data)
  208. {
  209. struct user *dummy = NULL;
  210. addr_t offset;
  211. if (addr < (addr_t) &dummy->regs.acrs) {
  212. /*
  213. * psw and gprs are stored on the stack
  214. */
  215. if (addr == (addr_t) &dummy->regs.psw.mask &&
  216. #ifdef CONFIG_COMPAT
  217. data != PSW_MASK_MERGE(psw_user32_bits, data) &&
  218. #endif
  219. data != PSW_MASK_MERGE(psw_user_bits, data))
  220. /* Invalid psw mask. */
  221. return -EINVAL;
  222. #ifndef CONFIG_64BIT
  223. if (addr == (addr_t) &dummy->regs.psw.addr)
  224. /* I'd like to reject addresses without the
  225. high order bit but older gdb's rely on it */
  226. data |= PSW_ADDR_AMODE;
  227. #endif
  228. *(addr_t *)((addr_t) &task_pt_regs(child)->psw + addr) = data;
  229. } else if (addr < (addr_t) (&dummy->regs.orig_gpr2)) {
  230. /*
  231. * access registers are stored in the thread structure
  232. */
  233. offset = addr - (addr_t) &dummy->regs.acrs;
  234. #ifdef CONFIG_64BIT
  235. /*
  236. * Very special case: old & broken 64 bit gdb writing
  237. * to acrs[15] with a 64 bit value. Ignore the lower
  238. * half of the value and write the upper 32 bit to
  239. * acrs[15]. Sick...
  240. */
  241. if (addr == (addr_t) &dummy->regs.acrs[15])
  242. child->thread.acrs[15] = (unsigned int) (data >> 32);
  243. else
  244. #endif
  245. *(addr_t *)((addr_t) &child->thread.acrs + offset) = data;
  246. } else if (addr == (addr_t) &dummy->regs.orig_gpr2) {
  247. /*
  248. * orig_gpr2 is stored on the kernel stack
  249. */
  250. task_pt_regs(child)->orig_gpr2 = data;
  251. } else if (addr < (addr_t) &dummy->regs.fp_regs) {
  252. /*
  253. * prevent writes of padding hole between
  254. * orig_gpr2 and fp_regs on s390.
  255. */
  256. return 0;
  257. } else if (addr < (addr_t) (&dummy->regs.fp_regs + 1)) {
  258. /*
  259. * floating point regs. are stored in the thread structure
  260. */
  261. if (addr == (addr_t) &dummy->regs.fp_regs.fpc &&
  262. (data & ~((unsigned long) FPC_VALID_MASK
  263. << (BITS_PER_LONG - 32))) != 0)
  264. return -EINVAL;
  265. offset = addr - (addr_t) &dummy->regs.fp_regs;
  266. *(addr_t *)((addr_t) &child->thread.fp_regs + offset) = data;
  267. } else if (addr < (addr_t) (&dummy->regs.per_info + 1)) {
  268. /*
  269. * per_info is found in the thread structure
  270. */
  271. offset = addr - (addr_t) &dummy->regs.per_info;
  272. *(addr_t *)((addr_t) &child->thread.per_info + offset) = data;
  273. }
  274. FixPerRegisters(child);
  275. return 0;
  276. }
  277. static int
  278. poke_user(struct task_struct *child, addr_t addr, addr_t data)
  279. {
  280. struct user *dummy = NULL;
  281. addr_t mask;
  282. /*
  283. * Stupid gdb peeks/pokes the access registers in 64 bit with
  284. * an alignment of 4. Programmers from hell indeed...
  285. */
  286. mask = __ADDR_MASK;
  287. #ifdef CONFIG_64BIT
  288. if (addr >= (addr_t) &dummy->regs.acrs &&
  289. addr < (addr_t) &dummy->regs.orig_gpr2)
  290. mask = 3;
  291. #endif
  292. if ((addr & mask) || addr > sizeof(struct user) - __ADDR_MASK)
  293. return -EIO;
  294. return __poke_user(child, addr, data);
  295. }
  296. long arch_ptrace(struct task_struct *child, long request, long addr, long data)
  297. {
  298. ptrace_area parea;
  299. int copied, ret;
  300. switch (request) {
  301. case PTRACE_PEEKTEXT:
  302. case PTRACE_PEEKDATA:
  303. /* Remove high order bit from address (only for 31 bit). */
  304. addr &= PSW_ADDR_INSN;
  305. /* read word at location addr. */
  306. return generic_ptrace_peekdata(child, addr, data);
  307. case PTRACE_PEEKUSR:
  308. /* read the word at location addr in the USER area. */
  309. return peek_user(child, addr, data);
  310. case PTRACE_POKETEXT:
  311. case PTRACE_POKEDATA:
  312. /* Remove high order bit from address (only for 31 bit). */
  313. addr &= PSW_ADDR_INSN;
  314. /* write the word at location addr. */
  315. return generic_ptrace_pokedata(child, addr, data);
  316. case PTRACE_POKEUSR:
  317. /* write the word at location addr in the USER area */
  318. return poke_user(child, addr, data);
  319. case PTRACE_PEEKUSR_AREA:
  320. case PTRACE_POKEUSR_AREA:
  321. if (copy_from_user(&parea, (void __force __user *) addr,
  322. sizeof(parea)))
  323. return -EFAULT;
  324. addr = parea.kernel_addr;
  325. data = parea.process_addr;
  326. copied = 0;
  327. while (copied < parea.len) {
  328. if (request == PTRACE_PEEKUSR_AREA)
  329. ret = peek_user(child, addr, data);
  330. else {
  331. addr_t utmp;
  332. if (get_user(utmp,
  333. (addr_t __force __user *) data))
  334. return -EFAULT;
  335. ret = poke_user(child, addr, utmp);
  336. }
  337. if (ret)
  338. return ret;
  339. addr += sizeof(unsigned long);
  340. data += sizeof(unsigned long);
  341. copied += sizeof(unsigned long);
  342. }
  343. return 0;
  344. }
  345. return ptrace_request(child, request, addr, data);
  346. }
  347. #ifdef CONFIG_COMPAT
  348. /*
  349. * Now the fun part starts... a 31 bit program running in the
  350. * 31 bit emulation tracing another program. PTRACE_PEEKTEXT,
  351. * PTRACE_PEEKDATA, PTRACE_POKETEXT and PTRACE_POKEDATA are easy
  352. * to handle, the difference to the 64 bit versions of the requests
  353. * is that the access is done in multiples of 4 byte instead of
  354. * 8 bytes (sizeof(unsigned long) on 31/64 bit).
  355. * The ugly part are PTRACE_PEEKUSR, PTRACE_PEEKUSR_AREA,
  356. * PTRACE_POKEUSR and PTRACE_POKEUSR_AREA. If the traced program
  357. * is a 31 bit program too, the content of struct user can be
  358. * emulated. A 31 bit program peeking into the struct user of
  359. * a 64 bit program is a no-no.
  360. */
  361. /*
  362. * Same as peek_user but for a 31 bit program.
  363. */
  364. static u32 __peek_user_compat(struct task_struct *child, addr_t addr)
  365. {
  366. struct user32 *dummy32 = NULL;
  367. per_struct32 *dummy_per32 = NULL;
  368. addr_t offset;
  369. __u32 tmp;
  370. if (addr < (addr_t) &dummy32->regs.acrs) {
  371. /*
  372. * psw and gprs are stored on the stack
  373. */
  374. if (addr == (addr_t) &dummy32->regs.psw.mask) {
  375. /* Fake a 31 bit psw mask. */
  376. tmp = (__u32)(task_pt_regs(child)->psw.mask >> 32);
  377. tmp = PSW32_MASK_MERGE(psw32_user_bits, tmp);
  378. } else if (addr == (addr_t) &dummy32->regs.psw.addr) {
  379. /* Fake a 31 bit psw address. */
  380. tmp = (__u32) task_pt_regs(child)->psw.addr |
  381. PSW32_ADDR_AMODE31;
  382. } else {
  383. /* gpr 0-15 */
  384. tmp = *(__u32 *)((addr_t) &task_pt_regs(child)->psw +
  385. addr*2 + 4);
  386. }
  387. } else if (addr < (addr_t) (&dummy32->regs.orig_gpr2)) {
  388. /*
  389. * access registers are stored in the thread structure
  390. */
  391. offset = addr - (addr_t) &dummy32->regs.acrs;
  392. tmp = *(__u32*)((addr_t) &child->thread.acrs + offset);
  393. } else if (addr == (addr_t) (&dummy32->regs.orig_gpr2)) {
  394. /*
  395. * orig_gpr2 is stored on the kernel stack
  396. */
  397. tmp = *(__u32*)((addr_t) &task_pt_regs(child)->orig_gpr2 + 4);
  398. } else if (addr < (addr_t) &dummy32->regs.fp_regs) {
  399. /*
  400. * prevent reads of padding hole between
  401. * orig_gpr2 and fp_regs on s390.
  402. */
  403. tmp = 0;
  404. } else if (addr < (addr_t) (&dummy32->regs.fp_regs + 1)) {
  405. /*
  406. * floating point regs. are stored in the thread structure
  407. */
  408. offset = addr - (addr_t) &dummy32->regs.fp_regs;
  409. tmp = *(__u32 *)((addr_t) &child->thread.fp_regs + offset);
  410. } else if (addr < (addr_t) (&dummy32->regs.per_info + 1)) {
  411. /*
  412. * per_info is found in the thread structure
  413. */
  414. offset = addr - (addr_t) &dummy32->regs.per_info;
  415. /* This is magic. See per_struct and per_struct32. */
  416. if ((offset >= (addr_t) &dummy_per32->control_regs &&
  417. offset < (addr_t) (&dummy_per32->control_regs + 1)) ||
  418. (offset >= (addr_t) &dummy_per32->starting_addr &&
  419. offset <= (addr_t) &dummy_per32->ending_addr) ||
  420. offset == (addr_t) &dummy_per32->lowcore.words.address)
  421. offset = offset*2 + 4;
  422. else
  423. offset = offset*2;
  424. tmp = *(__u32 *)((addr_t) &child->thread.per_info + offset);
  425. } else
  426. tmp = 0;
  427. return tmp;
  428. }
  429. static int peek_user_compat(struct task_struct *child,
  430. addr_t addr, addr_t data)
  431. {
  432. __u32 tmp;
  433. if (!test_thread_flag(TIF_31BIT) ||
  434. (addr & 3) || addr > sizeof(struct user) - 3)
  435. return -EIO;
  436. tmp = __peek_user_compat(child, addr);
  437. return put_user(tmp, (__u32 __user *) data);
  438. }
  439. /*
  440. * Same as poke_user but for a 31 bit program.
  441. */
  442. static int __poke_user_compat(struct task_struct *child,
  443. addr_t addr, addr_t data)
  444. {
  445. struct user32 *dummy32 = NULL;
  446. per_struct32 *dummy_per32 = NULL;
  447. __u32 tmp = (__u32) data;
  448. addr_t offset;
  449. if (addr < (addr_t) &dummy32->regs.acrs) {
  450. /*
  451. * psw, gprs, acrs and orig_gpr2 are stored on the stack
  452. */
  453. if (addr == (addr_t) &dummy32->regs.psw.mask) {
  454. /* Build a 64 bit psw mask from 31 bit mask. */
  455. if (tmp != PSW32_MASK_MERGE(psw32_user_bits, tmp))
  456. /* Invalid psw mask. */
  457. return -EINVAL;
  458. task_pt_regs(child)->psw.mask =
  459. PSW_MASK_MERGE(psw_user32_bits, (__u64) tmp << 32);
  460. } else if (addr == (addr_t) &dummy32->regs.psw.addr) {
  461. /* Build a 64 bit psw address from 31 bit address. */
  462. task_pt_regs(child)->psw.addr =
  463. (__u64) tmp & PSW32_ADDR_INSN;
  464. } else {
  465. /* gpr 0-15 */
  466. *(__u32*)((addr_t) &task_pt_regs(child)->psw
  467. + addr*2 + 4) = tmp;
  468. }
  469. } else if (addr < (addr_t) (&dummy32->regs.orig_gpr2)) {
  470. /*
  471. * access registers are stored in the thread structure
  472. */
  473. offset = addr - (addr_t) &dummy32->regs.acrs;
  474. *(__u32*)((addr_t) &child->thread.acrs + offset) = tmp;
  475. } else if (addr == (addr_t) (&dummy32->regs.orig_gpr2)) {
  476. /*
  477. * orig_gpr2 is stored on the kernel stack
  478. */
  479. *(__u32*)((addr_t) &task_pt_regs(child)->orig_gpr2 + 4) = tmp;
  480. } else if (addr < (addr_t) &dummy32->regs.fp_regs) {
  481. /*
  482. * prevent writess of padding hole between
  483. * orig_gpr2 and fp_regs on s390.
  484. */
  485. return 0;
  486. } else if (addr < (addr_t) (&dummy32->regs.fp_regs + 1)) {
  487. /*
  488. * floating point regs. are stored in the thread structure
  489. */
  490. if (addr == (addr_t) &dummy32->regs.fp_regs.fpc &&
  491. (tmp & ~FPC_VALID_MASK) != 0)
  492. /* Invalid floating point control. */
  493. return -EINVAL;
  494. offset = addr - (addr_t) &dummy32->regs.fp_regs;
  495. *(__u32 *)((addr_t) &child->thread.fp_regs + offset) = tmp;
  496. } else if (addr < (addr_t) (&dummy32->regs.per_info + 1)) {
  497. /*
  498. * per_info is found in the thread structure.
  499. */
  500. offset = addr - (addr_t) &dummy32->regs.per_info;
  501. /*
  502. * This is magic. See per_struct and per_struct32.
  503. * By incident the offsets in per_struct are exactly
  504. * twice the offsets in per_struct32 for all fields.
  505. * The 8 byte fields need special handling though,
  506. * because the second half (bytes 4-7) is needed and
  507. * not the first half.
  508. */
  509. if ((offset >= (addr_t) &dummy_per32->control_regs &&
  510. offset < (addr_t) (&dummy_per32->control_regs + 1)) ||
  511. (offset >= (addr_t) &dummy_per32->starting_addr &&
  512. offset <= (addr_t) &dummy_per32->ending_addr) ||
  513. offset == (addr_t) &dummy_per32->lowcore.words.address)
  514. offset = offset*2 + 4;
  515. else
  516. offset = offset*2;
  517. *(__u32 *)((addr_t) &child->thread.per_info + offset) = tmp;
  518. }
  519. FixPerRegisters(child);
  520. return 0;
  521. }
  522. static int poke_user_compat(struct task_struct *child,
  523. addr_t addr, addr_t data)
  524. {
  525. if (!test_thread_flag(TIF_31BIT) ||
  526. (addr & 3) || addr > sizeof(struct user32) - 3)
  527. return -EIO;
  528. return __poke_user_compat(child, addr, data);
  529. }
  530. long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
  531. compat_ulong_t caddr, compat_ulong_t cdata)
  532. {
  533. unsigned long addr = caddr;
  534. unsigned long data = cdata;
  535. ptrace_area_emu31 parea;
  536. int copied, ret;
  537. switch (request) {
  538. case PTRACE_PEEKUSR:
  539. /* read the word at location addr in the USER area. */
  540. return peek_user_compat(child, addr, data);
  541. case PTRACE_POKEUSR:
  542. /* write the word at location addr in the USER area */
  543. return poke_user_compat(child, addr, data);
  544. case PTRACE_PEEKUSR_AREA:
  545. case PTRACE_POKEUSR_AREA:
  546. if (copy_from_user(&parea, (void __force __user *) addr,
  547. sizeof(parea)))
  548. return -EFAULT;
  549. addr = parea.kernel_addr;
  550. data = parea.process_addr;
  551. copied = 0;
  552. while (copied < parea.len) {
  553. if (request == PTRACE_PEEKUSR_AREA)
  554. ret = peek_user_compat(child, addr, data);
  555. else {
  556. __u32 utmp;
  557. if (get_user(utmp,
  558. (__u32 __force __user *) data))
  559. return -EFAULT;
  560. ret = poke_user_compat(child, addr, utmp);
  561. }
  562. if (ret)
  563. return ret;
  564. addr += sizeof(unsigned int);
  565. data += sizeof(unsigned int);
  566. copied += sizeof(unsigned int);
  567. }
  568. return 0;
  569. }
  570. return compat_ptrace_request(child, request, addr, data);
  571. }
  572. #endif
  573. asmlinkage void
  574. syscall_trace(struct pt_regs *regs, int entryexit)
  575. {
  576. if (unlikely(current->audit_context) && entryexit)
  577. audit_syscall_exit(AUDITSC_RESULT(regs->gprs[2]), regs->gprs[2]);
  578. if (!test_thread_flag(TIF_SYSCALL_TRACE))
  579. goto out;
  580. if (!(current->ptrace & PT_PTRACED))
  581. goto out;
  582. ptrace_notify(SIGTRAP | ((current->ptrace & PT_TRACESYSGOOD)
  583. ? 0x80 : 0));
  584. /*
  585. * If the debuffer has set an invalid system call number,
  586. * we prepare to skip the system call restart handling.
  587. */
  588. if (!entryexit && regs->gprs[2] >= NR_syscalls)
  589. regs->trap = -1;
  590. /*
  591. * this isn't the same as continuing with a signal, but it will do
  592. * for normal use. strace only continues with a signal if the
  593. * stopping signal is not SIGTRAP. -brl
  594. */
  595. if (current->exit_code) {
  596. send_sig(current->exit_code, current, 1);
  597. current->exit_code = 0;
  598. }
  599. out:
  600. if (unlikely(current->audit_context) && !entryexit)
  601. audit_syscall_entry(test_thread_flag(TIF_31BIT)?AUDIT_ARCH_S390:AUDIT_ARCH_S390X,
  602. regs->gprs[2], regs->orig_gpr2, regs->gprs[3],
  603. regs->gprs[4], regs->gprs[5]);
  604. }
  605. /*
  606. * user_regset definitions.
  607. */
  608. static int s390_regs_get(struct task_struct *target,
  609. const struct user_regset *regset,
  610. unsigned int pos, unsigned int count,
  611. void *kbuf, void __user *ubuf)
  612. {
  613. if (target == current)
  614. save_access_regs(target->thread.acrs);
  615. if (kbuf) {
  616. unsigned long *k = kbuf;
  617. while (count > 0) {
  618. *k++ = __peek_user(target, pos);
  619. count -= sizeof(*k);
  620. pos += sizeof(*k);
  621. }
  622. } else {
  623. unsigned long __user *u = ubuf;
  624. while (count > 0) {
  625. if (__put_user(__peek_user(target, pos), u++))
  626. return -EFAULT;
  627. count -= sizeof(*u);
  628. pos += sizeof(*u);
  629. }
  630. }
  631. return 0;
  632. }
  633. static int s390_regs_set(struct task_struct *target,
  634. const struct user_regset *regset,
  635. unsigned int pos, unsigned int count,
  636. const void *kbuf, const void __user *ubuf)
  637. {
  638. int rc = 0;
  639. if (target == current)
  640. save_access_regs(target->thread.acrs);
  641. if (kbuf) {
  642. const unsigned long *k = kbuf;
  643. while (count > 0 && !rc) {
  644. rc = __poke_user(target, pos, *k++);
  645. count -= sizeof(*k);
  646. pos += sizeof(*k);
  647. }
  648. } else {
  649. const unsigned long __user *u = ubuf;
  650. while (count > 0 && !rc) {
  651. unsigned long word;
  652. rc = __get_user(word, u++);
  653. if (rc)
  654. break;
  655. rc = __poke_user(target, pos, word);
  656. count -= sizeof(*u);
  657. pos += sizeof(*u);
  658. }
  659. }
  660. if (rc == 0 && target == current)
  661. restore_access_regs(target->thread.acrs);
  662. return rc;
  663. }
  664. static int s390_fpregs_get(struct task_struct *target,
  665. const struct user_regset *regset, unsigned int pos,
  666. unsigned int count, void *kbuf, void __user *ubuf)
  667. {
  668. if (target == current)
  669. save_fp_regs(&target->thread.fp_regs);
  670. return user_regset_copyout(&pos, &count, &kbuf, &ubuf,
  671. &target->thread.fp_regs, 0, -1);
  672. }
  673. static int s390_fpregs_set(struct task_struct *target,
  674. const struct user_regset *regset, unsigned int pos,
  675. unsigned int count, const void *kbuf,
  676. const void __user *ubuf)
  677. {
  678. int rc = 0;
  679. if (target == current)
  680. save_fp_regs(&target->thread.fp_regs);
  681. /* If setting FPC, must validate it first. */
  682. if (count > 0 && pos < offsetof(s390_fp_regs, fprs)) {
  683. u32 fpc[2] = { target->thread.fp_regs.fpc, 0 };
  684. rc = user_regset_copyin(&pos, &count, &kbuf, &ubuf, &fpc,
  685. 0, offsetof(s390_fp_regs, fprs));
  686. if (rc)
  687. return rc;
  688. if ((fpc[0] & ~FPC_VALID_MASK) != 0 || fpc[1] != 0)
  689. return -EINVAL;
  690. target->thread.fp_regs.fpc = fpc[0];
  691. }
  692. if (rc == 0 && count > 0)
  693. rc = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
  694. target->thread.fp_regs.fprs,
  695. offsetof(s390_fp_regs, fprs), -1);
  696. if (rc == 0 && target == current)
  697. restore_fp_regs(&target->thread.fp_regs);
  698. return rc;
  699. }
  700. static const struct user_regset s390_regsets[] = {
  701. [REGSET_GENERAL] = {
  702. .core_note_type = NT_PRSTATUS,
  703. .n = sizeof(s390_regs) / sizeof(long),
  704. .size = sizeof(long),
  705. .align = sizeof(long),
  706. .get = s390_regs_get,
  707. .set = s390_regs_set,
  708. },
  709. [REGSET_FP] = {
  710. .core_note_type = NT_PRFPREG,
  711. .n = sizeof(s390_fp_regs) / sizeof(long),
  712. .size = sizeof(long),
  713. .align = sizeof(long),
  714. .get = s390_fpregs_get,
  715. .set = s390_fpregs_set,
  716. },
  717. };
  718. static const struct user_regset_view user_s390_view = {
  719. .name = UTS_MACHINE,
  720. .e_machine = EM_S390,
  721. .regsets = s390_regsets,
  722. .n = ARRAY_SIZE(s390_regsets)
  723. };
  724. #ifdef CONFIG_COMPAT
  725. static int s390_compat_regs_get(struct task_struct *target,
  726. const struct user_regset *regset,
  727. unsigned int pos, unsigned int count,
  728. void *kbuf, void __user *ubuf)
  729. {
  730. if (target == current)
  731. save_access_regs(target->thread.acrs);
  732. if (kbuf) {
  733. compat_ulong_t *k = kbuf;
  734. while (count > 0) {
  735. *k++ = __peek_user_compat(target, pos);
  736. count -= sizeof(*k);
  737. pos += sizeof(*k);
  738. }
  739. } else {
  740. compat_ulong_t __user *u = ubuf;
  741. while (count > 0) {
  742. if (__put_user(__peek_user_compat(target, pos), u++))
  743. return -EFAULT;
  744. count -= sizeof(*u);
  745. pos += sizeof(*u);
  746. }
  747. }
  748. return 0;
  749. }
  750. static int s390_compat_regs_set(struct task_struct *target,
  751. const struct user_regset *regset,
  752. unsigned int pos, unsigned int count,
  753. const void *kbuf, const void __user *ubuf)
  754. {
  755. int rc = 0;
  756. if (target == current)
  757. save_access_regs(target->thread.acrs);
  758. if (kbuf) {
  759. const compat_ulong_t *k = kbuf;
  760. while (count > 0 && !rc) {
  761. rc = __poke_user_compat(target, pos, *k++);
  762. count -= sizeof(*k);
  763. pos += sizeof(*k);
  764. }
  765. } else {
  766. const compat_ulong_t __user *u = ubuf;
  767. while (count > 0 && !rc) {
  768. compat_ulong_t word;
  769. rc = __get_user(word, u++);
  770. if (rc)
  771. break;
  772. rc = __poke_user_compat(target, pos, word);
  773. count -= sizeof(*u);
  774. pos += sizeof(*u);
  775. }
  776. }
  777. if (rc == 0 && target == current)
  778. restore_access_regs(target->thread.acrs);
  779. return rc;
  780. }
  781. static const struct user_regset s390_compat_regsets[] = {
  782. [REGSET_GENERAL] = {
  783. .core_note_type = NT_PRSTATUS,
  784. .n = sizeof(s390_compat_regs) / sizeof(compat_long_t),
  785. .size = sizeof(compat_long_t),
  786. .align = sizeof(compat_long_t),
  787. .get = s390_compat_regs_get,
  788. .set = s390_compat_regs_set,
  789. },
  790. [REGSET_FP] = {
  791. .core_note_type = NT_PRFPREG,
  792. .n = sizeof(s390_fp_regs) / sizeof(compat_long_t),
  793. .size = sizeof(compat_long_t),
  794. .align = sizeof(compat_long_t),
  795. .get = s390_fpregs_get,
  796. .set = s390_fpregs_set,
  797. },
  798. };
  799. static const struct user_regset_view user_s390_compat_view = {
  800. .name = "s390",
  801. .e_machine = EM_S390,
  802. .regsets = s390_compat_regsets,
  803. .n = ARRAY_SIZE(s390_compat_regsets)
  804. };
  805. #endif
  806. const struct user_regset_view *task_user_regset_view(struct task_struct *task)
  807. {
  808. #ifdef CONFIG_COMPAT
  809. if (test_tsk_thread_flag(task, TIF_31BIT))
  810. return &user_s390_compat_view;
  811. #endif
  812. return &user_s390_view;
  813. }