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