ptrace.c 37 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370
  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_pt_regs_flag(task_pt_regs(task), PIF_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 ^ PSW_USER_BITS) & ~mask)
  305. /* Invalid psw mask. */
  306. return -EINVAL;
  307. if ((data & PSW_MASK_ASC) == PSW_ASC_HOME)
  308. /* Invalid address-space-control bits */
  309. return -EINVAL;
  310. if ((data & PSW_MASK_EA) && !(data & PSW_MASK_BA))
  311. /* Invalid addressing mode bits */
  312. return -EINVAL;
  313. }
  314. *(addr_t *)((addr_t) &task_pt_regs(child)->psw + addr) = data;
  315. } else if (addr < (addr_t) (&dummy->regs.orig_gpr2)) {
  316. /*
  317. * access registers are stored in the thread structure
  318. */
  319. offset = addr - (addr_t) &dummy->regs.acrs;
  320. #ifdef CONFIG_64BIT
  321. /*
  322. * Very special case: old & broken 64 bit gdb writing
  323. * to acrs[15] with a 64 bit value. Ignore the lower
  324. * half of the value and write the upper 32 bit to
  325. * acrs[15]. Sick...
  326. */
  327. if (addr == (addr_t) &dummy->regs.acrs[15])
  328. child->thread.acrs[15] = (unsigned int) (data >> 32);
  329. else
  330. #endif
  331. *(addr_t *)((addr_t) &child->thread.acrs + offset) = data;
  332. } else if (addr == (addr_t) &dummy->regs.orig_gpr2) {
  333. /*
  334. * orig_gpr2 is stored on the kernel stack
  335. */
  336. task_pt_regs(child)->orig_gpr2 = data;
  337. } else if (addr < (addr_t) &dummy->regs.fp_regs) {
  338. /*
  339. * prevent writes of padding hole between
  340. * orig_gpr2 and fp_regs on s390.
  341. */
  342. return 0;
  343. } else if (addr < (addr_t) (&dummy->regs.fp_regs + 1)) {
  344. /*
  345. * floating point regs. are stored in the thread structure
  346. */
  347. if (addr == (addr_t) &dummy->regs.fp_regs.fpc)
  348. if ((unsigned int) data != 0 ||
  349. test_fp_ctl(data >> (BITS_PER_LONG - 32)))
  350. return -EINVAL;
  351. offset = addr - (addr_t) &dummy->regs.fp_regs;
  352. *(addr_t *)((addr_t) &child->thread.fp_regs + offset) = data;
  353. } else if (addr < (addr_t) (&dummy->regs.per_info + 1)) {
  354. /*
  355. * Handle access to the per_info structure.
  356. */
  357. addr -= (addr_t) &dummy->regs.per_info;
  358. __poke_user_per(child, addr, data);
  359. }
  360. return 0;
  361. }
  362. static int poke_user(struct task_struct *child, addr_t addr, addr_t data)
  363. {
  364. addr_t mask;
  365. /*
  366. * Stupid gdb peeks/pokes the access registers in 64 bit with
  367. * an alignment of 4. Programmers from hell indeed...
  368. */
  369. mask = __ADDR_MASK;
  370. #ifdef CONFIG_64BIT
  371. if (addr >= (addr_t) &((struct user *) NULL)->regs.acrs &&
  372. addr < (addr_t) &((struct user *) NULL)->regs.orig_gpr2)
  373. mask = 3;
  374. #endif
  375. if ((addr & mask) || addr > sizeof(struct user) - __ADDR_MASK)
  376. return -EIO;
  377. return __poke_user(child, addr, data);
  378. }
  379. long arch_ptrace(struct task_struct *child, long request,
  380. unsigned long addr, unsigned long data)
  381. {
  382. ptrace_area parea;
  383. int copied, ret;
  384. switch (request) {
  385. case PTRACE_PEEKUSR:
  386. /* read the word at location addr in the USER area. */
  387. return peek_user(child, addr, data);
  388. case PTRACE_POKEUSR:
  389. /* write the word at location addr in the USER area */
  390. return poke_user(child, addr, data);
  391. case PTRACE_PEEKUSR_AREA:
  392. case PTRACE_POKEUSR_AREA:
  393. if (copy_from_user(&parea, (void __force __user *) addr,
  394. sizeof(parea)))
  395. return -EFAULT;
  396. addr = parea.kernel_addr;
  397. data = parea.process_addr;
  398. copied = 0;
  399. while (copied < parea.len) {
  400. if (request == PTRACE_PEEKUSR_AREA)
  401. ret = peek_user(child, addr, data);
  402. else {
  403. addr_t utmp;
  404. if (get_user(utmp,
  405. (addr_t __force __user *) data))
  406. return -EFAULT;
  407. ret = poke_user(child, addr, utmp);
  408. }
  409. if (ret)
  410. return ret;
  411. addr += sizeof(unsigned long);
  412. data += sizeof(unsigned long);
  413. copied += sizeof(unsigned long);
  414. }
  415. return 0;
  416. case PTRACE_GET_LAST_BREAK:
  417. put_user(task_thread_info(child)->last_break,
  418. (unsigned long __user *) data);
  419. return 0;
  420. case PTRACE_ENABLE_TE:
  421. if (!MACHINE_HAS_TE)
  422. return -EIO;
  423. child->thread.per_flags &= ~PER_FLAG_NO_TE;
  424. return 0;
  425. case PTRACE_DISABLE_TE:
  426. if (!MACHINE_HAS_TE)
  427. return -EIO;
  428. child->thread.per_flags |= PER_FLAG_NO_TE;
  429. child->thread.per_flags &= ~PER_FLAG_TE_ABORT_RAND;
  430. return 0;
  431. case PTRACE_TE_ABORT_RAND:
  432. if (!MACHINE_HAS_TE || (child->thread.per_flags & PER_FLAG_NO_TE))
  433. return -EIO;
  434. switch (data) {
  435. case 0UL:
  436. child->thread.per_flags &= ~PER_FLAG_TE_ABORT_RAND;
  437. break;
  438. case 1UL:
  439. child->thread.per_flags |= PER_FLAG_TE_ABORT_RAND;
  440. child->thread.per_flags |= PER_FLAG_TE_ABORT_RAND_TEND;
  441. break;
  442. case 2UL:
  443. child->thread.per_flags |= PER_FLAG_TE_ABORT_RAND;
  444. child->thread.per_flags &= ~PER_FLAG_TE_ABORT_RAND_TEND;
  445. break;
  446. default:
  447. return -EINVAL;
  448. }
  449. return 0;
  450. default:
  451. /* Removing high order bit from addr (only for 31 bit). */
  452. addr &= PSW_ADDR_INSN;
  453. return ptrace_request(child, request, addr, data);
  454. }
  455. }
  456. #ifdef CONFIG_COMPAT
  457. /*
  458. * Now the fun part starts... a 31 bit program running in the
  459. * 31 bit emulation tracing another program. PTRACE_PEEKTEXT,
  460. * PTRACE_PEEKDATA, PTRACE_POKETEXT and PTRACE_POKEDATA are easy
  461. * to handle, the difference to the 64 bit versions of the requests
  462. * is that the access is done in multiples of 4 byte instead of
  463. * 8 bytes (sizeof(unsigned long) on 31/64 bit).
  464. * The ugly part are PTRACE_PEEKUSR, PTRACE_PEEKUSR_AREA,
  465. * PTRACE_POKEUSR and PTRACE_POKEUSR_AREA. If the traced program
  466. * is a 31 bit program too, the content of struct user can be
  467. * emulated. A 31 bit program peeking into the struct user of
  468. * a 64 bit program is a no-no.
  469. */
  470. /*
  471. * Same as peek_user_per but for a 31 bit program.
  472. */
  473. static inline __u32 __peek_user_per_compat(struct task_struct *child,
  474. addr_t addr)
  475. {
  476. struct compat_per_struct_kernel *dummy32 = NULL;
  477. if (addr == (addr_t) &dummy32->cr9)
  478. /* Control bits of the active per set. */
  479. return (__u32) test_thread_flag(TIF_SINGLE_STEP) ?
  480. PER_EVENT_IFETCH : child->thread.per_user.control;
  481. else if (addr == (addr_t) &dummy32->cr10)
  482. /* Start address of the active per set. */
  483. return (__u32) test_thread_flag(TIF_SINGLE_STEP) ?
  484. 0 : child->thread.per_user.start;
  485. else if (addr == (addr_t) &dummy32->cr11)
  486. /* End address of the active per set. */
  487. return test_thread_flag(TIF_SINGLE_STEP) ?
  488. PSW32_ADDR_INSN : child->thread.per_user.end;
  489. else if (addr == (addr_t) &dummy32->bits)
  490. /* Single-step bit. */
  491. return (__u32) test_thread_flag(TIF_SINGLE_STEP) ?
  492. 0x80000000 : 0;
  493. else if (addr == (addr_t) &dummy32->starting_addr)
  494. /* Start address of the user specified per set. */
  495. return (__u32) child->thread.per_user.start;
  496. else if (addr == (addr_t) &dummy32->ending_addr)
  497. /* End address of the user specified per set. */
  498. return (__u32) child->thread.per_user.end;
  499. else if (addr == (addr_t) &dummy32->perc_atmid)
  500. /* PER code, ATMID and AI of the last PER trap */
  501. return (__u32) child->thread.per_event.cause << 16;
  502. else if (addr == (addr_t) &dummy32->address)
  503. /* Address of the last PER trap */
  504. return (__u32) child->thread.per_event.address;
  505. else if (addr == (addr_t) &dummy32->access_id)
  506. /* Access id of the last PER trap */
  507. return (__u32) child->thread.per_event.paid << 24;
  508. return 0;
  509. }
  510. /*
  511. * Same as peek_user but for a 31 bit program.
  512. */
  513. static u32 __peek_user_compat(struct task_struct *child, addr_t addr)
  514. {
  515. struct compat_user *dummy32 = NULL;
  516. addr_t offset;
  517. __u32 tmp;
  518. if (addr < (addr_t) &dummy32->regs.acrs) {
  519. struct pt_regs *regs = task_pt_regs(child);
  520. /*
  521. * psw and gprs are stored on the stack
  522. */
  523. if (addr == (addr_t) &dummy32->regs.psw.mask) {
  524. /* Fake a 31 bit psw mask. */
  525. tmp = (__u32)(regs->psw.mask >> 32);
  526. tmp &= PSW32_MASK_USER | PSW32_MASK_RI;
  527. tmp |= PSW32_USER_BITS;
  528. } else if (addr == (addr_t) &dummy32->regs.psw.addr) {
  529. /* Fake a 31 bit psw address. */
  530. tmp = (__u32) regs->psw.addr |
  531. (__u32)(regs->psw.mask & PSW_MASK_BA);
  532. } else {
  533. /* gpr 0-15 */
  534. tmp = *(__u32 *)((addr_t) &regs->psw + addr*2 + 4);
  535. }
  536. } else if (addr < (addr_t) (&dummy32->regs.orig_gpr2)) {
  537. /*
  538. * access registers are stored in the thread structure
  539. */
  540. offset = addr - (addr_t) &dummy32->regs.acrs;
  541. tmp = *(__u32*)((addr_t) &child->thread.acrs + offset);
  542. } else if (addr == (addr_t) (&dummy32->regs.orig_gpr2)) {
  543. /*
  544. * orig_gpr2 is stored on the kernel stack
  545. */
  546. tmp = *(__u32*)((addr_t) &task_pt_regs(child)->orig_gpr2 + 4);
  547. } else if (addr < (addr_t) &dummy32->regs.fp_regs) {
  548. /*
  549. * prevent reads of padding hole between
  550. * orig_gpr2 and fp_regs on s390.
  551. */
  552. tmp = 0;
  553. } else if (addr < (addr_t) (&dummy32->regs.fp_regs + 1)) {
  554. /*
  555. * floating point regs. are stored in the thread structure
  556. */
  557. offset = addr - (addr_t) &dummy32->regs.fp_regs;
  558. tmp = *(__u32 *)((addr_t) &child->thread.fp_regs + offset);
  559. } else if (addr < (addr_t) (&dummy32->regs.per_info + 1)) {
  560. /*
  561. * Handle access to the per_info structure.
  562. */
  563. addr -= (addr_t) &dummy32->regs.per_info;
  564. tmp = __peek_user_per_compat(child, addr);
  565. } else
  566. tmp = 0;
  567. return tmp;
  568. }
  569. static int peek_user_compat(struct task_struct *child,
  570. addr_t addr, addr_t data)
  571. {
  572. __u32 tmp;
  573. if (!is_compat_task() || (addr & 3) || addr > sizeof(struct user) - 3)
  574. return -EIO;
  575. tmp = __peek_user_compat(child, addr);
  576. return put_user(tmp, (__u32 __user *) data);
  577. }
  578. /*
  579. * Same as poke_user_per but for a 31 bit program.
  580. */
  581. static inline void __poke_user_per_compat(struct task_struct *child,
  582. addr_t addr, __u32 data)
  583. {
  584. struct compat_per_struct_kernel *dummy32 = NULL;
  585. if (addr == (addr_t) &dummy32->cr9)
  586. /* PER event mask of the user specified per set. */
  587. child->thread.per_user.control =
  588. data & (PER_EVENT_MASK | PER_CONTROL_MASK);
  589. else if (addr == (addr_t) &dummy32->starting_addr)
  590. /* Starting address of the user specified per set. */
  591. child->thread.per_user.start = data;
  592. else if (addr == (addr_t) &dummy32->ending_addr)
  593. /* Ending address of the user specified per set. */
  594. child->thread.per_user.end = data;
  595. }
  596. /*
  597. * Same as poke_user but for a 31 bit program.
  598. */
  599. static int __poke_user_compat(struct task_struct *child,
  600. addr_t addr, addr_t data)
  601. {
  602. struct compat_user *dummy32 = NULL;
  603. __u32 tmp = (__u32) data;
  604. addr_t offset;
  605. if (addr < (addr_t) &dummy32->regs.acrs) {
  606. struct pt_regs *regs = task_pt_regs(child);
  607. /*
  608. * psw, gprs, acrs and orig_gpr2 are stored on the stack
  609. */
  610. if (addr == (addr_t) &dummy32->regs.psw.mask) {
  611. __u32 mask = PSW32_MASK_USER;
  612. mask |= is_ri_task(child) ? PSW32_MASK_RI : 0;
  613. /* Build a 64 bit psw mask from 31 bit mask. */
  614. if ((tmp ^ PSW32_USER_BITS) & ~mask)
  615. /* Invalid psw mask. */
  616. return -EINVAL;
  617. if ((data & PSW32_MASK_ASC) == PSW32_ASC_HOME)
  618. /* Invalid address-space-control bits */
  619. return -EINVAL;
  620. regs->psw.mask = (regs->psw.mask & ~PSW_MASK_USER) |
  621. (regs->psw.mask & PSW_MASK_BA) |
  622. (__u64)(tmp & mask) << 32;
  623. } else if (addr == (addr_t) &dummy32->regs.psw.addr) {
  624. /* Build a 64 bit psw address from 31 bit address. */
  625. regs->psw.addr = (__u64) tmp & PSW32_ADDR_INSN;
  626. /* Transfer 31 bit amode bit to psw mask. */
  627. regs->psw.mask = (regs->psw.mask & ~PSW_MASK_BA) |
  628. (__u64)(tmp & PSW32_ADDR_AMODE);
  629. } else {
  630. /* gpr 0-15 */
  631. *(__u32*)((addr_t) &regs->psw + addr*2 + 4) = tmp;
  632. }
  633. } else if (addr < (addr_t) (&dummy32->regs.orig_gpr2)) {
  634. /*
  635. * access registers are stored in the thread structure
  636. */
  637. offset = addr - (addr_t) &dummy32->regs.acrs;
  638. *(__u32*)((addr_t) &child->thread.acrs + offset) = tmp;
  639. } else if (addr == (addr_t) (&dummy32->regs.orig_gpr2)) {
  640. /*
  641. * orig_gpr2 is stored on the kernel stack
  642. */
  643. *(__u32*)((addr_t) &task_pt_regs(child)->orig_gpr2 + 4) = tmp;
  644. } else if (addr < (addr_t) &dummy32->regs.fp_regs) {
  645. /*
  646. * prevent writess of padding hole between
  647. * orig_gpr2 and fp_regs on s390.
  648. */
  649. return 0;
  650. } else if (addr < (addr_t) (&dummy32->regs.fp_regs + 1)) {
  651. /*
  652. * floating point regs. are stored in the thread structure
  653. */
  654. if (addr == (addr_t) &dummy32->regs.fp_regs.fpc &&
  655. test_fp_ctl(tmp))
  656. return -EINVAL;
  657. offset = addr - (addr_t) &dummy32->regs.fp_regs;
  658. *(__u32 *)((addr_t) &child->thread.fp_regs + offset) = tmp;
  659. } else if (addr < (addr_t) (&dummy32->regs.per_info + 1)) {
  660. /*
  661. * Handle access to the per_info structure.
  662. */
  663. addr -= (addr_t) &dummy32->regs.per_info;
  664. __poke_user_per_compat(child, addr, data);
  665. }
  666. return 0;
  667. }
  668. static int poke_user_compat(struct task_struct *child,
  669. addr_t addr, addr_t data)
  670. {
  671. if (!is_compat_task() || (addr & 3) ||
  672. addr > sizeof(struct compat_user) - 3)
  673. return -EIO;
  674. return __poke_user_compat(child, addr, data);
  675. }
  676. long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
  677. compat_ulong_t caddr, compat_ulong_t cdata)
  678. {
  679. unsigned long addr = caddr;
  680. unsigned long data = cdata;
  681. compat_ptrace_area parea;
  682. int copied, ret;
  683. switch (request) {
  684. case PTRACE_PEEKUSR:
  685. /* read the word at location addr in the USER area. */
  686. return peek_user_compat(child, addr, data);
  687. case PTRACE_POKEUSR:
  688. /* write the word at location addr in the USER area */
  689. return poke_user_compat(child, addr, data);
  690. case PTRACE_PEEKUSR_AREA:
  691. case PTRACE_POKEUSR_AREA:
  692. if (copy_from_user(&parea, (void __force __user *) addr,
  693. sizeof(parea)))
  694. return -EFAULT;
  695. addr = parea.kernel_addr;
  696. data = parea.process_addr;
  697. copied = 0;
  698. while (copied < parea.len) {
  699. if (request == PTRACE_PEEKUSR_AREA)
  700. ret = peek_user_compat(child, addr, data);
  701. else {
  702. __u32 utmp;
  703. if (get_user(utmp,
  704. (__u32 __force __user *) data))
  705. return -EFAULT;
  706. ret = poke_user_compat(child, addr, utmp);
  707. }
  708. if (ret)
  709. return ret;
  710. addr += sizeof(unsigned int);
  711. data += sizeof(unsigned int);
  712. copied += sizeof(unsigned int);
  713. }
  714. return 0;
  715. case PTRACE_GET_LAST_BREAK:
  716. put_user(task_thread_info(child)->last_break,
  717. (unsigned int __user *) data);
  718. return 0;
  719. }
  720. return compat_ptrace_request(child, request, addr, data);
  721. }
  722. #endif
  723. asmlinkage long do_syscall_trace_enter(struct pt_regs *regs)
  724. {
  725. long ret = 0;
  726. /* Do the secure computing check first. */
  727. if (secure_computing(regs->gprs[2])) {
  728. /* seccomp failures shouldn't expose any additional code. */
  729. ret = -1;
  730. goto out;
  731. }
  732. /*
  733. * The sysc_tracesys code in entry.S stored the system
  734. * call number to gprs[2].
  735. */
  736. if (test_thread_flag(TIF_SYSCALL_TRACE) &&
  737. (tracehook_report_syscall_entry(regs) ||
  738. regs->gprs[2] >= NR_syscalls)) {
  739. /*
  740. * Tracing decided this syscall should not happen or the
  741. * debugger stored an invalid system call number. Skip
  742. * the system call and the system call restart handling.
  743. */
  744. clear_pt_regs_flag(regs, PIF_SYSCALL);
  745. ret = -1;
  746. }
  747. if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
  748. trace_sys_enter(regs, regs->gprs[2]);
  749. audit_syscall_entry(is_compat_task() ?
  750. AUDIT_ARCH_S390 : AUDIT_ARCH_S390X,
  751. regs->gprs[2], regs->orig_gpr2,
  752. regs->gprs[3], regs->gprs[4],
  753. regs->gprs[5]);
  754. out:
  755. return ret ?: regs->gprs[2];
  756. }
  757. asmlinkage void do_syscall_trace_exit(struct pt_regs *regs)
  758. {
  759. audit_syscall_exit(regs);
  760. if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
  761. trace_sys_exit(regs, regs->gprs[2]);
  762. if (test_thread_flag(TIF_SYSCALL_TRACE))
  763. tracehook_report_syscall_exit(regs, 0);
  764. }
  765. /*
  766. * user_regset definitions.
  767. */
  768. static int s390_regs_get(struct task_struct *target,
  769. const struct user_regset *regset,
  770. unsigned int pos, unsigned int count,
  771. void *kbuf, void __user *ubuf)
  772. {
  773. if (target == current)
  774. save_access_regs(target->thread.acrs);
  775. if (kbuf) {
  776. unsigned long *k = kbuf;
  777. while (count > 0) {
  778. *k++ = __peek_user(target, pos);
  779. count -= sizeof(*k);
  780. pos += sizeof(*k);
  781. }
  782. } else {
  783. unsigned long __user *u = ubuf;
  784. while (count > 0) {
  785. if (__put_user(__peek_user(target, pos), u++))
  786. return -EFAULT;
  787. count -= sizeof(*u);
  788. pos += sizeof(*u);
  789. }
  790. }
  791. return 0;
  792. }
  793. static int s390_regs_set(struct task_struct *target,
  794. const struct user_regset *regset,
  795. unsigned int pos, unsigned int count,
  796. const void *kbuf, const void __user *ubuf)
  797. {
  798. int rc = 0;
  799. if (target == current)
  800. save_access_regs(target->thread.acrs);
  801. if (kbuf) {
  802. const unsigned long *k = kbuf;
  803. while (count > 0 && !rc) {
  804. rc = __poke_user(target, pos, *k++);
  805. count -= sizeof(*k);
  806. pos += sizeof(*k);
  807. }
  808. } else {
  809. const unsigned long __user *u = ubuf;
  810. while (count > 0 && !rc) {
  811. unsigned long word;
  812. rc = __get_user(word, u++);
  813. if (rc)
  814. break;
  815. rc = __poke_user(target, pos, word);
  816. count -= sizeof(*u);
  817. pos += sizeof(*u);
  818. }
  819. }
  820. if (rc == 0 && target == current)
  821. restore_access_regs(target->thread.acrs);
  822. return rc;
  823. }
  824. static int s390_fpregs_get(struct task_struct *target,
  825. const struct user_regset *regset, unsigned int pos,
  826. unsigned int count, void *kbuf, void __user *ubuf)
  827. {
  828. if (target == current) {
  829. save_fp_ctl(&target->thread.fp_regs.fpc);
  830. save_fp_regs(target->thread.fp_regs.fprs);
  831. }
  832. return user_regset_copyout(&pos, &count, &kbuf, &ubuf,
  833. &target->thread.fp_regs, 0, -1);
  834. }
  835. static int s390_fpregs_set(struct task_struct *target,
  836. const struct user_regset *regset, unsigned int pos,
  837. unsigned int count, const void *kbuf,
  838. const void __user *ubuf)
  839. {
  840. int rc = 0;
  841. if (target == current) {
  842. save_fp_ctl(&target->thread.fp_regs.fpc);
  843. save_fp_regs(target->thread.fp_regs.fprs);
  844. }
  845. /* If setting FPC, must validate it first. */
  846. if (count > 0 && pos < offsetof(s390_fp_regs, fprs)) {
  847. u32 ufpc[2] = { target->thread.fp_regs.fpc, 0 };
  848. rc = user_regset_copyin(&pos, &count, &kbuf, &ubuf, &ufpc,
  849. 0, offsetof(s390_fp_regs, fprs));
  850. if (rc)
  851. return rc;
  852. if (ufpc[1] != 0 || test_fp_ctl(ufpc[0]))
  853. return -EINVAL;
  854. target->thread.fp_regs.fpc = ufpc[0];
  855. }
  856. if (rc == 0 && count > 0)
  857. rc = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
  858. target->thread.fp_regs.fprs,
  859. offsetof(s390_fp_regs, fprs), -1);
  860. if (rc == 0 && target == current) {
  861. restore_fp_ctl(&target->thread.fp_regs.fpc);
  862. restore_fp_regs(target->thread.fp_regs.fprs);
  863. }
  864. return rc;
  865. }
  866. #ifdef CONFIG_64BIT
  867. static int s390_last_break_get(struct task_struct *target,
  868. const struct user_regset *regset,
  869. unsigned int pos, unsigned int count,
  870. void *kbuf, void __user *ubuf)
  871. {
  872. if (count > 0) {
  873. if (kbuf) {
  874. unsigned long *k = kbuf;
  875. *k = task_thread_info(target)->last_break;
  876. } else {
  877. unsigned long __user *u = ubuf;
  878. if (__put_user(task_thread_info(target)->last_break, u))
  879. return -EFAULT;
  880. }
  881. }
  882. return 0;
  883. }
  884. static int s390_last_break_set(struct task_struct *target,
  885. const struct user_regset *regset,
  886. unsigned int pos, unsigned int count,
  887. const void *kbuf, const void __user *ubuf)
  888. {
  889. return 0;
  890. }
  891. static int s390_tdb_get(struct task_struct *target,
  892. const struct user_regset *regset,
  893. unsigned int pos, unsigned int count,
  894. void *kbuf, void __user *ubuf)
  895. {
  896. struct pt_regs *regs = task_pt_regs(target);
  897. unsigned char *data;
  898. if (!(regs->int_code & 0x200))
  899. return -ENODATA;
  900. data = target->thread.trap_tdb;
  901. return user_regset_copyout(&pos, &count, &kbuf, &ubuf, data, 0, 256);
  902. }
  903. static int s390_tdb_set(struct task_struct *target,
  904. const struct user_regset *regset,
  905. unsigned int pos, unsigned int count,
  906. const void *kbuf, const void __user *ubuf)
  907. {
  908. return 0;
  909. }
  910. #endif
  911. static int s390_system_call_get(struct task_struct *target,
  912. const struct user_regset *regset,
  913. unsigned int pos, unsigned int count,
  914. void *kbuf, void __user *ubuf)
  915. {
  916. unsigned int *data = &task_thread_info(target)->system_call;
  917. return user_regset_copyout(&pos, &count, &kbuf, &ubuf,
  918. data, 0, sizeof(unsigned int));
  919. }
  920. static int s390_system_call_set(struct task_struct *target,
  921. const struct user_regset *regset,
  922. unsigned int pos, unsigned int count,
  923. const void *kbuf, const void __user *ubuf)
  924. {
  925. unsigned int *data = &task_thread_info(target)->system_call;
  926. return user_regset_copyin(&pos, &count, &kbuf, &ubuf,
  927. data, 0, sizeof(unsigned int));
  928. }
  929. static const struct user_regset s390_regsets[] = {
  930. [REGSET_GENERAL] = {
  931. .core_note_type = NT_PRSTATUS,
  932. .n = sizeof(s390_regs) / sizeof(long),
  933. .size = sizeof(long),
  934. .align = sizeof(long),
  935. .get = s390_regs_get,
  936. .set = s390_regs_set,
  937. },
  938. [REGSET_FP] = {
  939. .core_note_type = NT_PRFPREG,
  940. .n = sizeof(s390_fp_regs) / sizeof(long),
  941. .size = sizeof(long),
  942. .align = sizeof(long),
  943. .get = s390_fpregs_get,
  944. .set = s390_fpregs_set,
  945. },
  946. #ifdef CONFIG_64BIT
  947. [REGSET_LAST_BREAK] = {
  948. .core_note_type = NT_S390_LAST_BREAK,
  949. .n = 1,
  950. .size = sizeof(long),
  951. .align = sizeof(long),
  952. .get = s390_last_break_get,
  953. .set = s390_last_break_set,
  954. },
  955. [REGSET_TDB] = {
  956. .core_note_type = NT_S390_TDB,
  957. .n = 1,
  958. .size = 256,
  959. .align = 1,
  960. .get = s390_tdb_get,
  961. .set = s390_tdb_set,
  962. },
  963. #endif
  964. [REGSET_SYSTEM_CALL] = {
  965. .core_note_type = NT_S390_SYSTEM_CALL,
  966. .n = 1,
  967. .size = sizeof(unsigned int),
  968. .align = sizeof(unsigned int),
  969. .get = s390_system_call_get,
  970. .set = s390_system_call_set,
  971. },
  972. };
  973. static const struct user_regset_view user_s390_view = {
  974. .name = UTS_MACHINE,
  975. .e_machine = EM_S390,
  976. .regsets = s390_regsets,
  977. .n = ARRAY_SIZE(s390_regsets)
  978. };
  979. #ifdef CONFIG_COMPAT
  980. static int s390_compat_regs_get(struct task_struct *target,
  981. const struct user_regset *regset,
  982. unsigned int pos, unsigned int count,
  983. void *kbuf, void __user *ubuf)
  984. {
  985. if (target == current)
  986. save_access_regs(target->thread.acrs);
  987. if (kbuf) {
  988. compat_ulong_t *k = kbuf;
  989. while (count > 0) {
  990. *k++ = __peek_user_compat(target, pos);
  991. count -= sizeof(*k);
  992. pos += sizeof(*k);
  993. }
  994. } else {
  995. compat_ulong_t __user *u = ubuf;
  996. while (count > 0) {
  997. if (__put_user(__peek_user_compat(target, pos), u++))
  998. return -EFAULT;
  999. count -= sizeof(*u);
  1000. pos += sizeof(*u);
  1001. }
  1002. }
  1003. return 0;
  1004. }
  1005. static int s390_compat_regs_set(struct task_struct *target,
  1006. const struct user_regset *regset,
  1007. unsigned int pos, unsigned int count,
  1008. const void *kbuf, const void __user *ubuf)
  1009. {
  1010. int rc = 0;
  1011. if (target == current)
  1012. save_access_regs(target->thread.acrs);
  1013. if (kbuf) {
  1014. const compat_ulong_t *k = kbuf;
  1015. while (count > 0 && !rc) {
  1016. rc = __poke_user_compat(target, pos, *k++);
  1017. count -= sizeof(*k);
  1018. pos += sizeof(*k);
  1019. }
  1020. } else {
  1021. const compat_ulong_t __user *u = ubuf;
  1022. while (count > 0 && !rc) {
  1023. compat_ulong_t word;
  1024. rc = __get_user(word, u++);
  1025. if (rc)
  1026. break;
  1027. rc = __poke_user_compat(target, pos, word);
  1028. count -= sizeof(*u);
  1029. pos += sizeof(*u);
  1030. }
  1031. }
  1032. if (rc == 0 && target == current)
  1033. restore_access_regs(target->thread.acrs);
  1034. return rc;
  1035. }
  1036. static int s390_compat_regs_high_get(struct task_struct *target,
  1037. const struct user_regset *regset,
  1038. unsigned int pos, unsigned int count,
  1039. void *kbuf, void __user *ubuf)
  1040. {
  1041. compat_ulong_t *gprs_high;
  1042. gprs_high = (compat_ulong_t *)
  1043. &task_pt_regs(target)->gprs[pos / sizeof(compat_ulong_t)];
  1044. if (kbuf) {
  1045. compat_ulong_t *k = kbuf;
  1046. while (count > 0) {
  1047. *k++ = *gprs_high;
  1048. gprs_high += 2;
  1049. count -= sizeof(*k);
  1050. }
  1051. } else {
  1052. compat_ulong_t __user *u = ubuf;
  1053. while (count > 0) {
  1054. if (__put_user(*gprs_high, u++))
  1055. return -EFAULT;
  1056. gprs_high += 2;
  1057. count -= sizeof(*u);
  1058. }
  1059. }
  1060. return 0;
  1061. }
  1062. static int s390_compat_regs_high_set(struct task_struct *target,
  1063. const struct user_regset *regset,
  1064. unsigned int pos, unsigned int count,
  1065. const void *kbuf, const void __user *ubuf)
  1066. {
  1067. compat_ulong_t *gprs_high;
  1068. int rc = 0;
  1069. gprs_high = (compat_ulong_t *)
  1070. &task_pt_regs(target)->gprs[pos / sizeof(compat_ulong_t)];
  1071. if (kbuf) {
  1072. const compat_ulong_t *k = kbuf;
  1073. while (count > 0) {
  1074. *gprs_high = *k++;
  1075. *gprs_high += 2;
  1076. count -= sizeof(*k);
  1077. }
  1078. } else {
  1079. const compat_ulong_t __user *u = ubuf;
  1080. while (count > 0 && !rc) {
  1081. unsigned long word;
  1082. rc = __get_user(word, u++);
  1083. if (rc)
  1084. break;
  1085. *gprs_high = word;
  1086. *gprs_high += 2;
  1087. count -= sizeof(*u);
  1088. }
  1089. }
  1090. return rc;
  1091. }
  1092. static int s390_compat_last_break_get(struct task_struct *target,
  1093. const struct user_regset *regset,
  1094. unsigned int pos, unsigned int count,
  1095. void *kbuf, void __user *ubuf)
  1096. {
  1097. compat_ulong_t last_break;
  1098. if (count > 0) {
  1099. last_break = task_thread_info(target)->last_break;
  1100. if (kbuf) {
  1101. unsigned long *k = kbuf;
  1102. *k = last_break;
  1103. } else {
  1104. unsigned long __user *u = ubuf;
  1105. if (__put_user(last_break, u))
  1106. return -EFAULT;
  1107. }
  1108. }
  1109. return 0;
  1110. }
  1111. static int s390_compat_last_break_set(struct task_struct *target,
  1112. const struct user_regset *regset,
  1113. unsigned int pos, unsigned int count,
  1114. const void *kbuf, const void __user *ubuf)
  1115. {
  1116. return 0;
  1117. }
  1118. static const struct user_regset s390_compat_regsets[] = {
  1119. [REGSET_GENERAL] = {
  1120. .core_note_type = NT_PRSTATUS,
  1121. .n = sizeof(s390_compat_regs) / sizeof(compat_long_t),
  1122. .size = sizeof(compat_long_t),
  1123. .align = sizeof(compat_long_t),
  1124. .get = s390_compat_regs_get,
  1125. .set = s390_compat_regs_set,
  1126. },
  1127. [REGSET_FP] = {
  1128. .core_note_type = NT_PRFPREG,
  1129. .n = sizeof(s390_fp_regs) / sizeof(compat_long_t),
  1130. .size = sizeof(compat_long_t),
  1131. .align = sizeof(compat_long_t),
  1132. .get = s390_fpregs_get,
  1133. .set = s390_fpregs_set,
  1134. },
  1135. [REGSET_LAST_BREAK] = {
  1136. .core_note_type = NT_S390_LAST_BREAK,
  1137. .n = 1,
  1138. .size = sizeof(long),
  1139. .align = sizeof(long),
  1140. .get = s390_compat_last_break_get,
  1141. .set = s390_compat_last_break_set,
  1142. },
  1143. [REGSET_TDB] = {
  1144. .core_note_type = NT_S390_TDB,
  1145. .n = 1,
  1146. .size = 256,
  1147. .align = 1,
  1148. .get = s390_tdb_get,
  1149. .set = s390_tdb_set,
  1150. },
  1151. [REGSET_SYSTEM_CALL] = {
  1152. .core_note_type = NT_S390_SYSTEM_CALL,
  1153. .n = 1,
  1154. .size = sizeof(compat_uint_t),
  1155. .align = sizeof(compat_uint_t),
  1156. .get = s390_system_call_get,
  1157. .set = s390_system_call_set,
  1158. },
  1159. [REGSET_GENERAL_EXTENDED] = {
  1160. .core_note_type = NT_S390_HIGH_GPRS,
  1161. .n = sizeof(s390_compat_regs_high) / sizeof(compat_long_t),
  1162. .size = sizeof(compat_long_t),
  1163. .align = sizeof(compat_long_t),
  1164. .get = s390_compat_regs_high_get,
  1165. .set = s390_compat_regs_high_set,
  1166. },
  1167. };
  1168. static const struct user_regset_view user_s390_compat_view = {
  1169. .name = "s390",
  1170. .e_machine = EM_S390,
  1171. .regsets = s390_compat_regsets,
  1172. .n = ARRAY_SIZE(s390_compat_regsets)
  1173. };
  1174. #endif
  1175. const struct user_regset_view *task_user_regset_view(struct task_struct *task)
  1176. {
  1177. #ifdef CONFIG_COMPAT
  1178. if (test_tsk_thread_flag(task, TIF_31BIT))
  1179. return &user_s390_compat_view;
  1180. #endif
  1181. return &user_s390_view;
  1182. }
  1183. static const char *gpr_names[NUM_GPRS] = {
  1184. "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
  1185. "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
  1186. };
  1187. unsigned long regs_get_register(struct pt_regs *regs, unsigned int offset)
  1188. {
  1189. if (offset >= NUM_GPRS)
  1190. return 0;
  1191. return regs->gprs[offset];
  1192. }
  1193. int regs_query_register_offset(const char *name)
  1194. {
  1195. unsigned long offset;
  1196. if (!name || *name != 'r')
  1197. return -EINVAL;
  1198. if (kstrtoul(name + 1, 10, &offset))
  1199. return -EINVAL;
  1200. if (offset >= NUM_GPRS)
  1201. return -EINVAL;
  1202. return offset;
  1203. }
  1204. const char *regs_query_register_name(unsigned int offset)
  1205. {
  1206. if (offset >= NUM_GPRS)
  1207. return NULL;
  1208. return gpr_names[offset];
  1209. }
  1210. static int regs_within_kernel_stack(struct pt_regs *regs, unsigned long addr)
  1211. {
  1212. unsigned long ksp = kernel_stack_pointer(regs);
  1213. return (addr & ~(THREAD_SIZE - 1)) == (ksp & ~(THREAD_SIZE - 1));
  1214. }
  1215. /**
  1216. * regs_get_kernel_stack_nth() - get Nth entry of the stack
  1217. * @regs:pt_regs which contains kernel stack pointer.
  1218. * @n:stack entry number.
  1219. *
  1220. * regs_get_kernel_stack_nth() returns @n th entry of the kernel stack which
  1221. * is specifined by @regs. If the @n th entry is NOT in the kernel stack,
  1222. * this returns 0.
  1223. */
  1224. unsigned long regs_get_kernel_stack_nth(struct pt_regs *regs, unsigned int n)
  1225. {
  1226. unsigned long addr;
  1227. addr = kernel_stack_pointer(regs) + n * sizeof(long);
  1228. if (!regs_within_kernel_stack(regs, addr))
  1229. return 0;
  1230. return *(unsigned long *)addr;
  1231. }