diff options
author | bde <bde@FreeBSD.org> | 1999-02-02 14:14:05 +0000 |
---|---|---|
committer | bde <bde@FreeBSD.org> | 1999-02-02 14:14:05 +0000 |
commit | 78b0de3bf4da3d2f06a3acb35097a2b381f9e01c (patch) | |
tree | cf27bc2feeb131d283f8b7d07405ccc6394add1d | |
parent | 0fd52730c216aa70c9761b100b73f0ec0ffab6ea (diff) | |
download | FreeBSD-src-78b0de3bf4da3d2f06a3acb35097a2b381f9e01c.zip FreeBSD-src-78b0de3bf4da3d2f06a3acb35097a2b381f9e01c.tar.gz |
Check for signals while reading /dev/urandom. Reading 10MB from
/dev/urandom takes about 38 seconds on a P5/133. It is useful
to be able to kill such reads almost immediately. Processes
doing such reads are now scheduled so their denial of service
is no worse than that of processes looping in user mode.
-rw-r--r-- | sys/amd64/amd64/mem.c | 13 | ||||
-rw-r--r-- | sys/i386/i386/mem.c | 13 |
2 files changed, 24 insertions, 2 deletions
diff --git a/sys/amd64/amd64/mem.c b/sys/amd64/amd64/mem.c index 1994f12..725eaa1 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.52 1998/06/21 11:33:29 bde Exp $ + * $Id: mem.c,v 1.53 1998/11/08 12:39:01 dfr Exp $ */ /* @@ -59,6 +59,7 @@ #include <sys/uio.h> #include <sys/malloc.h> #include <sys/proc.h> +#include <sys/signalvar.h> #include <machine/frame.h> #include <machine/random.h> @@ -287,6 +288,16 @@ mmrw(dev, uio, flags) c = iov->iov_len; break; } + if (CURSIG(curproc) != 0) { + /* + * Use tsleep() to get the error code right. + * It should return immediately. + */ + error = tsleep(&random_softc[0], + PZERO | PCATCH, "urand", 1); + if (error != 0 && error != EWOULDBLOCK) + continue; + } if (buf == NULL) buf = (caddr_t) malloc(PAGE_SIZE, M_TEMP, M_WAITOK); diff --git a/sys/i386/i386/mem.c b/sys/i386/i386/mem.c index 1994f12..725eaa1 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.52 1998/06/21 11:33:29 bde Exp $ + * $Id: mem.c,v 1.53 1998/11/08 12:39:01 dfr Exp $ */ /* @@ -59,6 +59,7 @@ #include <sys/uio.h> #include <sys/malloc.h> #include <sys/proc.h> +#include <sys/signalvar.h> #include <machine/frame.h> #include <machine/random.h> @@ -287,6 +288,16 @@ mmrw(dev, uio, flags) c = iov->iov_len; break; } + if (CURSIG(curproc) != 0) { + /* + * Use tsleep() to get the error code right. + * It should return immediately. + */ + error = tsleep(&random_softc[0], + PZERO | PCATCH, "urand", 1); + if (error != 0 && error != EWOULDBLOCK) + continue; + } if (buf == NULL) buf = (caddr_t) malloc(PAGE_SIZE, M_TEMP, M_WAITOK); |