diff options
author | Linus Torvalds <torvalds@ppc970.osdl.org> | 2005-04-16 18:20:36 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@ppc970.osdl.org> | 2005-04-16 18:20:36 -0400 |
commit | 1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 (patch) | |
tree | 0bba044c4ce775e45a88a51686b5d9f90697ea9d /arch/i386/kernel/signal.c |
Linux-2.6.12-rc2v2.6.12-rc2
Initial git repository build. I'm not bothering with the full history,
even though we have it. We can create a separate "historical" git
archive of that later if we want to, and in the meantime it's about
3.2GB when imported into git - space that would just make the early
git days unnecessarily complicated, when we don't have a lot of good
infrastructure for it.
Let it rip!
Diffstat (limited to 'arch/i386/kernel/signal.c')
-rw-r--r-- | arch/i386/kernel/signal.c | 665 |
1 files changed, 665 insertions, 0 deletions
diff --git a/arch/i386/kernel/signal.c b/arch/i386/kernel/signal.c new file mode 100644 index 000000000000..ef3602e1c052 --- /dev/null +++ b/arch/i386/kernel/signal.c | |||
@@ -0,0 +1,665 @@ | |||
1 | /* | ||
2 | * linux/arch/i386/kernel/signal.c | ||
3 | * | ||
4 | * Copyright (C) 1991, 1992 Linus Torvalds | ||
5 | * | ||
6 | * 1997-11-28 Modified for POSIX.1b signals by Richard Henderson | ||
7 | * 2000-06-20 Pentium III FXSR, SSE support by Gareth Hughes | ||
8 | */ | ||
9 | |||
10 | #include <linux/sched.h> | ||
11 | #include <linux/mm.h> | ||
12 | #include <linux/smp.h> | ||
13 | #include <linux/smp_lock.h> | ||
14 | #include <linux/kernel.h> | ||
15 | #include <linux/signal.h> | ||
16 | #include <linux/errno.h> | ||
17 | #include <linux/wait.h> | ||
18 | #include <linux/unistd.h> | ||
19 | #include <linux/stddef.h> | ||
20 | #include <linux/personality.h> | ||
21 | #include <linux/suspend.h> | ||
22 | #include <linux/ptrace.h> | ||
23 | #include <linux/elf.h> | ||
24 | #include <asm/processor.h> | ||
25 | #include <asm/ucontext.h> | ||
26 | #include <asm/uaccess.h> | ||
27 | #include <asm/i387.h> | ||
28 | #include "sigframe.h" | ||
29 | |||
30 | #define DEBUG_SIG 0 | ||
31 | |||
32 | #define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP))) | ||
33 | |||
34 | /* | ||
35 | * Atomically swap in the new signal mask, and wait for a signal. | ||
36 | */ | ||
37 | asmlinkage int | ||
38 | sys_sigsuspend(int history0, int history1, old_sigset_t mask) | ||
39 | { | ||
40 | struct pt_regs * regs = (struct pt_regs *) &history0; | ||
41 | sigset_t saveset; | ||
42 | |||
43 | mask &= _BLOCKABLE; | ||
44 | spin_lock_irq(¤t->sighand->siglock); | ||
45 | saveset = current->blocked; | ||
46 | siginitset(¤t->blocked, mask); | ||
47 | recalc_sigpending(); | ||
48 | spin_unlock_irq(¤t->sighand->siglock); | ||
49 | |||
50 | regs->eax = -EINTR; | ||
51 | while (1) { | ||
52 | current->state = TASK_INTERRUPTIBLE; | ||
53 | schedule(); | ||
54 | if (do_signal(regs, &saveset)) | ||
55 | return -EINTR; | ||
56 | } | ||
57 | } | ||
58 | |||
59 | asmlinkage int | ||
60 | sys_rt_sigsuspend(struct pt_regs regs) | ||
61 | { | ||
62 | sigset_t saveset, newset; | ||
63 | |||
64 | /* XXX: Don't preclude handling different sized sigset_t's. */ | ||
65 | if (regs.ecx != sizeof(sigset_t)) | ||
66 | return -EINVAL; | ||
67 | |||
68 | if (copy_from_user(&newset, (sigset_t __user *)regs.ebx, sizeof(newset))) | ||
69 | return -EFAULT; | ||
70 | sigdelsetmask(&newset, ~_BLOCKABLE); | ||
71 | |||
72 | spin_lock_irq(¤t->sighand->siglock); | ||
73 | saveset = current->blocked; | ||
74 | current->blocked = newset; | ||
75 | recalc_sigpending(); | ||
76 | spin_unlock_irq(¤t->sighand->siglock); | ||
77 | |||
78 | regs.eax = -EINTR; | ||
79 | while (1) { | ||
80 | current->state = TASK_INTERRUPTIBLE; | ||
81 | schedule(); | ||
82 | if (do_signal(®s, &saveset)) | ||
83 | return -EINTR; | ||
84 | } | ||
85 | } | ||
86 | |||
87 | asmlinkage int | ||
88 | sys_sigaction(int sig, const struct old_sigaction __user *act, | ||
89 | struct old_sigaction __user *oact) | ||
90 | { | ||
91 | struct k_sigaction new_ka, old_ka; | ||
92 | int ret; | ||
93 | |||
94 | if (act) { | ||
95 | old_sigset_t mask; | ||
96 | if (!access_ok(VERIFY_READ, act, sizeof(*act)) || | ||
97 | __get_user(new_ka.sa.sa_handler, &act->sa_handler) || | ||
98 | __get_user(new_ka.sa.sa_restorer, &act->sa_restorer)) | ||
99 | return -EFAULT; | ||
100 | __get_user(new_ka.sa.sa_flags, &act->sa_flags); | ||
101 | __get_user(mask, &act->sa_mask); | ||
102 | siginitset(&new_ka.sa.sa_mask, mask); | ||
103 | } | ||
104 | |||
105 | ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL); | ||
106 | |||
107 | if (!ret && oact) { | ||
108 | if (!access_ok(VERIFY_WRITE, oact, sizeof(*oact)) || | ||
109 | __put_user(old_ka.sa.sa_handler, &oact->sa_handler) || | ||
110 | __put_user(old_ka.sa.sa_restorer, &oact->sa_restorer)) | ||
111 | return -EFAULT; | ||
112 | __put_user(old_ka.sa.sa_flags, &oact->sa_flags); | ||
113 | __put_user(old_ka.sa.sa_mask.sig[0], &oact->sa_mask); | ||
114 | } | ||
115 | |||
116 | return ret; | ||
117 | } | ||
118 | |||
119 | asmlinkage int | ||
120 | sys_sigaltstack(unsigned long ebx) | ||
121 | { | ||
122 | /* This is needed to make gcc realize it doesn't own the "struct pt_regs" */ | ||
123 | struct pt_regs *regs = (struct pt_regs *)&ebx; | ||
124 | const stack_t __user *uss = (const stack_t __user *)ebx; | ||
125 | stack_t __user *uoss = (stack_t __user *)regs->ecx; | ||
126 | |||
127 | return do_sigaltstack(uss, uoss, regs->esp); | ||
128 | } | ||
129 | |||
130 | |||
131 | /* | ||
132 | * Do a signal return; undo the signal stack. | ||
133 | */ | ||
134 | |||
135 | static int | ||
136 | restore_sigcontext(struct pt_regs *regs, struct sigcontext __user *sc, int *peax) | ||
137 | { | ||
138 | unsigned int err = 0; | ||
139 | |||
140 | /* Always make any pending restarted system calls return -EINTR */ | ||
141 | current_thread_info()->restart_block.fn = do_no_restart_syscall; | ||
142 | |||
143 | #define COPY(x) err |= __get_user(regs->x, &sc->x) | ||
144 | |||
145 | #define COPY_SEG(seg) \ | ||
146 | { unsigned short tmp; \ | ||
147 | err |= __get_user(tmp, &sc->seg); \ | ||
148 | regs->x##seg = tmp; } | ||
149 | |||
150 | #define COPY_SEG_STRICT(seg) \ | ||
151 | { unsigned short tmp; \ | ||
152 | err |= __get_user(tmp, &sc->seg); \ | ||
153 | regs->x##seg = tmp|3; } | ||
154 | |||
155 | #define GET_SEG(seg) \ | ||
156 | { unsigned short tmp; \ | ||
157 | err |= __get_user(tmp, &sc->seg); \ | ||
158 | loadsegment(seg,tmp); } | ||
159 | |||
160 | #define FIX_EFLAGS (X86_EFLAGS_AC | X86_EFLAGS_OF | X86_EFLAGS_DF | \ | ||
161 | X86_EFLAGS_TF | X86_EFLAGS_SF | X86_EFLAGS_ZF | \ | ||
162 | X86_EFLAGS_AF | X86_EFLAGS_PF | X86_EFLAGS_CF) | ||
163 | |||
164 | GET_SEG(gs); | ||
165 | GET_SEG(fs); | ||
166 | COPY_SEG(es); | ||
167 | COPY_SEG(ds); | ||
168 | COPY(edi); | ||
169 | COPY(esi); | ||
170 | COPY(ebp); | ||
171 | COPY(esp); | ||
172 | COPY(ebx); | ||
173 | COPY(edx); | ||
174 | COPY(ecx); | ||
175 | COPY(eip); | ||
176 | COPY_SEG_STRICT(cs); | ||
177 | COPY_SEG_STRICT(ss); | ||
178 | |||
179 | { | ||
180 | unsigned int tmpflags; | ||
181 | err |= __get_user(tmpflags, &sc->eflags); | ||
182 | regs->eflags = (regs->eflags & ~FIX_EFLAGS) | (tmpflags & FIX_EFLAGS); | ||
183 | regs->orig_eax = -1; /* disable syscall checks */ | ||
184 | } | ||
185 | |||
186 | { | ||
187 | struct _fpstate __user * buf; | ||
188 | err |= __get_user(buf, &sc->fpstate); | ||
189 | if (buf) { | ||
190 | if (!access_ok(VERIFY_READ, buf, sizeof(*buf))) | ||
191 | goto badframe; | ||
192 | err |= restore_i387(buf); | ||
193 | } else { | ||
194 | struct task_struct *me = current; | ||
195 | if (used_math()) { | ||
196 | clear_fpu(me); | ||
197 | clear_used_math(); | ||
198 | } | ||
199 | } | ||
200 | } | ||
201 | |||
202 | err |= __get_user(*peax, &sc->eax); | ||
203 | return err; | ||
204 | |||
205 | badframe: | ||
206 | return 1; | ||
207 | } | ||
208 | |||
209 | asmlinkage int sys_sigreturn(unsigned long __unused) | ||
210 | { | ||
211 | struct pt_regs *regs = (struct pt_regs *) &__unused; | ||
212 | struct sigframe __user *frame = (struct sigframe __user *)(regs->esp - 8); | ||
213 | sigset_t set; | ||
214 | int eax; | ||
215 | |||
216 | if (!access_ok(VERIFY_READ, frame, sizeof(*frame))) | ||
217 | goto badframe; | ||
218 | if (__get_user(set.sig[0], &frame->sc.oldmask) | ||
219 | || (_NSIG_WORDS > 1 | ||
220 | && __copy_from_user(&set.sig[1], &frame->extramask, | ||
221 | sizeof(frame->extramask)))) | ||
222 | goto badframe; | ||
223 | |||
224 | sigdelsetmask(&set, ~_BLOCKABLE); | ||
225 | spin_lock_irq(¤t->sighand->siglock); | ||
226 | current->blocked = set; | ||
227 | recalc_sigpending(); | ||
228 | spin_unlock_irq(¤t->sighand->siglock); | ||
229 | |||
230 | if (restore_sigcontext(regs, &frame->sc, &eax)) | ||
231 | goto badframe; | ||
232 | return eax; | ||
233 | |||
234 | badframe: | ||
235 | force_sig(SIGSEGV, current); | ||
236 | return 0; | ||
237 | } | ||
238 | |||
239 | asmlinkage int sys_rt_sigreturn(unsigned long __unused) | ||
240 | { | ||
241 | struct pt_regs *regs = (struct pt_regs *) &__unused; | ||
242 | struct rt_sigframe __user *frame = (struct rt_sigframe __user *)(regs->esp - 4); | ||
243 | sigset_t set; | ||
244 | int eax; | ||
245 | |||
246 | if (!access_ok(VERIFY_READ, frame, sizeof(*frame))) | ||
247 | goto badframe; | ||
248 | if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set))) | ||
249 | goto badframe; | ||
250 | |||
251 | sigdelsetmask(&set, ~_BLOCKABLE); | ||
252 | spin_lock_irq(¤t->sighand->siglock); | ||
253 | current->blocked = set; | ||
254 | recalc_sigpending(); | ||
255 | spin_unlock_irq(¤t->sighand->siglock); | ||
256 | |||
257 | if (restore_sigcontext(regs, &frame->uc.uc_mcontext, &eax)) | ||
258 | goto badframe; | ||
259 | |||
260 | if (do_sigaltstack(&frame->uc.uc_stack, NULL, regs->esp) == -EFAULT) | ||
261 | goto badframe; | ||
262 | |||
263 | return eax; | ||
264 | |||
265 | badframe: | ||
266 | force_sig(SIGSEGV, current); | ||
267 | return 0; | ||
268 | } | ||
269 | |||
270 | /* | ||
271 | * Set up a signal frame. | ||
272 | */ | ||
273 | |||
274 | static int | ||
275 | setup_sigcontext(struct sigcontext __user *sc, struct _fpstate __user *fpstate, | ||
276 | struct pt_regs *regs, unsigned long mask) | ||
277 | { | ||
278 | int tmp, err = 0; | ||
279 | |||
280 | tmp = 0; | ||
281 | __asm__("movl %%gs,%0" : "=r"(tmp): "0"(tmp)); | ||
282 | err |= __put_user(tmp, (unsigned int __user *)&sc->gs); | ||
283 | __asm__("movl %%fs,%0" : "=r"(tmp): "0"(tmp)); | ||
284 | err |= __put_user(tmp, (unsigned int __user *)&sc->fs); | ||
285 | |||
286 | err |= __put_user(regs->xes, (unsigned int __user *)&sc->es); | ||
287 | err |= __put_user(regs->xds, (unsigned int __user *)&sc->ds); | ||
288 | err |= __put_user(regs->edi, &sc->edi); | ||
289 | err |= __put_user(regs->esi, &sc->esi); | ||
290 | err |= __put_user(regs->ebp, &sc->ebp); | ||
291 | err |= __put_user(regs->esp, &sc->esp); | ||
292 | err |= __put_user(regs->ebx, &sc->ebx); | ||
293 | err |= __put_user(regs->edx, &sc->edx); | ||
294 | err |= __put_user(regs->ecx, &sc->ecx); | ||
295 | err |= __put_user(regs->eax, &sc->eax); | ||
296 | err |= __put_user(current->thread.trap_no, &sc->trapno); | ||
297 | err |= __put_user(current->thread.error_code, &sc->err); | ||
298 | err |= __put_user(regs->eip, &sc->eip); | ||
299 | err |= __put_user(regs->xcs, (unsigned int __user *)&sc->cs); | ||
300 | err |= __put_user(regs->eflags, &sc->eflags); | ||
301 | err |= __put_user(regs->esp, &sc->esp_at_signal); | ||
302 | err |= __put_user(regs->xss, (unsigned int __user *)&sc->ss); | ||
303 | |||
304 | tmp = save_i387(fpstate); | ||
305 | if (tmp < 0) | ||
306 | err = 1; | ||
307 | else | ||
308 | err |= __put_user(tmp ? fpstate : NULL, &sc->fpstate); | ||
309 | |||
310 | /* non-iBCS2 extensions.. */ | ||
311 | err |= __put_user(mask, &sc->oldmask); | ||
312 | err |= __put_user(current->thread.cr2, &sc->cr2); | ||
313 | |||
314 | return err; | ||
315 | } | ||
316 | |||
317 | /* | ||
318 | * Determine which stack to use.. | ||
319 | */ | ||
320 | static inline void __user * | ||
321 | get_sigframe(struct k_sigaction *ka, struct pt_regs * regs, size_t frame_size) | ||
322 | { | ||
323 | unsigned long esp; | ||
324 | |||
325 | /* Default to using normal stack */ | ||
326 | esp = regs->esp; | ||
327 | |||
328 | /* This is the X/Open sanctioned signal stack switching. */ | ||
329 | if (ka->sa.sa_flags & SA_ONSTACK) { | ||
330 | if (sas_ss_flags(esp) == 0) | ||
331 | esp = current->sas_ss_sp + current->sas_ss_size; | ||
332 | } | ||
333 | |||
334 | /* This is the legacy signal stack switching. */ | ||
335 | else if ((regs->xss & 0xffff) != __USER_DS && | ||
336 | !(ka->sa.sa_flags & SA_RESTORER) && | ||
337 | ka->sa.sa_restorer) { | ||
338 | esp = (unsigned long) ka->sa.sa_restorer; | ||
339 | } | ||
340 | |||
341 | return (void __user *)((esp - frame_size) & -8ul); | ||
342 | } | ||
343 | |||
344 | /* These symbols are defined with the addresses in the vsyscall page. | ||
345 | See vsyscall-sigreturn.S. */ | ||
346 | extern void __user __kernel_sigreturn; | ||
347 | extern void __user __kernel_rt_sigreturn; | ||
348 | |||
349 | static void setup_frame(int sig, struct k_sigaction *ka, | ||
350 | sigset_t *set, struct pt_regs * regs) | ||
351 | { | ||
352 | void __user *restorer; | ||
353 | struct sigframe __user *frame; | ||
354 | int err = 0; | ||
355 | int usig; | ||
356 | |||
357 | frame = get_sigframe(ka, regs, sizeof(*frame)); | ||
358 | |||
359 | if (!access_ok(VERIFY_WRITE, frame, sizeof(*frame))) | ||
360 | goto give_sigsegv; | ||
361 | |||
362 | usig = current_thread_info()->exec_domain | ||
363 | && current_thread_info()->exec_domain->signal_invmap | ||
364 | && sig < 32 | ||
365 | ? current_thread_info()->exec_domain->signal_invmap[sig] | ||
366 | : sig; | ||
367 | |||
368 | err = __put_user(usig, &frame->sig); | ||
369 | if (err) | ||
370 | goto give_sigsegv; | ||
371 | |||
372 | err = setup_sigcontext(&frame->sc, &frame->fpstate, regs, set->sig[0]); | ||
373 | if (err) | ||
374 | goto give_sigsegv; | ||
375 | |||
376 | if (_NSIG_WORDS > 1) { | ||
377 | err = __copy_to_user(&frame->extramask, &set->sig[1], | ||
378 | sizeof(frame->extramask)); | ||
379 | if (err) | ||
380 | goto give_sigsegv; | ||
381 | } | ||
382 | |||
383 | restorer = &__kernel_sigreturn; | ||
384 | if (ka->sa.sa_flags & SA_RESTORER) | ||
385 | restorer = ka->sa.sa_restorer; | ||
386 | |||
387 | /* Set up to return from userspace. */ | ||
388 | err |= __put_user(restorer, &frame->pretcode); | ||
389 | |||
390 | /* | ||
391 | * This is popl %eax ; movl $,%eax ; int $0x80 | ||
392 | * | ||
393 | * WE DO NOT USE IT ANY MORE! It's only left here for historical | ||
394 | * reasons and because gdb uses it as a signature to notice | ||
395 | * signal handler stack frames. | ||
396 | */ | ||
397 | err |= __put_user(0xb858, (short __user *)(frame->retcode+0)); | ||
398 | err |= __put_user(__NR_sigreturn, (int __user *)(frame->retcode+2)); | ||
399 | err |= __put_user(0x80cd, (short __user *)(frame->retcode+6)); | ||
400 | |||
401 | if (err) | ||
402 | goto give_sigsegv; | ||
403 | |||
404 | /* Set up registers for signal handler */ | ||
405 | regs->esp = (unsigned long) frame; | ||
406 | regs->eip = (unsigned long) ka->sa.sa_handler; | ||
407 | regs->eax = (unsigned long) sig; | ||
408 | regs->edx = (unsigned long) 0; | ||
409 | regs->ecx = (unsigned long) 0; | ||
410 | |||
411 | set_fs(USER_DS); | ||
412 | regs->xds = __USER_DS; | ||
413 | regs->xes = __USER_DS; | ||
414 | regs->xss = __USER_DS; | ||
415 | regs->xcs = __USER_CS; | ||
416 | |||
417 | /* | ||
418 | * Clear TF when entering the signal handler, but | ||
419 | * notify any tracer that was single-stepping it. | ||
420 | * The tracer may want to single-step inside the | ||
421 | * handler too. | ||
422 | */ | ||
423 | regs->eflags &= ~TF_MASK; | ||
424 | if (test_thread_flag(TIF_SINGLESTEP)) | ||
425 | ptrace_notify(SIGTRAP); | ||
426 | |||
427 | #if DEBUG_SIG | ||
428 | printk("SIG deliver (%s:%d): sp=%p pc=%p ra=%p\n", | ||
429 | current->comm, current->pid, frame, regs->eip, frame->pretcode); | ||
430 | #endif | ||
431 | |||
432 | return; | ||
433 | |||
434 | give_sigsegv: | ||
435 | force_sigsegv(sig, current); | ||
436 | } | ||
437 | |||
438 | static void setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info, | ||
439 | sigset_t *set, struct pt_regs * regs) | ||
440 | { | ||
441 | void __user *restorer; | ||
442 | struct rt_sigframe __user *frame; | ||
443 | int err = 0; | ||
444 | int usig; | ||
445 | |||
446 | frame = get_sigframe(ka, regs, sizeof(*frame)); | ||
447 | |||
448 | if (!access_ok(VERIFY_WRITE, frame, sizeof(*frame))) | ||
449 | goto give_sigsegv; | ||
450 | |||
451 | usig = current_thread_info()->exec_domain | ||
452 | && current_thread_info()->exec_domain->signal_invmap | ||
453 | && sig < 32 | ||
454 | ? current_thread_info()->exec_domain->signal_invmap[sig] | ||
455 | : sig; | ||
456 | |||
457 | err |= __put_user(usig, &frame->sig); | ||
458 | err |= __put_user(&frame->info, &frame->pinfo); | ||
459 | err |= __put_user(&frame->uc, &frame->puc); | ||
460 | err |= copy_siginfo_to_user(&frame->info, info); | ||
461 | if (err) | ||
462 | goto give_sigsegv; | ||
463 | |||
464 | /* Create the ucontext. */ | ||
465 | err |= __put_user(0, &frame->uc.uc_flags); | ||
466 | err |= __put_user(0, &frame->uc.uc_link); | ||
467 | err |= __put_user(current->sas_ss_sp, &frame->uc.uc_stack.ss_sp); | ||
468 | err |= __put_user(sas_ss_flags(regs->esp), | ||
469 | &frame->uc.uc_stack.ss_flags); | ||
470 | err |= __put_user(current->sas_ss_size, &frame->uc.uc_stack.ss_size); | ||
471 | err |= setup_sigcontext(&frame->uc.uc_mcontext, &frame->fpstate, | ||
472 | regs, set->sig[0]); | ||
473 | err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set)); | ||
474 | if (err) | ||
475 | goto give_sigsegv; | ||
476 | |||
477 | /* Set up to return from userspace. */ | ||
478 | restorer = &__kernel_rt_sigreturn; | ||
479 | if (ka->sa.sa_flags & SA_RESTORER) | ||
480 | restorer = ka->sa.sa_restorer; | ||
481 | err |= __put_user(restorer, &frame->pretcode); | ||
482 | |||
483 | /* | ||
484 | * This is movl $,%eax ; int $0x80 | ||
485 | * | ||
486 | * WE DO NOT USE IT ANY MORE! It's only left here for historical | ||
487 | * reasons and because gdb uses it as a signature to notice | ||
488 | * signal handler stack frames. | ||
489 | */ | ||
490 | err |= __put_user(0xb8, (char __user *)(frame->retcode+0)); | ||
491 | err |= __put_user(__NR_rt_sigreturn, (int __user *)(frame->retcode+1)); | ||
492 | err |= __put_user(0x80cd, (short __user *)(frame->retcode+5)); | ||
493 | |||
494 | if (err) | ||
495 | goto give_sigsegv; | ||
496 | |||
497 | /* Set up registers for signal handler */ | ||
498 | regs->esp = (unsigned long) frame; | ||
499 | regs->eip = (unsigned long) ka->sa.sa_handler; | ||
500 | regs->eax = (unsigned long) usig; | ||
501 | regs->edx = (unsigned long) &frame->info; | ||
502 | regs->ecx = (unsigned long) &frame->uc; | ||
503 | |||
504 | set_fs(USER_DS); | ||
505 | regs->xds = __USER_DS; | ||
506 | regs->xes = __USER_DS; | ||
507 | regs->xss = __USER_DS; | ||
508 | regs->xcs = __USER_CS; | ||
509 | |||
510 | /* | ||
511 | * Clear TF when entering the signal handler, but | ||
512 | * notify any tracer that was single-stepping it. | ||
513 | * The tracer may want to single-step inside the | ||
514 | * handler too. | ||
515 | */ | ||
516 | regs->eflags &= ~TF_MASK; | ||
517 | if (test_thread_flag(TIF_SINGLESTEP)) | ||
518 | ptrace_notify(SIGTRAP); | ||
519 | |||
520 | #if DEBUG_SIG | ||
521 | printk("SIG deliver (%s:%d): sp=%p pc=%p ra=%p\n", | ||
522 | current->comm, current->pid, frame, regs->eip, frame->pretcode); | ||
523 | #endif | ||
524 | |||
525 | return; | ||
526 | |||
527 | give_sigsegv: | ||
528 | force_sigsegv(sig, current); | ||
529 | } | ||
530 | |||
531 | /* | ||
532 | * OK, we're invoking a handler | ||
533 | */ | ||
534 | |||
535 | static void | ||
536 | handle_signal(unsigned long sig, siginfo_t *info, struct k_sigaction *ka, | ||
537 | sigset_t *oldset, struct pt_regs * regs) | ||
538 | { | ||
539 | /* Are we from a system call? */ | ||
540 | if (regs->orig_eax >= 0) { | ||
541 | /* If so, check system call restarting.. */ | ||
542 | switch (regs->eax) { | ||
543 | case -ERESTART_RESTARTBLOCK: | ||
544 | case -ERESTARTNOHAND: | ||
545 | regs->eax = -EINTR; | ||
546 | break; | ||
547 | |||
548 | case -ERESTARTSYS: | ||
549 | if (!(ka->sa.sa_flags & SA_RESTART)) { | ||
550 | regs->eax = -EINTR; | ||
551 | break; | ||
552 | } | ||
553 | /* fallthrough */ | ||
554 | case -ERESTARTNOINTR: | ||
555 | regs->eax = regs->orig_eax; | ||
556 | regs->eip -= 2; | ||
557 | } | ||
558 | } | ||
559 | |||
560 | /* | ||
561 | * If TF is set due to a debugger (PT_DTRACE), clear the TF flag so | ||
562 | * that register information in the sigcontext is correct. | ||
563 | */ | ||
564 | if (unlikely(regs->eflags & TF_MASK) | ||
565 | && likely(current->ptrace & PT_DTRACE)) { | ||
566 | current->ptrace &= ~PT_DTRACE; | ||
567 | regs->eflags &= ~TF_MASK; | ||
568 | } | ||
569 | |||
570 | /* Set up the stack frame */ | ||
571 | if (ka->sa.sa_flags & SA_SIGINFO) | ||
572 | setup_rt_frame(sig, ka, info, oldset, regs); | ||
573 | else | ||
574 | setup_frame(sig, ka, oldset, regs); | ||
575 | |||
576 | if (!(ka->sa.sa_flags & SA_NODEFER)) { | ||
577 | spin_lock_irq(¤t->sighand->siglock); | ||
578 | sigorsets(¤t->blocked,¤t->blocked,&ka->sa.sa_mask); | ||
579 | sigaddset(¤t->blocked,sig); | ||
580 | recalc_sigpending(); | ||
581 | spin_unlock_irq(¤t->sighand->siglock); | ||
582 | } | ||
583 | } | ||
584 | |||
585 | /* | ||
586 | * Note that 'init' is a special process: it doesn't get signals it doesn't | ||
587 | * want to handle. Thus you cannot kill init even with a SIGKILL even by | ||
588 | * mistake. | ||
589 | */ | ||
590 | int fastcall do_signal(struct pt_regs *regs, sigset_t *oldset) | ||
591 | { | ||
592 | siginfo_t info; | ||
593 | int signr; | ||
594 | struct k_sigaction ka; | ||
595 | |||
596 | /* | ||
597 | * We want the common case to go fast, which | ||
598 | * is why we may in certain cases get here from | ||
599 | * kernel mode. Just return without doing anything | ||
600 | * if so. | ||
601 | */ | ||
602 | if ((regs->xcs & 3) != 3) | ||
603 | return 1; | ||
604 | |||
605 | if (current->flags & PF_FREEZE) { | ||
606 | refrigerator(0); | ||
607 | goto no_signal; | ||
608 | } | ||
609 | |||
610 | if (!oldset) | ||
611 | oldset = ¤t->blocked; | ||
612 | |||
613 | signr = get_signal_to_deliver(&info, &ka, regs, NULL); | ||
614 | if (signr > 0) { | ||
615 | /* Reenable any watchpoints before delivering the | ||
616 | * signal to user space. The processor register will | ||
617 | * have been cleared if the watchpoint triggered | ||
618 | * inside the kernel. | ||
619 | */ | ||
620 | if (unlikely(current->thread.debugreg[7])) { | ||
621 | __asm__("movl %0,%%db7" : : "r" (current->thread.debugreg[7])); | ||
622 | } | ||
623 | |||
624 | /* Whee! Actually deliver the signal. */ | ||
625 | handle_signal(signr, &info, &ka, oldset, regs); | ||
626 | return 1; | ||
627 | } | ||
628 | |||
629 | no_signal: | ||
630 | /* Did we come from a system call? */ | ||
631 | if (regs->orig_eax >= 0) { | ||
632 | /* Restart the system call - no handlers present */ | ||
633 | if (regs->eax == -ERESTARTNOHAND || | ||
634 | regs->eax == -ERESTARTSYS || | ||
635 | regs->eax == -ERESTARTNOINTR) { | ||
636 | regs->eax = regs->orig_eax; | ||
637 | regs->eip -= 2; | ||
638 | } | ||
639 | if (regs->eax == -ERESTART_RESTARTBLOCK){ | ||
640 | regs->eax = __NR_restart_syscall; | ||
641 | regs->eip -= 2; | ||
642 | } | ||
643 | } | ||
644 | return 0; | ||
645 | } | ||
646 | |||
647 | /* | ||
648 | * notification of userspace execution resumption | ||
649 | * - triggered by current->work.notify_resume | ||
650 | */ | ||
651 | __attribute__((regparm(3))) | ||
652 | void do_notify_resume(struct pt_regs *regs, sigset_t *oldset, | ||
653 | __u32 thread_info_flags) | ||
654 | { | ||
655 | /* Pending single-step? */ | ||
656 | if (thread_info_flags & _TIF_SINGLESTEP) { | ||
657 | regs->eflags |= TF_MASK; | ||
658 | clear_thread_flag(TIF_SINGLESTEP); | ||
659 | } | ||
660 | /* deal with pending signal delivery */ | ||
661 | if (thread_info_flags & _TIF_SIGPENDING) | ||
662 | do_signal(regs,oldset); | ||
663 | |||
664 | clear_thread_flag(TIF_IRET); | ||
665 | } | ||