Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/kdump Decode futex op codes.



details:   https://anonhg.NetBSD.org/src/rev/97ea4fa70b64
branches:  trunk
changeset: 971642:97ea4fa70b64
user:      thorpej <thorpej%NetBSD.org@localhost>
date:      Thu Apr 30 12:17:01 2020 +0000

description:
Decode futex op codes.

diffstat:

 usr.bin/kdump/kdump.c |  77 +++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 75 insertions(+), 2 deletions(-)

diffs (112 lines):

diff -r ed87cbe57e33 -r 97ea4fa70b64 usr.bin/kdump/kdump.c
--- a/usr.bin/kdump/kdump.c     Thu Apr 30 12:13:39 2020 +0000
+++ b/usr.bin/kdump/kdump.c     Thu Apr 30 12:17:01 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: kdump.c,v 1.137 2020/04/20 00:35:41 christos Exp $     */
+/*     $NetBSD: kdump.c,v 1.138 2020/04/30 12:17:01 thorpej Exp $      */
 
 /*-
  * Copyright (c) 1988, 1993
@@ -39,7 +39,7 @@
 #if 0
 static char sccsid[] = "@(#)kdump.c    8.4 (Berkeley) 4/28/95";
 #else
-__RCSID("$NetBSD: kdump.c,v 1.137 2020/04/20 00:35:41 christos Exp $");
+__RCSID("$NetBSD: kdump.c,v 1.138 2020/04/30 12:17:01 thorpej Exp $");
 #endif
 #endif /* not lint */
 
@@ -55,6 +55,7 @@
 #include <sys/ioctl.h>
 #include <sys/ptrace.h>
 #include <sys/socket.h>
+#include <sys/futex.h>
 
 #include <ctype.h>
 #include <err.h>
@@ -629,6 +630,59 @@
        }
 }
 
+static const char *
+futex_op_name(u_long op)
+{
+#define        FUTEXCASE(a)    case a: return # a
+       switch (op & FUTEX_CMD_MASK) {
+       FUTEXCASE(FUTEX_WAIT);
+       FUTEXCASE(FUTEX_WAKE);
+       FUTEXCASE(FUTEX_FD);
+       FUTEXCASE(FUTEX_REQUEUE);
+       FUTEXCASE(FUTEX_CMP_REQUEUE);
+       FUTEXCASE(FUTEX_WAKE_OP);
+       FUTEXCASE(FUTEX_LOCK_PI);
+       FUTEXCASE(FUTEX_UNLOCK_PI);
+       FUTEXCASE(FUTEX_TRYLOCK_PI);
+       FUTEXCASE(FUTEX_WAIT_BITSET);
+       FUTEXCASE(FUTEX_WAKE_BITSET);
+       FUTEXCASE(FUTEX_WAIT_REQUEUE_PI);
+       FUTEXCASE(FUTEX_CMP_REQUEUE_PI);
+       default:
+               return NULL;
+       }
+#undef FUTEXCASE
+}
+
+static void
+futexput(u_long op)
+{
+       const char *opname = futex_op_name(op);
+       const char *s = "";
+
+       if (opname == NULL) {
+               printf("%#lx", op & FUTEX_CMD_MASK);
+       } else {
+               fputs(opname, stdout);
+       }
+       op &= ~FUTEX_CMD_MASK;
+
+       if (op & FUTEX_PRIVATE_FLAG) {
+               fputs("_PRIVATE", stdout);
+               op &= ~FUTEX_PRIVATE_FLAG;
+       }
+
+       if (op & FUTEX_CLOCK_REALTIME) {
+               printf("%sFUTEX_CLOCK_REALTIME", s);
+               op &= ~FUTEX_CLOCK_REALTIME;
+               s = "|";
+       }
+
+       if (op) {
+               printf("%s%#lx", s, op);
+       }
+}
+
 static void
 ktrsyscall(struct ktr_syscall *ktr)
 {
@@ -699,6 +753,25 @@
                        ap++;
                        argcount--;
                        c = ',';
+
+                       /*
+                        * Linux name is "futex".
+                        * Native name is "__futex".
+                        * Both have the same op argument.
+                        */
+               } else if ((strcmp(sys_name, "futex") == 0 ||
+                           strcmp(sys_name, "__futex") == 0) &&
+                          argcount > 2) {
+                       (void)putchar('(');
+                       output_long((long)*ap, 1);
+                       (void)putchar(',');
+                       ap++;
+                       argcount--;
+                       futexput(*ap);
+                       ap++;
+                       argcount--;
+                       c = ',';
+
                } else if ((strstr(sys_name, "sigaction") != NULL ||
                    strstr(sys_name, "sigvec") != NULL) && argcount >= 1) {
                        (void)printf("(SIG%s", signame(ap[0], 1));



Home | Main Index | Thread Index | Old Index