if (summary & 1) { /* Software-completion summary bit is set, so try to emulate the instruction. If the processor supports
precise exceptions, we don't have to search. */ if (!amask(AMASK_PRECISE_TRAP))
si_code = alpha_fp_emul(regs->pc - 4); else
si_code = alpha_fp_emul_imprecise(regs, write_mask); if (si_code == 0) return;
}
die_if_kernel("Arithmetic fault", regs, 0, NULL);
if (type == 3) { /* FEN fault */ /* Irritating users can call PAL_clrfen to disable the FPU for the process. The kernel will then trap in do_switch_stack and undo_switch_stack when we try to save and restore the FP registers.
Given that GCC by default generates code that uses the FP registers, PAL_clrfen is not useful except for DoS attacks. So turn the bleeding FPU back on and be done
with it. */
current_thread_info()->pcb.flags |= 1;
__reload_thread(¤t_thread_info()->pcb); return;
} if (!user_mode(regs)) { if (type == 1) { constunsignedint *data
= (constunsignedint *) regs->pc;
printk("Kernel bug at %s:%d\n",
(constchar *)(data[1] | (long)data[2] << 32),
data[0]);
} #ifdef CONFIG_ALPHA_WTINT if (type == 4) { /* If CALL_PAL WTINT is totally unsupported by the PALcode, e.g. MILO, "emulate" it by overwriting
the insn. */ unsignedint *pinsn
= (unsignedint *) regs->pc - 1; if (*pinsn == PAL_wtint) {
*pinsn = 0x47e01400; /* mov 0,$0 */
imb();
regs->r0 = 0; return;
}
} #endif/* ALPHA_WTINT */
die_if_kernel((type == 1 ? "Kernel Bug" : "Instruction fault"),
regs, type, NULL);
}
switch (type) { case 0: /* breakpoint */ if (ptrace_cancel_bpt(current)) {
regs->pc -= 4; /* make pc point to former bpt */
}
case 2: /* gentrap */ switch ((long) regs->r16) { case GEN_INTOVF:
signo = SIGFPE;
code = FPE_INTOVF; break; case GEN_INTDIV:
signo = SIGFPE;
code = FPE_INTDIV; break; case GEN_FLTOVF:
signo = SIGFPE;
code = FPE_FLTOVF; break; case GEN_FLTDIV:
signo = SIGFPE;
code = FPE_FLTDIV; break; case GEN_FLTUND:
signo = SIGFPE;
code = FPE_FLTUND; break; case GEN_FLTINV:
signo = SIGFPE;
code = FPE_FLTINV; break; case GEN_FLTINE:
signo = SIGFPE;
code = FPE_FLTRES; break; case GEN_ROPRAND:
signo = SIGFPE;
code = FPE_FLTUNK; break;
case GEN_DECOVF: case GEN_DECDIV: case GEN_DECINV: case GEN_ASSERTERR: case GEN_NULPTRERR: case GEN_STKOVF: case GEN_STRLENERR: case GEN_SUBSTRERR: case GEN_RANGERR: case GEN_SUBRNG: case GEN_SUBRNG1: case GEN_SUBRNG2: case GEN_SUBRNG3: case GEN_SUBRNG4: case GEN_SUBRNG5: case GEN_SUBRNG6: case GEN_SUBRNG7: default:
signo = SIGTRAP;
code = TRAP_UNK; break;
}
/* There is an ifdef in the PALcode in MILO that enables a "kernel debugging entry point" as an unprivileged call_pal.
We don't want to have anything to do with it, but unfortunately several versions of MILO included in distributions have it enabled,
and if we don't put something on the entry point we'll oops. */
/* * entUna has a different register layout to be reasonably simple. It * needs access to all the integer registers (the kernel doesn't use * fp-regs), and it needs to have them in order for simpler access. * * Due to the non-standard register layout (and because we don't want * to handle floating-point regs), user-mode unaligned accesses are * handled separately by do_entUnaUser below. * * Oh, btw, we don't handle the "gp" register correctly, but if we fault * on a gp-register unaligned load/store, something is _very_ wrong * in the kernel anyway..
*/ struct allregs { unsignedlong regs[32]; unsignedlong ps, pc, gp, a0, a1, a2;
};
struct unaligned_stat { unsignedlong count, va, pc;
} unaligned[2];
/* We don't want to use the generic get/put unaligned macros as we want to trap exceptions. Only if we actually get an
exception will we decide whether we should have caught it. */
/* Note that the store sequences do not indicate that they change memory because it _should_ be affecting nothing in this context.
(Otherwise we have other, much larger, problems.) */ case 0x0d: /* stw */
__asm__ __volatile__( "1: ldq_u %2,1(%5)\n" "2: ldq_u %1,0(%5)\n" " inswh %6,%5,%4\n" " inswl %6,%5,%3\n" " mskwh %2,%5,%2\n" " mskwl %1,%5,%1\n" " or %2,%4,%2\n" " or %1,%3,%1\n" "3: stq_u %2,1(%5)\n" "4: stq_u %1,0(%5)\n" "5:\n"
EXC(1b,5b,%2,%0)
EXC(2b,5b,%1,%0)
EXC(3b,5b,$31,%0)
EXC(4b,5b,$31,%0)
: "=r"(error), "=&r"(tmp1), "=&r"(tmp2), "=&r"(tmp3), "=&r"(tmp4)
: "r"(va), "r"(una_reg(reg)), "0"(0)); if (error) goto got_exception; return;
printk("Bad unaligned kernel access at %016lx: %p %lx %lu\n",
pc, va, opcode, reg);
make_task_dead(SIGSEGV);
got_exception: /* Ok, we caught the exception, but we don't want it. Is there
someone to pass it along to? */ if ((fixup = search_exception_tables(pc)) != 0) { unsignedlong newpc;
newpc = fixup_exception(una_reg, fixup, pc);
printk("Forwarding unaligned exception at %lx (%lx)\n",
pc, newpc);
regs->pc = newpc; return;
}
/* * Yikes! No one to forward the exception to. * Since the registers are in a weird format, dump them ourselves.
*/
/* * Convert an s-floating point value in register format to the * corresponding value in memory format.
*/ staticinlineunsignedlong
s_reg_to_mem (unsignedlong s_reg)
{ return ((s_reg >> 62) << 30) | ((s_reg << 5) >> 34);
}
/* * Handle user-level unaligned fault. Handling user-level unaligned * faults is *extremely* slow and produces nasty messages. A user * program *should* fix unaligned faults ASAP. * * Notice that we have (almost) the regular kernel stack layout here, * so finding the appropriate registers is a little more difficult * than in the kernel case. * * Finally, we handle regular integer load/stores only. In * particular, load-linked/store-conditionally and floating point * load/stores are not supported. The former make no sense with * unaligned faults (they are guaranteed to fail) and I don't think * the latter will occur in any decent program. * * Sigh. We *do* have to handle some FP operations, because GCC will * uses them as temporary storage for integer memory to memory copies. * However, we need to deal with stt/ldt and sts/lds only.
*/
unsignedlong tmp1, tmp2, tmp3, tmp4; unsignedlong fake_reg, *reg_addr = &fake_reg; int si_code; long error;
/* Check the UAC bits to decide what the user wants us to do
with the unaligned access. */
if (!(current_thread_info()->status & TS_UAC_NOPRINT)) { if (__ratelimit(&ratelimit)) {
printk("%s(%d): unaligned trap at %016lx: %p %lx %ld\n",
current->comm, task_pid_nr(current),
regs->pc - 4, va, opcode, reg);
}
} if ((current_thread_info()->status & TS_UAC_SIGBUS)) goto give_sigbus; /* Not sure why you'd want to use this, but... */ if ((current_thread_info()->status & TS_UAC_NOFIX)) return;
/* Don't bother reading ds in the access check since we already know that this came from the user. Also rely on the fact that
the page at TASK_SIZE is unmapped and so can't be touched anyway. */ if ((unsignedlong)va >= TASK_SIZE) goto give_sigsegv;
if ((1L << opcode) & OP_INT_MASK) { /* it's an integer load/store */ if (reg < 30) {
reg_addr = (unsignedlong *)
((char *)regs + unauser_reg_offsets[reg]);
} elseif (reg == 30) { /* usp in PAL regs */
fake_reg = rdusp();
} else { /* zero "register" */
fake_reg = 0;
}
}
/* We don't want to use the generic get/put unaligned macros as we want to trap exceptions. Only if we actually get an
exception will we decide whether we should have caught it. */
/* Note that the store sequences do not indicate that they change memory because it _should_ be affecting nothing in this context.
(Otherwise we have other, much larger, problems.) */ case 0x0d: /* stw */
__asm__ __volatile__( "1: ldq_u %2,1(%5)\n" "2: ldq_u %1,0(%5)\n" " inswh %6,%5,%4\n" " inswl %6,%5,%3\n" " mskwh %2,%5,%2\n" " mskwl %1,%5,%1\n" " or %2,%4,%2\n" " or %1,%3,%1\n" "3: stq_u %2,1(%5)\n" "4: stq_u %1,0(%5)\n" "5:\n"
EXC(1b,5b,%2,%0)
EXC(2b,5b,%1,%0)
EXC(3b,5b,$31,%0)
EXC(4b,5b,$31,%0)
: "=r"(error), "=&r"(tmp1), "=&r"(tmp2), "=&r"(tmp3), "=&r"(tmp4)
: "r"(va), "r"(*reg_addr), "0"(0)); if (error) goto give_sigsegv; return;
case 0x26: /* sts */
fake_reg = s_reg_to_mem(alpha_read_fp_reg(reg));
fallthrough;
default: /* What instruction were you trying to use, exactly? */ goto give_sigbus;
}
/* Only integer loads should get here; everyone else returns early. */ if (reg == 30)
wrusp(fake_reg); return;
give_sigsegv:
regs->pc -= 4; /* make pc point to faulting insn */
/* We need to replicate some of the logic in mm/fault.c, since we don't have access to the fault code in the
exception handling return path. */ if ((unsignedlong)va >= TASK_SIZE)
si_code = SEGV_ACCERR; else { struct mm_struct *mm = current->mm;
mmap_read_lock(mm); if (find_vma(mm, (unsignedlong)va))
si_code = SEGV_ACCERR; else
si_code = SEGV_MAPERR;
mmap_read_unlock(mm);
}
send_sig_fault(SIGSEGV, si_code, va, current); return;
give_sigbus:
regs->pc -= 4;
send_sig_fault(SIGBUS, BUS_ADRALN, va, current); return;
}
void
trap_init(void)
{ /* Tell PAL-code what global pointer we want in the kernel. */ registerunsignedlong gptr __asm__("$29");
wrkgp(gptr);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.