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

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

Version: ~ [ linux-5.6-rc1 ] ~ [ linux-5.5.2 ] ~ [ linux-5.4.17 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.102 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.170 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.213 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.213 ] ~ [ 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.81 ] ~ [ 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 /*
  2  *  linux/arch/m32r/kernel/signal.c
  3  *
  4  *  Copyright (c) 2003  Hitoshi Yamamoto
  5  *
  6  *  Taken from i386 version.
  7  *  Copyright (C) 1991, 1992  Linus Torvalds
  8  *
  9  *  1997-11-28  Modified for POSIX.1b signals by Richard Henderson
 10  *  2000-06-20  Pentium III FXSR, SSE support by Gareth Hughes
 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/unistd.h>
 21 #include <linux/stddef.h>
 22 #include <linux/personality.h>
 23 #include <linux/tracehook.h>
 24 #include <asm/cacheflush.h>
 25 #include <asm/ucontext.h>
 26 #include <asm/uaccess.h>
 27 
 28 #define DEBUG_SIG 0
 29 
 30 /*
 31  * Do a signal return; undo the signal stack.
 32  */
 33 
 34 struct rt_sigframe
 35 {
 36         int sig;
 37         struct siginfo __user *pinfo;
 38         void __user *puc;
 39         struct siginfo info;
 40         struct ucontext uc;
 41 //      struct _fpstate fpstate;
 42 };
 43 
 44 static int
 45 restore_sigcontext(struct pt_regs *regs, struct sigcontext __user *sc,
 46                    int *r0_p)
 47 {
 48         unsigned int err = 0;
 49 
 50         /* Always make any pending restarted system calls return -EINTR */
 51         current_thread_info()->restart_block.fn = do_no_restart_syscall;
 52 
 53 #define COPY(x)         err |= __get_user(regs->x, &sc->sc_##x)
 54         COPY(r4);
 55         COPY(r5);
 56         COPY(r6);
 57         COPY(pt_regs);
 58         /* COPY(r0); Skip r0 */
 59         COPY(r1);
 60         COPY(r2);
 61         COPY(r3);
 62         COPY(r7);
 63         COPY(r8);
 64         COPY(r9);
 65         COPY(r10);
 66         COPY(r11);
 67         COPY(r12);
 68         COPY(acc0h);
 69         COPY(acc0l);
 70         COPY(acc1h);            /* ISA_DSP_LEVEL2 only */
 71         COPY(acc1l);            /* ISA_DSP_LEVEL2 only */
 72         COPY(psw);
 73         COPY(bpc);
 74         COPY(bbpsw);
 75         COPY(bbpc);
 76         COPY(spu);
 77         COPY(fp);
 78         COPY(lr);
 79         COPY(spi);
 80 #undef COPY
 81 
 82         regs->syscall_nr = -1;  /* disable syscall checks */
 83         err |= __get_user(*r0_p, &sc->sc_r0);
 84 
 85         return err;
 86 }
 87 
 88 asmlinkage int
 89 sys_rt_sigreturn(unsigned long r0, unsigned long r1,
 90                  unsigned long r2, unsigned long r3, unsigned long r4,
 91                  unsigned long r5, unsigned long r6, struct pt_regs *regs)
 92 {
 93         struct rt_sigframe __user *frame = (struct rt_sigframe __user *)regs->spu;
 94         sigset_t set;
 95         int result;
 96 
 97         if (!access_ok(VERIFY_READ, frame, sizeof(*frame)))
 98                 goto badframe;
 99         if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set)))
100                 goto badframe;
101 
102         set_current_blocked(&set);
103 
104         if (restore_sigcontext(regs, &frame->uc.uc_mcontext, &result))
105                 goto badframe;
106 
107         if (restore_altstack(&frame->uc.uc_stack))
108                 goto badframe;
109 
110         return result;
111 
112 badframe:
113         force_sig(SIGSEGV, current);
114         return 0;
115 }
116 
117 /*
118  * Set up a signal frame.
119  */
120 
121 static int
122 setup_sigcontext(struct sigcontext __user *sc, struct pt_regs *regs,
123                  unsigned long mask)
124 {
125         int err = 0;
126 
127 #define COPY(x) err |= __put_user(regs->x, &sc->sc_##x)
128         COPY(r4);
129         COPY(r5);
130         COPY(r6);
131         COPY(pt_regs);
132         COPY(r0);
133         COPY(r1);
134         COPY(r2);
135         COPY(r3);
136         COPY(r7);
137         COPY(r8);
138         COPY(r9);
139         COPY(r10);
140         COPY(r11);
141         COPY(r12);
142         COPY(acc0h);
143         COPY(acc0l);
144         COPY(acc1h);            /* ISA_DSP_LEVEL2 only */
145         COPY(acc1l);            /* ISA_DSP_LEVEL2 only */
146         COPY(psw);
147         COPY(bpc);
148         COPY(bbpsw);
149         COPY(bbpc);
150         COPY(spu);
151         COPY(fp);
152         COPY(lr);
153         COPY(spi);
154 #undef COPY
155 
156         err |= __put_user(mask, &sc->oldmask);
157 
158         return err;
159 }
160 
161 /*
162  * Determine which stack to use..
163  */
164 static inline void __user *
165 get_sigframe(struct k_sigaction *ka, unsigned long sp, size_t frame_size)
166 {
167         /* This is the X/Open sanctioned signal stack switching.  */
168         if (ka->sa.sa_flags & SA_ONSTACK) {
169                 if (sas_ss_flags(sp) == 0)
170                         sp = current->sas_ss_sp + current->sas_ss_size;
171         }
172 
173         return (void __user *)((sp - frame_size) & -8ul);
174 }
175 
176 static int setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
177                            sigset_t *set, struct pt_regs *regs)
178 {
179         struct rt_sigframe __user *frame;
180         int err = 0;
181         int signal;
182 
183         frame = get_sigframe(ka, regs->spu, sizeof(*frame));
184 
185         if (!access_ok(VERIFY_WRITE, frame, sizeof(*frame)))
186                 goto give_sigsegv;
187 
188         signal = current_thread_info()->exec_domain
189                 && current_thread_info()->exec_domain->signal_invmap
190                 && sig < 32
191                 ? current_thread_info()->exec_domain->signal_invmap[sig]
192                 : sig;
193 
194         err |= __put_user(signal, &frame->sig);
195         if (err)
196                 goto give_sigsegv;
197 
198         err |= __put_user(&frame->info, &frame->pinfo);
199         err |= __put_user(&frame->uc, &frame->puc);
200         err |= copy_siginfo_to_user(&frame->info, info);
201         if (err)
202                 goto give_sigsegv;
203 
204         /* Create the ucontext.  */
205         err |= __put_user(0, &frame->uc.uc_flags);
206         err |= __put_user(0, &frame->uc.uc_link);
207         err |= __save_altstack(&frame->uc.uc_stack, regs->spu);
208         err |= setup_sigcontext(&frame->uc.uc_mcontext, regs, set->sig[0]);
209         err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set));
210         if (err)
211                 goto give_sigsegv;
212 
213         /* Set up to return from userspace.  */
214         regs->lr = (unsigned long)ka->sa.sa_restorer;
215 
216         /* Set up registers for signal handler */
217         regs->spu = (unsigned long)frame;
218         regs->r0 = signal;      /* Arg for signal handler */
219         regs->r1 = (unsigned long)&frame->info;
220         regs->r2 = (unsigned long)&frame->uc;
221         regs->bpc = (unsigned long)ka->sa.sa_handler;
222 
223         set_fs(USER_DS);
224 
225 #if DEBUG_SIG
226         printk("SIG deliver (%s:%d): sp=%p pc=%p\n",
227                 current->comm, current->pid, frame, regs->pc);
228 #endif
229 
230         return 0;
231 
232 give_sigsegv:
233         force_sigsegv(sig, current);
234         return -EFAULT;
235 }
236 
237 static int prev_insn(struct pt_regs *regs)
238 {
239         u16 inst;
240         if (get_user(inst, (u16 __user *)(regs->bpc - 2)))
241                 return -EFAULT;
242         if ((inst & 0xfff0) == 0x10f0)  /* trap ? */
243                 regs->bpc -= 2;
244         else
245                 regs->bpc -= 4;
246         regs->syscall_nr = -1;
247         return 0;
248 }
249 
250 /*
251  * OK, we're invoking a handler
252  */
253 
254 static void
255 handle_signal(unsigned long sig, struct k_sigaction *ka, siginfo_t *info,
256               struct pt_regs *regs)
257 {
258         /* Are we from a system call? */
259         if (regs->syscall_nr >= 0) {
260                 /* If so, check system call restarting.. */
261                 switch (regs->r0) {
262                         case -ERESTART_RESTARTBLOCK:
263                         case -ERESTARTNOHAND:
264                                 regs->r0 = -EINTR;
265                                 break;
266 
267                         case -ERESTARTSYS:
268                                 if (!(ka->sa.sa_flags & SA_RESTART)) {
269                                         regs->r0 = -EINTR;
270                                         break;
271                                 }
272                         /* fallthrough */
273                         case -ERESTARTNOINTR:
274                                 regs->r0 = regs->orig_r0;
275                                 if (prev_insn(regs) < 0)
276                                         return;
277                 }
278         }
279 
280         /* Set up the stack frame */
281         if (setup_rt_frame(sig, ka, info, sigmask_to_save(), regs))
282                 return;
283 
284         signal_delivered(sig, info, ka, regs, 0);
285 }
286 
287 /*
288  * Note that 'init' is a special process: it doesn't get signals it doesn't
289  * want to handle. Thus you cannot kill init even with a SIGKILL even by
290  * mistake.
291  */
292 static void do_signal(struct pt_regs *regs)
293 {
294         siginfo_t info;
295         int signr;
296         struct k_sigaction ka;
297 
298         /*
299          * We want the common case to go fast, which
300          * is why we may in certain cases get here from
301          * kernel mode. Just return without doing anything
302          * if so.
303          */
304         if (!user_mode(regs))
305                 return;
306 
307         signr = get_signal_to_deliver(&info, &ka, regs, NULL);
308         if (signr > 0) {
309                 /* Re-enable any watchpoints before delivering the
310                  * signal to user space. The processor register will
311                  * have been cleared if the watchpoint triggered
312                  * inside the kernel.
313                  */
314 
315                 /* Whee!  Actually deliver the signal.  */
316                 handle_signal(signr, &ka, &info, regs);
317 
318                 return;
319         }
320 
321         /* Did we come from a system call? */
322         if (regs->syscall_nr >= 0) {
323                 /* Restart the system call - no handlers present */
324                 if (regs->r0 == -ERESTARTNOHAND ||
325                     regs->r0 == -ERESTARTSYS ||
326                     regs->r0 == -ERESTARTNOINTR) {
327                         regs->r0 = regs->orig_r0;
328                         prev_insn(regs);
329                 } else if (regs->r0 == -ERESTART_RESTARTBLOCK){
330                         regs->r0 = regs->orig_r0;
331                         regs->r7 = __NR_restart_syscall;
332                         prev_insn(regs);
333                 }
334         }
335         restore_saved_sigmask();
336 }
337 
338 /*
339  * notification of userspace execution resumption
340  * - triggered by current->work.notify_resume
341  */
342 void do_notify_resume(struct pt_regs *regs, __u32 thread_info_flags)
343 {
344         /* Pending single-step? */
345         if (thread_info_flags & _TIF_SINGLESTEP)
346                 clear_thread_flag(TIF_SINGLESTEP);
347 
348         /* deal with pending signal delivery */
349         if (thread_info_flags & _TIF_SIGPENDING)
350                 do_signal(regs);
351 
352         if (thread_info_flags & _TIF_NOTIFY_RESUME) {
353                 clear_thread_flag(TIF_NOTIFY_RESUME);
354                 tracehook_notify_resume(regs);
355         }
356 }
357 

~ [ 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