aboutsummaryrefslogtreecommitdiffstats
path: root/arch/xtensa/kernel/signal.c
diff options
context:
space:
mode:
Diffstat (limited to 'arch/xtensa/kernel/signal.c')
-rw-r--r--arch/xtensa/kernel/signal.c89
1 files changed, 55 insertions, 34 deletions
diff --git a/arch/xtensa/kernel/signal.c b/arch/xtensa/kernel/signal.c
index 033aae0336d2..f2220b5bdce6 100644
--- a/arch/xtensa/kernel/signal.c
+++ b/arch/xtensa/kernel/signal.c
@@ -35,13 +35,17 @@ asmlinkage int do_signal(struct pt_regs *regs, sigset_t *oldset);
35 35
36extern struct task_struct *coproc_owners[]; 36extern struct task_struct *coproc_owners[];
37 37
38extern void release_all_cp (struct task_struct *);
39
40struct rt_sigframe 38struct rt_sigframe
41{ 39{
42 struct siginfo info; 40 struct siginfo info;
43 struct ucontext uc; 41 struct ucontext uc;
44 cp_state_t cpstate; 42 struct {
43 xtregs_opt_t opt;
44 xtregs_user_t user;
45#if XTENSA_HAVE_COPROCESSORS
46 xtregs_coprocessor_t cp;
47#endif
48 } xtregs;
45 unsigned char retcode[6]; 49 unsigned char retcode[6];
46 unsigned int window[4]; 50 unsigned int window[4];
47}; 51};
@@ -49,8 +53,6 @@ struct rt_sigframe
49/* 53/*
50 * Flush register windows stored in pt_regs to stack. 54 * Flush register windows stored in pt_regs to stack.
51 * Returns 1 for errors. 55 * Returns 1 for errors.
52 *
53 * Note that windowbase, windowstart, and wmask are not updated!
54 */ 56 */
55 57
56int 58int
@@ -116,6 +118,9 @@ flush_window_regs_user(struct pt_regs *regs)
116 base += inc; 118 base += inc;
117 } 119 }
118 120
121 regs->wmask = 1;
122 regs->windowstart = 1 << wb;
123
119 return 0; 124 return 0;
120 125
121errout: 126errout:
@@ -131,9 +136,10 @@ errout:
131 */ 136 */
132 137
133static int 138static int
134setup_sigcontext(struct sigcontext __user *sc, cp_state_t *cpstate, 139setup_sigcontext(struct rt_sigframe __user *frame, struct pt_regs *regs)
135 struct pt_regs *regs, unsigned long mask)
136{ 140{
141 struct sigcontext __user *sc = &frame->uc.uc_mcontext;
142 struct thread_info *ti = current_thread_info();
137 int err = 0; 143 int err = 0;
138 144
139#define COPY(x) err |= __put_user(regs->x, &sc->sc_##x) 145#define COPY(x) err |= __put_user(regs->x, &sc->sc_##x)
@@ -147,23 +153,32 @@ setup_sigcontext(struct sigcontext __user *sc, cp_state_t *cpstate,
147 153
148 err |= flush_window_regs_user(regs); 154 err |= flush_window_regs_user(regs);
149 err |= __copy_to_user (sc->sc_a, regs->areg, 16 * 4); 155 err |= __copy_to_user (sc->sc_a, regs->areg, 16 * 4);
156 err |= __put_user(0, &sc->sc_xtregs);
150 157
151 // err |= __copy_to_user (sc->sc_a, regs->areg, XCHAL_NUM_AREGS * 4) 158 if (err)
159 return err;
152 160
153#if XCHAL_HAVE_CP 161#if XTENSA_HAVE_COPROCESSORS
154# error Coprocessors unsupported 162 coprocessor_flush_all(ti);
155 err |= save_cpextra(cpstate); 163 coprocessor_release_all(ti);
156 err |= __put_user(err ? NULL : cpstate, &sc->sc_cpstate); 164 err |= __copy_to_user(&frame->xtregs.cp, &ti->xtregs_cp,
165 sizeof (frame->xtregs.cp));
157#endif 166#endif
158 /* non-iBCS2 extensions.. */ 167 err |= __copy_to_user(&frame->xtregs.opt, &regs->xtregs_opt,
159 err |= __put_user(mask, &sc->oldmask); 168 sizeof (xtregs_opt_t));
169 err |= __copy_to_user(&frame->xtregs.user, &ti->xtregs_user,
170 sizeof (xtregs_user_t));
171
172 err |= __put_user(err ? NULL : &frame->xtregs, &sc->sc_xtregs);
160 173
161 return err; 174 return err;
162} 175}
163 176
164static int 177static int
165restore_sigcontext(struct pt_regs *regs, struct sigcontext __user *sc) 178restore_sigcontext(struct pt_regs *regs, struct rt_sigframe __user *frame)
166{ 179{
180 struct sigcontext __user *sc = &frame->uc.uc_mcontext;
181 struct thread_info *ti = current_thread_info();
167 unsigned int err = 0; 182 unsigned int err = 0;
168 unsigned long ps; 183 unsigned long ps;
169 184
@@ -181,6 +196,8 @@ restore_sigcontext(struct pt_regs *regs, struct sigcontext __user *sc)
181 regs->windowbase = 0; 196 regs->windowbase = 0;
182 regs->windowstart = 1; 197 regs->windowstart = 1;
183 198
199 regs->syscall = -1; /* disable syscall checks */
200
184 /* For PS, restore only PS.CALLINC. 201 /* For PS, restore only PS.CALLINC.
185 * Assume that all other bits are either the same as for the signal 202 * Assume that all other bits are either the same as for the signal
186 * handler, or the user mode value doesn't matter (e.g. PS.OWB). 203 * handler, or the user mode value doesn't matter (e.g. PS.OWB).
@@ -196,8 +213,9 @@ restore_sigcontext(struct pt_regs *regs, struct sigcontext __user *sc)
196 213
197 err |= __copy_from_user(regs->areg, sc->sc_a, 16 * 4); 214 err |= __copy_from_user(regs->areg, sc->sc_a, 16 * 4);
198 215
199#if XCHAL_HAVE_CP 216 if (err)
200# error Coprocessors unsupported 217 return err;
218
201 /* The signal handler may have used coprocessors in which 219 /* The signal handler may have used coprocessors in which
202 * case they are still enabled. We disable them to force a 220 * case they are still enabled. We disable them to force a
203 * reloading of the original task's CP state by the lazy 221 * reloading of the original task's CP state by the lazy
@@ -205,20 +223,20 @@ restore_sigcontext(struct pt_regs *regs, struct sigcontext __user *sc)
205 * Also, we essentially discard any coprocessor state that the 223 * Also, we essentially discard any coprocessor state that the
206 * signal handler created. */ 224 * signal handler created. */
207 225
208 if (!err) { 226#if XTENSA_HAVE_COPROCESSORS
209 struct task_struct *tsk = current; 227 coprocessor_release_all(ti);
210 release_all_cp(tsk); 228 err |= __copy_from_user(&ti->xtregs_cp, &frame->xtregs.cp,
211 err |= __copy_from_user(tsk->thread.cpextra, sc->sc_cpstate, 229 sizeof (frame->xtregs.cp));
212 XTENSA_CP_EXTRA_SIZE);
213 }
214#endif 230#endif
231 err |= __copy_from_user(&ti->xtregs_user, &frame->xtregs.user,
232 sizeof (xtregs_user_t));
233 err |= __copy_from_user(&regs->xtregs_opt, &frame->xtregs.opt,
234 sizeof (xtregs_opt_t));
215 235
216 regs->syscall = -1; /* disable syscall checks */
217 return err; 236 return err;
218} 237}
219 238
220 239
221
222/* 240/*
223 * Do a signal return; undo the signal stack. 241 * Do a signal return; undo the signal stack.
224 */ 242 */
@@ -247,7 +265,7 @@ asmlinkage long xtensa_rt_sigreturn(long a0, long a1, long a2, long a3,
247 recalc_sigpending(); 265 recalc_sigpending();
248 spin_unlock_irq(&current->sighand->siglock); 266 spin_unlock_irq(&current->sighand->siglock);
249 267
250 if (restore_sigcontext(regs, &frame->uc.uc_mcontext)) 268 if (restore_sigcontext(regs, frame))
251 goto badframe; 269 goto badframe;
252 270
253 ret = regs->areg[2]; 271 ret = regs->areg[2];
@@ -360,18 +378,22 @@ static void setup_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
360 err |= __put_user(sas_ss_flags(regs->areg[1]), 378 err |= __put_user(sas_ss_flags(regs->areg[1]),
361 &frame->uc.uc_stack.ss_flags); 379 &frame->uc.uc_stack.ss_flags);
362 err |= __put_user(current->sas_ss_size, &frame->uc.uc_stack.ss_size); 380 err |= __put_user(current->sas_ss_size, &frame->uc.uc_stack.ss_size);
363 err |= setup_sigcontext(&frame->uc.uc_mcontext, &frame->cpstate, 381 err |= setup_sigcontext(frame, regs);
364 regs, set->sig[0]);
365 err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set)); 382 err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set));
366 383
367 /* Create sys_rt_sigreturn syscall in stack frame */ 384 if (ka->sa.sa_flags & SA_RESTORER) {
385 ra = (unsigned long)ka->sa.sa_restorer;
386 } else {
368 387
369 err |= gen_return_code(frame->retcode); 388 /* Create sys_rt_sigreturn syscall in stack frame */
370 389
371 if (err) { 390 err |= gen_return_code(frame->retcode);
372 goto give_sigsegv; 391
392 if (err) {
393 goto give_sigsegv;
394 }
395 ra = (unsigned long) frame->retcode;
373 } 396 }
374
375 397
376 /* 398 /*
377 * Create signal handler execution context. 399 * Create signal handler execution context.
@@ -385,7 +407,6 @@ static void setup_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
385 /* Set up a stack frame for a call4 407 /* Set up a stack frame for a call4
386 * Note: PS.CALLINC is set to one by start_thread 408 * Note: PS.CALLINC is set to one by start_thread
387 */ 409 */
388 ra = (unsigned long) frame->retcode;
389 regs->areg[4] = (((unsigned long) ra) & 0x3fffffff) | 0x40000000; 410 regs->areg[4] = (((unsigned long) ra) & 0x3fffffff) | 0x40000000;
390 regs->areg[6] = (unsigned long) signal; 411 regs->areg[6] = (unsigned long) signal;
391 regs->areg[7] = (unsigned long) &frame->info; 412 regs->areg[7] = (unsigned long) &frame->info;