use sival_ptr instead of sival_int for breakpoint and illegal inst
authorjsg <jsg@openbsd.org>
Sat, 1 May 2021 03:03:15 +0000 (03:03 +0000)
committerjsg <jsg@openbsd.org>
Sat, 1 May 2021 03:03:15 +0000 (03:03 +0000)
For breakpoints stval will have a vaddr.  For illegal instructions stval
may be as large as a register or the widest instruction.

Also avoid using an uninitialised variable for stval.

ok mlarkin@ drahn@

sys/arch/riscv64/riscv64/trap_machdep.c

index 0b35a1f..b8a64be 100644 (file)
@@ -110,7 +110,6 @@ do_trap_user(struct trapframe *frame)
        union sigval sv; 
        struct proc *p;
        struct pcb *pcb;
-       uint64_t stval;
 
        p = curcpu()->ci_curproc;
        p->p_addr->u_pcb.pcb_tf = frame;
@@ -172,7 +171,7 @@ do_trap_user(struct trapframe *frame)
                }
        }
        printf("ILL at %lx scause %lx stval %lx\n", frame->tf_sepc, frame->tf_scause, frame->tf_stval);
-               sv.sival_int = stval;
+               sv.sival_ptr = (void *)frame->tf_stval;
                KERNEL_LOCK();
                trapsignal(p, SIGILL, 0, ILL_ILLTRP, sv);
                KERNEL_UNLOCK();
@@ -180,7 +179,7 @@ do_trap_user(struct trapframe *frame)
                break;
        case EXCP_BREAKPOINT:
        printf("BREAKPOINT\n");
-               sv.sival_int = stval;
+               sv.sival_ptr = (void *)frame->tf_stval;
                KERNEL_LOCK();
                trapsignal(p, SIGTRAP, 0, TRAP_BRKPT, sv);
                KERNEL_UNLOCK();
@@ -267,7 +266,7 @@ data_abort(struct trapframe *frame, int usermode)
                                sig = SIGSEGV;
                                code = SEGV_MAPERR;
                        }
-                       sv.sival_int = stval;
+                       sv.sival_ptr = (void *)stval;
                        KERNEL_LOCK();
                        //printf("signalling %d at pc 0%lx ra 0x%lx %llx\n", code, frame->tf_sepc, frame->tf_ra, stval);
                        trapsignal(p, sig, 0, code, sv);
@@ -289,6 +288,7 @@ done:
 
 fatal:
        dump_regs(frame);
-       panic("Fatal page fault at %#lx: %#08x", frame->tf_sepc, sv.sival_int);
+       panic("Fatal page fault at %#lx: %#08lx", frame->tf_sepc,
+           (vaddr_t)sv.sival_ptr);
 }