^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Port on Texas Instruments TMS320C6x architecture
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright (C) 2004, 2006, 2009, 2010, 2011 Texas Instruments Incorporated
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Author: Aurelien Jacquiot (aurelien.jacquiot@jaluna.com)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * Updated for 2.6.34: Mark Salter <msalter@redhat.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/uaccess.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/syscalls.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/tracehook.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <asm/ucontext.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <asm/cacheflush.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) * Do a signal return, undo the signal stack.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #define RETCODE_SIZE (9 << 2) /* 9 instructions = 36 bytes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) struct rt_sigframe {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) struct siginfo __user *pinfo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) void __user *puc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) struct siginfo info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) struct ucontext uc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) unsigned long retcode[RETCODE_SIZE >> 2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) static int restore_sigcontext(struct pt_regs *regs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) struct sigcontext __user *sc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) int err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) /* The access_ok check was done by caller, so use __get_user here */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) #define COPY(x) (err |= __get_user(regs->x, &sc->sc_##x))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) COPY(sp); COPY(a4); COPY(b4); COPY(a6); COPY(b6); COPY(a8); COPY(b8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) COPY(a0); COPY(a1); COPY(a2); COPY(a3); COPY(a5); COPY(a7); COPY(a9);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) COPY(b0); COPY(b1); COPY(b2); COPY(b3); COPY(b5); COPY(b7); COPY(b9);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) COPY(a16); COPY(a17); COPY(a18); COPY(a19);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) COPY(a20); COPY(a21); COPY(a22); COPY(a23);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) COPY(a24); COPY(a25); COPY(a26); COPY(a27);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) COPY(a28); COPY(a29); COPY(a30); COPY(a31);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) COPY(b16); COPY(b17); COPY(b18); COPY(b19);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) COPY(b20); COPY(b21); COPY(b22); COPY(b23);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) COPY(b24); COPY(b25); COPY(b26); COPY(b27);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) COPY(b28); COPY(b29); COPY(b30); COPY(b31);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) COPY(csr); COPY(pc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) #undef COPY
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) asmlinkage int do_rt_sigreturn(struct pt_regs *regs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) struct rt_sigframe __user *frame;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) sigset_t set;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) /* Always make any pending restarted system calls return -EINTR */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) current->restart_block.fn = do_no_restart_syscall;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) * Since we stacked the signal on a dword boundary,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) * 'sp' should be dword aligned here. If it's
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) * not, then the user is trying to mess with us.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) if (regs->sp & 7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) goto badframe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) frame = (struct rt_sigframe __user *) ((unsigned long) regs->sp + 8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) if (!access_ok(frame, sizeof(*frame)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) goto badframe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) goto badframe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) set_current_blocked(&set);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) if (restore_sigcontext(regs, &frame->uc.uc_mcontext))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) goto badframe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) return regs->a4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) badframe:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) force_sig(SIGSEGV);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) static int setup_sigcontext(struct sigcontext __user *sc, struct pt_regs *regs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) unsigned long mask)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) int err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) err |= __put_user(mask, &sc->sc_mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) /* The access_ok check was done by caller, so use __put_user here */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) #define COPY(x) (err |= __put_user(regs->x, &sc->sc_##x))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) COPY(sp); COPY(a4); COPY(b4); COPY(a6); COPY(b6); COPY(a8); COPY(b8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) COPY(a0); COPY(a1); COPY(a2); COPY(a3); COPY(a5); COPY(a7); COPY(a9);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) COPY(b0); COPY(b1); COPY(b2); COPY(b3); COPY(b5); COPY(b7); COPY(b9);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) COPY(a16); COPY(a17); COPY(a18); COPY(a19);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) COPY(a20); COPY(a21); COPY(a22); COPY(a23);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) COPY(a24); COPY(a25); COPY(a26); COPY(a27);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) COPY(a28); COPY(a29); COPY(a30); COPY(a31);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) COPY(b16); COPY(b17); COPY(b18); COPY(b19);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) COPY(b20); COPY(b21); COPY(b22); COPY(b23);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) COPY(b24); COPY(b25); COPY(b26); COPY(b27);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) COPY(b28); COPY(b29); COPY(b30); COPY(b31);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) COPY(csr); COPY(pc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) #undef COPY
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) static inline void __user *get_sigframe(struct ksignal *ksig,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) struct pt_regs *regs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) unsigned long framesize)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) unsigned long sp = sigsp(regs->sp, ksig);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) * No matter what happens, 'sp' must be dword
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) * aligned. Otherwise, nasty things will happen
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) return (void __user *)((sp - framesize) & ~7);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) static int setup_rt_frame(struct ksignal *ksig, sigset_t *set,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) struct pt_regs *regs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) struct rt_sigframe __user *frame;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) unsigned long __user *retcode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) int err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) frame = get_sigframe(ksig, regs, sizeof(*frame));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) if (!access_ok(frame, sizeof(*frame)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) err |= __put_user(&frame->info, &frame->pinfo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) err |= __put_user(&frame->uc, &frame->puc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) err |= copy_siginfo_to_user(&frame->info, &ksig->info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) /* Clear all the bits of the ucontext we don't use. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) err |= __clear_user(&frame->uc, offsetof(struct ucontext, uc_mcontext));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) err |= setup_sigcontext(&frame->uc.uc_mcontext, regs, set->sig[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) /* Set up to return from userspace */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) retcode = (unsigned long __user *) &frame->retcode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) /* The access_ok check was done above, so use __put_user here */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) #define COPY(x) (err |= __put_user(x, retcode++))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) COPY(0x0000002AUL | (__NR_rt_sigreturn << 7));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) /* MVK __NR_rt_sigreturn,B0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) COPY(0x10000000UL); /* SWE */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) COPY(0x00006000UL); /* NOP 4 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) COPY(0x00006000UL); /* NOP 4 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) COPY(0x00006000UL); /* NOP 4 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) COPY(0x00006000UL); /* NOP 4 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) COPY(0x00006000UL); /* NOP 4 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) COPY(0x00006000UL); /* NOP 4 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) COPY(0x00006000UL); /* NOP 4 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) #undef COPY
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) flush_icache_range((unsigned long) &frame->retcode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) (unsigned long) &frame->retcode + RETCODE_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) retcode = (unsigned long __user *) &frame->retcode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) /* Change user context to branch to signal handler */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) regs->sp = (unsigned long) frame - 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) regs->b3 = (unsigned long) retcode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) regs->pc = (unsigned long) ksig->ka.sa.sa_handler;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) /* Give the signal number to the handler */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) regs->a4 = ksig->sig;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) * For realtime signals we must also set the second and third
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) * arguments for the signal handler.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) * -- Peter Maydell <pmaydell@chiark.greenend.org.uk> 2000-12-06
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) regs->b4 = (unsigned long)&frame->info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) regs->a6 = (unsigned long)&frame->uc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) static inline void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) handle_restart(struct pt_regs *regs, struct k_sigaction *ka, int has_handler)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) switch (regs->a4) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) case -ERESTARTNOHAND:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) if (!has_handler)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) goto do_restart;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) regs->a4 = -EINTR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) case -ERESTARTSYS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) if (has_handler && !(ka->sa.sa_flags & SA_RESTART)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) regs->a4 = -EINTR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) fallthrough;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) case -ERESTARTNOINTR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) do_restart:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) regs->a4 = regs->orig_a4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) regs->pc -= 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) * handle the actual delivery of a signal to userspace
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) static void handle_signal(struct ksignal *ksig, struct pt_regs *regs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) int syscall)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) /* Are we from a system call? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) if (syscall) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) /* If so, check system call restarting.. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) switch (regs->a4) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) case -ERESTART_RESTARTBLOCK:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) case -ERESTARTNOHAND:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) regs->a4 = -EINTR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) case -ERESTARTSYS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) if (!(ksig->ka.sa.sa_flags & SA_RESTART)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) regs->a4 = -EINTR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) fallthrough;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) case -ERESTARTNOINTR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) regs->a4 = regs->orig_a4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) regs->pc -= 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) /* Set up the stack frame */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) ret = setup_rt_frame(ksig, sigmask_to_save(), regs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) signal_setup_done(ret, ksig, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) * handle a potential signal
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) static void do_signal(struct pt_regs *regs, int syscall)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) struct ksignal ksig;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) /* we want the common case to go fast, which is why we may in certain
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) * cases get here from kernel mode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) if (!user_mode(regs))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) if (get_signal(&ksig)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) handle_signal(&ksig, regs, syscall);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) /* did we come from a system call? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) if (syscall) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) /* restart the system call - no handlers present */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) switch (regs->a4) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) case -ERESTARTNOHAND:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) case -ERESTARTSYS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) case -ERESTARTNOINTR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) regs->a4 = regs->orig_a4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) regs->pc -= 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) case -ERESTART_RESTARTBLOCK:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) regs->a4 = regs->orig_a4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) regs->b0 = __NR_restart_syscall;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) regs->pc -= 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) /* if there's no signal to deliver, we just put the saved sigmask
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) * back */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) restore_saved_sigmask();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) * notification of userspace execution resumption
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) * - triggered by current->work.notify_resume
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) asmlinkage void do_notify_resume(struct pt_regs *regs, u32 thread_info_flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) int syscall)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) /* deal with pending signal delivery */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) if (thread_info_flags & (1 << TIF_SIGPENDING))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) do_signal(regs, syscall);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) if (thread_info_flags & (1 << TIF_NOTIFY_RESUME))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) tracehook_notify_resume(regs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) }