summaryrefslogtreecommitdiffstats
path: root/sys
diff options
context:
space:
mode:
Diffstat (limited to 'sys')
-rw-r--r--sys/amd64/amd64/mem.c20
-rw-r--r--sys/i386/i386/mem.c20
-rw-r--r--sys/i386/isa/random_machdep.c31
-rw-r--r--sys/kern/kern_random.c31
4 files changed, 96 insertions, 6 deletions
diff --git a/sys/amd64/amd64/mem.c b/sys/amd64/amd64/mem.c
index cddbca3..497ed8f 100644
--- a/sys/amd64/amd64/mem.c
+++ b/sys/amd64/amd64/mem.c
@@ -38,7 +38,7 @@
*
* from: Utah $Hdr: mem.c 1.13 89/10/08$
* from: @(#)mem.c 7.2 (Berkeley) 5/9/91
- * $Id: mem.c,v 1.36 1996/07/15 05:23:04 bde Exp $
+ * $Id: mem.c,v 1.37 1996/07/15 18:22:07 nate Exp $
*/
/*
@@ -80,12 +80,13 @@ static d_close_t mmclose;
static d_read_t mmrw;
static d_ioctl_t mmioctl;
static d_mmap_t memmmap;
+static d_select_t mmselect;
#define CDEV_MAJOR 2
static struct cdevsw mem_cdevsw =
{ mmopen, mmclose, mmrw, mmrw, /*2*/
mmioctl, nullstop, nullreset, nodevtotty,/* memory */
- seltrue, memmmap, NULL, "mem", NULL, -1 };
+ mmselect, memmmap, NULL, "mem", NULL, -1 };
static caddr_t zbuf;
@@ -474,6 +475,21 @@ mmioctl(dev, cmd, cmdarg, flags, p)
return (0);
}
+int
+mmselect(dev, rw, p)
+ dev_t dev;
+ int rw;
+ struct proc *p;
+{
+ switch (minor(dev)) {
+ case 3: /* /dev/random */
+ return random_select(dev, rw, p);
+ case 4: /* /dev/urandom */
+ default:
+ return seltrue(dev, rw, p);
+ }
+}
+
/*
* Routine that identifies /dev/mem and /dev/kmem.
*
diff --git a/sys/i386/i386/mem.c b/sys/i386/i386/mem.c
index cddbca3..497ed8f 100644
--- a/sys/i386/i386/mem.c
+++ b/sys/i386/i386/mem.c
@@ -38,7 +38,7 @@
*
* from: Utah $Hdr: mem.c 1.13 89/10/08$
* from: @(#)mem.c 7.2 (Berkeley) 5/9/91
- * $Id: mem.c,v 1.36 1996/07/15 05:23:04 bde Exp $
+ * $Id: mem.c,v 1.37 1996/07/15 18:22:07 nate Exp $
*/
/*
@@ -80,12 +80,13 @@ static d_close_t mmclose;
static d_read_t mmrw;
static d_ioctl_t mmioctl;
static d_mmap_t memmmap;
+static d_select_t mmselect;
#define CDEV_MAJOR 2
static struct cdevsw mem_cdevsw =
{ mmopen, mmclose, mmrw, mmrw, /*2*/
mmioctl, nullstop, nullreset, nodevtotty,/* memory */
- seltrue, memmmap, NULL, "mem", NULL, -1 };
+ mmselect, memmmap, NULL, "mem", NULL, -1 };
static caddr_t zbuf;
@@ -474,6 +475,21 @@ mmioctl(dev, cmd, cmdarg, flags, p)
return (0);
}
+int
+mmselect(dev, rw, p)
+ dev_t dev;
+ int rw;
+ struct proc *p;
+{
+ switch (minor(dev)) {
+ case 3: /* /dev/random */
+ return random_select(dev, rw, p);
+ case 4: /* /dev/urandom */
+ default:
+ return seltrue(dev, rw, p);
+ }
+}
+
/*
* Routine that identifies /dev/mem and /dev/kmem.
*
diff --git a/sys/i386/isa/random_machdep.c b/sys/i386/isa/random_machdep.c
index 7a6ea06..31b4563 100644
--- a/sys/i386/isa/random_machdep.c
+++ b/sys/i386/isa/random_machdep.c
@@ -1,7 +1,7 @@
/*
* random_machdep.c -- A strong random number generator
*
- * $Id: random_machdep.c,v 1.9 1996/06/17 16:47:43 bde Exp $
+ * $Id: random_machdep.c,v 1.10 1996/08/02 21:16:27 bde Exp $
*
* Version 0.95, last modified 18-Oct-95
*
@@ -44,6 +44,8 @@
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/kernel.h>
+#include <sys/select.h>
+#include <sys/fcntl.h>
#include <machine/clock.h>
#include <machine/random.h>
@@ -85,6 +87,7 @@ struct random_bucket {
u_int entropy_count;
int input_rotate;
u_int32_t *pool;
+ struct selinfo rsel;
};
/* There is one of these per entropy source */
@@ -118,6 +121,8 @@ rand_initialize(void)
random_state.entropy_count = 0;
random_state.pool = random_pool;
random_wait = NULL;
+ random_state.rsel.si_flags = 0;
+ random_state.rsel.si_pid = 0;
}
/*
@@ -225,6 +230,9 @@ add_timer_randomness(struct random_bucket *r, struct timer_rand_state *state,
/* Prevent overflow */
if (r->entropy_count > POOLBITS)
r->entropy_count = POOLBITS;
+
+ if (r->entropy_count >= 8)
+ selwakeup(&random_state.rsel);
}
void
@@ -479,3 +487,24 @@ write_random(const char *buf, u_int nbytes)
return nbytes;
}
#endif /* notused */
+
+int
+random_select(dev_t dev, int rw, struct proc *p)
+{
+ int s, ret;
+
+ if (rw == FWRITE)
+ return 1; /* heh. */
+
+ s = splhigh();
+ if (random_state.entropy_count >= 8)
+ ret = 1;
+ else {
+ selrecord(p, &random_state.rsel);
+ ret = 0;
+ }
+ splx(s);
+
+ return ret;
+}
+
diff --git a/sys/kern/kern_random.c b/sys/kern/kern_random.c
index 7a6ea06..31b4563 100644
--- a/sys/kern/kern_random.c
+++ b/sys/kern/kern_random.c
@@ -1,7 +1,7 @@
/*
* random_machdep.c -- A strong random number generator
*
- * $Id: random_machdep.c,v 1.9 1996/06/17 16:47:43 bde Exp $
+ * $Id: random_machdep.c,v 1.10 1996/08/02 21:16:27 bde Exp $
*
* Version 0.95, last modified 18-Oct-95
*
@@ -44,6 +44,8 @@
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/kernel.h>
+#include <sys/select.h>
+#include <sys/fcntl.h>
#include <machine/clock.h>
#include <machine/random.h>
@@ -85,6 +87,7 @@ struct random_bucket {
u_int entropy_count;
int input_rotate;
u_int32_t *pool;
+ struct selinfo rsel;
};
/* There is one of these per entropy source */
@@ -118,6 +121,8 @@ rand_initialize(void)
random_state.entropy_count = 0;
random_state.pool = random_pool;
random_wait = NULL;
+ random_state.rsel.si_flags = 0;
+ random_state.rsel.si_pid = 0;
}
/*
@@ -225,6 +230,9 @@ add_timer_randomness(struct random_bucket *r, struct timer_rand_state *state,
/* Prevent overflow */
if (r->entropy_count > POOLBITS)
r->entropy_count = POOLBITS;
+
+ if (r->entropy_count >= 8)
+ selwakeup(&random_state.rsel);
}
void
@@ -479,3 +487,24 @@ write_random(const char *buf, u_int nbytes)
return nbytes;
}
#endif /* notused */
+
+int
+random_select(dev_t dev, int rw, struct proc *p)
+{
+ int s, ret;
+
+ if (rw == FWRITE)
+ return 1; /* heh. */
+
+ s = splhigh();
+ if (random_state.entropy_count >= 8)
+ ret = 1;
+ else {
+ selrecord(p, &random_state.rsel);
+ ret = 0;
+ }
+ splx(s);
+
+ return ret;
+}
+
OpenPOWER on IntegriCloud