ptrace.c 34 KB

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