Print this page
8634 epoll fails to wake on certain edge-triggered conditions
8635 epoll should not emit POLLNVAL
8636 recursive epoll should emit EPOLLRDNORM
Reviewed by: Jerry Jelinek <jerry.jelinek@joyent.com>
Reviewed by: Robert Mustacchi <rm@joyent.com>
Reviewed by: Toomas Soome <tsoome@me.com>
Reviewed by: Igor Kozhukhov <igor@dilos.org>


   3  *
   4  * The contents of this file are subject to the terms of the
   5  * Common Development and Distribution License (the "License").
   6  * You may not use this file except in compliance with the License.
   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  *
  21  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
  22  * Use is subject to license terms.


  23  */
  24 
  25 
  26 /*
  27  * Random number generator pseudo-driver
  28  *
  29  * This is a lightweight driver which calls in to the Kernel Cryptographic
  30  * Framework to do the real work. Kernel modules should NOT depend on this
  31  * driver for /dev/random kernel API.
  32  *
  33  * Applications may ask for 2 types of random bits:
  34  * . High quality random by reading from /dev/random. The output is extracted
  35  *   only when a minimum amount of entropy is available.
  36  * . Pseudo-random, by reading from /dev/urandom, that can be generated any
  37  *   time.
  38  */
  39 
  40 #include <sys/types.h>
  41 #include <sys/errno.h>
  42 #include <sys/stat.h>


 312 /*
 313  * poll(2) is supported as follows:
 314  * . Only POLLIN, POLLOUT, and POLLRDNORM events are supported.
 315  * . POLLOUT always succeeds.
 316  * . POLLIN and POLLRDNORM from /dev/urandom always succeeds.
 317  * . POLLIN and POLLRDNORM from /dev/random will block until a
 318  *   minimum amount of entropy is available.
 319  */
 320 static int
 321 rnd_chpoll(dev_t dev, short events, int anyyet, short *reventsp,
 322     struct pollhead **phpp)
 323 {
 324         switch (getminor(dev)) {
 325         case DEVURANDOM:
 326                 *reventsp = events & (POLLOUT | POLLIN | POLLRDNORM);
 327 
 328                 /*
 329                  * A non NULL pollhead pointer should be returned in case
 330                  * user polls for 0 events.
 331                  */
 332                 if (*reventsp == 0 && !anyyet)
 333                         *phpp = &urnd_pollhd;
 334 
 335                 break;
 336         case DEVRANDOM:
 337                 kcf_rnd_chpoll(events, anyyet, reventsp, phpp);
 338                 break;
 339         default:
 340                 return (ENXIO);
 341         }
 342 
 343         return (0);
 344 }


   3  *
   4  * The contents of this file are subject to the terms of the
   5  * Common Development and Distribution License (the "License").
   6  * You may not use this file except in compliance with the License.
   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  *
  21  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
  22  * Use is subject to license terms.
  23  *
  24  * Copyright 2017 Joyent, Inc.
  25  */
  26 
  27 
  28 /*
  29  * Random number generator pseudo-driver
  30  *
  31  * This is a lightweight driver which calls in to the Kernel Cryptographic
  32  * Framework to do the real work. Kernel modules should NOT depend on this
  33  * driver for /dev/random kernel API.
  34  *
  35  * Applications may ask for 2 types of random bits:
  36  * . High quality random by reading from /dev/random. The output is extracted
  37  *   only when a minimum amount of entropy is available.
  38  * . Pseudo-random, by reading from /dev/urandom, that can be generated any
  39  *   time.
  40  */
  41 
  42 #include <sys/types.h>
  43 #include <sys/errno.h>
  44 #include <sys/stat.h>


 314 /*
 315  * poll(2) is supported as follows:
 316  * . Only POLLIN, POLLOUT, and POLLRDNORM events are supported.
 317  * . POLLOUT always succeeds.
 318  * . POLLIN and POLLRDNORM from /dev/urandom always succeeds.
 319  * . POLLIN and POLLRDNORM from /dev/random will block until a
 320  *   minimum amount of entropy is available.
 321  */
 322 static int
 323 rnd_chpoll(dev_t dev, short events, int anyyet, short *reventsp,
 324     struct pollhead **phpp)
 325 {
 326         switch (getminor(dev)) {
 327         case DEVURANDOM:
 328                 *reventsp = events & (POLLOUT | POLLIN | POLLRDNORM);
 329 
 330                 /*
 331                  * A non NULL pollhead pointer should be returned in case
 332                  * user polls for 0 events.
 333                  */
 334                 if ((*reventsp == 0 && !anyyet) || (events & POLLET))
 335                         *phpp = &urnd_pollhd;
 336 
 337                 break;
 338         case DEVRANDOM:
 339                 kcf_rnd_chpoll(events, anyyet, reventsp, phpp);
 340                 break;
 341         default:
 342                 return (ENXIO);
 343         }
 344 
 345         return (0);
 346 }