Print this page
9971 Make getrandom(2) a public interface

Split Close
Expand all
Collapse all
          --- old/usr/src/uts/common/syscall/getrandom.c
          +++ new/usr/src/uts/common/syscall/getrandom.c
↓ open down ↓ 2 lines elided ↑ open up ↑
   3    3   * Common Development and Distribution License ("CDDL"), version 1.0.
   4    4   * You may only use this file in accordance with the terms of version
   5    5   * 1.0 of the CDDL.
   6    6   *
   7    7   * A full copy of the text of the CDDL should have accompanied this
   8    8   * source.  A copy of the CDDL is also available via the Internet at
   9    9   * http://www.illumos.org/license/CDDL.
  10   10   */
  11   11  
  12   12  /*
  13      - * Copyright (c) 2015, Joyent, Inc.
       13 + * Copyright (c) 2018, Joyent, Inc.
  14   14   */
  15   15  
  16   16  /*
  17   17   * getrandom system call implementation
  18   18   */
  19   19  
  20   20  #include <sys/types.h>
  21   21  #include <sys/errno.h>
  22   22  #include <sys/systm.h>
  23   23  #include <sys/random.h>
↓ open down ↓ 5 lines elided ↑ open up ↑
  29   29  
  30   30  /*
  31   31   * Impose a maximum upper bound on the number of bytes that we'll read in one
  32   32   * go, ala a read of /dev/random. For /dev/urandom, we clamp it based on our
  33   33   * return value, because the system call returns an int, we can't handle more
  34   34   * than INT_MAX.
  35   35   */
  36   36  #define MAXRANDBYTES    1024
  37   37  #define MAXURANDBYTES   INT_MAX
  38   38  
  39      -int
  40      -getrandom(void *bufp, size_t buflen, int flags)
       39 +ssize_t
       40 +getrandom(void *bufp, size_t buflen, unsigned int flags)
  41   41  {
  42   42          int out = 0;
  43   43          uint8_t rbytes[128];
  44   44          uint8_t *buf = bufp;
  45   45  
  46   46          if (flags & ~(GRND_NONBLOCK | GRND_RANDOM))
  47   47                  return (set_errno(EINVAL));
  48   48  
  49   49          if ((flags & GRND_RANDOM) && buflen > MAXRANDBYTES) {
  50   50                  buflen = MAXRANDBYTES;
↓ open down ↓ 30 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX