1 // SPDX-License-Identifier: GPL-2.0-or-later !! 1 /* $Id: signal32.c,v 1.70 2001/04/24 01:09:12 davem Exp $ 2 /* Signal support for 32-bit kernel builds !! 2 * arch/sparc64/kernel/signal32.c 3 * 3 * 4 * Copyright (C) 2001 Matthew Wilcox <willy !! 4 * Copyright (C) 1991, 1992 Linus Torvalds 5 * Copyright (C) 2006 Kyle McMartin <kyle a !! 5 * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu) 6 * !! 6 * Copyright (C) 1996 Miguel de Icaza (miguel@nuclecu.unam.mx) 7 * Code was mostly borrowed from kernel/sig !! 7 * Copyright (C) 1997 Eddie C. Dost (ecd@skynet.be) 8 * See kernel/signal.c for additional Copyr !! 8 * Copyright (C) 1997,1998 Jakub Jelinek (jj@sunsite.mff.cuni.cz) 9 */ 9 */ 10 10 11 #include <linux/compat.h> << 12 #include <linux/module.h> << 13 #include <linux/unistd.h> << 14 #include <linux/init.h> << 15 #include <linux/sched.h> 11 #include <linux/sched.h> 16 #include <linux/syscalls.h> !! 12 #include <linux/kernel.h> 17 #include <linux/types.h> !! 13 #include <linux/signal.h> 18 #include <linux/errno.h> 14 #include <linux/errno.h> >> 15 #include <linux/wait.h> >> 16 #include <linux/ptrace.h> >> 17 #include <linux/unistd.h> >> 18 #include <linux/mm.h> >> 19 #include <linux/smp_lock.h> 19 20 20 #include <linux/uaccess.h> !! 21 #include <asm/uaccess.h> >> 22 #include <asm/bitops.h> >> 23 #include <asm/ptrace.h> >> 24 #include <asm/svr4.h> >> 25 #include <asm/pgtable.h> >> 26 #include <asm/psrcompat.h> >> 27 #include <asm/fpumacro.h> >> 28 #include <asm/visasm.h> 21 29 22 #include "signal32.h" !! 30 #define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP))) 23 31 24 #define DEBUG_COMPAT_SIG 0 !! 32 asmlinkage int do_signal32(sigset_t *oldset, struct pt_regs *regs, 25 #define DEBUG_COMPAT_SIG_LEVEL 2 !! 33 unsigned long orig_o0, int ret_from_syscall); 26 34 27 #if DEBUG_COMPAT_SIG !! 35 /* This turned off for production... */ 28 #define DBG(LEVEL, ...) \ !! 36 /* #define DEBUG_SIGNALS 1 */ 29 ((DEBUG_COMPAT_SIG_LEVEL >= LEVEL) \ !! 37 /* #define DEBUG_SIGNALS_TRACE 1 */ 30 ? printk(__VA_ARGS__) : (void) 0) !! 38 /* #define DEBUG_SIGNALS_MAPS 1 */ 31 #else !! 39 /* #define DEBUG_SIGNALS_TLB 1 */ 32 #define DBG(LEVEL, ...) << 33 #endif << 34 40 35 long !! 41 /* Signal frames: the original one (compatible with SunOS): 36 restore_sigcontext32(struct compat_sigcontext !! 42 * 37 struct pt_regs *regs) !! 43 * Set up a signal frame... Make the stack look the way SunOS 38 { !! 44 * expects it to look which is basically: 39 long err = 0; !! 45 * 40 compat_uint_t compat_reg; !! 46 * ---------------------------------- <-- %sp at signal time 41 compat_uint_t compat_regt; !! 47 * Struct sigcontext 42 int regn; !! 48 * Signal address 43 !! 49 * Ptr to sigcontext area above 44 /* When loading 32-bit values into 64- !! 50 * Signal code 45 sure to clear the upper 32-bits */ !! 51 * The signal number itself 46 DBG(2,"restore_sigcontext32: PER_LINUX !! 52 * One register window 47 DBG(2,"restore_sigcontext32: sc = 0x%p !! 53 * ---------------------------------- <-- New %sp 48 DBG(2,"restore_sigcontext32: compat_si !! 54 */ 49 for(regn=0; regn < 32; regn++){ !! 55 struct signal_sframe32 { 50 err |= __get_user(compat_reg,& !! 56 struct reg_window32 sig_window; 51 regs->gr[regn] = compat_reg; !! 57 int sig_num; 52 /* Load upper half */ !! 58 int sig_code; 53 err |= __get_user(compat_regt, !! 59 /* struct sigcontext32 * */ u32 sig_scptr; 54 regs->gr[regn] = ((u64)compat_ !! 60 int sig_address; 55 DBG(3,"restore_sigcontext32: g !! 61 struct sigcontext32 sig_context; 56 regn, regs->gr !! 62 unsigned extramask[_NSIG_WORDS32 - 1]; 57 } !! 63 }; 58 DBG(2,"restore_sigcontext32: sc->sc_fr !! 64 59 /* XXX: BE WARNED FR's are 64-BIT! */ !! 65 /* This magic should be in g_upper[0] for all upper parts 60 err |= __copy_from_user(regs->fr, sc-> !! 66 * to be valid. 61 !! 67 */ 62 /* Better safe than sorry, pass __get_ !! 68 #define SIGINFO_EXTRA_V8PLUS_MAGIC 0x130e269 63 the same size and let gcc do the up !! 69 typedef struct { 64 64-bits */ !! 70 unsigned int g_upper[8]; 65 err |= __get_user(compat_reg, &sc->sc_ !! 71 unsigned int o_upper[8]; 66 /* Load upper half */ !! 72 unsigned int asi; 67 err |= __get_user(compat_regt, &rf->rf !! 73 } siginfo_extra_v8plus_t; 68 regs->iaoq[0] = ((u64)compat_regt << 3 !! 74 69 DBG(2,"restore_sigcontext32: upper hal !! 75 /* 70 DBG(2,"restore_sigcontext32: sc->sc_ia !! 76 * And the new one, intended to be used for Linux applications only 71 &sc->sc_iaoq[0], compa !! 77 * (we have enough in there to work with clone). 72 !! 78 * All the interesting bits are in the info field. 73 err |= __get_user(compat_reg, &sc->sc_ !! 79 */ 74 /* Load upper half */ !! 80 struct new_signal_frame32 { 75 err |= __get_user(compat_regt, &rf->rf !! 81 struct sparc_stackf32 ss; 76 regs->iaoq[1] = ((u64)compat_regt << 3 !! 82 __siginfo32_t info; 77 DBG(2,"restore_sigcontext32: upper hal !! 83 /* __siginfo_fpu32_t * */ u32 fpu_save; 78 DBG(2,"restore_sigcontext32: sc->sc_ia !! 84 unsigned int insns [2]; 79 &sc->sc_iaoq[1],compat !! 85 unsigned extramask[_NSIG_WORDS32 - 1]; 80 DBG(2,"restore_sigcontext32: iaoq is % !! 86 unsigned extra_size; /* Should be sizeof(siginfo_extra_v8plus_t) */ 81 regs->iaoq[0],regs->ia !! 87 /* Only valid if (info.si_regs.psr & (PSR_VERS|PSR_IMPL)) == PSR_V8PLUS */ 82 !! 88 siginfo_extra_v8plus_t v8plus; 83 err |= __get_user(compat_reg, &sc->sc_ !! 89 __siginfo_fpu_t fpu_state; 84 /* Load the upper half for iasq */ !! 90 }; 85 err |= __get_user(compat_regt, &rf->rf !! 91 86 regs->iasq[0] = ((u64)compat_regt << 3 !! 92 struct rt_signal_frame32 { 87 DBG(2,"restore_sigcontext32: upper hal !! 93 struct sparc_stackf32 ss; 88 !! 94 siginfo_t32 info; 89 err |= __get_user(compat_reg, &sc->sc_ !! 95 struct pt_regs32 regs; 90 /* Load the upper half for iasq */ !! 96 sigset_t32 mask; 91 err |= __get_user(compat_regt, &rf->rf !! 97 /* __siginfo_fpu32_t * */ u32 fpu_save; 92 regs->iasq[1] = ((u64)compat_regt << 3 !! 98 unsigned int insns [2]; 93 DBG(2,"restore_sigcontext32: upper hal !! 99 stack_t32 stack; 94 DBG(2,"restore_sigcontext32: iasq is % !! 100 unsigned extra_size; /* Should be sizeof(siginfo_extra_v8plus_t) */ 95 regs->iasq[0],regs->iasq[1]); !! 101 /* Only valid if (regs.psr & (PSR_VERS|PSR_IMPL)) == PSR_V8PLUS */ 96 !! 102 siginfo_extra_v8plus_t v8plus; 97 err |= __get_user(compat_reg, &sc->sc_ !! 103 __siginfo_fpu_t fpu_state; 98 /* Load the upper half for sar */ !! 104 }; 99 err |= __get_user(compat_regt, &rf->rf !! 105 100 regs->sar = ((u64)compat_regt << 32) | !! 106 /* Align macros */ 101 DBG(2,"restore_sigcontext32: upper_hal !! 107 #define SF_ALIGNEDSZ (((sizeof(struct signal_sframe32) + 7) & (~7))) 102 DBG(2,"restore_sigcontext32: sar is %# !! 108 #define NF_ALIGNEDSZ (((sizeof(struct new_signal_frame32) + 7) & (~7))) 103 DBG(2,"restore_sigcontext32: r28 is %l !! 109 #define RT_ALIGNEDSZ (((sizeof(struct rt_signal_frame32) + 7) & (~7))) 104 !! 110 >> 111 int copy_siginfo_to_user32(siginfo_t32 *to, siginfo_t *from) >> 112 { >> 113 int err; >> 114 >> 115 if (!access_ok (VERIFY_WRITE, to, sizeof(siginfo_t32))) >> 116 return -EFAULT; >> 117 >> 118 /* If you change siginfo_t structure, please be sure >> 119 this code is fixed accordingly. >> 120 It should never copy any pad contained in the structure >> 121 to avoid security leaks, but must copy the generic >> 122 3 ints plus the relevant union member. >> 123 This routine must convert siginfo from 64bit to 32bit as well >> 124 at the same time. */ >> 125 err = __put_user(from->si_signo, &to->si_signo); >> 126 err |= __put_user(from->si_errno, &to->si_errno); >> 127 err |= __put_user((short)from->si_code, &to->si_code); >> 128 if (from->si_code < 0) >> 129 err |= __copy_to_user(&to->_sifields._pad, &from->_sifields._pad, SI_PAD_SIZE); >> 130 else { >> 131 switch (from->si_code >> 16) { >> 132 case __SI_CHLD >> 16: >> 133 err |= __put_user(from->si_utime, &to->si_utime); >> 134 err |= __put_user(from->si_stime, &to->si_stime); >> 135 err |= __put_user(from->si_status, &to->si_status); >> 136 default: >> 137 err |= __put_user(from->si_pid, &to->si_pid); >> 138 err |= __put_user(from->si_uid, &to->si_uid); >> 139 break; >> 140 case __SI_FAULT >> 16: >> 141 case __SI_POLL >> 16: >> 142 err |= __put_user(from->si_trapno, &to->si_trapno); >> 143 err |= __put_user((long)from->si_addr, &to->si_addr); >> 144 break; >> 145 /* case __SI_RT: This is not generated by the kernel as of now. */ >> 146 } >> 147 } 105 return err; 148 return err; 106 } 149 } 107 150 108 /* 151 /* 109 * Set up the sigcontext structure for this pr !! 152 * atomically swap in the new signal mask, and wait for a signal. 110 * This is not an easy task if the kernel is 6 !! 153 * This is really tricky on the Sparc, watch out... 111 * that we examine the process personality to !! 154 */ 112 * truncate for a 32-bit userspace. !! 155 asmlinkage void _sigpause32_common(old_sigset_t32 set, struct pt_regs *regs) 113 */ !! 156 { 114 long !! 157 sigset_t saveset; 115 setup_sigcontext32(struct compat_sigcontext __ !! 158 116 struct pt_regs *regs, int in_s !! 159 set &= _BLOCKABLE; 117 { !! 160 spin_lock_irq(¤t->sigmask_lock); 118 compat_int_t flags = 0; !! 161 saveset = current->blocked; 119 long err = 0; !! 162 siginitset(¤t->blocked, set); 120 compat_uint_t compat_reg; !! 163 recalc_sigpending(current); 121 compat_uint_t compat_regb; !! 164 spin_unlock_irq(¤t->sigmask_lock); 122 int regn; << 123 165 124 if (on_sig_stack((unsigned long) sc)) !! 166 regs->tpc = regs->tnpc; 125 flags |= PARISC_SC_FLAG_ONSTAC !! 167 regs->tnpc += 4; >> 168 if ((current->thread.flags & SPARC_FLAG_32BIT) != 0) { >> 169 regs->tpc &= 0xffffffff; >> 170 regs->tnpc &= 0xffffffff; >> 171 } >> 172 >> 173 /* Condition codes and return value where set here for sigpause, >> 174 * and so got used by setup_frame, which again causes sigreturn() >> 175 * to return -EINTR. >> 176 */ >> 177 while (1) { >> 178 current->state = TASK_INTERRUPTIBLE; >> 179 schedule(); >> 180 /* >> 181 * Return -EINTR and set condition code here, >> 182 * so the interrupted system call actually returns >> 183 * these. >> 184 */ >> 185 regs->tstate |= TSTATE_ICARRY; >> 186 regs->u_regs[UREG_I0] = EINTR; >> 187 if (do_signal32(&saveset, regs, 0, 0)) >> 188 return; >> 189 } >> 190 } >> 191 >> 192 asmlinkage void do_rt_sigsuspend32(u32 uset, size_t sigsetsize, struct pt_regs *regs) >> 193 { >> 194 sigset_t oldset, set; >> 195 sigset_t32 set32; >> 196 >> 197 /* XXX: Don't preclude handling different sized sigset_t's. */ >> 198 if (((__kernel_size_t32)sigsetsize) != sizeof(sigset_t)) { >> 199 regs->tstate |= TSTATE_ICARRY; >> 200 regs->u_regs[UREG_I0] = EINVAL; >> 201 return; >> 202 } >> 203 if (copy_from_user(&set32, (void *)(long)uset, sizeof(set32))) { >> 204 regs->tstate |= TSTATE_ICARRY; >> 205 regs->u_regs[UREG_I0] = EFAULT; >> 206 return; >> 207 } >> 208 switch (_NSIG_WORDS) { >> 209 case 4: set.sig[3] = set32.sig[6] + (((long)set32.sig[7]) << 32); >> 210 case 3: set.sig[2] = set32.sig[4] + (((long)set32.sig[5]) << 32); >> 211 case 2: set.sig[1] = set32.sig[2] + (((long)set32.sig[3]) << 32); >> 212 case 1: set.sig[0] = set32.sig[0] + (((long)set32.sig[1]) << 32); >> 213 } >> 214 sigdelsetmask(&set, ~_BLOCKABLE); >> 215 spin_lock_irq(¤t->sigmask_lock); >> 216 oldset = current->blocked; >> 217 current->blocked = set; >> 218 recalc_sigpending(current); >> 219 spin_unlock_irq(¤t->sigmask_lock); 126 220 127 if (in_syscall) { !! 221 regs->tpc = regs->tnpc; 128 !! 222 regs->tnpc += 4; 129 DBG(1,"setup_sigcontext32: in_ !! 223 if ((current->thread.flags & SPARC_FLAG_32BIT) != 0) { 130 !! 224 regs->tpc &= 0xffffffff; 131 flags |= PARISC_SC_FLAG_IN_SYS !! 225 regs->tnpc &= 0xffffffff; 132 /* Truncate gr31 */ !! 226 } 133 compat_reg = (compat_uint_t)(r !! 227 134 /* regs->iaoq is undefined in !! 228 /* Condition codes and return value where set here for sigpause, 135 err |= __put_user(compat_reg, !! 229 * and so got used by setup_frame, which again causes sigreturn() 136 DBG(2,"setup_sigcontext32: sc- !! 230 * to return -EINTR. 137 &sc->sc_iaoq[0 !! 231 */ 138 !! 232 while (1) { 139 /* Store upper half */ !! 233 current->state = TASK_INTERRUPTIBLE; 140 compat_reg = (compat_uint_t)(r !! 234 schedule(); 141 err |= __put_user(compat_reg, !! 235 /* 142 DBG(2,"setup_sigcontext32: upp !! 236 * Return -EINTR and set condition code here, 143 !! 237 * so the interrupted system call actually returns 144 !! 238 * these. 145 compat_reg = (compat_uint_t)(r !! 239 */ 146 err |= __put_user(compat_reg, !! 240 regs->tstate |= TSTATE_ICARRY; 147 DBG(2,"setup_sigcontext32: sc- !! 241 regs->u_regs[UREG_I0] = EINTR; 148 &sc->sc_iaoq[1 !! 242 if (do_signal32(&oldset, regs, 0, 0)) 149 /* Store upper half */ !! 243 return; 150 compat_reg = (compat_uint_t)(( !! 244 } 151 err |= __put_user(compat_reg, !! 245 } 152 DBG(2,"setup_sigcontext32: upp !! 246 153 !! 247 static inline int restore_fpu_state32(struct pt_regs *regs, __siginfo_fpu_t *fpu) 154 /* Truncate sr3 */ !! 248 { 155 compat_reg = (compat_uint_t)(r !! 249 unsigned long *fpregs = (unsigned long *)(((char *)current) + AOFF_task_fpregs); 156 err |= __put_user(compat_reg, !! 250 unsigned long fprs; 157 err |= __put_user(compat_reg, !! 251 int err; 158 !! 252 159 /* Store upper half */ !! 253 err = __get_user(fprs, &fpu->si_fprs); 160 compat_reg = (compat_uint_t)(r !! 254 fprs_write(0); 161 err |= __put_user(compat_reg, !! 255 regs->tstate &= ~TSTATE_PEF; 162 err |= __put_user(compat_reg, !! 256 if (fprs & FPRS_DL) 163 !! 257 err |= copy_from_user(fpregs, &fpu->si_float_regs[0], (sizeof(unsigned int) * 32)); 164 DBG(2,"setup_sigcontext32: upp !! 258 if (fprs & FPRS_DU) 165 DBG(2,"setup_sigcontext32: upp !! 259 err |= copy_from_user(fpregs+16, &fpu->si_float_regs[32], (sizeof(unsigned int) * 32)); 166 DBG(1,"setup_sigcontext32: iao !! 260 err |= __get_user(current->thread.xfsr[0], &fpu->si_fsr); 167 regs->gr[31], regs->gr !! 261 err |= __get_user(current->thread.gsr[0], &fpu->si_gsr); >> 262 current->thread.fpsaved[0] |= fprs; >> 263 return err; >> 264 } >> 265 >> 266 void do_new_sigreturn32(struct pt_regs *regs) >> 267 { >> 268 struct new_signal_frame32 *sf; >> 269 unsigned int psr; >> 270 unsigned pc, npc, fpu_save; >> 271 sigset_t set; >> 272 unsigned seta[_NSIG_WORDS32]; >> 273 int err, i; >> 274 >> 275 regs->u_regs[UREG_FP] &= 0x00000000ffffffffUL; >> 276 sf = (struct new_signal_frame32 *) regs->u_regs [UREG_FP]; >> 277 >> 278 /* 1. Make sure we are not getting garbage from the user */ >> 279 if (verify_area (VERIFY_READ, sf, sizeof (*sf)) || >> 280 (((unsigned long) sf) & 3)) >> 281 goto segv; >> 282 >> 283 get_user(pc, &sf->info.si_regs.pc); >> 284 __get_user(npc, &sf->info.si_regs.npc); >> 285 >> 286 if ((pc | npc) & 3) >> 287 goto segv; >> 288 >> 289 if ((current->thread.flags & SPARC_FLAG_32BIT) != 0) { >> 290 pc &= 0xffffffff; >> 291 npc &= 0xffffffff; >> 292 } >> 293 regs->tpc = pc; >> 294 regs->tnpc = npc; >> 295 >> 296 /* 2. Restore the state */ >> 297 err = __get_user(regs->y, &sf->info.si_regs.y); >> 298 err |= __get_user(psr, &sf->info.si_regs.psr); >> 299 >> 300 for (i = UREG_G1; i <= UREG_I7; i++) >> 301 err |= __get_user(regs->u_regs[i], &sf->info.si_regs.u_regs[i]); >> 302 if ((psr & (PSR_VERS|PSR_IMPL)) == PSR_V8PLUS) { >> 303 err |= __get_user(i, &sf->v8plus.g_upper[0]); >> 304 if (i == SIGINFO_EXTRA_V8PLUS_MAGIC) { >> 305 unsigned long asi; >> 306 >> 307 for (i = UREG_G1; i <= UREG_I7; i++) >> 308 err |= __get_user(((u32 *)regs->u_regs)[2*i], &sf->v8plus.g_upper[i]); >> 309 err |= __get_user(asi, &sf->v8plus.asi); >> 310 regs->tstate &= ~TSTATE_ASI; >> 311 regs->tstate |= ((asi & 0xffUL) << 24UL); >> 312 } >> 313 } >> 314 >> 315 /* User can only change condition codes in %tstate. */ >> 316 regs->tstate &= ~(TSTATE_ICC|TSTATE_XCC); >> 317 regs->tstate |= psr_to_tstate_icc(psr); >> 318 >> 319 err |= __get_user(fpu_save, &sf->fpu_save); >> 320 if (fpu_save) >> 321 err |= restore_fpu_state32(regs, &sf->fpu_state); >> 322 err |= __get_user(seta[0], &sf->info.si_mask); >> 323 err |= copy_from_user(seta+1, &sf->extramask, (_NSIG_WORDS32 - 1) * sizeof(unsigned)); >> 324 if (err) >> 325 goto segv; >> 326 switch (_NSIG_WORDS) { >> 327 case 4: set.sig[3] = seta[6] + (((long)seta[7]) << 32); >> 328 case 3: set.sig[2] = seta[4] + (((long)seta[5]) << 32); >> 329 case 2: set.sig[1] = seta[2] + (((long)seta[3]) << 32); >> 330 case 1: set.sig[0] = seta[0] + (((long)seta[1]) << 32); >> 331 } >> 332 sigdelsetmask(&set, ~_BLOCKABLE); >> 333 spin_lock_irq(¤t->sigmask_lock); >> 334 current->blocked = set; >> 335 recalc_sigpending(current); >> 336 spin_unlock_irq(¤t->sigmask_lock); >> 337 return; >> 338 >> 339 segv: >> 340 do_exit(SIGSEGV); >> 341 } >> 342 >> 343 asmlinkage void do_sigreturn32(struct pt_regs *regs) >> 344 { >> 345 struct sigcontext32 *scptr; >> 346 unsigned pc, npc, psr; >> 347 sigset_t set; >> 348 unsigned seta[_NSIG_WORDS32]; >> 349 int err; >> 350 >> 351 synchronize_user_stack(); >> 352 if (current->thread.flags & SPARC_FLAG_NEWSIGNALS) >> 353 return do_new_sigreturn32(regs); >> 354 >> 355 scptr = (struct sigcontext32 *) >> 356 (regs->u_regs[UREG_I0] & 0x00000000ffffffffUL); >> 357 /* Check sanity of the user arg. */ >> 358 if(verify_area(VERIFY_READ, scptr, sizeof(struct sigcontext32)) || >> 359 (((unsigned long) scptr) & 3)) >> 360 goto segv; >> 361 >> 362 err = __get_user(pc, &scptr->sigc_pc); >> 363 err |= __get_user(npc, &scptr->sigc_npc); >> 364 >> 365 if((pc | npc) & 3) >> 366 goto segv; /* Nice try. */ >> 367 >> 368 err |= __get_user(seta[0], &scptr->sigc_mask); >> 369 /* Note that scptr + 1 points to extramask */ >> 370 err |= copy_from_user(seta+1, scptr + 1, (_NSIG_WORDS32 - 1) * sizeof(unsigned)); >> 371 if (err) >> 372 goto segv; >> 373 switch (_NSIG_WORDS) { >> 374 case 4: set.sig[3] = seta[6] + (((long)seta[7]) << 32); >> 375 case 3: set.sig[2] = seta[4] + (((long)seta[5]) << 32); >> 376 case 2: set.sig[1] = seta[2] + (((long)seta[3]) << 32); >> 377 case 1: set.sig[0] = seta[0] + (((long)seta[1]) << 32); >> 378 } >> 379 sigdelsetmask(&set, ~_BLOCKABLE); >> 380 spin_lock_irq(¤t->sigmask_lock); >> 381 current->blocked = set; >> 382 recalc_sigpending(current); >> 383 spin_unlock_irq(¤t->sigmask_lock); >> 384 >> 385 if ((current->thread.flags & SPARC_FLAG_32BIT) != 0) { >> 386 pc &= 0xffffffff; >> 387 npc &= 0xffffffff; >> 388 } >> 389 regs->tpc = pc; >> 390 regs->tnpc = npc; >> 391 err = __get_user(regs->u_regs[UREG_FP], &scptr->sigc_sp); >> 392 err |= __get_user(regs->u_regs[UREG_I0], &scptr->sigc_o0); >> 393 err |= __get_user(regs->u_regs[UREG_G1], &scptr->sigc_g1); >> 394 >> 395 /* User can only change condition codes in %tstate. */ >> 396 err |= __get_user(psr, &scptr->sigc_psr); >> 397 if (err) >> 398 goto segv; >> 399 regs->tstate &= ~(TSTATE_ICC|TSTATE_XCC); >> 400 regs->tstate |= psr_to_tstate_icc(psr); >> 401 return; >> 402 >> 403 segv: >> 404 do_exit(SIGSEGV); >> 405 } >> 406 >> 407 asmlinkage void do_rt_sigreturn32(struct pt_regs *regs) >> 408 { >> 409 struct rt_signal_frame32 *sf; >> 410 unsigned int psr; >> 411 unsigned pc, npc, fpu_save, u_ss_sp; >> 412 mm_segment_t old_fs; >> 413 sigset_t set; >> 414 sigset_t32 seta; >> 415 stack_t st; >> 416 int err, i; >> 417 >> 418 synchronize_user_stack(); >> 419 regs->u_regs[UREG_FP] &= 0x00000000ffffffffUL; >> 420 sf = (struct rt_signal_frame32 *) regs->u_regs [UREG_FP]; >> 421 >> 422 /* 1. Make sure we are not getting garbage from the user */ >> 423 if (verify_area (VERIFY_READ, sf, sizeof (*sf)) || >> 424 (((unsigned long) sf) & 3)) >> 425 goto segv; >> 426 >> 427 get_user(pc, &sf->regs.pc); >> 428 __get_user(npc, &sf->regs.npc); >> 429 >> 430 if ((pc | npc) & 3) >> 431 goto segv; >> 432 >> 433 if ((current->thread.flags & SPARC_FLAG_32BIT) != 0) { >> 434 pc &= 0xffffffff; >> 435 npc &= 0xffffffff; >> 436 } >> 437 regs->tpc = pc; >> 438 regs->tnpc = npc; >> 439 >> 440 /* 2. Restore the state */ >> 441 err = __get_user(regs->y, &sf->regs.y); >> 442 err |= __get_user(psr, &sf->regs.psr); >> 443 >> 444 for (i = UREG_G1; i <= UREG_I7; i++) >> 445 err |= __get_user(regs->u_regs[i], &sf->regs.u_regs[i]); >> 446 if ((psr & (PSR_VERS|PSR_IMPL)) == PSR_V8PLUS) { >> 447 err |= __get_user(i, &sf->v8plus.g_upper[0]); >> 448 if (i == SIGINFO_EXTRA_V8PLUS_MAGIC) { >> 449 unsigned long asi; >> 450 >> 451 for (i = UREG_G1; i <= UREG_I7; i++) >> 452 err |= __get_user(((u32 *)regs->u_regs)[2*i], &sf->v8plus.g_upper[i]); >> 453 err |= __get_user(asi, &sf->v8plus.asi); >> 454 regs->tstate &= ~TSTATE_ASI; >> 455 regs->tstate |= ((asi & 0xffUL) << 24UL); >> 456 } >> 457 } >> 458 >> 459 /* User can only change condition codes in %tstate. */ >> 460 regs->tstate &= ~(TSTATE_ICC|TSTATE_XCC); >> 461 regs->tstate |= psr_to_tstate_icc(psr); >> 462 >> 463 err |= __get_user(fpu_save, &sf->fpu_save); >> 464 if (fpu_save) >> 465 err |= restore_fpu_state32(regs, &sf->fpu_state); >> 466 err |= copy_from_user(&seta, &sf->mask, sizeof(sigset_t32)); >> 467 err |= __get_user(u_ss_sp, &sf->stack.ss_sp); >> 468 st.ss_sp = (void *) (long) u_ss_sp; >> 469 err |= __get_user(st.ss_flags, &sf->stack.ss_flags); >> 470 err |= __get_user(st.ss_size, &sf->stack.ss_size); >> 471 if (err) >> 472 goto segv; 168 473 >> 474 /* It is more difficult to avoid calling this function than to >> 475 call it and ignore errors. */ >> 476 old_fs = get_fs(); >> 477 set_fs(KERNEL_DS); >> 478 do_sigaltstack(&st, NULL, (unsigned long)sf); >> 479 set_fs(old_fs); >> 480 >> 481 switch (_NSIG_WORDS) { >> 482 case 4: set.sig[3] = seta.sig[6] + (((long)seta.sig[7]) << 32); >> 483 case 3: set.sig[2] = seta.sig[4] + (((long)seta.sig[5]) << 32); >> 484 case 2: set.sig[1] = seta.sig[2] + (((long)seta.sig[3]) << 32); >> 485 case 1: set.sig[0] = seta.sig[0] + (((long)seta.sig[1]) << 32); >> 486 } >> 487 sigdelsetmask(&set, ~_BLOCKABLE); >> 488 spin_lock_irq(¤t->sigmask_lock); >> 489 current->blocked = set; >> 490 recalc_sigpending(current); >> 491 spin_unlock_irq(¤t->sigmask_lock); >> 492 return; >> 493 segv: >> 494 do_exit(SIGSEGV); >> 495 } >> 496 >> 497 /* Checks if the fp is valid */ >> 498 static int invalid_frame_pointer(void *fp, int fplen) >> 499 { >> 500 if ((((unsigned long) fp) & 7) || ((unsigned long)fp) > 0x100000000ULL - fplen) >> 501 return 1; >> 502 return 0; >> 503 } >> 504 >> 505 static inline void *get_sigframe(struct sigaction *sa, struct pt_regs *regs, unsigned long framesize) >> 506 { >> 507 unsigned long sp; >> 508 >> 509 regs->u_regs[UREG_FP] &= 0x00000000ffffffffUL; >> 510 sp = regs->u_regs[UREG_FP]; >> 511 >> 512 /* This is the X/Open sanctioned signal stack switching. */ >> 513 if (sa->sa_flags & SA_ONSTACK) { >> 514 if (!on_sig_stack(sp) && !((current->sas_ss_sp + current->sas_ss_size) & 7)) >> 515 sp = current->sas_ss_sp + current->sas_ss_size; >> 516 } >> 517 return (void *)(sp - framesize); >> 518 } >> 519 >> 520 static void >> 521 setup_frame32(struct sigaction *sa, struct pt_regs *regs, int signr, sigset_t *oldset, siginfo_t *info) >> 522 { >> 523 struct signal_sframe32 *sframep; >> 524 struct sigcontext32 *sc; >> 525 unsigned seta[_NSIG_WORDS32]; >> 526 int err = 0; >> 527 void *sig_address; >> 528 int sig_code; >> 529 unsigned long pc = regs->tpc; >> 530 unsigned long npc = regs->tnpc; >> 531 >> 532 #if 0 >> 533 int window = 0; >> 534 #endif >> 535 unsigned psr; >> 536 >> 537 if ((current->thread.flags & SPARC_FLAG_32BIT) != 0) { >> 538 pc &= 0xffffffff; >> 539 npc &= 0xffffffff; >> 540 } >> 541 >> 542 synchronize_user_stack(); >> 543 save_and_clear_fpu(); >> 544 >> 545 sframep = (struct signal_sframe32 *)get_sigframe(sa, regs, SF_ALIGNEDSZ); >> 546 if (invalid_frame_pointer (sframep, sizeof(*sframep))){ >> 547 #ifdef DEBUG_SIGNALS /* fills up the console logs during crashme runs, yuck... */ >> 548 printk("%s [%d]: User has trashed signal stack\n", >> 549 current->comm, current->pid); >> 550 printk("Sigstack ptr %p handler at pc<%016lx> for sig<%d>\n", >> 551 sframep, pc, signr); >> 552 #endif >> 553 /* Don't change signal code and address, so that >> 554 * post mortem debuggers can have a look. >> 555 */ >> 556 do_exit(SIGILL); >> 557 } >> 558 >> 559 sc = &sframep->sig_context; >> 560 >> 561 /* We've already made sure frame pointer isn't in kernel space... */ >> 562 err = __put_user((sas_ss_flags(regs->u_regs[UREG_FP]) == SS_ONSTACK), >> 563 &sc->sigc_onstack); >> 564 >> 565 switch (_NSIG_WORDS) { >> 566 case 4: seta[7] = (oldset->sig[3] >> 32); >> 567 seta[6] = oldset->sig[3]; >> 568 case 3: seta[5] = (oldset->sig[2] >> 32); >> 569 seta[4] = oldset->sig[2]; >> 570 case 2: seta[3] = (oldset->sig[1] >> 32); >> 571 seta[2] = oldset->sig[1]; >> 572 case 1: seta[1] = (oldset->sig[0] >> 32); >> 573 seta[0] = oldset->sig[0]; >> 574 } >> 575 err |= __put_user(seta[0], &sc->sigc_mask); >> 576 err |= __copy_to_user(sframep->extramask, seta + 1, >> 577 (_NSIG_WORDS32 - 1) * sizeof(unsigned)); >> 578 err |= __put_user(regs->u_regs[UREG_FP], &sc->sigc_sp); >> 579 err |= __put_user(pc, &sc->sigc_pc); >> 580 err |= __put_user(npc, &sc->sigc_npc); >> 581 psr = tstate_to_psr (regs->tstate); >> 582 if(current->thread.fpsaved[0] & FPRS_FEF) >> 583 psr |= PSR_EF; >> 584 err |= __put_user(psr, &sc->sigc_psr); >> 585 err |= __put_user(regs->u_regs[UREG_G1], &sc->sigc_g1); >> 586 err |= __put_user(regs->u_regs[UREG_I0], &sc->sigc_o0); >> 587 err |= __put_user(current->thread.w_saved, &sc->sigc_oswins); >> 588 #if 0 >> 589 /* w_saved is not currently used... */ >> 590 if(current->thread.w_saved) >> 591 for(window = 0; window < current->thread.w_saved; window++) { >> 592 sc->sigc_spbuf[window] = >> 593 (char *)current->thread.rwbuf_stkptrs[window]; >> 594 err |= copy_to_user(&sc->sigc_wbuf[window], >> 595 ¤t->thread.reg_window[window], >> 596 sizeof(struct reg_window)); >> 597 } >> 598 else >> 599 #endif >> 600 err |= copy_in_user((u32 *)sframep, >> 601 (u32 *)(regs->u_regs[UREG_FP]), >> 602 sizeof(struct reg_window32)); >> 603 >> 604 current->thread.w_saved = 0; /* So process is allowed to execute. */ >> 605 err |= __put_user(signr, &sframep->sig_num); >> 606 sig_address = NULL; >> 607 sig_code = 0; >> 608 if (SI_FROMKERNEL (info) && (info->si_code & __SI_MASK) == __SI_FAULT) { >> 609 sig_address = info->si_addr; >> 610 switch (signr) { >> 611 case SIGSEGV: >> 612 switch (info->si_code) { >> 613 case SEGV_MAPERR: sig_code = SUBSIG_NOMAPPING; break; >> 614 default: sig_code = SUBSIG_PROTECTION; break; >> 615 } >> 616 break; >> 617 case SIGILL: >> 618 switch (info->si_code) { >> 619 case ILL_ILLOPC: sig_code = SUBSIG_ILLINST; break; >> 620 case ILL_PRVOPC: sig_code = SUBSIG_PRIVINST; break; >> 621 case ILL_ILLTRP: sig_code = SUBSIG_BADTRAP (info->si_trapno); break; >> 622 default: sig_code = SUBSIG_STACK; break; >> 623 } >> 624 break; >> 625 case SIGFPE: >> 626 switch (info->si_code) { >> 627 case FPE_INTDIV: sig_code = SUBSIG_IDIVZERO; break; >> 628 case FPE_INTOVF: sig_code = SUBSIG_FPINTOVFL; break; >> 629 case FPE_FLTDIV: sig_code = SUBSIG_FPDIVZERO; break; >> 630 case FPE_FLTOVF: sig_code = SUBSIG_FPOVFLOW; break; >> 631 case FPE_FLTUND: sig_code = SUBSIG_FPUNFLOW; break; >> 632 case FPE_FLTRES: sig_code = SUBSIG_FPINEXACT; break; >> 633 case FPE_FLTINV: sig_code = SUBSIG_FPOPERROR; break; >> 634 default: sig_code = SUBSIG_FPERROR; break; >> 635 } >> 636 break; >> 637 case SIGBUS: >> 638 switch (info->si_code) { >> 639 case BUS_ADRALN: sig_code = SUBSIG_ALIGNMENT; break; >> 640 case BUS_ADRERR: sig_code = SUBSIG_MISCERROR; break; >> 641 default: sig_code = SUBSIG_BUSTIMEOUT; break; >> 642 } >> 643 break; >> 644 case SIGEMT: >> 645 switch (info->si_code) { >> 646 case EMT_TAGOVF: sig_code = SUBSIG_TAG; break; >> 647 } >> 648 break; >> 649 case SIGSYS: >> 650 if (info->si_code == (__SI_FAULT|0x100)) { >> 651 /* See sys_sunos32.c */ >> 652 sig_code = info->si_trapno; >> 653 break; >> 654 } >> 655 default: >> 656 sig_address = NULL; >> 657 } >> 658 } >> 659 err |= __put_user((long)sig_address, &sframep->sig_address); >> 660 err |= __put_user(sig_code, &sframep->sig_code); >> 661 err |= __put_user((u64)sc, &sframep->sig_scptr); >> 662 if (err) >> 663 goto sigsegv; >> 664 >> 665 regs->u_regs[UREG_FP] = (unsigned long) sframep; >> 666 regs->tpc = (unsigned long) sa->sa_handler; >> 667 regs->tnpc = (regs->tpc + 4); >> 668 if ((current->thread.flags & SPARC_FLAG_32BIT) != 0) { >> 669 regs->tpc &= 0xffffffff; >> 670 regs->tnpc &= 0xffffffff; >> 671 } >> 672 return; >> 673 >> 674 sigsegv: >> 675 do_exit(SIGSEGV); >> 676 } >> 677 >> 678 >> 679 static inline int save_fpu_state32(struct pt_regs *regs, __siginfo_fpu_t *fpu) >> 680 { >> 681 unsigned long *fpregs = (unsigned long *)(((char *)current) + AOFF_task_fpregs); >> 682 unsigned long fprs; >> 683 int err = 0; >> 684 >> 685 fprs = current->thread.fpsaved[0]; >> 686 if (fprs & FPRS_DL) >> 687 err |= copy_to_user(&fpu->si_float_regs[0], fpregs, >> 688 (sizeof(unsigned int) * 32)); >> 689 if (fprs & FPRS_DU) >> 690 err |= copy_to_user(&fpu->si_float_regs[32], fpregs+16, >> 691 (sizeof(unsigned int) * 32)); >> 692 err |= __put_user(current->thread.xfsr[0], &fpu->si_fsr); >> 693 err |= __put_user(current->thread.gsr[0], &fpu->si_gsr); >> 694 err |= __put_user(fprs, &fpu->si_fprs); >> 695 >> 696 return err; >> 697 } >> 698 >> 699 static inline void new_setup_frame32(struct k_sigaction *ka, struct pt_regs *regs, >> 700 int signo, sigset_t *oldset) >> 701 { >> 702 struct new_signal_frame32 *sf; >> 703 int sigframe_size; >> 704 u32 psr; >> 705 int i, err; >> 706 unsigned seta[_NSIG_WORDS32]; >> 707 >> 708 /* 1. Make sure everything is clean */ >> 709 synchronize_user_stack(); >> 710 save_and_clear_fpu(); >> 711 >> 712 sigframe_size = NF_ALIGNEDSZ; >> 713 if (!(current->thread.fpsaved[0] & FPRS_FEF)) >> 714 sigframe_size -= sizeof(__siginfo_fpu_t); >> 715 >> 716 sf = (struct new_signal_frame32 *)get_sigframe(&ka->sa, regs, sigframe_size); >> 717 >> 718 if (invalid_frame_pointer (sf, sigframe_size)) { >> 719 #ifdef DEBUG_SIGNALS >> 720 printk("new_setup_frame32(%s:%d): invalid_frame_pointer(%p, %d)\n", >> 721 current->comm, current->pid, sf, sigframe_size); >> 722 #endif >> 723 goto sigill; >> 724 } >> 725 >> 726 if (current->thread.w_saved != 0) { >> 727 #ifdef DEBUG_SIGNALS >> 728 printk ("%s[%d]: Invalid user stack frame for " >> 729 "signal delivery.\n", current->comm, current->pid); >> 730 #endif >> 731 goto sigill; >> 732 } >> 733 >> 734 /* 2. Save the current process state */ >> 735 if ((current->thread.flags & SPARC_FLAG_32BIT) != 0) { >> 736 regs->tpc &= 0xffffffff; >> 737 regs->tnpc &= 0xffffffff; >> 738 } >> 739 err = put_user(regs->tpc, &sf->info.si_regs.pc); >> 740 err |= __put_user(regs->tnpc, &sf->info.si_regs.npc); >> 741 err |= __put_user(regs->y, &sf->info.si_regs.y); >> 742 psr = tstate_to_psr (regs->tstate); >> 743 if(current->thread.fpsaved[0] & FPRS_FEF) >> 744 psr |= PSR_EF; >> 745 err |= __put_user(psr, &sf->info.si_regs.psr); >> 746 for (i = 0; i < 16; i++) >> 747 err |= __put_user(regs->u_regs[i], &sf->info.si_regs.u_regs[i]); >> 748 err |= __put_user(sizeof(siginfo_extra_v8plus_t), &sf->extra_size); >> 749 err |= __put_user(SIGINFO_EXTRA_V8PLUS_MAGIC, &sf->v8plus.g_upper[0]); >> 750 for (i = 1; i < 16; i++) >> 751 err |= __put_user(((u32 *)regs->u_regs)[2*i], >> 752 &sf->v8plus.g_upper[i]); >> 753 err |= __put_user((regs->tstate & TSTATE_ASI) >> 24UL, >> 754 &sf->v8plus.asi); >> 755 >> 756 if (psr & PSR_EF) { >> 757 err |= save_fpu_state32(regs, &sf->fpu_state); >> 758 err |= __put_user((u64)&sf->fpu_state, &sf->fpu_save); 169 } else { 759 } else { >> 760 err |= __put_user(0, &sf->fpu_save); >> 761 } >> 762 >> 763 switch (_NSIG_WORDS) { >> 764 case 4: seta[7] = (oldset->sig[3] >> 32); >> 765 seta[6] = oldset->sig[3]; >> 766 case 3: seta[5] = (oldset->sig[2] >> 32); >> 767 seta[4] = oldset->sig[2]; >> 768 case 2: seta[3] = (oldset->sig[1] >> 32); >> 769 seta[2] = oldset->sig[1]; >> 770 case 1: seta[1] = (oldset->sig[0] >> 32); >> 771 seta[0] = oldset->sig[0]; >> 772 } >> 773 err |= __put_user(seta[0], &sf->info.si_mask); >> 774 err |= __copy_to_user(sf->extramask, seta + 1, >> 775 (_NSIG_WORDS32 - 1) * sizeof(unsigned)); >> 776 >> 777 err |= copy_in_user((u32 *)sf, >> 778 (u32 *)(regs->u_regs[UREG_FP]), >> 779 sizeof(struct reg_window32)); >> 780 >> 781 if (err) >> 782 goto sigsegv; >> 783 >> 784 /* 3. signal handler back-trampoline and parameters */ >> 785 regs->u_regs[UREG_FP] = (unsigned long) sf; >> 786 regs->u_regs[UREG_I0] = signo; >> 787 regs->u_regs[UREG_I1] = (unsigned long) &sf->info; >> 788 regs->u_regs[UREG_I2] = (unsigned long) &sf->info; >> 789 >> 790 /* 4. signal handler */ >> 791 regs->tpc = (unsigned long) ka->sa.sa_handler; >> 792 regs->tnpc = (regs->tpc + 4); >> 793 if ((current->thread.flags & SPARC_FLAG_32BIT) != 0) { >> 794 regs->tpc &= 0xffffffff; >> 795 regs->tnpc &= 0xffffffff; >> 796 } >> 797 >> 798 /* 5. return to kernel instructions */ >> 799 if (ka->ka_restorer) { >> 800 regs->u_regs[UREG_I7] = (unsigned long)ka->ka_restorer; >> 801 } else { >> 802 /* Flush instruction space. */ >> 803 unsigned long address = ((unsigned long)&(sf->insns[0])); >> 804 pgd_t *pgdp = pgd_offset(current->mm, address); >> 805 pmd_t *pmdp = pmd_offset(pgdp, address); >> 806 pte_t *ptep = pte_offset(pmdp, address); >> 807 >> 808 regs->u_regs[UREG_I7] = (unsigned long) (&(sf->insns[0]) - 2); >> 809 >> 810 err = __put_user(0x821020d8, &sf->insns[0]); /*mov __NR_sigreturn, %g1*/ >> 811 err |= __put_user(0x91d02010, &sf->insns[1]); /*t 0x10*/ >> 812 if(err) >> 813 goto sigsegv; >> 814 >> 815 if(pte_present(*ptep)) { >> 816 unsigned long page = (unsigned long) page_address(pte_page(*ptep)); >> 817 >> 818 __asm__ __volatile__( >> 819 " membar #StoreStore\n" >> 820 " flush %0 + %1" >> 821 : : "r" (page), "r" (address & (PAGE_SIZE - 1)) >> 822 : "memory"); >> 823 } >> 824 } >> 825 return; >> 826 >> 827 sigill: >> 828 do_exit(SIGILL); >> 829 sigsegv: >> 830 do_exit(SIGSEGV); >> 831 } >> 832 >> 833 /* Setup a Solaris stack frame */ >> 834 static inline void >> 835 setup_svr4_frame32(struct sigaction *sa, unsigned long pc, unsigned long npc, >> 836 struct pt_regs *regs, int signr, sigset_t *oldset) >> 837 { >> 838 svr4_signal_frame_t *sfp; >> 839 svr4_gregset_t *gr; >> 840 svr4_siginfo_t *si; >> 841 svr4_mcontext_t *mc; >> 842 svr4_gwindows_t *gw; >> 843 svr4_ucontext_t *uc; >> 844 svr4_sigset_t setv; >> 845 #if 0 >> 846 int window = 0; >> 847 #endif >> 848 unsigned psr; >> 849 int i, err; >> 850 >> 851 synchronize_user_stack(); >> 852 save_and_clear_fpu(); >> 853 >> 854 regs->u_regs[UREG_FP] &= 0x00000000ffffffffUL; >> 855 sfp = (svr4_signal_frame_t *) get_sigframe(sa, regs, sizeof(struct reg_window32) + SVR4_SF_ALIGNED); >> 856 >> 857 if (invalid_frame_pointer (sfp, sizeof (*sfp))){ >> 858 #ifdef DEBUG_SIGNALS >> 859 printk ("Invalid stack frame\n"); >> 860 #endif >> 861 do_exit(SIGILL); >> 862 } >> 863 >> 864 /* Start with a clean frame pointer and fill it */ >> 865 err = clear_user(sfp, sizeof (*sfp)); >> 866 >> 867 /* Setup convenience variables */ >> 868 si = &sfp->si; >> 869 uc = &sfp->uc; >> 870 gw = &sfp->gw; >> 871 mc = &uc->mcontext; >> 872 gr = &mc->greg; >> 873 >> 874 /* FIXME: where am I supposed to put this? >> 875 * sc->sigc_onstack = old_status; >> 876 * anyways, it does not look like it is used for anything at all. >> 877 */ >> 878 setv.sigbits[0] = oldset->sig[0]; >> 879 setv.sigbits[1] = (oldset->sig[0] >> 32); >> 880 if (_NSIG_WORDS >= 2) { >> 881 setv.sigbits[2] = oldset->sig[1]; >> 882 setv.sigbits[3] = (oldset->sig[1] >> 32); >> 883 err |= __copy_to_user(&uc->sigmask, &setv, sizeof(svr4_sigset_t)); >> 884 } else >> 885 err |= __copy_to_user(&uc->sigmask, &setv, 2 * sizeof(unsigned)); >> 886 >> 887 /* Store registers */ >> 888 if ((current->thread.flags & SPARC_FLAG_32BIT) != 0) { >> 889 regs->tpc &= 0xffffffff; >> 890 regs->tnpc &= 0xffffffff; >> 891 } >> 892 err |= __put_user(regs->tpc, &((*gr) [SVR4_PC])); >> 893 err |= __put_user(regs->tnpc, &((*gr) [SVR4_NPC])); >> 894 psr = tstate_to_psr (regs->tstate); >> 895 if(current->thread.fpsaved[0] & FPRS_FEF) >> 896 psr |= PSR_EF; >> 897 err |= __put_user(psr, &((*gr) [SVR4_PSR])); >> 898 err |= __put_user(regs->y, &((*gr) [SVR4_Y])); >> 899 >> 900 /* Copy g [1..7] and o [0..7] registers */ >> 901 for (i = 0; i < 7; i++) >> 902 err |= __put_user(regs->u_regs[UREG_G1+i], (&(*gr)[SVR4_G1])+i); >> 903 for (i = 0; i < 8; i++) >> 904 err |= __put_user(regs->u_regs[UREG_I0+i], (&(*gr)[SVR4_O0])+i); >> 905 >> 906 /* Setup sigaltstack */ >> 907 err |= __put_user(current->sas_ss_sp, &uc->stack.sp); >> 908 err |= __put_user(sas_ss_flags(regs->u_regs[UREG_FP]), &uc->stack.flags); >> 909 err |= __put_user(current->sas_ss_size, &uc->stack.size); >> 910 >> 911 /* Save the currently window file: */ >> 912 >> 913 /* 1. Link sfp->uc->gwins to our windows */ >> 914 err |= __put_user((u32)(long)gw, &mc->gwin); >> 915 >> 916 /* 2. Number of windows to restore at setcontext (): */ >> 917 err |= __put_user(current->thread.w_saved, &gw->count); >> 918 >> 919 /* 3. Save each valid window >> 920 * Currently, it makes a copy of the windows from the kernel copy. >> 921 * David's code for SunOS, makes the copy but keeps the pointer to >> 922 * the kernel. My version makes the pointer point to a userland >> 923 * copy of those. Mhm, I wonder if I shouldn't just ignore those >> 924 * on setcontext and use those that are on the kernel, the signal >> 925 * handler should not be modyfing those, mhm. >> 926 * >> 927 * These windows are just used in case synchronize_user_stack failed >> 928 * to flush the user windows. >> 929 */ >> 930 #if 0 >> 931 for(window = 0; window < current->thread.w_saved; window++) { >> 932 err |= __put_user((int *) &(gw->win [window]), >> 933 (int **)gw->winptr +window ); >> 934 err |= copy_to_user(&gw->win [window], >> 935 ¤t->thread.reg_window [window], >> 936 sizeof (svr4_rwindow_t)); >> 937 err |= __put_user(0, (int *)gw->winptr + window); >> 938 } >> 939 #endif >> 940 >> 941 /* 4. We just pay attention to the gw->count field on setcontext */ >> 942 current->thread.w_saved = 0; /* So process is allowed to execute. */ >> 943 >> 944 /* Setup the signal information. Solaris expects a bunch of >> 945 * information to be passed to the signal handler, we don't provide >> 946 * that much currently, should use siginfo. >> 947 */ >> 948 err |= __put_user(signr, &si->siginfo.signo); >> 949 err |= __put_user(SVR4_SINOINFO, &si->siginfo.code); >> 950 if (err) >> 951 goto sigsegv; >> 952 >> 953 regs->u_regs[UREG_FP] = (unsigned long) sfp; >> 954 regs->tpc = (unsigned long) sa->sa_handler; >> 955 regs->tnpc = (regs->tpc + 4); >> 956 if ((current->thread.flags & SPARC_FLAG_32BIT) != 0) { >> 957 regs->tpc &= 0xffffffff; >> 958 regs->tnpc &= 0xffffffff; >> 959 } >> 960 >> 961 #ifdef DEBUG_SIGNALS >> 962 printk ("Solaris-frame: %x %x\n", (int) regs->tpc, (int) regs->tnpc); >> 963 #endif >> 964 /* Arguments passed to signal handler */ >> 965 if (regs->u_regs [14]){ >> 966 struct reg_window32 *rw = (struct reg_window32 *) >> 967 (regs->u_regs [14] & 0x00000000ffffffffUL); >> 968 >> 969 err |= __put_user(signr, &rw->ins [0]); >> 970 err |= __put_user((u64)si, &rw->ins [1]); >> 971 err |= __put_user((u64)uc, &rw->ins [2]); >> 972 err |= __put_user((u64)sfp, &rw->ins [6]); /* frame pointer */ >> 973 if (err) >> 974 goto sigsegv; >> 975 >> 976 regs->u_regs[UREG_I0] = signr; >> 977 regs->u_regs[UREG_I1] = (u32)(u64) si; >> 978 regs->u_regs[UREG_I2] = (u32)(u64) uc; >> 979 } >> 980 return; >> 981 >> 982 sigsegv: >> 983 do_exit(SIGSEGV); >> 984 } >> 985 >> 986 asmlinkage int >> 987 svr4_getcontext(svr4_ucontext_t *uc, struct pt_regs *regs) >> 988 { >> 989 svr4_gregset_t *gr; >> 990 svr4_mcontext_t *mc; >> 991 svr4_sigset_t setv; >> 992 int i, err; >> 993 >> 994 synchronize_user_stack(); >> 995 save_and_clear_fpu(); >> 996 >> 997 if (current->thread.w_saved){ >> 998 printk ("Uh oh, w_saved is not zero (%d)\n", (int) current->thread.w_saved); >> 999 do_exit (SIGSEGV); >> 1000 } >> 1001 err = clear_user(uc, sizeof (*uc)); >> 1002 >> 1003 /* Setup convenience variables */ >> 1004 mc = &uc->mcontext; >> 1005 gr = &mc->greg; >> 1006 >> 1007 setv.sigbits[0] = current->blocked.sig[0]; >> 1008 setv.sigbits[1] = (current->blocked.sig[0] >> 32); >> 1009 if (_NSIG_WORDS >= 2) { >> 1010 setv.sigbits[2] = current->blocked.sig[1]; >> 1011 setv.sigbits[3] = (current->blocked.sig[1] >> 32); >> 1012 err |= __copy_to_user(&uc->sigmask, &setv, sizeof(svr4_sigset_t)); >> 1013 } else >> 1014 err |= __copy_to_user(&uc->sigmask, &setv, 2 * sizeof(unsigned)); >> 1015 >> 1016 /* Store registers */ >> 1017 if ((current->thread.flags & SPARC_FLAG_32BIT) != 0) { >> 1018 regs->tpc &= 0xffffffff; >> 1019 regs->tnpc &= 0xffffffff; >> 1020 } >> 1021 err |= __put_user(regs->tpc, &uc->mcontext.greg [SVR4_PC]); >> 1022 err |= __put_user(regs->tnpc, &uc->mcontext.greg [SVR4_NPC]); >> 1023 #if 1 >> 1024 err |= __put_user(0, &uc->mcontext.greg [SVR4_PSR]); >> 1025 #else >> 1026 i = tstate_to_psr(regs->tstate) & ~PSR_EF; >> 1027 if (current->thread.fpsaved[0] & FPRS_FEF) >> 1028 i |= PSR_EF; >> 1029 err |= __put_user(i, &uc->mcontext.greg [SVR4_PSR]); >> 1030 #endif >> 1031 err |= __put_user(regs->y, &uc->mcontext.greg [SVR4_Y]); >> 1032 >> 1033 /* Copy g [1..7] and o [0..7] registers */ >> 1034 for (i = 0; i < 7; i++) >> 1035 err |= __put_user(regs->u_regs[UREG_G1+i], (&(*gr)[SVR4_G1])+i); >> 1036 for (i = 0; i < 8; i++) >> 1037 err |= __put_user(regs->u_regs[UREG_I0+i], (&(*gr)[SVR4_O0])+i); >> 1038 >> 1039 /* Setup sigaltstack */ >> 1040 err |= __put_user(current->sas_ss_sp, &uc->stack.sp); >> 1041 err |= __put_user(sas_ss_flags(regs->u_regs[UREG_FP]), &uc->stack.flags); >> 1042 err |= __put_user(current->sas_ss_size, &uc->stack.size); >> 1043 >> 1044 /* The register file is not saved >> 1045 * we have already stuffed all of it with sync_user_stack >> 1046 */ >> 1047 return (err ? -EFAULT : 0); >> 1048 } >> 1049 >> 1050 >> 1051 /* Set the context for a svr4 application, this is Solaris way to sigreturn */ >> 1052 asmlinkage int svr4_setcontext(svr4_ucontext_t *c, struct pt_regs *regs) >> 1053 { >> 1054 struct thread_struct *tp = ¤t->thread; >> 1055 svr4_gregset_t *gr; >> 1056 mm_segment_t old_fs; >> 1057 u32 pc, npc, psr, u_ss_sp; >> 1058 sigset_t set; >> 1059 svr4_sigset_t setv; >> 1060 int i, err; >> 1061 stack_t st; >> 1062 >> 1063 /* Fixme: restore windows, or is this already taken care of in >> 1064 * svr4_setup_frame when sync_user_windows is done? >> 1065 */ >> 1066 flush_user_windows(); >> 1067 >> 1068 if (tp->w_saved){ >> 1069 printk ("Uh oh, w_saved is: 0x%x\n", tp->w_saved); >> 1070 goto sigsegv; >> 1071 } >> 1072 if (((unsigned long) c) & 3){ >> 1073 printk ("Unaligned structure passed\n"); >> 1074 goto sigsegv; >> 1075 } >> 1076 >> 1077 if(!__access_ok((unsigned long)c, sizeof(*c))) { >> 1078 /* Miguel, add nice debugging msg _here_. ;-) */ >> 1079 goto sigsegv; >> 1080 } >> 1081 >> 1082 /* Check for valid PC and nPC */ >> 1083 gr = &c->mcontext.greg; >> 1084 err = __get_user(pc, &((*gr)[SVR4_PC])); >> 1085 err |= __get_user(npc, &((*gr)[SVR4_NPC])); >> 1086 if((pc | npc) & 3) { >> 1087 #ifdef DEBUG_SIGNALS >> 1088 printk ("setcontext, PC or nPC were bogus\n"); >> 1089 #endif >> 1090 goto sigsegv; >> 1091 } >> 1092 >> 1093 /* Retrieve information from passed ucontext */ >> 1094 /* note that nPC is ored a 1, this is used to inform entry.S */ >> 1095 /* that we don't want it to mess with our PC and nPC */ >> 1096 >> 1097 err |= copy_from_user (&setv, &c->sigmask, sizeof(svr4_sigset_t)); >> 1098 set.sig[0] = setv.sigbits[0] | (((long)setv.sigbits[1]) << 32); >> 1099 if (_NSIG_WORDS >= 2) >> 1100 set.sig[1] = setv.sigbits[2] | (((long)setv.sigbits[3]) << 32); >> 1101 >> 1102 err |= __get_user(u_ss_sp, &c->stack.sp); >> 1103 st.ss_sp = (void *) (long) u_ss_sp; >> 1104 err |= __get_user(st.ss_flags, &c->stack.flags); >> 1105 err |= __get_user(st.ss_size, &c->stack.size); >> 1106 if (err) >> 1107 goto sigsegv; 170 1108 171 compat_reg = (compat_uint_t)(r !! 1109 /* It is more difficult to avoid calling this function than to 172 err |= __put_user(compat_reg, !! 1110 call it and ignore errors. */ 173 DBG(2,"setup_sigcontext32: sc- !! 1111 old_fs = get_fs(); 174 &sc->sc_iaoq[0 !! 1112 set_fs(KERNEL_DS); 175 /* Store upper half */ !! 1113 do_sigaltstack(&st, NULL, regs->u_regs[UREG_I6]); 176 compat_reg = (compat_uint_t)(r !! 1114 set_fs(old_fs); 177 err |= __put_user(compat_reg, !! 1115 178 DBG(2,"setup_sigcontext32: upp !! 1116 sigdelsetmask(&set, ~_BLOCKABLE); 179 !! 1117 spin_lock_irq(¤t->sigmask_lock); 180 compat_reg = (compat_uint_t)(r !! 1118 current->blocked = set; 181 err |= __put_user(compat_reg, !! 1119 recalc_sigpending(current); 182 DBG(2,"setup_sigcontext32: sc- !! 1120 spin_unlock_irq(¤t->sigmask_lock); 183 &sc->sc_iaoq[1 !! 1121 regs->tpc = pc; 184 /* Store upper half */ !! 1122 regs->tnpc = npc | 1; 185 compat_reg = (compat_uint_t)(r !! 1123 if ((current->thread.flags & SPARC_FLAG_32BIT) != 0) { 186 err |= __put_user(compat_reg, !! 1124 regs->tpc &= 0xffffffff; 187 DBG(2,"setup_sigcontext32: upp !! 1125 regs->tnpc &= 0xffffffff; 188 !! 1126 } >> 1127 err |= __get_user(regs->y, &((*gr) [SVR4_Y])); >> 1128 err |= __get_user(psr, &((*gr) [SVR4_PSR])); >> 1129 regs->tstate &= ~(TSTATE_ICC|TSTATE_XCC); >> 1130 regs->tstate |= psr_to_tstate_icc(psr); >> 1131 #if 0 >> 1132 if(psr & PSR_EF) >> 1133 regs->tstate |= TSTATE_PEF; >> 1134 #endif >> 1135 /* Restore g[1..7] and o[0..7] registers */ >> 1136 for (i = 0; i < 7; i++) >> 1137 err |= __get_user(regs->u_regs[UREG_G1+i], (&(*gr)[SVR4_G1])+i); >> 1138 for (i = 0; i < 8; i++) >> 1139 err |= __get_user(regs->u_regs[UREG_I0+i], (&(*gr)[SVR4_O0])+i); >> 1140 if(err) >> 1141 goto sigsegv; >> 1142 >> 1143 return -EINTR; >> 1144 sigsegv: >> 1145 do_exit(SIGSEGV); >> 1146 } >> 1147 >> 1148 static inline void setup_rt_frame32(struct k_sigaction *ka, struct pt_regs *regs, >> 1149 unsigned long signr, sigset_t *oldset, >> 1150 siginfo_t *info) >> 1151 { >> 1152 struct rt_signal_frame32 *sf; >> 1153 int sigframe_size; >> 1154 u32 psr; >> 1155 int i, err; >> 1156 sigset_t32 seta; >> 1157 >> 1158 /* 1. Make sure everything is clean */ >> 1159 synchronize_user_stack(); >> 1160 save_and_clear_fpu(); >> 1161 >> 1162 sigframe_size = RT_ALIGNEDSZ; >> 1163 if (!(current->thread.fpsaved[0] & FPRS_FEF)) >> 1164 sigframe_size -= sizeof(__siginfo_fpu_t); >> 1165 >> 1166 sf = (struct rt_signal_frame32 *)get_sigframe(&ka->sa, regs, sigframe_size); >> 1167 >> 1168 if (invalid_frame_pointer (sf, sigframe_size)) { >> 1169 #ifdef DEBUG_SIGNALS >> 1170 printk("rt_setup_frame32(%s:%d): invalid_frame_pointer(%p, %d)\n", >> 1171 current->comm, current->pid, sf, sigframe_size); >> 1172 #endif >> 1173 goto sigill; >> 1174 } >> 1175 >> 1176 if (current->thread.w_saved != 0) { >> 1177 #ifdef DEBUG_SIGNALS >> 1178 printk ("%s[%d]: Invalid user stack frame for " >> 1179 "signal delivery.\n", current->comm, current->pid); >> 1180 #endif >> 1181 goto sigill; >> 1182 } >> 1183 >> 1184 /* 2. Save the current process state */ >> 1185 if ((current->thread.flags & SPARC_FLAG_32BIT) != 0) { >> 1186 regs->tpc &= 0xffffffff; >> 1187 regs->tnpc &= 0xffffffff; >> 1188 } >> 1189 err = put_user(regs->tpc, &sf->regs.pc); >> 1190 err |= __put_user(regs->tnpc, &sf->regs.npc); >> 1191 err |= __put_user(regs->y, &sf->regs.y); >> 1192 psr = tstate_to_psr (regs->tstate); >> 1193 if(current->thread.fpsaved[0] & FPRS_FEF) >> 1194 psr |= PSR_EF; >> 1195 err |= __put_user(psr, &sf->regs.psr); >> 1196 for (i = 0; i < 16; i++) >> 1197 err |= __put_user(regs->u_regs[i], &sf->regs.u_regs[i]); >> 1198 err |= __put_user(sizeof(siginfo_extra_v8plus_t), &sf->extra_size); >> 1199 err |= __put_user(SIGINFO_EXTRA_V8PLUS_MAGIC, &sf->v8plus.g_upper[0]); >> 1200 for (i = 1; i < 16; i++) >> 1201 err |= __put_user(((u32 *)regs->u_regs)[2*i], >> 1202 &sf->v8plus.g_upper[i]); >> 1203 err |= __put_user((regs->tstate & TSTATE_ASI) >> 24UL, >> 1204 &sf->v8plus.asi); >> 1205 >> 1206 if (psr & PSR_EF) { >> 1207 err |= save_fpu_state32(regs, &sf->fpu_state); >> 1208 err |= __put_user((u64)&sf->fpu_state, &sf->fpu_save); >> 1209 } else { >> 1210 err |= __put_user(0, &sf->fpu_save); >> 1211 } >> 1212 >> 1213 /* Update the siginfo structure. */ >> 1214 err |= copy_siginfo_to_user32(&sf->info, info); >> 1215 >> 1216 /* Setup sigaltstack */ >> 1217 err |= __put_user(current->sas_ss_sp, &sf->stack.ss_sp); >> 1218 err |= __put_user(sas_ss_flags(regs->u_regs[UREG_FP]), &sf->stack.ss_flags); >> 1219 err |= __put_user(current->sas_ss_size, &sf->stack.ss_size); >> 1220 >> 1221 switch (_NSIG_WORDS) { >> 1222 case 4: seta.sig[7] = (oldset->sig[3] >> 32); >> 1223 seta.sig[6] = oldset->sig[3]; >> 1224 case 3: seta.sig[5] = (oldset->sig[2] >> 32); >> 1225 seta.sig[4] = oldset->sig[2]; >> 1226 case 2: seta.sig[3] = (oldset->sig[1] >> 32); >> 1227 seta.sig[2] = oldset->sig[1]; >> 1228 case 1: seta.sig[1] = (oldset->sig[0] >> 32); >> 1229 seta.sig[0] = oldset->sig[0]; >> 1230 } >> 1231 err |= __copy_to_user(&sf->mask, &seta, sizeof(sigset_t32)); >> 1232 >> 1233 err |= copy_in_user((u32 *)sf, >> 1234 (u32 *)(regs->u_regs[UREG_FP]), >> 1235 sizeof(struct reg_window32)); >> 1236 if (err) >> 1237 goto sigsegv; >> 1238 >> 1239 /* 3. signal handler back-trampoline and parameters */ >> 1240 regs->u_regs[UREG_FP] = (unsigned long) sf; >> 1241 regs->u_regs[UREG_I0] = signr; >> 1242 regs->u_regs[UREG_I1] = (unsigned long) &sf->info; >> 1243 regs->u_regs[UREG_I2] = (unsigned long) &sf->regs; >> 1244 >> 1245 /* 4. signal handler */ >> 1246 regs->tpc = (unsigned long) ka->sa.sa_handler; >> 1247 regs->tnpc = (regs->tpc + 4); >> 1248 if ((current->thread.flags & SPARC_FLAG_32BIT) != 0) { >> 1249 regs->tpc &= 0xffffffff; >> 1250 regs->tnpc &= 0xffffffff; >> 1251 } >> 1252 >> 1253 /* 5. return to kernel instructions */ >> 1254 if (ka->ka_restorer) >> 1255 regs->u_regs[UREG_I7] = (unsigned long)ka->ka_restorer; >> 1256 else { >> 1257 /* Flush instruction space. */ >> 1258 unsigned long address = ((unsigned long)&(sf->insns[0])); >> 1259 pgd_t *pgdp = pgd_offset(current->mm, address); >> 1260 pmd_t *pmdp = pmd_offset(pgdp, address); >> 1261 pte_t *ptep = pte_offset(pmdp, address); >> 1262 >> 1263 regs->u_regs[UREG_I7] = (unsigned long) (&(sf->insns[0]) - 2); >> 1264 >> 1265 /* mov __NR_rt_sigreturn, %g1 */ >> 1266 err |= __put_user(0x82102065, &sf->insns[0]); >> 1267 >> 1268 /* t 0x10 */ >> 1269 err |= __put_user(0x91d02010, &sf->insns[1]); >> 1270 if (err) >> 1271 goto sigsegv; >> 1272 >> 1273 if(pte_present(*ptep)) { >> 1274 unsigned long page = (unsigned long) page_address(pte_page(*ptep)); >> 1275 >> 1276 __asm__ __volatile__( >> 1277 " membar #StoreStore\n" >> 1278 " flush %0 + %1" >> 1279 : : "r" (page), "r" (address & (PAGE_SIZE - 1)) >> 1280 : "memory"); >> 1281 } >> 1282 } >> 1283 return; >> 1284 >> 1285 sigill: >> 1286 do_exit(SIGILL); >> 1287 sigsegv: >> 1288 do_exit(SIGSEGV); >> 1289 } >> 1290 >> 1291 static inline void handle_signal32(unsigned long signr, struct k_sigaction *ka, >> 1292 siginfo_t *info, >> 1293 sigset_t *oldset, struct pt_regs *regs, >> 1294 int svr4_signal) >> 1295 { >> 1296 if(svr4_signal) >> 1297 setup_svr4_frame32(&ka->sa, regs->tpc, regs->tnpc, regs, signr, oldset); >> 1298 else { >> 1299 if (ka->sa.sa_flags & SA_SIGINFO) >> 1300 setup_rt_frame32(ka, regs, signr, oldset, info); >> 1301 else if (current->thread.flags & SPARC_FLAG_NEWSIGNALS) >> 1302 new_setup_frame32(ka, regs, signr, oldset); >> 1303 else >> 1304 setup_frame32(&ka->sa, regs, signr, oldset, info); >> 1305 } >> 1306 if(ka->sa.sa_flags & SA_ONESHOT) >> 1307 ka->sa.sa_handler = SIG_DFL; >> 1308 if(!(ka->sa.sa_flags & SA_NOMASK)) { >> 1309 spin_lock_irq(¤t->sigmask_lock); >> 1310 sigorsets(¤t->blocked,¤t->blocked,&ka->sa.sa_mask); >> 1311 sigaddset(¤t->blocked,signr); >> 1312 recalc_sigpending(current); >> 1313 spin_unlock_irq(¤t->sigmask_lock); >> 1314 } >> 1315 } >> 1316 >> 1317 static inline void syscall_restart32(unsigned long orig_i0, struct pt_regs *regs, >> 1318 struct sigaction *sa) >> 1319 { >> 1320 switch(regs->u_regs[UREG_I0]) { >> 1321 case ERESTARTNOHAND: >> 1322 no_system_call_restart: >> 1323 regs->u_regs[UREG_I0] = EINTR; >> 1324 regs->tstate |= TSTATE_ICARRY; >> 1325 break; >> 1326 case ERESTARTSYS: >> 1327 if(!(sa->sa_flags & SA_RESTART)) >> 1328 goto no_system_call_restart; >> 1329 /* fallthrough */ >> 1330 case ERESTARTNOINTR: >> 1331 regs->u_regs[UREG_I0] = orig_i0; >> 1332 regs->tpc -= 4; >> 1333 regs->tnpc -= 4; >> 1334 } >> 1335 } >> 1336 >> 1337 #ifdef DEBUG_SIGNALS_MAPS >> 1338 >> 1339 #define MAPS_LINE_FORMAT "%016lx-%016lx %s %016lx %s %lu " >> 1340 >> 1341 static inline void read_maps (void) >> 1342 { >> 1343 struct vm_area_struct * map, * next; >> 1344 char * buffer; >> 1345 ssize_t i; >> 1346 >> 1347 buffer = (char*)__get_free_page(GFP_KERNEL); >> 1348 if (!buffer) >> 1349 return; >> 1350 >> 1351 for (map = current->mm->mmap ; map ; map = next ) { >> 1352 /* produce the next line */ >> 1353 char *line; >> 1354 char str[5], *cp = str; >> 1355 int flags; >> 1356 kdev_t dev; >> 1357 unsigned long ino; >> 1358 >> 1359 /* >> 1360 * Get the next vma now (but it won't be used if we sleep). >> 1361 */ >> 1362 next = map->vm_next; >> 1363 flags = map->vm_flags; >> 1364 >> 1365 *cp++ = flags & VM_READ ? 'r' : '-'; >> 1366 *cp++ = flags & VM_WRITE ? 'w' : '-'; >> 1367 *cp++ = flags & VM_EXEC ? 'x' : '-'; >> 1368 *cp++ = flags & VM_MAYSHARE ? 's' : 'p'; >> 1369 *cp++ = 0; >> 1370 >> 1371 dev = 0; >> 1372 ino = 0; >> 1373 if (map->vm_file != NULL) { >> 1374 dev = map->vm_file->f_dentry->d_inode->i_dev; >> 1375 ino = map->vm_file->f_dentry->d_inode->i_ino; >> 1376 line = d_path(map->vm_file->f_dentry, >> 1377 map->vm_file->f_vfsmnt, >> 1378 buffer, PAGE_SIZE); >> 1379 if (IS_ERR(line)) >> 1380 break; >> 1381 } >> 1382 printk(MAPS_LINE_FORMAT, map->vm_start, map->vm_end, str, map->vm_pgoff << PAGE_SHIFT, >> 1383 kdevname(dev), ino); >> 1384 if (map->vm_file != NULL) >> 1385 printk("%s\n", line); >> 1386 else >> 1387 printk("\n"); >> 1388 } >> 1389 free_page((unsigned long)buffer); >> 1390 return; >> 1391 } >> 1392 >> 1393 #endif >> 1394 >> 1395 /* Note that 'init' is a special process: it doesn't get signals it doesn't >> 1396 * want to handle. Thus you cannot kill init even with a SIGKILL even by >> 1397 * mistake. >> 1398 */ >> 1399 asmlinkage int do_signal32(sigset_t *oldset, struct pt_regs * regs, >> 1400 unsigned long orig_i0, int restart_syscall) >> 1401 { >> 1402 unsigned long signr; >> 1403 struct k_sigaction *ka; >> 1404 siginfo_t info; >> 1405 >> 1406 int svr4_signal = current->personality == PER_SVR4; >> 1407 >> 1408 for (;;) { >> 1409 spin_lock_irq(¤t->sigmask_lock); >> 1410 signr = dequeue_signal(¤t->blocked, &info); >> 1411 spin_unlock_irq(¤t->sigmask_lock); 189 1412 190 compat_reg = (compat_uint_t)(r !! 1413 if (!signr) 191 err |= __put_user(compat_reg, !! 1414 break; 192 DBG(2,"setup_sigcontext32: sc- !! 1415 193 &sc->sc_iasq[0 !! 1416 if ((current->ptrace & PT_PTRACED) && signr != SIGKILL) { 194 /* Store upper half */ !! 1417 /* Do the syscall restart before we let the debugger 195 compat_reg = (compat_uint_t)(r !! 1418 * look at the child registers. 196 err |= __put_user(compat_reg, !! 1419 */ 197 DBG(2,"setup_sigcontext32: upp !! 1420 if (restart_syscall && >> 1421 (regs->u_regs[UREG_I0] == ERESTARTNOHAND || >> 1422 regs->u_regs[UREG_I0] == ERESTARTSYS || >> 1423 regs->u_regs[UREG_I0] == ERESTARTNOINTR)) { >> 1424 regs->u_regs[UREG_I0] = orig_i0; >> 1425 regs->tpc -= 4; >> 1426 regs->tnpc -= 4; >> 1427 restart_syscall = 0; >> 1428 } >> 1429 >> 1430 current->exit_code = signr; >> 1431 current->state = TASK_STOPPED; >> 1432 notify_parent(current, SIGCHLD); >> 1433 schedule(); >> 1434 if (!(signr = current->exit_code)) >> 1435 continue; >> 1436 current->exit_code = 0; >> 1437 if (signr == SIGSTOP) >> 1438 continue; >> 1439 >> 1440 /* Update the siginfo structure. Is this good? */ >> 1441 if (signr != info.si_signo) { >> 1442 info.si_signo = signr; >> 1443 info.si_errno = 0; >> 1444 info.si_code = SI_USER; >> 1445 info.si_pid = current->p_pptr->pid; >> 1446 info.si_uid = current->p_pptr->uid; >> 1447 } >> 1448 >> 1449 /* If the (new) signal is now blocked, requeue it. */ >> 1450 if (sigismember(¤t->blocked, signr)) { >> 1451 send_sig_info(signr, &info, current); >> 1452 continue; >> 1453 } >> 1454 } 198 1455 >> 1456 ka = ¤t->sig->action[signr-1]; 199 1457 200 compat_reg = (compat_uint_t)(r !! 1458 if (ka->sa.sa_handler == SIG_IGN) { 201 err |= __put_user(compat_reg, !! 1459 if (signr != SIGCHLD) 202 DBG(2,"setup_sigcontext32: sc- !! 1460 continue; 203 &sc->sc_iasq[1 << 204 /* Store upper half */ << 205 compat_reg = (compat_uint_t)(r << 206 err |= __put_user(compat_reg, << 207 DBG(2,"setup_sigcontext32: upp << 208 << 209 /* Print out the IAOQ for debu << 210 DBG(1,"setup_sigcontext32: ia0 << 211 regs->iaoq[0], regs->i << 212 } << 213 << 214 err |= __put_user(flags, &sc->sc_flags << 215 << 216 DBG(1,"setup_sigcontext32: Truncating << 217 << 218 for(regn=0; regn < 32; regn++){ << 219 /* Truncate a general register << 220 compat_reg = (compat_uint_t)(r << 221 err |= __put_user(compat_reg, << 222 /* Store upper half */ << 223 compat_regb = (compat_uint_t)( << 224 err |= __put_user(compat_regb, << 225 << 226 /* DEBUG: Write out the "upper << 227 DBG(2,"setup_sigcontext32: gr% << 228 compat_regb, c << 229 } << 230 << 231 /* Copy the floating point registers ( << 232 XXX: BE WARNED FR's are 64-BIT! */ << 233 DBG(1,"setup_sigcontext32: Copying fro << 234 "sc->sc_fr size = %#lx, regs->fr << 235 sizeof(regs->fr), sizeof(sc->s << 236 err |= __copy_to_user(sc->sc_fr, regs- << 237 << 238 compat_reg = (compat_uint_t)(regs->sar << 239 err |= __put_user(compat_reg, &sc->sc_ << 240 DBG(2,"setup_sigcontext32: sar is %#x\ << 241 /* Store upper half */ << 242 compat_reg = (compat_uint_t)(regs->sar << 243 err |= __put_user(compat_reg, &rf->rf_ << 244 DBG(2,"setup_sigcontext32: upper half << 245 DBG(1,"setup_sigcontext32: r28 is %ld\ << 246 1461 247 return err; !! 1462 /* sys_wait4() grabs the master kernel lock, so >> 1463 * we need not do so, that sucker should be >> 1464 * threaded and would not be that difficult to >> 1465 * do anyways. >> 1466 */ >> 1467 while (sys_wait4(-1, NULL, WNOHANG, NULL) > 0) >> 1468 ; >> 1469 continue; >> 1470 } >> 1471 if (ka->sa.sa_handler == SIG_DFL) { >> 1472 unsigned long exit_code = signr; >> 1473 >> 1474 if (current->pid == 1) >> 1475 continue; >> 1476 switch (signr) { >> 1477 case SIGCONT: case SIGCHLD: case SIGWINCH: case SIGURG: >> 1478 continue; >> 1479 >> 1480 case SIGTSTP: case SIGTTIN: case SIGTTOU: >> 1481 if (is_orphaned_pgrp(current->pgrp)) >> 1482 continue; >> 1483 >> 1484 case SIGSTOP: >> 1485 if (current->ptrace & PT_PTRACED) >> 1486 continue; >> 1487 current->state = TASK_STOPPED; >> 1488 current->exit_code = signr; >> 1489 if (!(current->p_pptr->sig->action[SIGCHLD-1].sa.sa_flags & >> 1490 SA_NOCLDSTOP)) >> 1491 notify_parent(current, SIGCHLD); >> 1492 schedule(); >> 1493 continue; >> 1494 >> 1495 case SIGQUIT: case SIGILL: case SIGTRAP: >> 1496 case SIGABRT: case SIGFPE: case SIGSEGV: >> 1497 case SIGBUS: case SIGSYS: case SIGXCPU: case SIGXFSZ: >> 1498 if (do_coredump(signr, regs)) >> 1499 exit_code |= 0x80; >> 1500 #ifdef DEBUG_SIGNALS >> 1501 /* Very useful to debug dynamic linker problems */ >> 1502 printk ("Sig %ld going for %s[%d]...\n", signr, current->comm, current->pid); >> 1503 /* On SMP we are only interested in the current >> 1504 * CPU's registers. >> 1505 */ >> 1506 __show_regs (regs); >> 1507 #ifdef DEBUG_SIGNALS_TLB >> 1508 do { >> 1509 extern void sparc_ultra_dump_itlb(void); >> 1510 extern void sparc_ultra_dump_dtlb(void); >> 1511 sparc_ultra_dump_dtlb(); >> 1512 sparc_ultra_dump_itlb(); >> 1513 } while(0); >> 1514 #endif >> 1515 #ifdef DEBUG_SIGNALS_TRACE >> 1516 { >> 1517 struct reg_window32 *rw = (struct reg_window32 *)(regs->u_regs[UREG_FP] & 0xffffffff); >> 1518 unsigned int ins[8]; >> 1519 >> 1520 while (rw && >> 1521 !(((unsigned long) rw) & 0x3)) { >> 1522 copy_from_user(ins, &rw->ins[0], sizeof(ins)); >> 1523 printk("Caller[%08x](%08x,%08x,%08x,%08x,%08x,%08x)\n", ins[7], ins[0], ins[1], ins[2], ins[3], ins[4], ins[5]); >> 1524 rw = (struct reg_window32 *)(unsigned long)ins[6]; >> 1525 } >> 1526 } >> 1527 #endif >> 1528 #ifdef DEBUG_SIGNALS_MAPS >> 1529 printk("Maps:\n"); >> 1530 read_maps(); >> 1531 #endif >> 1532 #endif >> 1533 /* fall through */ >> 1534 default: >> 1535 sig_exit(signr, exit_code, &info); >> 1536 /* NOT REACHED */ >> 1537 } >> 1538 } >> 1539 if (restart_syscall) >> 1540 syscall_restart32(orig_i0, regs, &ka->sa); >> 1541 handle_signal32(signr, ka, &info, oldset, regs, svr4_signal); >> 1542 return 1; >> 1543 } >> 1544 if (restart_syscall && >> 1545 (regs->u_regs[UREG_I0] == ERESTARTNOHAND || >> 1546 regs->u_regs[UREG_I0] == ERESTARTSYS || >> 1547 regs->u_regs[UREG_I0] == ERESTARTNOINTR)) { >> 1548 /* replay the system call when we are done */ >> 1549 regs->u_regs[UREG_I0] = orig_i0; >> 1550 regs->tpc -= 4; >> 1551 regs->tnpc -= 4; >> 1552 } >> 1553 return 0; >> 1554 } >> 1555 >> 1556 struct sigstack32 { >> 1557 u32 the_stack; >> 1558 int cur_status; >> 1559 }; >> 1560 >> 1561 asmlinkage int do_sys32_sigstack(u32 u_ssptr, u32 u_ossptr, unsigned long sp) >> 1562 { >> 1563 struct sigstack32 *ssptr = (struct sigstack32 *)((unsigned long)(u_ssptr)); >> 1564 struct sigstack32 *ossptr = (struct sigstack32 *)((unsigned long)(u_ossptr)); >> 1565 int ret = -EFAULT; >> 1566 >> 1567 /* First see if old state is wanted. */ >> 1568 if (ossptr) { >> 1569 if (put_user(current->sas_ss_sp + current->sas_ss_size, &ossptr->the_stack) || >> 1570 __put_user(on_sig_stack(sp), &ossptr->cur_status)) >> 1571 goto out; >> 1572 } >> 1573 >> 1574 /* Now see if we want to update the new state. */ >> 1575 if (ssptr) { >> 1576 u32 ss_sp; >> 1577 >> 1578 if (get_user(ss_sp, &ssptr->the_stack)) >> 1579 goto out; >> 1580 /* If the current stack was set with sigaltstack, don't >> 1581 swap stacks while we are on it. */ >> 1582 ret = -EPERM; >> 1583 if (current->sas_ss_sp && on_sig_stack(sp)) >> 1584 goto out; >> 1585 >> 1586 /* Since we don't know the extent of the stack, and we don't >> 1587 track onstack-ness, but rather calculate it, we must >> 1588 presume a size. Ho hum this interface is lossy. */ >> 1589 current->sas_ss_sp = (unsigned long)ss_sp - SIGSTKSZ; >> 1590 current->sas_ss_size = SIGSTKSZ; >> 1591 } >> 1592 >> 1593 ret = 0; >> 1594 out: >> 1595 return ret; >> 1596 } >> 1597 >> 1598 asmlinkage int do_sys32_sigaltstack(u32 ussa, u32 uossa, unsigned long sp) >> 1599 { >> 1600 stack_t uss, uoss; >> 1601 u32 u_ss_sp = 0; >> 1602 int ret; >> 1603 mm_segment_t old_fs; >> 1604 >> 1605 if (ussa && (get_user(u_ss_sp, &((stack_t32 *)(long)ussa)->ss_sp) || >> 1606 __get_user(uss.ss_flags, &((stack_t32 *)(long)ussa)->ss_flags) || >> 1607 __get_user(uss.ss_size, &((stack_t32 *)(long)ussa)->ss_size))) >> 1608 return -EFAULT; >> 1609 uss.ss_sp = (void *) (long) u_ss_sp; >> 1610 old_fs = get_fs(); >> 1611 set_fs(KERNEL_DS); >> 1612 ret = do_sigaltstack(ussa ? &uss : NULL, uossa ? &uoss : NULL, sp); >> 1613 set_fs(old_fs); >> 1614 if (!ret && uossa && (put_user((long)uoss.ss_sp, &((stack_t32 *)(long)uossa)->ss_sp) || >> 1615 __put_user(uoss.ss_flags, &((stack_t32 *)(long)uossa)->ss_flags) || >> 1616 __put_user(uoss.ss_size, &((stack_t32 *)(long)uossa)->ss_size))) >> 1617 return -EFAULT; >> 1618 return ret; 248 } 1619 } 249 1620
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.