diff options
Diffstat (limited to 'arch/sparc64/kernel/signal32.c')
-rw-r--r-- | arch/sparc64/kernel/signal32.c | 1469 |
1 files changed, 1469 insertions, 0 deletions
diff --git a/arch/sparc64/kernel/signal32.c b/arch/sparc64/kernel/signal32.c new file mode 100644 index 000000000000..859255cf6762 --- /dev/null +++ b/arch/sparc64/kernel/signal32.c | |||
@@ -0,0 +1,1469 @@ | |||
1 | /* $Id: signal32.c,v 1.74 2002/02/09 19:49:30 davem Exp $ | ||
2 | * arch/sparc64/kernel/signal32.c | ||
3 | * | ||
4 | * Copyright (C) 1991, 1992 Linus Torvalds | ||
5 | * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu) | ||
6 | * Copyright (C) 1996 Miguel de Icaza (miguel@nuclecu.unam.mx) | ||
7 | * Copyright (C) 1997 Eddie C. Dost (ecd@skynet.be) | ||
8 | * Copyright (C) 1997,1998 Jakub Jelinek (jj@sunsite.mff.cuni.cz) | ||
9 | */ | ||
10 | |||
11 | #include <linux/sched.h> | ||
12 | #include <linux/kernel.h> | ||
13 | #include <linux/signal.h> | ||
14 | #include <linux/errno.h> | ||
15 | #include <linux/wait.h> | ||
16 | #include <linux/ptrace.h> | ||
17 | #include <linux/unistd.h> | ||
18 | #include <linux/mm.h> | ||
19 | #include <linux/tty.h> | ||
20 | #include <linux/smp_lock.h> | ||
21 | #include <linux/binfmts.h> | ||
22 | #include <linux/compat.h> | ||
23 | #include <linux/bitops.h> | ||
24 | |||
25 | #include <asm/uaccess.h> | ||
26 | #include <asm/ptrace.h> | ||
27 | #include <asm/svr4.h> | ||
28 | #include <asm/pgtable.h> | ||
29 | #include <asm/psrcompat.h> | ||
30 | #include <asm/fpumacro.h> | ||
31 | #include <asm/visasm.h> | ||
32 | |||
33 | #define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP))) | ||
34 | |||
35 | int do_signal32(sigset_t *oldset, struct pt_regs *regs, | ||
36 | unsigned long orig_o0, int ret_from_syscall); | ||
37 | |||
38 | /* Signal frames: the original one (compatible with SunOS): | ||
39 | * | ||
40 | * Set up a signal frame... Make the stack look the way SunOS | ||
41 | * expects it to look which is basically: | ||
42 | * | ||
43 | * ---------------------------------- <-- %sp at signal time | ||
44 | * Struct sigcontext | ||
45 | * Signal address | ||
46 | * Ptr to sigcontext area above | ||
47 | * Signal code | ||
48 | * The signal number itself | ||
49 | * One register window | ||
50 | * ---------------------------------- <-- New %sp | ||
51 | */ | ||
52 | struct signal_sframe32 { | ||
53 | struct reg_window32 sig_window; | ||
54 | int sig_num; | ||
55 | int sig_code; | ||
56 | /* struct sigcontext32 * */ u32 sig_scptr; | ||
57 | int sig_address; | ||
58 | struct sigcontext32 sig_context; | ||
59 | unsigned int extramask[_COMPAT_NSIG_WORDS - 1]; | ||
60 | }; | ||
61 | |||
62 | /* This magic should be in g_upper[0] for all upper parts | ||
63 | * to be valid. | ||
64 | */ | ||
65 | #define SIGINFO_EXTRA_V8PLUS_MAGIC 0x130e269 | ||
66 | typedef struct { | ||
67 | unsigned int g_upper[8]; | ||
68 | unsigned int o_upper[8]; | ||
69 | unsigned int asi; | ||
70 | } siginfo_extra_v8plus_t; | ||
71 | |||
72 | /* | ||
73 | * And the new one, intended to be used for Linux applications only | ||
74 | * (we have enough in there to work with clone). | ||
75 | * All the interesting bits are in the info field. | ||
76 | */ | ||
77 | struct new_signal_frame32 { | ||
78 | struct sparc_stackf32 ss; | ||
79 | __siginfo32_t info; | ||
80 | /* __siginfo_fpu32_t * */ u32 fpu_save; | ||
81 | unsigned int insns[2]; | ||
82 | unsigned int extramask[_COMPAT_NSIG_WORDS - 1]; | ||
83 | unsigned int extra_size; /* Should be sizeof(siginfo_extra_v8plus_t) */ | ||
84 | /* Only valid if (info.si_regs.psr & (PSR_VERS|PSR_IMPL)) == PSR_V8PLUS */ | ||
85 | siginfo_extra_v8plus_t v8plus; | ||
86 | __siginfo_fpu_t fpu_state; | ||
87 | }; | ||
88 | |||
89 | typedef struct compat_siginfo{ | ||
90 | int si_signo; | ||
91 | int si_errno; | ||
92 | int si_code; | ||
93 | |||
94 | union { | ||
95 | int _pad[SI_PAD_SIZE32]; | ||
96 | |||
97 | /* kill() */ | ||
98 | struct { | ||
99 | compat_pid_t _pid; /* sender's pid */ | ||
100 | unsigned int _uid; /* sender's uid */ | ||
101 | } _kill; | ||
102 | |||
103 | /* POSIX.1b timers */ | ||
104 | struct { | ||
105 | timer_t _tid; /* timer id */ | ||
106 | int _overrun; /* overrun count */ | ||
107 | compat_sigval_t _sigval; /* same as below */ | ||
108 | int _sys_private; /* not to be passed to user */ | ||
109 | } _timer; | ||
110 | |||
111 | /* POSIX.1b signals */ | ||
112 | struct { | ||
113 | compat_pid_t _pid; /* sender's pid */ | ||
114 | unsigned int _uid; /* sender's uid */ | ||
115 | compat_sigval_t _sigval; | ||
116 | } _rt; | ||
117 | |||
118 | /* SIGCHLD */ | ||
119 | struct { | ||
120 | compat_pid_t _pid; /* which child */ | ||
121 | unsigned int _uid; /* sender's uid */ | ||
122 | int _status; /* exit code */ | ||
123 | compat_clock_t _utime; | ||
124 | compat_clock_t _stime; | ||
125 | } _sigchld; | ||
126 | |||
127 | /* SIGILL, SIGFPE, SIGSEGV, SIGBUS, SIGEMT */ | ||
128 | struct { | ||
129 | u32 _addr; /* faulting insn/memory ref. */ | ||
130 | int _trapno; | ||
131 | } _sigfault; | ||
132 | |||
133 | /* SIGPOLL */ | ||
134 | struct { | ||
135 | int _band; /* POLL_IN, POLL_OUT, POLL_MSG */ | ||
136 | int _fd; | ||
137 | } _sigpoll; | ||
138 | } _sifields; | ||
139 | }compat_siginfo_t; | ||
140 | |||
141 | struct rt_signal_frame32 { | ||
142 | struct sparc_stackf32 ss; | ||
143 | compat_siginfo_t info; | ||
144 | struct pt_regs32 regs; | ||
145 | compat_sigset_t mask; | ||
146 | /* __siginfo_fpu32_t * */ u32 fpu_save; | ||
147 | unsigned int insns[2]; | ||
148 | stack_t32 stack; | ||
149 | unsigned int extra_size; /* Should be sizeof(siginfo_extra_v8plus_t) */ | ||
150 | /* Only valid if (regs.psr & (PSR_VERS|PSR_IMPL)) == PSR_V8PLUS */ | ||
151 | siginfo_extra_v8plus_t v8plus; | ||
152 | __siginfo_fpu_t fpu_state; | ||
153 | }; | ||
154 | |||
155 | /* Align macros */ | ||
156 | #define SF_ALIGNEDSZ (((sizeof(struct signal_sframe32) + 7) & (~7))) | ||
157 | #define NF_ALIGNEDSZ (((sizeof(struct new_signal_frame32) + 7) & (~7))) | ||
158 | #define RT_ALIGNEDSZ (((sizeof(struct rt_signal_frame32) + 7) & (~7))) | ||
159 | |||
160 | int copy_siginfo_to_user32(compat_siginfo_t __user *to, siginfo_t *from) | ||
161 | { | ||
162 | int err; | ||
163 | |||
164 | if (!access_ok(VERIFY_WRITE, to, sizeof(compat_siginfo_t))) | ||
165 | return -EFAULT; | ||
166 | |||
167 | /* If you change siginfo_t structure, please be sure | ||
168 | this code is fixed accordingly. | ||
169 | It should never copy any pad contained in the structure | ||
170 | to avoid security leaks, but must copy the generic | ||
171 | 3 ints plus the relevant union member. | ||
172 | This routine must convert siginfo from 64bit to 32bit as well | ||
173 | at the same time. */ | ||
174 | err = __put_user(from->si_signo, &to->si_signo); | ||
175 | err |= __put_user(from->si_errno, &to->si_errno); | ||
176 | err |= __put_user((short)from->si_code, &to->si_code); | ||
177 | if (from->si_code < 0) | ||
178 | err |= __copy_to_user(&to->_sifields._pad, &from->_sifields._pad, SI_PAD_SIZE); | ||
179 | else { | ||
180 | switch (from->si_code >> 16) { | ||
181 | case __SI_TIMER >> 16: | ||
182 | err |= __put_user(from->si_tid, &to->si_tid); | ||
183 | err |= __put_user(from->si_overrun, &to->si_overrun); | ||
184 | err |= __put_user(from->si_int, &to->si_int); | ||
185 | break; | ||
186 | case __SI_CHLD >> 16: | ||
187 | err |= __put_user(from->si_utime, &to->si_utime); | ||
188 | err |= __put_user(from->si_stime, &to->si_stime); | ||
189 | err |= __put_user(from->si_status, &to->si_status); | ||
190 | default: | ||
191 | err |= __put_user(from->si_pid, &to->si_pid); | ||
192 | err |= __put_user(from->si_uid, &to->si_uid); | ||
193 | break; | ||
194 | case __SI_FAULT >> 16: | ||
195 | case __SI_POLL >> 16: | ||
196 | err |= __put_user(from->si_trapno, &to->si_trapno); | ||
197 | err |= __put_user((unsigned long)from->si_addr, &to->si_addr); | ||
198 | break; | ||
199 | case __SI_RT >> 16: /* This is not generated by the kernel as of now. */ | ||
200 | case __SI_MESGQ >> 16: | ||
201 | err |= __put_user(from->si_pid, &to->si_pid); | ||
202 | err |= __put_user(from->si_uid, &to->si_uid); | ||
203 | err |= __put_user(from->si_int, &to->si_int); | ||
204 | break; | ||
205 | } | ||
206 | } | ||
207 | return err; | ||
208 | } | ||
209 | |||
210 | /* CAUTION: This is just a very minimalist implementation for the | ||
211 | * sake of compat_sys_rt_sigqueueinfo() | ||
212 | */ | ||
213 | int copy_siginfo_from_user32(siginfo_t *to, compat_siginfo_t __user *from) | ||
214 | { | ||
215 | if (!access_ok(VERIFY_WRITE, from, sizeof(compat_siginfo_t))) | ||
216 | return -EFAULT; | ||
217 | |||
218 | if (copy_from_user(to, from, 3*sizeof(int)) || | ||
219 | copy_from_user(to->_sifields._pad, from->_sifields._pad, | ||
220 | SI_PAD_SIZE)) | ||
221 | return -EFAULT; | ||
222 | |||
223 | return 0; | ||
224 | } | ||
225 | |||
226 | /* | ||
227 | * atomically swap in the new signal mask, and wait for a signal. | ||
228 | * This is really tricky on the Sparc, watch out... | ||
229 | */ | ||
230 | asmlinkage void _sigpause32_common(compat_old_sigset_t set, struct pt_regs *regs) | ||
231 | { | ||
232 | sigset_t saveset; | ||
233 | |||
234 | set &= _BLOCKABLE; | ||
235 | spin_lock_irq(¤t->sighand->siglock); | ||
236 | saveset = current->blocked; | ||
237 | siginitset(¤t->blocked, set); | ||
238 | recalc_sigpending(); | ||
239 | spin_unlock_irq(¤t->sighand->siglock); | ||
240 | |||
241 | regs->tpc = regs->tnpc; | ||
242 | regs->tnpc += 4; | ||
243 | if (test_thread_flag(TIF_32BIT)) { | ||
244 | regs->tpc &= 0xffffffff; | ||
245 | regs->tnpc &= 0xffffffff; | ||
246 | } | ||
247 | |||
248 | /* Condition codes and return value where set here for sigpause, | ||
249 | * and so got used by setup_frame, which again causes sigreturn() | ||
250 | * to return -EINTR. | ||
251 | */ | ||
252 | while (1) { | ||
253 | current->state = TASK_INTERRUPTIBLE; | ||
254 | schedule(); | ||
255 | /* | ||
256 | * Return -EINTR and set condition code here, | ||
257 | * so the interrupted system call actually returns | ||
258 | * these. | ||
259 | */ | ||
260 | regs->tstate |= TSTATE_ICARRY; | ||
261 | regs->u_regs[UREG_I0] = EINTR; | ||
262 | if (do_signal32(&saveset, regs, 0, 0)) | ||
263 | return; | ||
264 | } | ||
265 | } | ||
266 | |||
267 | asmlinkage void do_rt_sigsuspend32(u32 uset, size_t sigsetsize, struct pt_regs *regs) | ||
268 | { | ||
269 | sigset_t oldset, set; | ||
270 | compat_sigset_t set32; | ||
271 | |||
272 | /* XXX: Don't preclude handling different sized sigset_t's. */ | ||
273 | if (((compat_size_t)sigsetsize) != sizeof(sigset_t)) { | ||
274 | regs->tstate |= TSTATE_ICARRY; | ||
275 | regs->u_regs[UREG_I0] = EINVAL; | ||
276 | return; | ||
277 | } | ||
278 | if (copy_from_user(&set32, compat_ptr(uset), sizeof(set32))) { | ||
279 | regs->tstate |= TSTATE_ICARRY; | ||
280 | regs->u_regs[UREG_I0] = EFAULT; | ||
281 | return; | ||
282 | } | ||
283 | switch (_NSIG_WORDS) { | ||
284 | case 4: set.sig[3] = set32.sig[6] + (((long)set32.sig[7]) << 32); | ||
285 | case 3: set.sig[2] = set32.sig[4] + (((long)set32.sig[5]) << 32); | ||
286 | case 2: set.sig[1] = set32.sig[2] + (((long)set32.sig[3]) << 32); | ||
287 | case 1: set.sig[0] = set32.sig[0] + (((long)set32.sig[1]) << 32); | ||
288 | } | ||
289 | sigdelsetmask(&set, ~_BLOCKABLE); | ||
290 | spin_lock_irq(¤t->sighand->siglock); | ||
291 | oldset = current->blocked; | ||
292 | current->blocked = set; | ||
293 | recalc_sigpending(); | ||
294 | spin_unlock_irq(¤t->sighand->siglock); | ||
295 | |||
296 | regs->tpc = regs->tnpc; | ||
297 | regs->tnpc += 4; | ||
298 | if (test_thread_flag(TIF_32BIT)) { | ||
299 | regs->tpc &= 0xffffffff; | ||
300 | regs->tnpc &= 0xffffffff; | ||
301 | } | ||
302 | |||
303 | /* Condition codes and return value where set here for sigpause, | ||
304 | * and so got used by setup_frame, which again causes sigreturn() | ||
305 | * to return -EINTR. | ||
306 | */ | ||
307 | while (1) { | ||
308 | current->state = TASK_INTERRUPTIBLE; | ||
309 | schedule(); | ||
310 | /* | ||
311 | * Return -EINTR and set condition code here, | ||
312 | * so the interrupted system call actually returns | ||
313 | * these. | ||
314 | */ | ||
315 | regs->tstate |= TSTATE_ICARRY; | ||
316 | regs->u_regs[UREG_I0] = EINTR; | ||
317 | if (do_signal32(&oldset, regs, 0, 0)) | ||
318 | return; | ||
319 | } | ||
320 | } | ||
321 | |||
322 | static int restore_fpu_state32(struct pt_regs *regs, __siginfo_fpu_t __user *fpu) | ||
323 | { | ||
324 | unsigned long *fpregs = current_thread_info()->fpregs; | ||
325 | unsigned long fprs; | ||
326 | int err; | ||
327 | |||
328 | err = __get_user(fprs, &fpu->si_fprs); | ||
329 | fprs_write(0); | ||
330 | regs->tstate &= ~TSTATE_PEF; | ||
331 | if (fprs & FPRS_DL) | ||
332 | err |= copy_from_user(fpregs, &fpu->si_float_regs[0], (sizeof(unsigned int) * 32)); | ||
333 | if (fprs & FPRS_DU) | ||
334 | err |= copy_from_user(fpregs+16, &fpu->si_float_regs[32], (sizeof(unsigned int) * 32)); | ||
335 | err |= __get_user(current_thread_info()->xfsr[0], &fpu->si_fsr); | ||
336 | err |= __get_user(current_thread_info()->gsr[0], &fpu->si_gsr); | ||
337 | current_thread_info()->fpsaved[0] |= fprs; | ||
338 | return err; | ||
339 | } | ||
340 | |||
341 | void do_new_sigreturn32(struct pt_regs *regs) | ||
342 | { | ||
343 | struct new_signal_frame32 __user *sf; | ||
344 | unsigned int psr; | ||
345 | unsigned pc, npc, fpu_save; | ||
346 | sigset_t set; | ||
347 | unsigned seta[_COMPAT_NSIG_WORDS]; | ||
348 | int err, i; | ||
349 | |||
350 | regs->u_regs[UREG_FP] &= 0x00000000ffffffffUL; | ||
351 | sf = (struct new_signal_frame32 __user *) regs->u_regs[UREG_FP]; | ||
352 | |||
353 | /* 1. Make sure we are not getting garbage from the user */ | ||
354 | if (!access_ok(VERIFY_READ, sf, sizeof(*sf)) || | ||
355 | (((unsigned long) sf) & 3)) | ||
356 | goto segv; | ||
357 | |||
358 | get_user(pc, &sf->info.si_regs.pc); | ||
359 | __get_user(npc, &sf->info.si_regs.npc); | ||
360 | |||
361 | if ((pc | npc) & 3) | ||
362 | goto segv; | ||
363 | |||
364 | if (test_thread_flag(TIF_32BIT)) { | ||
365 | pc &= 0xffffffff; | ||
366 | npc &= 0xffffffff; | ||
367 | } | ||
368 | regs->tpc = pc; | ||
369 | regs->tnpc = npc; | ||
370 | |||
371 | /* 2. Restore the state */ | ||
372 | err = __get_user(regs->y, &sf->info.si_regs.y); | ||
373 | err |= __get_user(psr, &sf->info.si_regs.psr); | ||
374 | |||
375 | for (i = UREG_G1; i <= UREG_I7; i++) | ||
376 | err |= __get_user(regs->u_regs[i], &sf->info.si_regs.u_regs[i]); | ||
377 | if ((psr & (PSR_VERS|PSR_IMPL)) == PSR_V8PLUS) { | ||
378 | err |= __get_user(i, &sf->v8plus.g_upper[0]); | ||
379 | if (i == SIGINFO_EXTRA_V8PLUS_MAGIC) { | ||
380 | unsigned long asi; | ||
381 | |||
382 | for (i = UREG_G1; i <= UREG_I7; i++) | ||
383 | err |= __get_user(((u32 *)regs->u_regs)[2*i], &sf->v8plus.g_upper[i]); | ||
384 | err |= __get_user(asi, &sf->v8plus.asi); | ||
385 | regs->tstate &= ~TSTATE_ASI; | ||
386 | regs->tstate |= ((asi & 0xffUL) << 24UL); | ||
387 | } | ||
388 | } | ||
389 | |||
390 | /* User can only change condition codes in %tstate. */ | ||
391 | regs->tstate &= ~(TSTATE_ICC|TSTATE_XCC); | ||
392 | regs->tstate |= psr_to_tstate_icc(psr); | ||
393 | |||
394 | err |= __get_user(fpu_save, &sf->fpu_save); | ||
395 | if (fpu_save) | ||
396 | err |= restore_fpu_state32(regs, &sf->fpu_state); | ||
397 | err |= __get_user(seta[0], &sf->info.si_mask); | ||
398 | err |= copy_from_user(seta+1, &sf->extramask, | ||
399 | (_COMPAT_NSIG_WORDS - 1) * sizeof(unsigned int)); | ||
400 | if (err) | ||
401 | goto segv; | ||
402 | switch (_NSIG_WORDS) { | ||
403 | case 4: set.sig[3] = seta[6] + (((long)seta[7]) << 32); | ||
404 | case 3: set.sig[2] = seta[4] + (((long)seta[5]) << 32); | ||
405 | case 2: set.sig[1] = seta[2] + (((long)seta[3]) << 32); | ||
406 | case 1: set.sig[0] = seta[0] + (((long)seta[1]) << 32); | ||
407 | } | ||
408 | sigdelsetmask(&set, ~_BLOCKABLE); | ||
409 | spin_lock_irq(¤t->sighand->siglock); | ||
410 | current->blocked = set; | ||
411 | recalc_sigpending(); | ||
412 | spin_unlock_irq(¤t->sighand->siglock); | ||
413 | return; | ||
414 | |||
415 | segv: | ||
416 | force_sig(SIGSEGV, current); | ||
417 | } | ||
418 | |||
419 | asmlinkage void do_sigreturn32(struct pt_regs *regs) | ||
420 | { | ||
421 | struct sigcontext32 __user *scptr; | ||
422 | unsigned int pc, npc, psr; | ||
423 | sigset_t set; | ||
424 | unsigned int seta[_COMPAT_NSIG_WORDS]; | ||
425 | int err; | ||
426 | |||
427 | /* Always make any pending restarted system calls return -EINTR */ | ||
428 | current_thread_info()->restart_block.fn = do_no_restart_syscall; | ||
429 | |||
430 | synchronize_user_stack(); | ||
431 | if (test_thread_flag(TIF_NEWSIGNALS)) { | ||
432 | do_new_sigreturn32(regs); | ||
433 | return; | ||
434 | } | ||
435 | |||
436 | scptr = (struct sigcontext32 __user *) | ||
437 | (regs->u_regs[UREG_I0] & 0x00000000ffffffffUL); | ||
438 | /* Check sanity of the user arg. */ | ||
439 | if (!access_ok(VERIFY_READ, scptr, sizeof(struct sigcontext32)) || | ||
440 | (((unsigned long) scptr) & 3)) | ||
441 | goto segv; | ||
442 | |||
443 | err = __get_user(pc, &scptr->sigc_pc); | ||
444 | err |= __get_user(npc, &scptr->sigc_npc); | ||
445 | |||
446 | if ((pc | npc) & 3) | ||
447 | goto segv; /* Nice try. */ | ||
448 | |||
449 | err |= __get_user(seta[0], &scptr->sigc_mask); | ||
450 | /* Note that scptr + 1 points to extramask */ | ||
451 | err |= copy_from_user(seta+1, scptr + 1, | ||
452 | (_COMPAT_NSIG_WORDS - 1) * sizeof(unsigned int)); | ||
453 | if (err) | ||
454 | goto segv; | ||
455 | switch (_NSIG_WORDS) { | ||
456 | case 4: set.sig[3] = seta[6] + (((long)seta[7]) << 32); | ||
457 | case 3: set.sig[2] = seta[4] + (((long)seta[5]) << 32); | ||
458 | case 2: set.sig[1] = seta[2] + (((long)seta[3]) << 32); | ||
459 | case 1: set.sig[0] = seta[0] + (((long)seta[1]) << 32); | ||
460 | } | ||
461 | sigdelsetmask(&set, ~_BLOCKABLE); | ||
462 | spin_lock_irq(¤t->sighand->siglock); | ||
463 | current->blocked = set; | ||
464 | recalc_sigpending(); | ||
465 | spin_unlock_irq(¤t->sighand->siglock); | ||
466 | |||
467 | if (test_thread_flag(TIF_32BIT)) { | ||
468 | pc &= 0xffffffff; | ||
469 | npc &= 0xffffffff; | ||
470 | } | ||
471 | regs->tpc = pc; | ||
472 | regs->tnpc = npc; | ||
473 | err = __get_user(regs->u_regs[UREG_FP], &scptr->sigc_sp); | ||
474 | err |= __get_user(regs->u_regs[UREG_I0], &scptr->sigc_o0); | ||
475 | err |= __get_user(regs->u_regs[UREG_G1], &scptr->sigc_g1); | ||
476 | |||
477 | /* User can only change condition codes in %tstate. */ | ||
478 | err |= __get_user(psr, &scptr->sigc_psr); | ||
479 | if (err) | ||
480 | goto segv; | ||
481 | regs->tstate &= ~(TSTATE_ICC|TSTATE_XCC); | ||
482 | regs->tstate |= psr_to_tstate_icc(psr); | ||
483 | return; | ||
484 | |||
485 | segv: | ||
486 | force_sig(SIGSEGV, current); | ||
487 | } | ||
488 | |||
489 | asmlinkage void do_rt_sigreturn32(struct pt_regs *regs) | ||
490 | { | ||
491 | struct rt_signal_frame32 __user *sf; | ||
492 | unsigned int psr, pc, npc, fpu_save, u_ss_sp; | ||
493 | mm_segment_t old_fs; | ||
494 | sigset_t set; | ||
495 | compat_sigset_t seta; | ||
496 | stack_t st; | ||
497 | int err, i; | ||
498 | |||
499 | /* Always make any pending restarted system calls return -EINTR */ | ||
500 | current_thread_info()->restart_block.fn = do_no_restart_syscall; | ||
501 | |||
502 | synchronize_user_stack(); | ||
503 | regs->u_regs[UREG_FP] &= 0x00000000ffffffffUL; | ||
504 | sf = (struct rt_signal_frame32 __user *) regs->u_regs[UREG_FP]; | ||
505 | |||
506 | /* 1. Make sure we are not getting garbage from the user */ | ||
507 | if (!access_ok(VERIFY_READ, sf, sizeof(*sf)) || | ||
508 | (((unsigned long) sf) & 3)) | ||
509 | goto segv; | ||
510 | |||
511 | get_user(pc, &sf->regs.pc); | ||
512 | __get_user(npc, &sf->regs.npc); | ||
513 | |||
514 | if ((pc | npc) & 3) | ||
515 | goto segv; | ||
516 | |||
517 | if (test_thread_flag(TIF_32BIT)) { | ||
518 | pc &= 0xffffffff; | ||
519 | npc &= 0xffffffff; | ||
520 | } | ||
521 | regs->tpc = pc; | ||
522 | regs->tnpc = npc; | ||
523 | |||
524 | /* 2. Restore the state */ | ||
525 | err = __get_user(regs->y, &sf->regs.y); | ||
526 | err |= __get_user(psr, &sf->regs.psr); | ||
527 | |||
528 | for (i = UREG_G1; i <= UREG_I7; i++) | ||
529 | err |= __get_user(regs->u_regs[i], &sf->regs.u_regs[i]); | ||
530 | if ((psr & (PSR_VERS|PSR_IMPL)) == PSR_V8PLUS) { | ||
531 | err |= __get_user(i, &sf->v8plus.g_upper[0]); | ||
532 | if (i == SIGINFO_EXTRA_V8PLUS_MAGIC) { | ||
533 | unsigned long asi; | ||
534 | |||
535 | for (i = UREG_G1; i <= UREG_I7; i++) | ||
536 | err |= __get_user(((u32 *)regs->u_regs)[2*i], &sf->v8plus.g_upper[i]); | ||
537 | err |= __get_user(asi, &sf->v8plus.asi); | ||
538 | regs->tstate &= ~TSTATE_ASI; | ||
539 | regs->tstate |= ((asi & 0xffUL) << 24UL); | ||
540 | } | ||
541 | } | ||
542 | |||
543 | /* User can only change condition codes in %tstate. */ | ||
544 | regs->tstate &= ~(TSTATE_ICC|TSTATE_XCC); | ||
545 | regs->tstate |= psr_to_tstate_icc(psr); | ||
546 | |||
547 | err |= __get_user(fpu_save, &sf->fpu_save); | ||
548 | if (fpu_save) | ||
549 | err |= restore_fpu_state32(regs, &sf->fpu_state); | ||
550 | err |= copy_from_user(&seta, &sf->mask, sizeof(compat_sigset_t)); | ||
551 | err |= __get_user(u_ss_sp, &sf->stack.ss_sp); | ||
552 | st.ss_sp = compat_ptr(u_ss_sp); | ||
553 | err |= __get_user(st.ss_flags, &sf->stack.ss_flags); | ||
554 | err |= __get_user(st.ss_size, &sf->stack.ss_size); | ||
555 | if (err) | ||
556 | goto segv; | ||
557 | |||
558 | /* It is more difficult to avoid calling this function than to | ||
559 | call it and ignore errors. */ | ||
560 | old_fs = get_fs(); | ||
561 | set_fs(KERNEL_DS); | ||
562 | do_sigaltstack((stack_t __user *) &st, NULL, (unsigned long)sf); | ||
563 | set_fs(old_fs); | ||
564 | |||
565 | switch (_NSIG_WORDS) { | ||
566 | case 4: set.sig[3] = seta.sig[6] + (((long)seta.sig[7]) << 32); | ||
567 | case 3: set.sig[2] = seta.sig[4] + (((long)seta.sig[5]) << 32); | ||
568 | case 2: set.sig[1] = seta.sig[2] + (((long)seta.sig[3]) << 32); | ||
569 | case 1: set.sig[0] = seta.sig[0] + (((long)seta.sig[1]) << 32); | ||
570 | } | ||
571 | sigdelsetmask(&set, ~_BLOCKABLE); | ||
572 | spin_lock_irq(¤t->sighand->siglock); | ||
573 | current->blocked = set; | ||
574 | recalc_sigpending(); | ||
575 | spin_unlock_irq(¤t->sighand->siglock); | ||
576 | return; | ||
577 | segv: | ||
578 | force_sig(SIGSEGV, current); | ||
579 | } | ||
580 | |||
581 | /* Checks if the fp is valid */ | ||
582 | static int invalid_frame_pointer(void __user *fp, int fplen) | ||
583 | { | ||
584 | if ((((unsigned long) fp) & 7) || ((unsigned long)fp) > 0x100000000ULL - fplen) | ||
585 | return 1; | ||
586 | return 0; | ||
587 | } | ||
588 | |||
589 | static void __user *get_sigframe(struct sigaction *sa, struct pt_regs *regs, unsigned long framesize) | ||
590 | { | ||
591 | unsigned long sp; | ||
592 | |||
593 | regs->u_regs[UREG_FP] &= 0x00000000ffffffffUL; | ||
594 | sp = regs->u_regs[UREG_FP]; | ||
595 | |||
596 | /* This is the X/Open sanctioned signal stack switching. */ | ||
597 | if (sa->sa_flags & SA_ONSTACK) { | ||
598 | if (!on_sig_stack(sp) && !((current->sas_ss_sp + current->sas_ss_size) & 7)) | ||
599 | sp = current->sas_ss_sp + current->sas_ss_size; | ||
600 | } | ||
601 | return (void __user *)(sp - framesize); | ||
602 | } | ||
603 | |||
604 | static void | ||
605 | setup_frame32(struct sigaction *sa, struct pt_regs *regs, int signr, sigset_t *oldset, siginfo_t *info) | ||
606 | { | ||
607 | struct signal_sframe32 __user *sframep; | ||
608 | struct sigcontext32 __user *sc; | ||
609 | unsigned int seta[_COMPAT_NSIG_WORDS]; | ||
610 | int err = 0; | ||
611 | void __user *sig_address; | ||
612 | int sig_code; | ||
613 | unsigned long pc = regs->tpc; | ||
614 | unsigned long npc = regs->tnpc; | ||
615 | unsigned int psr; | ||
616 | |||
617 | if (test_thread_flag(TIF_32BIT)) { | ||
618 | pc &= 0xffffffff; | ||
619 | npc &= 0xffffffff; | ||
620 | } | ||
621 | |||
622 | synchronize_user_stack(); | ||
623 | save_and_clear_fpu(); | ||
624 | |||
625 | sframep = (struct signal_sframe32 __user *) | ||
626 | get_sigframe(sa, regs, SF_ALIGNEDSZ); | ||
627 | if (invalid_frame_pointer(sframep, sizeof(*sframep))){ | ||
628 | /* Don't change signal code and address, so that | ||
629 | * post mortem debuggers can have a look. | ||
630 | */ | ||
631 | do_exit(SIGILL); | ||
632 | } | ||
633 | |||
634 | sc = &sframep->sig_context; | ||
635 | |||
636 | /* We've already made sure frame pointer isn't in kernel space... */ | ||
637 | err = __put_user((sas_ss_flags(regs->u_regs[UREG_FP]) == SS_ONSTACK), | ||
638 | &sc->sigc_onstack); | ||
639 | |||
640 | switch (_NSIG_WORDS) { | ||
641 | case 4: seta[7] = (oldset->sig[3] >> 32); | ||
642 | seta[6] = oldset->sig[3]; | ||
643 | case 3: seta[5] = (oldset->sig[2] >> 32); | ||
644 | seta[4] = oldset->sig[2]; | ||
645 | case 2: seta[3] = (oldset->sig[1] >> 32); | ||
646 | seta[2] = oldset->sig[1]; | ||
647 | case 1: seta[1] = (oldset->sig[0] >> 32); | ||
648 | seta[0] = oldset->sig[0]; | ||
649 | } | ||
650 | err |= __put_user(seta[0], &sc->sigc_mask); | ||
651 | err |= __copy_to_user(sframep->extramask, seta + 1, | ||
652 | (_COMPAT_NSIG_WORDS - 1) * sizeof(unsigned int)); | ||
653 | err |= __put_user(regs->u_regs[UREG_FP], &sc->sigc_sp); | ||
654 | err |= __put_user(pc, &sc->sigc_pc); | ||
655 | err |= __put_user(npc, &sc->sigc_npc); | ||
656 | psr = tstate_to_psr(regs->tstate); | ||
657 | if (current_thread_info()->fpsaved[0] & FPRS_FEF) | ||
658 | psr |= PSR_EF; | ||
659 | err |= __put_user(psr, &sc->sigc_psr); | ||
660 | err |= __put_user(regs->u_regs[UREG_G1], &sc->sigc_g1); | ||
661 | err |= __put_user(regs->u_regs[UREG_I0], &sc->sigc_o0); | ||
662 | err |= __put_user(get_thread_wsaved(), &sc->sigc_oswins); | ||
663 | |||
664 | err |= copy_in_user((u32 __user *)sframep, | ||
665 | (u32 __user *)(regs->u_regs[UREG_FP]), | ||
666 | sizeof(struct reg_window32)); | ||
667 | |||
668 | set_thread_wsaved(0); /* So process is allowed to execute. */ | ||
669 | err |= __put_user(signr, &sframep->sig_num); | ||
670 | sig_address = NULL; | ||
671 | sig_code = 0; | ||
672 | if (SI_FROMKERNEL (info) && (info->si_code & __SI_MASK) == __SI_FAULT) { | ||
673 | sig_address = info->si_addr; | ||
674 | switch (signr) { | ||
675 | case SIGSEGV: | ||
676 | switch (info->si_code) { | ||
677 | case SEGV_MAPERR: sig_code = SUBSIG_NOMAPPING; break; | ||
678 | default: sig_code = SUBSIG_PROTECTION; break; | ||
679 | } | ||
680 | break; | ||
681 | case SIGILL: | ||
682 | switch (info->si_code) { | ||
683 | case ILL_ILLOPC: sig_code = SUBSIG_ILLINST; break; | ||
684 | case ILL_PRVOPC: sig_code = SUBSIG_PRIVINST; break; | ||
685 | case ILL_ILLTRP: sig_code = SUBSIG_BADTRAP(info->si_trapno); break; | ||
686 | default: sig_code = SUBSIG_STACK; break; | ||
687 | } | ||
688 | break; | ||
689 | case SIGFPE: | ||
690 | switch (info->si_code) { | ||
691 | case FPE_INTDIV: sig_code = SUBSIG_IDIVZERO; break; | ||
692 | case FPE_INTOVF: sig_code = SUBSIG_FPINTOVFL; break; | ||
693 | case FPE_FLTDIV: sig_code = SUBSIG_FPDIVZERO; break; | ||
694 | case FPE_FLTOVF: sig_code = SUBSIG_FPOVFLOW; break; | ||
695 | case FPE_FLTUND: sig_code = SUBSIG_FPUNFLOW; break; | ||
696 | case FPE_FLTRES: sig_code = SUBSIG_FPINEXACT; break; | ||
697 | case FPE_FLTINV: sig_code = SUBSIG_FPOPERROR; break; | ||
698 | default: sig_code = SUBSIG_FPERROR; break; | ||
699 | } | ||
700 | break; | ||
701 | case SIGBUS: | ||
702 | switch (info->si_code) { | ||
703 | case BUS_ADRALN: sig_code = SUBSIG_ALIGNMENT; break; | ||
704 | case BUS_ADRERR: sig_code = SUBSIG_MISCERROR; break; | ||
705 | default: sig_code = SUBSIG_BUSTIMEOUT; break; | ||
706 | } | ||
707 | break; | ||
708 | case SIGEMT: | ||
709 | switch (info->si_code) { | ||
710 | case EMT_TAGOVF: sig_code = SUBSIG_TAG; break; | ||
711 | } | ||
712 | break; | ||
713 | case SIGSYS: | ||
714 | if (info->si_code == (__SI_FAULT|0x100)) { | ||
715 | /* See sys_sunos32.c */ | ||
716 | sig_code = info->si_trapno; | ||
717 | break; | ||
718 | } | ||
719 | default: | ||
720 | sig_address = NULL; | ||
721 | } | ||
722 | } | ||
723 | err |= __put_user(ptr_to_compat(sig_address), &sframep->sig_address); | ||
724 | err |= __put_user(sig_code, &sframep->sig_code); | ||
725 | err |= __put_user(ptr_to_compat(sc), &sframep->sig_scptr); | ||
726 | if (err) | ||
727 | goto sigsegv; | ||
728 | |||
729 | regs->u_regs[UREG_FP] = (unsigned long) sframep; | ||
730 | regs->tpc = (unsigned long) sa->sa_handler; | ||
731 | regs->tnpc = (regs->tpc + 4); | ||
732 | if (test_thread_flag(TIF_32BIT)) { | ||
733 | regs->tpc &= 0xffffffff; | ||
734 | regs->tnpc &= 0xffffffff; | ||
735 | } | ||
736 | return; | ||
737 | |||
738 | sigsegv: | ||
739 | force_sigsegv(signr, current); | ||
740 | } | ||
741 | |||
742 | |||
743 | static int save_fpu_state32(struct pt_regs *regs, __siginfo_fpu_t __user *fpu) | ||
744 | { | ||
745 | unsigned long *fpregs = current_thread_info()->fpregs; | ||
746 | unsigned long fprs; | ||
747 | int err = 0; | ||
748 | |||
749 | fprs = current_thread_info()->fpsaved[0]; | ||
750 | if (fprs & FPRS_DL) | ||
751 | err |= copy_to_user(&fpu->si_float_regs[0], fpregs, | ||
752 | (sizeof(unsigned int) * 32)); | ||
753 | if (fprs & FPRS_DU) | ||
754 | err |= copy_to_user(&fpu->si_float_regs[32], fpregs+16, | ||
755 | (sizeof(unsigned int) * 32)); | ||
756 | err |= __put_user(current_thread_info()->xfsr[0], &fpu->si_fsr); | ||
757 | err |= __put_user(current_thread_info()->gsr[0], &fpu->si_gsr); | ||
758 | err |= __put_user(fprs, &fpu->si_fprs); | ||
759 | |||
760 | return err; | ||
761 | } | ||
762 | |||
763 | static void new_setup_frame32(struct k_sigaction *ka, struct pt_regs *regs, | ||
764 | int signo, sigset_t *oldset) | ||
765 | { | ||
766 | struct new_signal_frame32 __user *sf; | ||
767 | int sigframe_size; | ||
768 | u32 psr; | ||
769 | int i, err; | ||
770 | unsigned int seta[_COMPAT_NSIG_WORDS]; | ||
771 | |||
772 | /* 1. Make sure everything is clean */ | ||
773 | synchronize_user_stack(); | ||
774 | save_and_clear_fpu(); | ||
775 | |||
776 | sigframe_size = NF_ALIGNEDSZ; | ||
777 | if (!(current_thread_info()->fpsaved[0] & FPRS_FEF)) | ||
778 | sigframe_size -= sizeof(__siginfo_fpu_t); | ||
779 | |||
780 | sf = (struct new_signal_frame32 __user *) | ||
781 | get_sigframe(&ka->sa, regs, sigframe_size); | ||
782 | |||
783 | if (invalid_frame_pointer(sf, sigframe_size)) | ||
784 | goto sigill; | ||
785 | |||
786 | if (get_thread_wsaved() != 0) | ||
787 | goto sigill; | ||
788 | |||
789 | /* 2. Save the current process state */ | ||
790 | if (test_thread_flag(TIF_32BIT)) { | ||
791 | regs->tpc &= 0xffffffff; | ||
792 | regs->tnpc &= 0xffffffff; | ||
793 | } | ||
794 | err = put_user(regs->tpc, &sf->info.si_regs.pc); | ||
795 | err |= __put_user(regs->tnpc, &sf->info.si_regs.npc); | ||
796 | err |= __put_user(regs->y, &sf->info.si_regs.y); | ||
797 | psr = tstate_to_psr(regs->tstate); | ||
798 | if (current_thread_info()->fpsaved[0] & FPRS_FEF) | ||
799 | psr |= PSR_EF; | ||
800 | err |= __put_user(psr, &sf->info.si_regs.psr); | ||
801 | for (i = 0; i < 16; i++) | ||
802 | err |= __put_user(regs->u_regs[i], &sf->info.si_regs.u_regs[i]); | ||
803 | err |= __put_user(sizeof(siginfo_extra_v8plus_t), &sf->extra_size); | ||
804 | err |= __put_user(SIGINFO_EXTRA_V8PLUS_MAGIC, &sf->v8plus.g_upper[0]); | ||
805 | for (i = 1; i < 16; i++) | ||
806 | err |= __put_user(((u32 *)regs->u_regs)[2*i], | ||
807 | &sf->v8plus.g_upper[i]); | ||
808 | err |= __put_user((regs->tstate & TSTATE_ASI) >> 24UL, | ||
809 | &sf->v8plus.asi); | ||
810 | |||
811 | if (psr & PSR_EF) { | ||
812 | err |= save_fpu_state32(regs, &sf->fpu_state); | ||
813 | err |= __put_user((u64)&sf->fpu_state, &sf->fpu_save); | ||
814 | } else { | ||
815 | err |= __put_user(0, &sf->fpu_save); | ||
816 | } | ||
817 | |||
818 | switch (_NSIG_WORDS) { | ||
819 | case 4: seta[7] = (oldset->sig[3] >> 32); | ||
820 | seta[6] = oldset->sig[3]; | ||
821 | case 3: seta[5] = (oldset->sig[2] >> 32); | ||
822 | seta[4] = oldset->sig[2]; | ||
823 | case 2: seta[3] = (oldset->sig[1] >> 32); | ||
824 | seta[2] = oldset->sig[1]; | ||
825 | case 1: seta[1] = (oldset->sig[0] >> 32); | ||
826 | seta[0] = oldset->sig[0]; | ||
827 | } | ||
828 | err |= __put_user(seta[0], &sf->info.si_mask); | ||
829 | err |= __copy_to_user(sf->extramask, seta + 1, | ||
830 | (_COMPAT_NSIG_WORDS - 1) * sizeof(unsigned int)); | ||
831 | |||
832 | err |= copy_in_user((u32 __user *)sf, | ||
833 | (u32 __user *)(regs->u_regs[UREG_FP]), | ||
834 | sizeof(struct reg_window32)); | ||
835 | |||
836 | if (err) | ||
837 | goto sigsegv; | ||
838 | |||
839 | /* 3. signal handler back-trampoline and parameters */ | ||
840 | regs->u_regs[UREG_FP] = (unsigned long) sf; | ||
841 | regs->u_regs[UREG_I0] = signo; | ||
842 | regs->u_regs[UREG_I1] = (unsigned long) &sf->info; | ||
843 | regs->u_regs[UREG_I2] = (unsigned long) &sf->info; | ||
844 | |||
845 | /* 4. signal handler */ | ||
846 | regs->tpc = (unsigned long) ka->sa.sa_handler; | ||
847 | regs->tnpc = (regs->tpc + 4); | ||
848 | if (test_thread_flag(TIF_32BIT)) { | ||
849 | regs->tpc &= 0xffffffff; | ||
850 | regs->tnpc &= 0xffffffff; | ||
851 | } | ||
852 | |||
853 | /* 5. return to kernel instructions */ | ||
854 | if (ka->ka_restorer) { | ||
855 | regs->u_regs[UREG_I7] = (unsigned long)ka->ka_restorer; | ||
856 | } else { | ||
857 | /* Flush instruction space. */ | ||
858 | unsigned long address = ((unsigned long)&(sf->insns[0])); | ||
859 | pgd_t *pgdp = pgd_offset(current->mm, address); | ||
860 | pud_t *pudp = pud_offset(pgdp, address); | ||
861 | pmd_t *pmdp = pmd_offset(pudp, address); | ||
862 | pte_t *ptep; | ||
863 | |||
864 | regs->u_regs[UREG_I7] = (unsigned long) (&(sf->insns[0]) - 2); | ||
865 | |||
866 | err = __put_user(0x821020d8, &sf->insns[0]); /*mov __NR_sigreturn, %g1*/ | ||
867 | err |= __put_user(0x91d02010, &sf->insns[1]); /*t 0x10*/ | ||
868 | if (err) | ||
869 | goto sigsegv; | ||
870 | |||
871 | preempt_disable(); | ||
872 | ptep = pte_offset_map(pmdp, address); | ||
873 | if (pte_present(*ptep)) { | ||
874 | unsigned long page = (unsigned long) | ||
875 | page_address(pte_page(*ptep)); | ||
876 | |||
877 | __asm__ __volatile__( | ||
878 | " membar #StoreStore\n" | ||
879 | " flush %0 + %1" | ||
880 | : : "r" (page), "r" (address & (PAGE_SIZE - 1)) | ||
881 | : "memory"); | ||
882 | } | ||
883 | pte_unmap(ptep); | ||
884 | preempt_enable(); | ||
885 | } | ||
886 | return; | ||
887 | |||
888 | sigill: | ||
889 | do_exit(SIGILL); | ||
890 | sigsegv: | ||
891 | force_sigsegv(signo, current); | ||
892 | } | ||
893 | |||
894 | /* Setup a Solaris stack frame */ | ||
895 | static void | ||
896 | setup_svr4_frame32(struct sigaction *sa, unsigned long pc, unsigned long npc, | ||
897 | struct pt_regs *regs, int signr, sigset_t *oldset) | ||
898 | { | ||
899 | svr4_signal_frame_t __user *sfp; | ||
900 | svr4_gregset_t __user *gr; | ||
901 | svr4_siginfo_t __user *si; | ||
902 | svr4_mcontext_t __user *mc; | ||
903 | svr4_gwindows_t __user *gw; | ||
904 | svr4_ucontext_t __user *uc; | ||
905 | svr4_sigset_t setv; | ||
906 | unsigned int psr; | ||
907 | int i, err; | ||
908 | |||
909 | synchronize_user_stack(); | ||
910 | save_and_clear_fpu(); | ||
911 | |||
912 | regs->u_regs[UREG_FP] &= 0x00000000ffffffffUL; | ||
913 | sfp = (svr4_signal_frame_t __user *) | ||
914 | get_sigframe(sa, regs, | ||
915 | sizeof(struct reg_window32) + SVR4_SF_ALIGNED); | ||
916 | |||
917 | if (invalid_frame_pointer(sfp, sizeof(*sfp))) | ||
918 | do_exit(SIGILL); | ||
919 | |||
920 | /* Start with a clean frame pointer and fill it */ | ||
921 | err = clear_user(sfp, sizeof(*sfp)); | ||
922 | |||
923 | /* Setup convenience variables */ | ||
924 | si = &sfp->si; | ||
925 | uc = &sfp->uc; | ||
926 | gw = &sfp->gw; | ||
927 | mc = &uc->mcontext; | ||
928 | gr = &mc->greg; | ||
929 | |||
930 | /* FIXME: where am I supposed to put this? | ||
931 | * sc->sigc_onstack = old_status; | ||
932 | * anyways, it does not look like it is used for anything at all. | ||
933 | */ | ||
934 | setv.sigbits[0] = oldset->sig[0]; | ||
935 | setv.sigbits[1] = (oldset->sig[0] >> 32); | ||
936 | if (_NSIG_WORDS >= 2) { | ||
937 | setv.sigbits[2] = oldset->sig[1]; | ||
938 | setv.sigbits[3] = (oldset->sig[1] >> 32); | ||
939 | err |= __copy_to_user(&uc->sigmask, &setv, sizeof(svr4_sigset_t)); | ||
940 | } else | ||
941 | err |= __copy_to_user(&uc->sigmask, &setv, | ||
942 | 2 * sizeof(unsigned int)); | ||
943 | |||
944 | /* Store registers */ | ||
945 | if (test_thread_flag(TIF_32BIT)) { | ||
946 | regs->tpc &= 0xffffffff; | ||
947 | regs->tnpc &= 0xffffffff; | ||
948 | } | ||
949 | err |= __put_user(regs->tpc, &((*gr)[SVR4_PC])); | ||
950 | err |= __put_user(regs->tnpc, &((*gr)[SVR4_NPC])); | ||
951 | psr = tstate_to_psr(regs->tstate); | ||
952 | if (current_thread_info()->fpsaved[0] & FPRS_FEF) | ||
953 | psr |= PSR_EF; | ||
954 | err |= __put_user(psr, &((*gr)[SVR4_PSR])); | ||
955 | err |= __put_user(regs->y, &((*gr)[SVR4_Y])); | ||
956 | |||
957 | /* Copy g[1..7] and o[0..7] registers */ | ||
958 | for (i = 0; i < 7; i++) | ||
959 | err |= __put_user(regs->u_regs[UREG_G1+i], (&(*gr)[SVR4_G1])+i); | ||
960 | for (i = 0; i < 8; i++) | ||
961 | err |= __put_user(regs->u_regs[UREG_I0+i], (&(*gr)[SVR4_O0])+i); | ||
962 | |||
963 | /* Setup sigaltstack */ | ||
964 | err |= __put_user(current->sas_ss_sp, &uc->stack.sp); | ||
965 | err |= __put_user(sas_ss_flags(regs->u_regs[UREG_FP]), &uc->stack.flags); | ||
966 | err |= __put_user(current->sas_ss_size, &uc->stack.size); | ||
967 | |||
968 | /* Save the currently window file: */ | ||
969 | |||
970 | /* 1. Link sfp->uc->gwins to our windows */ | ||
971 | err |= __put_user(ptr_to_compat(gw), &mc->gwin); | ||
972 | |||
973 | /* 2. Number of windows to restore at setcontext (): */ | ||
974 | err |= __put_user(get_thread_wsaved(), &gw->count); | ||
975 | |||
976 | /* 3. We just pay attention to the gw->count field on setcontext */ | ||
977 | set_thread_wsaved(0); /* So process is allowed to execute. */ | ||
978 | |||
979 | /* Setup the signal information. Solaris expects a bunch of | ||
980 | * information to be passed to the signal handler, we don't provide | ||
981 | * that much currently, should use siginfo. | ||
982 | */ | ||
983 | err |= __put_user(signr, &si->siginfo.signo); | ||
984 | err |= __put_user(SVR4_SINOINFO, &si->siginfo.code); | ||
985 | if (err) | ||
986 | goto sigsegv; | ||
987 | |||
988 | regs->u_regs[UREG_FP] = (unsigned long) sfp; | ||
989 | regs->tpc = (unsigned long) sa->sa_handler; | ||
990 | regs->tnpc = (regs->tpc + 4); | ||
991 | if (test_thread_flag(TIF_32BIT)) { | ||
992 | regs->tpc &= 0xffffffff; | ||
993 | regs->tnpc &= 0xffffffff; | ||
994 | } | ||
995 | |||
996 | /* Arguments passed to signal handler */ | ||
997 | if (regs->u_regs[14]){ | ||
998 | struct reg_window32 __user *rw = (struct reg_window32 __user *) | ||
999 | (regs->u_regs[14] & 0x00000000ffffffffUL); | ||
1000 | |||
1001 | err |= __put_user(signr, &rw->ins[0]); | ||
1002 | err |= __put_user((u64)si, &rw->ins[1]); | ||
1003 | err |= __put_user((u64)uc, &rw->ins[2]); | ||
1004 | err |= __put_user((u64)sfp, &rw->ins[6]); /* frame pointer */ | ||
1005 | if (err) | ||
1006 | goto sigsegv; | ||
1007 | |||
1008 | regs->u_regs[UREG_I0] = signr; | ||
1009 | regs->u_regs[UREG_I1] = (u32)(u64) si; | ||
1010 | regs->u_regs[UREG_I2] = (u32)(u64) uc; | ||
1011 | } | ||
1012 | return; | ||
1013 | |||
1014 | sigsegv: | ||
1015 | force_sigsegv(signr, current); | ||
1016 | } | ||
1017 | |||
1018 | asmlinkage int | ||
1019 | svr4_getcontext(svr4_ucontext_t __user *uc, struct pt_regs *regs) | ||
1020 | { | ||
1021 | svr4_gregset_t __user *gr; | ||
1022 | svr4_mcontext_t __user *mc; | ||
1023 | svr4_sigset_t setv; | ||
1024 | int i, err; | ||
1025 | u32 psr; | ||
1026 | |||
1027 | synchronize_user_stack(); | ||
1028 | save_and_clear_fpu(); | ||
1029 | |||
1030 | if (get_thread_wsaved()) | ||
1031 | do_exit(SIGSEGV); | ||
1032 | |||
1033 | err = clear_user(uc, sizeof(*uc)); | ||
1034 | |||
1035 | /* Setup convenience variables */ | ||
1036 | mc = &uc->mcontext; | ||
1037 | gr = &mc->greg; | ||
1038 | |||
1039 | setv.sigbits[0] = current->blocked.sig[0]; | ||
1040 | setv.sigbits[1] = (current->blocked.sig[0] >> 32); | ||
1041 | if (_NSIG_WORDS >= 2) { | ||
1042 | setv.sigbits[2] = current->blocked.sig[1]; | ||
1043 | setv.sigbits[3] = (current->blocked.sig[1] >> 32); | ||
1044 | err |= __copy_to_user(&uc->sigmask, &setv, sizeof(svr4_sigset_t)); | ||
1045 | } else | ||
1046 | err |= __copy_to_user(&uc->sigmask, &setv, 2 * sizeof(unsigned)); | ||
1047 | |||
1048 | /* Store registers */ | ||
1049 | if (test_thread_flag(TIF_32BIT)) { | ||
1050 | regs->tpc &= 0xffffffff; | ||
1051 | regs->tnpc &= 0xffffffff; | ||
1052 | } | ||
1053 | err |= __put_user(regs->tpc, &uc->mcontext.greg[SVR4_PC]); | ||
1054 | err |= __put_user(regs->tnpc, &uc->mcontext.greg[SVR4_NPC]); | ||
1055 | |||
1056 | psr = tstate_to_psr(regs->tstate) & ~PSR_EF; | ||
1057 | if (current_thread_info()->fpsaved[0] & FPRS_FEF) | ||
1058 | psr |= PSR_EF; | ||
1059 | err |= __put_user(psr, &uc->mcontext.greg[SVR4_PSR]); | ||
1060 | |||
1061 | err |= __put_user(regs->y, &uc->mcontext.greg[SVR4_Y]); | ||
1062 | |||
1063 | /* Copy g[1..7] and o[0..7] registers */ | ||
1064 | for (i = 0; i < 7; i++) | ||
1065 | err |= __put_user(regs->u_regs[UREG_G1+i], (&(*gr)[SVR4_G1])+i); | ||
1066 | for (i = 0; i < 8; i++) | ||
1067 | err |= __put_user(regs->u_regs[UREG_I0+i], (&(*gr)[SVR4_O0])+i); | ||
1068 | |||
1069 | /* Setup sigaltstack */ | ||
1070 | err |= __put_user(current->sas_ss_sp, &uc->stack.sp); | ||
1071 | err |= __put_user(sas_ss_flags(regs->u_regs[UREG_FP]), &uc->stack.flags); | ||
1072 | err |= __put_user(current->sas_ss_size, &uc->stack.size); | ||
1073 | |||
1074 | /* The register file is not saved | ||
1075 | * we have already stuffed all of it with sync_user_stack | ||
1076 | */ | ||
1077 | return (err ? -EFAULT : 0); | ||
1078 | } | ||
1079 | |||
1080 | |||
1081 | /* Set the context for a svr4 application, this is Solaris way to sigreturn */ | ||
1082 | asmlinkage int svr4_setcontext(svr4_ucontext_t __user *c, struct pt_regs *regs) | ||
1083 | { | ||
1084 | svr4_gregset_t __user *gr; | ||
1085 | mm_segment_t old_fs; | ||
1086 | u32 pc, npc, psr, u_ss_sp; | ||
1087 | sigset_t set; | ||
1088 | svr4_sigset_t setv; | ||
1089 | int i, err; | ||
1090 | stack_t st; | ||
1091 | |||
1092 | /* Fixme: restore windows, or is this already taken care of in | ||
1093 | * svr4_setup_frame when sync_user_windows is done? | ||
1094 | */ | ||
1095 | flush_user_windows(); | ||
1096 | |||
1097 | if (get_thread_wsaved()) | ||
1098 | goto sigsegv; | ||
1099 | |||
1100 | if (((unsigned long) c) & 3){ | ||
1101 | printk("Unaligned structure passed\n"); | ||
1102 | goto sigsegv; | ||
1103 | } | ||
1104 | |||
1105 | if (!__access_ok(c, sizeof(*c))) { | ||
1106 | /* Miguel, add nice debugging msg _here_. ;-) */ | ||
1107 | goto sigsegv; | ||
1108 | } | ||
1109 | |||
1110 | /* Check for valid PC and nPC */ | ||
1111 | gr = &c->mcontext.greg; | ||
1112 | err = __get_user(pc, &((*gr)[SVR4_PC])); | ||
1113 | err |= __get_user(npc, &((*gr)[SVR4_NPC])); | ||
1114 | if ((pc | npc) & 3) | ||
1115 | goto sigsegv; | ||
1116 | |||
1117 | /* Retrieve information from passed ucontext */ | ||
1118 | /* note that nPC is ored a 1, this is used to inform entry.S */ | ||
1119 | /* that we don't want it to mess with our PC and nPC */ | ||
1120 | |||
1121 | err |= copy_from_user(&setv, &c->sigmask, sizeof(svr4_sigset_t)); | ||
1122 | set.sig[0] = setv.sigbits[0] | (((long)setv.sigbits[1]) << 32); | ||
1123 | if (_NSIG_WORDS >= 2) | ||
1124 | set.sig[1] = setv.sigbits[2] | (((long)setv.sigbits[3]) << 32); | ||
1125 | |||
1126 | err |= __get_user(u_ss_sp, &c->stack.sp); | ||
1127 | st.ss_sp = compat_ptr(u_ss_sp); | ||
1128 | err |= __get_user(st.ss_flags, &c->stack.flags); | ||
1129 | err |= __get_user(st.ss_size, &c->stack.size); | ||
1130 | if (err) | ||
1131 | goto sigsegv; | ||
1132 | |||
1133 | /* It is more difficult to avoid calling this function than to | ||
1134 | call it and ignore errors. */ | ||
1135 | old_fs = get_fs(); | ||
1136 | set_fs(KERNEL_DS); | ||
1137 | do_sigaltstack((stack_t __user *) &st, NULL, regs->u_regs[UREG_I6]); | ||
1138 | set_fs(old_fs); | ||
1139 | |||
1140 | sigdelsetmask(&set, ~_BLOCKABLE); | ||
1141 | spin_lock_irq(¤t->sighand->siglock); | ||
1142 | current->blocked = set; | ||
1143 | recalc_sigpending(); | ||
1144 | spin_unlock_irq(¤t->sighand->siglock); | ||
1145 | regs->tpc = pc; | ||
1146 | regs->tnpc = npc | 1; | ||
1147 | if (test_thread_flag(TIF_32BIT)) { | ||
1148 | regs->tpc &= 0xffffffff; | ||
1149 | regs->tnpc &= 0xffffffff; | ||
1150 | } | ||
1151 | err |= __get_user(regs->y, &((*gr)[SVR4_Y])); | ||
1152 | err |= __get_user(psr, &((*gr)[SVR4_PSR])); | ||
1153 | regs->tstate &= ~(TSTATE_ICC|TSTATE_XCC); | ||
1154 | regs->tstate |= psr_to_tstate_icc(psr); | ||
1155 | |||
1156 | /* Restore g[1..7] and o[0..7] registers */ | ||
1157 | for (i = 0; i < 7; i++) | ||
1158 | err |= __get_user(regs->u_regs[UREG_G1+i], (&(*gr)[SVR4_G1])+i); | ||
1159 | for (i = 0; i < 8; i++) | ||
1160 | err |= __get_user(regs->u_regs[UREG_I0+i], (&(*gr)[SVR4_O0])+i); | ||
1161 | if (err) | ||
1162 | goto sigsegv; | ||
1163 | |||
1164 | return -EINTR; | ||
1165 | sigsegv: | ||
1166 | return -EFAULT; | ||
1167 | } | ||
1168 | |||
1169 | static void setup_rt_frame32(struct k_sigaction *ka, struct pt_regs *regs, | ||
1170 | unsigned long signr, sigset_t *oldset, | ||
1171 | siginfo_t *info) | ||
1172 | { | ||
1173 | struct rt_signal_frame32 __user *sf; | ||
1174 | int sigframe_size; | ||
1175 | u32 psr; | ||
1176 | int i, err; | ||
1177 | compat_sigset_t seta; | ||
1178 | |||
1179 | /* 1. Make sure everything is clean */ | ||
1180 | synchronize_user_stack(); | ||
1181 | save_and_clear_fpu(); | ||
1182 | |||
1183 | sigframe_size = RT_ALIGNEDSZ; | ||
1184 | if (!(current_thread_info()->fpsaved[0] & FPRS_FEF)) | ||
1185 | sigframe_size -= sizeof(__siginfo_fpu_t); | ||
1186 | |||
1187 | sf = (struct rt_signal_frame32 __user *) | ||
1188 | get_sigframe(&ka->sa, regs, sigframe_size); | ||
1189 | |||
1190 | if (invalid_frame_pointer(sf, sigframe_size)) | ||
1191 | goto sigill; | ||
1192 | |||
1193 | if (get_thread_wsaved() != 0) | ||
1194 | goto sigill; | ||
1195 | |||
1196 | /* 2. Save the current process state */ | ||
1197 | if (test_thread_flag(TIF_32BIT)) { | ||
1198 | regs->tpc &= 0xffffffff; | ||
1199 | regs->tnpc &= 0xffffffff; | ||
1200 | } | ||
1201 | err = put_user(regs->tpc, &sf->regs.pc); | ||
1202 | err |= __put_user(regs->tnpc, &sf->regs.npc); | ||
1203 | err |= __put_user(regs->y, &sf->regs.y); | ||
1204 | psr = tstate_to_psr(regs->tstate); | ||
1205 | if (current_thread_info()->fpsaved[0] & FPRS_FEF) | ||
1206 | psr |= PSR_EF; | ||
1207 | err |= __put_user(psr, &sf->regs.psr); | ||
1208 | for (i = 0; i < 16; i++) | ||
1209 | err |= __put_user(regs->u_regs[i], &sf->regs.u_regs[i]); | ||
1210 | err |= __put_user(sizeof(siginfo_extra_v8plus_t), &sf->extra_size); | ||
1211 | err |= __put_user(SIGINFO_EXTRA_V8PLUS_MAGIC, &sf->v8plus.g_upper[0]); | ||
1212 | for (i = 1; i < 16; i++) | ||
1213 | err |= __put_user(((u32 *)regs->u_regs)[2*i], | ||
1214 | &sf->v8plus.g_upper[i]); | ||
1215 | err |= __put_user((regs->tstate & TSTATE_ASI) >> 24UL, | ||
1216 | &sf->v8plus.asi); | ||
1217 | |||
1218 | if (psr & PSR_EF) { | ||
1219 | err |= save_fpu_state32(regs, &sf->fpu_state); | ||
1220 | err |= __put_user((u64)&sf->fpu_state, &sf->fpu_save); | ||
1221 | } else { | ||
1222 | err |= __put_user(0, &sf->fpu_save); | ||
1223 | } | ||
1224 | |||
1225 | /* Update the siginfo structure. */ | ||
1226 | err |= copy_siginfo_to_user32(&sf->info, info); | ||
1227 | |||
1228 | /* Setup sigaltstack */ | ||
1229 | err |= __put_user(current->sas_ss_sp, &sf->stack.ss_sp); | ||
1230 | err |= __put_user(sas_ss_flags(regs->u_regs[UREG_FP]), &sf->stack.ss_flags); | ||
1231 | err |= __put_user(current->sas_ss_size, &sf->stack.ss_size); | ||
1232 | |||
1233 | switch (_NSIG_WORDS) { | ||
1234 | case 4: seta.sig[7] = (oldset->sig[3] >> 32); | ||
1235 | seta.sig[6] = oldset->sig[3]; | ||
1236 | case 3: seta.sig[5] = (oldset->sig[2] >> 32); | ||
1237 | seta.sig[4] = oldset->sig[2]; | ||
1238 | case 2: seta.sig[3] = (oldset->sig[1] >> 32); | ||
1239 | seta.sig[2] = oldset->sig[1]; | ||
1240 | case 1: seta.sig[1] = (oldset->sig[0] >> 32); | ||
1241 | seta.sig[0] = oldset->sig[0]; | ||
1242 | } | ||
1243 | err |= __copy_to_user(&sf->mask, &seta, sizeof(compat_sigset_t)); | ||
1244 | |||
1245 | err |= copy_in_user((u32 __user *)sf, | ||
1246 | (u32 __user *)(regs->u_regs[UREG_FP]), | ||
1247 | sizeof(struct reg_window32)); | ||
1248 | if (err) | ||
1249 | goto sigsegv; | ||
1250 | |||
1251 | /* 3. signal handler back-trampoline and parameters */ | ||
1252 | regs->u_regs[UREG_FP] = (unsigned long) sf; | ||
1253 | regs->u_regs[UREG_I0] = signr; | ||
1254 | regs->u_regs[UREG_I1] = (unsigned long) &sf->info; | ||
1255 | regs->u_regs[UREG_I2] = (unsigned long) &sf->regs; | ||
1256 | |||
1257 | /* 4. signal handler */ | ||
1258 | regs->tpc = (unsigned long) ka->sa.sa_handler; | ||
1259 | regs->tnpc = (regs->tpc + 4); | ||
1260 | if (test_thread_flag(TIF_32BIT)) { | ||
1261 | regs->tpc &= 0xffffffff; | ||
1262 | regs->tnpc &= 0xffffffff; | ||
1263 | } | ||
1264 | |||
1265 | /* 5. return to kernel instructions */ | ||
1266 | if (ka->ka_restorer) | ||
1267 | regs->u_regs[UREG_I7] = (unsigned long)ka->ka_restorer; | ||
1268 | else { | ||
1269 | /* Flush instruction space. */ | ||
1270 | unsigned long address = ((unsigned long)&(sf->insns[0])); | ||
1271 | pgd_t *pgdp = pgd_offset(current->mm, address); | ||
1272 | pud_t *pudp = pud_offset(pgdp, address); | ||
1273 | pmd_t *pmdp = pmd_offset(pudp, address); | ||
1274 | pte_t *ptep; | ||
1275 | |||
1276 | regs->u_regs[UREG_I7] = (unsigned long) (&(sf->insns[0]) - 2); | ||
1277 | |||
1278 | /* mov __NR_rt_sigreturn, %g1 */ | ||
1279 | err |= __put_user(0x82102065, &sf->insns[0]); | ||
1280 | |||
1281 | /* t 0x10 */ | ||
1282 | err |= __put_user(0x91d02010, &sf->insns[1]); | ||
1283 | if (err) | ||
1284 | goto sigsegv; | ||
1285 | |||
1286 | preempt_disable(); | ||
1287 | ptep = pte_offset_map(pmdp, address); | ||
1288 | if (pte_present(*ptep)) { | ||
1289 | unsigned long page = (unsigned long) | ||
1290 | page_address(pte_page(*ptep)); | ||
1291 | |||
1292 | __asm__ __volatile__( | ||
1293 | " membar #StoreStore\n" | ||
1294 | " flush %0 + %1" | ||
1295 | : : "r" (page), "r" (address & (PAGE_SIZE - 1)) | ||
1296 | : "memory"); | ||
1297 | } | ||
1298 | pte_unmap(ptep); | ||
1299 | preempt_enable(); | ||
1300 | } | ||
1301 | return; | ||
1302 | |||
1303 | sigill: | ||
1304 | do_exit(SIGILL); | ||
1305 | sigsegv: | ||
1306 | force_sigsegv(signr, current); | ||
1307 | } | ||
1308 | |||
1309 | static inline void handle_signal32(unsigned long signr, struct k_sigaction *ka, | ||
1310 | siginfo_t *info, | ||
1311 | sigset_t *oldset, struct pt_regs *regs, | ||
1312 | int svr4_signal) | ||
1313 | { | ||
1314 | if (svr4_signal) | ||
1315 | setup_svr4_frame32(&ka->sa, regs->tpc, regs->tnpc, | ||
1316 | regs, signr, oldset); | ||
1317 | else { | ||
1318 | if (ka->sa.sa_flags & SA_SIGINFO) | ||
1319 | setup_rt_frame32(ka, regs, signr, oldset, info); | ||
1320 | else if (test_thread_flag(TIF_NEWSIGNALS)) | ||
1321 | new_setup_frame32(ka, regs, signr, oldset); | ||
1322 | else | ||
1323 | setup_frame32(&ka->sa, regs, signr, oldset, info); | ||
1324 | } | ||
1325 | if (!(ka->sa.sa_flags & SA_NOMASK)) { | ||
1326 | spin_lock_irq(¤t->sighand->siglock); | ||
1327 | sigorsets(¤t->blocked,¤t->blocked,&ka->sa.sa_mask); | ||
1328 | sigaddset(¤t->blocked,signr); | ||
1329 | recalc_sigpending(); | ||
1330 | spin_unlock_irq(¤t->sighand->siglock); | ||
1331 | } | ||
1332 | } | ||
1333 | |||
1334 | static inline void syscall_restart32(unsigned long orig_i0, struct pt_regs *regs, | ||
1335 | struct sigaction *sa) | ||
1336 | { | ||
1337 | switch (regs->u_regs[UREG_I0]) { | ||
1338 | case ERESTART_RESTARTBLOCK: | ||
1339 | case ERESTARTNOHAND: | ||
1340 | no_system_call_restart: | ||
1341 | regs->u_regs[UREG_I0] = EINTR; | ||
1342 | regs->tstate |= TSTATE_ICARRY; | ||
1343 | break; | ||
1344 | case ERESTARTSYS: | ||
1345 | if (!(sa->sa_flags & SA_RESTART)) | ||
1346 | goto no_system_call_restart; | ||
1347 | /* fallthrough */ | ||
1348 | case ERESTARTNOINTR: | ||
1349 | regs->u_regs[UREG_I0] = orig_i0; | ||
1350 | regs->tpc -= 4; | ||
1351 | regs->tnpc -= 4; | ||
1352 | } | ||
1353 | } | ||
1354 | |||
1355 | /* Note that 'init' is a special process: it doesn't get signals it doesn't | ||
1356 | * want to handle. Thus you cannot kill init even with a SIGKILL even by | ||
1357 | * mistake. | ||
1358 | */ | ||
1359 | int do_signal32(sigset_t *oldset, struct pt_regs * regs, | ||
1360 | unsigned long orig_i0, int restart_syscall) | ||
1361 | { | ||
1362 | siginfo_t info; | ||
1363 | struct signal_deliver_cookie cookie; | ||
1364 | struct k_sigaction ka; | ||
1365 | int signr; | ||
1366 | int svr4_signal = current->personality == PER_SVR4; | ||
1367 | |||
1368 | cookie.restart_syscall = restart_syscall; | ||
1369 | cookie.orig_i0 = orig_i0; | ||
1370 | |||
1371 | signr = get_signal_to_deliver(&info, &ka, regs, &cookie); | ||
1372 | if (signr > 0) { | ||
1373 | if (cookie.restart_syscall) | ||
1374 | syscall_restart32(orig_i0, regs, &ka.sa); | ||
1375 | handle_signal32(signr, &ka, &info, oldset, | ||
1376 | regs, svr4_signal); | ||
1377 | return 1; | ||
1378 | } | ||
1379 | if (cookie.restart_syscall && | ||
1380 | (regs->u_regs[UREG_I0] == ERESTARTNOHAND || | ||
1381 | regs->u_regs[UREG_I0] == ERESTARTSYS || | ||
1382 | regs->u_regs[UREG_I0] == ERESTARTNOINTR)) { | ||
1383 | /* replay the system call when we are done */ | ||
1384 | regs->u_regs[UREG_I0] = cookie.orig_i0; | ||
1385 | regs->tpc -= 4; | ||
1386 | regs->tnpc -= 4; | ||
1387 | } | ||
1388 | if (cookie.restart_syscall && | ||
1389 | regs->u_regs[UREG_I0] == ERESTART_RESTARTBLOCK) { | ||
1390 | regs->u_regs[UREG_G1] = __NR_restart_syscall; | ||
1391 | regs->tpc -= 4; | ||
1392 | regs->tnpc -= 4; | ||
1393 | } | ||
1394 | return 0; | ||
1395 | } | ||
1396 | |||
1397 | struct sigstack32 { | ||
1398 | u32 the_stack; | ||
1399 | int cur_status; | ||
1400 | }; | ||
1401 | |||
1402 | asmlinkage int do_sys32_sigstack(u32 u_ssptr, u32 u_ossptr, unsigned long sp) | ||
1403 | { | ||
1404 | struct sigstack32 __user *ssptr = | ||
1405 | (struct sigstack32 __user *)((unsigned long)(u_ssptr)); | ||
1406 | struct sigstack32 __user *ossptr = | ||
1407 | (struct sigstack32 __user *)((unsigned long)(u_ossptr)); | ||
1408 | int ret = -EFAULT; | ||
1409 | |||
1410 | /* First see if old state is wanted. */ | ||
1411 | if (ossptr) { | ||
1412 | if (put_user(current->sas_ss_sp + current->sas_ss_size, | ||
1413 | &ossptr->the_stack) || | ||
1414 | __put_user(on_sig_stack(sp), &ossptr->cur_status)) | ||
1415 | goto out; | ||
1416 | } | ||
1417 | |||
1418 | /* Now see if we want to update the new state. */ | ||
1419 | if (ssptr) { | ||
1420 | u32 ss_sp; | ||
1421 | |||
1422 | if (get_user(ss_sp, &ssptr->the_stack)) | ||
1423 | goto out; | ||
1424 | |||
1425 | /* If the current stack was set with sigaltstack, don't | ||
1426 | * swap stacks while we are on it. | ||
1427 | */ | ||
1428 | ret = -EPERM; | ||
1429 | if (current->sas_ss_sp && on_sig_stack(sp)) | ||
1430 | goto out; | ||
1431 | |||
1432 | /* Since we don't know the extent of the stack, and we don't | ||
1433 | * track onstack-ness, but rather calculate it, we must | ||
1434 | * presume a size. Ho hum this interface is lossy. | ||
1435 | */ | ||
1436 | current->sas_ss_sp = (unsigned long)ss_sp - SIGSTKSZ; | ||
1437 | current->sas_ss_size = SIGSTKSZ; | ||
1438 | } | ||
1439 | |||
1440 | ret = 0; | ||
1441 | out: | ||
1442 | return ret; | ||
1443 | } | ||
1444 | |||
1445 | asmlinkage long do_sys32_sigaltstack(u32 ussa, u32 uossa, unsigned long sp) | ||
1446 | { | ||
1447 | stack_t uss, uoss; | ||
1448 | u32 u_ss_sp = 0; | ||
1449 | int ret; | ||
1450 | mm_segment_t old_fs; | ||
1451 | stack_t32 __user *uss32 = compat_ptr(ussa); | ||
1452 | stack_t32 __user *uoss32 = compat_ptr(uossa); | ||
1453 | |||
1454 | if (ussa && (get_user(u_ss_sp, &uss32->ss_sp) || | ||
1455 | __get_user(uss.ss_flags, &uss32->ss_flags) || | ||
1456 | __get_user(uss.ss_size, &uss32->ss_size))) | ||
1457 | return -EFAULT; | ||
1458 | uss.ss_sp = compat_ptr(u_ss_sp); | ||
1459 | old_fs = get_fs(); | ||
1460 | set_fs(KERNEL_DS); | ||
1461 | ret = do_sigaltstack(ussa ? (stack_t __user *) &uss : NULL, | ||
1462 | uossa ? (stack_t __user *) &uoss : NULL, sp); | ||
1463 | set_fs(old_fs); | ||
1464 | if (!ret && uossa && (put_user(ptr_to_compat(uoss.ss_sp), &uoss32->ss_sp) || | ||
1465 | __put_user(uoss.ss_flags, &uoss32->ss_flags) || | ||
1466 | __put_user(uoss.ss_size, &uoss32->ss_size))) | ||
1467 | return -EFAULT; | ||
1468 | return ret; | ||
1469 | } | ||