diff options
Diffstat (limited to 'arch/microblaze/kernel/signal.c')
-rw-r--r-- | arch/microblaze/kernel/signal.c | 175 |
1 files changed, 37 insertions, 138 deletions
diff --git a/arch/microblaze/kernel/signal.c b/arch/microblaze/kernel/signal.c index 4c0e6521b114..1c80e4fc40ce 100644 --- a/arch/microblaze/kernel/signal.c +++ b/arch/microblaze/kernel/signal.c | |||
@@ -21,7 +21,6 @@ | |||
21 | #include <linux/sched.h> | 21 | #include <linux/sched.h> |
22 | #include <linux/mm.h> | 22 | #include <linux/mm.h> |
23 | #include <linux/smp.h> | 23 | #include <linux/smp.h> |
24 | #include <linux/smp_lock.h> | ||
25 | #include <linux/kernel.h> | 24 | #include <linux/kernel.h> |
26 | #include <linux/signal.h> | 25 | #include <linux/signal.h> |
27 | #include <linux/errno.h> | 26 | #include <linux/errno.h> |
@@ -45,91 +44,8 @@ | |||
45 | 44 | ||
46 | asmlinkage int do_signal(struct pt_regs *regs, sigset_t *oldset, int in_sycall); | 45 | asmlinkage int do_signal(struct pt_regs *regs, sigset_t *oldset, int in_sycall); |
47 | 46 | ||
48 | /* | ||
49 | * Atomically swap in the new signal mask, and wait for a signal. | ||
50 | */ | ||
51 | asmlinkage int | ||
52 | sys_sigsuspend(old_sigset_t mask, struct pt_regs *regs) | ||
53 | { | ||
54 | sigset_t saveset; | ||
55 | |||
56 | mask &= _BLOCKABLE; | ||
57 | spin_lock_irq(¤t->sighand->siglock); | ||
58 | saveset = current->blocked; | ||
59 | siginitset(¤t->blocked, mask); | ||
60 | recalc_sigpending(); | ||
61 | spin_unlock_irq(¤t->sighand->siglock); | ||
62 | |||
63 | regs->r3 = -EINTR; | ||
64 | while (1) { | ||
65 | current->state = TASK_INTERRUPTIBLE; | ||
66 | schedule(); | ||
67 | if (do_signal(regs, &saveset, 1)) | ||
68 | return -EINTR; | ||
69 | } | ||
70 | } | ||
71 | |||
72 | asmlinkage int | ||
73 | sys_rt_sigsuspend(sigset_t __user *unewset, size_t sigsetsize, | ||
74 | struct pt_regs *regs) | ||
75 | { | ||
76 | sigset_t saveset, newset; | ||
77 | |||
78 | /* XXX: Don't preclude handling different sized sigset_t's. */ | ||
79 | if (sigsetsize != sizeof(sigset_t)) | ||
80 | return -EINVAL; | ||
81 | |||
82 | if (copy_from_user(&newset, unewset, sizeof(newset))) | ||
83 | return -EFAULT; | ||
84 | sigdelsetmask(&newset, ~_BLOCKABLE); | ||
85 | spin_lock_irq(¤t->sighand->siglock); | ||
86 | saveset = current->blocked; | ||
87 | current->blocked = newset; | ||
88 | recalc_sigpending(); | ||
89 | spin_unlock_irq(¤t->sighand->siglock); | ||
90 | |||
91 | regs->r3 = -EINTR; | ||
92 | while (1) { | ||
93 | current->state = TASK_INTERRUPTIBLE; | ||
94 | schedule(); | ||
95 | if (do_signal(regs, &saveset, 1)) | ||
96 | return -EINTR; | ||
97 | } | ||
98 | } | ||
99 | |||
100 | asmlinkage int | ||
101 | sys_sigaction(int sig, const struct old_sigaction *act, | ||
102 | struct old_sigaction *oact) | ||
103 | { | ||
104 | struct k_sigaction new_ka, old_ka; | ||
105 | int ret; | ||
106 | |||
107 | if (act) { | ||
108 | old_sigset_t mask; | ||
109 | if (!access_ok(VERIFY_READ, act, sizeof(*act)) || | ||
110 | __get_user(new_ka.sa.sa_handler, &act->sa_handler) || | ||
111 | __get_user(new_ka.sa.sa_restorer, &act->sa_restorer)) | ||
112 | return -EFAULT; | ||
113 | __get_user(new_ka.sa.sa_flags, &act->sa_flags); | ||
114 | __get_user(mask, &act->sa_mask); | ||
115 | siginitset(&new_ka.sa.sa_mask, mask); | ||
116 | } | ||
117 | 47 | ||
118 | ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL); | 48 | asmlinkage long |
119 | |||
120 | if (!ret && oact) { | ||
121 | if (!access_ok(VERIFY_WRITE, oact, sizeof(*oact)) || | ||
122 | __put_user(old_ka.sa.sa_handler, &oact->sa_handler) || | ||
123 | __put_user(old_ka.sa.sa_restorer, &oact->sa_restorer)) | ||
124 | return -EFAULT; | ||
125 | __put_user(old_ka.sa.sa_flags, &oact->sa_flags); | ||
126 | __put_user(old_ka.sa.sa_mask.sig[0], &oact->sa_mask); | ||
127 | } | ||
128 | |||
129 | return ret; | ||
130 | } | ||
131 | |||
132 | asmlinkage int | ||
133 | sys_sigaltstack(const stack_t __user *uss, stack_t __user *uoss, | 49 | sys_sigaltstack(const stack_t __user *uss, stack_t __user *uoss, |
134 | struct pt_regs *regs) | 50 | struct pt_regs *regs) |
135 | { | 51 | { |
@@ -139,7 +55,6 @@ sys_sigaltstack(const stack_t __user *uss, stack_t __user *uoss, | |||
139 | /* | 55 | /* |
140 | * Do a signal return; undo the signal stack. | 56 | * Do a signal return; undo the signal stack. |
141 | */ | 57 | */ |
142 | |||
143 | struct sigframe { | 58 | struct sigframe { |
144 | struct sigcontext sc; | 59 | struct sigcontext sc; |
145 | unsigned long extramask[_NSIG_WORDS-1]; | 60 | unsigned long extramask[_NSIG_WORDS-1]; |
@@ -176,40 +91,7 @@ static int restore_sigcontext(struct pt_regs *regs, | |||
176 | return err; | 91 | return err; |
177 | } | 92 | } |
178 | 93 | ||
179 | asmlinkage int sys_sigreturn(struct pt_regs *regs) | 94 | asmlinkage long sys_rt_sigreturn(struct pt_regs *regs) |
180 | { | ||
181 | struct sigframe *frame = | ||
182 | (struct sigframe *)(regs->r1 + STATE_SAVE_ARG_SPACE); | ||
183 | |||
184 | sigset_t set; | ||
185 | int rval; | ||
186 | |||
187 | if (!access_ok(VERIFY_READ, frame, sizeof(*frame))) | ||
188 | goto badframe; | ||
189 | |||
190 | if (__get_user(set.sig[0], &frame->sc.oldmask) | ||
191 | || (_NSIG_WORDS > 1 | ||
192 | && __copy_from_user(&set.sig[1], &frame->extramask, | ||
193 | sizeof(frame->extramask)))) | ||
194 | goto badframe; | ||
195 | |||
196 | sigdelsetmask(&set, ~_BLOCKABLE); | ||
197 | |||
198 | spin_lock_irq(¤t->sighand->siglock); | ||
199 | current->blocked = set; | ||
200 | recalc_sigpending(); | ||
201 | spin_unlock_irq(¤t->sighand->siglock); | ||
202 | |||
203 | if (restore_sigcontext(regs, &frame->sc, &rval)) | ||
204 | goto badframe; | ||
205 | return rval; | ||
206 | |||
207 | badframe: | ||
208 | force_sig(SIGSEGV, current); | ||
209 | return 0; | ||
210 | } | ||
211 | |||
212 | asmlinkage int sys_rt_sigreturn(struct pt_regs *regs) | ||
213 | { | 95 | { |
214 | struct rt_sigframe __user *frame = | 96 | struct rt_sigframe __user *frame = |
215 | (struct rt_sigframe __user *)(regs->r1 + STATE_SAVE_ARG_SPACE); | 97 | (struct rt_sigframe __user *)(regs->r1 + STATE_SAVE_ARG_SPACE); |
@@ -324,21 +206,17 @@ static void setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info, | |||
324 | /* Set up to return from userspace. If provided, use a stub | 206 | /* Set up to return from userspace. If provided, use a stub |
325 | already in userspace. */ | 207 | already in userspace. */ |
326 | /* minus 8 is offset to cater for "rtsd r15,8" */ | 208 | /* minus 8 is offset to cater for "rtsd r15,8" */ |
327 | if (ka->sa.sa_flags & SA_RESTORER) { | 209 | /* addi r12, r0, __NR_sigreturn */ |
328 | regs->r15 = ((unsigned long)ka->sa.sa_restorer)-8; | 210 | err |= __put_user(0x31800000 | __NR_rt_sigreturn , |
329 | } else { | 211 | frame->tramp + 0); |
330 | /* addi r12, r0, __NR_sigreturn */ | 212 | /* brki r14, 0x8 */ |
331 | err |= __put_user(0x31800000 | __NR_rt_sigreturn , | 213 | err |= __put_user(0xb9cc0008, frame->tramp + 1); |
332 | frame->tramp + 0); | 214 | |
333 | /* brki r14, 0x8 */ | 215 | /* Return from sighandler will jump to the tramp. |
334 | err |= __put_user(0xb9cc0008, frame->tramp + 1); | 216 | Negative 8 offset because return is rtsd r15, 8 */ |
335 | 217 | regs->r15 = ((unsigned long)frame->tramp)-8; | |
336 | /* Return from sighandler will jump to the tramp. | 218 | |
337 | Negative 8 offset because return is rtsd r15, 8 */ | 219 | __invalidate_cache_sigtramp((unsigned long)frame->tramp); |
338 | regs->r15 = ((unsigned long)frame->tramp)-8; | ||
339 | |||
340 | __invalidate_cache_sigtramp((unsigned long)frame->tramp); | ||
341 | } | ||
342 | 220 | ||
343 | if (err) | 221 | if (err) |
344 | goto give_sigsegv; | 222 | goto give_sigsegv; |
@@ -405,7 +283,7 @@ do_restart: | |||
405 | * OK, we're invoking a handler | 283 | * OK, we're invoking a handler |
406 | */ | 284 | */ |
407 | 285 | ||
408 | static void | 286 | static int |
409 | handle_signal(unsigned long sig, struct k_sigaction *ka, | 287 | handle_signal(unsigned long sig, struct k_sigaction *ka, |
410 | siginfo_t *info, sigset_t *oldset, struct pt_regs *regs) | 288 | siginfo_t *info, sigset_t *oldset, struct pt_regs *regs) |
411 | { | 289 | { |
@@ -426,6 +304,7 @@ handle_signal(unsigned long sig, struct k_sigaction *ka, | |||
426 | recalc_sigpending(); | 304 | recalc_sigpending(); |
427 | spin_unlock_irq(¤t->sighand->siglock); | 305 | spin_unlock_irq(¤t->sighand->siglock); |
428 | } | 306 | } |
307 | return 1; | ||
429 | } | 308 | } |
430 | 309 | ||
431 | /* | 310 | /* |
@@ -456,7 +335,9 @@ int do_signal(struct pt_regs *regs, sigset_t *oldset, int in_syscall) | |||
456 | if (kernel_mode(regs)) | 335 | if (kernel_mode(regs)) |
457 | return 1; | 336 | return 1; |
458 | 337 | ||
459 | if (!oldset) | 338 | if (current_thread_info()->status & TS_RESTORE_SIGMASK) |
339 | oldset = ¤t->saved_sigmask; | ||
340 | else | ||
460 | oldset = ¤t->blocked; | 341 | oldset = ¤t->blocked; |
461 | 342 | ||
462 | signr = get_signal_to_deliver(&info, &ka, regs, NULL); | 343 | signr = get_signal_to_deliver(&info, &ka, regs, NULL); |
@@ -464,13 +345,31 @@ int do_signal(struct pt_regs *regs, sigset_t *oldset, int in_syscall) | |||
464 | /* Whee! Actually deliver the signal. */ | 345 | /* Whee! Actually deliver the signal. */ |
465 | if (in_syscall) | 346 | if (in_syscall) |
466 | handle_restart(regs, &ka, 1); | 347 | handle_restart(regs, &ka, 1); |
467 | handle_signal(signr, &ka, &info, oldset, regs); | 348 | if (handle_signal(signr, &ka, &info, oldset, regs)) { |
349 | /* | ||
350 | * A signal was successfully delivered; the saved | ||
351 | * sigmask will have been stored in the signal frame, | ||
352 | * and will be restored by sigreturn, so we can simply | ||
353 | * clear the TS_RESTORE_SIGMASK flag. | ||
354 | */ | ||
355 | current_thread_info()->status &= | ||
356 | ~TS_RESTORE_SIGMASK; | ||
357 | } | ||
468 | return 1; | 358 | return 1; |
469 | } | 359 | } |
470 | 360 | ||
471 | if (in_syscall) | 361 | if (in_syscall) |
472 | handle_restart(regs, NULL, 0); | 362 | handle_restart(regs, NULL, 0); |
473 | 363 | ||
364 | /* | ||
365 | * If there's no signal to deliver, we just put the saved sigmask | ||
366 | * back. | ||
367 | */ | ||
368 | if (current_thread_info()->status & TS_RESTORE_SIGMASK) { | ||
369 | current_thread_info()->status &= ~TS_RESTORE_SIGMASK; | ||
370 | sigprocmask(SIG_SETMASK, ¤t->saved_sigmask, NULL); | ||
371 | } | ||
372 | |||
474 | /* Did we come from a system call? */ | 373 | /* Did we come from a system call? */ |
475 | return 0; | 374 | return 0; |
476 | } | 375 | } |