This source file includes following definitions.
- sys_sigsuspend
- sys_sigreturn
- setup_frame
- do_signal
1
2
3
4
5
6
7 #include <linux/sched.h>
8 #include <linux/kernel.h>
9 #include <linux/signal.h>
10 #include <linux/errno.h>
11 #include <linux/wait.h>
12 #include <linux/ptrace.h>
13 #include <linux/unistd.h>
14
15 #include <asm/segment.h>
16
17 #define _S(nr) (1<<((nr)-1))
18
19 #define _BLOCKABLE (~(_S(SIGKILL) | _S(SIGSTOP)))
20
21 asmlinkage int sys_waitpid(pid_t pid,unsigned long * stat_addr, int options);
22
23
24
25
26 asmlinkage int sys_sigsuspend(int restart, unsigned long oldmask, unsigned long set)
27 {
28 unsigned long mask;
29 struct pt_regs * regs = (struct pt_regs *) &restart;
30
31 mask = current->blocked;
32 current->blocked = set & _BLOCKABLE;
33 regs->eax = -EINTR;
34 while (1) {
35 current->state = TASK_INTERRUPTIBLE;
36 schedule();
37 if (do_signal(mask,regs))
38 return -EINTR;
39 }
40 }
41
42
43
44
45 asmlinkage int sys_sigreturn(unsigned long __unused)
46 {
47 #define COPY(x) regs->x = context.x
48 #define COPY_SEG(x) \
49 if ((context.x & 0xfffc) && (context.x & 3) != 3) goto badframe; COPY(x);
50 #define COPY_SEG_STRICT(x) \
51 if (!(context.x & 0xfffc) || (context.x & 3) != 3) goto badframe; COPY(x);
52 struct sigcontext_struct context;
53 struct pt_regs * regs;
54
55 regs = (struct pt_regs *) &__unused;
56 if (verify_area(VERIFY_READ, (void *) regs->esp, sizeof(context)))
57 goto badframe;
58 memcpy_fromfs(&context,(void *) regs->esp, sizeof(context));
59 current->blocked = context.oldmask & _BLOCKABLE;
60 COPY_SEG(ds);
61 COPY_SEG(es);
62 COPY_SEG(fs);
63 COPY_SEG(gs);
64 COPY_SEG_STRICT(ss);
65 COPY_SEG_STRICT(cs);
66 COPY(eip);
67 COPY(ecx); COPY(edx);
68 COPY(ebx);
69 COPY(esp); COPY(ebp);
70 COPY(edi); COPY(esi);
71 regs->eflags &= ~0x40DD5;
72 regs->eflags |= context.eflags & 0x40DD5;
73 regs->orig_eax = -1;
74 return context.eax;
75 badframe:
76 do_exit(SIGSEGV);
77 }
78
79
80
81
82
83 void setup_frame(struct sigaction * sa, unsigned long ** fp, unsigned long eip,
84 struct pt_regs * regs, int signr, unsigned long oldmask)
85 {
86 unsigned long * frame;
87
88 #define __CODE ((unsigned long)(frame+24))
89 #define CODE(x) ((unsigned long *) ((x)+__CODE))
90 frame = *fp;
91 if (regs->ss != USER_DS)
92 frame = (unsigned long *) sa->sa_restorer;
93 frame -= 32;
94 if (verify_area(VERIFY_WRITE,frame,32*4))
95 do_exit(SIGSEGV);
96
97 put_fs_long(__CODE,frame);
98 if (current->exec_domain && current->exec_domain->signal_invmap)
99 put_fs_long(current->exec_domain->signal_invmap[signr], frame+1);
100 else
101 put_fs_long(signr, frame+1);
102 put_fs_long(regs->gs, frame+2);
103 put_fs_long(regs->fs, frame+3);
104 put_fs_long(regs->es, frame+4);
105 put_fs_long(regs->ds, frame+5);
106 put_fs_long(regs->edi, frame+6);
107 put_fs_long(regs->esi, frame+7);
108 put_fs_long(regs->ebp, frame+8);
109 put_fs_long((long)*fp, frame+9);
110 put_fs_long(regs->ebx, frame+10);
111 put_fs_long(regs->edx, frame+11);
112 put_fs_long(regs->ecx, frame+12);
113 put_fs_long(regs->eax, frame+13);
114 put_fs_long(current->tss.trap_no, frame+14);
115 put_fs_long(current->tss.error_code, frame+15);
116 put_fs_long(eip, frame+16);
117 put_fs_long(regs->cs, frame+17);
118 put_fs_long(regs->eflags, frame+18);
119 put_fs_long(regs->esp, frame+19);
120 put_fs_long(regs->ss, frame+20);
121 put_fs_long(0,frame+21);
122
123 put_fs_long(oldmask, frame+22);
124 put_fs_long(current->tss.cr2, frame+23);
125
126 put_fs_long(0x0000b858, CODE(0));
127 put_fs_long(0x80cd0000, CODE(4));
128 put_fs_long(__NR_sigreturn, CODE(2));
129 *fp = frame;
130 #undef __CODE
131 #undef CODE
132 }
133
134
135
136
137
138
139
140
141
142
143 asmlinkage int do_signal(unsigned long oldmask, struct pt_regs * regs)
144 {
145 unsigned long mask = ~current->blocked;
146 unsigned long handler_signal = 0;
147 unsigned long *frame = NULL;
148 unsigned long eip = 0;
149 unsigned long signr;
150 struct sigaction * sa;
151
152 while ((signr = current->signal & mask)) {
153 __asm__("bsf %2,%1\n\t"
154 "btrl %1,%0"
155 :"=m" (current->signal),"=r" (signr)
156 :"1" (signr));
157 sa = current->sigaction + signr;
158 signr++;
159 if ((current->flags & PF_PTRACED) && signr != SIGKILL) {
160 current->exit_code = signr;
161 current->state = TASK_STOPPED;
162 notify_parent(current);
163 schedule();
164 if (!(signr = current->exit_code))
165 continue;
166 current->exit_code = 0;
167 if (signr == SIGSTOP)
168 continue;
169 if (_S(signr) & current->blocked) {
170 current->signal |= _S(signr);
171 continue;
172 }
173 sa = current->sigaction + signr - 1;
174 }
175 if (sa->sa_handler == SIG_IGN) {
176 if (signr != SIGCHLD)
177 continue;
178
179 while (sys_waitpid(-1,NULL,WNOHANG) > 0)
180 ;
181 continue;
182 }
183 if (sa->sa_handler == SIG_DFL) {
184 if (current->pid == 1)
185 continue;
186 switch (signr) {
187 case SIGCONT: case SIGCHLD: case SIGWINCH:
188 continue;
189
190 case SIGSTOP: case SIGTSTP: case SIGTTIN: case SIGTTOU:
191 if (current->flags & PF_PTRACED)
192 continue;
193 current->state = TASK_STOPPED;
194 current->exit_code = signr;
195 if (!(current->p_pptr->sigaction[SIGCHLD-1].sa_flags &
196 SA_NOCLDSTOP))
197 notify_parent(current);
198 schedule();
199 continue;
200
201 case SIGQUIT: case SIGILL: case SIGTRAP:
202 case SIGIOT: case SIGFPE: case SIGSEGV:
203 if (current->binfmt && current->binfmt->core_dump) {
204 if (current->binfmt->core_dump(signr, regs))
205 signr |= 0x80;
206 }
207
208 default:
209 current->signal |= _S(signr & 0x7f);
210 do_exit(signr);
211 }
212 }
213
214
215
216 if (regs->orig_eax >= 0) {
217 if (regs->eax == -ERESTARTNOHAND ||
218 (regs->eax == -ERESTARTSYS && !(sa->sa_flags & SA_RESTART)))
219 regs->eax = -EINTR;
220 }
221 handler_signal |= 1 << (signr-1);
222 mask &= ~sa->sa_mask;
223 }
224 if (regs->orig_eax >= 0 &&
225 (regs->eax == -ERESTARTNOHAND ||
226 regs->eax == -ERESTARTSYS ||
227 regs->eax == -ERESTARTNOINTR)) {
228 regs->eax = regs->orig_eax;
229 regs->eip -= 2;
230 }
231 if (!handler_signal)
232 return 0;
233 eip = regs->eip;
234 frame = (unsigned long *) regs->esp;
235 signr = 1;
236 sa = current->sigaction;
237 for (mask = 1 ; mask ; sa++,signr++,mask += mask) {
238 if (mask > handler_signal)
239 break;
240 if (!(mask & handler_signal))
241 continue;
242 setup_frame(sa,&frame,eip,regs,signr,oldmask);
243 eip = (unsigned long) sa->sa_handler;
244 if (sa->sa_flags & SA_ONESHOT)
245 sa->sa_handler = NULL;
246
247 __asm__("testb $0,%%fs:%0": :"m" (*(char *) eip));
248 regs->cs = USER_CS; regs->ss = USER_DS;
249 regs->ds = USER_DS; regs->es = USER_DS;
250 regs->gs = USER_DS; regs->fs = USER_DS;
251 current->blocked |= sa->sa_mask;
252 oldmask |= sa->sa_mask;
253 }
254 regs->esp = (unsigned long) frame;
255 regs->eip = eip;
256 current->tss.trap_no = current->tss.error_code = 0;
257 return 1;
258 }