only openbsd & linux have been tested. hp,irix,macosx,solaris are
unchanged. they were different and/or i have no chance of testing
them.
http://code.google.com/p/inferno-npe/source/detail?r=04b3e2d2e6
Modified:
/emu/DragonFly/os.c
/emu/FreeBSD/os.c
/emu/Linux/os.c
/emu/NetBSD/os.c
/emu/OpenBSD/os.c
=======================================
--- /emu/DragonFly/os.c Wed Jan 13 15:30:03 2010
+++ /emu/DragonFly/os.c Mon Feb 1 04:40:39 2010
@@ -64,17 +64,6 @@
if(kstack != nil)
stackfreeandexit(kstack);
}
-
-void
-trapBUS(int signo, siginfo_t *info, void *context)
-{
- if(info)
- print("trapBUS: signo: %d code: %d addr: %lx\n",
- info->si_signo, info->si_code, info->si_addr);
- else
- print("trapBUS: no info\n");
- disfault(nil, "Bus error");
-}
static void
trapUSR1(int signo)
@@ -98,17 +87,53 @@
USED(signo);
/* we've done our work of interrupting sigsuspend */
}
+
static void
-trapILL(int signo)
-{
- disfault(nil, "Illegal instruction");
+diserr(char *msg, siginfo_t *si)
+{
+ char buf[128];
+
+ if(si != nil) {
+ snprint(buf, sizeof buf, "%s, addr=%p", msg, si->si_addr);
+ disfault(nil, buf);
+ } else
+ disfault(nil, msg);
}
static void
-trapSEGV(int signo)
-{
- disfault(nil, "Segmentation violation");
+trapBUS(int signo, siginfo_t *si, void *context)
+{
+ USED(signo);
+ USED(context);
+ diserr("Bus error", si);
+}
+
+static void
+trapILL(int signo, siginfo_t *si, void *context)
+{
+ USED(signo);
+ USED(context);
+ diserr("Illegal instruction", si);
+}
+
+static void
+trapSEGV(int signo, siginfo_t *si, void *context)
+{
+ USED(signo);
+ USED(context);
+ diserr("Segmentation violation", si);
+}
+
+#include <fpuctl.h>
+void
+trapFPE(int signo, siginfo_t *si, void *context)
+{
+ USED(signo);
+ USED(context);
+
+ print("FPU status=0x%.4lux\n", getfsr());
+ diserr("Floating point exception", si);
}
static sigset_t initmask;
@@ -146,16 +171,19 @@
panic("sigaction SIGCHLD");
if(sflag == 0) {
- act.sa_sigaction = trapBUS;
act.sa_flags |= SA_SIGINFO;
+ act.sa_sigaction = trapBUS;
if(sigaction(SIGBUS, &act, nil))
panic("sigaction SIGBUS");
- act.sa_handler = trapILL;
+ act.sa_sigaction = trapILL;
if(sigaction(SIGILL, &act, nil))
- panic("sigaction SIGBUS");
- act.sa_handler = trapSEGV;
+ panic("sigaction SIGILL");
+ act.sa_sigaction = trapSEGV;
if(sigaction(SIGSEGV, &act, nil))
panic("sigaction SIGSEGV");
+ act.sa_sigaction = trapFPE;
+ if(sigaction(SIGFPE, &act, nil))
+ panic("sigaction SIGFPE");
if(sigaddset(&initmask, SIGINT) == -1)
panic("sigaddset");
}
=======================================
--- /emu/FreeBSD/os.c Sun Jul 19 09:10:21 2009
+++ /emu/FreeBSD/os.c Mon Feb 1 04:40:39 2010
@@ -64,17 +64,6 @@
if(kstack != nil)
stackfreeandexit(kstack);
}
-
-void
-trapBUS(int signo, siginfo_t *info, void *context)
-{
- if(info)
- print("trapBUS: signo: %d code: %d addr: %lx\n",
- info->si_signo, info->si_code, info->si_addr);
- else
- print("trapBUS: no info\n");
- disfault(nil, "Bus error");
-}
static void
trapUSR1(int signo)
@@ -100,15 +89,50 @@
}
static void
-trapILL(int signo)
-{
- disfault(nil, "Illegal instruction");
+diserr(char *msg, siginfo_t *si)
+{
+ char buf[128];
+
+ if(si != nil) {
+ snprint(buf, sizeof buf, "%s, addr=%p", msg, si->si_addr);
+ disfault(nil, buf);
+ } else
+ disfault(nil, msg);
}
static void
-trapSEGV(int signo)
-{
- disfault(nil, "Segmentation violation");
+trapBUS(int signo, siginfo_t *si, void *context)
+{
+ USED(signo);
+ USED(context);
+ diserr("Bus error", si);
+}
+
+static void
+trapILL(int signo, siginfo_t *si, void *context)
+{
+ USED(signo);
+ USED(context);
+ diserr("Illegal instruction", si);
+}
+
+static void
+trapSEGV(int signo, siginfo_t *si, void *context)
+{
+ USED(signo);
+ USED(context);
+ diserr("Segmentation violation", si);
+}
+
+#include <fpuctl.h>
+void
+trapFPE(int signo, siginfo_t *si, void *context)
+{
+ USED(signo);
+ USED(context);
+
+ print("FPU status=0x%.4lux\n", getfsr());
+ diserr("Floating point exception", si);
}
static sigset_t initmask;
@@ -146,16 +170,19 @@
panic("sigaction SIGCHLD");
if(sflag == 0) {
- act.sa_sigaction = trapBUS;
act.sa_flags |= SA_SIGINFO;
+ act.sa_sigaction = trapBUS;
if(sigaction(SIGBUS, &act, nil))
panic("sigaction SIGBUS");
- act.sa_handler = trapILL;
+ act.sa_sigaction = trapILL;
if(sigaction(SIGILL, &act, nil))
- panic("sigaction SIGBUS");
- act.sa_handler = trapSEGV;
+ panic("sigaction SIGILL");
+ act.sa_sigaction = trapSEGV;
if(sigaction(SIGSEGV, &act, nil))
panic("sigaction SIGSEGV");
+ act.sa_sigaction = trapFPE;
+ if(sigaction(SIGFPE, &act, nil))
+ panic("sigaction SIGFPE");
if(sigaddset(&initmask, SIGINT) == -1)
panic("sigaddset");
}
=======================================
--- /emu/Linux/os.c Fri Nov 13 05:07:00 2009
+++ /emu/Linux/os.c Mon Feb 1 04:40:39 2010
@@ -150,82 +150,82 @@
return 0;
}
-/*
- * TO DO:
- * To get pc on trap, use sigaction instead of signal and
- * examine its siginfo structure
- */
-
-/*
static void
-diserr(char *s, int pc)
-{
- char buf[ERRMAX];
-
- snprint(buf, sizeof(buf), "%s: pc=0x%lux", s, pc);
- disfault(nil, buf);
-}
-*/
+trapUSR1(int signo)
+{
+ int intwait;
+
+ USED(signo);
+
+ intwait = up->intwait;
+ up->intwait = 0; /* clear it to let proc continue in osleave */
+
+ if(up->type != Interp) /* Used to unblock pending I/O */
+ return;
+
+ if(intwait == 0) /* Not posted so it's a sync error */
+ disfault(nil, Eintr); /* Should never happen */
+}
+
+/* called to wake up kproc blocked on a syscall */
+void
+oshostintr(Proc *p)
+{
+ kill(p->sigid, SIGUSR1);
+}
static void
-trapILL(int signo)
+trapUSR2(int signo)
{
USED(signo);
- disfault(nil, "Illegal instruction");
+ /* we've done our work of interrupting sigsuspend */
}
static void
-trapBUS(int signo)
-{
- USED(signo);
- disfault(nil, "Bus error");
+diserr(char *msg, siginfo_t *si)
+{
+ char buf[128];
+
+ if(si != nil) {
+ snprint(buf, sizeof buf, "%s, addr=%p", msg, si->si_addr);
+ disfault(nil, buf);
+ } else
+ disfault(nil, msg);
}
static void
-trapSEGV(int signo)
+trapBUS(int signo, siginfo_t *si, void *context)
{
USED(signo);
- disfault(nil, "Segmentation violation");
+ USED(context);
+ diserr("Bus error", si);
}
-#include <fpuctl.h>
static void
-trapFPE(int signo)
+trapILL(int signo, siginfo_t *si, void *context)
{
USED(signo);
- print("FPU status=0x%.4lux", getfsr());
- disfault(nil, "Floating exception");
+ USED(context);
+ diserr("Illegal instruction", si);
}
static void
-trapUSR1(int signo)
-{
- int intwait;
-
+trapSEGV(int signo, siginfo_t *si, void *context)
+{
USED(signo);
-
- intwait = up->intwait;
- up->intwait = 0; /* clear it to let proc continue in osleave */
-
- if(up->type != Interp) /* Used to unblock pending I/O */
- return;
-
- if(intwait == 0) /* Not posted so it's a sync error */
- disfault(nil, Eintr); /* Should never happen */
+ USED(context);
+ diserr("Segmentation violation", si);
}
-/* called to wake up kproc blocked on a syscall */
+#include <fpuctl.h>
void
-oshostintr(Proc *p)
-{
- kill(p->sigid, SIGUSR1);
-}
-
-static void
-trapUSR2(int signo)
+trapFPE(int signo, siginfo_t *si, void *context)
{
USED(signo);
- /* we've done our work of interrupting sigsuspend */
+ USED(context);
+
+ print("FPU status=0x%.4lux\n", getfsr());
+ diserr("Floating point exception", si);
}
void
@@ -343,14 +343,19 @@
signal(SIGINT, cleanexit);
if(sflag == 0) {
- act.sa_handler = trapBUS;
- sigaction(SIGBUS, &act, nil);
- act.sa_handler = trapILL;
- sigaction(SIGILL, &act, nil);
- act.sa_handler = trapSEGV;
- sigaction(SIGSEGV, &act, nil);
- act.sa_handler = trapFPE;
- sigaction(SIGFPE, &act, nil);
+ act.sa_flags |= SA_SIGINFO;
+ act.sa_sigaction = trapBUS;
+ if(sigaction(SIGBUS, &act, nil))
+ panic("sigaction SIGBUS");
+ act.sa_sigaction = trapILL;
+ if(sigaction(SIGILL, &act, nil))
+ panic("sigaction SIGILL");
+ act.sa_sigaction = trapSEGV;
+ if(sigaction(SIGSEGV, &act, nil))
+ panic("sigaction SIGSEGV");
+ act.sa_sigaction = trapFPE;
+ if(sigaction(SIGFPE, &act, nil))
+ panic("sigaction SIGFPE");
}
p = newproc();
=======================================
--- /emu/NetBSD/os.c Sun Jul 19 09:10:21 2009
+++ /emu/NetBSD/os.c Mon Feb 1 04:40:39 2010
@@ -150,68 +150,68 @@
return 0;
}
-/*
- * TO DO:
- * To get pc on trap, use sigaction instead of signal and
- * examine its siginfo structure
- */
-
-/*
static void
-diserr(char *s, int pc)
-{
- char buf[ERRMAX];
-
- snprint(buf, sizeof(buf), "%s: pc=0x%lux", s, pc);
- disfault(nil, buf);
-}
-*/
+trapUSR1(int signo)
+{
+ int intwait;
+
+ USED(signo);
+
+ intwait = up->intwait;
+ up->intwait = 0; /* clear it to let proc continue in osleave */
+
+ if(up->type != Interp) /* Used to unblock pending I/O */
+ return;
+
+ if(intwait == 0) /* Not posted so it's a sync error */
+ disfault(nil, Eintr); /* Should never happen */
+}
static void
-trapILL(int signo)
-{
- USED(signo);
- disfault(nil, "Illegal instruction");
+diserr(char *msg, siginfo_t *si)
+{
+ char buf[128];
+
+ if(si != nil) {
+ snprint(buf, sizeof buf, "%s, addr=%p", msg, si->si_addr);
+ disfault(nil, buf);
+ } else
+ disfault(nil, msg);
}
static void
-trapBUS(int signo)
+trapBUS(int signo, siginfo_t *si, void *context)
{
USED(signo);
- disfault(nil, "Bus error");
+ USED(context);
+ diserr("Bus error", si);
}
static void
-trapSEGV(int signo)
+trapILL(int signo, siginfo_t *si, void *context)
{
USED(signo);
- disfault(nil, "Segmentation violation");
+ USED(context);
+ diserr("Illegal instruction", si);
}
-#include <fpuctl.h>
static void
-trapFPE(int signo)
+trapSEGV(int signo, siginfo_t *si, void *context)
{
USED(signo);
- print("FPU status=0x%.4lux", getfsr());
- disfault(nil, "Floating exception");
+ USED(context);
+ diserr("Segmentation violation", si);
}
-static void
-trapUSR1(int signo)
-{
- int intwait;
-
+#include <fpuctl.h>
+void
+trapFPE(int signo, siginfo_t *si, void *context)
+{
USED(signo);
-
- intwait = up->intwait;
- up->intwait = 0; /* clear it to let proc continue in osleave */
-
- if(up->type != Interp) /* Used to unblock pending I/O */
- return;
-
- if(intwait == 0) /* Not posted so it's a sync error */
- disfault(nil, Eintr); /* Should never happen */
+ USED(context);
+
+ print("FPU status=0x%.4lux\n", getfsr());
+ diserr("Floating point exception", si);
}
/* called to wake up kproc blocked on a syscall */
@@ -348,14 +348,20 @@
signal(SIGINT, cleanexit);
if(sflag == 0) {
- act.sa_handler = trapBUS;
- sigaction(SIGBUS, &act, nil);
- act.sa_handler = trapILL;
- sigaction(SIGILL, &act, nil);
- act.sa_handler = trapSEGV;
- sigaction(SIGSEGV, &act, nil);
- act.sa_handler = trapFPE;
- sigaction(SIGFPE, &act, nil);
+ act.sa_flags |= SA_SIGINFO;
+ if(sigaction(SIGBUS, &act, nil))
+ panic("sigaction SIGBUS");
+ act.sa_sigaction = trapILL;
+ if(sigaction(SIGILL, &act, nil))
+ panic("sigaction SIGILL");
+ act.sa_sigaction = trapSEGV;
+ if(sigaction(SIGSEGV, &act, nil))
+ panic("sigaction SIGSEGV");
+ act.sa_sigaction = trapFPE;
+ if(sigaction(SIGFPE, &act, nil))
+ panic("sigaction SIGFPE");
+ if(sigaddset(&initmask, SIGINT) == -1)
+ panic("sigaddset");
}
p = newproc();
=======================================
--- /emu/OpenBSD/os.c Fri Nov 13 06:21:46 2009
+++ /emu/OpenBSD/os.c Mon Feb 1 04:40:39 2010
@@ -69,17 +69,6 @@
if(kstack != nil)
stackfreeandexit(kstack);
}
-
-void
-trapBUS(int signo, siginfo_t *info, void *context)
-{
- if(info)
- print("trapBUS: signo: %d code: %d addr: %lx\n",
- info->si_signo, info->si_code, info->si_addr);
- else
- print("trapBUS: no info\n");
- disfault(nil, "Bus error");
-}
static void
trapUSR1(int signo)
@@ -105,24 +94,50 @@
}
static void
-trapILL(int signo)
-{
- disfault(nil, "Illegal instruction");
+diserr(char *msg, siginfo_t *si)
+{
+ char buf[128];
+
+ if(si != nil) {
+ snprint(buf, sizeof buf, "%s, addr=%p", msg, si->si_addr);
+ disfault(nil, buf);
+ } else
+ disfault(nil, msg);
}
static void
-trapSEGV(int signo)
-{
- disfault(nil, "Segmentation violation");
+trapBUS(int signo, siginfo_t *si, void *context)
+{
+ USED(signo);
+ USED(context);
+ diserr("Bus error", si);
+}
+
+static void
+trapILL(int signo, siginfo_t *si, void *context)
+{
+ USED(signo);
+ USED(context);
+ diserr("Illegal instruction", si);
+}
+
+static void
+trapSEGV(int signo, siginfo_t *si, void *context)
+{
+ USED(signo);
+ USED(context);
+ diserr("Segmentation violation", si);
}
#include <fpuctl.h>
void
-trapFPE(int signo)
+trapFPE(int signo, siginfo_t *si, void *context)
{
USED(signo);
- print("FPU status=0x%.4lux", getfsr());
- disfault(nil, "Floating point exception");
+ USED(context);
+
+ print("FPU status=0x%.4lux\n", getfsr());
+ diserr("Floating point exception", si);
}
static sigset_t initmask;
@@ -160,17 +175,17 @@
panic("sigaction SIGCHLD");
if(sflag == 0) {
- act.sa_sigaction = trapBUS;
act.sa_flags |= SA_SIGINFO;
+ act.sa_sigaction = trapBUS;
if(sigaction(SIGBUS, &act, nil))
panic("sigaction SIGBUS");
- act.sa_handler = trapILL;
+ act.sa_sigaction = trapILL;
if(sigaction(SIGILL, &act, nil))
- panic("sigaction SIGBUS");
- act.sa_handler = trapSEGV;
+ panic("sigaction SIGILL");
+ act.sa_sigaction = trapSEGV;
if(sigaction(SIGSEGV, &act, nil))
panic("sigaction SIGSEGV");
- act.sa_handler = trapFPE;
+ act.sa_sigaction = trapFPE;
if(sigaction(SIGFPE, &act, nil))
panic("sigaction SIGFPE");
if(sigaddset(&initmask, SIGINT) == -1)