ptrace.c 33 KB

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