1 |
62 |
marcus.erl |
/*
|
2 |
|
|
* linux/arch/or32/kernel/signal.c
|
3 |
|
|
*
|
4 |
|
|
* or32 version
|
5 |
|
|
* author(s): Matjaz Breskvar (phoenix@bsemi.com)
|
6 |
|
|
*
|
7 |
|
|
* derived from cris, i386, m68k, ppc, sh ports.
|
8 |
|
|
*
|
9 |
|
|
* changes:
|
10 |
|
|
* 18. 11. 2003: Matjaz Breskvar (phoenix@bsemi.com)
|
11 |
|
|
* initial port to or32 architecture
|
12 |
|
|
*
|
13 |
|
|
* Based on linux/arch/cris/kernel/signal.c
|
14 |
|
|
* Copyright (C) 2000, 2001, 2002 Axis Communications AB
|
15 |
|
|
* Authors: Bjorn Wesen (bjornw@axis.com)
|
16 |
|
|
*
|
17 |
|
|
*/
|
18 |
|
|
|
19 |
|
|
#include <linux/sched.h>
|
20 |
|
|
#include <linux/mm.h>
|
21 |
|
|
#include <linux/smp.h>
|
22 |
|
|
#include <linux/smp_lock.h>
|
23 |
|
|
#include <linux/kernel.h>
|
24 |
|
|
#include <linux/signal.h>
|
25 |
|
|
#include <linux/errno.h>
|
26 |
|
|
#include <linux/wait.h>
|
27 |
|
|
#include <linux/ptrace.h>
|
28 |
|
|
#include <linux/unistd.h>
|
29 |
|
|
#include <linux/stddef.h>
|
30 |
|
|
|
31 |
|
|
#include <asm/processor.h>
|
32 |
|
|
#include <asm/ucontext.h>
|
33 |
|
|
#include <asm/uaccess.h>
|
34 |
|
|
#include <asm/or32-hf.h>
|
35 |
|
|
|
36 |
|
|
#define DEBUG_SIG 0
|
37 |
|
|
|
38 |
|
|
#define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP)))
|
39 |
|
|
|
40 |
|
|
/* a syscall in Linux/OR32 is a "l.sys 1" instruction which is 4 bytes */
|
41 |
|
|
/* manipulate regs so that upon return, it will be re-executed */
|
42 |
|
|
|
43 |
|
|
/* We rely on that pc points to the instruction after "l.sys 1", so the
|
44 |
|
|
* library must never do strange things like putting it in a delay slot.
|
45 |
|
|
*/
|
46 |
|
|
#define RESTART_OR32_SYS(regs) regs->gprs[1] = regs->orig_gpr3; regs->pc -= 4;
|
47 |
|
|
|
48 |
|
|
int do_signal(int canrestart, sigset_t *oldset, struct pt_regs *regs);
|
49 |
|
|
|
50 |
|
|
/*
|
51 |
|
|
* Atomically swap in the new signal mask, and wait for a signal. Define
|
52 |
|
|
* dummy arguments to be able to reach the regs argument. (Note that this
|
53 |
|
|
* arrangement relies on old_sigset_t occupying one register.)
|
54 |
|
|
*/
|
55 |
|
|
int sys_sigsuspend(old_sigset_t mask, long r4, long r5, long mof,
|
56 |
|
|
long srp, struct pt_regs *regs)
|
57 |
|
|
{
|
58 |
|
|
sigset_t saveset;
|
59 |
|
|
phx_signal("mask 0x%lx, r4 0x%lx, r5 0x%lx, mof 0x%lx, srp 0x%lx, regs %p",
|
60 |
|
|
mask, r4, r5, mof, srp, regs);
|
61 |
|
|
|
62 |
|
|
|
63 |
|
|
mask &= _BLOCKABLE;
|
64 |
|
|
spin_lock_irq(¤t->sighand->siglock);
|
65 |
|
|
saveset = current->blocked;
|
66 |
|
|
siginitset(¤t->blocked, mask);
|
67 |
|
|
recalc_sigpending();
|
68 |
|
|
spin_unlock_irq(¤t->sighand->siglock);
|
69 |
|
|
|
70 |
|
|
regs->gprs[1] = -EINTR;
|
71 |
|
|
while (1) {
|
72 |
|
|
current->state = TASK_INTERRUPTIBLE;
|
73 |
|
|
schedule();
|
74 |
|
|
if (do_signal(0, &saveset, regs))
|
75 |
|
|
/* We will get here twice: once to call the signal
|
76 |
|
|
handler, then again to return from the
|
77 |
|
|
sigsuspend system call. When calling the
|
78 |
|
|
signal handler, R10 holds the signal number as
|
79 |
|
|
set through do_signal. The sigsuspend call
|
80 |
|
|
will return with the restored value set above;
|
81 |
|
|
always -EINTR. */
|
82 |
|
|
return regs->gprs[1];
|
83 |
|
|
}
|
84 |
|
|
}
|
85 |
|
|
|
86 |
|
|
/* Define dummy arguments to be able to reach the regs argument. (Note that
|
87 |
|
|
* this arrangement relies on size_t occupying one register.)
|
88 |
|
|
*/
|
89 |
|
|
int sys_rt_sigsuspend(sigset_t *unewset, size_t sigsetsize, long r5,
|
90 |
|
|
long mof, long srp, struct pt_regs *regs)
|
91 |
|
|
{
|
92 |
|
|
sigset_t saveset, newset;
|
93 |
|
|
|
94 |
|
|
phx_signal("unewset %p, sigsetsize 0x%x, r5 0x%lx, mof 0x%lx, srp 0x%lx, regs %p",
|
95 |
|
|
unewset, sigsetsize, r5, mof, srp, regs);
|
96 |
|
|
|
97 |
|
|
/* XXX: Don't preclude handling different sized sigset_t's. */
|
98 |
|
|
if (sigsetsize != sizeof(sigset_t))
|
99 |
|
|
return -EINVAL;
|
100 |
|
|
|
101 |
|
|
if (copy_from_user(&newset, unewset, sizeof(newset)))
|
102 |
|
|
return -EFAULT;
|
103 |
|
|
sigdelsetmask(&newset, ~_BLOCKABLE);
|
104 |
|
|
|
105 |
|
|
spin_lock_irq(¤t->sighand->siglock);
|
106 |
|
|
saveset = current->blocked;
|
107 |
|
|
current->blocked = newset;
|
108 |
|
|
recalc_sigpending();
|
109 |
|
|
spin_unlock_irq(¤t->sighand->siglock);
|
110 |
|
|
|
111 |
|
|
regs->gprs[1] = -EINTR;
|
112 |
|
|
while (1) {
|
113 |
|
|
current->state = TASK_INTERRUPTIBLE;
|
114 |
|
|
schedule();
|
115 |
|
|
if (do_signal(0, &saveset, regs))
|
116 |
|
|
/* We will get here twice: once to call the signal
|
117 |
|
|
handler, then again to return from the
|
118 |
|
|
sigsuspend system call. When calling the
|
119 |
|
|
signal handler, R10 holds the signal number as
|
120 |
|
|
set through do_signal. The sigsuspend call
|
121 |
|
|
will return with the restored value set above;
|
122 |
|
|
always -EINTR. */
|
123 |
|
|
return regs->gprs[1];
|
124 |
|
|
}
|
125 |
|
|
}
|
126 |
|
|
|
127 |
|
|
int sys_sigaction(int sig, const struct old_sigaction *act,
|
128 |
|
|
struct old_sigaction *oact)
|
129 |
|
|
{
|
130 |
|
|
struct k_sigaction new_ka, old_ka;
|
131 |
|
|
int ret;
|
132 |
|
|
|
133 |
|
|
phx_signal("sig %d, old act %p, old oact %p",
|
134 |
|
|
sig, act, oact);
|
135 |
|
|
|
136 |
|
|
if (act) {
|
137 |
|
|
old_sigset_t mask;
|
138 |
|
|
if (verify_area(VERIFY_READ, act, sizeof(*act)) ||
|
139 |
|
|
__get_user(new_ka.sa.sa_handler, &act->sa_handler) ||
|
140 |
|
|
__get_user(new_ka.sa.sa_restorer, &act->sa_restorer))
|
141 |
|
|
return -EFAULT;
|
142 |
|
|
__get_user(new_ka.sa.sa_flags, &act->sa_flags);
|
143 |
|
|
__get_user(mask, &act->sa_mask);
|
144 |
|
|
siginitset(&new_ka.sa.sa_mask, mask);
|
145 |
|
|
}
|
146 |
|
|
|
147 |
|
|
ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL);
|
148 |
|
|
|
149 |
|
|
if (!ret && oact) {
|
150 |
|
|
if (verify_area(VERIFY_WRITE, oact, sizeof(*oact)) ||
|
151 |
|
|
__put_user(old_ka.sa.sa_handler, &oact->sa_handler) ||
|
152 |
|
|
__put_user(old_ka.sa.sa_restorer, &oact->sa_restorer))
|
153 |
|
|
return -EFAULT;
|
154 |
|
|
__put_user(old_ka.sa.sa_flags, &oact->sa_flags);
|
155 |
|
|
__put_user(old_ka.sa.sa_mask.sig[0], &oact->sa_mask);
|
156 |
|
|
}
|
157 |
|
|
|
158 |
|
|
return ret;
|
159 |
|
|
}
|
160 |
|
|
|
161 |
|
|
int sys_sigaltstack(const stack_t *uss, stack_t *uoss)
|
162 |
|
|
{
|
163 |
|
|
struct pt_regs *regs = (struct pt_regs *) &uss;
|
164 |
|
|
phx_signal("uss %p, uoss %p",
|
165 |
|
|
uss, uoss);
|
166 |
|
|
|
167 |
|
|
return do_sigaltstack(uss, uoss, regs->sp);
|
168 |
|
|
}
|
169 |
|
|
|
170 |
|
|
|
171 |
|
|
/*
|
172 |
|
|
* Do a signal return; undo the signal stack.
|
173 |
|
|
*/
|
174 |
|
|
|
175 |
|
|
struct sigframe {
|
176 |
|
|
struct sigcontext sc;
|
177 |
|
|
unsigned long extramask[_NSIG_WORDS-1];
|
178 |
|
|
unsigned char retcode[16]; /* trampoline code */
|
179 |
|
|
};
|
180 |
|
|
|
181 |
|
|
struct rt_sigframe {
|
182 |
|
|
struct siginfo *pinfo;
|
183 |
|
|
void *puc;
|
184 |
|
|
struct siginfo info;
|
185 |
|
|
struct ucontext uc;
|
186 |
|
|
unsigned char retcode[16]; /* trampoline code */
|
187 |
|
|
};
|
188 |
|
|
|
189 |
|
|
|
190 |
|
|
static int restore_sigcontext(struct pt_regs *regs, struct sigcontext *sc)
|
191 |
|
|
{
|
192 |
|
|
unsigned int err = 0;
|
193 |
|
|
unsigned long old_usp;
|
194 |
|
|
|
195 |
|
|
phx_signal("regs %p, sc %p",
|
196 |
|
|
regs, sc);
|
197 |
|
|
|
198 |
|
|
/* restore the regs from &sc->regs (same as sc, since regs is first)
|
199 |
|
|
* (sc is already checked for VERIFY_READ since the sigframe was
|
200 |
|
|
* checked in sys_sigreturn previously)
|
201 |
|
|
*/
|
202 |
|
|
|
203 |
|
|
if (__copy_from_user(regs, sc, sizeof(struct pt_regs)))
|
204 |
|
|
goto badframe;
|
205 |
|
|
|
206 |
|
|
/* make sure the U-flag is set so user-mode cannot fool us */
|
207 |
|
|
|
208 |
|
|
regs->sr &= ~SPR_SR_SM;
|
209 |
|
|
// __PHX__ FIXME
|
210 |
|
|
// regs->dccr |= 1 << 8;
|
211 |
|
|
|
212 |
|
|
/* restore the old USP as it was before we stacked the sc etc.
|
213 |
|
|
* (we cannot just pop the sigcontext since we aligned the sp and
|
214 |
|
|
* stuff after pushing it)
|
215 |
|
|
*/
|
216 |
|
|
|
217 |
|
|
err |= __get_user(old_usp, &sc->usp);
|
218 |
|
|
phx_signal("old_usp 0x%lx", old_usp);
|
219 |
|
|
|
220 |
|
|
// __PHX__ REALLY ???
|
221 |
|
|
// wrusp(old_usp);
|
222 |
|
|
regs->sp = old_usp;
|
223 |
|
|
|
224 |
|
|
/* TODO: the other ports use regs->orig_XX to disable syscall checks
|
225 |
|
|
* after this completes, but we don't use that mechanism. maybe we can
|
226 |
|
|
* use it now ?
|
227 |
|
|
*/
|
228 |
|
|
|
229 |
|
|
return err;
|
230 |
|
|
|
231 |
|
|
badframe:
|
232 |
|
|
return 1;
|
233 |
|
|
}
|
234 |
|
|
|
235 |
|
|
/* Define dummy arguments to be able to reach the regs argument. */
|
236 |
|
|
|
237 |
|
|
asmlinkage int sys_sigreturn(long r3, long r4, long r5, long mof,
|
238 |
|
|
long srp, struct pt_regs *regs)
|
239 |
|
|
{
|
240 |
|
|
struct sigframe *frame = (struct sigframe *)regs->sp;
|
241 |
|
|
sigset_t set;
|
242 |
|
|
|
243 |
|
|
phx_signal("r3 0x%lx, r4 0x%lx, r5 0x%lx, mof 0x%lx, srp 0x%lx, regs %p (regs->sp 0x%lx)",
|
244 |
|
|
r3, r4, r5, mof, srp, regs, regs->sp);
|
245 |
|
|
|
246 |
|
|
/*
|
247 |
|
|
* Since we stacked the signal on a dword boundary,
|
248 |
|
|
* then frame should be dword aligned here. If it's
|
249 |
|
|
* not, then the user is trying to mess with us.
|
250 |
|
|
*/
|
251 |
|
|
if (((long)frame) & 3)
|
252 |
|
|
goto badframe;
|
253 |
|
|
|
254 |
|
|
if (verify_area(VERIFY_READ, frame, sizeof(*frame)))
|
255 |
|
|
goto badframe;
|
256 |
|
|
if (__get_user(set.sig[0], &frame->sc.oldmask)
|
257 |
|
|
|| (_NSIG_WORDS > 1
|
258 |
|
|
&& __copy_from_user(&set.sig[1], &frame->extramask,
|
259 |
|
|
sizeof(frame->extramask))))
|
260 |
|
|
goto badframe;
|
261 |
|
|
|
262 |
|
|
sigdelsetmask(&set, ~_BLOCKABLE);
|
263 |
|
|
spin_lock_irq(¤t->sighand->siglock);
|
264 |
|
|
current->blocked = set;
|
265 |
|
|
recalc_sigpending();
|
266 |
|
|
|
267 |
|
|
/* __PHX__ throw this out */
|
268 |
|
|
phx_signal("SIGPENDING: %d", signal_pending(current));
|
269 |
|
|
|
270 |
|
|
spin_unlock_irq(¤t->sighand->siglock);
|
271 |
|
|
|
272 |
|
|
if (restore_sigcontext(regs, &frame->sc))
|
273 |
|
|
goto badframe;
|
274 |
|
|
|
275 |
|
|
/* TODO: SIGTRAP when single-stepping as in arm ? */
|
276 |
|
|
|
277 |
|
|
return regs->gprs[1];
|
278 |
|
|
|
279 |
|
|
badframe:
|
280 |
|
|
force_sig(SIGSEGV, current);
|
281 |
|
|
return 0;
|
282 |
|
|
}
|
283 |
|
|
|
284 |
|
|
/* Define dummy arguments to be able to reach the regs argument. */
|
285 |
|
|
|
286 |
|
|
asmlinkage int sys_rt_sigreturn(long r3, long r4, long r5,
|
287 |
|
|
long mof, long srp, struct pt_regs *regs)
|
288 |
|
|
{
|
289 |
|
|
struct rt_sigframe *frame = (struct rt_sigframe *)regs->sp;
|
290 |
|
|
sigset_t set;
|
291 |
|
|
stack_t st;
|
292 |
|
|
|
293 |
|
|
phx_signal("r3 0x%lx, r4 0x%lx, r5 0x%lx, mof 0x%lx, srp 0x%lx, regs %p (regs->sp 0x%lx)",
|
294 |
|
|
r3, r4, r5, mof, srp, regs, regs->sp);
|
295 |
|
|
|
296 |
|
|
/*
|
297 |
|
|
* Since we stacked the signal on a dword boundary,
|
298 |
|
|
* then frame should be dword aligned here. If it's
|
299 |
|
|
* not, then the user is trying to mess with us.
|
300 |
|
|
*/
|
301 |
|
|
if (((long)frame) & 3)
|
302 |
|
|
goto badframe;
|
303 |
|
|
|
304 |
|
|
if (verify_area(VERIFY_READ, frame, sizeof(*frame)))
|
305 |
|
|
goto badframe;
|
306 |
|
|
if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set)))
|
307 |
|
|
goto badframe;
|
308 |
|
|
|
309 |
|
|
sigdelsetmask(&set, ~_BLOCKABLE);
|
310 |
|
|
spin_lock_irq(¤t->sighand->siglock);
|
311 |
|
|
current->blocked = set;
|
312 |
|
|
recalc_sigpending();
|
313 |
|
|
spin_unlock_irq(¤t->sighand->siglock);
|
314 |
|
|
|
315 |
|
|
if (restore_sigcontext(regs, &frame->uc.uc_mcontext))
|
316 |
|
|
goto badframe;
|
317 |
|
|
|
318 |
|
|
if (__copy_from_user(&st, &frame->uc.uc_stack, sizeof(st)))
|
319 |
|
|
goto badframe;
|
320 |
|
|
/* It is more difficult to avoid calling this function than to
|
321 |
|
|
call it and ignore errors. */
|
322 |
|
|
do_sigaltstack(&st, NULL, regs->sp);
|
323 |
|
|
|
324 |
|
|
return regs->gprs[1];
|
325 |
|
|
|
326 |
|
|
badframe:
|
327 |
|
|
force_sig(SIGSEGV, current);
|
328 |
|
|
return 0;
|
329 |
|
|
}
|
330 |
|
|
|
331 |
|
|
/*
|
332 |
|
|
* Set up a signal frame.
|
333 |
|
|
*/
|
334 |
|
|
|
335 |
|
|
static int setup_sigcontext(struct sigcontext *sc, struct pt_regs *regs,
|
336 |
|
|
unsigned long mask)
|
337 |
|
|
{
|
338 |
|
|
int err = 0;
|
339 |
|
|
unsigned long usp = regs->sp;
|
340 |
|
|
|
341 |
|
|
phx_signal("sc %p, regs %p, mask 0x%lx",
|
342 |
|
|
sc, regs, mask);
|
343 |
|
|
|
344 |
|
|
/* copy the regs. they are first in sc so we can use sc directly */
|
345 |
|
|
|
346 |
|
|
err |= __copy_to_user(sc, regs, sizeof(struct pt_regs));
|
347 |
|
|
|
348 |
|
|
/* Set the frametype to CRIS_FRAME_NORMAL for the execution of
|
349 |
|
|
the signal handler. The frametype will be restored to its previous
|
350 |
|
|
value in restore_sigcontext. */
|
351 |
|
|
// regs->frametype = CRIS_FRAME_NORMAL;
|
352 |
|
|
|
353 |
|
|
/* then some other stuff */
|
354 |
|
|
|
355 |
|
|
err |= __put_user(mask, &sc->oldmask);
|
356 |
|
|
|
357 |
|
|
err |= __put_user(usp, &sc->usp);
|
358 |
|
|
|
359 |
|
|
return err;
|
360 |
|
|
}
|
361 |
|
|
|
362 |
|
|
/* figure out where we want to put the new signal frame - usually on the stack */
|
363 |
|
|
|
364 |
|
|
static inline void * get_sigframe(struct k_sigaction *ka,
|
365 |
|
|
struct pt_regs * regs, size_t frame_size)
|
366 |
|
|
{
|
367 |
|
|
unsigned long sp = regs->sp;
|
368 |
|
|
|
369 |
|
|
phx_signal("ka %p, regs %p, frame_size 0x%x (sp 0x%lx)",
|
370 |
|
|
ka, regs, frame_size, sp);
|
371 |
|
|
|
372 |
|
|
/* This is the X/Open sanctioned signal stack switching. */
|
373 |
|
|
if (ka->sa.sa_flags & SA_ONSTACK) {
|
374 |
|
|
if (! on_sig_stack(sp))
|
375 |
|
|
sp = current->sas_ss_sp + current->sas_ss_size;
|
376 |
|
|
}
|
377 |
|
|
|
378 |
|
|
/* make sure the frame is dword-aligned */
|
379 |
|
|
|
380 |
|
|
sp &= ~3;
|
381 |
|
|
|
382 |
|
|
return (void *)(sp - frame_size);
|
383 |
|
|
}
|
384 |
|
|
|
385 |
|
|
/* grab and setup a signal frame.
|
386 |
|
|
*
|
387 |
|
|
* basically we stack a lot of state info, and arrange for the
|
388 |
|
|
* user-mode program to return to the kernel using either a
|
389 |
|
|
* trampoline which performs the syscall sigreturn, or a provided
|
390 |
|
|
* user-mode trampoline.
|
391 |
|
|
*/
|
392 |
|
|
|
393 |
|
|
static void setup_frame(int sig, struct k_sigaction *ka,
|
394 |
|
|
sigset_t *set, struct pt_regs * regs)
|
395 |
|
|
{
|
396 |
|
|
struct sigframe *frame;
|
397 |
|
|
unsigned long return_ip;
|
398 |
|
|
int err = 0;
|
399 |
|
|
|
400 |
|
|
phx_signal("sig %d, ka %p, set %p, regs %p",
|
401 |
|
|
sig, ka, set, regs);
|
402 |
|
|
|
403 |
|
|
frame = get_sigframe(ka, regs, sizeof(*frame));
|
404 |
|
|
|
405 |
|
|
if (!access_ok(VERIFY_WRITE, frame, sizeof(*frame)))
|
406 |
|
|
goto give_sigsegv;
|
407 |
|
|
|
408 |
|
|
err |= setup_sigcontext(&frame->sc, regs, set->sig[0]);
|
409 |
|
|
if (err)
|
410 |
|
|
goto give_sigsegv;
|
411 |
|
|
|
412 |
|
|
if (_NSIG_WORDS > 1) {
|
413 |
|
|
err |= __copy_to_user(frame->extramask, &set->sig[1],
|
414 |
|
|
sizeof(frame->extramask));
|
415 |
|
|
}
|
416 |
|
|
if (err)
|
417 |
|
|
goto give_sigsegv;
|
418 |
|
|
|
419 |
|
|
/* Set up to return from userspace. If provided, use a stub
|
420 |
|
|
already in userspace. */
|
421 |
|
|
if (ka->sa.sa_flags & SA_RESTORER) {
|
422 |
|
|
return_ip = (unsigned long)ka->sa.sa_restorer;
|
423 |
|
|
phx_signal("SA_RESTORER: return_ip 0x%lx", return_ip);
|
424 |
|
|
} else {
|
425 |
|
|
/* trampoline - the desired return ip is the retcode itself */
|
426 |
|
|
return_ip = (unsigned long)&frame->retcode;
|
427 |
|
|
phx_signal("ktrampoline: return_ip 0x%lx", return_ip);
|
428 |
|
|
/* This is l.ori r11,r0,__NR_sigreturn, l.sys 1 */
|
429 |
|
|
err |= __put_user(0xa960 , (short *)(frame->retcode+0));
|
430 |
|
|
err |= __put_user(__NR_sigreturn, (short *)(frame->retcode+2));
|
431 |
|
|
err |= __put_user(0x20000001, (unsigned long *)(frame->retcode+4));
|
432 |
|
|
err |= __put_user(0x15000000, (unsigned long *)(frame->retcode+8));
|
433 |
|
|
}
|
434 |
|
|
|
435 |
|
|
if (err)
|
436 |
|
|
goto give_sigsegv;
|
437 |
|
|
|
438 |
|
|
/* Set up registers for signal handler */
|
439 |
|
|
|
440 |
|
|
regs->pc = (unsigned long) ka->sa.sa_handler; /* what we enter NOW */
|
441 |
|
|
regs->gprs[7] = return_ip; /* what we enter LATER */
|
442 |
|
|
regs->gprs[1] = sig; /* first argument is signo */
|
443 |
|
|
|
444 |
|
|
/* actually move the usp to reflect the stacked frame */
|
445 |
|
|
|
446 |
|
|
// wrusp((unsigned long)frame);
|
447 |
|
|
regs->sp=(unsigned long) frame;
|
448 |
|
|
|
449 |
|
|
return;
|
450 |
|
|
|
451 |
|
|
give_sigsegv:
|
452 |
|
|
if (sig == SIGSEGV)
|
453 |
|
|
ka->sa.sa_handler = SIG_DFL;
|
454 |
|
|
force_sig(SIGSEGV, current);
|
455 |
|
|
}
|
456 |
|
|
|
457 |
|
|
static void setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
|
458 |
|
|
sigset_t *set, struct pt_regs * regs)
|
459 |
|
|
{
|
460 |
|
|
struct rt_sigframe *frame;
|
461 |
|
|
unsigned long return_ip;
|
462 |
|
|
int err = 0;
|
463 |
|
|
|
464 |
|
|
phx_signal("sig %d, ka %p, info %p, set %p, regs %p",
|
465 |
|
|
sig, ka, info, set, regs);
|
466 |
|
|
|
467 |
|
|
frame = get_sigframe(ka, regs, sizeof(*frame));
|
468 |
|
|
|
469 |
|
|
if (!access_ok(VERIFY_WRITE, frame, sizeof(*frame)))
|
470 |
|
|
goto give_sigsegv;
|
471 |
|
|
|
472 |
|
|
err |= __put_user(&frame->info, &frame->pinfo);
|
473 |
|
|
err |= __put_user(&frame->uc, &frame->puc);
|
474 |
|
|
err |= copy_siginfo_to_user(&frame->info, info);
|
475 |
|
|
if (err)
|
476 |
|
|
goto give_sigsegv;
|
477 |
|
|
|
478 |
|
|
/* Clear all the bits of the ucontext we don't use. */
|
479 |
|
|
err |= __clear_user(&frame->uc, offsetof(struct ucontext, uc_mcontext));
|
480 |
|
|
|
481 |
|
|
err |= setup_sigcontext(&frame->uc.uc_mcontext, regs, set->sig[0]);
|
482 |
|
|
|
483 |
|
|
err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set));
|
484 |
|
|
|
485 |
|
|
if (err)
|
486 |
|
|
goto give_sigsegv;
|
487 |
|
|
|
488 |
|
|
if (ka->sa.sa_flags & SA_RESTORER) {
|
489 |
|
|
return_ip = (unsigned long)ka->sa.sa_restorer;
|
490 |
|
|
phx_signal("SA_RESTORER: return_ip 0x%lx", return_ip);
|
491 |
|
|
} else {
|
492 |
|
|
/* trampoline - the desired return ip is the retcode itself */
|
493 |
|
|
return_ip = (unsigned long)&frame->retcode;
|
494 |
|
|
phx_signal("ktrampoline: return_ip 0x%lx", return_ip);
|
495 |
|
|
/* This is l.ori r11,r0,__NR_sigreturn, l.sys 1 */
|
496 |
|
|
err |= __put_user(0xa960 , (short *)(frame->retcode+0));
|
497 |
|
|
err |= __put_user(__NR_sigreturn, (short *)(frame->retcode+2));
|
498 |
|
|
err |= __put_user(0x20000001, (unsigned long *)(frame->retcode+4));
|
499 |
|
|
err |= __put_user(0x15000000, (unsigned long *)(frame->retcode+8));
|
500 |
|
|
}
|
501 |
|
|
|
502 |
|
|
if (err)
|
503 |
|
|
goto give_sigsegv;
|
504 |
|
|
|
505 |
|
|
/* TODO what is the current->exec_domain stuff and invmap ? */
|
506 |
|
|
|
507 |
|
|
/* Set up registers for signal handler */
|
508 |
|
|
|
509 |
|
|
regs->pc = (unsigned long) ka->sa.sa_handler; /* what we enter NOW */
|
510 |
|
|
regs->gprs[7] = return_ip; /* what we enter LATER */
|
511 |
|
|
regs->gprs[1] = sig; /* first argument is signo */
|
512 |
|
|
regs->gprs[3] = (unsigned long) &frame->info; /* second argument is (siginfo_t *) */
|
513 |
|
|
regs->gprs[4] = 0; /* third argument is unused */
|
514 |
|
|
|
515 |
|
|
/* actually move the usp to reflect the stacked frame */
|
516 |
|
|
|
517 |
|
|
// wrusp((unsigned long)frame);
|
518 |
|
|
regs->sp = (unsigned long)frame;
|
519 |
|
|
|
520 |
|
|
return;
|
521 |
|
|
|
522 |
|
|
give_sigsegv:
|
523 |
|
|
if (sig == SIGSEGV)
|
524 |
|
|
ka->sa.sa_handler = SIG_DFL;
|
525 |
|
|
force_sig(SIGSEGV, current);
|
526 |
|
|
}
|
527 |
|
|
|
528 |
|
|
/*
|
529 |
|
|
* OK, we're invoking a handler
|
530 |
|
|
*/
|
531 |
|
|
|
532 |
|
|
extern inline void
|
533 |
|
|
handle_signal(int canrestart, unsigned long sig,
|
534 |
|
|
siginfo_t *info, struct k_sigaction *ka,
|
535 |
|
|
sigset_t *oldset, struct pt_regs * regs)
|
536 |
|
|
{
|
537 |
|
|
|
538 |
|
|
phx_signal("canrestart %d, sig %ld, ka %p, info %p, oldset %p, regs %p",
|
539 |
|
|
canrestart, sig, ka, info, oldset, regs);
|
540 |
|
|
|
541 |
|
|
phx_signal("(regs->pc 0x%lx, regs->sp 0x%lx, regs->gprs[7] 0x%lx)",
|
542 |
|
|
regs->pc, regs->sp, regs->gprs[7]);
|
543 |
|
|
|
544 |
|
|
/* Are we from a system call? */
|
545 |
|
|
if (canrestart) {
|
546 |
|
|
/* If so, check system call restarting.. */
|
547 |
|
|
switch (regs->gprs[1]) {
|
548 |
|
|
case -ERESTARTNOHAND:
|
549 |
|
|
/* ERESTARTNOHAND means that the syscall should only be
|
550 |
|
|
restarted if there was no handler for the signal, and since
|
551 |
|
|
we only get here if there is a handler, we dont restart */
|
552 |
|
|
regs->gprs[1] = -EINTR;
|
553 |
|
|
break;
|
554 |
|
|
|
555 |
|
|
case -ERESTARTSYS:
|
556 |
|
|
/* ERESTARTSYS means to restart the syscall if there is no
|
557 |
|
|
handler or the handler was registered with SA_RESTART */
|
558 |
|
|
if (!(ka->sa.sa_flags & SA_RESTART)) {
|
559 |
|
|
regs->gprs[1] = -EINTR;
|
560 |
|
|
break;
|
561 |
|
|
}
|
562 |
|
|
/* fallthrough */
|
563 |
|
|
case -ERESTARTNOINTR:
|
564 |
|
|
/* ERESTARTNOINTR means that the syscall should be called again
|
565 |
|
|
after the signal handler returns. */
|
566 |
|
|
RESTART_OR32_SYS(regs);
|
567 |
|
|
}
|
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_ONESHOT)
|
577 |
|
|
ka->sa.sa_handler = SIG_DFL;
|
578 |
|
|
|
579 |
|
|
if (!(ka->sa.sa_flags & SA_NODEFER)) {
|
580 |
|
|
spin_lock_irq(¤t->sighand->siglock);
|
581 |
|
|
sigorsets(¤t->blocked,¤t->blocked,&ka->sa.sa_mask);
|
582 |
|
|
sigaddset(¤t->blocked,sig);
|
583 |
|
|
recalc_sigpending();
|
584 |
|
|
spin_unlock_irq(¤t->sighand->siglock);
|
585 |
|
|
}
|
586 |
|
|
}
|
587 |
|
|
|
588 |
|
|
/*
|
589 |
|
|
* Note that 'init' is a special process: it doesn't get signals it doesn't
|
590 |
|
|
* want to handle. Thus you cannot kill init even with a SIGKILL even by
|
591 |
|
|
* mistake.
|
592 |
|
|
*
|
593 |
|
|
* Also note that the regs structure given here as an argument, is the latest
|
594 |
|
|
* pushed pt_regs. It may or may not be the same as the first pushed registers
|
595 |
|
|
* when the initial usermode->kernelmode transition took place. Therefore
|
596 |
|
|
* we can use user_mode(regs) to see if we came directly from kernel or user
|
597 |
|
|
* mode below.
|
598 |
|
|
*/
|
599 |
|
|
|
600 |
|
|
int do_signal(int canrestart, sigset_t *oldset, struct pt_regs *regs)
|
601 |
|
|
{
|
602 |
|
|
siginfo_t info;
|
603 |
|
|
int signr;
|
604 |
|
|
struct k_sigaction ka;
|
605 |
|
|
|
606 |
|
|
check_stack(NULL, __FILE__, __FUNCTION__, __LINE__);
|
607 |
|
|
|
608 |
|
|
phx_signal("canrestart %d, oldset %p, regs %p",
|
609 |
|
|
canrestart, oldset, regs);
|
610 |
|
|
|
611 |
|
|
/*
|
612 |
|
|
* We want the common case to go fast, which
|
613 |
|
|
* is why we may in certain cases get here from
|
614 |
|
|
* kernel mode. Just return without doing anything
|
615 |
|
|
* if so.
|
616 |
|
|
*/
|
617 |
|
|
if (!user_mode(regs))
|
618 |
|
|
return 1;
|
619 |
|
|
|
620 |
|
|
if (!oldset)
|
621 |
|
|
oldset = ¤t->blocked;
|
622 |
|
|
|
623 |
|
|
signr = get_signal_to_deliver(&info, &ka, regs, NULL);
|
624 |
|
|
if (signr > 0) {
|
625 |
|
|
/* Whee! Actually deliver the signal. */
|
626 |
|
|
handle_signal(canrestart, signr, &info, &ka, oldset, regs);
|
627 |
|
|
return 1;
|
628 |
|
|
}
|
629 |
|
|
|
630 |
|
|
/* Did we come from a system call? */
|
631 |
|
|
if (canrestart) {
|
632 |
|
|
/* Restart the system call - no handlers present */
|
633 |
|
|
if (regs->gprs[1] == -ERESTARTNOHAND ||
|
634 |
|
|
regs->gprs[1] == -ERESTARTSYS ||
|
635 |
|
|
regs->gprs[1] == -ERESTARTNOINTR) {
|
636 |
|
|
RESTART_OR32_SYS(regs);
|
637 |
|
|
}
|
638 |
|
|
if (regs->gprs[1] == -ERESTART_RESTARTBLOCK){
|
639 |
|
|
/* look at cris port how to handle this */
|
640 |
|
|
printk("do_signal: (%s:%d): don't know how to handle ERESTART_RESTARTBLOCK\n",
|
641 |
|
|
__FILE__, __LINE__);
|
642 |
|
|
}
|
643 |
|
|
}
|
644 |
|
|
|
645 |
|
|
return 0;
|
646 |
|
|
}
|
647 |
|
|
|