blob: 83339d33c4b127b0aaf2e36a7e56aef91b57bbfa [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * arch/s390/kernel/ptrace.c
3 *
4 * S390 version
5 * Copyright (C) 1999,2000 IBM Deutschland Entwicklung GmbH, IBM Corporation
6 * Author(s): Denis Joseph Barrow (djbarrow@de.ibm.com,barrow_dj@yahoo.com),
7 * Martin Schwidefsky (schwidefsky@de.ibm.com)
8 *
9 * Based on PowerPC version
10 * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org)
11 *
12 * Derived from "arch/m68k/kernel/ptrace.c"
13 * Copyright (C) 1994 by Hamish Macdonald
14 * Taken from linux/kernel/ptrace.c and modified for M680x0.
15 * linux/kernel/ptrace.c is by Ross Biro 1/23/92, edited by Linus Torvalds
16 *
17 * Modified by Cort Dougan (cort@cs.nmt.edu)
18 *
19 *
20 * This file is subject to the terms and conditions of the GNU General
21 * Public License. See the file README.legal in the main directory of
22 * this archive for more details.
23 */
24
25#include <linux/kernel.h>
26#include <linux/sched.h>
27#include <linux/mm.h>
28#include <linux/smp.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070029#include <linux/errno.h>
30#include <linux/ptrace.h>
31#include <linux/user.h>
32#include <linux/security.h>
33#include <linux/audit.h>
Jesper Juhl7ed20e12005-05-01 08:59:14 -070034#include <linux/signal.h>
Martin Schwidefsky63506c42008-07-14 09:58:54 +020035#include <linux/elf.h>
36#include <linux/regset.h>
Martin Schwidefsky753c4dd2008-10-10 21:33:20 +020037#include <linux/tracehook.h>
Heiko Carstensbcf5cef2009-06-12 10:26:26 +020038#include <linux/seccomp.h>
Heiko Carstens9bf12262009-06-12 10:26:47 +020039#include <trace/syscall.h>
Heiko Carstensbcf5cef2009-06-12 10:26:26 +020040#include <asm/compat.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070041#include <asm/segment.h>
42#include <asm/page.h>
43#include <asm/pgtable.h>
44#include <asm/pgalloc.h>
45#include <asm/system.h>
46#include <asm/uaccess.h>
Martin Schwidefsky778959d2005-06-04 15:43:30 -070047#include <asm/unistd.h>
Heiko Carstensa8061702008-04-17 07:46:26 +020048#include "entry.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070049
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -080050#ifdef CONFIG_COMPAT
Linus Torvalds1da177e2005-04-16 15:20:36 -070051#include "compat_ptrace.h"
52#endif
53
Josh Stone1c569f02009-08-24 14:43:14 -070054#define CREATE_TRACE_POINTS
55#include <trace/events/syscalls.h>
Ingo Molnar5e9ad7d2009-08-18 10:41:57 +020056
Martin Schwidefsky63506c42008-07-14 09:58:54 +020057enum s390_regset {
58 REGSET_GENERAL,
59 REGSET_FP,
Martin Schwidefsky86f25522010-05-17 10:00:05 +020060 REGSET_LAST_BREAK,
Heiko Carstensea2a4d32009-10-06 10:34:13 +020061 REGSET_GENERAL_EXTENDED,
Martin Schwidefsky63506c42008-07-14 09:58:54 +020062};
63
Linus Torvalds1da177e2005-04-16 15:20:36 -070064static void
65FixPerRegisters(struct task_struct *task)
66{
67 struct pt_regs *regs;
68 per_struct *per_info;
Martin Schwidefskyc3311c12010-01-13 20:44:25 +010069 per_cr_words cr_words;
Linus Torvalds1da177e2005-04-16 15:20:36 -070070
Al Viroc7584fb2006-01-12 01:05:49 -080071 regs = task_pt_regs(task);
Linus Torvalds1da177e2005-04-16 15:20:36 -070072 per_info = (per_struct *) &task->thread.per_info;
73 per_info->control_regs.bits.em_instruction_fetch =
74 per_info->single_step | per_info->instruction_fetch;
75
76 if (per_info->single_step) {
77 per_info->control_regs.bits.starting_addr = 0;
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -080078#ifdef CONFIG_COMPAT
Heiko Carstens77575912009-06-12 10:26:25 +020079 if (is_compat_task())
Linus Torvalds1da177e2005-04-16 15:20:36 -070080 per_info->control_regs.bits.ending_addr = 0x7fffffffUL;
81 else
82#endif
83 per_info->control_regs.bits.ending_addr = PSW_ADDR_INSN;
84 } else {
85 per_info->control_regs.bits.starting_addr =
86 per_info->starting_addr;
87 per_info->control_regs.bits.ending_addr =
88 per_info->ending_addr;
89 }
90 /*
91 * if any of the control reg tracing bits are on
92 * we switch on per in the psw
93 */
94 if (per_info->control_regs.words.cr[0] & PER_EM_MASK)
95 regs->psw.mask |= PSW_MASK_PER;
96 else
97 regs->psw.mask &= ~PSW_MASK_PER;
98
99 if (per_info->control_regs.bits.em_storage_alteration)
100 per_info->control_regs.bits.storage_alt_space_ctl = 1;
101 else
102 per_info->control_regs.bits.storage_alt_space_ctl = 0;
Martin Schwidefskyc3311c12010-01-13 20:44:25 +0100103
104 if (task == current) {
105 __ctl_store(cr_words, 9, 11);
106 if (memcmp(&cr_words, &per_info->control_regs.words,
107 sizeof(cr_words)) != 0)
108 __ctl_load(per_info->control_regs.words, 9, 11);
109 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110}
111
Roland McGrath0ac30be2008-01-26 14:11:22 +0100112void user_enable_single_step(struct task_struct *task)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113{
114 task->thread.per_info.single_step = 1;
115 FixPerRegisters(task);
116}
117
Roland McGrath0ac30be2008-01-26 14:11:22 +0100118void user_disable_single_step(struct task_struct *task)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119{
120 task->thread.per_info.single_step = 0;
121 FixPerRegisters(task);
122}
123
124/*
125 * Called by kernel/ptrace.c when detaching..
126 *
127 * Make sure single step bits etc are not set.
128 */
129void
130ptrace_disable(struct task_struct *child)
131{
132 /* make sure the single step bit is not set. */
Roland McGrath0ac30be2008-01-26 14:11:22 +0100133 user_disable_single_step(child);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134}
135
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800136#ifndef CONFIG_64BIT
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137# define __ADDR_MASK 3
138#else
139# define __ADDR_MASK 7
140#endif
141
142/*
143 * Read the word at offset addr from the user area of a process. The
144 * trouble here is that the information is littered over different
145 * locations. The process registers are found on the kernel stack,
146 * the floating point stuff and the trace settings are stored in
147 * the task structure. In addition the different structures in
148 * struct user contain pad bytes that should be read as zeroes.
149 * Lovely...
150 */
Martin Schwidefsky63506c42008-07-14 09:58:54 +0200151static unsigned long __peek_user(struct task_struct *child, addr_t addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152{
153 struct user *dummy = NULL;
Martin Schwidefsky63506c42008-07-14 09:58:54 +0200154 addr_t offset, tmp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155
156 if (addr < (addr_t) &dummy->regs.acrs) {
157 /*
158 * psw and gprs are stored on the stack
159 */
Al Viroc7584fb2006-01-12 01:05:49 -0800160 tmp = *(addr_t *)((addr_t) &task_pt_regs(child)->psw + addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161 if (addr == (addr_t) &dummy->regs.psw.mask)
162 /* Remove per bit from user psw. */
163 tmp &= ~PSW_MASK_PER;
164
165 } else if (addr < (addr_t) &dummy->regs.orig_gpr2) {
166 /*
167 * access registers are stored in the thread structure
168 */
169 offset = addr - (addr_t) &dummy->regs.acrs;
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800170#ifdef CONFIG_64BIT
Martin Schwidefsky778959d2005-06-04 15:43:30 -0700171 /*
172 * Very special case: old & broken 64 bit gdb reading
173 * from acrs[15]. Result is a 64 bit value. Read the
174 * 32 bit acrs[15] value and shift it by 32. Sick...
175 */
176 if (addr == (addr_t) &dummy->regs.acrs[15])
177 tmp = ((unsigned long) child->thread.acrs[15]) << 32;
178 else
179#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180 tmp = *(addr_t *)((addr_t) &child->thread.acrs + offset);
181
182 } else if (addr == (addr_t) &dummy->regs.orig_gpr2) {
183 /*
184 * orig_gpr2 is stored on the kernel stack
185 */
Al Viroc7584fb2006-01-12 01:05:49 -0800186 tmp = (addr_t) task_pt_regs(child)->orig_gpr2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187
Jarod Wilson3d6e48f2008-09-09 12:38:56 +0200188 } else if (addr < (addr_t) &dummy->regs.fp_regs) {
189 /*
190 * prevent reads of padding hole between
191 * orig_gpr2 and fp_regs on s390.
192 */
193 tmp = 0;
194
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195 } else if (addr < (addr_t) (&dummy->regs.fp_regs + 1)) {
196 /*
197 * floating point regs. are stored in the thread structure
198 */
199 offset = addr - (addr_t) &dummy->regs.fp_regs;
200 tmp = *(addr_t *)((addr_t) &child->thread.fp_regs + offset);
Martin Schwidefsky778959d2005-06-04 15:43:30 -0700201 if (addr == (addr_t) &dummy->regs.fp_regs.fpc)
202 tmp &= (unsigned long) FPC_VALID_MASK
203 << (BITS_PER_LONG - 32);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204
205 } else if (addr < (addr_t) (&dummy->regs.per_info + 1)) {
206 /*
207 * per_info is found in the thread structure
208 */
209 offset = addr - (addr_t) &dummy->regs.per_info;
210 tmp = *(addr_t *)((addr_t) &child->thread.per_info + offset);
211
212 } else
213 tmp = 0;
214
Martin Schwidefsky63506c42008-07-14 09:58:54 +0200215 return tmp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216}
217
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218static int
Martin Schwidefsky63506c42008-07-14 09:58:54 +0200219peek_user(struct task_struct *child, addr_t addr, addr_t data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220{
Martin Schwidefsky63506c42008-07-14 09:58:54 +0200221 addr_t tmp, mask;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222
223 /*
224 * Stupid gdb peeks/pokes the access registers in 64 bit with
Martin Schwidefsky63506c42008-07-14 09:58:54 +0200225 * an alignment of 4. Programmers from hell...
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226 */
Martin Schwidefsky778959d2005-06-04 15:43:30 -0700227 mask = __ADDR_MASK;
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800228#ifdef CONFIG_64BIT
Martin Schwidefsky547e3ce2008-12-25 13:39:00 +0100229 if (addr >= (addr_t) &((struct user *) NULL)->regs.acrs &&
230 addr < (addr_t) &((struct user *) NULL)->regs.orig_gpr2)
Martin Schwidefsky778959d2005-06-04 15:43:30 -0700231 mask = 3;
232#endif
233 if ((addr & mask) || addr > sizeof(struct user) - __ADDR_MASK)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234 return -EIO;
235
Martin Schwidefsky63506c42008-07-14 09:58:54 +0200236 tmp = __peek_user(child, addr);
237 return put_user(tmp, (addr_t __user *) data);
238}
239
240/*
241 * Write a word to the user area of a process at location addr. This
242 * operation does have an additional problem compared to peek_user.
243 * Stores to the program status word and on the floating point
244 * control register needs to get checked for validity.
245 */
246static int __poke_user(struct task_struct *child, addr_t addr, addr_t data)
247{
248 struct user *dummy = NULL;
249 addr_t offset;
250
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251 if (addr < (addr_t) &dummy->regs.acrs) {
252 /*
253 * psw and gprs are stored on the stack
254 */
255 if (addr == (addr_t) &dummy->regs.psw.mask &&
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800256#ifdef CONFIG_COMPAT
Gerald Schaeferc1821c22007-02-05 21:18:17 +0100257 data != PSW_MASK_MERGE(psw_user32_bits, data) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258#endif
Gerald Schaeferc1821c22007-02-05 21:18:17 +0100259 data != PSW_MASK_MERGE(psw_user_bits, data))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260 /* Invalid psw mask. */
261 return -EINVAL;
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800262#ifndef CONFIG_64BIT
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263 if (addr == (addr_t) &dummy->regs.psw.addr)
264 /* I'd like to reject addresses without the
265 high order bit but older gdb's rely on it */
266 data |= PSW_ADDR_AMODE;
267#endif
Al Viroc7584fb2006-01-12 01:05:49 -0800268 *(addr_t *)((addr_t) &task_pt_regs(child)->psw + addr) = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269
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;
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800275#ifdef CONFIG_64BIT
Martin Schwidefsky778959d2005-06-04 15:43:30 -0700276 /*
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
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286 *(addr_t *)((addr_t) &child->thread.acrs + offset) = data;
287
288 } else if (addr == (addr_t) &dummy->regs.orig_gpr2) {
289 /*
290 * orig_gpr2 is stored on the kernel stack
291 */
Al Viroc7584fb2006-01-12 01:05:49 -0800292 task_pt_regs(child)->orig_gpr2 = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293
Jarod Wilson3d6e48f2008-09-09 12:38:56 +0200294 } 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
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301 } else if (addr < (addr_t) (&dummy->regs.fp_regs + 1)) {
302 /*
303 * floating point regs. are stored in the thread structure
304 */
305 if (addr == (addr_t) &dummy->regs.fp_regs.fpc &&
Martin Schwidefsky778959d2005-06-04 15:43:30 -0700306 (data & ~((unsigned long) FPC_VALID_MASK
307 << (BITS_PER_LONG - 32))) != 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700308 return -EINVAL;
309 offset = addr - (addr_t) &dummy->regs.fp_regs;
310 *(addr_t *)((addr_t) &child->thread.fp_regs + offset) = data;
311
312 } else if (addr < (addr_t) (&dummy->regs.per_info + 1)) {
313 /*
314 * per_info is found in the thread structure
315 */
316 offset = addr - (addr_t) &dummy->regs.per_info;
317 *(addr_t *)((addr_t) &child->thread.per_info + offset) = data;
318
319 }
320
321 FixPerRegisters(child);
322 return 0;
323}
324
Martin Schwidefsky63506c42008-07-14 09:58:54 +0200325static int
326poke_user(struct task_struct *child, addr_t addr, addr_t data)
327{
Martin Schwidefsky63506c42008-07-14 09:58:54 +0200328 addr_t mask;
329
330 /*
331 * Stupid gdb peeks/pokes the access registers in 64 bit with
332 * an alignment of 4. Programmers from hell indeed...
333 */
334 mask = __ADDR_MASK;
335#ifdef CONFIG_64BIT
Martin Schwidefsky547e3ce2008-12-25 13:39:00 +0100336 if (addr >= (addr_t) &((struct user *) NULL)->regs.acrs &&
337 addr < (addr_t) &((struct user *) NULL)->regs.orig_gpr2)
Martin Schwidefsky63506c42008-07-14 09:58:54 +0200338 mask = 3;
339#endif
340 if ((addr & mask) || addr > sizeof(struct user) - __ADDR_MASK)
341 return -EIO;
342
343 return __poke_user(child, addr, data);
344}
345
Roland McGrathb499d762008-05-07 09:22:57 +0200346long arch_ptrace(struct task_struct *child, long request, long addr, long data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348 ptrace_area parea;
349 int copied, ret;
350
351 switch (request) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352 case PTRACE_PEEKUSR:
353 /* read the word at location addr in the USER area. */
354 return peek_user(child, addr, data);
355
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356 case PTRACE_POKEUSR:
357 /* write the word at location addr in the USER area */
358 return poke_user(child, addr, data);
359
360 case PTRACE_PEEKUSR_AREA:
361 case PTRACE_POKEUSR_AREA:
Heiko Carstens2b67fc42007-02-05 21:16:47 +0100362 if (copy_from_user(&parea, (void __force __user *) addr,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363 sizeof(parea)))
364 return -EFAULT;
365 addr = parea.kernel_addr;
366 data = parea.process_addr;
367 copied = 0;
368 while (copied < parea.len) {
369 if (request == PTRACE_PEEKUSR_AREA)
370 ret = peek_user(child, addr, data);
371 else {
Heiko Carstens2b67fc42007-02-05 21:16:47 +0100372 addr_t utmp;
373 if (get_user(utmp,
374 (addr_t __force __user *) data))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375 return -EFAULT;
Heiko Carstens2b67fc42007-02-05 21:16:47 +0100376 ret = poke_user(child, addr, utmp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377 }
378 if (ret)
379 return ret;
380 addr += sizeof(unsigned long);
381 data += sizeof(unsigned long);
382 copied += sizeof(unsigned long);
383 }
384 return 0;
Martin Schwidefsky86f25522010-05-17 10:00:05 +0200385 case PTRACE_GET_LAST_BREAK:
386 put_user(task_thread_info(child)->last_break,
387 (unsigned long __user *) data);
388 return 0;
Christian Borntraeger07805ac2009-09-22 22:58:48 +0200389 default:
390 /* Removing high order bit from addr (only for 31 bit). */
391 addr &= PSW_ADDR_INSN;
392 return ptrace_request(child, request, addr, data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394}
395
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800396#ifdef CONFIG_COMPAT
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397/*
398 * Now the fun part starts... a 31 bit program running in the
399 * 31 bit emulation tracing another program. PTRACE_PEEKTEXT,
400 * PTRACE_PEEKDATA, PTRACE_POKETEXT and PTRACE_POKEDATA are easy
401 * to handle, the difference to the 64 bit versions of the requests
402 * is that the access is done in multiples of 4 byte instead of
403 * 8 bytes (sizeof(unsigned long) on 31/64 bit).
404 * The ugly part are PTRACE_PEEKUSR, PTRACE_PEEKUSR_AREA,
405 * PTRACE_POKEUSR and PTRACE_POKEUSR_AREA. If the traced program
406 * is a 31 bit program too, the content of struct user can be
407 * emulated. A 31 bit program peeking into the struct user of
408 * a 64 bit program is a no-no.
409 */
410
411/*
412 * Same as peek_user but for a 31 bit program.
413 */
Martin Schwidefsky63506c42008-07-14 09:58:54 +0200414static u32 __peek_user_compat(struct task_struct *child, addr_t addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415{
416 struct user32 *dummy32 = NULL;
417 per_struct32 *dummy_per32 = NULL;
418 addr_t offset;
419 __u32 tmp;
420
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421 if (addr < (addr_t) &dummy32->regs.acrs) {
422 /*
423 * psw and gprs are stored on the stack
424 */
425 if (addr == (addr_t) &dummy32->regs.psw.mask) {
426 /* Fake a 31 bit psw mask. */
Al Viroc7584fb2006-01-12 01:05:49 -0800427 tmp = (__u32)(task_pt_regs(child)->psw.mask >> 32);
Gerald Schaeferc1821c22007-02-05 21:18:17 +0100428 tmp = PSW32_MASK_MERGE(psw32_user_bits, tmp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429 } else if (addr == (addr_t) &dummy32->regs.psw.addr) {
430 /* Fake a 31 bit psw address. */
Al Viroc7584fb2006-01-12 01:05:49 -0800431 tmp = (__u32) task_pt_regs(child)->psw.addr |
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432 PSW32_ADDR_AMODE31;
433 } else {
434 /* gpr 0-15 */
Al Viroc7584fb2006-01-12 01:05:49 -0800435 tmp = *(__u32 *)((addr_t) &task_pt_regs(child)->psw +
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436 addr*2 + 4);
437 }
438 } else if (addr < (addr_t) (&dummy32->regs.orig_gpr2)) {
439 /*
440 * access registers are stored in the thread structure
441 */
442 offset = addr - (addr_t) &dummy32->regs.acrs;
443 tmp = *(__u32*)((addr_t) &child->thread.acrs + offset);
444
445 } else if (addr == (addr_t) (&dummy32->regs.orig_gpr2)) {
446 /*
447 * orig_gpr2 is stored on the kernel stack
448 */
Al Viroc7584fb2006-01-12 01:05:49 -0800449 tmp = *(__u32*)((addr_t) &task_pt_regs(child)->orig_gpr2 + 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450
Jarod Wilson3d6e48f2008-09-09 12:38:56 +0200451 } else if (addr < (addr_t) &dummy32->regs.fp_regs) {
452 /*
453 * prevent reads of padding hole between
454 * orig_gpr2 and fp_regs on s390.
455 */
456 tmp = 0;
457
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458 } else if (addr < (addr_t) (&dummy32->regs.fp_regs + 1)) {
459 /*
460 * floating point regs. are stored in the thread structure
461 */
462 offset = addr - (addr_t) &dummy32->regs.fp_regs;
463 tmp = *(__u32 *)((addr_t) &child->thread.fp_regs + offset);
464
465 } else if (addr < (addr_t) (&dummy32->regs.per_info + 1)) {
466 /*
467 * per_info is found in the thread structure
468 */
469 offset = addr - (addr_t) &dummy32->regs.per_info;
470 /* This is magic. See per_struct and per_struct32. */
471 if ((offset >= (addr_t) &dummy_per32->control_regs &&
472 offset < (addr_t) (&dummy_per32->control_regs + 1)) ||
473 (offset >= (addr_t) &dummy_per32->starting_addr &&
474 offset <= (addr_t) &dummy_per32->ending_addr) ||
475 offset == (addr_t) &dummy_per32->lowcore.words.address)
476 offset = offset*2 + 4;
477 else
478 offset = offset*2;
479 tmp = *(__u32 *)((addr_t) &child->thread.per_info + offset);
480
481 } else
482 tmp = 0;
483
Martin Schwidefsky63506c42008-07-14 09:58:54 +0200484 return tmp;
485}
486
487static int peek_user_compat(struct task_struct *child,
488 addr_t addr, addr_t data)
489{
490 __u32 tmp;
491
Heiko Carstens77575912009-06-12 10:26:25 +0200492 if (!is_compat_task() || (addr & 3) || addr > sizeof(struct user) - 3)
Martin Schwidefsky63506c42008-07-14 09:58:54 +0200493 return -EIO;
494
495 tmp = __peek_user_compat(child, addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496 return put_user(tmp, (__u32 __user *) data);
497}
498
499/*
500 * Same as poke_user but for a 31 bit program.
501 */
Martin Schwidefsky63506c42008-07-14 09:58:54 +0200502static int __poke_user_compat(struct task_struct *child,
503 addr_t addr, addr_t data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504{
505 struct user32 *dummy32 = NULL;
506 per_struct32 *dummy_per32 = NULL;
Martin Schwidefsky63506c42008-07-14 09:58:54 +0200507 __u32 tmp = (__u32) data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700508 addr_t offset;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509
510 if (addr < (addr_t) &dummy32->regs.acrs) {
511 /*
512 * psw, gprs, acrs and orig_gpr2 are stored on the stack
513 */
514 if (addr == (addr_t) &dummy32->regs.psw.mask) {
515 /* Build a 64 bit psw mask from 31 bit mask. */
Gerald Schaeferc1821c22007-02-05 21:18:17 +0100516 if (tmp != PSW32_MASK_MERGE(psw32_user_bits, tmp))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517 /* Invalid psw mask. */
518 return -EINVAL;
Al Viroc7584fb2006-01-12 01:05:49 -0800519 task_pt_regs(child)->psw.mask =
Gerald Schaeferc1821c22007-02-05 21:18:17 +0100520 PSW_MASK_MERGE(psw_user32_bits, (__u64) tmp << 32);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521 } else if (addr == (addr_t) &dummy32->regs.psw.addr) {
522 /* Build a 64 bit psw address from 31 bit address. */
Al Viroc7584fb2006-01-12 01:05:49 -0800523 task_pt_regs(child)->psw.addr =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700524 (__u64) tmp & PSW32_ADDR_INSN;
525 } else {
526 /* gpr 0-15 */
Al Viroc7584fb2006-01-12 01:05:49 -0800527 *(__u32*)((addr_t) &task_pt_regs(child)->psw
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528 + addr*2 + 4) = tmp;
529 }
530 } else if (addr < (addr_t) (&dummy32->regs.orig_gpr2)) {
531 /*
532 * access registers are stored in the thread structure
533 */
534 offset = addr - (addr_t) &dummy32->regs.acrs;
535 *(__u32*)((addr_t) &child->thread.acrs + offset) = tmp;
536
537 } else if (addr == (addr_t) (&dummy32->regs.orig_gpr2)) {
538 /*
539 * orig_gpr2 is stored on the kernel stack
540 */
Al Viroc7584fb2006-01-12 01:05:49 -0800541 *(__u32*)((addr_t) &task_pt_regs(child)->orig_gpr2 + 4) = tmp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700542
Jarod Wilson3d6e48f2008-09-09 12:38:56 +0200543 } else if (addr < (addr_t) &dummy32->regs.fp_regs) {
544 /*
545 * prevent writess of padding hole between
546 * orig_gpr2 and fp_regs on s390.
547 */
548 return 0;
549
Linus Torvalds1da177e2005-04-16 15:20:36 -0700550 } else if (addr < (addr_t) (&dummy32->regs.fp_regs + 1)) {
551 /*
552 * floating point regs. are stored in the thread structure
553 */
554 if (addr == (addr_t) &dummy32->regs.fp_regs.fpc &&
555 (tmp & ~FPC_VALID_MASK) != 0)
556 /* Invalid floating point control. */
557 return -EINVAL;
558 offset = addr - (addr_t) &dummy32->regs.fp_regs;
559 *(__u32 *)((addr_t) &child->thread.fp_regs + offset) = tmp;
560
561 } else if (addr < (addr_t) (&dummy32->regs.per_info + 1)) {
562 /*
563 * per_info is found in the thread structure.
564 */
565 offset = addr - (addr_t) &dummy32->regs.per_info;
566 /*
567 * This is magic. See per_struct and per_struct32.
568 * By incident the offsets in per_struct are exactly
569 * twice the offsets in per_struct32 for all fields.
570 * The 8 byte fields need special handling though,
571 * because the second half (bytes 4-7) is needed and
572 * not the first half.
573 */
574 if ((offset >= (addr_t) &dummy_per32->control_regs &&
575 offset < (addr_t) (&dummy_per32->control_regs + 1)) ||
576 (offset >= (addr_t) &dummy_per32->starting_addr &&
577 offset <= (addr_t) &dummy_per32->ending_addr) ||
578 offset == (addr_t) &dummy_per32->lowcore.words.address)
579 offset = offset*2 + 4;
580 else
581 offset = offset*2;
582 *(__u32 *)((addr_t) &child->thread.per_info + offset) = tmp;
583
584 }
585
586 FixPerRegisters(child);
587 return 0;
588}
589
Martin Schwidefsky63506c42008-07-14 09:58:54 +0200590static int poke_user_compat(struct task_struct *child,
591 addr_t addr, addr_t data)
592{
Heiko Carstens77575912009-06-12 10:26:25 +0200593 if (!is_compat_task() || (addr & 3) || addr > sizeof(struct user32) - 3)
Martin Schwidefsky63506c42008-07-14 09:58:54 +0200594 return -EIO;
595
596 return __poke_user_compat(child, addr, data);
597}
598
Roland McGrathb499d762008-05-07 09:22:57 +0200599long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
600 compat_ulong_t caddr, compat_ulong_t cdata)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601{
Roland McGrathb499d762008-05-07 09:22:57 +0200602 unsigned long addr = caddr;
603 unsigned long data = cdata;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604 ptrace_area_emu31 parea;
605 int copied, ret;
606
607 switch (request) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700608 case PTRACE_PEEKUSR:
609 /* read the word at location addr in the USER area. */
Martin Schwidefsky63506c42008-07-14 09:58:54 +0200610 return peek_user_compat(child, addr, data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700611
Linus Torvalds1da177e2005-04-16 15:20:36 -0700612 case PTRACE_POKEUSR:
613 /* write the word at location addr in the USER area */
Martin Schwidefsky63506c42008-07-14 09:58:54 +0200614 return poke_user_compat(child, addr, data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700615
616 case PTRACE_PEEKUSR_AREA:
617 case PTRACE_POKEUSR_AREA:
Heiko Carstens2b67fc42007-02-05 21:16:47 +0100618 if (copy_from_user(&parea, (void __force __user *) addr,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619 sizeof(parea)))
620 return -EFAULT;
621 addr = parea.kernel_addr;
622 data = parea.process_addr;
623 copied = 0;
624 while (copied < parea.len) {
625 if (request == PTRACE_PEEKUSR_AREA)
Martin Schwidefsky63506c42008-07-14 09:58:54 +0200626 ret = peek_user_compat(child, addr, data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700627 else {
Heiko Carstens2b67fc42007-02-05 21:16:47 +0100628 __u32 utmp;
629 if (get_user(utmp,
630 (__u32 __force __user *) data))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700631 return -EFAULT;
Martin Schwidefsky63506c42008-07-14 09:58:54 +0200632 ret = poke_user_compat(child, addr, utmp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700633 }
634 if (ret)
635 return ret;
636 addr += sizeof(unsigned int);
637 data += sizeof(unsigned int);
638 copied += sizeof(unsigned int);
639 }
640 return 0;
Martin Schwidefsky86f25522010-05-17 10:00:05 +0200641 case PTRACE_GET_LAST_BREAK:
642 put_user(task_thread_info(child)->last_break,
643 (unsigned int __user *) data);
644 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645 }
Roland McGrathb499d762008-05-07 09:22:57 +0200646 return compat_ptrace_request(child, request, addr, data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700647}
648#endif
649
Martin Schwidefsky753c4dd2008-10-10 21:33:20 +0200650asmlinkage long do_syscall_trace_enter(struct pt_regs *regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700651{
Gerald Schaefer545c1742010-05-12 09:32:12 +0200652 long ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700653
Heiko Carstensbcf5cef2009-06-12 10:26:26 +0200654 /* Do the secure computing check first. */
655 secure_computing(regs->gprs[2]);
656
Linus Torvalds1da177e2005-04-16 15:20:36 -0700657 /*
Martin Schwidefsky753c4dd2008-10-10 21:33:20 +0200658 * The sysc_tracesys code in entry.S stored the system
659 * call number to gprs[2].
Bodo Stroesserc5c3a6d2005-06-04 15:43:32 -0700660 */
Martin Schwidefsky753c4dd2008-10-10 21:33:20 +0200661 if (test_thread_flag(TIF_SYSCALL_TRACE) &&
662 (tracehook_report_syscall_entry(regs) ||
663 regs->gprs[2] >= NR_syscalls)) {
664 /*
665 * Tracing decided this syscall should not happen or the
666 * debugger stored an invalid system call number. Skip
667 * the system call and the system call restart handling.
668 */
Martin Schwidefsky59da2132008-11-27 11:05:55 +0100669 regs->svcnr = 0;
Martin Schwidefsky753c4dd2008-10-10 21:33:20 +0200670 ret = -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700671 }
Martin Schwidefsky753c4dd2008-10-10 21:33:20 +0200672
Josh Stone66700002009-08-24 14:43:11 -0700673 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
Josh Stone1c569f02009-08-24 14:43:14 -0700674 trace_sys_enter(regs, regs->gprs[2]);
Heiko Carstens9bf12262009-06-12 10:26:47 +0200675
Martin Schwidefsky753c4dd2008-10-10 21:33:20 +0200676 if (unlikely(current->audit_context))
Heiko Carstens77575912009-06-12 10:26:25 +0200677 audit_syscall_entry(is_compat_task() ?
Martin Schwidefsky753c4dd2008-10-10 21:33:20 +0200678 AUDIT_ARCH_S390 : AUDIT_ARCH_S390X,
679 regs->gprs[2], regs->orig_gpr2,
680 regs->gprs[3], regs->gprs[4],
681 regs->gprs[5]);
Gerald Schaefer545c1742010-05-12 09:32:12 +0200682 return ret ?: regs->gprs[2];
Martin Schwidefsky753c4dd2008-10-10 21:33:20 +0200683}
684
685asmlinkage void do_syscall_trace_exit(struct pt_regs *regs)
686{
687 if (unlikely(current->audit_context))
688 audit_syscall_exit(AUDITSC_RESULT(regs->gprs[2]),
689 regs->gprs[2]);
690
Josh Stone66700002009-08-24 14:43:11 -0700691 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
Josh Stone1c569f02009-08-24 14:43:14 -0700692 trace_sys_exit(regs, regs->gprs[2]);
Heiko Carstens9bf12262009-06-12 10:26:47 +0200693
Martin Schwidefsky753c4dd2008-10-10 21:33:20 +0200694 if (test_thread_flag(TIF_SYSCALL_TRACE))
695 tracehook_report_syscall_exit(regs, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700696}
Martin Schwidefsky63506c42008-07-14 09:58:54 +0200697
698/*
699 * user_regset definitions.
700 */
701
702static int s390_regs_get(struct task_struct *target,
703 const struct user_regset *regset,
704 unsigned int pos, unsigned int count,
705 void *kbuf, void __user *ubuf)
706{
707 if (target == current)
708 save_access_regs(target->thread.acrs);
709
710 if (kbuf) {
711 unsigned long *k = kbuf;
712 while (count > 0) {
713 *k++ = __peek_user(target, pos);
714 count -= sizeof(*k);
715 pos += sizeof(*k);
716 }
717 } else {
718 unsigned long __user *u = ubuf;
719 while (count > 0) {
720 if (__put_user(__peek_user(target, pos), u++))
721 return -EFAULT;
722 count -= sizeof(*u);
723 pos += sizeof(*u);
724 }
725 }
726 return 0;
727}
728
729static int s390_regs_set(struct task_struct *target,
730 const struct user_regset *regset,
731 unsigned int pos, unsigned int count,
732 const void *kbuf, const void __user *ubuf)
733{
734 int rc = 0;
735
736 if (target == current)
737 save_access_regs(target->thread.acrs);
738
739 if (kbuf) {
740 const unsigned long *k = kbuf;
741 while (count > 0 && !rc) {
742 rc = __poke_user(target, pos, *k++);
743 count -= sizeof(*k);
744 pos += sizeof(*k);
745 }
746 } else {
747 const unsigned long __user *u = ubuf;
748 while (count > 0 && !rc) {
749 unsigned long word;
750 rc = __get_user(word, u++);
751 if (rc)
752 break;
753 rc = __poke_user(target, pos, word);
754 count -= sizeof(*u);
755 pos += sizeof(*u);
756 }
757 }
758
759 if (rc == 0 && target == current)
760 restore_access_regs(target->thread.acrs);
761
762 return rc;
763}
764
765static int s390_fpregs_get(struct task_struct *target,
766 const struct user_regset *regset, unsigned int pos,
767 unsigned int count, void *kbuf, void __user *ubuf)
768{
769 if (target == current)
770 save_fp_regs(&target->thread.fp_regs);
771
772 return user_regset_copyout(&pos, &count, &kbuf, &ubuf,
773 &target->thread.fp_regs, 0, -1);
774}
775
776static int s390_fpregs_set(struct task_struct *target,
777 const struct user_regset *regset, unsigned int pos,
778 unsigned int count, const void *kbuf,
779 const void __user *ubuf)
780{
781 int rc = 0;
782
783 if (target == current)
784 save_fp_regs(&target->thread.fp_regs);
785
786 /* If setting FPC, must validate it first. */
787 if (count > 0 && pos < offsetof(s390_fp_regs, fprs)) {
788 u32 fpc[2] = { target->thread.fp_regs.fpc, 0 };
789 rc = user_regset_copyin(&pos, &count, &kbuf, &ubuf, &fpc,
790 0, offsetof(s390_fp_regs, fprs));
791 if (rc)
792 return rc;
793 if ((fpc[0] & ~FPC_VALID_MASK) != 0 || fpc[1] != 0)
794 return -EINVAL;
795 target->thread.fp_regs.fpc = fpc[0];
796 }
797
798 if (rc == 0 && count > 0)
799 rc = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
800 target->thread.fp_regs.fprs,
801 offsetof(s390_fp_regs, fprs), -1);
802
803 if (rc == 0 && target == current)
804 restore_fp_regs(&target->thread.fp_regs);
805
806 return rc;
807}
808
Martin Schwidefsky86f25522010-05-17 10:00:05 +0200809#ifdef CONFIG_64BIT
810
811static int s390_last_break_get(struct task_struct *target,
812 const struct user_regset *regset,
813 unsigned int pos, unsigned int count,
814 void *kbuf, void __user *ubuf)
815{
816 if (count > 0) {
817 if (kbuf) {
818 unsigned long *k = kbuf;
819 *k = task_thread_info(target)->last_break;
820 } else {
821 unsigned long __user *u = ubuf;
822 if (__put_user(task_thread_info(target)->last_break, u))
823 return -EFAULT;
824 }
825 }
826 return 0;
827}
828
829#endif
830
Martin Schwidefsky63506c42008-07-14 09:58:54 +0200831static const struct user_regset s390_regsets[] = {
832 [REGSET_GENERAL] = {
833 .core_note_type = NT_PRSTATUS,
834 .n = sizeof(s390_regs) / sizeof(long),
835 .size = sizeof(long),
836 .align = sizeof(long),
837 .get = s390_regs_get,
838 .set = s390_regs_set,
839 },
840 [REGSET_FP] = {
841 .core_note_type = NT_PRFPREG,
842 .n = sizeof(s390_fp_regs) / sizeof(long),
843 .size = sizeof(long),
844 .align = sizeof(long),
845 .get = s390_fpregs_get,
846 .set = s390_fpregs_set,
847 },
Martin Schwidefsky86f25522010-05-17 10:00:05 +0200848#ifdef CONFIG_64BIT
849 [REGSET_LAST_BREAK] = {
850 .core_note_type = NT_S390_LAST_BREAK,
851 .n = 1,
852 .size = sizeof(long),
853 .align = sizeof(long),
854 .get = s390_last_break_get,
855 },
856#endif
Martin Schwidefsky63506c42008-07-14 09:58:54 +0200857};
858
859static const struct user_regset_view user_s390_view = {
860 .name = UTS_MACHINE,
861 .e_machine = EM_S390,
862 .regsets = s390_regsets,
863 .n = ARRAY_SIZE(s390_regsets)
864};
865
866#ifdef CONFIG_COMPAT
867static 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
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
894static int s390_compat_regs_set(struct task_struct *target,
895 const struct user_regset *regset,
896 unsigned int pos, unsigned int count,
897 const void *kbuf, const void __user *ubuf)
898{
899 int rc = 0;
900
901 if (target == current)
902 save_access_regs(target->thread.acrs);
903
904 if (kbuf) {
905 const compat_ulong_t *k = kbuf;
906 while (count > 0 && !rc) {
907 rc = __poke_user_compat(target, pos, *k++);
908 count -= sizeof(*k);
909 pos += sizeof(*k);
910 }
911 } else {
912 const compat_ulong_t __user *u = ubuf;
913 while (count > 0 && !rc) {
914 compat_ulong_t word;
915 rc = __get_user(word, u++);
916 if (rc)
917 break;
918 rc = __poke_user_compat(target, pos, word);
919 count -= sizeof(*u);
920 pos += sizeof(*u);
921 }
922 }
923
924 if (rc == 0 && target == current)
925 restore_access_regs(target->thread.acrs);
926
927 return rc;
928}
929
Heiko Carstensea2a4d32009-10-06 10:34:13 +0200930static int s390_compat_regs_high_get(struct task_struct *target,
931 const struct user_regset *regset,
932 unsigned int pos, unsigned int count,
933 void *kbuf, void __user *ubuf)
934{
935 compat_ulong_t *gprs_high;
936
937 gprs_high = (compat_ulong_t *)
938 &task_pt_regs(target)->gprs[pos / sizeof(compat_ulong_t)];
939 if (kbuf) {
940 compat_ulong_t *k = kbuf;
941 while (count > 0) {
942 *k++ = *gprs_high;
943 gprs_high += 2;
944 count -= sizeof(*k);
945 }
946 } else {
947 compat_ulong_t __user *u = ubuf;
948 while (count > 0) {
949 if (__put_user(*gprs_high, u++))
950 return -EFAULT;
951 gprs_high += 2;
952 count -= sizeof(*u);
953 }
954 }
955 return 0;
956}
957
958static int s390_compat_regs_high_set(struct task_struct *target,
959 const struct user_regset *regset,
960 unsigned int pos, unsigned int count,
961 const void *kbuf, const void __user *ubuf)
962{
963 compat_ulong_t *gprs_high;
964 int rc = 0;
965
966 gprs_high = (compat_ulong_t *)
967 &task_pt_regs(target)->gprs[pos / sizeof(compat_ulong_t)];
968 if (kbuf) {
969 const compat_ulong_t *k = kbuf;
970 while (count > 0) {
971 *gprs_high = *k++;
972 *gprs_high += 2;
973 count -= sizeof(*k);
974 }
975 } else {
976 const compat_ulong_t __user *u = ubuf;
977 while (count > 0 && !rc) {
978 unsigned long word;
979 rc = __get_user(word, u++);
980 if (rc)
981 break;
982 *gprs_high = word;
983 *gprs_high += 2;
984 count -= sizeof(*u);
985 }
986 }
987
988 return rc;
989}
990
Martin Schwidefsky86f25522010-05-17 10:00:05 +0200991static int s390_compat_last_break_get(struct task_struct *target,
992 const struct user_regset *regset,
993 unsigned int pos, unsigned int count,
994 void *kbuf, void __user *ubuf)
995{
996 compat_ulong_t last_break;
997
998 if (count > 0) {
999 last_break = task_thread_info(target)->last_break;
1000 if (kbuf) {
1001 unsigned long *k = kbuf;
1002 *k = last_break;
1003 } else {
1004 unsigned long __user *u = ubuf;
1005 if (__put_user(last_break, u))
1006 return -EFAULT;
1007 }
1008 }
1009 return 0;
1010}
1011
Martin Schwidefsky63506c42008-07-14 09:58:54 +02001012static const struct user_regset s390_compat_regsets[] = {
1013 [REGSET_GENERAL] = {
1014 .core_note_type = NT_PRSTATUS,
1015 .n = sizeof(s390_compat_regs) / sizeof(compat_long_t),
1016 .size = sizeof(compat_long_t),
1017 .align = sizeof(compat_long_t),
1018 .get = s390_compat_regs_get,
1019 .set = s390_compat_regs_set,
1020 },
1021 [REGSET_FP] = {
1022 .core_note_type = NT_PRFPREG,
1023 .n = sizeof(s390_fp_regs) / sizeof(compat_long_t),
1024 .size = sizeof(compat_long_t),
1025 .align = sizeof(compat_long_t),
1026 .get = s390_fpregs_get,
1027 .set = s390_fpregs_set,
1028 },
Martin Schwidefsky86f25522010-05-17 10:00:05 +02001029 [REGSET_LAST_BREAK] = {
1030 .core_note_type = NT_S390_LAST_BREAK,
1031 .n = 1,
1032 .size = sizeof(long),
1033 .align = sizeof(long),
1034 .get = s390_compat_last_break_get,
1035 },
Heiko Carstensea2a4d32009-10-06 10:34:13 +02001036 [REGSET_GENERAL_EXTENDED] = {
Martin Schwidefsky622e99b2009-12-18 17:43:20 +01001037 .core_note_type = NT_S390_HIGH_GPRS,
Heiko Carstensea2a4d32009-10-06 10:34:13 +02001038 .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 },
Martin Schwidefsky63506c42008-07-14 09:58:54 +02001044};
1045
1046static const struct user_regset_view user_s390_compat_view = {
1047 .name = "s390",
1048 .e_machine = EM_S390,
1049 .regsets = s390_compat_regsets,
1050 .n = ARRAY_SIZE(s390_compat_regsets)
1051};
1052#endif
1053
1054const 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}
Heiko Carstens952974ac62010-02-12 13:38:40 +01001062
1063static const char *gpr_names[NUM_GPRS] = {
1064 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
1065 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
1066};
1067
1068unsigned long regs_get_register(struct pt_regs *regs, unsigned int offset)
1069{
1070 if (offset >= NUM_GPRS)
1071 return 0;
1072 return regs->gprs[offset];
1073}
1074
1075int regs_query_register_offset(const char *name)
1076{
1077 unsigned long offset;
1078
1079 if (!name || *name != 'r')
1080 return -EINVAL;
1081 if (strict_strtoul(name + 1, 10, &offset))
1082 return -EINVAL;
1083 if (offset >= NUM_GPRS)
1084 return -EINVAL;
1085 return offset;
1086}
1087
1088const char *regs_query_register_name(unsigned int offset)
1089{
1090 if (offset >= NUM_GPRS)
1091 return NULL;
1092 return gpr_names[offset];
1093}
1094
1095static int regs_within_kernel_stack(struct pt_regs *regs, unsigned long addr)
1096{
1097 unsigned long ksp = kernel_stack_pointer(regs);
1098
1099 return (addr & ~(THREAD_SIZE - 1)) == (ksp & ~(THREAD_SIZE - 1));
1100}
1101
1102/**
1103 * regs_get_kernel_stack_nth() - get Nth entry of the stack
1104 * @regs:pt_regs which contains kernel stack pointer.
1105 * @n:stack entry number.
1106 *
1107 * regs_get_kernel_stack_nth() returns @n th entry of the kernel stack which
1108 * is specifined by @regs. If the @n th entry is NOT in the kernel stack,
1109 * this returns 0.
1110 */
1111unsigned long regs_get_kernel_stack_nth(struct pt_regs *regs, unsigned int n)
1112{
1113 unsigned long addr;
1114
1115 addr = kernel_stack_pointer(regs) + n * sizeof(long);
1116 if (!regs_within_kernel_stack(regs, addr))
1117 return 0;
1118 return *(unsigned long *)addr;
1119}