ptrace.c 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362
  1. /*
  2. * Ptrace user space interface.
  3. *
  4. * Copyright IBM Corp. 1999, 2010
  5. * Author(s): Denis Joseph Barrow
  6. * Martin Schwidefsky (schwidefsky@de.ibm.com)
  7. */
  8. #include <linux/kernel.h>
  9. #include <linux/sched.h>
  10. #include <linux/mm.h>
  11. #include <linux/smp.h>
  12. #include <linux/errno.h>
  13. #include <linux/ptrace.h>
  14. #include <linux/user.h>
  15. #include <linux/security.h>
  16. #include <linux/audit.h>
  17. #include <linux/signal.h>
  18. #include <linux/elf.h>
  19. #include <linux/regset.h>
  20. #include <linux/tracehook.h>
  21. #include <linux/seccomp.h>
  22. #include <linux/compat.h>
  23. #include <trace/syscall.h>
  24. #include <asm/segment.h>
  25. #include <asm/page.h>
  26. #include <asm/pgtable.h>
  27. #include <asm/pgalloc.h>
  28. #include <asm/uaccess.h>
  29. #include <asm/unistd.h>
  30. #include <asm/switch_to.h>
  31. #include "entry.h"
  32. #ifdef CONFIG_COMPAT
  33. #include "compat_ptrace.h"
  34. #endif
  35. #define CREATE_TRACE_POINTS
  36. #include <trace/events/syscalls.h>
  37. enum s390_regset {
  38. REGSET_GENERAL,
  39. REGSET_FP,
  40. REGSET_LAST_BREAK,
  41. REGSET_TDB,
  42. REGSET_SYSTEM_CALL,
  43. REGSET_GENERAL_EXTENDED,
  44. };
  45. void update_cr_regs(struct task_struct *task)
  46. {
  47. struct pt_regs *regs = task_pt_regs(task);
  48. struct thread_struct *thread = &task->thread;
  49. struct per_regs old, new;
  50. #ifdef CONFIG_64BIT
  51. /* Take care of the enable/disable of transactional execution. */
  52. if (MACHINE_HAS_TE) {
  53. unsigned long cr, cr_new;
  54. __ctl_store(cr, 0, 0);
  55. /* Set or clear transaction execution TXC bit 8. */
  56. cr_new = cr | (1UL << 55);
  57. if (task->thread.per_flags & PER_FLAG_NO_TE)
  58. cr_new &= ~(1UL << 55);
  59. if (cr_new != cr)
  60. __ctl_load(cr_new, 0, 0);
  61. /* Set or clear transaction execution TDC bits 62 and 63. */
  62. __ctl_store(cr, 2, 2);
  63. cr_new = cr & ~3UL;
  64. if (task->thread.per_flags & PER_FLAG_TE_ABORT_RAND) {
  65. if (task->thread.per_flags & PER_FLAG_TE_ABORT_RAND_TEND)
  66. cr_new |= 1UL;
  67. else
  68. cr_new |= 2UL;
  69. }
  70. if (cr_new != cr)
  71. __ctl_load(cr_new, 2, 2);
  72. }
  73. #endif
  74. /* Copy user specified PER registers */
  75. new.control = thread->per_user.control;
  76. new.start = thread->per_user.start;
  77. new.end = thread->per_user.end;
  78. /* merge TIF_SINGLE_STEP into user specified PER registers. */
  79. if (test_tsk_thread_flag(task, TIF_SINGLE_STEP)) {
  80. if (test_tsk_thread_flag(task, TIF_BLOCK_STEP))
  81. new.control |= PER_EVENT_BRANCH;
  82. else
  83. new.control |= PER_EVENT_IFETCH;
  84. #ifdef CONFIG_64BIT
  85. new.control |= PER_CONTROL_SUSPENSION;
  86. new.control |= PER_EVENT_TRANSACTION_END;
  87. #endif
  88. new.start = 0;
  89. new.end = PSW_ADDR_INSN;
  90. }
  91. /* Take care of the PER enablement bit in the PSW. */
  92. if (!(new.control & PER_EVENT_MASK)) {
  93. regs->psw.mask &= ~PSW_MASK_PER;
  94. return;
  95. }
  96. regs->psw.mask |= PSW_MASK_PER;
  97. __ctl_store(old, 9, 11);
  98. if (memcmp(&new, &old, sizeof(struct per_regs)) != 0)
  99. __ctl_load(new, 9, 11);
  100. }
  101. void user_enable_single_step(struct task_struct *task)
  102. {
  103. clear_tsk_thread_flag(task, TIF_BLOCK_STEP);
  104. set_tsk_thread_flag(task, TIF_SINGLE_STEP);
  105. }
  106. void user_disable_single_step(struct task_struct *task)
  107. {
  108. clear_tsk_thread_flag(task, TIF_BLOCK_STEP);
  109. clear_tsk_thread_flag(task, TIF_SINGLE_STEP);
  110. }
  111. void user_enable_block_step(struct task_struct *task)
  112. {
  113. set_tsk_thread_flag(task, TIF_SINGLE_STEP);
  114. set_tsk_thread_flag(task, TIF_BLOCK_STEP);
  115. }
  116. /*
  117. * Called by kernel/ptrace.c when detaching..
  118. *
  119. * Clear all debugging related fields.
  120. */
  121. void ptrace_disable(struct task_struct *task)
  122. {
  123. memset(&task->thread.per_user, 0, sizeof(task->thread.per_user));
  124. memset(&task->thread.per_event, 0, sizeof(task->thread.per_event));
  125. clear_tsk_thread_flag(task, TIF_SINGLE_STEP);
  126. clear_tsk_thread_flag(task, TIF_PER_TRAP);
  127. task->thread.per_flags = 0;
  128. }
  129. #ifndef CONFIG_64BIT
  130. # define __ADDR_MASK 3
  131. #else
  132. # define __ADDR_MASK 7
  133. #endif
  134. static inline unsigned long __peek_user_per(struct task_struct *child,
  135. addr_t addr)
  136. {
  137. struct per_struct_kernel *dummy = NULL;
  138. if (addr == (addr_t) &dummy->cr9)
  139. /* Control bits of the active per set. */
  140. return test_thread_flag(TIF_SINGLE_STEP) ?
  141. PER_EVENT_IFETCH : child->thread.per_user.control;
  142. else if (addr == (addr_t) &dummy->cr10)
  143. /* Start address of the active per set. */
  144. return test_thread_flag(TIF_SINGLE_STEP) ?
  145. 0 : child->thread.per_user.start;
  146. else if (addr == (addr_t) &dummy->cr11)
  147. /* End address of the active per set. */
  148. return test_thread_flag(TIF_SINGLE_STEP) ?
  149. PSW_ADDR_INSN : child->thread.per_user.end;
  150. else if (addr == (addr_t) &dummy->bits)
  151. /* Single-step bit. */
  152. return test_thread_flag(TIF_SINGLE_STEP) ?
  153. (1UL << (BITS_PER_LONG - 1)) : 0;
  154. else if (addr == (addr_t) &dummy->starting_addr)
  155. /* Start address of the user specified per set. */
  156. return child->thread.per_user.start;
  157. else if (addr == (addr_t) &dummy->ending_addr)
  158. /* End address of the user specified per set. */
  159. return child->thread.per_user.end;
  160. else if (addr == (addr_t) &dummy->perc_atmid)
  161. /* PER code, ATMID and AI of the last PER trap */
  162. return (unsigned long)
  163. child->thread.per_event.cause << (BITS_PER_LONG - 16);
  164. else if (addr == (addr_t) &dummy->address)
  165. /* Address of the last PER trap */
  166. return child->thread.per_event.address;
  167. else if (addr == (addr_t) &dummy->access_id)
  168. /* Access id of the last PER trap */
  169. return (unsigned long)
  170. child->thread.per_event.paid << (BITS_PER_LONG - 8);
  171. return 0;
  172. }
  173. /*
  174. * Read the word at offset addr from the user area of a process. The
  175. * trouble here is that the information is littered over different
  176. * locations. The process registers are found on the kernel stack,
  177. * the floating point stuff and the trace settings are stored in
  178. * the task structure. In addition the different structures in
  179. * struct user contain pad bytes that should be read as zeroes.
  180. * Lovely...
  181. */
  182. static unsigned long __peek_user(struct task_struct *child, addr_t addr)
  183. {
  184. struct user *dummy = NULL;
  185. addr_t offset, tmp;
  186. if (addr < (addr_t) &dummy->regs.acrs) {
  187. /*
  188. * psw and gprs are stored on the stack
  189. */
  190. tmp = *(addr_t *)((addr_t) &task_pt_regs(child)->psw + addr);
  191. if (addr == (addr_t) &dummy->regs.psw.mask) {
  192. /* Return a clean psw mask. */
  193. tmp &= PSW_MASK_USER | PSW_MASK_RI;
  194. tmp |= PSW_USER_BITS;
  195. }
  196. } else if (addr < (addr_t) &dummy->regs.orig_gpr2) {
  197. /*
  198. * access registers are stored in the thread structure
  199. */
  200. offset = addr - (addr_t) &dummy->regs.acrs;
  201. #ifdef CONFIG_64BIT
  202. /*
  203. * Very special case: old & broken 64 bit gdb reading
  204. * from acrs[15]. Result is a 64 bit value. Read the
  205. * 32 bit acrs[15] value and shift it by 32. Sick...
  206. */
  207. if (addr == (addr_t) &dummy->regs.acrs[15])
  208. tmp = ((unsigned long) child->thread.acrs[15]) << 32;
  209. else
  210. #endif
  211. tmp = *(addr_t *)((addr_t) &child->thread.acrs + offset);
  212. } else if (addr == (addr_t) &dummy->regs.orig_gpr2) {
  213. /*
  214. * orig_gpr2 is stored on the kernel stack
  215. */
  216. tmp = (addr_t) task_pt_regs(child)->orig_gpr2;
  217. } else if (addr < (addr_t) &dummy->regs.fp_regs) {
  218. /*
  219. * prevent reads of padding hole between
  220. * orig_gpr2 and fp_regs on s390.
  221. */
  222. tmp = 0;
  223. } else if (addr < (addr_t) (&dummy->regs.fp_regs + 1)) {
  224. /*
  225. * floating point regs. are stored in the thread structure
  226. */
  227. offset = addr - (addr_t) &dummy->regs.fp_regs;
  228. tmp = *(addr_t *)((addr_t) &child->thread.fp_regs + offset);
  229. if (addr == (addr_t) &dummy->regs.fp_regs.fpc)
  230. tmp <<= BITS_PER_LONG - 32;
  231. } else if (addr < (addr_t) (&dummy->regs.per_info + 1)) {
  232. /*
  233. * Handle access to the per_info structure.
  234. */
  235. addr -= (addr_t) &dummy->regs.per_info;
  236. tmp = __peek_user_per(child, addr);
  237. } else
  238. tmp = 0;
  239. return tmp;
  240. }
  241. static int
  242. peek_user(struct task_struct *child, addr_t addr, addr_t data)
  243. {
  244. addr_t tmp, mask;
  245. /*
  246. * Stupid gdb peeks/pokes the access registers in 64 bit with
  247. * an alignment of 4. Programmers from hell...
  248. */
  249. mask = __ADDR_MASK;
  250. #ifdef CONFIG_64BIT
  251. if (addr >= (addr_t) &((struct user *) NULL)->regs.acrs &&
  252. addr < (addr_t) &((struct user *) NULL)->regs.orig_gpr2)
  253. mask = 3;
  254. #endif
  255. if ((addr & mask) || addr > sizeof(struct user) - __ADDR_MASK)
  256. return -EIO;
  257. tmp = __peek_user(child, addr);
  258. return put_user(tmp, (addr_t __user *) data);
  259. }
  260. static inline void __poke_user_per(struct task_struct *child,
  261. addr_t addr, addr_t data)
  262. {
  263. struct per_struct_kernel *dummy = NULL;
  264. /*
  265. * There are only three fields in the per_info struct that the
  266. * debugger user can write to.
  267. * 1) cr9: the debugger wants to set a new PER event mask
  268. * 2) starting_addr: the debugger wants to set a new starting
  269. * address to use with the PER event mask.
  270. * 3) ending_addr: the debugger wants to set a new ending
  271. * address to use with the PER event mask.
  272. * The user specified PER event mask and the start and end
  273. * addresses are used only if single stepping is not in effect.
  274. * Writes to any other field in per_info are ignored.
  275. */
  276. if (addr == (addr_t) &dummy->cr9)
  277. /* PER event mask of the user specified per set. */
  278. child->thread.per_user.control =
  279. data & (PER_EVENT_MASK | PER_CONTROL_MASK);
  280. else if (addr == (addr_t) &dummy->starting_addr)
  281. /* Starting address of the user specified per set. */
  282. child->thread.per_user.start = data;
  283. else if (addr == (addr_t) &dummy->ending_addr)
  284. /* Ending address of the user specified per set. */
  285. child->thread.per_user.end = data;
  286. }
  287. /*
  288. * Write a word to the user area of a process at location addr. This
  289. * operation does have an additional problem compared to peek_user.
  290. * Stores to the program status word and on the floating point
  291. * control register needs to get checked for validity.
  292. */
  293. static int __poke_user(struct task_struct *child, addr_t addr, addr_t data)
  294. {
  295. struct user *dummy = NULL;
  296. addr_t offset;
  297. if (addr < (addr_t) &dummy->regs.acrs) {
  298. /*
  299. * psw and gprs are stored on the stack
  300. */
  301. if (addr == (addr_t) &dummy->regs.psw.mask) {
  302. unsigned long mask = PSW_MASK_USER;
  303. mask |= is_ri_task(child) ? PSW_MASK_RI : 0;
  304. if ((data & ~mask) != PSW_USER_BITS)
  305. return -EINVAL;
  306. if ((data & PSW_MASK_EA) && !(data & PSW_MASK_BA))
  307. return -EINVAL;
  308. }
  309. *(addr_t *)((addr_t) &task_pt_regs(child)->psw + addr) = data;
  310. } else if (addr < (addr_t) (&dummy->regs.orig_gpr2)) {
  311. /*
  312. * access registers are stored in the thread structure
  313. */
  314. offset = addr - (addr_t) &dummy->regs.acrs;
  315. #ifdef CONFIG_64BIT
  316. /*
  317. * Very special case: old & broken 64 bit gdb writing
  318. * to acrs[15] with a 64 bit value. Ignore the lower
  319. * half of the value and write the upper 32 bit to
  320. * acrs[15]. Sick...
  321. */
  322. if (addr == (addr_t) &dummy->regs.acrs[15])
  323. child->thread.acrs[15] = (unsigned int) (data >> 32);
  324. else
  325. #endif
  326. *(addr_t *)((addr_t) &child->thread.acrs + offset) = data;
  327. } else if (addr == (addr_t) &dummy->regs.orig_gpr2) {
  328. /*
  329. * orig_gpr2 is stored on the kernel stack
  330. */
  331. task_pt_regs(child)->orig_gpr2 = data;
  332. } else if (addr < (addr_t) &dummy->regs.fp_regs) {
  333. /*
  334. * prevent writes of padding hole between
  335. * orig_gpr2 and fp_regs on s390.
  336. */
  337. return 0;
  338. } else if (addr < (addr_t) (&dummy->regs.fp_regs + 1)) {
  339. /*
  340. * floating point regs. are stored in the thread structure
  341. */
  342. if (addr == (addr_t) &dummy->regs.fp_regs.fpc)
  343. if ((unsigned int) data != 0 ||
  344. test_fp_ctl(data >> (BITS_PER_LONG - 32)))
  345. return -EINVAL;
  346. offset = addr - (addr_t) &dummy->regs.fp_regs;
  347. *(addr_t *)((addr_t) &child->thread.fp_regs + offset) = data;
  348. } else if (addr < (addr_t) (&dummy->regs.per_info + 1)) {
  349. /*
  350. * Handle access to the per_info structure.
  351. */
  352. addr -= (addr_t) &dummy->regs.per_info;
  353. __poke_user_per(child, addr, data);
  354. }
  355. return 0;
  356. }
  357. static int poke_user(struct task_struct *child, addr_t addr, addr_t data)
  358. {
  359. addr_t mask;
  360. /*
  361. * Stupid gdb peeks/pokes the access registers in 64 bit with
  362. * an alignment of 4. Programmers from hell indeed...
  363. */
  364. mask = __ADDR_MASK;
  365. #ifdef CONFIG_64BIT
  366. if (addr >= (addr_t) &((struct user *) NULL)->regs.acrs &&
  367. addr < (addr_t) &((struct user *) NULL)->regs.orig_gpr2)
  368. mask = 3;
  369. #endif
  370. if ((addr & mask) || addr > sizeof(struct user) - __ADDR_MASK)
  371. return -EIO;
  372. return __poke_user(child, addr, data);
  373. }
  374. long arch_ptrace(struct task_struct *child, long request,
  375. unsigned long addr, unsigned long data)
  376. {
  377. ptrace_area parea;
  378. int copied, ret;
  379. switch (request) {
  380. case PTRACE_PEEKUSR:
  381. /* read the word at location addr in the USER area. */
  382. return peek_user(child, addr, data);
  383. case PTRACE_POKEUSR:
  384. /* write the word at location addr in the USER area */
  385. return poke_user(child, addr, data);
  386. case PTRACE_PEEKUSR_AREA:
  387. case PTRACE_POKEUSR_AREA:
  388. if (copy_from_user(&parea, (void __force __user *) addr,
  389. sizeof(parea)))
  390. return -EFAULT;
  391. addr = parea.kernel_addr;
  392. data = parea.process_addr;
  393. copied = 0;
  394. while (copied < parea.len) {
  395. if (request == PTRACE_PEEKUSR_AREA)
  396. ret = peek_user(child, addr, data);
  397. else {
  398. addr_t utmp;
  399. if (get_user(utmp,
  400. (addr_t __force __user *) data))
  401. return -EFAULT;
  402. ret = poke_user(child, addr, utmp);
  403. }
  404. if (ret)
  405. return ret;
  406. addr += sizeof(unsigned long);
  407. data += sizeof(unsigned long);
  408. copied += sizeof(unsigned long);
  409. }
  410. return 0;
  411. case PTRACE_GET_LAST_BREAK:
  412. put_user(task_thread_info(child)->last_break,
  413. (unsigned long __user *) data);
  414. return 0;
  415. case PTRACE_ENABLE_TE:
  416. if (!MACHINE_HAS_TE)
  417. return -EIO;
  418. child->thread.per_flags &= ~PER_FLAG_NO_TE;
  419. return 0;
  420. case PTRACE_DISABLE_TE:
  421. if (!MACHINE_HAS_TE)
  422. return -EIO;
  423. child->thread.per_flags |= PER_FLAG_NO_TE;
  424. child->thread.per_flags &= ~PER_FLAG_TE_ABORT_RAND;
  425. return 0;
  426. case PTRACE_TE_ABORT_RAND:
  427. if (!MACHINE_HAS_TE || (child->thread.per_flags & PER_FLAG_NO_TE))
  428. return -EIO;
  429. switch (data) {
  430. case 0UL:
  431. child->thread.per_flags &= ~PER_FLAG_TE_ABORT_RAND;
  432. break;
  433. case 1UL:
  434. child->thread.per_flags |= PER_FLAG_TE_ABORT_RAND;
  435. child->thread.per_flags |= PER_FLAG_TE_ABORT_RAND_TEND;
  436. break;
  437. case 2UL:
  438. child->thread.per_flags |= PER_FLAG_TE_ABORT_RAND;
  439. child->thread.per_flags &= ~PER_FLAG_TE_ABORT_RAND_TEND;
  440. break;
  441. default:
  442. return -EINVAL;
  443. }
  444. return 0;
  445. default:
  446. /* Removing high order bit from addr (only for 31 bit). */
  447. addr &= PSW_ADDR_INSN;
  448. return ptrace_request(child, request, addr, data);
  449. }
  450. }
  451. #ifdef CONFIG_COMPAT
  452. /*
  453. * Now the fun part starts... a 31 bit program running in the
  454. * 31 bit emulation tracing another program. PTRACE_PEEKTEXT,
  455. * PTRACE_PEEKDATA, PTRACE_POKETEXT and PTRACE_POKEDATA are easy
  456. * to handle, the difference to the 64 bit versions of the requests
  457. * is that the access is done in multiples of 4 byte instead of
  458. * 8 bytes (sizeof(unsigned long) on 31/64 bit).
  459. * The ugly part are PTRACE_PEEKUSR, PTRACE_PEEKUSR_AREA,
  460. * PTRACE_POKEUSR and PTRACE_POKEUSR_AREA. If the traced program
  461. * is a 31 bit program too, the content of struct user can be
  462. * emulated. A 31 bit program peeking into the struct user of
  463. * a 64 bit program is a no-no.
  464. */
  465. /*
  466. * Same as peek_user_per but for a 31 bit program.
  467. */
  468. static inline __u32 __peek_user_per_compat(struct task_struct *child,
  469. addr_t addr)
  470. {
  471. struct compat_per_struct_kernel *dummy32 = NULL;
  472. if (addr == (addr_t) &dummy32->cr9)
  473. /* Control bits of the active per set. */
  474. return (__u32) test_thread_flag(TIF_SINGLE_STEP) ?
  475. PER_EVENT_IFETCH : child->thread.per_user.control;
  476. else if (addr == (addr_t) &dummy32->cr10)
  477. /* Start address of the active per set. */
  478. return (__u32) test_thread_flag(TIF_SINGLE_STEP) ?
  479. 0 : child->thread.per_user.start;
  480. else if (addr == (addr_t) &dummy32->cr11)
  481. /* End address of the active per set. */
  482. return test_thread_flag(TIF_SINGLE_STEP) ?
  483. PSW32_ADDR_INSN : child->thread.per_user.end;
  484. else if (addr == (addr_t) &dummy32->bits)
  485. /* Single-step bit. */
  486. return (__u32) test_thread_flag(TIF_SINGLE_STEP) ?
  487. 0x80000000 : 0;
  488. else if (addr == (addr_t) &dummy32->starting_addr)
  489. /* Start address of the user specified per set. */
  490. return (__u32) child->thread.per_user.start;
  491. else if (addr == (addr_t) &dummy32->ending_addr)
  492. /* End address of the user specified per set. */
  493. return (__u32) child->thread.per_user.end;
  494. else if (addr == (addr_t) &dummy32->perc_atmid)
  495. /* PER code, ATMID and AI of the last PER trap */
  496. return (__u32) child->thread.per_event.cause << 16;
  497. else if (addr == (addr_t) &dummy32->address)
  498. /* Address of the last PER trap */
  499. return (__u32) child->thread.per_event.address;
  500. else if (addr == (addr_t) &dummy32->access_id)
  501. /* Access id of the last PER trap */
  502. return (__u32) child->thread.per_event.paid << 24;
  503. return 0;
  504. }
  505. /*
  506. * Same as peek_user but for a 31 bit program.
  507. */
  508. static u32 __peek_user_compat(struct task_struct *child, addr_t addr)
  509. {
  510. struct compat_user *dummy32 = NULL;
  511. addr_t offset;
  512. __u32 tmp;
  513. if (addr < (addr_t) &dummy32->regs.acrs) {
  514. struct pt_regs *regs = task_pt_regs(child);
  515. /*
  516. * psw and gprs are stored on the stack
  517. */
  518. if (addr == (addr_t) &dummy32->regs.psw.mask) {
  519. /* Fake a 31 bit psw mask. */
  520. tmp = (__u32)(regs->psw.mask >> 32);
  521. tmp &= PSW32_MASK_USER | PSW32_MASK_RI;
  522. tmp |= PSW32_USER_BITS;
  523. } else if (addr == (addr_t) &dummy32->regs.psw.addr) {
  524. /* Fake a 31 bit psw address. */
  525. tmp = (__u32) regs->psw.addr |
  526. (__u32)(regs->psw.mask & PSW_MASK_BA);
  527. } else {
  528. /* gpr 0-15 */
  529. tmp = *(__u32 *)((addr_t) &regs->psw + addr*2 + 4);
  530. }
  531. } else if (addr < (addr_t) (&dummy32->regs.orig_gpr2)) {
  532. /*
  533. * access registers are stored in the thread structure
  534. */
  535. offset = addr - (addr_t) &dummy32->regs.acrs;
  536. tmp = *(__u32*)((addr_t) &child->thread.acrs + offset);
  537. } else if (addr == (addr_t) (&dummy32->regs.orig_gpr2)) {
  538. /*
  539. * orig_gpr2 is stored on the kernel stack
  540. */
  541. tmp = *(__u32*)((addr_t) &task_pt_regs(child)->orig_gpr2 + 4);
  542. } else if (addr < (addr_t) &dummy32->regs.fp_regs) {
  543. /*
  544. * prevent reads of padding hole between
  545. * orig_gpr2 and fp_regs on s390.
  546. */
  547. tmp = 0;
  548. } else if (addr < (addr_t) (&dummy32->regs.fp_regs + 1)) {
  549. /*
  550. * floating point regs. are stored in the thread structure
  551. */
  552. offset = addr - (addr_t) &dummy32->regs.fp_regs;
  553. tmp = *(__u32 *)((addr_t) &child->thread.fp_regs + offset);
  554. } else if (addr < (addr_t) (&dummy32->regs.per_info + 1)) {
  555. /*
  556. * Handle access to the per_info structure.
  557. */
  558. addr -= (addr_t) &dummy32->regs.per_info;
  559. tmp = __peek_user_per_compat(child, addr);
  560. } else
  561. tmp = 0;
  562. return tmp;
  563. }
  564. static int peek_user_compat(struct task_struct *child,
  565. addr_t addr, addr_t data)
  566. {
  567. __u32 tmp;
  568. if (!is_compat_task() || (addr & 3) || addr > sizeof(struct user) - 3)
  569. return -EIO;
  570. tmp = __peek_user_compat(child, addr);
  571. return put_user(tmp, (__u32 __user *) data);
  572. }
  573. /*
  574. * Same as poke_user_per but for a 31 bit program.
  575. */
  576. static inline void __poke_user_per_compat(struct task_struct *child,
  577. addr_t addr, __u32 data)
  578. {
  579. struct compat_per_struct_kernel *dummy32 = NULL;
  580. if (addr == (addr_t) &dummy32->cr9)
  581. /* PER event mask of the user specified per set. */
  582. child->thread.per_user.control =
  583. data & (PER_EVENT_MASK | PER_CONTROL_MASK);
  584. else if (addr == (addr_t) &dummy32->starting_addr)
  585. /* Starting address of the user specified per set. */
  586. child->thread.per_user.start = data;
  587. else if (addr == (addr_t) &dummy32->ending_addr)
  588. /* Ending address of the user specified per set. */
  589. child->thread.per_user.end = data;
  590. }
  591. /*
  592. * Same as poke_user but for a 31 bit program.
  593. */
  594. static int __poke_user_compat(struct task_struct *child,
  595. addr_t addr, addr_t data)
  596. {
  597. struct compat_user *dummy32 = NULL;
  598. __u32 tmp = (__u32) data;
  599. addr_t offset;
  600. if (addr < (addr_t) &dummy32->regs.acrs) {
  601. struct pt_regs *regs = task_pt_regs(child);
  602. /*
  603. * psw, gprs, acrs and orig_gpr2 are stored on the stack
  604. */
  605. if (addr == (addr_t) &dummy32->regs.psw.mask) {
  606. __u32 mask = PSW32_MASK_USER;
  607. mask |= is_ri_task(child) ? PSW32_MASK_RI : 0;
  608. /* Build a 64 bit psw mask from 31 bit mask. */
  609. if ((tmp & ~mask) != PSW32_USER_BITS)
  610. /* Invalid psw mask. */
  611. return -EINVAL;
  612. regs->psw.mask = (regs->psw.mask & ~PSW_MASK_USER) |
  613. (regs->psw.mask & PSW_MASK_BA) |
  614. (__u64)(tmp & mask) << 32;
  615. } else if (addr == (addr_t) &dummy32->regs.psw.addr) {
  616. /* Build a 64 bit psw address from 31 bit address. */
  617. regs->psw.addr = (__u64) tmp & PSW32_ADDR_INSN;
  618. /* Transfer 31 bit amode bit to psw mask. */
  619. regs->psw.mask = (regs->psw.mask & ~PSW_MASK_BA) |
  620. (__u64)(tmp & PSW32_ADDR_AMODE);
  621. } else {
  622. /* gpr 0-15 */
  623. *(__u32*)((addr_t) &regs->psw + addr*2 + 4) = tmp;
  624. }
  625. } else if (addr < (addr_t) (&dummy32->regs.orig_gpr2)) {
  626. /*
  627. * access registers are stored in the thread structure
  628. */
  629. offset = addr - (addr_t) &dummy32->regs.acrs;
  630. *(__u32*)((addr_t) &child->thread.acrs + offset) = tmp;
  631. } else if (addr == (addr_t) (&dummy32->regs.orig_gpr2)) {
  632. /*
  633. * orig_gpr2 is stored on the kernel stack
  634. */
  635. *(__u32*)((addr_t) &task_pt_regs(child)->orig_gpr2 + 4) = tmp;
  636. } else if (addr < (addr_t) &dummy32->regs.fp_regs) {
  637. /*
  638. * prevent writess of padding hole between
  639. * orig_gpr2 and fp_regs on s390.
  640. */
  641. return 0;
  642. } else if (addr < (addr_t) (&dummy32->regs.fp_regs + 1)) {
  643. /*
  644. * floating point regs. are stored in the thread structure
  645. */
  646. if (addr == (addr_t) &dummy32->regs.fp_regs.fpc &&
  647. test_fp_ctl(tmp))
  648. return -EINVAL;
  649. offset = addr - (addr_t) &dummy32->regs.fp_regs;
  650. *(__u32 *)((addr_t) &child->thread.fp_regs + offset) = tmp;
  651. } else if (addr < (addr_t) (&dummy32->regs.per_info + 1)) {
  652. /*
  653. * Handle access to the per_info structure.
  654. */
  655. addr -= (addr_t) &dummy32->regs.per_info;
  656. __poke_user_per_compat(child, addr, data);
  657. }
  658. return 0;
  659. }
  660. static int poke_user_compat(struct task_struct *child,
  661. addr_t addr, addr_t data)
  662. {
  663. if (!is_compat_task() || (addr & 3) ||
  664. addr > sizeof(struct compat_user) - 3)
  665. return -EIO;
  666. return __poke_user_compat(child, addr, data);
  667. }
  668. long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
  669. compat_ulong_t caddr, compat_ulong_t cdata)
  670. {
  671. unsigned long addr = caddr;
  672. unsigned long data = cdata;
  673. compat_ptrace_area parea;
  674. int copied, ret;
  675. switch (request) {
  676. case PTRACE_PEEKUSR:
  677. /* read the word at location addr in the USER area. */
  678. return peek_user_compat(child, addr, data);
  679. case PTRACE_POKEUSR:
  680. /* write the word at location addr in the USER area */
  681. return poke_user_compat(child, addr, data);
  682. case PTRACE_PEEKUSR_AREA:
  683. case PTRACE_POKEUSR_AREA:
  684. if (copy_from_user(&parea, (void __force __user *) addr,
  685. sizeof(parea)))
  686. return -EFAULT;
  687. addr = parea.kernel_addr;
  688. data = parea.process_addr;
  689. copied = 0;
  690. while (copied < parea.len) {
  691. if (request == PTRACE_PEEKUSR_AREA)
  692. ret = peek_user_compat(child, addr, data);
  693. else {
  694. __u32 utmp;
  695. if (get_user(utmp,
  696. (__u32 __force __user *) data))
  697. return -EFAULT;
  698. ret = poke_user_compat(child, addr, utmp);
  699. }
  700. if (ret)
  701. return ret;
  702. addr += sizeof(unsigned int);
  703. data += sizeof(unsigned int);
  704. copied += sizeof(unsigned int);
  705. }
  706. return 0;
  707. case PTRACE_GET_LAST_BREAK:
  708. put_user(task_thread_info(child)->last_break,
  709. (unsigned int __user *) data);
  710. return 0;
  711. }
  712. return compat_ptrace_request(child, request, addr, data);
  713. }
  714. #endif
  715. asmlinkage long do_syscall_trace_enter(struct pt_regs *regs)
  716. {
  717. long ret = 0;
  718. /* Do the secure computing check first. */
  719. if (secure_computing(regs->gprs[2])) {
  720. /* seccomp failures shouldn't expose any additional code. */
  721. ret = -1;
  722. goto out;
  723. }
  724. /*
  725. * The sysc_tracesys code in entry.S stored the system
  726. * call number to gprs[2].
  727. */
  728. if (test_thread_flag(TIF_SYSCALL_TRACE) &&
  729. (tracehook_report_syscall_entry(regs) ||
  730. regs->gprs[2] >= NR_syscalls)) {
  731. /*
  732. * Tracing decided this syscall should not happen or the
  733. * debugger stored an invalid system call number. Skip
  734. * the system call and the system call restart handling.
  735. */
  736. clear_thread_flag(TIF_SYSCALL);
  737. ret = -1;
  738. }
  739. if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
  740. trace_sys_enter(regs, regs->gprs[2]);
  741. audit_syscall_entry(is_compat_task() ?
  742. AUDIT_ARCH_S390 : AUDIT_ARCH_S390X,
  743. regs->gprs[2], regs->orig_gpr2,
  744. regs->gprs[3], regs->gprs[4],
  745. regs->gprs[5]);
  746. out:
  747. return ret ?: regs->gprs[2];
  748. }
  749. asmlinkage void do_syscall_trace_exit(struct pt_regs *regs)
  750. {
  751. audit_syscall_exit(regs);
  752. if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
  753. trace_sys_exit(regs, regs->gprs[2]);
  754. if (test_thread_flag(TIF_SYSCALL_TRACE))
  755. tracehook_report_syscall_exit(regs, 0);
  756. }
  757. /*
  758. * user_regset definitions.
  759. */
  760. static int s390_regs_get(struct task_struct *target,
  761. const struct user_regset *regset,
  762. unsigned int pos, unsigned int count,
  763. void *kbuf, void __user *ubuf)
  764. {
  765. if (target == current)
  766. save_access_regs(target->thread.acrs);
  767. if (kbuf) {
  768. unsigned long *k = kbuf;
  769. while (count > 0) {
  770. *k++ = __peek_user(target, pos);
  771. count -= sizeof(*k);
  772. pos += sizeof(*k);
  773. }
  774. } else {
  775. unsigned long __user *u = ubuf;
  776. while (count > 0) {
  777. if (__put_user(__peek_user(target, pos), u++))
  778. return -EFAULT;
  779. count -= sizeof(*u);
  780. pos += sizeof(*u);
  781. }
  782. }
  783. return 0;
  784. }
  785. static int s390_regs_set(struct task_struct *target,
  786. const struct user_regset *regset,
  787. unsigned int pos, unsigned int count,
  788. const void *kbuf, const void __user *ubuf)
  789. {
  790. int rc = 0;
  791. if (target == current)
  792. save_access_regs(target->thread.acrs);
  793. if (kbuf) {
  794. const unsigned long *k = kbuf;
  795. while (count > 0 && !rc) {
  796. rc = __poke_user(target, pos, *k++);
  797. count -= sizeof(*k);
  798. pos += sizeof(*k);
  799. }
  800. } else {
  801. const unsigned long __user *u = ubuf;
  802. while (count > 0 && !rc) {
  803. unsigned long word;
  804. rc = __get_user(word, u++);
  805. if (rc)
  806. break;
  807. rc = __poke_user(target, pos, word);
  808. count -= sizeof(*u);
  809. pos += sizeof(*u);
  810. }
  811. }
  812. if (rc == 0 && target == current)
  813. restore_access_regs(target->thread.acrs);
  814. return rc;
  815. }
  816. static int s390_fpregs_get(struct task_struct *target,
  817. const struct user_regset *regset, unsigned int pos,
  818. unsigned int count, void *kbuf, void __user *ubuf)
  819. {
  820. if (target == current) {
  821. save_fp_ctl(&target->thread.fp_regs.fpc);
  822. save_fp_regs(target->thread.fp_regs.fprs);
  823. }
  824. return user_regset_copyout(&pos, &count, &kbuf, &ubuf,
  825. &target->thread.fp_regs, 0, -1);
  826. }
  827. static int s390_fpregs_set(struct task_struct *target,
  828. const struct user_regset *regset, unsigned int pos,
  829. unsigned int count, const void *kbuf,
  830. const void __user *ubuf)
  831. {
  832. int rc = 0;
  833. if (target == current) {
  834. save_fp_ctl(&target->thread.fp_regs.fpc);
  835. save_fp_regs(target->thread.fp_regs.fprs);
  836. }
  837. /* If setting FPC, must validate it first. */
  838. if (count > 0 && pos < offsetof(s390_fp_regs, fprs)) {
  839. u32 ufpc[2] = { target->thread.fp_regs.fpc, 0 };
  840. rc = user_regset_copyin(&pos, &count, &kbuf, &ubuf, &ufpc,
  841. 0, offsetof(s390_fp_regs, fprs));
  842. if (rc)
  843. return rc;
  844. if (ufpc[1] != 0 || test_fp_ctl(ufpc[0]))
  845. return -EINVAL;
  846. target->thread.fp_regs.fpc = ufpc[0];
  847. }
  848. if (rc == 0 && count > 0)
  849. rc = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
  850. target->thread.fp_regs.fprs,
  851. offsetof(s390_fp_regs, fprs), -1);
  852. if (rc == 0 && target == current) {
  853. restore_fp_ctl(&target->thread.fp_regs.fpc);
  854. restore_fp_regs(target->thread.fp_regs.fprs);
  855. }
  856. return rc;
  857. }
  858. #ifdef CONFIG_64BIT
  859. static int s390_last_break_get(struct task_struct *target,
  860. const struct user_regset *regset,
  861. unsigned int pos, unsigned int count,
  862. void *kbuf, void __user *ubuf)
  863. {
  864. if (count > 0) {
  865. if (kbuf) {
  866. unsigned long *k = kbuf;
  867. *k = task_thread_info(target)->last_break;
  868. } else {
  869. unsigned long __user *u = ubuf;
  870. if (__put_user(task_thread_info(target)->last_break, u))
  871. return -EFAULT;
  872. }
  873. }
  874. return 0;
  875. }
  876. static int s390_last_break_set(struct task_struct *target,
  877. const struct user_regset *regset,
  878. unsigned int pos, unsigned int count,
  879. const void *kbuf, const void __user *ubuf)
  880. {
  881. return 0;
  882. }
  883. static int s390_tdb_get(struct task_struct *target,
  884. const struct user_regset *regset,
  885. unsigned int pos, unsigned int count,
  886. void *kbuf, void __user *ubuf)
  887. {
  888. struct pt_regs *regs = task_pt_regs(target);
  889. unsigned char *data;
  890. if (!(regs->int_code & 0x200))
  891. return -ENODATA;
  892. data = target->thread.trap_tdb;
  893. return user_regset_copyout(&pos, &count, &kbuf, &ubuf, data, 0, 256);
  894. }
  895. static int s390_tdb_set(struct task_struct *target,
  896. const struct user_regset *regset,
  897. unsigned int pos, unsigned int count,
  898. const void *kbuf, const void __user *ubuf)
  899. {
  900. return 0;
  901. }
  902. #endif
  903. static int s390_system_call_get(struct task_struct *target,
  904. const struct user_regset *regset,
  905. unsigned int pos, unsigned int count,
  906. void *kbuf, void __user *ubuf)
  907. {
  908. unsigned int *data = &task_thread_info(target)->system_call;
  909. return user_regset_copyout(&pos, &count, &kbuf, &ubuf,
  910. data, 0, sizeof(unsigned int));
  911. }
  912. static int s390_system_call_set(struct task_struct *target,
  913. const struct user_regset *regset,
  914. unsigned int pos, unsigned int count,
  915. const void *kbuf, const void __user *ubuf)
  916. {
  917. unsigned int *data = &task_thread_info(target)->system_call;
  918. return user_regset_copyin(&pos, &count, &kbuf, &ubuf,
  919. data, 0, sizeof(unsigned int));
  920. }
  921. static const struct user_regset s390_regsets[] = {
  922. [REGSET_GENERAL] = {
  923. .core_note_type = NT_PRSTATUS,
  924. .n = sizeof(s390_regs) / sizeof(long),
  925. .size = sizeof(long),
  926. .align = sizeof(long),
  927. .get = s390_regs_get,
  928. .set = s390_regs_set,
  929. },
  930. [REGSET_FP] = {
  931. .core_note_type = NT_PRFPREG,
  932. .n = sizeof(s390_fp_regs) / sizeof(long),
  933. .size = sizeof(long),
  934. .align = sizeof(long),
  935. .get = s390_fpregs_get,
  936. .set = s390_fpregs_set,
  937. },
  938. #ifdef CONFIG_64BIT
  939. [REGSET_LAST_BREAK] = {
  940. .core_note_type = NT_S390_LAST_BREAK,
  941. .n = 1,
  942. .size = sizeof(long),
  943. .align = sizeof(long),
  944. .get = s390_last_break_get,
  945. .set = s390_last_break_set,
  946. },
  947. [REGSET_TDB] = {
  948. .core_note_type = NT_S390_TDB,
  949. .n = 1,
  950. .size = 256,
  951. .align = 1,
  952. .get = s390_tdb_get,
  953. .set = s390_tdb_set,
  954. },
  955. #endif
  956. [REGSET_SYSTEM_CALL] = {
  957. .core_note_type = NT_S390_SYSTEM_CALL,
  958. .n = 1,
  959. .size = sizeof(unsigned int),
  960. .align = sizeof(unsigned int),
  961. .get = s390_system_call_get,
  962. .set = s390_system_call_set,
  963. },
  964. };
  965. static const struct user_regset_view user_s390_view = {
  966. .name = UTS_MACHINE,
  967. .e_machine = EM_S390,
  968. .regsets = s390_regsets,
  969. .n = ARRAY_SIZE(s390_regsets)
  970. };
  971. #ifdef CONFIG_COMPAT
  972. static int s390_compat_regs_get(struct task_struct *target,
  973. const struct user_regset *regset,
  974. unsigned int pos, unsigned int count,
  975. void *kbuf, void __user *ubuf)
  976. {
  977. if (target == current)
  978. save_access_regs(target->thread.acrs);
  979. if (kbuf) {
  980. compat_ulong_t *k = kbuf;
  981. while (count > 0) {
  982. *k++ = __peek_user_compat(target, pos);
  983. count -= sizeof(*k);
  984. pos += sizeof(*k);
  985. }
  986. } else {
  987. compat_ulong_t __user *u = ubuf;
  988. while (count > 0) {
  989. if (__put_user(__peek_user_compat(target, pos), u++))
  990. return -EFAULT;
  991. count -= sizeof(*u);
  992. pos += sizeof(*u);
  993. }
  994. }
  995. return 0;
  996. }
  997. static int s390_compat_regs_set(struct task_struct *target,
  998. const struct user_regset *regset,
  999. unsigned int pos, unsigned int count,
  1000. const void *kbuf, const void __user *ubuf)
  1001. {
  1002. int rc = 0;
  1003. if (target == current)
  1004. save_access_regs(target->thread.acrs);
  1005. if (kbuf) {
  1006. const compat_ulong_t *k = kbuf;
  1007. while (count > 0 && !rc) {
  1008. rc = __poke_user_compat(target, pos, *k++);
  1009. count -= sizeof(*k);
  1010. pos += sizeof(*k);
  1011. }
  1012. } else {
  1013. const compat_ulong_t __user *u = ubuf;
  1014. while (count > 0 && !rc) {
  1015. compat_ulong_t word;
  1016. rc = __get_user(word, u++);
  1017. if (rc)
  1018. break;
  1019. rc = __poke_user_compat(target, pos, word);
  1020. count -= sizeof(*u);
  1021. pos += sizeof(*u);
  1022. }
  1023. }
  1024. if (rc == 0 && target == current)
  1025. restore_access_regs(target->thread.acrs);
  1026. return rc;
  1027. }
  1028. static int s390_compat_regs_high_get(struct task_struct *target,
  1029. const struct user_regset *regset,
  1030. unsigned int pos, unsigned int count,
  1031. void *kbuf, void __user *ubuf)
  1032. {
  1033. compat_ulong_t *gprs_high;
  1034. gprs_high = (compat_ulong_t *)
  1035. &task_pt_regs(target)->gprs[pos / sizeof(compat_ulong_t)];
  1036. if (kbuf) {
  1037. compat_ulong_t *k = kbuf;
  1038. while (count > 0) {
  1039. *k++ = *gprs_high;
  1040. gprs_high += 2;
  1041. count -= sizeof(*k);
  1042. }
  1043. } else {
  1044. compat_ulong_t __user *u = ubuf;
  1045. while (count > 0) {
  1046. if (__put_user(*gprs_high, u++))
  1047. return -EFAULT;
  1048. gprs_high += 2;
  1049. count -= sizeof(*u);
  1050. }
  1051. }
  1052. return 0;
  1053. }
  1054. static int s390_compat_regs_high_set(struct task_struct *target,
  1055. const struct user_regset *regset,
  1056. unsigned int pos, unsigned int count,
  1057. const void *kbuf, const void __user *ubuf)
  1058. {
  1059. compat_ulong_t *gprs_high;
  1060. int rc = 0;
  1061. gprs_high = (compat_ulong_t *)
  1062. &task_pt_regs(target)->gprs[pos / sizeof(compat_ulong_t)];
  1063. if (kbuf) {
  1064. const compat_ulong_t *k = kbuf;
  1065. while (count > 0) {
  1066. *gprs_high = *k++;
  1067. *gprs_high += 2;
  1068. count -= sizeof(*k);
  1069. }
  1070. } else {
  1071. const compat_ulong_t __user *u = ubuf;
  1072. while (count > 0 && !rc) {
  1073. unsigned long word;
  1074. rc = __get_user(word, u++);
  1075. if (rc)
  1076. break;
  1077. *gprs_high = word;
  1078. *gprs_high += 2;
  1079. count -= sizeof(*u);
  1080. }
  1081. }
  1082. return rc;
  1083. }
  1084. static int s390_compat_last_break_get(struct task_struct *target,
  1085. const struct user_regset *regset,
  1086. unsigned int pos, unsigned int count,
  1087. void *kbuf, void __user *ubuf)
  1088. {
  1089. compat_ulong_t last_break;
  1090. if (count > 0) {
  1091. last_break = task_thread_info(target)->last_break;
  1092. if (kbuf) {
  1093. unsigned long *k = kbuf;
  1094. *k = last_break;
  1095. } else {
  1096. unsigned long __user *u = ubuf;
  1097. if (__put_user(last_break, u))
  1098. return -EFAULT;
  1099. }
  1100. }
  1101. return 0;
  1102. }
  1103. static int s390_compat_last_break_set(struct task_struct *target,
  1104. const struct user_regset *regset,
  1105. unsigned int pos, unsigned int count,
  1106. const void *kbuf, const void __user *ubuf)
  1107. {
  1108. return 0;
  1109. }
  1110. static const struct user_regset s390_compat_regsets[] = {
  1111. [REGSET_GENERAL] = {
  1112. .core_note_type = NT_PRSTATUS,
  1113. .n = sizeof(s390_compat_regs) / sizeof(compat_long_t),
  1114. .size = sizeof(compat_long_t),
  1115. .align = sizeof(compat_long_t),
  1116. .get = s390_compat_regs_get,
  1117. .set = s390_compat_regs_set,
  1118. },
  1119. [REGSET_FP] = {
  1120. .core_note_type = NT_PRFPREG,
  1121. .n = sizeof(s390_fp_regs) / sizeof(compat_long_t),
  1122. .size = sizeof(compat_long_t),
  1123. .align = sizeof(compat_long_t),
  1124. .get = s390_fpregs_get,
  1125. .set = s390_fpregs_set,
  1126. },
  1127. [REGSET_LAST_BREAK] = {
  1128. .core_note_type = NT_S390_LAST_BREAK,
  1129. .n = 1,
  1130. .size = sizeof(long),
  1131. .align = sizeof(long),
  1132. .get = s390_compat_last_break_get,
  1133. .set = s390_compat_last_break_set,
  1134. },
  1135. [REGSET_TDB] = {
  1136. .core_note_type = NT_S390_TDB,
  1137. .n = 1,
  1138. .size = 256,
  1139. .align = 1,
  1140. .get = s390_tdb_get,
  1141. .set = s390_tdb_set,
  1142. },
  1143. [REGSET_SYSTEM_CALL] = {
  1144. .core_note_type = NT_S390_SYSTEM_CALL,
  1145. .n = 1,
  1146. .size = sizeof(compat_uint_t),
  1147. .align = sizeof(compat_uint_t),
  1148. .get = s390_system_call_get,
  1149. .set = s390_system_call_set,
  1150. },
  1151. [REGSET_GENERAL_EXTENDED] = {
  1152. .core_note_type = NT_S390_HIGH_GPRS,
  1153. .n = sizeof(s390_compat_regs_high) / sizeof(compat_long_t),
  1154. .size = sizeof(compat_long_t),
  1155. .align = sizeof(compat_long_t),
  1156. .get = s390_compat_regs_high_get,
  1157. .set = s390_compat_regs_high_set,
  1158. },
  1159. };
  1160. static const struct user_regset_view user_s390_compat_view = {
  1161. .name = "s390",
  1162. .e_machine = EM_S390,
  1163. .regsets = s390_compat_regsets,
  1164. .n = ARRAY_SIZE(s390_compat_regsets)
  1165. };
  1166. #endif
  1167. const struct user_regset_view *task_user_regset_view(struct task_struct *task)
  1168. {
  1169. #ifdef CONFIG_COMPAT
  1170. if (test_tsk_thread_flag(task, TIF_31BIT))
  1171. return &user_s390_compat_view;
  1172. #endif
  1173. return &user_s390_view;
  1174. }
  1175. static const char *gpr_names[NUM_GPRS] = {
  1176. "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
  1177. "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
  1178. };
  1179. unsigned long regs_get_register(struct pt_regs *regs, unsigned int offset)
  1180. {
  1181. if (offset >= NUM_GPRS)
  1182. return 0;
  1183. return regs->gprs[offset];
  1184. }
  1185. int regs_query_register_offset(const char *name)
  1186. {
  1187. unsigned long offset;
  1188. if (!name || *name != 'r')
  1189. return -EINVAL;
  1190. if (kstrtoul(name + 1, 10, &offset))
  1191. return -EINVAL;
  1192. if (offset >= NUM_GPRS)
  1193. return -EINVAL;
  1194. return offset;
  1195. }
  1196. const char *regs_query_register_name(unsigned int offset)
  1197. {
  1198. if (offset >= NUM_GPRS)
  1199. return NULL;
  1200. return gpr_names[offset];
  1201. }
  1202. static int regs_within_kernel_stack(struct pt_regs *regs, unsigned long addr)
  1203. {
  1204. unsigned long ksp = kernel_stack_pointer(regs);
  1205. return (addr & ~(THREAD_SIZE - 1)) == (ksp & ~(THREAD_SIZE - 1));
  1206. }
  1207. /**
  1208. * regs_get_kernel_stack_nth() - get Nth entry of the stack
  1209. * @regs:pt_regs which contains kernel stack pointer.
  1210. * @n:stack entry number.
  1211. *
  1212. * regs_get_kernel_stack_nth() returns @n th entry of the kernel stack which
  1213. * is specifined by @regs. If the @n th entry is NOT in the kernel stack,
  1214. * this returns 0.
  1215. */
  1216. unsigned long regs_get_kernel_stack_nth(struct pt_regs *regs, unsigned int n)
  1217. {
  1218. unsigned long addr;
  1219. addr = kernel_stack_pointer(regs) + n * sizeof(long);
  1220. if (!regs_within_kernel_stack(regs, addr))
  1221. return 0;
  1222. return *(unsigned long *)addr;
  1223. }