diff options
Diffstat (limited to 'arch/microblaze/kernel/signal.c')
-rw-r--r-- | arch/microblaze/kernel/signal.c | 174 |
1 files changed, 37 insertions, 137 deletions
diff --git a/arch/microblaze/kernel/signal.c b/arch/microblaze/kernel/signal.c index 4c0e6521b114..493819c25fba 100644 --- a/arch/microblaze/kernel/signal.c +++ b/arch/microblaze/kernel/signal.c | |||
@@ -45,91 +45,8 @@ | |||
45 | 45 | ||
46 | asmlinkage int do_signal(struct pt_regs *regs, sigset_t *oldset, int in_sycall); | 46 | asmlinkage int do_signal(struct pt_regs *regs, sigset_t *oldset, int in_sycall); |
47 | 47 | ||
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 | 48 | ||
118 | ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL); | 49 | 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, | 50 | sys_sigaltstack(const stack_t __user *uss, stack_t __user *uoss, |
134 | struct pt_regs *regs) | 51 | struct pt_regs *regs) |
135 | { | 52 | { |
@@ -139,7 +56,6 @@ sys_sigaltstack(const stack_t __user *uss, stack_t __user *uoss, | |||
139 | /* | 56 | /* |
140 | * Do a signal return; undo the signal stack. | 57 | * Do a signal return; undo the signal stack. |
141 | */ | 58 | */ |
142 | |||
143 | struct sigframe { | 59 | struct sigframe { |
144 | struct sigcontext sc; | 60 | struct sigcontext sc; |
145 | unsigned long extramask[_NSIG_WORDS-1]; | 61 | unsigned long extramask[_NSIG_WORDS-1]; |
@@ -176,40 +92,7 @@ static int restore_sigcontext(struct pt_regs *regs, | |||
176 | return err; | 92 | return err; |
177 | } | 93 | } |
178 | 94 | ||
179 | asmlinkage int sys_sigreturn(struct pt_regs *regs) | 95 | 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 | { | 96 | { |
214 | struct rt_sigframe __user *frame = | 97 | struct rt_sigframe __user *frame = |
215 | (struct rt_sigframe __user *)(regs->r1 + STATE_SAVE_ARG_SPACE); | 98 | (struct rt_sigframe __user *)(regs->r1 + STATE_SAVE_ARG_SPACE); |
@@ -324,21 +207,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 | 207 | /* Set up to return from userspace. If provided, use a stub |
325 | already in userspace. */ | 208 | already in userspace. */ |
326 | /* minus 8 is offset to cater for "rtsd r15,8" */ | 209 | /* minus 8 is offset to cater for "rtsd r15,8" */ |
327 | if (ka->sa.sa_flags & SA_RESTORER) { | 210 | /* addi r12, r0, __NR_sigreturn */ |
328 | regs->r15 = ((unsigned long)ka->sa.sa_restorer)-8; | 211 | err |= __put_user(0x31800000 | __NR_rt_sigreturn , |
329 | } else { | 212 | frame->tramp + 0); |
330 | /* addi r12, r0, __NR_sigreturn */ | 213 | /* brki r14, 0x8 */ |
331 | err |= __put_user(0x31800000 | __NR_rt_sigreturn , | 214 | err |= __put_user(0xb9cc0008, frame->tramp + 1); |
332 | frame->tramp + 0); | 215 | |
333 | /* brki r14, 0x8 */ | 216 | /* Return from sighandler will jump to the tramp. |
334 | err |= __put_user(0xb9cc0008, frame->tramp + 1); | 217 | Negative 8 offset because return is rtsd r15, 8 */ |
335 | 218 | regs->r15 = ((unsigned long)frame->tramp)-8; | |
336 | /* Return from sighandler will jump to the tramp. | 219 | |
337 | Negative 8 offset because return is rtsd r15, 8 */ | 220 | __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 | 221 | ||
343 | if (err) | 222 | if (err) |
344 | goto give_sigsegv; | 223 | goto give_sigsegv; |
@@ -405,7 +284,7 @@ do_restart: | |||
405 | * OK, we're invoking a handler | 284 | * OK, we're invoking a handler |
406 | */ | 285 | */ |
407 | 286 | ||
408 | static void | 287 | static int |
409 | handle_signal(unsigned long sig, struct k_sigaction *ka, | 288 | handle_signal(unsigned long sig, struct k_sigaction *ka, |
410 | siginfo_t *info, sigset_t *oldset, struct pt_regs *regs) | 289 | siginfo_t *info, sigset_t *oldset, struct pt_regs *regs) |
411 | { | 290 | { |
@@ -426,6 +305,7 @@ handle_signal(unsigned long sig, struct k_sigaction *ka, | |||
426 | recalc_sigpending(); | 305 | recalc_sigpending(); |
427 | spin_unlock_irq(¤t->sighand->siglock); | 306 | spin_unlock_irq(¤t->sighand->siglock); |
428 | } | 307 | } |
308 | return 1; | ||
429 | } | 309 | } |
430 | 310 | ||
431 | /* | 311 | /* |
@@ -456,7 +336,9 @@ int do_signal(struct pt_regs *regs, sigset_t *oldset, int in_syscall) | |||
456 | if (kernel_mode(regs)) | 336 | if (kernel_mode(regs)) |
457 | return 1; | 337 | return 1; |
458 | 338 | ||
459 | if (!oldset) | 339 | if (current_thread_info()->status & TS_RESTORE_SIGMASK) |
340 | oldset = ¤t->saved_sigmask; | ||
341 | else | ||
460 | oldset = ¤t->blocked; | 342 | oldset = ¤t->blocked; |
461 | 343 | ||
462 | signr = get_signal_to_deliver(&info, &ka, regs, NULL); | 344 | signr = get_signal_to_deliver(&info, &ka, regs, NULL); |
@@ -464,13 +346,31 @@ int do_signal(struct pt_regs *regs, sigset_t *oldset, int in_syscall) | |||
464 | /* Whee! Actually deliver the signal. */ | 346 | /* Whee! Actually deliver the signal. */ |
465 | if (in_syscall) | 347 | if (in_syscall) |
466 | handle_restart(regs, &ka, 1); | 348 | handle_restart(regs, &ka, 1); |
467 | handle_signal(signr, &ka, &info, oldset, regs); | 349 | if (handle_signal(signr, &ka, &info, oldset, regs)) { |
350 | /* | ||
351 | * A signal was successfully delivered; the saved | ||
352 | * sigmask will have been stored in the signal frame, | ||
353 | * and will be restored by sigreturn, so we can simply | ||
354 | * clear the TS_RESTORE_SIGMASK flag. | ||
355 | */ | ||
356 | current_thread_info()->status &= | ||
357 | ~TS_RESTORE_SIGMASK; | ||
358 | } | ||
468 | return 1; | 359 | return 1; |
469 | } | 360 | } |
470 | 361 | ||
471 | if (in_syscall) | 362 | if (in_syscall) |
472 | handle_restart(regs, NULL, 0); | 363 | handle_restart(regs, NULL, 0); |
473 | 364 | ||
365 | /* | ||
366 | * If there's no signal to deliver, we just put the saved sigmask | ||
367 | * back. | ||
368 | */ | ||
369 | if (current_thread_info()->status & TS_RESTORE_SIGMASK) { | ||
370 | current_thread_info()->status &= ~TS_RESTORE_SIGMASK; | ||
371 | sigprocmask(SIG_SETMASK, ¤t->saved_sigmask, NULL); | ||
372 | } | ||
373 | |||
474 | /* Did we come from a system call? */ | 374 | /* Did we come from a system call? */ |
475 | return 0; | 375 | return 0; |
476 | } | 376 | } |