ptrace.c 33 KB

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