blob: 545448b7aebaf0d3bf9c85421c3cad411416b934 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002 * Copyright (C) 1991, 1992 Linus Torvalds
3 *
4 * 1997-11-28 Modified for POSIX.1b signals by Richard Henderson
5 * 2000-06-20 Pentium III FXSR, SSE support by Gareth Hughes
6 */
Ingo Molnar7e907f42008-03-06 10:33:08 +01007#include <linux/list.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07008
Linus Torvalds1da177e2005-04-16 15:20:36 -07009#include <linux/personality.h>
Andi Kleen9fbbd4d2007-02-13 13:26:26 +010010#include <linux/binfmts.h>
Ingo Molnar7e907f42008-03-06 10:33:08 +010011#include <linux/suspend.h>
12#include <linux/kernel.h>
13#include <linux/ptrace.h>
14#include <linux/signal.h>
15#include <linux/stddef.h>
16#include <linux/unistd.h>
17#include <linux/errno.h>
18#include <linux/sched.h>
19#include <linux/wait.h>
Roland McGrath36a03302008-03-14 17:46:38 -070020#include <linux/tracehook.h>
Ingo Molnar7e907f42008-03-06 10:33:08 +010021#include <linux/elf.h>
22#include <linux/smp.h>
23#include <linux/mm.h>
24
Linus Torvalds1da177e2005-04-16 15:20:36 -070025#include <asm/processor.h>
26#include <asm/ucontext.h>
27#include <asm/uaccess.h>
28#include <asm/i387.h>
Roland McGrath6c3652e2008-01-30 13:30:42 +010029#include <asm/vdso.h>
Hiroshi Shimamotobb579252008-09-05 16:26:55 -070030#include <asm/syscall.h>
Jaswinder Singhbbc1f692008-07-21 21:34:13 +053031#include <asm/syscalls.h>
Ingo Molnar7e907f42008-03-06 10:33:08 +010032
Harvey Harrison123a6342008-02-08 12:10:00 -080033#include "sigframe.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070034
Linus Torvalds1da177e2005-04-16 15:20:36 -070035#define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP)))
36
Harvey Harrison1a176802008-02-08 12:09:59 -080037#define __FIX_EFLAGS (X86_EFLAGS_AC | X86_EFLAGS_OF | \
38 X86_EFLAGS_DF | X86_EFLAGS_TF | X86_EFLAGS_SF | \
39 X86_EFLAGS_ZF | X86_EFLAGS_AF | X86_EFLAGS_PF | \
40 X86_EFLAGS_CF)
41
42#ifdef CONFIG_X86_32
43# define FIX_EFLAGS (__FIX_EFLAGS | X86_EFLAGS_RF)
44#else
45# define FIX_EFLAGS __FIX_EFLAGS
46#endif
47
Linus Torvalds1da177e2005-04-16 15:20:36 -070048/*
49 * Atomically swap in the new signal mask, and wait for a signal.
50 */
51asmlinkage int
52sys_sigsuspend(int history0, int history1, old_sigset_t mask)
53{
Linus Torvalds1da177e2005-04-16 15:20:36 -070054 mask &= _BLOCKABLE;
55 spin_lock_irq(&current->sighand->siglock);
David Howells283828f2006-01-18 17:44:00 -080056 current->saved_sigmask = current->blocked;
Linus Torvalds1da177e2005-04-16 15:20:36 -070057 siginitset(&current->blocked, mask);
58 recalc_sigpending();
59 spin_unlock_irq(&current->sighand->siglock);
60
David Howells283828f2006-01-18 17:44:00 -080061 current->state = TASK_INTERRUPTIBLE;
62 schedule();
Roland McGrath5a8da0e2008-04-30 00:53:10 -070063 set_restore_sigmask();
Ingo Molnar7e907f42008-03-06 10:33:08 +010064
David Howells283828f2006-01-18 17:44:00 -080065 return -ERESTARTNOHAND;
Linus Torvalds1da177e2005-04-16 15:20:36 -070066}
67
Ingo Molnar7e907f42008-03-06 10:33:08 +010068asmlinkage int
Linus Torvalds1da177e2005-04-16 15:20:36 -070069sys_sigaction(int sig, const struct old_sigaction __user *act,
70 struct old_sigaction __user *oact)
71{
72 struct k_sigaction new_ka, old_ka;
73 int ret;
74
75 if (act) {
76 old_sigset_t mask;
Ingo Molnar7e907f42008-03-06 10:33:08 +010077
Linus Torvalds1da177e2005-04-16 15:20:36 -070078 if (!access_ok(VERIFY_READ, act, sizeof(*act)) ||
79 __get_user(new_ka.sa.sa_handler, &act->sa_handler) ||
80 __get_user(new_ka.sa.sa_restorer, &act->sa_restorer))
81 return -EFAULT;
Ingo Molnar7e907f42008-03-06 10:33:08 +010082
Linus Torvalds1da177e2005-04-16 15:20:36 -070083 __get_user(new_ka.sa.sa_flags, &act->sa_flags);
84 __get_user(mask, &act->sa_mask);
85 siginitset(&new_ka.sa.sa_mask, mask);
86 }
87
88 ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL);
89
90 if (!ret && oact) {
91 if (!access_ok(VERIFY_WRITE, oact, sizeof(*oact)) ||
92 __put_user(old_ka.sa.sa_handler, &oact->sa_handler) ||
93 __put_user(old_ka.sa.sa_restorer, &oact->sa_restorer))
94 return -EFAULT;
Ingo Molnar7e907f42008-03-06 10:33:08 +010095
Linus Torvalds1da177e2005-04-16 15:20:36 -070096 __put_user(old_ka.sa.sa_flags, &oact->sa_flags);
97 __put_user(old_ka.sa.sa_mask.sig[0], &oact->sa_mask);
98 }
99
100 return ret;
101}
102
Ingo Molnar7e907f42008-03-06 10:33:08 +0100103asmlinkage int sys_sigaltstack(unsigned long bx)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104{
Ingo Molnar7e907f42008-03-06 10:33:08 +0100105 /*
106 * This is needed to make gcc realize it doesn't own the
107 * "struct pt_regs"
108 */
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100109 struct pt_regs *regs = (struct pt_regs *)&bx;
110 const stack_t __user *uss = (const stack_t __user *)bx;
111 stack_t __user *uoss = (stack_t __user *)regs->cx;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100113 return do_sigaltstack(uss, uoss, regs->sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114}
115
Hiroshi Shimamotoa2e8d3d2008-10-02 22:09:20 -0700116#define COPY(x) { \
117 err |= __get_user(regs->x, &sc->x); \
118}
119
120#define COPY_SEG(seg) { \
121 unsigned short tmp; \
122 err |= __get_user(tmp, &sc->seg); \
123 regs->seg = tmp; \
124}
125
126#define COPY_SEG_STRICT(seg) { \
127 unsigned short tmp; \
128 err |= __get_user(tmp, &sc->seg); \
129 regs->seg = tmp | 3; \
130}
131
132#define GET_SEG(seg) { \
133 unsigned short tmp; \
134 err |= __get_user(tmp, &sc->seg); \
135 loadsegment(seg, tmp); \
136}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137
138/*
139 * Do a signal return; undo the signal stack.
140 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141static int
Harvey Harrison866bc132008-02-08 12:10:02 -0800142restore_sigcontext(struct pt_regs *regs, struct sigcontext __user *sc,
143 unsigned long *pax)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144{
145 unsigned int err = 0;
146
147 /* Always make any pending restarted system calls return -EINTR */
148 current_thread_info()->restart_block.fn = do_no_restart_syscall;
149
Jeremy Fitzhardinge464d1a72007-02-13 13:26:20 +0100150 GET_SEG(gs);
151 COPY_SEG(fs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152 COPY_SEG(es);
153 COPY_SEG(ds);
Harvey Harrisonac66f3f2008-02-08 12:09:58 -0800154 COPY(di); COPY(si); COPY(bp); COPY(sp); COPY(bx);
155 COPY(dx); COPY(cx); COPY(ip);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156 COPY_SEG_STRICT(cs);
157 COPY_SEG_STRICT(ss);
Ingo Molnar7e907f42008-03-06 10:33:08 +0100158
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159 {
160 unsigned int tmpflags;
Ingo Molnar7e907f42008-03-06 10:33:08 +0100161
H. Peter Anvin742fa542008-01-30 13:30:56 +0100162 err |= __get_user(tmpflags, &sc->flags);
Ingo Molnar7e907f42008-03-06 10:33:08 +0100163 regs->flags = (regs->flags & ~FIX_EFLAGS) |
164 (tmpflags & FIX_EFLAGS);
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100165 regs->orig_ax = -1; /* disable syscall checks */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166 }
167
168 {
Suresh Siddhaab513702008-07-29 10:29:22 -0700169 void __user *buf;
Ingo Molnar7e907f42008-03-06 10:33:08 +0100170
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171 err |= __get_user(buf, &sc->fpstate);
Suresh Siddhaab513702008-07-29 10:29:22 -0700172 err |= restore_i387_xstate(buf);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173 }
174
Harvey Harrison866bc132008-02-08 12:10:02 -0800175 err |= __get_user(*pax, &sc->ax);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177}
178
Harvey Harrison866bc132008-02-08 12:10:02 -0800179asmlinkage unsigned long sys_sigreturn(unsigned long __unused)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180{
Ingo Molnar7e907f42008-03-06 10:33:08 +0100181 struct sigframe __user *frame;
182 struct pt_regs *regs;
Harvey Harrison866bc132008-02-08 12:10:02 -0800183 unsigned long ax;
Ingo Molnar7e907f42008-03-06 10:33:08 +0100184 sigset_t set;
185
186 regs = (struct pt_regs *) &__unused;
187 frame = (struct sigframe __user *)(regs->sp - 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188
189 if (!access_ok(VERIFY_READ, frame, sizeof(*frame)))
190 goto badframe;
Ingo Molnar7e907f42008-03-06 10:33:08 +0100191 if (__get_user(set.sig[0], &frame->sc.oldmask) || (_NSIG_WORDS > 1
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192 && __copy_from_user(&set.sig[1], &frame->extramask,
193 sizeof(frame->extramask))))
194 goto badframe;
195
196 sigdelsetmask(&set, ~_BLOCKABLE);
197 spin_lock_irq(&current->sighand->siglock);
198 current->blocked = set;
199 recalc_sigpending();
200 spin_unlock_irq(&current->sighand->siglock);
Ingo Molnar7e907f42008-03-06 10:33:08 +0100201
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100202 if (restore_sigcontext(regs, &frame->sc, &ax))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203 goto badframe;
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100204 return ax;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205
206badframe:
Andi Kleen03252912008-01-30 13:33:18 +0100207 if (show_unhandled_signals && printk_ratelimit()) {
Hiroshi Shimamoto1181f8b2008-07-03 13:12:13 -0700208 printk("%s%s[%d] bad frame in sigreturn frame:"
Ingo Molnar97b44ae2008-03-06 10:43:17 +0100209 "%p ip:%lx sp:%lx oeax:%lx",
Alexey Dobriyan19c58702007-10-18 23:40:41 -0700210 task_pid_nr(current) > 1 ? KERN_INFO : KERN_EMERG,
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100211 current->comm, task_pid_nr(current), frame, regs->ip,
212 regs->sp, regs->orig_ax);
Andi Kleen03252912008-01-30 13:33:18 +0100213 print_vma_addr(" in ", regs->ip);
Ingo Molnar97b44ae2008-03-06 10:43:17 +0100214 printk(KERN_CONT "\n");
Andi Kleen03252912008-01-30 13:33:18 +0100215 }
Masoud Asgharifard Sharbianiabd4f752007-07-22 11:12:28 +0200216
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217 force_sig(SIGSEGV, current);
Ingo Molnar7e907f42008-03-06 10:33:08 +0100218
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219 return 0;
Ingo Molnar7e907f42008-03-06 10:33:08 +0100220}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221
Hiroshi Shimamotoe6babb62008-09-12 17:03:31 -0700222static long do_rt_sigreturn(struct pt_regs *regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223{
Harvey Harrison2d19c452008-02-08 12:10:00 -0800224 struct rt_sigframe __user *frame;
Harvey Harrison866bc132008-02-08 12:10:02 -0800225 unsigned long ax;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226 sigset_t set;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227
Harvey Harrison2d19c452008-02-08 12:10:00 -0800228 frame = (struct rt_sigframe __user *)(regs->sp - sizeof(long));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229 if (!access_ok(VERIFY_READ, frame, sizeof(*frame)))
230 goto badframe;
231 if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set)))
232 goto badframe;
233
234 sigdelsetmask(&set, ~_BLOCKABLE);
235 spin_lock_irq(&current->sighand->siglock);
236 current->blocked = set;
237 recalc_sigpending();
238 spin_unlock_irq(&current->sighand->siglock);
Ingo Molnar7e907f42008-03-06 10:33:08 +0100239
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100240 if (restore_sigcontext(regs, &frame->uc.uc_mcontext, &ax))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241 goto badframe;
242
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100243 if (do_sigaltstack(&frame->uc.uc_stack, NULL, regs->sp) == -EFAULT)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244 goto badframe;
245
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100246 return ax;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247
248badframe:
Hiroshi Shimamotoe6babb62008-09-12 17:03:31 -0700249 signal_fault(regs, frame, "rt_sigreturn");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250 return 0;
Ingo Molnar7e907f42008-03-06 10:33:08 +0100251}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252
Hiroshi Shimamotoe6babb62008-09-12 17:03:31 -0700253asmlinkage int sys_rt_sigreturn(unsigned long __unused)
254{
255 struct pt_regs *regs = (struct pt_regs *)&__unused;
256
257 return do_rt_sigreturn(regs);
258}
259
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260/*
261 * Set up a signal frame.
262 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263static int
Suresh Siddhaab513702008-07-29 10:29:22 -0700264setup_sigcontext(struct sigcontext __user *sc, void __user *fpstate,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265 struct pt_regs *regs, unsigned long mask)
266{
267 int tmp, err = 0;
268
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100269 err |= __put_user(regs->fs, (unsigned int __user *)&sc->fs);
Jeremy Fitzhardinge464d1a72007-02-13 13:26:20 +0100270 savesegment(gs, tmp);
271 err |= __put_user(tmp, (unsigned int __user *)&sc->gs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100273 err |= __put_user(regs->es, (unsigned int __user *)&sc->es);
274 err |= __put_user(regs->ds, (unsigned int __user *)&sc->ds);
H. Peter Anvin742fa542008-01-30 13:30:56 +0100275 err |= __put_user(regs->di, &sc->di);
276 err |= __put_user(regs->si, &sc->si);
277 err |= __put_user(regs->bp, &sc->bp);
278 err |= __put_user(regs->sp, &sc->sp);
279 err |= __put_user(regs->bx, &sc->bx);
280 err |= __put_user(regs->dx, &sc->dx);
281 err |= __put_user(regs->cx, &sc->cx);
282 err |= __put_user(regs->ax, &sc->ax);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283 err |= __put_user(current->thread.trap_no, &sc->trapno);
284 err |= __put_user(current->thread.error_code, &sc->err);
H. Peter Anvin742fa542008-01-30 13:30:56 +0100285 err |= __put_user(regs->ip, &sc->ip);
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100286 err |= __put_user(regs->cs, (unsigned int __user *)&sc->cs);
H. Peter Anvin742fa542008-01-30 13:30:56 +0100287 err |= __put_user(regs->flags, &sc->flags);
288 err |= __put_user(regs->sp, &sc->sp_at_signal);
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100289 err |= __put_user(regs->ss, (unsigned int __user *)&sc->ss);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290
Suresh Siddhaab513702008-07-29 10:29:22 -0700291 tmp = save_i387_xstate(fpstate);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292 if (tmp < 0)
Ingo Molnar7e907f42008-03-06 10:33:08 +0100293 err = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294 else
Ingo Molnar7e907f42008-03-06 10:33:08 +0100295 err |= __put_user(tmp ? fpstate : NULL, &sc->fpstate);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296
297 /* non-iBCS2 extensions.. */
298 err |= __put_user(mask, &sc->oldmask);
299 err |= __put_user(current->thread.cr2, &sc->cr2);
300
301 return err;
302}
303
304/*
305 * Determine which stack to use..
306 */
307static inline void __user *
Suresh Siddha3c1c7f12008-07-29 10:29:21 -0700308get_sigframe(struct k_sigaction *ka, struct pt_regs *regs, size_t frame_size,
Suresh Siddhaab513702008-07-29 10:29:22 -0700309 void **fpstate)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310{
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100311 unsigned long sp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312
313 /* Default to using normal stack */
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100314 sp = regs->sp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315
Roland McGrath83bd0102008-01-30 13:30:06 +0100316 /*
317 * If we are on the alternate signal stack and would overflow it, don't.
318 * Return an always-bogus address instead so we will die with SIGSEGV.
319 */
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100320 if (on_sig_stack(sp) && !likely(on_sig_stack(sp - frame_size)))
Roland McGrath83bd0102008-01-30 13:30:06 +0100321 return (void __user *) -1L;
322
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323 /* This is the X/Open sanctioned signal stack switching. */
324 if (ka->sa.sa_flags & SA_ONSTACK) {
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100325 if (sas_ss_flags(sp) == 0)
326 sp = current->sas_ss_sp + current->sas_ss_size;
Ingo Molnar7e907f42008-03-06 10:33:08 +0100327 } else {
328 /* This is the legacy signal stack switching. */
329 if ((regs->ss & 0xffff) != __USER_DS &&
330 !(ka->sa.sa_flags & SA_RESTORER) &&
331 ka->sa.sa_restorer)
332 sp = (unsigned long) ka->sa.sa_restorer;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333 }
334
Suresh Siddha3c1c7f12008-07-29 10:29:21 -0700335 if (used_math()) {
336 sp = sp - sig_xstate_size;
337 *fpstate = (struct _fpstate *) sp;
338 }
339
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100340 sp -= frame_size;
Ingo Molnar7e907f42008-03-06 10:33:08 +0100341 /*
342 * Align the stack pointer according to the i386 ABI,
343 * i.e. so that on function entry ((sp + 4) & 15) == 0.
344 */
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100345 sp = ((sp + 4) & -16ul) - 4;
Ingo Molnar7e907f42008-03-06 10:33:08 +0100346
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100347 return (void __user *) sp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348}
349
Ingo Molnar7e907f42008-03-06 10:33:08 +0100350static int
Hiroshi Shimamoto1d130242008-09-05 16:28:06 -0700351__setup_frame(int sig, struct k_sigaction *ka, sigset_t *set,
352 struct pt_regs *regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354 struct sigframe __user *frame;
Ingo Molnar7e907f42008-03-06 10:33:08 +0100355 void __user *restorer;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356 int err = 0;
Suresh Siddhaab513702008-07-29 10:29:22 -0700357 void __user *fpstate = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700358
Suresh Siddha3c1c7f12008-07-29 10:29:21 -0700359 frame = get_sigframe(ka, regs, sizeof(*frame), &fpstate);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360
361 if (!access_ok(VERIFY_WRITE, frame, sizeof(*frame)))
Hiroshi Shimamoto3d0aedd2008-09-12 17:01:09 -0700362 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363
Hiroshi Shimamoto2ba48e12008-09-12 17:02:53 -0700364 if (__put_user(sig, &frame->sig))
Hiroshi Shimamoto3d0aedd2008-09-12 17:01:09 -0700365 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366
Hiroshi Shimamoto2ba48e12008-09-12 17:02:53 -0700367 if (setup_sigcontext(&frame->sc, fpstate, regs, set->sig[0]))
Hiroshi Shimamoto3d0aedd2008-09-12 17:01:09 -0700368 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369
370 if (_NSIG_WORDS > 1) {
Hiroshi Shimamoto2ba48e12008-09-12 17:02:53 -0700371 if (__copy_to_user(&frame->extramask, &set->sig[1],
372 sizeof(frame->extramask)))
Hiroshi Shimamoto3d0aedd2008-09-12 17:01:09 -0700373 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700374 }
375
Roland McGrath1a3e4ca2008-04-09 01:29:27 -0700376 if (current->mm->context.vdso)
Roland McGrath6c3652e2008-01-30 13:30:42 +0100377 restorer = VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
Andi Kleen9fbbd4d2007-02-13 13:26:26 +0100378 else
Jan Engelhardtade1af72008-01-30 13:33:23 +0100379 restorer = &frame->retcode;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700380 if (ka->sa.sa_flags & SA_RESTORER)
381 restorer = ka->sa.sa_restorer;
382
383 /* Set up to return from userspace. */
384 err |= __put_user(restorer, &frame->pretcode);
Ingo Molnar7e907f42008-03-06 10:33:08 +0100385
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386 /*
Ingo Molnar7e907f42008-03-06 10:33:08 +0100387 * This is popl %eax ; movl $__NR_sigreturn, %eax ; int $0x80
Linus Torvalds1da177e2005-04-16 15:20:36 -0700388 *
389 * WE DO NOT USE IT ANY MORE! It's only left here for historical
390 * reasons and because gdb uses it as a signature to notice
391 * signal handler stack frames.
392 */
393 err |= __put_user(0xb858, (short __user *)(frame->retcode+0));
394 err |= __put_user(__NR_sigreturn, (int __user *)(frame->retcode+2));
395 err |= __put_user(0x80cd, (short __user *)(frame->retcode+6));
396
397 if (err)
Hiroshi Shimamoto3d0aedd2008-09-12 17:01:09 -0700398 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399
400 /* Set up registers for signal handler */
Ingo Molnar7e907f42008-03-06 10:33:08 +0100401 regs->sp = (unsigned long)frame;
402 regs->ip = (unsigned long)ka->sa.sa_handler;
403 regs->ax = (unsigned long)sig;
Harvey Harrison92bc2052008-02-08 12:09:56 -0800404 regs->dx = 0;
405 regs->cx = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100407 regs->ds = __USER_DS;
408 regs->es = __USER_DS;
409 regs->ss = __USER_DS;
410 regs->cs = __USER_CS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411
David Howells283828f2006-01-18 17:44:00 -0800412 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413}
414
Hiroshi Shimamoto1d130242008-09-05 16:28:06 -0700415static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
416 sigset_t *set, struct pt_regs *regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418 struct rt_sigframe __user *frame;
Ingo Molnar7e907f42008-03-06 10:33:08 +0100419 void __user *restorer;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420 int err = 0;
Suresh Siddhaab513702008-07-29 10:29:22 -0700421 void __user *fpstate = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422
Suresh Siddha3c1c7f12008-07-29 10:29:21 -0700423 frame = get_sigframe(ka, regs, sizeof(*frame), &fpstate);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700424
425 if (!access_ok(VERIFY_WRITE, frame, sizeof(*frame)))
Hiroshi Shimamoto3d0aedd2008-09-12 17:01:09 -0700426 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427
Hiroshi Shimamoto13ad7722008-09-05 16:28:38 -0700428 err |= __put_user(sig, &frame->sig);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429 err |= __put_user(&frame->info, &frame->pinfo);
430 err |= __put_user(&frame->uc, &frame->puc);
431 err |= copy_siginfo_to_user(&frame->info, info);
432 if (err)
Hiroshi Shimamoto3d0aedd2008-09-12 17:01:09 -0700433 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700434
435 /* Create the ucontext. */
Suresh Siddhac37b5ef2008-07-29 10:29:25 -0700436 if (cpu_has_xsave)
437 err |= __put_user(UC_FP_XSTATE, &frame->uc.uc_flags);
438 else
439 err |= __put_user(0, &frame->uc.uc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440 err |= __put_user(0, &frame->uc.uc_link);
441 err |= __put_user(current->sas_ss_sp, &frame->uc.uc_stack.ss_sp);
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100442 err |= __put_user(sas_ss_flags(regs->sp),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443 &frame->uc.uc_stack.ss_flags);
444 err |= __put_user(current->sas_ss_size, &frame->uc.uc_stack.ss_size);
Suresh Siddha3c1c7f12008-07-29 10:29:21 -0700445 err |= setup_sigcontext(&frame->uc.uc_mcontext, fpstate,
Ingo Molnar7e907f42008-03-06 10:33:08 +0100446 regs, set->sig[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447 err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set));
448 if (err)
Hiroshi Shimamoto3d0aedd2008-09-12 17:01:09 -0700449 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450
451 /* Set up to return from userspace. */
Roland McGrath6c3652e2008-01-30 13:30:42 +0100452 restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453 if (ka->sa.sa_flags & SA_RESTORER)
454 restorer = ka->sa.sa_restorer;
455 err |= __put_user(restorer, &frame->pretcode);
Ingo Molnar7e907f42008-03-06 10:33:08 +0100456
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457 /*
Ingo Molnar7e907f42008-03-06 10:33:08 +0100458 * This is movl $__NR_rt_sigreturn, %ax ; int $0x80
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459 *
460 * WE DO NOT USE IT ANY MORE! It's only left here for historical
461 * reasons and because gdb uses it as a signature to notice
462 * signal handler stack frames.
463 */
464 err |= __put_user(0xb8, (char __user *)(frame->retcode+0));
465 err |= __put_user(__NR_rt_sigreturn, (int __user *)(frame->retcode+1));
466 err |= __put_user(0x80cd, (short __user *)(frame->retcode+5));
467
468 if (err)
Hiroshi Shimamoto3d0aedd2008-09-12 17:01:09 -0700469 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470
471 /* Set up registers for signal handler */
Ingo Molnar7e907f42008-03-06 10:33:08 +0100472 regs->sp = (unsigned long)frame;
473 regs->ip = (unsigned long)ka->sa.sa_handler;
Hiroshi Shimamoto13ad7722008-09-05 16:28:38 -0700474 regs->ax = (unsigned long)sig;
Ingo Molnar7e907f42008-03-06 10:33:08 +0100475 regs->dx = (unsigned long)&frame->info;
476 regs->cx = (unsigned long)&frame->uc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100478 regs->ds = __USER_DS;
479 regs->es = __USER_DS;
480 regs->ss = __USER_DS;
481 regs->cs = __USER_CS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482
David Howells283828f2006-01-18 17:44:00 -0800483 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700484}
485
486/*
Ingo Molnar7e907f42008-03-06 10:33:08 +0100487 * OK, we're invoking a handler:
488 */
Hiroshi Shimamoto8d8c13b2008-09-24 19:10:29 -0700489static int signr_convert(int sig)
490{
491 struct thread_info *info = current_thread_info();
492
493 if (info->exec_domain && info->exec_domain->signal_invmap && sig < 32)
494 return info->exec_domain->signal_invmap[sig];
495 return sig;
496}
497
Hiroshi Shimamoto455edbc2008-09-24 19:13:11 -0700498#define is_ia32 1
Hiroshi Shimamoto4694d232008-09-24 19:13:29 -0700499#define ia32_setup_frame __setup_frame
500#define ia32_setup_rt_frame __setup_rt_frame
Hiroshi Shimamoto455edbc2008-09-24 19:13:11 -0700501
Roland McGrath7c1def12005-06-23 00:08:21 -0700502static int
Hiroshi Shimamoto1d130242008-09-05 16:28:06 -0700503setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
504 sigset_t *set, struct pt_regs *regs)
505{
Hiroshi Shimamoto8d8c13b2008-09-24 19:10:29 -0700506 int usig = signr_convert(sig);
Hiroshi Shimamoto1d130242008-09-05 16:28:06 -0700507 int ret;
508
509 /* Set up the stack frame */
Hiroshi Shimamoto455edbc2008-09-24 19:13:11 -0700510 if (is_ia32) {
511 if (ka->sa.sa_flags & SA_SIGINFO)
Hiroshi Shimamoto4694d232008-09-24 19:13:29 -0700512 ret = ia32_setup_rt_frame(usig, ka, info, set, regs);
Hiroshi Shimamoto455edbc2008-09-24 19:13:11 -0700513 else
Hiroshi Shimamoto4694d232008-09-24 19:13:29 -0700514 ret = ia32_setup_frame(usig, ka, set, regs);
Hiroshi Shimamoto455edbc2008-09-24 19:13:11 -0700515 } else
516 ret = __setup_rt_frame(sig, ka, info, set, regs);
Hiroshi Shimamoto1d130242008-09-05 16:28:06 -0700517
Hiroshi Shimamoto3d0aedd2008-09-12 17:01:09 -0700518 if (ret) {
519 force_sigsegv(sig, current);
520 return -EFAULT;
521 }
522
Hiroshi Shimamoto1d130242008-09-05 16:28:06 -0700523 return ret;
524}
525
526static int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527handle_signal(unsigned long sig, siginfo_t *info, struct k_sigaction *ka,
Harvey Harrisonac66f3f2008-02-08 12:09:58 -0800528 sigset_t *oldset, struct pt_regs *regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529{
Roland McGrath7c1def12005-06-23 00:08:21 -0700530 int ret;
531
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532 /* Are we from a system call? */
Hiroshi Shimamotobb579252008-09-05 16:26:55 -0700533 if (syscall_get_nr(current, regs) >= 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700534 /* If so, check system call restarting.. */
Hiroshi Shimamotobb579252008-09-05 16:26:55 -0700535 switch (syscall_get_error(current, regs)) {
Harvey Harrisonac66f3f2008-02-08 12:09:58 -0800536 case -ERESTART_RESTARTBLOCK:
537 case -ERESTARTNOHAND:
538 regs->ax = -EINTR;
539 break;
540
541 case -ERESTARTSYS:
542 if (!(ka->sa.sa_flags & SA_RESTART)) {
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100543 regs->ax = -EINTR;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544 break;
Harvey Harrisonac66f3f2008-02-08 12:09:58 -0800545 }
546 /* fallthrough */
547 case -ERESTARTNOINTR:
548 regs->ax = regs->orig_ax;
549 regs->ip -= 2;
550 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551 }
552 }
553
554 /*
Roland McGrathe1f28772008-01-30 13:30:50 +0100555 * If TF is set due to a debugger (TIF_FORCED_TF), clear the TF
556 * flag so that register information in the sigcontext is correct.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557 */
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100558 if (unlikely(regs->flags & X86_EFLAGS_TF) &&
Roland McGrathe1f28772008-01-30 13:30:50 +0100559 likely(test_and_clear_thread_flag(TIF_FORCED_TF)))
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100560 regs->flags &= ~X86_EFLAGS_TF;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700561
Hiroshi Shimamoto1d130242008-09-05 16:28:06 -0700562 ret = setup_rt_frame(sig, ka, info, oldset, regs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700563
Ingo Molnar7e907f42008-03-06 10:33:08 +0100564 if (ret)
565 return ret;
Roland McGrath7c1def12005-06-23 00:08:21 -0700566
Hiroshi Shimamoto86d32372008-09-23 17:22:32 -0700567#ifdef CONFIG_X86_64
568 /*
569 * This has nothing to do with segment registers,
570 * despite the name. This magic affects uaccess.h
571 * macros' behavior. Reset it to the normal setting.
572 */
573 set_fs(USER_DS);
574#endif
575
Roland McGrath8b9c5ff2008-04-19 14:26:54 -0700576 /*
577 * Clear the direction flag as per the ABI for function entry.
578 */
579 regs->flags &= ~X86_EFLAGS_DF;
580
581 /*
582 * Clear TF when entering the signal handler, but
583 * notify any tracer that was single-stepping it.
584 * The tracer may want to single-step inside the
585 * handler too.
586 */
587 regs->flags &= ~X86_EFLAGS_TF;
Roland McGrath8b9c5ff2008-04-19 14:26:54 -0700588
Ingo Molnar7e907f42008-03-06 10:33:08 +0100589 spin_lock_irq(&current->sighand->siglock);
590 sigorsets(&current->blocked, &current->blocked, &ka->sa.sa_mask);
591 if (!(ka->sa.sa_flags & SA_NODEFER))
592 sigaddset(&current->blocked, sig);
593 recalc_sigpending();
594 spin_unlock_irq(&current->sighand->siglock);
595
Roland McGrath36a03302008-03-14 17:46:38 -0700596 tracehook_signal_handler(sig, info, ka, regs,
597 test_thread_flag(TIF_SINGLESTEP));
598
Ingo Molnar7e907f42008-03-06 10:33:08 +0100599 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600}
601
Hiroshi Shimamoto8fcd8e22008-09-05 16:27:39 -0700602#define NR_restart_syscall __NR_restart_syscall
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603/*
604 * Note that 'init' is a special process: it doesn't get signals it doesn't
605 * want to handle. Thus you cannot kill init even with a SIGKILL even by
606 * mistake.
607 */
Harvey Harrison75604d72008-01-30 13:31:17 +0100608static void do_signal(struct pt_regs *regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609{
Harvey Harrisonac66f3f2008-02-08 12:09:58 -0800610 struct k_sigaction ka;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700611 siginfo_t info;
612 int signr;
David Howells283828f2006-01-18 17:44:00 -0800613 sigset_t *oldset;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700614
615 /*
Harvey Harrisonac66f3f2008-02-08 12:09:58 -0800616 * We want the common case to go fast, which is why we may in certain
617 * cases get here from kernel mode. Just return without doing anything
618 * if so.
619 * X86_32: vm86 regs switched out by assembly code before reaching
620 * here, so testing against kernel CS suffices.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700621 */
Vincent Hanquez717b5942005-06-23 00:08:45 -0700622 if (!user_mode(regs))
David Howells283828f2006-01-18 17:44:00 -0800623 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700624
Roland McGrath5a8da0e2008-04-30 00:53:10 -0700625 if (current_thread_info()->status & TS_RESTORE_SIGMASK)
David Howells283828f2006-01-18 17:44:00 -0800626 oldset = &current->saved_sigmask;
627 else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700628 oldset = &current->blocked;
629
630 signr = get_signal_to_deliver(&info, &ka, regs, NULL);
631 if (signr > 0) {
Ingo Molnar7e907f42008-03-06 10:33:08 +0100632 /*
633 * Re-enable any watchpoints before delivering the
Linus Torvalds1da177e2005-04-16 15:20:36 -0700634 * signal to user space. The processor register will
635 * have been cleared if the watchpoint triggered
636 * inside the kernel.
637 */
Harvey Harrisonac66f3f2008-02-08 12:09:58 -0800638 if (current->thread.debugreg7)
Roland McGrath0f534092008-01-30 13:30:59 +0100639 set_debugreg(current->thread.debugreg7, 7);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700640
Ingo Molnar7e907f42008-03-06 10:33:08 +0100641 /* Whee! Actually deliver the signal. */
David Howells283828f2006-01-18 17:44:00 -0800642 if (handle_signal(signr, &info, &ka, oldset, regs) == 0) {
Ingo Molnar7e907f42008-03-06 10:33:08 +0100643 /*
Roland McGrath5a8da0e2008-04-30 00:53:10 -0700644 * A signal was successfully delivered; the saved
David Howells283828f2006-01-18 17:44:00 -0800645 * sigmask will have been stored in the signal frame,
646 * and will be restored by sigreturn, so we can simply
Roland McGrath5a8da0e2008-04-30 00:53:10 -0700647 * clear the TS_RESTORE_SIGMASK flag.
Ingo Molnar7e907f42008-03-06 10:33:08 +0100648 */
Roland McGrath5a8da0e2008-04-30 00:53:10 -0700649 current_thread_info()->status &= ~TS_RESTORE_SIGMASK;
David Howells283828f2006-01-18 17:44:00 -0800650 }
David Howells283828f2006-01-18 17:44:00 -0800651 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700652 }
653
Linus Torvalds1da177e2005-04-16 15:20:36 -0700654 /* Did we come from a system call? */
Hiroshi Shimamotobb579252008-09-05 16:26:55 -0700655 if (syscall_get_nr(current, regs) >= 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700656 /* Restart the system call - no handlers present */
Hiroshi Shimamotobb579252008-09-05 16:26:55 -0700657 switch (syscall_get_error(current, regs)) {
David Howells283828f2006-01-18 17:44:00 -0800658 case -ERESTARTNOHAND:
659 case -ERESTARTSYS:
660 case -ERESTARTNOINTR:
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100661 regs->ax = regs->orig_ax;
662 regs->ip -= 2;
David Howells283828f2006-01-18 17:44:00 -0800663 break;
664
665 case -ERESTART_RESTARTBLOCK:
Hiroshi Shimamoto8fcd8e22008-09-05 16:27:39 -0700666 regs->ax = NR_restart_syscall;
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100667 regs->ip -= 2;
David Howells283828f2006-01-18 17:44:00 -0800668 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700669 }
670 }
David Howells283828f2006-01-18 17:44:00 -0800671
Harvey Harrisonac66f3f2008-02-08 12:09:58 -0800672 /*
673 * If there's no signal to deliver, we just put the saved sigmask
674 * back.
675 */
Roland McGrath5a8da0e2008-04-30 00:53:10 -0700676 if (current_thread_info()->status & TS_RESTORE_SIGMASK) {
677 current_thread_info()->status &= ~TS_RESTORE_SIGMASK;
David Howells283828f2006-01-18 17:44:00 -0800678 sigprocmask(SIG_SETMASK, &current->saved_sigmask, NULL);
679 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700680}
681
682/*
683 * notification of userspace execution resumption
David Howells283828f2006-01-18 17:44:00 -0800684 * - triggered by the TIF_WORK_MASK flags
Linus Torvalds1da177e2005-04-16 15:20:36 -0700685 */
Ingo Molnar7e907f42008-03-06 10:33:08 +0100686void
687do_notify_resume(struct pt_regs *regs, void *unused, __u32 thread_info_flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700688{
Hiroshi Shimamotoee847c52008-09-23 17:21:45 -0700689#if defined(CONFIG_X86_64) && defined(CONFIG_X86_MCE)
690 /* notify userspace of pending MCEs */
691 if (thread_info_flags & _TIF_MCE_NOTIFY)
692 mce_notify_user();
693#endif /* CONFIG_X86_64 && CONFIG_X86_MCE */
694
Linus Torvalds1da177e2005-04-16 15:20:36 -0700695 /* deal with pending signal delivery */
Roland McGrath5a8da0e2008-04-30 00:53:10 -0700696 if (thread_info_flags & _TIF_SIGPENDING)
David Howells283828f2006-01-18 17:44:00 -0800697 do_signal(regs);
Peter Zijlstra8f4d37e2008-01-25 21:08:29 +0100698
Roland McGrath59e52132008-04-19 19:10:57 -0700699 if (thread_info_flags & _TIF_NOTIFY_RESUME) {
700 clear_thread_flag(TIF_NOTIFY_RESUME);
701 tracehook_notify_resume(regs);
702 }
703
Hiroshi Shimamotoee847c52008-09-23 17:21:45 -0700704#ifdef CONFIG_X86_32
Linus Torvalds1da177e2005-04-16 15:20:36 -0700705 clear_thread_flag(TIF_IRET);
Hiroshi Shimamotoee847c52008-09-23 17:21:45 -0700706#endif /* CONFIG_X86_32 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700707}
Hiroshi Shimamoto72fa50f2008-09-05 16:27:11 -0700708
709void signal_fault(struct pt_regs *regs, void __user *frame, char *where)
710{
711 struct task_struct *me = current;
712
713 if (show_unhandled_signals && printk_ratelimit()) {
714 printk(KERN_INFO
715 "%s[%d] bad frame in %s frame:%p ip:%lx sp:%lx orax:%lx",
716 me->comm, me->pid, where, frame,
717 regs->ip, regs->sp, regs->orig_ax);
718 print_vma_addr(" in ", regs->ip);
719 printk(KERN_CONT "\n");
720 }
721
722 force_sig(SIGSEGV, me);
723}