libvx32/Linux: segmentation faults do not update cr2! - vx32 - Local 9vx git repository for patches.
 (HTM) git clone git://r-36.net/vx32
 (DIR) Log
 (DIR) Files
 (DIR) Refs
       ---
 (DIR) commit 2b906e6f109d26364a2a7309c428ee5cbf0648bc
 (DIR) parent c14f1cf9af928d769bb73c5aaac69e7ba15bdb71
 (HTM) Author: Russ Cox <rsc@swtch.com>
       Date:   Sun, 29 Jun 2008 15:14:59 -0400
       
       libvx32/Linux: segmentation faults do not update cr2!
       
       Diffstat:
         M src/libvx32/linux.c                 |       6 +++++-
       
       1 file changed, 5 insertions(+), 1 deletion(-)
       ---
 (DIR) diff --git a/src/libvx32/linux.c b/src/libvx32/linux.c
       @@ -320,7 +320,11 @@ int vx32_sighandler(int signo, siginfo_t *si, void *v)
                        if (emu->trapenv == NULL)
                                return 0;
                        emu->cpu.traperr = ctx->err;
       -                emu->cpu.trapva = ctx->cr2;
       +                // Usually, ctx->cr2 == si->si_addr.
       +                // But on a segmentation fault (as opposed to a paging fault),
       +                // cr2 is not updated and the kernel sends an si_addr == 0.
       +                // Be sure to use si_addr, not cr2.
       +                emu->cpu.trapva = (uint32_t)si->si_addr;
                        memmove(mc->gregs, emu->trapenv->gregs, 19*4);
                        return 1;
                }