Merge remote-tracking branch 'asoc/fix/sgtl5000' into asoc-linus
[deliverable/linux.git] / arch / arm / kernel / signal.c
CommitLineData
1da177e4
LT
1/*
2 * linux/arch/arm/kernel/signal.c
3 *
ab72b007 4 * Copyright (C) 1995-2009 Russell King
1da177e4
LT
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 */
1da177e4
LT
10#include <linux/errno.h>
11#include <linux/signal.h>
1da177e4 12#include <linux/personality.h>
33fa9b13 13#include <linux/uaccess.h>
733e5e4b 14#include <linux/tracehook.h>
1da177e4 15
ee90dabc 16#include <asm/elf.h>
1da177e4
LT
17#include <asm/cacheflush.h>
18#include <asm/ucontext.h>
1da177e4 19#include <asm/unistd.h>
82c6f5a5 20#include <asm/vfp.h>
1da177e4 21
e00d349e 22#include "signal.h"
1da177e4 23
1da177e4
LT
24/*
25 * For ARM syscalls, we encode the syscall number into the instruction.
26 */
ee4cd588 27#define SWI_SYS_SIGRETURN (0xef000000|(__NR_sigreturn)|(__NR_OABI_SYSCALL_BASE))
28#define SWI_SYS_RT_SIGRETURN (0xef000000|(__NR_rt_sigreturn)|(__NR_OABI_SYSCALL_BASE))
1da177e4 29
fcca538b
NP
30/*
31 * With EABI, the syscall number has to be loaded into r7.
32 */
33#define MOV_R7_NR_SIGRETURN (0xe3a07000 | (__NR_sigreturn - __NR_SYSCALL_BASE))
34#define MOV_R7_NR_RT_SIGRETURN (0xe3a07000 | (__NR_rt_sigreturn - __NR_SYSCALL_BASE))
35
1da177e4
LT
36/*
37 * For Thumb syscalls, we pass the syscall number via r7. We therefore
38 * need two 16-bit instructions.
39 */
40#define SWI_THUMB_SIGRETURN (0xdf00 << 16 | 0x2700 | (__NR_sigreturn - __NR_SYSCALL_BASE))
41#define SWI_THUMB_RT_SIGRETURN (0xdf00 << 16 | 0x2700 | (__NR_rt_sigreturn - __NR_SYSCALL_BASE))
42
fcca538b
NP
43const unsigned long sigreturn_codes[7] = {
44 MOV_R7_NR_SIGRETURN, SWI_SYS_SIGRETURN, SWI_THUMB_SIGRETURN,
45 MOV_R7_NR_RT_SIGRETURN, SWI_SYS_RT_SIGRETURN, SWI_THUMB_RT_SIGRETURN,
1da177e4
LT
46};
47
3bec6ded 48#ifdef CONFIG_CRUNCH
65a5053b 49static int preserve_crunch_context(struct crunch_sigframe __user *frame)
3bec6ded
LB
50{
51 char kbuf[sizeof(*frame) + 8];
52 struct crunch_sigframe *kframe;
53
54 /* the crunch context must be 64 bit aligned */
55 kframe = (struct crunch_sigframe *)((unsigned long)(kbuf + 8) & ~7);
56 kframe->magic = CRUNCH_MAGIC;
57 kframe->size = CRUNCH_STORAGE_SIZE;
58 crunch_task_copy(current_thread_info(), &kframe->storage);
59 return __copy_to_user(frame, kframe, sizeof(*frame));
60}
61
65a5053b 62static int restore_crunch_context(struct crunch_sigframe __user *frame)
3bec6ded
LB
63{
64 char kbuf[sizeof(*frame) + 8];
65 struct crunch_sigframe *kframe;
66
67 /* the crunch context must be 64 bit aligned */
68 kframe = (struct crunch_sigframe *)((unsigned long)(kbuf + 8) & ~7);
69 if (__copy_from_user(kframe, frame, sizeof(*frame)))
70 return -1;
71 if (kframe->magic != CRUNCH_MAGIC ||
72 kframe->size != CRUNCH_STORAGE_SIZE)
73 return -1;
74 crunch_task_restore(current_thread_info(), &kframe->storage);
75 return 0;
76}
77#endif
78
1da177e4
LT
79#ifdef CONFIG_IWMMXT
80
1da177e4
LT
81static int preserve_iwmmxt_context(struct iwmmxt_sigframe *frame)
82{
69b04754
HD
83 char kbuf[sizeof(*frame) + 8];
84 struct iwmmxt_sigframe *kframe;
1da177e4
LT
85
86 /* the iWMMXt context must be 64 bit aligned */
69b04754 87 kframe = (struct iwmmxt_sigframe *)((unsigned long)(kbuf + 8) & ~7);
85fe0681
DJ
88 kframe->magic = IWMMXT_MAGIC;
89 kframe->size = IWMMXT_STORAGE_SIZE;
69b04754
HD
90 iwmmxt_task_copy(current_thread_info(), &kframe->storage);
91 return __copy_to_user(frame, kframe, sizeof(*frame));
1da177e4
LT
92}
93
94static int restore_iwmmxt_context(struct iwmmxt_sigframe *frame)
95{
69b04754
HD
96 char kbuf[sizeof(*frame) + 8];
97 struct iwmmxt_sigframe *kframe;
98
99 /* the iWMMXt context must be 64 bit aligned */
100 kframe = (struct iwmmxt_sigframe *)((unsigned long)(kbuf + 8) & ~7);
101 if (__copy_from_user(kframe, frame, sizeof(*frame)))
102 return -1;
85fe0681
DJ
103 if (kframe->magic != IWMMXT_MAGIC ||
104 kframe->size != IWMMXT_STORAGE_SIZE)
69b04754
HD
105 return -1;
106 iwmmxt_task_restore(current_thread_info(), &kframe->storage);
107 return 0;
1da177e4
LT
108}
109
110#endif
111
82c6f5a5
ID
112#ifdef CONFIG_VFP
113
114static int preserve_vfp_context(struct vfp_sigframe __user *frame)
115{
82c6f5a5
ID
116 const unsigned long magic = VFP_MAGIC;
117 const unsigned long size = VFP_STORAGE_SIZE;
118 int err = 0;
119
82c6f5a5
ID
120 __put_user_error(magic, &frame->magic, err);
121 __put_user_error(size, &frame->size, err);
122
2498814f
WD
123 if (err)
124 return -EFAULT;
125
126 return vfp_preserve_user_clear_hwstate(&frame->ufp, &frame->ufp_exc);
82c6f5a5
ID
127}
128
129static int restore_vfp_context(struct vfp_sigframe __user *frame)
130{
82c6f5a5
ID
131 unsigned long magic;
132 unsigned long size;
82c6f5a5
ID
133 int err = 0;
134
135 __get_user_error(magic, &frame->magic, err);
136 __get_user_error(size, &frame->size, err);
137
138 if (err)
139 return -EFAULT;
140 if (magic != VFP_MAGIC || size != VFP_STORAGE_SIZE)
141 return -EINVAL;
142
2498814f 143 return vfp_restore_user_hwstate(&frame->ufp, &frame->ufp_exc);
82c6f5a5
ID
144}
145
146#endif
147
1da177e4
LT
148/*
149 * Do a signal return; undo the signal stack. These are aligned to 64-bit.
150 */
151struct sigframe {
7d4fdc19 152 struct ucontext uc;
fcca538b 153 unsigned long retcode[2];
1da177e4
LT
154};
155
156struct rt_sigframe {
1da177e4 157 struct siginfo info;
cb3504e8 158 struct sigframe sig;
1da177e4
LT
159};
160
68071484 161static int restore_sigframe(struct pt_regs *regs, struct sigframe __user *sf)
1da177e4 162{
85fe0681 163 struct aux_sigframe __user *aux;
68071484
RK
164 sigset_t set;
165 int err;
166
167 err = __copy_from_user(&set, &sf->uc.uc_sigmask, sizeof(set));
77097ae5 168 if (err == 0)
101d9b0d 169 set_current_blocked(&set);
1da177e4 170
68071484
RK
171 __get_user_error(regs->ARM_r0, &sf->uc.uc_mcontext.arm_r0, err);
172 __get_user_error(regs->ARM_r1, &sf->uc.uc_mcontext.arm_r1, err);
173 __get_user_error(regs->ARM_r2, &sf->uc.uc_mcontext.arm_r2, err);
174 __get_user_error(regs->ARM_r3, &sf->uc.uc_mcontext.arm_r3, err);
175 __get_user_error(regs->ARM_r4, &sf->uc.uc_mcontext.arm_r4, err);
176 __get_user_error(regs->ARM_r5, &sf->uc.uc_mcontext.arm_r5, err);
177 __get_user_error(regs->ARM_r6, &sf->uc.uc_mcontext.arm_r6, err);
178 __get_user_error(regs->ARM_r7, &sf->uc.uc_mcontext.arm_r7, err);
179 __get_user_error(regs->ARM_r8, &sf->uc.uc_mcontext.arm_r8, err);
180 __get_user_error(regs->ARM_r9, &sf->uc.uc_mcontext.arm_r9, err);
181 __get_user_error(regs->ARM_r10, &sf->uc.uc_mcontext.arm_r10, err);
182 __get_user_error(regs->ARM_fp, &sf->uc.uc_mcontext.arm_fp, err);
183 __get_user_error(regs->ARM_ip, &sf->uc.uc_mcontext.arm_ip, err);
184 __get_user_error(regs->ARM_sp, &sf->uc.uc_mcontext.arm_sp, err);
185 __get_user_error(regs->ARM_lr, &sf->uc.uc_mcontext.arm_lr, err);
186 __get_user_error(regs->ARM_pc, &sf->uc.uc_mcontext.arm_pc, err);
187 __get_user_error(regs->ARM_cpsr, &sf->uc.uc_mcontext.arm_cpsr, err);
1da177e4
LT
188
189 err |= !valid_user_regs(regs);
190
85fe0681 191 aux = (struct aux_sigframe __user *) sf->uc.uc_regspace;
3bec6ded
LB
192#ifdef CONFIG_CRUNCH
193 if (err == 0)
194 err |= restore_crunch_context(&aux->crunch);
195#endif
1da177e4
LT
196#ifdef CONFIG_IWMMXT
197 if (err == 0 && test_thread_flag(TIF_USING_IWMMXT))
198 err |= restore_iwmmxt_context(&aux->iwmmxt);
199#endif
200#ifdef CONFIG_VFP
82c6f5a5
ID
201 if (err == 0)
202 err |= restore_vfp_context(&aux->vfp);
1da177e4
LT
203#endif
204
205 return err;
206}
207
208asmlinkage int sys_sigreturn(struct pt_regs *regs)
209{
210 struct sigframe __user *frame;
1da177e4
LT
211
212 /* Always make any pending restarted system calls return -EINTR */
213 current_thread_info()->restart_block.fn = do_no_restart_syscall;
214
215 /*
216 * Since we stacked the signal on a 64-bit boundary,
217 * then 'sp' should be word aligned here. If it's
218 * not, then the user is trying to mess with us.
219 */
220 if (regs->ARM_sp & 7)
221 goto badframe;
222
223 frame = (struct sigframe __user *)regs->ARM_sp;
224
225 if (!access_ok(VERIFY_READ, frame, sizeof (*frame)))
226 goto badframe;
1da177e4 227
68071484 228 if (restore_sigframe(regs, frame))
1da177e4
LT
229 goto badframe;
230
1da177e4
LT
231 return regs->ARM_r0;
232
233badframe:
234 force_sig(SIGSEGV, current);
235 return 0;
236}
237
238asmlinkage int sys_rt_sigreturn(struct pt_regs *regs)
239{
240 struct rt_sigframe __user *frame;
1da177e4
LT
241
242 /* Always make any pending restarted system calls return -EINTR */
243 current_thread_info()->restart_block.fn = do_no_restart_syscall;
244
245 /*
246 * Since we stacked the signal on a 64-bit boundary,
247 * then 'sp' should be word aligned here. If it's
248 * not, then the user is trying to mess with us.
249 */
250 if (regs->ARM_sp & 7)
251 goto badframe;
252
253 frame = (struct rt_sigframe __user *)regs->ARM_sp;
254
255 if (!access_ok(VERIFY_READ, frame, sizeof (*frame)))
256 goto badframe;
1da177e4 257
68071484 258 if (restore_sigframe(regs, &frame->sig))
1da177e4
LT
259 goto badframe;
260
ec93ac86 261 if (restore_altstack(&frame->sig.uc.uc_stack))
1da177e4
LT
262 goto badframe;
263
1da177e4
LT
264 return regs->ARM_r0;
265
266badframe:
267 force_sig(SIGSEGV, current);
268 return 0;
269}
270
271static int
aca6ca10 272setup_sigframe(struct sigframe __user *sf, struct pt_regs *regs, sigset_t *set)
1da177e4 273{
85fe0681 274 struct aux_sigframe __user *aux;
1da177e4
LT
275 int err = 0;
276
aca6ca10
RK
277 __put_user_error(regs->ARM_r0, &sf->uc.uc_mcontext.arm_r0, err);
278 __put_user_error(regs->ARM_r1, &sf->uc.uc_mcontext.arm_r1, err);
279 __put_user_error(regs->ARM_r2, &sf->uc.uc_mcontext.arm_r2, err);
280 __put_user_error(regs->ARM_r3, &sf->uc.uc_mcontext.arm_r3, err);
281 __put_user_error(regs->ARM_r4, &sf->uc.uc_mcontext.arm_r4, err);
282 __put_user_error(regs->ARM_r5, &sf->uc.uc_mcontext.arm_r5, err);
283 __put_user_error(regs->ARM_r6, &sf->uc.uc_mcontext.arm_r6, err);
284 __put_user_error(regs->ARM_r7, &sf->uc.uc_mcontext.arm_r7, err);
285 __put_user_error(regs->ARM_r8, &sf->uc.uc_mcontext.arm_r8, err);
286 __put_user_error(regs->ARM_r9, &sf->uc.uc_mcontext.arm_r9, err);
287 __put_user_error(regs->ARM_r10, &sf->uc.uc_mcontext.arm_r10, err);
288 __put_user_error(regs->ARM_fp, &sf->uc.uc_mcontext.arm_fp, err);
289 __put_user_error(regs->ARM_ip, &sf->uc.uc_mcontext.arm_ip, err);
290 __put_user_error(regs->ARM_sp, &sf->uc.uc_mcontext.arm_sp, err);
291 __put_user_error(regs->ARM_lr, &sf->uc.uc_mcontext.arm_lr, err);
292 __put_user_error(regs->ARM_pc, &sf->uc.uc_mcontext.arm_pc, err);
293 __put_user_error(regs->ARM_cpsr, &sf->uc.uc_mcontext.arm_cpsr, err);
294
295 __put_user_error(current->thread.trap_no, &sf->uc.uc_mcontext.trap_no, err);
296 __put_user_error(current->thread.error_code, &sf->uc.uc_mcontext.error_code, err);
297 __put_user_error(current->thread.address, &sf->uc.uc_mcontext.fault_address, err);
298 __put_user_error(set->sig[0], &sf->uc.uc_mcontext.oldmask, err);
299
300 err |= __copy_to_user(&sf->uc.uc_sigmask, set, sizeof(*set));
1da177e4 301
85fe0681 302 aux = (struct aux_sigframe __user *) sf->uc.uc_regspace;
3bec6ded
LB
303#ifdef CONFIG_CRUNCH
304 if (err == 0)
305 err |= preserve_crunch_context(&aux->crunch);
306#endif
1da177e4
LT
307#ifdef CONFIG_IWMMXT
308 if (err == 0 && test_thread_flag(TIF_USING_IWMMXT))
309 err |= preserve_iwmmxt_context(&aux->iwmmxt);
310#endif
311#ifdef CONFIG_VFP
82c6f5a5
ID
312 if (err == 0)
313 err |= preserve_vfp_context(&aux->vfp);
1da177e4 314#endif
85fe0681 315 __put_user_error(0, &aux->end_magic, err);
1da177e4
LT
316
317 return err;
318}
319
320static inline void __user *
7e243643 321get_sigframe(struct ksignal *ksig, struct pt_regs *regs, int framesize)
1da177e4 322{
7e243643 323 unsigned long sp = sigsp(regs->ARM_sp, ksig);
1da177e4
LT
324 void __user *frame;
325
1da177e4
LT
326 /*
327 * ATPCS B01 mandates 8-byte alignment
328 */
329 frame = (void __user *)((sp - framesize) & ~7);
330
331 /*
332 * Check that we can actually write to the signal frame.
333 */
334 if (!access_ok(VERIFY_WRITE, frame, framesize))
335 frame = NULL;
336
337 return frame;
338}
339
7e243643
AV
340/*
341 * translate the signal
342 */
343static inline int map_sig(int sig)
344{
345 struct thread_info *thread = current_thread_info();
346 if (sig < 32 && thread->exec_domain && thread->exec_domain->signal_invmap)
347 sig = thread->exec_domain->signal_invmap[sig];
348 return sig;
349}
350
1da177e4 351static int
7e243643
AV
352setup_return(struct pt_regs *regs, struct ksignal *ksig,
353 unsigned long __user *rc, void __user *frame)
1da177e4 354{
7e243643 355 unsigned long handler = (unsigned long)ksig->ka.sa.sa_handler;
1da177e4
LT
356 unsigned long retcode;
357 int thumb = 0;
53399053
RK
358 unsigned long cpsr = regs->ARM_cpsr & ~(PSR_f | PSR_E_BIT);
359
360 cpsr |= PSR_ENDSTATE;
1da177e4
LT
361
362 /*
363 * Maybe we need to deliver a 32-bit signal to a 26-bit task.
364 */
7e243643 365 if (ksig->ka.sa.sa_flags & SA_THIRTYTWO)
1da177e4
LT
366 cpsr = (cpsr & ~MODE_MASK) | USR_MODE;
367
368#ifdef CONFIG_ARM_THUMB
369 if (elf_hwcap & HWCAP_THUMB) {
370 /*
371 * The LSB of the handler determines if we're going to
372 * be using THUMB or ARM mode for this signal handler.
373 */
374 thumb = handler & 1;
375
d71e1352 376 if (thumb) {
1da177e4 377 cpsr |= PSR_T_BIT;
d71e1352
CM
378#if __LINUX_ARM_ARCH__ >= 7
379 /* clear the If-Then Thumb-2 execution state */
380 cpsr &= ~PSR_IT_MASK;
381#endif
382 } else
1da177e4
LT
383 cpsr &= ~PSR_T_BIT;
384 }
385#endif
386
7e243643
AV
387 if (ksig->ka.sa.sa_flags & SA_RESTORER) {
388 retcode = (unsigned long)ksig->ka.sa.sa_restorer;
1da177e4 389 } else {
fcca538b 390 unsigned int idx = thumb << 1;
1da177e4 391
7e243643 392 if (ksig->ka.sa.sa_flags & SA_SIGINFO)
fcca538b 393 idx += 3;
1da177e4 394
9dfc28b6
JA
395 /*
396 * Put the sigreturn code on the stack no matter which return
397 * mechanism we use in order to remain ABI compliant
398 */
fcca538b
NP
399 if (__put_user(sigreturn_codes[idx], rc) ||
400 __put_user(sigreturn_codes[idx+1], rc+1))
1da177e4
LT
401 return 1;
402
9dfc28b6 403 if ((cpsr & MODE32_BIT) && !IS_ENABLED(CONFIG_ARM_MPU)) {
e00d349e
RK
404 /*
405 * 32-bit code can use the new high-page
9dfc28b6
JA
406 * signal return code support except when the MPU has
407 * protected the vectors page from PL0
e00d349e
RK
408 */
409 retcode = KERN_SIGRETURN_CODE + (idx << 2) + thumb;
410 } else {
411 /*
412 * Ensure that the instruction cache sees
413 * the return code written onto the stack.
414 */
415 flush_icache_range((unsigned long)rc,
fcca538b 416 (unsigned long)(rc + 2));
e00d349e
RK
417
418 retcode = ((unsigned long)rc) + thumb;
419 }
1da177e4
LT
420 }
421
7e243643 422 regs->ARM_r0 = map_sig(ksig->sig);
1da177e4
LT
423 regs->ARM_sp = (unsigned long)frame;
424 regs->ARM_lr = retcode;
425 regs->ARM_pc = handler;
426 regs->ARM_cpsr = cpsr;
427
428 return 0;
429}
430
431static int
7e243643 432setup_frame(struct ksignal *ksig, sigset_t *set, struct pt_regs *regs)
1da177e4 433{
7e243643 434 struct sigframe __user *frame = get_sigframe(ksig, regs, sizeof(*frame));
1da177e4
LT
435 int err = 0;
436
437 if (!frame)
438 return 1;
439
ca195cfe
RK
440 /*
441 * Set uc.uc_flags to a value which sc.trap_no would never have.
442 */
443 __put_user_error(0x5ac3c35a, &frame->uc.uc_flags, err);
1da177e4 444
aca6ca10 445 err |= setup_sigframe(frame, regs, set);
1da177e4 446 if (err == 0)
7e243643 447 err = setup_return(regs, ksig, frame->retcode, frame);
1da177e4
LT
448
449 return err;
450}
451
452static int
7e243643 453setup_rt_frame(struct ksignal *ksig, sigset_t *set, struct pt_regs *regs)
1da177e4 454{
7e243643 455 struct rt_sigframe __user *frame = get_sigframe(ksig, regs, sizeof(*frame));
1da177e4
LT
456 int err = 0;
457
458 if (!frame)
459 return 1;
460
7e243643 461 err |= copy_siginfo_to_user(&frame->info, &ksig->info);
1da177e4 462
cb3504e8
RK
463 __put_user_error(0, &frame->sig.uc.uc_flags, err);
464 __put_user_error(NULL, &frame->sig.uc.uc_link, err);
1da177e4 465
ec93ac86 466 err |= __save_altstack(&frame->sig.uc.uc_stack, regs->ARM_sp);
aca6ca10 467 err |= setup_sigframe(&frame->sig, regs, set);
1da177e4 468 if (err == 0)
7e243643 469 err = setup_return(regs, ksig, frame->sig.retcode, frame);
1da177e4
LT
470
471 if (err == 0) {
472 /*
473 * For realtime signals we must also set the second and third
474 * arguments for the signal handler.
475 * -- Peter Maydell <pmaydell@chiark.greenend.org.uk> 2000-12-06
476 */
477 regs->ARM_r1 = (unsigned long)&frame->info;
cb3504e8 478 regs->ARM_r2 = (unsigned long)&frame->sig.uc;
1da177e4
LT
479 }
480
481 return err;
482}
483
1da177e4
LT
484/*
485 * OK, we're invoking a handler
486 */
7e243643 487static void handle_signal(struct ksignal *ksig, struct pt_regs *regs)
1da177e4 488{
b7f9a11a 489 sigset_t *oldset = sigmask_to_save();
1da177e4
LT
490 int ret;
491
1da177e4
LT
492 /*
493 * Set up the stack frame
494 */
7e243643
AV
495 if (ksig->ka.sa.sa_flags & SA_SIGINFO)
496 ret = setup_rt_frame(ksig, oldset, regs);
1da177e4 497 else
7e243643 498 ret = setup_frame(ksig, oldset, regs);
1da177e4
LT
499
500 /*
501 * Check that the resulting registers are actually sane.
502 */
503 ret |= !valid_user_regs(regs);
504
7e243643 505 signal_setup_done(ret, ksig, 0);
1da177e4
LT
506}
507
508/*
509 * Note that 'init' is a special process: it doesn't get signals it doesn't
510 * want to handle. Thus you cannot kill init even with a SIGKILL even by
511 * mistake.
512 *
513 * Note that we go through the signals twice: once to check the signals that
514 * the kernel can handle, and then we build all the user-level signal handling
515 * stack-frames in one go after that.
516 */
81783786 517static int do_signal(struct pt_regs *regs, int syscall)
1da177e4 518{
2af68df0 519 unsigned int retval = 0, continue_addr = 0, restart_addr = 0;
7e243643 520 struct ksignal ksig;
81783786 521 int restart = 0;
1da177e4 522
2af68df0
AB
523 /*
524 * If we were from a system call, check for system call restarting...
525 */
526 if (syscall) {
527 continue_addr = regs->ARM_pc;
528 restart_addr = continue_addr - (thumb_mode(regs) ? 2 : 4);
529 retval = regs->ARM_r0;
530
531 /*
532 * Prepare for system call restart. We do this here so that a
533 * debugger will see the already changed PSW.
534 */
535 switch (retval) {
81783786 536 case -ERESTART_RESTARTBLOCK:
66285217 537 restart -= 2;
2af68df0
AB
538 case -ERESTARTNOHAND:
539 case -ERESTARTSYS:
540 case -ERESTARTNOINTR:
81783786 541 restart++;
2af68df0
AB
542 regs->ARM_r0 = regs->ARM_ORIG_r0;
543 regs->ARM_pc = restart_addr;
544 break;
2af68df0
AB
545 }
546 }
547
2af68df0
AB
548 /*
549 * Get the signal to deliver. When running under ptrace, at this
550 * point the debugger may change all our registers ...
551 */
81783786
AV
552 /*
553 * Depending on the signal settings we may need to revert the
554 * decision to restart the system call. But skip this if a
555 * debugger has chosen to restart at a different PC.
556 */
7e243643
AV
557 if (get_signal(&ksig)) {
558 /* handler */
559 if (unlikely(restart) && regs->ARM_pc == restart_addr) {
ad82cc08
WD
560 if (retval == -ERESTARTNOHAND ||
561 retval == -ERESTART_RESTARTBLOCK
2af68df0 562 || (retval == -ERESTARTSYS
7e243643 563 && !(ksig.ka.sa.sa_flags & SA_RESTART))) {
2af68df0
AB
564 regs->ARM_r0 = -EINTR;
565 regs->ARM_pc = continue_addr;
566 }
567 }
7e243643
AV
568 handle_signal(&ksig, regs);
569 } else {
570 /* no handler */
571 restore_saved_sigmask();
572 if (unlikely(restart) && regs->ARM_pc == restart_addr) {
573 regs->ARM_pc = continue_addr;
574 return restart;
575 }
1da177e4 576 }
7e243643 577 return 0;
1da177e4
LT
578}
579
81783786 580asmlinkage int
0a267fa6 581do_work_pending(struct pt_regs *regs, unsigned int thread_flags, int syscall)
1da177e4 582{
0a267fa6
AV
583 do {
584 if (likely(thread_flags & _TIF_NEED_RESCHED)) {
585 schedule();
586 } else {
587 if (unlikely(!user_mode(regs)))
81783786 588 return 0;
0a267fa6
AV
589 local_irq_enable();
590 if (thread_flags & _TIF_SIGPENDING) {
66285217
AV
591 int restart = do_signal(regs, syscall);
592 if (unlikely(restart)) {
81783786
AV
593 /*
594 * Restart without handlers.
595 * Deal with it without leaving
596 * the kernel space.
597 */
66285217 598 return restart;
81783786 599 }
0a267fa6
AV
600 syscall = 0;
601 } else {
602 clear_thread_flag(TIF_NOTIFY_RESUME);
603 tracehook_notify_resume(regs);
604 }
605 }
606 local_irq_disable();
607 thread_flags = current_thread_info()->flags;
608 } while (thread_flags & _TIF_WORK_MASK);
81783786 609 return 0;
1da177e4 610}
This page took 0.646539 seconds and 5 git commands to generate.