blob: 3c0c19830c37f5a0f7896d0a292762b794b30a74 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Heiko Carstens54dfe5d2006-02-01 03:06:38 -08002 * arch/s390/kernel/compat_signal.c
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 *
Heiko Carstens54dfe5d2006-02-01 03:06:38 -08004 * Copyright (C) IBM Corp. 2000,2006
Linus Torvalds1da177e2005-04-16 15:20:36 -07005 * Author(s): Denis Joseph Barrow (djbarrow@de.ibm.com,barrow_dj@yahoo.com)
6 * Gerhard Tonn (ton@de.ibm.com)
7 *
8 * Copyright (C) 1991, 1992 Linus Torvalds
9 *
10 * 1997-11-28 Modified for POSIX.1b signals by Richard Henderson
11 */
12
Linus Torvalds1da177e2005-04-16 15:20:36 -070013#include <linux/compat.h>
14#include <linux/sched.h>
15#include <linux/mm.h>
16#include <linux/smp.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070017#include <linux/kernel.h>
18#include <linux/signal.h>
19#include <linux/errno.h>
20#include <linux/wait.h>
21#include <linux/ptrace.h>
22#include <linux/unistd.h>
23#include <linux/stddef.h>
24#include <linux/tty.h>
25#include <linux/personality.h>
26#include <linux/binfmts.h>
27#include <asm/ucontext.h>
28#include <asm/uaccess.h>
29#include <asm/lowcore.h>
David Howellsa0616cd2012-03-28 18:30:02 +010030#include <asm/switch_to.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070031#include "compat_linux.h"
32#include "compat_ptrace.h"
Heiko Carstensa8061702008-04-17 07:46:26 +020033#include "entry.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070034
Linus Torvalds1da177e2005-04-16 15:20:36 -070035typedef struct
36{
37 __u8 callee_used_stack[__SIGNAL_FRAMESIZE32];
38 struct sigcontext32 sc;
39 _sigregs32 sregs;
40 int signo;
Heiko Carstensea2a4d32009-10-06 10:34:13 +020041 __u32 gprs_high[NUM_GPRS];
Linus Torvalds1da177e2005-04-16 15:20:36 -070042 __u8 retcode[S390_SYSCALL_SIZE];
43} sigframe32;
44
45typedef struct
46{
47 __u8 callee_used_stack[__SIGNAL_FRAMESIZE32];
48 __u8 retcode[S390_SYSCALL_SIZE];
49 compat_siginfo_t info;
50 struct ucontext32 uc;
Heiko Carstensea2a4d32009-10-06 10:34:13 +020051 __u32 gprs_high[NUM_GPRS];
Linus Torvalds1da177e2005-04-16 15:20:36 -070052} rt_sigframe32;
53
Linus Torvalds1da177e2005-04-16 15:20:36 -070054int copy_siginfo_to_user32(compat_siginfo_t __user *to, siginfo_t *from)
55{
56 int err;
57
58 if (!access_ok (VERIFY_WRITE, to, sizeof(compat_siginfo_t)))
59 return -EFAULT;
60
61 /* If you change siginfo_t structure, please be sure
62 this code is fixed accordingly.
63 It should never copy any pad contained in the structure
64 to avoid security leaks, but must copy the generic
65 3 ints plus the relevant union member.
66 This routine must convert siginfo from 64bit to 32bit as well
67 at the same time. */
68 err = __put_user(from->si_signo, &to->si_signo);
69 err |= __put_user(from->si_errno, &to->si_errno);
70 err |= __put_user((short)from->si_code, &to->si_code);
71 if (from->si_code < 0)
72 err |= __copy_to_user(&to->_sifields._pad, &from->_sifields._pad, SI_PAD_SIZE);
73 else {
74 switch (from->si_code >> 16) {
75 case __SI_RT >> 16: /* This is not generated by the kernel as of now. */
76 case __SI_MESGQ >> 16:
77 err |= __put_user(from->si_int, &to->si_int);
78 /* fallthrough */
79 case __SI_KILL >> 16:
80 err |= __put_user(from->si_pid, &to->si_pid);
81 err |= __put_user(from->si_uid, &to->si_uid);
82 break;
83 case __SI_CHLD >> 16:
84 err |= __put_user(from->si_pid, &to->si_pid);
85 err |= __put_user(from->si_uid, &to->si_uid);
86 err |= __put_user(from->si_utime, &to->si_utime);
87 err |= __put_user(from->si_stime, &to->si_stime);
88 err |= __put_user(from->si_status, &to->si_status);
89 break;
90 case __SI_FAULT >> 16:
91 err |= __put_user((unsigned long) from->si_addr,
92 &to->si_addr);
93 break;
94 case __SI_POLL >> 16:
95 err |= __put_user(from->si_band, &to->si_band);
96 err |= __put_user(from->si_fd, &to->si_fd);
97 break;
98 case __SI_TIMER >> 16:
99 err |= __put_user(from->si_tid, &to->si_tid);
100 err |= __put_user(from->si_overrun, &to->si_overrun);
101 err |= __put_user(from->si_int, &to->si_int);
102 break;
103 default:
104 break;
105 }
106 }
107 return err;
108}
109
110int copy_siginfo_from_user32(siginfo_t *to, compat_siginfo_t __user *from)
111{
112 int err;
113 u32 tmp;
114
115 if (!access_ok (VERIFY_READ, from, sizeof(compat_siginfo_t)))
116 return -EFAULT;
117
118 err = __get_user(to->si_signo, &from->si_signo);
119 err |= __get_user(to->si_errno, &from->si_errno);
120 err |= __get_user(to->si_code, &from->si_code);
121
122 if (to->si_code < 0)
123 err |= __copy_from_user(&to->_sifields._pad, &from->_sifields._pad, SI_PAD_SIZE);
124 else {
125 switch (to->si_code >> 16) {
126 case __SI_RT >> 16: /* This is not generated by the kernel as of now. */
127 case __SI_MESGQ >> 16:
128 err |= __get_user(to->si_int, &from->si_int);
129 /* fallthrough */
130 case __SI_KILL >> 16:
131 err |= __get_user(to->si_pid, &from->si_pid);
132 err |= __get_user(to->si_uid, &from->si_uid);
133 break;
134 case __SI_CHLD >> 16:
135 err |= __get_user(to->si_pid, &from->si_pid);
136 err |= __get_user(to->si_uid, &from->si_uid);
137 err |= __get_user(to->si_utime, &from->si_utime);
138 err |= __get_user(to->si_stime, &from->si_stime);
139 err |= __get_user(to->si_status, &from->si_status);
140 break;
141 case __SI_FAULT >> 16:
142 err |= __get_user(tmp, &from->si_addr);
Martin Schwidefsky3c52e492011-10-30 15:17:15 +0100143 to->si_addr = (void __force __user *)
144 (u64) (tmp & PSW32_ADDR_INSN);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145 break;
146 case __SI_POLL >> 16:
147 err |= __get_user(to->si_band, &from->si_band);
148 err |= __get_user(to->si_fd, &from->si_fd);
149 break;
150 case __SI_TIMER >> 16:
151 err |= __get_user(to->si_tid, &from->si_tid);
152 err |= __get_user(to->si_overrun, &from->si_overrun);
153 err |= __get_user(to->si_int, &from->si_int);
154 break;
155 default:
156 break;
157 }
158 }
159 return err;
160}
161
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162asmlinkage long
163sys32_sigaction(int sig, const struct old_sigaction32 __user *act,
164 struct old_sigaction32 __user *oact)
165{
166 struct k_sigaction new_ka, old_ka;
167 unsigned long sa_handler, sa_restorer;
168 int ret;
169
170 if (act) {
171 compat_old_sigset_t mask;
172 if (!access_ok(VERIFY_READ, act, sizeof(*act)) ||
173 __get_user(sa_handler, &act->sa_handler) ||
Heiko Carstens12bae232006-10-27 12:39:22 +0200174 __get_user(sa_restorer, &act->sa_restorer) ||
175 __get_user(new_ka.sa.sa_flags, &act->sa_flags) ||
176 __get_user(mask, &act->sa_mask))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177 return -EFAULT;
178 new_ka.sa.sa_handler = (__sighandler_t) sa_handler;
179 new_ka.sa.sa_restorer = (void (*)(void)) sa_restorer;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180 siginitset(&new_ka.sa.sa_mask, mask);
181 }
182
183 ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL);
184
185 if (!ret && oact) {
186 sa_handler = (unsigned long) old_ka.sa.sa_handler;
187 sa_restorer = (unsigned long) old_ka.sa.sa_restorer;
188 if (!access_ok(VERIFY_WRITE, oact, sizeof(*oact)) ||
189 __put_user(sa_handler, &oact->sa_handler) ||
Heiko Carstens12bae232006-10-27 12:39:22 +0200190 __put_user(sa_restorer, &oact->sa_restorer) ||
191 __put_user(old_ka.sa.sa_flags, &oact->sa_flags) ||
192 __put_user(old_ka.sa.sa_mask.sig[0], &oact->sa_mask))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194 }
195
196 return ret;
197}
198
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199asmlinkage long
200sys32_rt_sigaction(int sig, const struct sigaction32 __user *act,
201 struct sigaction32 __user *oact, size_t sigsetsize)
202{
203 struct k_sigaction new_ka, old_ka;
204 unsigned long sa_handler;
205 int ret;
206 compat_sigset_t set32;
207
208 /* XXX: Don't preclude handling different sized sigset_t's. */
209 if (sigsetsize != sizeof(compat_sigset_t))
210 return -EINVAL;
211
212 if (act) {
213 ret = get_user(sa_handler, &act->sa_handler);
214 ret |= __copy_from_user(&set32, &act->sa_mask,
215 sizeof(compat_sigset_t));
Martin Schwidefsky399c1d82011-10-30 15:17:10 +0100216 new_ka.sa.sa_mask.sig[0] =
217 set32.sig[0] | (((long)set32.sig[1]) << 32);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218 ret |= __get_user(new_ka.sa.sa_flags, &act->sa_flags);
219
220 if (ret)
221 return -EFAULT;
222 new_ka.sa.sa_handler = (__sighandler_t) sa_handler;
223 }
224
225 ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL);
226
227 if (!ret && oact) {
Martin Schwidefsky399c1d82011-10-30 15:17:10 +0100228 set32.sig[1] = (old_ka.sa.sa_mask.sig[0] >> 32);
229 set32.sig[0] = old_ka.sa.sa_mask.sig[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230 ret = put_user((unsigned long)old_ka.sa.sa_handler, &oact->sa_handler);
231 ret |= __copy_to_user(&oact->sa_mask, &set32,
232 sizeof(compat_sigset_t));
233 ret |= __put_user(old_ka.sa.sa_flags, &oact->sa_flags);
234 }
235
236 return ret;
237}
238
239asmlinkage long
Martin Schwidefsky03ff9a22007-04-27 16:01:40 +0200240sys32_sigaltstack(const stack_t32 __user *uss, stack_t32 __user *uoss)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241{
Martin Schwidefsky03ff9a22007-04-27 16:01:40 +0200242 struct pt_regs *regs = task_pt_regs(current);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243 stack_t kss, koss;
244 unsigned long ss_sp;
245 int ret, err = 0;
246 mm_segment_t old_fs = get_fs();
247
248 if (uss) {
249 if (!access_ok(VERIFY_READ, uss, sizeof(*uss)))
250 return -EFAULT;
251 err |= __get_user(ss_sp, &uss->ss_sp);
252 err |= __get_user(kss.ss_size, &uss->ss_size);
253 err |= __get_user(kss.ss_flags, &uss->ss_flags);
254 if (err)
255 return -EFAULT;
Al Viroc2814472005-09-29 00:16:02 +0100256 kss.ss_sp = (void __user *) ss_sp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257 }
258
259 set_fs (KERNEL_DS);
Heiko Carstens2b67fc42007-02-05 21:16:47 +0100260 ret = do_sigaltstack((stack_t __force __user *) (uss ? &kss : NULL),
261 (stack_t __force __user *) (uoss ? &koss : NULL),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262 regs->gprs[15]);
263 set_fs (old_fs);
264
265 if (!ret && uoss) {
266 if (!access_ok(VERIFY_WRITE, uoss, sizeof(*uoss)))
267 return -EFAULT;
268 ss_sp = (unsigned long) koss.ss_sp;
269 err |= __put_user(ss_sp, &uoss->ss_sp);
270 err |= __put_user(koss.ss_size, &uoss->ss_size);
271 err |= __put_user(koss.ss_flags, &uoss->ss_flags);
272 if (err)
273 return -EFAULT;
274 }
275 return ret;
276}
277
278static int save_sigregs32(struct pt_regs *regs, _sigregs32 __user *sregs)
279{
280 _s390_regs_common32 regs32;
281 int err, i;
282
Martin Schwidefskyb50511e2011-10-30 15:16:50 +0100283 regs32.psw.mask = psw32_user_bits |
284 ((__u32)(regs->psw.mask >> 32) & PSW32_MASK_USER);
Martin Schwidefskyd4e81b32011-10-30 15:16:51 +0100285 regs32.psw.addr = (__u32) regs->psw.addr |
286 (__u32)(regs->psw.mask & PSW_MASK_BA);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287 for (i = 0; i < NUM_GPRS; i++)
288 regs32.gprs[i] = (__u32) regs->gprs[i];
289 save_access_regs(current->thread.acrs);
290 memcpy(regs32.acrs, current->thread.acrs, sizeof(regs32.acrs));
291 err = __copy_to_user(&sregs->regs, &regs32, sizeof(regs32));
292 if (err)
293 return err;
294 save_fp_regs(&current->thread.fp_regs);
295 /* s390_fp_regs and _s390_fp_regs32 are the same ! */
296 return __copy_to_user(&sregs->fpregs, &current->thread.fp_regs,
297 sizeof(_s390_fp_regs32));
298}
299
300static int restore_sigregs32(struct pt_regs *regs,_sigregs32 __user *sregs)
301{
302 _s390_regs_common32 regs32;
303 int err, i;
304
305 /* Alwys make any pending restarted system call return -EINTR */
306 current_thread_info()->restart_block.fn = do_no_restart_syscall;
307
308 err = __copy_from_user(&regs32, &sregs->regs, sizeof(regs32));
309 if (err)
310 return err;
Martin Schwidefskyb50511e2011-10-30 15:16:50 +0100311 regs->psw.mask = (regs->psw.mask & ~PSW_MASK_USER) |
Martin Schwidefskyd4e81b32011-10-30 15:16:51 +0100312 (__u64)(regs32.psw.mask & PSW32_MASK_USER) << 32 |
313 (__u64)(regs32.psw.addr & PSW32_ADDR_AMODE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314 regs->psw.addr = (__u64)(regs32.psw.addr & PSW32_ADDR_INSN);
315 for (i = 0; i < NUM_GPRS; i++)
316 regs->gprs[i] = (__u64) regs32.gprs[i];
317 memcpy(current->thread.acrs, regs32.acrs, sizeof(current->thread.acrs));
318 restore_access_regs(current->thread.acrs);
319
320 err = __copy_from_user(&current->thread.fp_regs, &sregs->fpregs,
321 sizeof(_s390_fp_regs32));
322 current->thread.fp_regs.fpc &= FPC_VALID_MASK;
323 if (err)
324 return err;
325
326 restore_fp_regs(&current->thread.fp_regs);
Martin Schwidefskyb6ef5bb2011-10-30 15:16:49 +0100327 clear_thread_flag(TIF_SYSCALL); /* No longer in a system call */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328 return 0;
329}
330
Heiko Carstensea2a4d32009-10-06 10:34:13 +0200331static int save_sigregs_gprs_high(struct pt_regs *regs, __u32 __user *uregs)
332{
333 __u32 gprs_high[NUM_GPRS];
334 int i;
335
336 for (i = 0; i < NUM_GPRS; i++)
337 gprs_high[i] = regs->gprs[i] >> 32;
338
339 return __copy_to_user(uregs, &gprs_high, sizeof(gprs_high));
340}
341
342static int restore_sigregs_gprs_high(struct pt_regs *regs, __u32 __user *uregs)
343{
344 __u32 gprs_high[NUM_GPRS];
345 int err, i;
346
347 err = __copy_from_user(&gprs_high, uregs, sizeof(gprs_high));
348 if (err)
349 return err;
350 for (i = 0; i < NUM_GPRS; i++)
351 *(__u32 *)&regs->gprs[i] = gprs_high[i];
352 return 0;
353}
354
Martin Schwidefsky03ff9a22007-04-27 16:01:40 +0200355asmlinkage long sys32_sigreturn(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356{
Martin Schwidefsky03ff9a22007-04-27 16:01:40 +0200357 struct pt_regs *regs = task_pt_regs(current);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700358 sigframe32 __user *frame = (sigframe32 __user *)regs->gprs[15];
359 sigset_t set;
360
361 if (!access_ok(VERIFY_READ, frame, sizeof(*frame)))
362 goto badframe;
363 if (__copy_from_user(&set.sig, &frame->sc.oldmask, _SIGMASK_COPY_SIZE32))
364 goto badframe;
Heiko Carstens391c62f2011-08-03 16:44:26 +0200365 set_current_blocked(&set);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366 if (restore_sigregs32(regs, &frame->sregs))
367 goto badframe;
Heiko Carstensea2a4d32009-10-06 10:34:13 +0200368 if (restore_sigregs_gprs_high(regs, frame->gprs_high))
369 goto badframe;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370 return regs->gprs[2];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371badframe:
372 force_sig(SIGSEGV, current);
373 return 0;
374}
375
Martin Schwidefsky03ff9a22007-04-27 16:01:40 +0200376asmlinkage long sys32_rt_sigreturn(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377{
Martin Schwidefsky03ff9a22007-04-27 16:01:40 +0200378 struct pt_regs *regs = task_pt_regs(current);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379 rt_sigframe32 __user *frame = (rt_sigframe32 __user *)regs->gprs[15];
380 sigset_t set;
381 stack_t st;
382 __u32 ss_sp;
383 int err;
384 mm_segment_t old_fs = get_fs();
385
386 if (!access_ok(VERIFY_READ, frame, sizeof(*frame)))
387 goto badframe;
388 if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set)))
389 goto badframe;
Heiko Carstens391c62f2011-08-03 16:44:26 +0200390 set_current_blocked(&set);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391 if (restore_sigregs32(regs, &frame->uc.uc_mcontext))
392 goto badframe;
Heiko Carstensea2a4d32009-10-06 10:34:13 +0200393 if (restore_sigregs_gprs_high(regs, frame->gprs_high))
394 goto badframe;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395 err = __get_user(ss_sp, &frame->uc.uc_stack.ss_sp);
Al Viroc2814472005-09-29 00:16:02 +0100396 st.ss_sp = compat_ptr(ss_sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397 err |= __get_user(st.ss_size, &frame->uc.uc_stack.ss_size);
398 err |= __get_user(st.ss_flags, &frame->uc.uc_stack.ss_flags);
399 if (err)
400 goto badframe;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401 set_fs (KERNEL_DS);
Heiko Carstens2b67fc42007-02-05 21:16:47 +0100402 do_sigaltstack((stack_t __force __user *)&st, NULL, regs->gprs[15]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403 set_fs (old_fs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404 return regs->gprs[2];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405badframe:
Martin Schwidefsky03ff9a22007-04-27 16:01:40 +0200406 force_sig(SIGSEGV, current);
407 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408}
409
410/*
411 * Set up a signal frame.
412 */
413
414
415/*
416 * Determine which stack to use..
417 */
418static inline void __user *
419get_sigframe(struct k_sigaction *ka, struct pt_regs * regs, size_t frame_size)
420{
421 unsigned long sp;
422
423 /* Default to using normal stack */
424 sp = (unsigned long) A(regs->gprs[15]);
425
Heiko Carstensde553432008-04-17 07:45:57 +0200426 /* Overflow on alternate signal stack gives SIGSEGV. */
427 if (on_sig_stack(sp) && !on_sig_stack((sp - frame_size) & -8UL))
428 return (void __user *) -1UL;
429
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430 /* This is the X/Open sanctioned signal stack switching. */
431 if (ka->sa.sa_flags & SA_ONSTACK) {
Laurent Meyer28f22372006-04-27 18:40:07 -0700432 if (! sas_ss_flags(sp))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433 sp = current->sas_ss_sp + current->sas_ss_size;
434 }
435
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436 return (void __user *)((sp - frame_size) & -8ul);
437}
438
439static inline int map_signal(int sig)
440{
441 if (current_thread_info()->exec_domain
442 && current_thread_info()->exec_domain->signal_invmap
443 && sig < 32)
444 return current_thread_info()->exec_domain->signal_invmap[sig];
445 else
446 return sig;
447}
448
Heiko Carstens54dfe5d2006-02-01 03:06:38 -0800449static int setup_frame32(int sig, struct k_sigaction *ka,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450 sigset_t *set, struct pt_regs * regs)
451{
452 sigframe32 __user *frame = get_sigframe(ka, regs, sizeof(sigframe32));
453 if (!access_ok(VERIFY_WRITE, frame, sizeof(sigframe32)))
454 goto give_sigsegv;
455
Heiko Carstensde553432008-04-17 07:45:57 +0200456 if (frame == (void __user *) -1UL)
457 goto give_sigsegv;
458
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459 if (__copy_to_user(&frame->sc.oldmask, &set->sig, _SIGMASK_COPY_SIZE32))
460 goto give_sigsegv;
461
462 if (save_sigregs32(regs, &frame->sregs))
463 goto give_sigsegv;
Heiko Carstensea2a4d32009-10-06 10:34:13 +0200464 if (save_sigregs_gprs_high(regs, frame->gprs_high))
465 goto give_sigsegv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466 if (__put_user((unsigned long) &frame->sregs, &frame->sc.sregs))
467 goto give_sigsegv;
468
469 /* Set up to return from userspace. If provided, use a stub
470 already in userspace. */
471 if (ka->sa.sa_flags & SA_RESTORER) {
Martin Schwidefskyd4e81b32011-10-30 15:16:51 +0100472 regs->gprs[14] = (__u64) ka->sa.sa_restorer | PSW32_ADDR_AMODE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473 } else {
Martin Schwidefskyd4e81b32011-10-30 15:16:51 +0100474 regs->gprs[14] = (__u64) frame->retcode | PSW32_ADDR_AMODE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700475 if (__put_user(S390_SYSCALL_OPCODE | __NR_sigreturn,
Martin Schwidefsky3c52e492011-10-30 15:17:15 +0100476 (u16 __force __user *)(frame->retcode)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477 goto give_sigsegv;
478 }
479
480 /* Set up backchain. */
481 if (__put_user(regs->gprs[15], (unsigned int __user *) frame))
482 goto give_sigsegv;
483
484 /* Set up registers for signal handler */
Martin Schwidefsky3c52e492011-10-30 15:17:15 +0100485 regs->gprs[15] = (__force __u64) frame;
Martin Schwidefskyd4e81b32011-10-30 15:16:51 +0100486 regs->psw.mask |= PSW_MASK_BA; /* force amode 31 */
Martin Schwidefsky3c52e492011-10-30 15:17:15 +0100487 regs->psw.addr = (__force __u64) ka->sa.sa_handler;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488
489 regs->gprs[2] = map_signal(sig);
Martin Schwidefsky3c52e492011-10-30 15:17:15 +0100490 regs->gprs[3] = (__force __u64) &frame->sc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491
492 /* We forgot to include these in the sigcontext.
493 To avoid breaking binary compatibility, they are passed as args. */
Martin Schwidefskyaa33c8c2011-12-27 11:27:18 +0100494 if (sig == SIGSEGV || sig == SIGBUS || sig == SIGILL ||
495 sig == SIGTRAP || sig == SIGFPE) {
496 /* set extra registers only for synchronous signals */
497 regs->gprs[4] = regs->int_code & 127;
498 regs->gprs[5] = regs->int_parm_long;
499 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500
501 /* Place signal number on stack to allow backtrace from handler. */
Martin Schwidefsky3c52e492011-10-30 15:17:15 +0100502 if (__put_user(regs->gprs[2], (int __force __user *) &frame->signo))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503 goto give_sigsegv;
Heiko Carstens54dfe5d2006-02-01 03:06:38 -0800504 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505
506give_sigsegv:
507 force_sigsegv(sig, current);
Heiko Carstens54dfe5d2006-02-01 03:06:38 -0800508 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509}
510
Heiko Carstens54dfe5d2006-02-01 03:06:38 -0800511static int setup_rt_frame32(int sig, struct k_sigaction *ka, siginfo_t *info,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700512 sigset_t *set, struct pt_regs * regs)
513{
514 int err = 0;
515 rt_sigframe32 __user *frame = get_sigframe(ka, regs, sizeof(rt_sigframe32));
516 if (!access_ok(VERIFY_WRITE, frame, sizeof(rt_sigframe32)))
517 goto give_sigsegv;
518
Heiko Carstensde553432008-04-17 07:45:57 +0200519 if (frame == (void __user *) -1UL)
520 goto give_sigsegv;
521
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522 if (copy_siginfo_to_user32(&frame->info, info))
523 goto give_sigsegv;
524
525 /* Create the ucontext. */
Heiko Carstensea2a4d32009-10-06 10:34:13 +0200526 err |= __put_user(UC_EXTENDED, &frame->uc.uc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527 err |= __put_user(0, &frame->uc.uc_link);
528 err |= __put_user(current->sas_ss_sp, &frame->uc.uc_stack.ss_sp);
529 err |= __put_user(sas_ss_flags(regs->gprs[15]),
530 &frame->uc.uc_stack.ss_flags);
531 err |= __put_user(current->sas_ss_size, &frame->uc.uc_stack.ss_size);
532 err |= save_sigregs32(regs, &frame->uc.uc_mcontext);
Heiko Carstensea2a4d32009-10-06 10:34:13 +0200533 err |= save_sigregs_gprs_high(regs, frame->gprs_high);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700534 err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set));
535 if (err)
536 goto give_sigsegv;
537
538 /* Set up to return from userspace. If provided, use a stub
539 already in userspace. */
540 if (ka->sa.sa_flags & SA_RESTORER) {
Martin Schwidefsky207a0542011-12-27 11:27:30 +0100541 regs->gprs[14] = (__u64) ka->sa.sa_restorer | PSW32_ADDR_AMODE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700542 } else {
Martin Schwidefsky207a0542011-12-27 11:27:30 +0100543 regs->gprs[14] = (__u64) frame->retcode | PSW32_ADDR_AMODE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544 err |= __put_user(S390_SYSCALL_OPCODE | __NR_rt_sigreturn,
Martin Schwidefsky3c52e492011-10-30 15:17:15 +0100545 (u16 __force __user *)(frame->retcode));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546 }
547
548 /* Set up backchain. */
Martin Schwidefsky3c52e492011-10-30 15:17:15 +0100549 if (__put_user(regs->gprs[15], (unsigned int __force __user *) frame))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700550 goto give_sigsegv;
551
552 /* Set up registers for signal handler */
Martin Schwidefsky3c52e492011-10-30 15:17:15 +0100553 regs->gprs[15] = (__force __u64) frame;
Martin Schwidefskyd4e81b32011-10-30 15:16:51 +0100554 regs->psw.mask |= PSW_MASK_BA; /* force amode 31 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555 regs->psw.addr = (__u64) ka->sa.sa_handler;
556
557 regs->gprs[2] = map_signal(sig);
Martin Schwidefsky3c52e492011-10-30 15:17:15 +0100558 regs->gprs[3] = (__force __u64) &frame->info;
559 regs->gprs[4] = (__force __u64) &frame->uc;
Heiko Carstens54dfe5d2006-02-01 03:06:38 -0800560 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700561
562give_sigsegv:
563 force_sigsegv(sig, current);
Heiko Carstens54dfe5d2006-02-01 03:06:38 -0800564 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565}
566
567/*
568 * OK, we're invoking a handler
569 */
570
Al Viroa610d6e2012-05-21 23:42:15 -0400571void handle_signal32(unsigned long sig, struct k_sigaction *ka,
Heiko Carstens391c62f2011-08-03 16:44:26 +0200572 siginfo_t *info, sigset_t *oldset, struct pt_regs *regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700573{
Heiko Carstens54dfe5d2006-02-01 03:06:38 -0800574 int ret;
575
Linus Torvalds1da177e2005-04-16 15:20:36 -0700576 /* Set up the stack frame */
577 if (ka->sa.sa_flags & SA_SIGINFO)
Heiko Carstens54dfe5d2006-02-01 03:06:38 -0800578 ret = setup_rt_frame32(sig, ka, info, oldset, regs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579 else
Heiko Carstens54dfe5d2006-02-01 03:06:38 -0800580 ret = setup_frame32(sig, ka, oldset, regs);
Heiko Carstens391c62f2011-08-03 16:44:26 +0200581 if (ret)
Al Viroa610d6e2012-05-21 23:42:15 -0400582 return;
Al Viroefee9842012-04-28 02:04:15 -0400583 signal_delivered(sig, info, ka, regs,
Al Viroa610d6e2012-05-21 23:42:15 -0400584 test_thread_flag(TIF_SINGLE_STEP));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585}
586