From bb25f0dd238cdc884f6d9da83cb6002ce1a46ab1 Mon Sep 17 00:00:00 2001 From: Bruce Evans Date: Tue, 2 Feb 1999 14:14:05 +0000 Subject: [PATCH] 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. --- sys/amd64/amd64/mem.c | 13 ++++++++++++- 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 1994f12ce53..725eaa1af11 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 #include #include +#include #include #include @@ -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 1994f12ce53..725eaa1af11 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 #include #include +#include #include #include @@ -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);