Subject: cosmetic fix to kdump for RET from EMUL "linux" (long)
To: None <tech-kern@netbsd.org>
From: Emmanuel Dreyfus <p99dreyf@criens.u-psud.fr>
List: tech-kern
Date: 02/01/2001 00:02:41
I made a rather complete fix, but I'm not sure it's The Right Way. Any
opinion on the following patch?

Index: usr.bin/kdump/kdump.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /cvsroot/basesrc/usr.bin/kdump/kdump.c,v
retrieving revision 1.34
diff -U4 -r1.34 kdump.c
--- usr.bin/kdump/kdump.c       2000/12/28 11:11:34     1.34
+++ usr.bin/kdump/kdump.c       2001/01/31 22:59:53
@@ -69,9 +69,9 @@
 #include "setemul.h"
=20
 #include <sys/syscall.h>
=20
-int timestamp, decimal, fancy =3D 1, tail, maxdata;
+int timestamp, decimal, fancy =3D 1, tail, maxdata, emul_changed =3D 0;
 const char *tracefile =3D DEF_TRACEFILE;
 struct ktr_header ktr_header;
=20
 #define eqs(s1, s2)    (strcmp((s1), (s2)) =3D=3D 0)
@@ -368,16 +368,22 @@
 void
 ktrsysret(ktr)
        struct ktr_sysret *ktr;
 {
+       const struct emulation *revelant;
        register_t ret =3D ktr->ktr_retval;
        int error =3D ktr->ktr_error;
        int code =3D ktr->ktr_code;
=20
-       if (code >=3D current->nsysnames || code < 0)
-               (void)printf("[%d] ", code);
+       if (emul_changed)
+               revelant =3D last;
        else
-               (void)printf("%s ", current->sysnames[code]);
+               revelant =3D current;
+
+       if (code >=3D revelant->nsysnames || code < 0)
+               (void)printf("[%d] ", code);
+       else=20
+               (void)printf("%s ", revelant->sysnames[code]);
=20
        switch (error) {
        case 0:
                if (fancy) {
@@ -397,8 +403,9 @@
                break;
        }
        (void)putchar('\n');
=20
+       emul_changed =3D 0;
 }
=20
 /*
  * We print the original emulation's error numerically, but we
@@ -407,42 +414,50 @@
 void
 eprint(e)
        int e;
 {
+       const struct emulation *revelant;
        int i =3D e;
=20
-       if (current->errnomap) {
+       if (emul_changed)=20
+               revelant =3D last;
+       else
+               revelant =3D current;
+
+       if (revelant->errnomap) {
=20
                /* No remapping for ERESTART and EJUSTRETURN */
                /* Kludge for linux that has negative error numbers */
-               if (current->errnomap[2] > 0 && e < 0)
+               if (revelant->errnomap[2] > 0 && e < 0)
                        goto normal;
=20
-               for (i =3D 0; i < current->nerrnomap; i++)
-                       if (e =3D=3D current->errnomap[i])
+               for (i =3D 0; i < revelant->nerrnomap; i++)
+                       if (e =3D=3D revelant->errnomap[i])
                                break;
=20
-               if (i =3D=3D current->nerrnomap) {
+               if (i =3D=3D revelant->nerrnomap) {
                        printf("-1 unknown errno %d", e);
                        return;
                }
        }
=20
 normal:
-       switch (i) {
-       case ERESTART:
+       if (i =3D=3D ERESTART) {
                (void)printf("RESTART");
-               break;
+               goto out;
+       }
=20
-       case EJUSTRETURN:
+       if (i =3D=3D revelant->justreturn) {
                (void)printf("JUSTRETURN");
-               break;
-
-       default:
-               (void)printf("-1 errno %d", e);
-               if (fancy)
-                       (void)printf(" %s", strerror(i));
+               goto out;
        }
+
+       (void)printf("-1 errno %d", e);
+       if (fancy)
+               (void)printf(" %s", strerror(i));
+
+out:
+       return;
 }
=20
 void
 ktrnamei(cp, len)
@@ -462,8 +477,9 @@
                len =3D bufsize - 1;
=20
        name[len] =3D '\0';
        setemul(name, ktr_header.ktr_pid, 1);
+       emul_changed =3D 1;
=20
        (void)printf("\"%s\"\n", name);
 }
=20
Index: usr.bin/kdump/setemul.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /cvsroot/basesrc/usr.bin/kdump/setemul.c,v
retrieving revision 1.5
diff -U4 -r1.5 setemul.c
--- usr.bin/kdump/setemul.c     2000/11/13 21:38:48     1.5
+++ usr.bin/kdump/setemul.c     2001/01/31 22:59:54
@@ -76,9 +76,11 @@
 __RCSID("$NetBSD: setemul.c,v 1.5 2000/11/13 21:38:48 jdolecek Exp $");
 #endif /* not lint */
=20
 #include <sys/param.h>
+#define _KERNEL
 #include <sys/errno.h>
+#undef _KERNEL
 #include <sys/time.h>
=20
 #include <err.h>
 #include <stdio.h>
@@ -123,29 +125,29 @@
 #define NELEM(a) (sizeof(a) / sizeof(a[0]))
=20
 static const struct emulation emulations[] =3D {
        {   "netbsd",          syscallnames,         SYS_MAXSYSCALL,
-               NULL,                   0 },
+               NULL,                   0,
EJUSTRETURN },
        {   "netbsd32", netbsd32_syscallnames,       SYS_MAXSYSCALL,
-               NULL,                   0 },
+               NULL,                   0,
EJUSTRETURN },
        {  "freebsd",  freebsd_syscallnames, FREEBSD_SYS_MAXSYSCALL,
-               NULL,                   0 },
+               NULL,                   0,
EJUSTRETURN },
        {     "hpux",     hpux_syscallnames,    HPUX_SYS_MAXSYSCALL,
-         native_to_hpux_errno,  NELEM(native_to_hpux_errno)  },
+         native_to_hpux_errno,  NELEM(native_to_hpux_errno),
EJUSTRET
URN },
        {    "ibcs2",    ibcs2_syscallnames,   IBCS2_SYS_MAXSYSCALL,
-        native_to_ibcs2_errno,  NELEM(native_to_ibcs2_errno) },
+        native_to_ibcs2_errno,  NELEM(native_to_ibcs2_errno),
EJUSTRETURN },
        {    "linux",    linux_syscallnames,   LINUX_SYS_MAXSYSCALL,
-        native_to_linux_errno,  NELEM(native_to_linux_errno) },
+        native_to_linux_errno,  NELEM(native_to_linux_errno),
LINUX_EJUSTRETUR
N },
        {     "osf1",     osf1_syscallnames,    OSF1_SYS_MAXSYSCALL,
-               NULL,                   0 },
+               NULL,                   0,
EJUSTRETURN },
        {    "sunos",    sunos_syscallnames,   SUNOS_SYS_MAXSYSCALL,
-               NULL,                   0 },
+               NULL,                   0,
EJUSTRETURN },
        {     "svr4",     svr4_syscallnames,    SVR4_SYS_MAXSYSCALL,
-         native_to_svr4_errno,  NELEM(native_to_svr4_errno)  },
+         native_to_svr4_errno,  NELEM(native_to_svr4_errno),
EJUSTRET
URN  },
        {   "ultrix",   ultrix_syscallnames,  ULTRIX_SYS_MAXSYSCALL,
-               NULL,                   0 },
+               NULL,                   0,
EJUSTRETURN },
        {   "pecoff",          syscallnames,         SYS_MAXSYSCALL,
-               NULL,                   0 },
+               NULL,                   0,
EJUSTRETURN },
        {       NULL,                  NULL,                      0,
                NULL,                   0 }
 };
=20
@@ -154,9 +156,12 @@
        const struct emulation *emulation;
        struct emulation_ctx *next;
 };
=20
-const struct emulation *current;
+/* Current emulation */
+const struct emulation *current =3D NULL;
+/* Previous emulation */
+const struct emulation *last;
=20
 static const struct emulation *default_emul=3DNULL;
=20
 struct emulation_ctx *current_ctx;
@@ -191,8 +196,13 @@
=20
        if (!default_emul)
                default_emul =3D match;
=20
+       if (current)=20
+               last =3D current;=20
+       else
+               last =3D match;
+
        current =3D match;
 }
=20
 /*
@@ -259,5 +269,6 @@
        else if (default_emul)
                current =3D default_emul;
        else
                current =3D &emulations[0]; /* NetBSD */
+      =20
 }
Index: usr.bin/kdump/setemul.h
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /cvsroot/basesrc/usr.bin/kdump/setemul.h,v
retrieving revision 1.4
diff -U4 -r1.4 setemul.h
--- usr.bin/kdump/setemul.h     2001/01/19 14:14:03     1.4
+++ usr.bin/kdump/setemul.h     2001/01/31 22:59:54
@@ -78,11 +78,13 @@
        const char * const *sysnames;   /* Array of system call names */
        int  nsysnames;         /* Number of */
        const int  *errnomap;   /* Array of error number mapping */
        int  nerrnomap;         /* number of elements in array */
+       int  justreturn;                /* error code for JUSTRETURN */
 };
=20
 extern const struct emulation *current;
+extern const struct emulation *last;
=20
 void setemul __P((const char *, pid_t, int));
 void ectx_sanify __P((pid_t));
=20
Index: sys/compat/linux/arch//alpha/linux_errno.h
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /cvsroot/syssrc/sys/compat/linux/arch/alpha/linux_errno.h,v
retrieving revision 1.1
diff -U4 -r1.1 linux_errno.h
--- sys/compat/linux/arch//alpha/linux_errno.h  1998/09/30 21:36:23
1.1
+++ sys/compat/linux/arch//alpha/linux_errno.h  2001/01/31 23:00:04
@@ -147,5 +147,7 @@
=20
 #define LINUX_ENOMEDIUM                129     /* No medium found */
 #define LINUX_EMEDIUMTYPE      130     /* Wrong medium type */
=20
+#define LINUX_EJUSTRETURN   2
+
 #endif /* !_ALPHA_LINUX_ERRNO_H */
Index: sys/compat/linux/arch//i386/linux_errno.h
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /cvsroot/syssrc/sys/compat/linux/arch/i386/linux_errno.h,v
retrieving revision 1.5
diff -U4 -r1.5 linux_errno.h
--- sys/compat/linux/arch//i386/linux_errno.h   2001/01/18 18:41:20
1.5
+++ sys/compat/linux/arch//i386/linux_errno.h   2001/01/31 23:00:05
@@ -127,5 +127,7 @@
 #define LINUX_EISNAM           120
 #define LINUX_EREMOTEIO                121
 #define LINUX_EDQUOT           122
=20
+#define LINUX_EJUSTRETURN   2
+
 #endif /* !_I386_LINUX_ERRNO_H */
Index: sys/compat/linux/arch//m68k/linux_errno.h
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /cvsroot/syssrc/sys/compat/linux/arch/m68k/linux_errno.h,v
retrieving revision 1.1
diff -U4 -r1.1 linux_errno.h
--- sys/compat/linux/arch//m68k/linux_errno.h   1998/12/15 19:25:40
1.1
+++ sys/compat/linux/arch//m68k/linux_errno.h   2001/01/31 23:00:05
@@ -130,5 +130,7 @@
 #define LINUX_EDQUOT           122
 #define        LINUX_ENOMEDIUM         123
 #define        LINUX_EMEDIUMTYPE       124
=20
+#define LINUX_EJUSTRETURN   2
+
 #endif /* !_M68K_LINUX_ERRNO_H */
Index: sys/compat/linux/arch//powerpc/linux_errno.h
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /cvsroot/syssrc/sys/compat/linux/arch/powerpc/linux_errno.h,v
retrieving revision 1.1
diff -U4 -r1.1 linux_errno.h
--- sys/compat/linux/arch//powerpc/linux_errno.h        2001/01/19
12:27:13    =20
1.1
+++ sys/compat/linux/arch//powerpc/linux_errno.h        2001/01/31
23:00:05
@@ -134,5 +134,7 @@
 #define LINUX_EDQUOT                   122    =20
 #define LINUX_ENOMEDIUM                123    =20
 #define LINUX_EMEDIUMTYPE      124    =20
=20
+#define LINUX_EJUSTRETURN      2
+
 #endif /* !_POWERPC_LINUX_ERRNO_H */

--=20
Emmanuel Dreyfus. En tant que serveur, Windows NT fait en moins bien=20
ce que UNIX fait depuis des ann=E9es avec une interface utilisateur=20
que seul un utilisateur d'UNIX est capable d'admirer.
p99dreyf@criens.u-psud.fr