~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/arch/frv/kernel/signal.c

Version: ~ [ linux-5.3-rc5 ] ~ [ linux-5.2.9 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.67 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.139 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.189 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.189 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.19.8 ] ~ [ linux-3.18.140 ] ~ [ linux-3.17.8 ] ~ [ linux-3.16.72 ] ~ [ linux-3.15.10 ] ~ [ linux-3.14.79 ] ~ [ linux-3.13.11 ] ~ [ linux-3.12.74 ] ~ [ linux-3.11.10 ] ~ [ linux-3.10.108 ] ~ [ linux-3.9.11 ] ~ [ linux-3.8.13 ] ~ [ linux-3.7.10 ] ~ [ linux-3.6.11 ] ~ [ linux-3.5.7 ] ~ [ linux-3.4.113 ] ~ [ linux-3.3.8 ] ~ [ linux-3.2.102 ] ~ [ linux-3.1.10 ] ~ [ linux-3.0.101 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.5 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /* signal.c: FRV specific bits of signal handling
  2  *
  3  * Copyright (C) 2003-5 Red Hat, Inc. All Rights Reserved.
  4  * Written by David Howells (dhowells@redhat.com)
  5  * - Derived from arch/m68k/kernel/signal.c
  6  *
  7  * This program is free software; you can redistribute it and/or
  8  * modify it under the terms of the GNU General Public License
  9  * as published by the Free Software Foundation; either version
 10  * 2 of the License, or (at your option) any later version.
 11  */
 12 
 13 #include <linux/sched.h>
 14 #include <linux/mm.h>
 15 #include <linux/smp.h>
 16 #include <linux/kernel.h>
 17 #include <linux/signal.h>
 18 #include <linux/errno.h>
 19 #include <linux/wait.h>
 20 #include <linux/ptrace.h>
 21 #include <linux/unistd.h>
 22 #include <linux/personality.h>
 23 #include <linux/tracehook.h>
 24 #include <asm/ucontext.h>
 25 #include <asm/uaccess.h>
 26 #include <asm/cacheflush.h>
 27 
 28 #define DEBUG_SIG 0
 29 
 30 struct fdpic_func_descriptor {
 31         unsigned long   text;
 32         unsigned long   GOT;
 33 };
 34 
 35 /*
 36  * Atomically swap in the new signal mask, and wait for a signal.
 37  */
 38 asmlinkage int sys_sigsuspend(int history0, int history1, old_sigset_t mask)
 39 {
 40         sigset_t blocked;
 41         siginitset(&blocked, mask);
 42         return sigsuspend(&blocked);
 43 }
 44 
 45 asmlinkage int sys_sigaction(int sig,
 46                              const struct old_sigaction __user *act,
 47                              struct old_sigaction __user *oact)
 48 {
 49         struct k_sigaction new_ka, old_ka;
 50         int ret;
 51 
 52         if (act) {
 53                 old_sigset_t mask;
 54                 if (!access_ok(VERIFY_READ, act, sizeof(*act)) ||
 55                     __get_user(new_ka.sa.sa_handler, &act->sa_handler) ||
 56                     __get_user(new_ka.sa.sa_restorer, &act->sa_restorer) ||
 57                     __get_user(new_ka.sa.sa_flags, &act->sa_flags) ||
 58                     __get_user(mask, &act->sa_mask))
 59                         return -EFAULT;
 60                 siginitset(&new_ka.sa.sa_mask, mask);
 61         }
 62 
 63         ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL);
 64 
 65         if (!ret && oact) {
 66                 if (!access_ok(VERIFY_WRITE, oact, sizeof(*oact)) ||
 67                     __put_user(old_ka.sa.sa_handler, &oact->sa_handler) ||
 68                     __put_user(old_ka.sa.sa_restorer, &oact->sa_restorer) ||
 69                     __put_user(old_ka.sa.sa_flags, &oact->sa_flags) ||
 70                     __put_user(old_ka.sa.sa_mask.sig[0], &oact->sa_mask))
 71                         return -EFAULT;
 72         }
 73 
 74         return ret;
 75 }
 76 
 77 asmlinkage
 78 int sys_sigaltstack(const stack_t __user *uss, stack_t __user *uoss)
 79 {
 80         return do_sigaltstack(uss, uoss, __frame->sp);
 81 }
 82 
 83 
 84 /*
 85  * Do a signal return; undo the signal stack.
 86  */
 87 
 88 struct sigframe
 89 {
 90         __sigrestore_t pretcode;
 91         int sig;
 92         struct sigcontext sc;
 93         unsigned long extramask[_NSIG_WORDS-1];
 94         uint32_t retcode[2];
 95 };
 96 
 97 struct rt_sigframe
 98 {
 99         __sigrestore_t pretcode;
100         int sig;
101         struct siginfo __user *pinfo;
102         void __user *puc;
103         struct siginfo info;
104         struct ucontext uc;
105         uint32_t retcode[2];
106 };
107 
108 static int restore_sigcontext(struct sigcontext __user *sc, int *_gr8)
109 {
110         struct user_context *user = current->thread.user;
111         unsigned long tbr, psr;
112 
113         /* Always make any pending restarted system calls return -EINTR */
114         current_thread_info()->restart_block.fn = do_no_restart_syscall;
115 
116         tbr = user->i.tbr;
117         psr = user->i.psr;
118         if (copy_from_user(user, &sc->sc_context, sizeof(sc->sc_context)))
119                 goto badframe;
120         user->i.tbr = tbr;
121         user->i.psr = psr;
122 
123         restore_user_regs(user);
124 
125         user->i.syscallno = -1;         /* disable syscall checks */
126 
127         *_gr8 = user->i.gr[8];
128         return 0;
129 
130  badframe:
131         return 1;
132 }
133 
134 asmlinkage int sys_sigreturn(void)
135 {
136         struct sigframe __user *frame = (struct sigframe __user *) __frame->sp;
137         sigset_t set;
138         int gr8;
139 
140         if (!access_ok(VERIFY_READ, frame, sizeof(*frame)))
141                 goto badframe;
142         if (__get_user(set.sig[0], &frame->sc.sc_oldmask))
143                 goto badframe;
144 
145         if (_NSIG_WORDS > 1 &&
146             __copy_from_user(&set.sig[1], &frame->extramask, sizeof(frame->extramask)))
147                 goto badframe;
148 
149         set_current_blocked(&set);
150 
151         if (restore_sigcontext(&frame->sc, &gr8))
152                 goto badframe;
153         return gr8;
154 
155  badframe:
156         force_sig(SIGSEGV, current);
157         return 0;
158 }
159 
160 asmlinkage int sys_rt_sigreturn(void)
161 {
162         struct rt_sigframe __user *frame = (struct rt_sigframe __user *) __frame->sp;
163         sigset_t set;
164         int gr8;
165 
166         if (!access_ok(VERIFY_READ, frame, sizeof(*frame)))
167                 goto badframe;
168         if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set)))
169                 goto badframe;
170 
171         set_current_blocked(&set);
172 
173         if (restore_sigcontext(&frame->uc.uc_mcontext, &gr8))
174                 goto badframe;
175 
176         if (do_sigaltstack(&frame->uc.uc_stack, NULL, __frame->sp) == -EFAULT)
177                 goto badframe;
178 
179         return gr8;
180 
181 badframe:
182         force_sig(SIGSEGV, current);
183         return 0;
184 }
185 
186 /*
187  * Set up a signal frame
188  */
189 static int setup_sigcontext(struct sigcontext __user *sc, unsigned long mask)
190 {
191         save_user_regs(current->thread.user);
192 
193         if (copy_to_user(&sc->sc_context, current->thread.user, sizeof(sc->sc_context)) != 0)
194                 goto badframe;
195 
196         /* non-iBCS2 extensions.. */
197         if (__put_user(mask, &sc->sc_oldmask) < 0)
198                 goto badframe;
199 
200         return 0;
201 
202  badframe:
203         return 1;
204 }
205 
206 /*****************************************************************************/
207 /*
208  * Determine which stack to use..
209  */
210 static inline void __user *get_sigframe(struct k_sigaction *ka,
211                                         size_t frame_size)
212 {
213         unsigned long sp;
214 
215         /* Default to using normal stack */
216         sp = __frame->sp;
217 
218         /* This is the X/Open sanctioned signal stack switching.  */
219         if (ka->sa.sa_flags & SA_ONSTACK) {
220                 if (! sas_ss_flags(sp))
221                         sp = current->sas_ss_sp + current->sas_ss_size;
222         }
223 
224         return (void __user *) ((sp - frame_size) & ~7UL);
225 
226 } /* end get_sigframe() */
227 
228 /*****************************************************************************/
229 /*
230  *
231  */
232 static int setup_frame(int sig, struct k_sigaction *ka, sigset_t *set)
233 {
234         struct sigframe __user *frame;
235         int rsig;
236 
237         set_fs(USER_DS);
238 
239         frame = get_sigframe(ka, sizeof(*frame));
240 
241         if (!access_ok(VERIFY_WRITE, frame, sizeof(*frame)))
242                 goto give_sigsegv;
243 
244         rsig = sig;
245         if (sig < 32 &&
246             __current_thread_info->exec_domain &&
247             __current_thread_info->exec_domain->signal_invmap)
248                 rsig = __current_thread_info->exec_domain->signal_invmap[sig];
249 
250         if (__put_user(rsig, &frame->sig) < 0)
251                 goto give_sigsegv;
252 
253         if (setup_sigcontext(&frame->sc, set->sig[0]))
254                 goto give_sigsegv;
255 
256         if (_NSIG_WORDS > 1) {
257                 if (__copy_to_user(frame->extramask, &set->sig[1],
258                                    sizeof(frame->extramask)))
259                         goto give_sigsegv;
260         }
261 
262         /* Set up to return from userspace.  If provided, use a stub
263          * already in userspace.  */
264         if (ka->sa.sa_flags & SA_RESTORER) {
265                 if (__put_user(ka->sa.sa_restorer, &frame->pretcode) < 0)
266                         goto give_sigsegv;
267         }
268         else {
269                 /* Set up the following code on the stack:
270                  *      setlos  #__NR_sigreturn,gr7
271                  *      tira    gr0,0
272                  */
273                 if (__put_user((__sigrestore_t)frame->retcode, &frame->pretcode) ||
274                     __put_user(0x8efc0000|__NR_sigreturn, &frame->retcode[0]) ||
275                     __put_user(0xc0700000, &frame->retcode[1]))
276                         goto give_sigsegv;
277 
278                 flush_icache_range((unsigned long) frame->retcode,
279                                    (unsigned long) (frame->retcode + 2));
280         }
281 
282         /* Set up registers for the signal handler */
283         if (current->personality & FDPIC_FUNCPTRS) {
284                 struct fdpic_func_descriptor __user *funcptr =
285                         (struct fdpic_func_descriptor __user *) ka->sa.sa_handler;
286                 struct fdpic_func_descriptor desc;
287                 if (copy_from_user(&desc, funcptr, sizeof(desc)))
288                         goto give_sigsegv;
289                 __frame->pc = desc.text;
290                 __frame->gr15 = desc.GOT;
291         } else {
292                 __frame->pc   = (unsigned long) ka->sa.sa_handler;
293                 __frame->gr15 = 0;
294         }
295 
296         __frame->sp   = (unsigned long) frame;
297         __frame->lr   = (unsigned long) &frame->retcode;
298         __frame->gr8  = sig;
299 
300 #if DEBUG_SIG
301         printk("SIG deliver %d (%s:%d): sp=%p pc=%lx ra=%p\n",
302                sig, current->comm, current->pid, frame, __frame->pc,
303                frame->pretcode);
304 #endif
305 
306         return 0;
307 
308 give_sigsegv:
309         force_sigsegv(sig, current);
310         return -EFAULT;
311 
312 } /* end setup_frame() */
313 
314 /*****************************************************************************/
315 /*
316  *
317  */
318 static int setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
319                           sigset_t *set)
320 {
321         struct rt_sigframe __user *frame;
322         int rsig;
323 
324         set_fs(USER_DS);
325 
326         frame = get_sigframe(ka, sizeof(*frame));
327 
328         if (!access_ok(VERIFY_WRITE, frame, sizeof(*frame)))
329                 goto give_sigsegv;
330 
331         rsig = sig;
332         if (sig < 32 &&
333             __current_thread_info->exec_domain &&
334             __current_thread_info->exec_domain->signal_invmap)
335                 rsig = __current_thread_info->exec_domain->signal_invmap[sig];
336 
337         if (__put_user(rsig,            &frame->sig) ||
338             __put_user(&frame->info,    &frame->pinfo) ||
339             __put_user(&frame->uc,      &frame->puc))
340                 goto give_sigsegv;
341 
342         if (copy_siginfo_to_user(&frame->info, info))
343                 goto give_sigsegv;
344 
345         /* Create the ucontext.  */
346         if (__put_user(0, &frame->uc.uc_flags) ||
347             __put_user(NULL, &frame->uc.uc_link) ||
348             __put_user((void __user *)current->sas_ss_sp, &frame->uc.uc_stack.ss_sp) ||
349             __put_user(sas_ss_flags(__frame->sp), &frame->uc.uc_stack.ss_flags) ||
350             __put_user(current->sas_ss_size, &frame->uc.uc_stack.ss_size))
351                 goto give_sigsegv;
352 
353         if (setup_sigcontext(&frame->uc.uc_mcontext, set->sig[0]))
354                 goto give_sigsegv;
355 
356         if (__copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set)))
357                 goto give_sigsegv;
358 
359         /* Set up to return from userspace.  If provided, use a stub
360          * already in userspace.  */
361         if (ka->sa.sa_flags & SA_RESTORER) {
362                 if (__put_user(ka->sa.sa_restorer, &frame->pretcode))
363                         goto give_sigsegv;
364         }
365         else {
366                 /* Set up the following code on the stack:
367                  *      setlos  #__NR_sigreturn,gr7
368                  *      tira    gr0,0
369                  */
370                 if (__put_user((__sigrestore_t)frame->retcode, &frame->pretcode) ||
371                     __put_user(0x8efc0000|__NR_rt_sigreturn, &frame->retcode[0]) ||
372                     __put_user(0xc0700000, &frame->retcode[1]))
373                         goto give_sigsegv;
374 
375                 flush_icache_range((unsigned long) frame->retcode,
376                                    (unsigned long) (frame->retcode + 2));
377         }
378 
379         /* Set up registers for signal handler */
380         if (current->personality & FDPIC_FUNCPTRS) {
381                 struct fdpic_func_descriptor __user *funcptr =
382                         (struct fdpic_func_descriptor __user *) ka->sa.sa_handler;
383                 struct fdpic_func_descriptor desc;
384                 if (copy_from_user(&desc, funcptr, sizeof(desc)))
385                         goto give_sigsegv;
386                 __frame->pc = desc.text;
387                 __frame->gr15 = desc.GOT;
388         } else {
389                 __frame->pc   = (unsigned long) ka->sa.sa_handler;
390                 __frame->gr15 = 0;
391         }
392 
393         __frame->sp  = (unsigned long) frame;
394         __frame->lr  = (unsigned long) &frame->retcode;
395         __frame->gr8 = sig;
396         __frame->gr9 = (unsigned long) &frame->info;
397 
398 #if DEBUG_SIG
399         printk("SIG deliver %d (%s:%d): sp=%p pc=%lx ra=%p\n",
400                sig, current->comm, current->pid, frame, __frame->pc,
401                frame->pretcode);
402 #endif
403 
404         return 0;
405 
406 give_sigsegv:
407         force_sigsegv(sig, current);
408         return -EFAULT;
409 
410 } /* end setup_rt_frame() */
411 
412 /*****************************************************************************/
413 /*
414  * OK, we're invoking a handler
415  */
416 static void handle_signal(unsigned long sig, siginfo_t *info,
417                          struct k_sigaction *ka)
418 {
419         sigset_t *oldset = sigmask_to_save();
420         int ret;
421 
422         /* Are we from a system call? */
423         if (__frame->syscallno != -1) {
424                 /* If so, check system call restarting.. */
425                 switch (__frame->gr8) {
426                 case -ERESTART_RESTARTBLOCK:
427                 case -ERESTARTNOHAND:
428                         __frame->gr8 = -EINTR;
429                         break;
430 
431                 case -ERESTARTSYS:
432                         if (!(ka->sa.sa_flags & SA_RESTART)) {
433                                 __frame->gr8 = -EINTR;
434                                 break;
435                         }
436 
437                         /* fallthrough */
438                 case -ERESTARTNOINTR:
439                         __frame->gr8 = __frame->orig_gr8;
440                         __frame->pc -= 4;
441                 }
442                 __frame->syscallno = -1;
443         }
444 
445         /* Set up the stack frame */
446         if (ka->sa.sa_flags & SA_SIGINFO)
447                 ret = setup_rt_frame(sig, ka, info, oldset);
448         else
449                 ret = setup_frame(sig, ka, oldset);
450 
451         if (ret)
452                 return;
453 
454         signal_delivered(sig, info, ka, __frame,
455                                  test_thread_flag(TIF_SINGLESTEP));
456 } /* end handle_signal() */
457 
458 /*****************************************************************************/
459 /*
460  * Note that 'init' is a special process: it doesn't get signals it doesn't
461  * want to handle. Thus you cannot kill init even with a SIGKILL even by
462  * mistake.
463  */
464 static void do_signal(void)
465 {
466         struct k_sigaction ka;
467         siginfo_t info;
468         int signr;
469 
470         signr = get_signal_to_deliver(&info, &ka, __frame, NULL);
471         if (signr > 0) {
472                 handle_signal(signr, &info, &ka);
473                 return;
474         }
475 
476         /* Did we come from a system call? */
477         if (__frame->syscallno != -1) {
478                 /* Restart the system call - no handlers present */
479                 switch (__frame->gr8) {
480                 case -ERESTARTNOHAND:
481                 case -ERESTARTSYS:
482                 case -ERESTARTNOINTR:
483                         __frame->gr8 = __frame->orig_gr8;
484                         __frame->pc -= 4;
485                         break;
486 
487                 case -ERESTART_RESTARTBLOCK:
488                         __frame->gr7 = __NR_restart_syscall;
489                         __frame->pc -= 4;
490                         break;
491                 }
492                 __frame->syscallno = -1;
493         }
494 
495         /* if there's no signal to deliver, we just put the saved sigmask
496          * back */
497         restore_saved_sigmask();
498 } /* end do_signal() */
499 
500 /*****************************************************************************/
501 /*
502  * notification of userspace execution resumption
503  * - triggered by the TIF_WORK_MASK flags
504  */
505 asmlinkage void do_notify_resume(__u32 thread_info_flags)
506 {
507         /* pending single-step? */
508         if (thread_info_flags & _TIF_SINGLESTEP)
509                 clear_thread_flag(TIF_SINGLESTEP);
510 
511         /* deal with pending signal delivery */
512         if (thread_info_flags & _TIF_SIGPENDING)
513                 do_signal();
514 
515         /* deal with notification on about to resume userspace execution */
516         if (thread_info_flags & _TIF_NOTIFY_RESUME) {
517                 clear_thread_flag(TIF_NOTIFY_RESUME);
518                 tracehook_notify_resume(__frame);
519         }
520 
521 } /* end do_notify_resume() */
522 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | Wiki (Japanese) | Wiki (English) | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

osdn.jp