^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) * linux/arch/h8300/kernel/signal.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * Copyright (C) 1991, 1992 Linus Torvalds
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * This file is subject to the terms and conditions of the GNU General Public
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * License. See the file COPYING in the main directory of this archive
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * for more details.
^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) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) * uClinux H8/300 support by Yoshinori Sato <ysato@users.sourceforge.jp>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) * and David McCullough <davidm@snapgear.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) * Based on
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) * Linux/m68k by Hamish Macdonald
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) */
^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) * ++roman (07/09/96): implemented signal stacks (specially for tosemu on
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) * Atari :-) Current limitation: Only one sigstack can be active at one time.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) * If a second signal with SA_ONSTACK set arrives while working on a sigstack,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) * SA_ONSTACK is ignored. This behaviour avoids lots of trouble with nested
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) * signal handlers!
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #include <linux/sched.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #include <linux/sched/task_stack.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) #include <linux/mm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) #include <linux/signal.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) #include <linux/syscalls.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) #include <linux/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) #include <linux/wait.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) #include <linux/ptrace.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) #include <linux/unistd.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) #include <linux/stddef.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) #include <linux/highuid.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) #include <linux/personality.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) #include <linux/tty.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) #include <linux/binfmts.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) #include <linux/tracehook.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) #include <asm/setup.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) #include <linux/uaccess.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) #include <asm/traps.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) #include <asm/ucontext.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) * Do a signal return; undo the signal stack.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) * Keep the return code on the stack quadword aligned!
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) * That makes the cache flush below easier.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) struct rt_sigframe {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) long dummy_er0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) long dummy_vector;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) #if defined(CONFIG_CPU_H8S)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) short dummy_exr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) long dummy_pc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) char *pretcode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) struct siginfo *pinfo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) void *puc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) unsigned char retcode[8];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) struct siginfo info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) struct ucontext uc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) int sig;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) } __packed __aligned(2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) static inline int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) restore_sigcontext(struct sigcontext *usc, int *pd0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) struct pt_regs *regs = current_pt_regs();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) int err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) unsigned int ccr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) unsigned int usp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) unsigned int er0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) /* Always make any pending restarted system calls return -EINTR */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) current->restart_block.fn = do_no_restart_syscall;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) /* restore passed registers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) #define COPY(r) do { err |= get_user(regs->r, &usc->sc_##r); } while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) COPY(er1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) COPY(er2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) COPY(er3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) COPY(er5);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) COPY(pc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) ccr = regs->ccr & 0x10;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) COPY(ccr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) #undef COPY
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) regs->ccr &= 0xef;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) regs->ccr |= ccr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) regs->orig_er0 = -1; /* disable syscall checks */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) err |= __get_user(usp, &usc->sc_usp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) regs->sp = usp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) err |= __get_user(er0, &usc->sc_er0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) *pd0 = er0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) asmlinkage int sys_rt_sigreturn(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) unsigned long usp = rdusp();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) struct rt_sigframe *frame = (struct rt_sigframe *)(usp - 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) sigset_t set;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) int er0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) if (!access_ok(frame, sizeof(*frame)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) goto badframe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) goto badframe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) set_current_blocked(&set);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) if (restore_sigcontext(&frame->uc.uc_mcontext, &er0))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) goto badframe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) if (restore_altstack(&frame->uc.uc_stack))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) goto badframe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) return er0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) badframe:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) force_sig(SIGSEGV);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) static int setup_sigcontext(struct sigcontext __user *sc, struct pt_regs *regs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) unsigned long mask)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) int err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) err |= __put_user(regs->er0, &sc->sc_er0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) err |= __put_user(regs->er1, &sc->sc_er1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) err |= __put_user(regs->er2, &sc->sc_er2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) err |= __put_user(regs->er3, &sc->sc_er3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) err |= __put_user(regs->er4, &sc->sc_er4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) err |= __put_user(regs->er5, &sc->sc_er5);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) err |= __put_user(regs->er6, &sc->sc_er6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) err |= __put_user(rdusp(), &sc->sc_usp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) err |= __put_user(regs->pc, &sc->sc_pc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) err |= __put_user(regs->ccr, &sc->sc_ccr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) err |= __put_user(mask, &sc->sc_mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) static inline void __user *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) get_sigframe(struct ksignal *ksig, struct pt_regs *regs, size_t frame_size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) return (void __user *)((sigsp(rdusp(), ksig) - frame_size) & -8UL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) static int setup_rt_frame(struct ksignal *ksig, sigset_t *set,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) struct pt_regs *regs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) struct rt_sigframe *frame;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) int err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) unsigned char *ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) frame = get_sigframe(ksig, regs, sizeof(*frame));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) if (!access_ok(frame, sizeof(*frame)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) if (ksig->ka.sa.sa_flags & SA_SIGINFO)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) err |= copy_siginfo_to_user(&frame->info, &ksig->info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) /* Create the ucontext. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) err |= __put_user(0, &frame->uc.uc_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) err |= __put_user(0, &frame->uc.uc_link);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) err |= __save_altstack(&frame->uc.uc_stack, rdusp());
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) err |= setup_sigcontext(&frame->uc.uc_mcontext, regs, set->sig[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) err |= copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) /* Set up to return from userspace. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) ret = (unsigned char *)&frame->retcode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) if (ksig->ka.sa.sa_flags & SA_RESTORER)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) ret = (unsigned char *)(ksig->ka.sa.sa_restorer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) /* sub.l er0,er0; mov.b #__NR_rt_sigreturn,r0l; trapa #0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) err |= __put_user(0x1a80f800 + (__NR_rt_sigreturn & 0xff),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) (unsigned long *)(frame->retcode + 0));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) err |= __put_user(0x5700,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) (unsigned short *)(frame->retcode + 4));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) err |= __put_user(ret, &frame->pretcode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) /* Set up registers for signal handler */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) regs->sp = (unsigned long)frame;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) regs->pc = (unsigned long)ksig->ka.sa.sa_handler;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) regs->er0 = ksig->sig;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) regs->er1 = (unsigned long)&(frame->info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) regs->er2 = (unsigned long)&frame->uc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) regs->er5 = current->mm->start_data; /* GOT base */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) handle_restart(struct pt_regs *regs, struct k_sigaction *ka)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) switch (regs->er0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) case -ERESTARTNOHAND:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) if (!ka)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) goto do_restart;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) regs->er0 = -EINTR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) case -ERESTART_RESTARTBLOCK:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) if (!ka) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) regs->er0 = __NR_restart_syscall;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) regs->pc -= 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) regs->er0 = -EINTR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) case -ERESTARTSYS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) if (!(ka->sa.sa_flags & SA_RESTART)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) regs->er0 = -EINTR;
^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) fallthrough;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) case -ERESTARTNOINTR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) do_restart:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) regs->er0 = regs->orig_er0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) regs->pc -= 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) * OK, we're invoking a handler
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) handle_signal(struct ksignal *ksig, struct pt_regs *regs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) sigset_t *oldset = sigmask_to_save();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) /* are we from a system call? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) if (regs->orig_er0 >= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) handle_restart(regs, &ksig->ka);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) ret = setup_rt_frame(ksig, oldset, regs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) signal_setup_done(ret, ksig, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) * Note that 'init' is a special process: it doesn't get signals it doesn't
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) * want to handle. Thus you cannot kill init even with a SIGKILL even by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) * mistake.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) static void do_signal(struct pt_regs *regs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) struct ksignal ksig;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) current->thread.esp0 = (unsigned long) regs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) if (get_signal(&ksig)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) /* Whee! Actually deliver the signal. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) handle_signal(&ksig, regs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) /* Did we come from a system call? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) if (regs->orig_er0 >= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) handle_restart(regs, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) /* If there's no signal to deliver, we just restore the saved mask. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) restore_saved_sigmask();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) asmlinkage void do_notify_resume(struct pt_regs *regs, u32 thread_info_flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) if (thread_info_flags & _TIF_SIGPENDING)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) do_signal(regs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) if (thread_info_flags & _TIF_NOTIFY_RESUME)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) tracehook_notify_resume(regs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) }