Module Name:    src
Committed By:   pooka
Date:           Thu Apr 30 16:59:32 UTC 2009

Modified Files:
        src/sys/rump/librump/rumpkern: rump.c

Log Message:
Stir up the stack a bit to help arc4random() decide on a more
"random" seed.  This is a quick hack, I'll play games with rnd(9)
later (no nethack).


To generate a diff of this commit:
cvs rdiff -u -r1.104 -r1.105 src/sys/rump/librump/rumpkern/rump.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/rump/librump/rumpkern/rump.c
diff -u src/sys/rump/librump/rumpkern/rump.c:1.104 src/sys/rump/librump/rumpkern/rump.c:1.105
--- src/sys/rump/librump/rumpkern/rump.c:1.104	Wed Apr 29 17:51:47 2009
+++ src/sys/rump/librump/rumpkern/rump.c	Thu Apr 30 16:59:32 2009
@@ -1,4 +1,4 @@
-/*	$NetBSD: rump.c,v 1.104 2009/04/29 17:51:47 pooka Exp $	*/
+/*	$NetBSD: rump.c,v 1.105 2009/04/30 16:59:32 pooka Exp $	*/
 
 /*
  * Copyright (c) 2007 Antti Kantee.  All Rights Reserved.
@@ -28,7 +28,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: rump.c,v 1.104 2009/04/29 17:51:47 pooka Exp $");
+__KERNEL_RCSID(0, "$NetBSD: rump.c,v 1.105 2009/04/30 16:59:32 pooka Exp $");
 
 #include <sys/param.h>
 #include <sys/atomic.h>
@@ -140,6 +140,28 @@
 rump_proc_vfs_init_fn rump_proc_vfs_init = pvfsinit_nop;
 rump_proc_vfs_release_fn rump_proc_vfs_release = pvfsrele_nop;
 
+/*
+ * Stir up the stack a bit.  These are exported functions to help
+ * convince the compiler that we don't want these routines completely
+ * optimized out or inlined.  Is there an easier way to do this?
+ */
+void nullfn(uint32_t *);
+void nullfn(uint32_t *arg){}
+void messthestack(void);
+void
+messthestack(void)
+{
+	uint32_t mess[64];
+	uint64_t d1, d2;
+	int i, error;
+
+	for (i = 0; i < 64; i++) {
+		rumpuser_gettime(&d1, &d2, &error);
+		mess[i] = d2;
+	}
+	nullfn(mess);
+}
+
 int
 rump__init(int rump_version)
 {
@@ -153,6 +175,14 @@
 		return 0;
 	rump_inited = 1;
 
+	/*
+	 * Seed arc4random() with a "reasonable" amount of randomness.
+	 * Yes, this is a quick kludge which depends on the arc4random
+	 * implementation.
+	 */
+	messthestack();
+	arc4random();
+
 	if (rump_version != RUMP_VERSION) {
 		printf("rump version mismatch, %d vs. %d\n",
 		    rump_version, RUMP_VERSION);

Reply via email to