ptrace.c 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916
  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 <linux/tracehook.h>
  38. #include <asm/segment.h>
  39. #include <asm/page.h>
  40. #include <asm/pgtable.h>
  41. #include <asm/pgalloc.h>
  42. #include <asm/system.h>
  43. #include <asm/uaccess.h>
  44. #include <asm/unistd.h>
  45. #include "entry.h"
  46. #ifdef CONFIG_COMPAT
  47. #include "compat_ptrace.h"
  48. #endif
  49. enum s390_regset {
  50. REGSET_GENERAL,
  51. REGSET_FP,
  52. };
  53. static void
  54. FixPerRegisters(struct task_struct *task)
  55. {
  56. struct pt_regs *regs;
  57. per_struct *per_info;
  58. regs = task_pt_regs(task);
  59. per_info = (per_struct *) &task->thread.per_info;
  60. per_info->control_regs.bits.em_instruction_fetch =
  61. per_info->single_step | per_info->instruction_fetch;
  62. if (per_info->single_step) {
  63. per_info->control_regs.bits.starting_addr = 0;
  64. #ifdef CONFIG_COMPAT
  65. if (test_thread_flag(TIF_31BIT))
  66. per_info->control_regs.bits.ending_addr = 0x7fffffffUL;
  67. else
  68. #endif
  69. per_info->control_regs.bits.ending_addr = PSW_ADDR_INSN;
  70. } else {
  71. per_info->control_regs.bits.starting_addr =
  72. per_info->starting_addr;
  73. per_info->control_regs.bits.ending_addr =
  74. per_info->ending_addr;
  75. }
  76. /*
  77. * if any of the control reg tracing bits are on
  78. * we switch on per in the psw
  79. */
  80. if (per_info->control_regs.words.cr[0] & PER_EM_MASK)
  81. regs->psw.mask |= PSW_MASK_PER;
  82. else
  83. regs->psw.mask &= ~PSW_MASK_PER;
  84. if (per_info->control_regs.bits.em_storage_alteration)
  85. per_info->control_regs.bits.storage_alt_space_ctl = 1;
  86. else
  87. per_info->control_regs.bits.storage_alt_space_ctl = 0;
  88. }
  89. void user_enable_single_step(struct task_struct *task)
  90. {
  91. task->thread.per_info.single_step = 1;
  92. FixPerRegisters(task);
  93. }
  94. void user_disable_single_step(struct task_struct *task)
  95. {
  96. task->thread.per_info.single_step = 0;
  97. FixPerRegisters(task);
  98. }
  99. /*
  100. * Called by kernel/ptrace.c when detaching..
  101. *
  102. * Make sure single step bits etc are not set.
  103. */
  104. void
  105. ptrace_disable(struct task_struct *child)
  106. {
  107. /* make sure the single step bit is not set. */
  108. user_disable_single_step(child);
  109. }
  110. #ifndef CONFIG_64BIT
  111. # define __ADDR_MASK 3
  112. #else
  113. # define __ADDR_MASK 7
  114. #endif
  115. /*
  116. * Read the word at offset addr from the user area of a process. The
  117. * trouble here is that the information is littered over different
  118. * locations. The process registers are found on the kernel stack,
  119. * the floating point stuff and the trace settings are stored in
  120. * the task structure. In addition the different structures in
  121. * struct user contain pad bytes that should be read as zeroes.
  122. * Lovely...
  123. */
  124. static unsigned long __peek_user(struct task_struct *child, addr_t addr)
  125. {
  126. struct user *dummy = NULL;
  127. addr_t offset, tmp;
  128. if (addr < (addr_t) &dummy->regs.acrs) {
  129. /*
  130. * psw and gprs are stored on the stack
  131. */
  132. tmp = *(addr_t *)((addr_t) &task_pt_regs(child)->psw + addr);
  133. if (addr == (addr_t) &dummy->regs.psw.mask)
  134. /* Remove per bit from user psw. */
  135. tmp &= ~PSW_MASK_PER;
  136. } else if (addr < (addr_t) &dummy->regs.orig_gpr2) {
  137. /*
  138. * access registers are stored in the thread structure
  139. */
  140. offset = addr - (addr_t) &dummy->regs.acrs;
  141. #ifdef CONFIG_64BIT
  142. /*
  143. * Very special case: old & broken 64 bit gdb reading
  144. * from acrs[15]. Result is a 64 bit value. Read the
  145. * 32 bit acrs[15] value and shift it by 32. Sick...
  146. */
  147. if (addr == (addr_t) &dummy->regs.acrs[15])
  148. tmp = ((unsigned long) child->thread.acrs[15]) << 32;
  149. else
  150. #endif
  151. tmp = *(addr_t *)((addr_t) &child->thread.acrs + offset);
  152. } else if (addr == (addr_t) &dummy->regs.orig_gpr2) {
  153. /*
  154. * orig_gpr2 is stored on the kernel stack
  155. */
  156. tmp = (addr_t) task_pt_regs(child)->orig_gpr2;
  157. } else if (addr < (addr_t) &dummy->regs.fp_regs) {
  158. /*
  159. * prevent reads of padding hole between
  160. * orig_gpr2 and fp_regs on s390.
  161. */
  162. tmp = 0;
  163. } else if (addr < (addr_t) (&dummy->regs.fp_regs + 1)) {
  164. /*
  165. * floating point regs. are stored in the thread structure
  166. */
  167. offset = addr - (addr_t) &dummy->regs.fp_regs;
  168. tmp = *(addr_t *)((addr_t) &child->thread.fp_regs + offset);
  169. if (addr == (addr_t) &dummy->regs.fp_regs.fpc)
  170. tmp &= (unsigned long) FPC_VALID_MASK
  171. << (BITS_PER_LONG - 32);
  172. } else if (addr < (addr_t) (&dummy->regs.per_info + 1)) {
  173. /*
  174. * per_info is found in the thread structure
  175. */
  176. offset = addr - (addr_t) &dummy->regs.per_info;
  177. tmp = *(addr_t *)((addr_t) &child->thread.per_info + offset);
  178. } else
  179. tmp = 0;
  180. return tmp;
  181. }
  182. static int
  183. peek_user(struct task_struct *child, addr_t addr, addr_t data)
  184. {
  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) &((struct user *) NULL)->regs.acrs &&
  193. addr < (addr_t) &((struct user *) NULL)->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. addr_t mask;
  281. /*
  282. * Stupid gdb peeks/pokes the access registers in 64 bit with
  283. * an alignment of 4. Programmers from hell indeed...
  284. */
  285. mask = __ADDR_MASK;
  286. #ifdef CONFIG_64BIT
  287. if (addr >= (addr_t) &((struct user *) NULL)->regs.acrs &&
  288. addr < (addr_t) &((struct user *) NULL)->regs.orig_gpr2)
  289. mask = 3;
  290. #endif
  291. if ((addr & mask) || addr > sizeof(struct user) - __ADDR_MASK)
  292. return -EIO;
  293. return __poke_user(child, addr, data);
  294. }
  295. long arch_ptrace(struct task_struct *child, long request, long addr, long data)
  296. {
  297. ptrace_area parea;
  298. int copied, ret;
  299. switch (request) {
  300. case PTRACE_PEEKTEXT:
  301. case PTRACE_PEEKDATA:
  302. /* Remove high order bit from address (only for 31 bit). */
  303. addr &= PSW_ADDR_INSN;
  304. /* read word at location addr. */
  305. return generic_ptrace_peekdata(child, addr, data);
  306. case PTRACE_PEEKUSR:
  307. /* read the word at location addr in the USER area. */
  308. return peek_user(child, addr, data);
  309. case PTRACE_POKETEXT:
  310. case PTRACE_POKEDATA:
  311. /* Remove high order bit from address (only for 31 bit). */
  312. addr &= PSW_ADDR_INSN;
  313. /* write the word at location addr. */
  314. return generic_ptrace_pokedata(child, addr, data);
  315. case PTRACE_POKEUSR:
  316. /* write the word at location addr in the USER area */
  317. return poke_user(child, addr, data);
  318. case PTRACE_PEEKUSR_AREA:
  319. case PTRACE_POKEUSR_AREA:
  320. if (copy_from_user(&parea, (void __force __user *) addr,
  321. sizeof(parea)))
  322. return -EFAULT;
  323. addr = parea.kernel_addr;
  324. data = parea.process_addr;
  325. copied = 0;
  326. while (copied < parea.len) {
  327. if (request == PTRACE_PEEKUSR_AREA)
  328. ret = peek_user(child, addr, data);
  329. else {
  330. addr_t utmp;
  331. if (get_user(utmp,
  332. (addr_t __force __user *) data))
  333. return -EFAULT;
  334. ret = poke_user(child, addr, utmp);
  335. }
  336. if (ret)
  337. return ret;
  338. addr += sizeof(unsigned long);
  339. data += sizeof(unsigned long);
  340. copied += sizeof(unsigned long);
  341. }
  342. return 0;
  343. }
  344. return ptrace_request(child, request, addr, data);
  345. }
  346. #ifdef CONFIG_COMPAT
  347. /*
  348. * Now the fun part starts... a 31 bit program running in the
  349. * 31 bit emulation tracing another program. PTRACE_PEEKTEXT,
  350. * PTRACE_PEEKDATA, PTRACE_POKETEXT and PTRACE_POKEDATA are easy
  351. * to handle, the difference to the 64 bit versions of the requests
  352. * is that the access is done in multiples of 4 byte instead of
  353. * 8 bytes (sizeof(unsigned long) on 31/64 bit).
  354. * The ugly part are PTRACE_PEEKUSR, PTRACE_PEEKUSR_AREA,
  355. * PTRACE_POKEUSR and PTRACE_POKEUSR_AREA. If the traced program
  356. * is a 31 bit program too, the content of struct user can be
  357. * emulated. A 31 bit program peeking into the struct user of
  358. * a 64 bit program is a no-no.
  359. */
  360. /*
  361. * Same as peek_user but for a 31 bit program.
  362. */
  363. static u32 __peek_user_compat(struct task_struct *child, addr_t addr)
  364. {
  365. struct user32 *dummy32 = NULL;
  366. per_struct32 *dummy_per32 = NULL;
  367. addr_t offset;
  368. __u32 tmp;
  369. if (addr < (addr_t) &dummy32->regs.acrs) {
  370. /*
  371. * psw and gprs are stored on the stack
  372. */
  373. if (addr == (addr_t) &dummy32->regs.psw.mask) {
  374. /* Fake a 31 bit psw mask. */
  375. tmp = (__u32)(task_pt_regs(child)->psw.mask >> 32);
  376. tmp = PSW32_MASK_MERGE(psw32_user_bits, tmp);
  377. } else if (addr == (addr_t) &dummy32->regs.psw.addr) {
  378. /* Fake a 31 bit psw address. */
  379. tmp = (__u32) task_pt_regs(child)->psw.addr |
  380. PSW32_ADDR_AMODE31;
  381. } else {
  382. /* gpr 0-15 */
  383. tmp = *(__u32 *)((addr_t) &task_pt_regs(child)->psw +
  384. addr*2 + 4);
  385. }
  386. } else if (addr < (addr_t) (&dummy32->regs.orig_gpr2)) {
  387. /*
  388. * access registers are stored in the thread structure
  389. */
  390. offset = addr - (addr_t) &dummy32->regs.acrs;
  391. tmp = *(__u32*)((addr_t) &child->thread.acrs + offset);
  392. } else if (addr == (addr_t) (&dummy32->regs.orig_gpr2)) {
  393. /*
  394. * orig_gpr2 is stored on the kernel stack
  395. */
  396. tmp = *(__u32*)((addr_t) &task_pt_regs(child)->orig_gpr2 + 4);
  397. } else if (addr < (addr_t) &dummy32->regs.fp_regs) {
  398. /*
  399. * prevent reads of padding hole between
  400. * orig_gpr2 and fp_regs on s390.
  401. */
  402. tmp = 0;
  403. } else if (addr < (addr_t) (&dummy32->regs.fp_regs + 1)) {
  404. /*
  405. * floating point regs. are stored in the thread structure
  406. */
  407. offset = addr - (addr_t) &dummy32->regs.fp_regs;
  408. tmp = *(__u32 *)((addr_t) &child->thread.fp_regs + offset);
  409. } else if (addr < (addr_t) (&dummy32->regs.per_info + 1)) {
  410. /*
  411. * per_info is found in the thread structure
  412. */
  413. offset = addr - (addr_t) &dummy32->regs.per_info;
  414. /* This is magic. See per_struct and per_struct32. */
  415. if ((offset >= (addr_t) &dummy_per32->control_regs &&
  416. offset < (addr_t) (&dummy_per32->control_regs + 1)) ||
  417. (offset >= (addr_t) &dummy_per32->starting_addr &&
  418. offset <= (addr_t) &dummy_per32->ending_addr) ||
  419. offset == (addr_t) &dummy_per32->lowcore.words.address)
  420. offset = offset*2 + 4;
  421. else
  422. offset = offset*2;
  423. tmp = *(__u32 *)((addr_t) &child->thread.per_info + offset);
  424. } else
  425. tmp = 0;
  426. return tmp;
  427. }
  428. static int peek_user_compat(struct task_struct *child,
  429. addr_t addr, addr_t data)
  430. {
  431. __u32 tmp;
  432. if (!test_thread_flag(TIF_31BIT) ||
  433. (addr & 3) || addr > sizeof(struct user) - 3)
  434. return -EIO;
  435. tmp = __peek_user_compat(child, addr);
  436. return put_user(tmp, (__u32 __user *) data);
  437. }
  438. /*
  439. * Same as poke_user but for a 31 bit program.
  440. */
  441. static int __poke_user_compat(struct task_struct *child,
  442. addr_t addr, addr_t data)
  443. {
  444. struct user32 *dummy32 = NULL;
  445. per_struct32 *dummy_per32 = NULL;
  446. __u32 tmp = (__u32) data;
  447. addr_t offset;
  448. if (addr < (addr_t) &dummy32->regs.acrs) {
  449. /*
  450. * psw, gprs, acrs and orig_gpr2 are stored on the stack
  451. */
  452. if (addr == (addr_t) &dummy32->regs.psw.mask) {
  453. /* Build a 64 bit psw mask from 31 bit mask. */
  454. if (tmp != PSW32_MASK_MERGE(psw32_user_bits, tmp))
  455. /* Invalid psw mask. */
  456. return -EINVAL;
  457. task_pt_regs(child)->psw.mask =
  458. PSW_MASK_MERGE(psw_user32_bits, (__u64) tmp << 32);
  459. } else if (addr == (addr_t) &dummy32->regs.psw.addr) {
  460. /* Build a 64 bit psw address from 31 bit address. */
  461. task_pt_regs(child)->psw.addr =
  462. (__u64) tmp & PSW32_ADDR_INSN;
  463. } else {
  464. /* gpr 0-15 */
  465. *(__u32*)((addr_t) &task_pt_regs(child)->psw
  466. + addr*2 + 4) = tmp;
  467. }
  468. } else if (addr < (addr_t) (&dummy32->regs.orig_gpr2)) {
  469. /*
  470. * access registers are stored in the thread structure
  471. */
  472. offset = addr - (addr_t) &dummy32->regs.acrs;
  473. *(__u32*)((addr_t) &child->thread.acrs + offset) = tmp;
  474. } else if (addr == (addr_t) (&dummy32->regs.orig_gpr2)) {
  475. /*
  476. * orig_gpr2 is stored on the kernel stack
  477. */
  478. *(__u32*)((addr_t) &task_pt_regs(child)->orig_gpr2 + 4) = tmp;
  479. } else if (addr < (addr_t) &dummy32->regs.fp_regs) {
  480. /*
  481. * prevent writess of padding hole between
  482. * orig_gpr2 and fp_regs on s390.
  483. */
  484. return 0;
  485. } else if (addr < (addr_t) (&dummy32->regs.fp_regs + 1)) {
  486. /*
  487. * floating point regs. are stored in the thread structure
  488. */
  489. if (addr == (addr_t) &dummy32->regs.fp_regs.fpc &&
  490. (tmp & ~FPC_VALID_MASK) != 0)
  491. /* Invalid floating point control. */
  492. return -EINVAL;
  493. offset = addr - (addr_t) &dummy32->regs.fp_regs;
  494. *(__u32 *)((addr_t) &child->thread.fp_regs + offset) = tmp;
  495. } else if (addr < (addr_t) (&dummy32->regs.per_info + 1)) {
  496. /*
  497. * per_info is found in the thread structure.
  498. */
  499. offset = addr - (addr_t) &dummy32->regs.per_info;
  500. /*
  501. * This is magic. See per_struct and per_struct32.
  502. * By incident the offsets in per_struct are exactly
  503. * twice the offsets in per_struct32 for all fields.
  504. * The 8 byte fields need special handling though,
  505. * because the second half (bytes 4-7) is needed and
  506. * not the first half.
  507. */
  508. if ((offset >= (addr_t) &dummy_per32->control_regs &&
  509. offset < (addr_t) (&dummy_per32->control_regs + 1)) ||
  510. (offset >= (addr_t) &dummy_per32->starting_addr &&
  511. offset <= (addr_t) &dummy_per32->ending_addr) ||
  512. offset == (addr_t) &dummy_per32->lowcore.words.address)
  513. offset = offset*2 + 4;
  514. else
  515. offset = offset*2;
  516. *(__u32 *)((addr_t) &child->thread.per_info + offset) = tmp;
  517. }
  518. FixPerRegisters(child);
  519. return 0;
  520. }
  521. static int poke_user_compat(struct task_struct *child,
  522. addr_t addr, addr_t data)
  523. {
  524. if (!test_thread_flag(TIF_31BIT) ||
  525. (addr & 3) || addr > sizeof(struct user32) - 3)
  526. return -EIO;
  527. return __poke_user_compat(child, addr, data);
  528. }
  529. long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
  530. compat_ulong_t caddr, compat_ulong_t cdata)
  531. {
  532. unsigned long addr = caddr;
  533. unsigned long data = cdata;
  534. ptrace_area_emu31 parea;
  535. int copied, ret;
  536. switch (request) {
  537. case PTRACE_PEEKUSR:
  538. /* read the word at location addr in the USER area. */
  539. return peek_user_compat(child, addr, data);
  540. case PTRACE_POKEUSR:
  541. /* write the word at location addr in the USER area */
  542. return poke_user_compat(child, addr, data);
  543. case PTRACE_PEEKUSR_AREA:
  544. case PTRACE_POKEUSR_AREA:
  545. if (copy_from_user(&parea, (void __force __user *) addr,
  546. sizeof(parea)))
  547. return -EFAULT;
  548. addr = parea.kernel_addr;
  549. data = parea.process_addr;
  550. copied = 0;
  551. while (copied < parea.len) {
  552. if (request == PTRACE_PEEKUSR_AREA)
  553. ret = peek_user_compat(child, addr, data);
  554. else {
  555. __u32 utmp;
  556. if (get_user(utmp,
  557. (__u32 __force __user *) data))
  558. return -EFAULT;
  559. ret = poke_user_compat(child, addr, utmp);
  560. }
  561. if (ret)
  562. return ret;
  563. addr += sizeof(unsigned int);
  564. data += sizeof(unsigned int);
  565. copied += sizeof(unsigned int);
  566. }
  567. return 0;
  568. }
  569. return compat_ptrace_request(child, request, addr, data);
  570. }
  571. #endif
  572. asmlinkage long do_syscall_trace_enter(struct pt_regs *regs)
  573. {
  574. long ret;
  575. /*
  576. * The sysc_tracesys code in entry.S stored the system
  577. * call number to gprs[2].
  578. */
  579. ret = regs->gprs[2];
  580. if (test_thread_flag(TIF_SYSCALL_TRACE) &&
  581. (tracehook_report_syscall_entry(regs) ||
  582. regs->gprs[2] >= NR_syscalls)) {
  583. /*
  584. * Tracing decided this syscall should not happen or the
  585. * debugger stored an invalid system call number. Skip
  586. * the system call and the system call restart handling.
  587. */
  588. regs->svcnr = 0;
  589. ret = -1;
  590. }
  591. if (unlikely(current->audit_context))
  592. audit_syscall_entry(test_thread_flag(TIF_31BIT) ?
  593. AUDIT_ARCH_S390 : AUDIT_ARCH_S390X,
  594. regs->gprs[2], regs->orig_gpr2,
  595. regs->gprs[3], regs->gprs[4],
  596. regs->gprs[5]);
  597. return ret;
  598. }
  599. asmlinkage void do_syscall_trace_exit(struct pt_regs *regs)
  600. {
  601. if (unlikely(current->audit_context))
  602. audit_syscall_exit(AUDITSC_RESULT(regs->gprs[2]),
  603. regs->gprs[2]);
  604. if (test_thread_flag(TIF_SYSCALL_TRACE))
  605. tracehook_report_syscall_exit(regs, 0);
  606. }
  607. /*
  608. * user_regset definitions.
  609. */
  610. static int s390_regs_get(struct task_struct *target,
  611. const struct user_regset *regset,
  612. unsigned int pos, unsigned int count,
  613. void *kbuf, void __user *ubuf)
  614. {
  615. if (target == current)
  616. save_access_regs(target->thread.acrs);
  617. if (kbuf) {
  618. unsigned long *k = kbuf;
  619. while (count > 0) {
  620. *k++ = __peek_user(target, pos);
  621. count -= sizeof(*k);
  622. pos += sizeof(*k);
  623. }
  624. } else {
  625. unsigned long __user *u = ubuf;
  626. while (count > 0) {
  627. if (__put_user(__peek_user(target, pos), u++))
  628. return -EFAULT;
  629. count -= sizeof(*u);
  630. pos += sizeof(*u);
  631. }
  632. }
  633. return 0;
  634. }
  635. static int s390_regs_set(struct task_struct *target,
  636. const struct user_regset *regset,
  637. unsigned int pos, unsigned int count,
  638. const void *kbuf, const void __user *ubuf)
  639. {
  640. int rc = 0;
  641. if (target == current)
  642. save_access_regs(target->thread.acrs);
  643. if (kbuf) {
  644. const unsigned long *k = kbuf;
  645. while (count > 0 && !rc) {
  646. rc = __poke_user(target, pos, *k++);
  647. count -= sizeof(*k);
  648. pos += sizeof(*k);
  649. }
  650. } else {
  651. const unsigned long __user *u = ubuf;
  652. while (count > 0 && !rc) {
  653. unsigned long word;
  654. rc = __get_user(word, u++);
  655. if (rc)
  656. break;
  657. rc = __poke_user(target, pos, word);
  658. count -= sizeof(*u);
  659. pos += sizeof(*u);
  660. }
  661. }
  662. if (rc == 0 && target == current)
  663. restore_access_regs(target->thread.acrs);
  664. return rc;
  665. }
  666. static int s390_fpregs_get(struct task_struct *target,
  667. const struct user_regset *regset, unsigned int pos,
  668. unsigned int count, void *kbuf, void __user *ubuf)
  669. {
  670. if (target == current)
  671. save_fp_regs(&target->thread.fp_regs);
  672. return user_regset_copyout(&pos, &count, &kbuf, &ubuf,
  673. &target->thread.fp_regs, 0, -1);
  674. }
  675. static int s390_fpregs_set(struct task_struct *target,
  676. const struct user_regset *regset, unsigned int pos,
  677. unsigned int count, const void *kbuf,
  678. const void __user *ubuf)
  679. {
  680. int rc = 0;
  681. if (target == current)
  682. save_fp_regs(&target->thread.fp_regs);
  683. /* If setting FPC, must validate it first. */
  684. if (count > 0 && pos < offsetof(s390_fp_regs, fprs)) {
  685. u32 fpc[2] = { target->thread.fp_regs.fpc, 0 };
  686. rc = user_regset_copyin(&pos, &count, &kbuf, &ubuf, &fpc,
  687. 0, offsetof(s390_fp_regs, fprs));
  688. if (rc)
  689. return rc;
  690. if ((fpc[0] & ~FPC_VALID_MASK) != 0 || fpc[1] != 0)
  691. return -EINVAL;
  692. target->thread.fp_regs.fpc = fpc[0];
  693. }
  694. if (rc == 0 && count > 0)
  695. rc = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
  696. target->thread.fp_regs.fprs,
  697. offsetof(s390_fp_regs, fprs), -1);
  698. if (rc == 0 && target == current)
  699. restore_fp_regs(&target->thread.fp_regs);
  700. return rc;
  701. }
  702. static const struct user_regset s390_regsets[] = {
  703. [REGSET_GENERAL] = {
  704. .core_note_type = NT_PRSTATUS,
  705. .n = sizeof(s390_regs) / sizeof(long),
  706. .size = sizeof(long),
  707. .align = sizeof(long),
  708. .get = s390_regs_get,
  709. .set = s390_regs_set,
  710. },
  711. [REGSET_FP] = {
  712. .core_note_type = NT_PRFPREG,
  713. .n = sizeof(s390_fp_regs) / sizeof(long),
  714. .size = sizeof(long),
  715. .align = sizeof(long),
  716. .get = s390_fpregs_get,
  717. .set = s390_fpregs_set,
  718. },
  719. };
  720. static const struct user_regset_view user_s390_view = {
  721. .name = UTS_MACHINE,
  722. .e_machine = EM_S390,
  723. .regsets = s390_regsets,
  724. .n = ARRAY_SIZE(s390_regsets)
  725. };
  726. #ifdef CONFIG_COMPAT
  727. static int s390_compat_regs_get(struct task_struct *target,
  728. const struct user_regset *regset,
  729. unsigned int pos, unsigned int count,
  730. void *kbuf, void __user *ubuf)
  731. {
  732. if (target == current)
  733. save_access_regs(target->thread.acrs);
  734. if (kbuf) {
  735. compat_ulong_t *k = kbuf;
  736. while (count > 0) {
  737. *k++ = __peek_user_compat(target, pos);
  738. count -= sizeof(*k);
  739. pos += sizeof(*k);
  740. }
  741. } else {
  742. compat_ulong_t __user *u = ubuf;
  743. while (count > 0) {
  744. if (__put_user(__peek_user_compat(target, pos), u++))
  745. return -EFAULT;
  746. count -= sizeof(*u);
  747. pos += sizeof(*u);
  748. }
  749. }
  750. return 0;
  751. }
  752. static int s390_compat_regs_set(struct task_struct *target,
  753. const struct user_regset *regset,
  754. unsigned int pos, unsigned int count,
  755. const void *kbuf, const void __user *ubuf)
  756. {
  757. int rc = 0;
  758. if (target == current)
  759. save_access_regs(target->thread.acrs);
  760. if (kbuf) {
  761. const compat_ulong_t *k = kbuf;
  762. while (count > 0 && !rc) {
  763. rc = __poke_user_compat(target, pos, *k++);
  764. count -= sizeof(*k);
  765. pos += sizeof(*k);
  766. }
  767. } else {
  768. const compat_ulong_t __user *u = ubuf;
  769. while (count > 0 && !rc) {
  770. compat_ulong_t word;
  771. rc = __get_user(word, u++);
  772. if (rc)
  773. break;
  774. rc = __poke_user_compat(target, pos, word);
  775. count -= sizeof(*u);
  776. pos += sizeof(*u);
  777. }
  778. }
  779. if (rc == 0 && target == current)
  780. restore_access_regs(target->thread.acrs);
  781. return rc;
  782. }
  783. static const struct user_regset s390_compat_regsets[] = {
  784. [REGSET_GENERAL] = {
  785. .core_note_type = NT_PRSTATUS,
  786. .n = sizeof(s390_compat_regs) / sizeof(compat_long_t),
  787. .size = sizeof(compat_long_t),
  788. .align = sizeof(compat_long_t),
  789. .get = s390_compat_regs_get,
  790. .set = s390_compat_regs_set,
  791. },
  792. [REGSET_FP] = {
  793. .core_note_type = NT_PRFPREG,
  794. .n = sizeof(s390_fp_regs) / sizeof(compat_long_t),
  795. .size = sizeof(compat_long_t),
  796. .align = sizeof(compat_long_t),
  797. .get = s390_fpregs_get,
  798. .set = s390_fpregs_set,
  799. },
  800. };
  801. static const struct user_regset_view user_s390_compat_view = {
  802. .name = "s390",
  803. .e_machine = EM_S390,
  804. .regsets = s390_compat_regsets,
  805. .n = ARRAY_SIZE(s390_compat_regsets)
  806. };
  807. #endif
  808. const struct user_regset_view *task_user_regset_view(struct task_struct *task)
  809. {
  810. #ifdef CONFIG_COMPAT
  811. if (test_tsk_thread_flag(task, TIF_31BIT))
  812. return &user_s390_compat_view;
  813. #endif
  814. return &user_s390_view;
  815. }