blob: 8b84bc373e945bbb2edaba876addbbf5a850fcdd [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Heiko Carstensa53c8fa2012-07-20 11:15:04 +02002 * Copyright IBM Corp. 2000, 2006
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 * Author(s): Denis Joseph Barrow (djbarrow@de.ibm.com,barrow_dj@yahoo.com)
4 * Gerhard Tonn (ton@de.ibm.com)
5 *
6 * Copyright (C) 1991, 1992 Linus Torvalds
7 *
8 * 1997-11-28 Modified for POSIX.1b signals by Richard Henderson
9 */
10
Linus Torvalds1da177e2005-04-16 15:20:36 -070011#include <linux/compat.h>
12#include <linux/sched.h>
13#include <linux/mm.h>
14#include <linux/smp.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070015#include <linux/kernel.h>
16#include <linux/signal.h>
17#include <linux/errno.h>
18#include <linux/wait.h>
19#include <linux/ptrace.h>
20#include <linux/unistd.h>
21#include <linux/stddef.h>
22#include <linux/tty.h>
23#include <linux/personality.h>
24#include <linux/binfmts.h>
25#include <asm/ucontext.h>
26#include <asm/uaccess.h>
27#include <asm/lowcore.h>
David Howellsa0616cd2012-03-28 18:30:02 +010028#include <asm/switch_to.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070029#include "compat_linux.h"
30#include "compat_ptrace.h"
Heiko Carstensa8061702008-04-17 07:46:26 +020031#include "entry.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070032
Linus Torvalds1da177e2005-04-16 15:20:36 -070033typedef struct
34{
35 __u8 callee_used_stack[__SIGNAL_FRAMESIZE32];
36 struct sigcontext32 sc;
37 _sigregs32 sregs;
38 int signo;
Heiko Carstensea2a4d32009-10-06 10:34:13 +020039 __u32 gprs_high[NUM_GPRS];
Linus Torvalds1da177e2005-04-16 15:20:36 -070040 __u8 retcode[S390_SYSCALL_SIZE];
41} sigframe32;
42
43typedef struct
44{
45 __u8 callee_used_stack[__SIGNAL_FRAMESIZE32];
46 __u8 retcode[S390_SYSCALL_SIZE];
47 compat_siginfo_t info;
48 struct ucontext32 uc;
Heiko Carstensea2a4d32009-10-06 10:34:13 +020049 __u32 gprs_high[NUM_GPRS];
Linus Torvalds1da177e2005-04-16 15:20:36 -070050} rt_sigframe32;
51
Al Viroce395962013-10-13 17:23:53 -040052int copy_siginfo_to_user32(compat_siginfo_t __user *to, const siginfo_t *from)
Linus Torvalds1da177e2005-04-16 15:20:36 -070053{
54 int err;
55
Linus Torvalds1da177e2005-04-16 15:20:36 -070056 /* If you change siginfo_t structure, please be sure
57 this code is fixed accordingly.
58 It should never copy any pad contained in the structure
59 to avoid security leaks, but must copy the generic
60 3 ints plus the relevant union member.
61 This routine must convert siginfo from 64bit to 32bit as well
62 at the same time. */
63 err = __put_user(from->si_signo, &to->si_signo);
64 err |= __put_user(from->si_errno, &to->si_errno);
65 err |= __put_user((short)from->si_code, &to->si_code);
66 if (from->si_code < 0)
67 err |= __copy_to_user(&to->_sifields._pad, &from->_sifields._pad, SI_PAD_SIZE);
68 else {
69 switch (from->si_code >> 16) {
70 case __SI_RT >> 16: /* This is not generated by the kernel as of now. */
71 case __SI_MESGQ >> 16:
72 err |= __put_user(from->si_int, &to->si_int);
73 /* fallthrough */
74 case __SI_KILL >> 16:
75 err |= __put_user(from->si_pid, &to->si_pid);
76 err |= __put_user(from->si_uid, &to->si_uid);
77 break;
78 case __SI_CHLD >> 16:
79 err |= __put_user(from->si_pid, &to->si_pid);
80 err |= __put_user(from->si_uid, &to->si_uid);
81 err |= __put_user(from->si_utime, &to->si_utime);
82 err |= __put_user(from->si_stime, &to->si_stime);
83 err |= __put_user(from->si_status, &to->si_status);
84 break;
85 case __SI_FAULT >> 16:
86 err |= __put_user((unsigned long) from->si_addr,
87 &to->si_addr);
88 break;
89 case __SI_POLL >> 16:
90 err |= __put_user(from->si_band, &to->si_band);
91 err |= __put_user(from->si_fd, &to->si_fd);
92 break;
93 case __SI_TIMER >> 16:
94 err |= __put_user(from->si_tid, &to->si_tid);
95 err |= __put_user(from->si_overrun, &to->si_overrun);
96 err |= __put_user(from->si_int, &to->si_int);
97 break;
98 default:
99 break;
100 }
101 }
Heiko Carstens0ebfd312013-10-14 12:09:37 +0200102 return err ? -EFAULT : 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103}
104
105int copy_siginfo_from_user32(siginfo_t *to, compat_siginfo_t __user *from)
106{
107 int err;
108 u32 tmp;
109
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110 err = __get_user(to->si_signo, &from->si_signo);
111 err |= __get_user(to->si_errno, &from->si_errno);
112 err |= __get_user(to->si_code, &from->si_code);
113
114 if (to->si_code < 0)
115 err |= __copy_from_user(&to->_sifields._pad, &from->_sifields._pad, SI_PAD_SIZE);
116 else {
117 switch (to->si_code >> 16) {
118 case __SI_RT >> 16: /* This is not generated by the kernel as of now. */
119 case __SI_MESGQ >> 16:
120 err |= __get_user(to->si_int, &from->si_int);
121 /* fallthrough */
122 case __SI_KILL >> 16:
123 err |= __get_user(to->si_pid, &from->si_pid);
124 err |= __get_user(to->si_uid, &from->si_uid);
125 break;
126 case __SI_CHLD >> 16:
127 err |= __get_user(to->si_pid, &from->si_pid);
128 err |= __get_user(to->si_uid, &from->si_uid);
129 err |= __get_user(to->si_utime, &from->si_utime);
130 err |= __get_user(to->si_stime, &from->si_stime);
131 err |= __get_user(to->si_status, &from->si_status);
132 break;
133 case __SI_FAULT >> 16:
134 err |= __get_user(tmp, &from->si_addr);
Martin Schwidefsky3c52e492011-10-30 15:17:15 +0100135 to->si_addr = (void __force __user *)
136 (u64) (tmp & PSW32_ADDR_INSN);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137 break;
138 case __SI_POLL >> 16:
139 err |= __get_user(to->si_band, &from->si_band);
140 err |= __get_user(to->si_fd, &from->si_fd);
141 break;
142 case __SI_TIMER >> 16:
143 err |= __get_user(to->si_tid, &from->si_tid);
144 err |= __get_user(to->si_overrun, &from->si_overrun);
145 err |= __get_user(to->si_int, &from->si_int);
146 break;
147 default:
148 break;
149 }
150 }
Heiko Carstens0ebfd312013-10-14 12:09:37 +0200151 return err ? -EFAULT : 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152}
153
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154static int save_sigregs32(struct pt_regs *regs, _sigregs32 __user *sregs)
155{
Martin Schwidefsky4725c862013-10-15 16:08:34 +0200156 _sigregs32 user_sregs;
157 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158
Heiko Carstens5ebf2502013-10-16 09:58:01 +0200159 user_sregs.regs.psw.mask = (__u32)(regs->psw.mask >> 32);
160 user_sregs.regs.psw.mask &= PSW32_MASK_USER | PSW32_MASK_RI;
Heiko Carstensf26946d2013-10-16 14:17:29 +0200161 user_sregs.regs.psw.mask |= PSW32_USER_BITS;
Martin Schwidefsky4725c862013-10-15 16:08:34 +0200162 user_sregs.regs.psw.addr = (__u32) regs->psw.addr |
Martin Schwidefskyd4e81b32011-10-30 15:16:51 +0100163 (__u32)(regs->psw.mask & PSW_MASK_BA);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164 for (i = 0; i < NUM_GPRS; i++)
Martin Schwidefsky4725c862013-10-15 16:08:34 +0200165 user_sregs.regs.gprs[i] = (__u32) regs->gprs[i];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166 save_access_regs(current->thread.acrs);
Martin Schwidefsky4725c862013-10-15 16:08:34 +0200167 memcpy(&user_sregs.regs.acrs, current->thread.acrs,
168 sizeof(user_sregs.regs.acrs));
169 save_fp_ctl(&current->thread.fp_regs.fpc);
170 save_fp_regs(current->thread.fp_regs.fprs);
171 memcpy(&user_sregs.fpregs, &current->thread.fp_regs,
172 sizeof(user_sregs.fpregs));
173 if (__copy_to_user(sregs, &user_sregs, sizeof(_sigregs32)))
Heiko Carstensf8544ec2013-10-14 13:34:28 +0200174 return -EFAULT;
175 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176}
177
178static int restore_sigregs32(struct pt_regs *regs,_sigregs32 __user *sregs)
179{
Martin Schwidefsky4725c862013-10-15 16:08:34 +0200180 _sigregs32 user_sregs;
181 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182
183 /* Alwys make any pending restarted system call return -EINTR */
184 current_thread_info()->restart_block.fn = do_no_restart_syscall;
185
Martin Schwidefsky4725c862013-10-15 16:08:34 +0200186 if (__copy_from_user(&user_sregs, &sregs->regs, sizeof(user_sregs)))
Heiko Carstensf8544ec2013-10-14 13:34:28 +0200187 return -EFAULT;
Martin Schwidefsky4725c862013-10-15 16:08:34 +0200188
Heiko Carstens5ebf2502013-10-16 09:58:01 +0200189 if (!is_ri_task(current) && (user_sregs.regs.psw.mask & PSW32_MASK_RI))
190 return -EINVAL;
191
Martin Schwidefsky4725c862013-10-15 16:08:34 +0200192 /* Loading the floating-point-control word can fail. Do that first. */
193 if (restore_fp_ctl(&user_sregs.fpregs.fpc))
194 return -EINVAL;
195
196 /* Use regs->psw.mask instead of PSW_USER_BITS to preserve PER bit. */
Hendrik Brueckneraa7e04b2013-11-19 12:26:09 +0100197 regs->psw.mask = (regs->psw.mask & ~(PSW_MASK_USER | PSW_MASK_RI)) |
Martin Schwidefsky4725c862013-10-15 16:08:34 +0200198 (__u64)(user_sregs.regs.psw.mask & PSW32_MASK_USER) << 32 |
Heiko Carstens5ebf2502013-10-16 09:58:01 +0200199 (__u64)(user_sregs.regs.psw.mask & PSW32_MASK_RI) << 32 |
Martin Schwidefsky4725c862013-10-15 16:08:34 +0200200 (__u64)(user_sregs.regs.psw.addr & PSW32_ADDR_AMODE);
Martin Schwidefskyfa968ee2012-11-07 10:44:08 +0100201 /* Check for invalid user address space control. */
Martin Schwidefskye258d712013-09-24 09:14:56 +0200202 if ((regs->psw.mask & PSW_MASK_ASC) == PSW_ASC_HOME)
203 regs->psw.mask = PSW_ASC_PRIMARY |
Martin Schwidefskyfa968ee2012-11-07 10:44:08 +0100204 (regs->psw.mask & ~PSW_MASK_ASC);
Martin Schwidefsky4725c862013-10-15 16:08:34 +0200205 regs->psw.addr = (__u64)(user_sregs.regs.psw.addr & PSW32_ADDR_INSN);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206 for (i = 0; i < NUM_GPRS; i++)
Martin Schwidefsky4725c862013-10-15 16:08:34 +0200207 regs->gprs[i] = (__u64) user_sregs.regs.gprs[i];
208 memcpy(&current->thread.acrs, &user_sregs.regs.acrs,
209 sizeof(current->thread.acrs));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210 restore_access_regs(current->thread.acrs);
211
Martin Schwidefsky4725c862013-10-15 16:08:34 +0200212 memcpy(&current->thread.fp_regs, &user_sregs.fpregs,
213 sizeof(current->thread.fp_regs));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214
Martin Schwidefsky4725c862013-10-15 16:08:34 +0200215 restore_fp_regs(current->thread.fp_regs.fprs);
Martin Schwidefskyb6ef5bb2011-10-30 15:16:49 +0100216 clear_thread_flag(TIF_SYSCALL); /* No longer in a system call */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217 return 0;
218}
219
Heiko Carstensea2a4d32009-10-06 10:34:13 +0200220static int save_sigregs_gprs_high(struct pt_regs *regs, __u32 __user *uregs)
221{
222 __u32 gprs_high[NUM_GPRS];
223 int i;
224
225 for (i = 0; i < NUM_GPRS; i++)
226 gprs_high[i] = regs->gprs[i] >> 32;
Heiko Carstensf8544ec2013-10-14 13:34:28 +0200227 if (__copy_to_user(uregs, &gprs_high, sizeof(gprs_high)))
228 return -EFAULT;
229 return 0;
Heiko Carstensea2a4d32009-10-06 10:34:13 +0200230}
231
232static int restore_sigregs_gprs_high(struct pt_regs *regs, __u32 __user *uregs)
233{
234 __u32 gprs_high[NUM_GPRS];
Heiko Carstensf8544ec2013-10-14 13:34:28 +0200235 int i;
Heiko Carstensea2a4d32009-10-06 10:34:13 +0200236
Heiko Carstensf8544ec2013-10-14 13:34:28 +0200237 if (__copy_from_user(&gprs_high, uregs, sizeof(gprs_high)))
238 return -EFAULT;
Heiko Carstensea2a4d32009-10-06 10:34:13 +0200239 for (i = 0; i < NUM_GPRS; i++)
240 *(__u32 *)&regs->gprs[i] = gprs_high[i];
241 return 0;
242}
243
Martin Schwidefsky03ff9a22007-04-27 16:01:40 +0200244asmlinkage long sys32_sigreturn(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245{
Martin Schwidefsky03ff9a22007-04-27 16:01:40 +0200246 struct pt_regs *regs = task_pt_regs(current);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247 sigframe32 __user *frame = (sigframe32 __user *)regs->gprs[15];
248 sigset_t set;
249
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250 if (__copy_from_user(&set.sig, &frame->sc.oldmask, _SIGMASK_COPY_SIZE32))
251 goto badframe;
Heiko Carstens391c62f2011-08-03 16:44:26 +0200252 set_current_blocked(&set);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253 if (restore_sigregs32(regs, &frame->sregs))
254 goto badframe;
Heiko Carstensea2a4d32009-10-06 10:34:13 +0200255 if (restore_sigregs_gprs_high(regs, frame->gprs_high))
256 goto badframe;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257 return regs->gprs[2];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258badframe:
259 force_sig(SIGSEGV, current);
260 return 0;
261}
262
Martin Schwidefsky03ff9a22007-04-27 16:01:40 +0200263asmlinkage long sys32_rt_sigreturn(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264{
Martin Schwidefsky03ff9a22007-04-27 16:01:40 +0200265 struct pt_regs *regs = task_pt_regs(current);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266 rt_sigframe32 __user *frame = (rt_sigframe32 __user *)regs->gprs[15];
267 sigset_t set;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269 if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set)))
270 goto badframe;
Heiko Carstens391c62f2011-08-03 16:44:26 +0200271 set_current_blocked(&set);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272 if (restore_sigregs32(regs, &frame->uc.uc_mcontext))
273 goto badframe;
Heiko Carstensea2a4d32009-10-06 10:34:13 +0200274 if (restore_sigregs_gprs_high(regs, frame->gprs_high))
275 goto badframe;
Al Viroe2141252012-12-23 03:36:41 -0500276 if (compat_restore_altstack(&frame->uc.uc_stack))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277 goto badframe;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278 return regs->gprs[2];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279badframe:
Martin Schwidefsky03ff9a22007-04-27 16:01:40 +0200280 force_sig(SIGSEGV, current);
281 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282}
283
284/*
285 * Set up a signal frame.
286 */
287
288
289/*
290 * Determine which stack to use..
291 */
292static inline void __user *
293get_sigframe(struct k_sigaction *ka, struct pt_regs * regs, size_t frame_size)
294{
295 unsigned long sp;
296
297 /* Default to using normal stack */
298 sp = (unsigned long) A(regs->gprs[15]);
299
Heiko Carstensde553432008-04-17 07:45:57 +0200300 /* Overflow on alternate signal stack gives SIGSEGV. */
301 if (on_sig_stack(sp) && !on_sig_stack((sp - frame_size) & -8UL))
302 return (void __user *) -1UL;
303
Linus Torvalds1da177e2005-04-16 15:20:36 -0700304 /* This is the X/Open sanctioned signal stack switching. */
305 if (ka->sa.sa_flags & SA_ONSTACK) {
Laurent Meyer28f22372006-04-27 18:40:07 -0700306 if (! sas_ss_flags(sp))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307 sp = current->sas_ss_sp + current->sas_ss_size;
308 }
309
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310 return (void __user *)((sp - frame_size) & -8ul);
311}
312
313static inline int map_signal(int sig)
314{
315 if (current_thread_info()->exec_domain
316 && current_thread_info()->exec_domain->signal_invmap
317 && sig < 32)
318 return current_thread_info()->exec_domain->signal_invmap[sig];
319 else
320 return sig;
321}
322
Heiko Carstens54dfe5d2006-02-01 03:06:38 -0800323static int setup_frame32(int sig, struct k_sigaction *ka,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324 sigset_t *set, struct pt_regs * regs)
325{
326 sigframe32 __user *frame = get_sigframe(ka, regs, sizeof(sigframe32));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327
Heiko Carstensde553432008-04-17 07:45:57 +0200328 if (frame == (void __user *) -1UL)
329 goto give_sigsegv;
330
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331 if (__copy_to_user(&frame->sc.oldmask, &set->sig, _SIGMASK_COPY_SIZE32))
332 goto give_sigsegv;
333
334 if (save_sigregs32(regs, &frame->sregs))
335 goto give_sigsegv;
Heiko Carstensea2a4d32009-10-06 10:34:13 +0200336 if (save_sigregs_gprs_high(regs, frame->gprs_high))
337 goto give_sigsegv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338 if (__put_user((unsigned long) &frame->sregs, &frame->sc.sregs))
339 goto give_sigsegv;
340
341 /* Set up to return from userspace. If provided, use a stub
342 already in userspace. */
343 if (ka->sa.sa_flags & SA_RESTORER) {
Heiko Carstens5b512be2013-09-06 18:52:31 +0200344 regs->gprs[14] = (__u64 __force) ka->sa.sa_restorer | PSW32_ADDR_AMODE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345 } else {
Heiko Carstens5b512be2013-09-06 18:52:31 +0200346 regs->gprs[14] = (__u64 __force) frame->retcode | PSW32_ADDR_AMODE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347 if (__put_user(S390_SYSCALL_OPCODE | __NR_sigreturn,
Martin Schwidefsky3c52e492011-10-30 15:17:15 +0100348 (u16 __force __user *)(frame->retcode)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349 goto give_sigsegv;
350 }
351
352 /* Set up backchain. */
353 if (__put_user(regs->gprs[15], (unsigned int __user *) frame))
354 goto give_sigsegv;
355
356 /* Set up registers for signal handler */
Martin Schwidefsky3c52e492011-10-30 15:17:15 +0100357 regs->gprs[15] = (__force __u64) frame;
Martin Schwidefskyfa968ee2012-11-07 10:44:08 +0100358 /* Force 31 bit amode and default user address space control. */
359 regs->psw.mask = PSW_MASK_BA |
Martin Schwidefskye258d712013-09-24 09:14:56 +0200360 (PSW_USER_BITS & PSW_MASK_ASC) |
Martin Schwidefskyfa968ee2012-11-07 10:44:08 +0100361 (regs->psw.mask & ~PSW_MASK_ASC);
Martin Schwidefsky3c52e492011-10-30 15:17:15 +0100362 regs->psw.addr = (__force __u64) ka->sa.sa_handler;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363
364 regs->gprs[2] = map_signal(sig);
Martin Schwidefsky3c52e492011-10-30 15:17:15 +0100365 regs->gprs[3] = (__force __u64) &frame->sc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366
367 /* We forgot to include these in the sigcontext.
368 To avoid breaking binary compatibility, they are passed as args. */
Martin Schwidefskyaa33c8c2011-12-27 11:27:18 +0100369 if (sig == SIGSEGV || sig == SIGBUS || sig == SIGILL ||
370 sig == SIGTRAP || sig == SIGFPE) {
371 /* set extra registers only for synchronous signals */
372 regs->gprs[4] = regs->int_code & 127;
373 regs->gprs[5] = regs->int_parm_long;
Michael Holzheubd9e0342013-04-15 17:50:03 +0200374 regs->gprs[6] = task_thread_info(current)->last_break;
Martin Schwidefskyaa33c8c2011-12-27 11:27:18 +0100375 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376
377 /* Place signal number on stack to allow backtrace from handler. */
Martin Schwidefsky3c52e492011-10-30 15:17:15 +0100378 if (__put_user(regs->gprs[2], (int __force __user *) &frame->signo))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379 goto give_sigsegv;
Heiko Carstens54dfe5d2006-02-01 03:06:38 -0800380 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381
382give_sigsegv:
383 force_sigsegv(sig, current);
Heiko Carstens54dfe5d2006-02-01 03:06:38 -0800384 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385}
386
Heiko Carstens54dfe5d2006-02-01 03:06:38 -0800387static int setup_rt_frame32(int sig, struct k_sigaction *ka, siginfo_t *info,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700388 sigset_t *set, struct pt_regs * regs)
389{
390 int err = 0;
391 rt_sigframe32 __user *frame = get_sigframe(ka, regs, sizeof(rt_sigframe32));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392
Heiko Carstensde553432008-04-17 07:45:57 +0200393 if (frame == (void __user *) -1UL)
394 goto give_sigsegv;
395
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396 if (copy_siginfo_to_user32(&frame->info, info))
397 goto give_sigsegv;
398
399 /* Create the ucontext. */
Heiko Carstensea2a4d32009-10-06 10:34:13 +0200400 err |= __put_user(UC_EXTENDED, &frame->uc.uc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401 err |= __put_user(0, &frame->uc.uc_link);
Al Viroe2141252012-12-23 03:36:41 -0500402 err |= __compat_save_altstack(&frame->uc.uc_stack, regs->gprs[15]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403 err |= save_sigregs32(regs, &frame->uc.uc_mcontext);
Heiko Carstensea2a4d32009-10-06 10:34:13 +0200404 err |= save_sigregs_gprs_high(regs, frame->gprs_high);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405 err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set));
406 if (err)
407 goto give_sigsegv;
408
409 /* Set up to return from userspace. If provided, use a stub
410 already in userspace. */
411 if (ka->sa.sa_flags & SA_RESTORER) {
Heiko Carstens5b512be2013-09-06 18:52:31 +0200412 regs->gprs[14] = (__u64 __force) ka->sa.sa_restorer | PSW32_ADDR_AMODE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413 } else {
Heiko Carstens5b512be2013-09-06 18:52:31 +0200414 regs->gprs[14] = (__u64 __force) frame->retcode | PSW32_ADDR_AMODE;
Martin Schwidefsky41932bc2013-12-10 16:18:07 +0100415 if (__put_user(S390_SYSCALL_OPCODE | __NR_rt_sigreturn,
416 (u16 __force __user *)(frame->retcode)))
417 goto give_sigsegv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418 }
419
420 /* Set up backchain. */
Martin Schwidefsky3c52e492011-10-30 15:17:15 +0100421 if (__put_user(regs->gprs[15], (unsigned int __force __user *) frame))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422 goto give_sigsegv;
423
424 /* Set up registers for signal handler */
Martin Schwidefsky3c52e492011-10-30 15:17:15 +0100425 regs->gprs[15] = (__force __u64) frame;
Martin Schwidefskyfa968ee2012-11-07 10:44:08 +0100426 /* Force 31 bit amode and default user address space control. */
427 regs->psw.mask = PSW_MASK_BA |
Martin Schwidefskye258d712013-09-24 09:14:56 +0200428 (PSW_USER_BITS & PSW_MASK_ASC) |
Martin Schwidefskyfa968ee2012-11-07 10:44:08 +0100429 (regs->psw.mask & ~PSW_MASK_ASC);
Heiko Carstens5b512be2013-09-06 18:52:31 +0200430 regs->psw.addr = (__u64 __force) ka->sa.sa_handler;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431
432 regs->gprs[2] = map_signal(sig);
Martin Schwidefsky3c52e492011-10-30 15:17:15 +0100433 regs->gprs[3] = (__force __u64) &frame->info;
434 regs->gprs[4] = (__force __u64) &frame->uc;
Michael Holzheubd9e0342013-04-15 17:50:03 +0200435 regs->gprs[5] = task_thread_info(current)->last_break;
Heiko Carstens54dfe5d2006-02-01 03:06:38 -0800436 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437
438give_sigsegv:
439 force_sigsegv(sig, current);
Heiko Carstens54dfe5d2006-02-01 03:06:38 -0800440 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700441}
442
443/*
444 * OK, we're invoking a handler
445 */
446
Al Viroa610d6e2012-05-21 23:42:15 -0400447void handle_signal32(unsigned long sig, struct k_sigaction *ka,
Heiko Carstens391c62f2011-08-03 16:44:26 +0200448 siginfo_t *info, sigset_t *oldset, struct pt_regs *regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449{
Heiko Carstens54dfe5d2006-02-01 03:06:38 -0800450 int ret;
451
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452 /* Set up the stack frame */
453 if (ka->sa.sa_flags & SA_SIGINFO)
Heiko Carstens54dfe5d2006-02-01 03:06:38 -0800454 ret = setup_rt_frame32(sig, ka, info, oldset, regs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455 else
Heiko Carstens54dfe5d2006-02-01 03:06:38 -0800456 ret = setup_frame32(sig, ka, oldset, regs);
Heiko Carstens391c62f2011-08-03 16:44:26 +0200457 if (ret)
Al Viroa610d6e2012-05-21 23:42:15 -0400458 return;
Al Viroefee9842012-04-28 02:04:15 -0400459 signal_delivered(sig, info, ka, regs,
Al Viroa610d6e2012-05-21 23:42:15 -0400460 test_thread_flag(TIF_SINGLE_STEP));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461}
462