Source-Changes-HG archive

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

[src/trunk]: src/usr.bin/fstat support printing rnd descriptor info



details:   https://anonhg.NetBSD.org/src/rev/a9fcbaec1f6f
branches:  trunk
changeset: 782891:a9fcbaec1f6f
user:      christos <christos%NetBSD.org@localhost>
date:      Sun Nov 25 15:30:28 2012 +0000

description:
support printing rnd descriptor info

diffstat:

 usr.bin/fstat/misc.c |  46 ++++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 42 insertions(+), 4 deletions(-)

diffs (102 lines):

diff -r 79f15729e1ac -r a9fcbaec1f6f usr.bin/fstat/misc.c
--- a/usr.bin/fstat/misc.c      Sun Nov 25 15:29:55 2012 +0000
+++ b/usr.bin/fstat/misc.c      Sun Nov 25 15:30:28 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: misc.c,v 1.10 2012/11/25 01:05:49 christos Exp $       */
+/*     $NetBSD: misc.c,v 1.11 2012/11/25 15:30:28 christos Exp $       */
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: misc.c,v 1.10 2012/11/25 01:05:49 christos Exp $");
+__RCSID("$NetBSD: misc.c,v 1.11 2012/11/25 15:30:28 christos Exp $");
 
 #define _KMEMUSER
 #include <stdbool.h>
@@ -50,6 +50,10 @@
 #include <sys/file.h>
 #define copyout_t int
 #include <sys/ksem.h>
+#define _LIB_LIBKERN_LIBKERN_H_
+#define mutex_enter(a)
+#define mutex_exit(a)
+#include <sys/cprng.h>
 #undef _KERNEL
 #include <sys/vnode.h>
 #include <sys/mount.h>
@@ -57,6 +61,7 @@
 #include <net/bpfdesc.h>
 
 #include <err.h>
+#include <util.h>
 #include <string.h>
 #include <kvm.h>
 #include "fstat.h"
@@ -96,7 +101,9 @@
     { .n_name = "vnops" },
 #define NL_XENEVT      16
     { .n_name = "xenevt_fileops" },
-#define NL_MAX         17
+#define NL_RND         17
+    { .n_name = "rnd_fileops" },
+#define NL_MAX         18
     { .n_name = NULL }
 };
 
@@ -189,6 +196,35 @@
        return 0;
 }
 
+static int
+p_rnd(struct file *f)
+{
+       rp_ctx_t rp;
+
+       if (!KVM_READ(f->f_data, &rp, sizeof(rp))) {
+               dprintf("can't read rnd at %p for pid %d", f->f_data, Pid);
+               return 0;
+       }
+       (void)printf("* rnd ");
+       if (rp.hard)
+               printf("bytesonkey=%d, ", rp.bytesonkey);
+       if (rp.cprng) {
+               cprng_strong_t cprng;
+               if (!KVM_READ(rp.cprng, &cprng, sizeof(cprng))) {
+                       dprintf("can't read rnd cprng at %p for pid %d",
+                           rp.cprng, Pid);
+               } else {
+                       char buf[128];
+                       snprintb(buf, sizeof(buf), CPRNG_FMT, cprng.flags);
+                       (void)printf("name=%s, serial=%d%s, flags=%s\n",
+                           cprng.name, cprng.entropy_serial,
+                           cprng.reseed_pending ?  ", reseed" : "", buf);
+                       return 0;
+               }
+       }
+       printf("\n");
+       return 0;
+}
 int
 pmisc(struct file *f, const char *name)
 {
@@ -222,6 +258,8 @@
                return p_kqueue(f);
        case NL_SEM:
                return p_sem(f);
+       case NL_RND:
+               return p_rnd(f);
        case NL_TAP:
                printf("* tap %lu\n", (unsigned long)(intptr_t)f->f_data);
                return 0;
@@ -229,7 +267,7 @@
                printf("* crypto %p\n", f->f_data);
                return 0;
        case NL_MAX:
-               printf("* %s %p\n", name, f->f_data);
+               printf("* %s ops=%p %p\n", name, f->f_ops, f->f_data);
                return 0;
        default:
                printf("* %s %p\n", nl[i].n_name, f->f_data);



Home | Main Index | Thread Index | Old Index