Re: svn commit: r346410 - in head: lib/libc/gen share/man/man9 sys/conf sys/libkern sys/sys

2019-09-03 Thread O. Hartmann
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA256

Am Fri, 19 Apr 2019 20:05:48 + (UTC)
Conrad Meyer  schrieb:

> Author: cem
> Date: Fri Apr 19 20:05:47 2019
> New Revision: 346410
> URL: https://svnweb.freebsd.org/changeset/base/346410
> 
> Log:
>   libkern: Bring in arc4random_uniform(9) from libc
>   
>   It is a useful arc4random wrapper in the kernel for much the same reasons as
>   in userspace.  Move the source to libkern (because kernel build is
>   restricted to sys/, but userspace can include any file it likes) and build
>   kernel and libc versions from the same source file.
>   
>   Copy the documentation from arc4random_uniform(3) to the section 9 page.
>   
>   While here, add missing arc4random_buf(9) symlink.
>   
>   Sponsored by:   Dell EMC Isilon
> 
> Added:
>   head/sys/libkern/arc4random_uniform.c
>  - copied, changed from r346409, head/lib/libc/gen/arc4random_uniform.c
> Deleted:
>   head/lib/libc/gen/arc4random_uniform.c
> Modified:
>   head/lib/libc/gen/Makefile.inc
>   head/share/man/man9/Makefile
>   head/share/man/man9/random.9
>   head/sys/conf/files
>   head/sys/sys/libkern.h
> 
> Modified: head/lib/libc/gen/Makefile.inc
> ==
> --- head/lib/libc/gen/Makefile.incFri Apr 19 19:45:19 2019
> (r346409)
> +++ head/lib/libc/gen/Makefile.incFri Apr 19 20:05:47 2019
> (r346410)
> @@ -3,6 +3,7 @@
>  
>  # machine-independent gen sources
>  .PATH: ${LIBC_SRCTOP}/${LIBC_ARCH}/gen ${LIBC_SRCTOP}/gen
> +.PATH: ${SRCTOP}/sys/libkern
>  
>  CONFS=   shells
>  
> 
> Modified: head/share/man/man9/Makefile
> ==
> --- head/share/man/man9/Makefile  Fri Apr 19 19:45:19 2019
> (r346409)
> +++ head/share/man/man9/Makefile  Fri Apr 19 20:05:47 2019
> (r346410)
> @@ -1668,6 +1668,8 @@ MLINKS+=psignal.9 gsignal.9 \
>   psignal.9 tdsignal.9
>  MLINKS+=random.9 arc4rand.9 \
>   random.9 arc4random.9 \
> + random.9 arc4random_buf.9 \
> + random.9 arc4random_uniform.9 \
>   random.9 is_random_seeded.9 \
>   random.9 read_random.9 \
>   random.9 read_random_uio.9 \
> 
> Modified: head/share/man/man9/random.9
> ==
> --- head/share/man/man9/random.9  Fri Apr 19 19:45:19 2019
> (r346409)
> +++ head/share/man/man9/random.9  Fri Apr 19 20:05:47 2019
> (r346410)
> @@ -26,7 +26,7 @@
>  .\"
>  .\" $FreeBSD$
>  .\" "
> -.Dd April 16, 2019
> +.Dd April 19, 2019
>  .Dt RANDOM 9
>  .Os
>  .Sh NAME
> @@ -45,6 +45,8 @@
>  .Fn arc4random "void"
>  .Ft void
>  .Fn arc4random_buf "void *ptr" "size_t len"
> +.Ft uint32_t
> +.Fn arc4random_uniform "uint32_t upper_bound"
>  .Ft void
>  .Fn arc4rand "void *ptr" "u_int length" "int reseed"
>  .Pp
> @@ -79,6 +81,15 @@ fills
>  with
>  .Fa len
>  bytes of random data.
> +.Pp
> +.Fn arc4random_uniform
> +will return a single 32-bit value, uniformly distributed but less than
> +.Fa upper_bound .
> +This is recommended over constructions like
> +.Dq Li arc4random() % upper_bound
> +as it avoids "modulo bias" when the upper bound is not a power of two.
> +In the worst case, this function may consume multiple iterations
> +to ensure uniformity.
>  .Pp
>  The
>  .Fn arc4rand
> 
> Modified: head/sys/conf/files
> ==
> --- head/sys/conf/files   Fri Apr 19 19:45:19 2019(r346409)
> +++ head/sys/conf/files   Fri Apr 19 20:05:47 2019(r346410)
> @@ -3985,6 +3985,7 @@ kgssapi/gsstest.c   optional kgssapi_debug
>  # the file should be moved to conf/files. from here.
>  #
>  libkern/arc4random.c standard
> +libkern/arc4random_uniform.c standard
>  crypto/chacha20/chacha.c standard
>  libkern/asprintf.c   standard
>  libkern/bcd.cstandard
> 
> Copied and modified: head/sys/libkern/arc4random_uniform.c (from r346409,
> head/lib/libc/gen/arc4random_uniform.c)
> ==
>  ---
> head/lib/libc/gen/arc4random_uniform.cFri Apr 19 19:45:19 2019
> (r346409, copy
> source) +++ head/sys/libkern/arc4random_uniform.c Fri Apr 19 20:05:47 2019
> (r346410) @@ -19,7 +19,11 @@ */
>  
>  #include 
> +#ifdef _KERNEL
> +#include 
> +#else
>  #include 
> +#endif
>  
>  /*
>   * Calculate a uniformly distributed random number less than upper_bound
> 
> Modified: head/sys/sys/libkern.h
> ==
> --- head/sys/sys/libkern.hFri Apr 19 19:45:19 2019(r346409)
> +++ head/sys/sys/libkern.hFri Apr 19 20:05:47 2019(r346410)
> @@ -128,6 +128,7 @@ struct malloc_type;
>  uint32_t arc4random(void);
>  void  arc4random_buf(void *, size_t);
>  void  arc4rand(void 

Re: svn commit: r346410 - in head: lib/libc/gen share/man/man9 sys/conf sys/libkern sys/sys

2019-09-03 Thread Charlie Li via svn-src-all
O. Hartmann wrote:
> Am Fri, 19 Apr 2019 20:05:48 + (UTC) Conrad Meyer schrieb:
>> Modified: head/lib/libc/gen/Makefile.inc
>> ==
>> --- head/lib/libc/gen/Makefile.inc   Fri Apr 19 19:45:19 2019
>> (r346409)
>> +++ head/lib/libc/gen/Makefile.inc   Fri Apr 19 20:05:47 2019
>> (r346410)
>> @@ -3,6 +3,7 @@
> 
>>  # machine-independent gen sources
>>  .PATH: ${LIBC_SRCTOP}/${LIBC_ARCH}/gen ${LIBC_SRCTOP}/gen
>> +.PATH: ${SRCTOP}/sys/libkern
> 
>>  CONFS=  shells
> 
> 
> After applying r346410 to our source tree, buildworld fails (WITH_META_MODE 
> is set):
> 
> [...]
> Building /usr/obj/usr/src/amd64.amd64/lib/libc/ev_timers.o
> --- inet_ntoa.o ---
> In file included from /usr/src/sys/libkern/inet_ntoa.c:34:
> /usr/obj/usr/src/amd64.amd64/tmp/usr/include/sys/systm.h:172:8: error: 
> unknown type name 'bool'
> extern bool dynamic_kenv;
>^
> /usr/obj/usr/src/amd64.amd64/tmp/usr/include/sys/systm.h:211:5: warning: 
> declaration of
> built-in function 'setjmp' requires inclusion of the header 
> [-Wbuiltin-requires-header] int setjmp(struct _jmp_buf *) 
> __returns_twice; ^
> /usr/obj/usr/src/amd64.amd64/tmp/usr/include/sys/systm.h:212:6: warning: 
> declaration of
> built-in function 'longjmp' requires inclusion of the header 
> [-Wbuiltin-requires-header] voidlongjmp(struct _jmp_buf *, int) __dead2; ^
> /usr/obj/usr/src/amd64.amd64/tmp/usr/include/sys/systm.h:285:6: warning: 
> incompatible
> redeclaration of library function 'log' 
> [-Wincompatible-library-redeclaration] void
> log(int, const char *, ...) __printflike(2, 3); ^
> /usr/obj/usr/src/amd64.amd64/tmp/usr/include/sys/systm.h:285:6: note: 'log' 
> is a builtin with
> type 'double (double)' 
> /usr/obj/usr/src/amd64.amd64/tmp/usr/include/sys/systm.h:382:39: error:
> unknown type name 'uintfptr_t'; did you mean 'uintptr_t'? void
> profclock(int cnt, int
> usermode, uintfptr_t pc); ^
> /usr/obj/usr/src/amd64.amd64/tmp/usr/include/sys/_stdint.h:80:22: note: 
> 'uintptr_t' declared
> here typedef __uintptr_t uintptr_t;
> 
> 
> Is there an include missing?
> Beat me to the initial email. With the specific file change quoted
above, looks like inet_*.c are getting pulled from sys/libkern instead
of the proper lib/libc/inet.

-- 
Charlie Li
…nope, still don't have an exit line.

(This email address is for mailing list use; replace local-part with
vishwin for off-list communication if possible)



signature.asc
Description: OpenPGP digital signature


svn commit: r346410 - in head: lib/libc/gen share/man/man9 sys/conf sys/libkern sys/sys

2019-09-03 Thread Conrad Meyer
Author: cem
Date: Fri Apr 19 20:05:47 2019
New Revision: 346410
URL: https://svnweb.freebsd.org/changeset/base/346410

Log:
  libkern: Bring in arc4random_uniform(9) from libc
  
  It is a useful arc4random wrapper in the kernel for much the same reasons as
  in userspace.  Move the source to libkern (because kernel build is
  restricted to sys/, but userspace can include any file it likes) and build
  kernel and libc versions from the same source file.
  
  Copy the documentation from arc4random_uniform(3) to the section 9 page.
  
  While here, add missing arc4random_buf(9) symlink.
  
  Sponsored by: Dell EMC Isilon

Added:
  head/sys/libkern/arc4random_uniform.c
 - copied, changed from r346409, head/lib/libc/gen/arc4random_uniform.c
Deleted:
  head/lib/libc/gen/arc4random_uniform.c
Modified:
  head/lib/libc/gen/Makefile.inc
  head/share/man/man9/Makefile
  head/share/man/man9/random.9
  head/sys/conf/files
  head/sys/sys/libkern.h

Modified: head/lib/libc/gen/Makefile.inc
==
--- head/lib/libc/gen/Makefile.inc  Fri Apr 19 19:45:19 2019
(r346409)
+++ head/lib/libc/gen/Makefile.inc  Fri Apr 19 20:05:47 2019
(r346410)
@@ -3,6 +3,7 @@
 
 # machine-independent gen sources
 .PATH: ${LIBC_SRCTOP}/${LIBC_ARCH}/gen ${LIBC_SRCTOP}/gen
+.PATH: ${SRCTOP}/sys/libkern
 
 CONFS= shells
 

Modified: head/share/man/man9/Makefile
==
--- head/share/man/man9/MakefileFri Apr 19 19:45:19 2019
(r346409)
+++ head/share/man/man9/MakefileFri Apr 19 20:05:47 2019
(r346410)
@@ -1668,6 +1668,8 @@ MLINKS+=psignal.9 gsignal.9 \
psignal.9 tdsignal.9
 MLINKS+=random.9 arc4rand.9 \
random.9 arc4random.9 \
+   random.9 arc4random_buf.9 \
+   random.9 arc4random_uniform.9 \
random.9 is_random_seeded.9 \
random.9 read_random.9 \
random.9 read_random_uio.9 \

Modified: head/share/man/man9/random.9
==
--- head/share/man/man9/random.9Fri Apr 19 19:45:19 2019
(r346409)
+++ head/share/man/man9/random.9Fri Apr 19 20:05:47 2019
(r346410)
@@ -26,7 +26,7 @@
 .\"
 .\" $FreeBSD$
 .\" "
-.Dd April 16, 2019
+.Dd April 19, 2019
 .Dt RANDOM 9
 .Os
 .Sh NAME
@@ -45,6 +45,8 @@
 .Fn arc4random "void"
 .Ft void
 .Fn arc4random_buf "void *ptr" "size_t len"
+.Ft uint32_t
+.Fn arc4random_uniform "uint32_t upper_bound"
 .Ft void
 .Fn arc4rand "void *ptr" "u_int length" "int reseed"
 .Pp
@@ -79,6 +81,15 @@ fills
 with
 .Fa len
 bytes of random data.
+.Pp
+.Fn arc4random_uniform
+will return a single 32-bit value, uniformly distributed but less than
+.Fa upper_bound .
+This is recommended over constructions like
+.Dq Li arc4random() % upper_bound
+as it avoids "modulo bias" when the upper bound is not a power of two.
+In the worst case, this function may consume multiple iterations
+to ensure uniformity.
 .Pp
 The
 .Fn arc4rand

Modified: head/sys/conf/files
==
--- head/sys/conf/files Fri Apr 19 19:45:19 2019(r346409)
+++ head/sys/conf/files Fri Apr 19 20:05:47 2019(r346410)
@@ -3985,6 +3985,7 @@ kgssapi/gsstest.c optional kgssapi_debug
 # the file should be moved to conf/files. from here.
 #
 libkern/arc4random.c   standard
+libkern/arc4random_uniform.c   standard
 crypto/chacha20/chacha.c   standard
 libkern/asprintf.c standard
 libkern/bcd.c  standard

Copied and modified: head/sys/libkern/arc4random_uniform.c (from r346409, 
head/lib/libc/gen/arc4random_uniform.c)
==
--- head/lib/libc/gen/arc4random_uniform.c  Fri Apr 19 19:45:19 2019
(r346409, copy source)
+++ head/sys/libkern/arc4random_uniform.c   Fri Apr 19 20:05:47 2019
(r346410)
@@ -19,7 +19,11 @@
  */
 
 #include 
+#ifdef _KERNEL
+#include 
+#else
 #include 
+#endif
 
 /*
  * Calculate a uniformly distributed random number less than upper_bound

Modified: head/sys/sys/libkern.h
==
--- head/sys/sys/libkern.h  Fri Apr 19 19:45:19 2019(r346409)
+++ head/sys/sys/libkern.h  Fri Apr 19 20:05:47 2019(r346410)
@@ -128,6 +128,7 @@ struct malloc_type;
 uint32_t arc4random(void);
 voidarc4random_buf(void *, size_t);
 voidarc4rand(void *, u_int, int);
+uint32_t arc4random_uniform(uint32_t);
 int timingsafe_bcmp(const void *, const void *, size_t);
 void   *bsearch(const void *, const void *, size_t,
size_t, int (*)(const void *, const void *));


___
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To 

Re: svn commit: r346410 - in head: lib/libc/gen share/man/man9 sys/conf sys/libkern sys/sys

2019-04-19 Thread Charlie Li via svn-src-all
O. Hartmann wrote:
> Am Fri, 19 Apr 2019 20:05:48 + (UTC) Conrad Meyer schrieb:
>> Modified: head/lib/libc/gen/Makefile.inc
>> ==
>> --- head/lib/libc/gen/Makefile.inc   Fri Apr 19 19:45:19 2019
>> (r346409)
>> +++ head/lib/libc/gen/Makefile.inc   Fri Apr 19 20:05:47 2019
>> (r346410)
>> @@ -3,6 +3,7 @@
> 
>>  # machine-independent gen sources
>>  .PATH: ${LIBC_SRCTOP}/${LIBC_ARCH}/gen ${LIBC_SRCTOP}/gen
>> +.PATH: ${SRCTOP}/sys/libkern
> 
>>  CONFS=  shells
> 
> 
> After applying r346410 to our source tree, buildworld fails (WITH_META_MODE 
> is set):
> 
> [...]
> Building /usr/obj/usr/src/amd64.amd64/lib/libc/ev_timers.o
> --- inet_ntoa.o ---
> In file included from /usr/src/sys/libkern/inet_ntoa.c:34:
> /usr/obj/usr/src/amd64.amd64/tmp/usr/include/sys/systm.h:172:8: error: 
> unknown type name 'bool'
> extern bool dynamic_kenv;
>^
> /usr/obj/usr/src/amd64.amd64/tmp/usr/include/sys/systm.h:211:5: warning: 
> declaration of
> built-in function 'setjmp' requires inclusion of the header 
> [-Wbuiltin-requires-header] int setjmp(struct _jmp_buf *) 
> __returns_twice; ^
> /usr/obj/usr/src/amd64.amd64/tmp/usr/include/sys/systm.h:212:6: warning: 
> declaration of
> built-in function 'longjmp' requires inclusion of the header 
> [-Wbuiltin-requires-header] voidlongjmp(struct _jmp_buf *, int) __dead2; ^
> /usr/obj/usr/src/amd64.amd64/tmp/usr/include/sys/systm.h:285:6: warning: 
> incompatible
> redeclaration of library function 'log' 
> [-Wincompatible-library-redeclaration] void
> log(int, const char *, ...) __printflike(2, 3); ^
> /usr/obj/usr/src/amd64.amd64/tmp/usr/include/sys/systm.h:285:6: note: 'log' 
> is a builtin with
> type 'double (double)' 
> /usr/obj/usr/src/amd64.amd64/tmp/usr/include/sys/systm.h:382:39: error:
> unknown type name 'uintfptr_t'; did you mean 'uintptr_t'? void
> profclock(int cnt, int
> usermode, uintfptr_t pc); ^
> /usr/obj/usr/src/amd64.amd64/tmp/usr/include/sys/_stdint.h:80:22: note: 
> 'uintptr_t' declared
> here typedef __uintptr_t uintptr_t;
> 
> 
> Is there an include missing?
> Beat me to the initial email. With the specific file change quoted
above, looks like inet_*.c are getting pulled from sys/libkern instead
of the proper lib/libc/inet.

-- 
Charlie Li
…nope, still don't have an exit line.

(This email address is for mailing list use; replace local-part with
vishwin for off-list communication if possible)



signature.asc
Description: OpenPGP digital signature


Re: svn commit: r346410 - in head: lib/libc/gen share/man/man9 sys/conf sys/libkern sys/sys

2019-04-19 Thread O. Hartmann
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA256

Am Fri, 19 Apr 2019 20:05:48 + (UTC)
Conrad Meyer  schrieb:

> Author: cem
> Date: Fri Apr 19 20:05:47 2019
> New Revision: 346410
> URL: https://svnweb.freebsd.org/changeset/base/346410
> 
> Log:
>   libkern: Bring in arc4random_uniform(9) from libc
>   
>   It is a useful arc4random wrapper in the kernel for much the same reasons as
>   in userspace.  Move the source to libkern (because kernel build is
>   restricted to sys/, but userspace can include any file it likes) and build
>   kernel and libc versions from the same source file.
>   
>   Copy the documentation from arc4random_uniform(3) to the section 9 page.
>   
>   While here, add missing arc4random_buf(9) symlink.
>   
>   Sponsored by:   Dell EMC Isilon
> 
> Added:
>   head/sys/libkern/arc4random_uniform.c
>  - copied, changed from r346409, head/lib/libc/gen/arc4random_uniform.c
> Deleted:
>   head/lib/libc/gen/arc4random_uniform.c
> Modified:
>   head/lib/libc/gen/Makefile.inc
>   head/share/man/man9/Makefile
>   head/share/man/man9/random.9
>   head/sys/conf/files
>   head/sys/sys/libkern.h
> 
> Modified: head/lib/libc/gen/Makefile.inc
> ==
> --- head/lib/libc/gen/Makefile.incFri Apr 19 19:45:19 2019
> (r346409)
> +++ head/lib/libc/gen/Makefile.incFri Apr 19 20:05:47 2019
> (r346410)
> @@ -3,6 +3,7 @@
>  
>  # machine-independent gen sources
>  .PATH: ${LIBC_SRCTOP}/${LIBC_ARCH}/gen ${LIBC_SRCTOP}/gen
> +.PATH: ${SRCTOP}/sys/libkern
>  
>  CONFS=   shells
>  
> 
> Modified: head/share/man/man9/Makefile
> ==
> --- head/share/man/man9/Makefile  Fri Apr 19 19:45:19 2019
> (r346409)
> +++ head/share/man/man9/Makefile  Fri Apr 19 20:05:47 2019
> (r346410)
> @@ -1668,6 +1668,8 @@ MLINKS+=psignal.9 gsignal.9 \
>   psignal.9 tdsignal.9
>  MLINKS+=random.9 arc4rand.9 \
>   random.9 arc4random.9 \
> + random.9 arc4random_buf.9 \
> + random.9 arc4random_uniform.9 \
>   random.9 is_random_seeded.9 \
>   random.9 read_random.9 \
>   random.9 read_random_uio.9 \
> 
> Modified: head/share/man/man9/random.9
> ==
> --- head/share/man/man9/random.9  Fri Apr 19 19:45:19 2019
> (r346409)
> +++ head/share/man/man9/random.9  Fri Apr 19 20:05:47 2019
> (r346410)
> @@ -26,7 +26,7 @@
>  .\"
>  .\" $FreeBSD$
>  .\" "
> -.Dd April 16, 2019
> +.Dd April 19, 2019
>  .Dt RANDOM 9
>  .Os
>  .Sh NAME
> @@ -45,6 +45,8 @@
>  .Fn arc4random "void"
>  .Ft void
>  .Fn arc4random_buf "void *ptr" "size_t len"
> +.Ft uint32_t
> +.Fn arc4random_uniform "uint32_t upper_bound"
>  .Ft void
>  .Fn arc4rand "void *ptr" "u_int length" "int reseed"
>  .Pp
> @@ -79,6 +81,15 @@ fills
>  with
>  .Fa len
>  bytes of random data.
> +.Pp
> +.Fn arc4random_uniform
> +will return a single 32-bit value, uniformly distributed but less than
> +.Fa upper_bound .
> +This is recommended over constructions like
> +.Dq Li arc4random() % upper_bound
> +as it avoids "modulo bias" when the upper bound is not a power of two.
> +In the worst case, this function may consume multiple iterations
> +to ensure uniformity.
>  .Pp
>  The
>  .Fn arc4rand
> 
> Modified: head/sys/conf/files
> ==
> --- head/sys/conf/files   Fri Apr 19 19:45:19 2019(r346409)
> +++ head/sys/conf/files   Fri Apr 19 20:05:47 2019(r346410)
> @@ -3985,6 +3985,7 @@ kgssapi/gsstest.c   optional kgssapi_debug
>  # the file should be moved to conf/files. from here.
>  #
>  libkern/arc4random.c standard
> +libkern/arc4random_uniform.c standard
>  crypto/chacha20/chacha.c standard
>  libkern/asprintf.c   standard
>  libkern/bcd.cstandard
> 
> Copied and modified: head/sys/libkern/arc4random_uniform.c (from r346409,
> head/lib/libc/gen/arc4random_uniform.c)
> ==
>  ---
> head/lib/libc/gen/arc4random_uniform.cFri Apr 19 19:45:19 2019
> (r346409, copy
> source) +++ head/sys/libkern/arc4random_uniform.c Fri Apr 19 20:05:47 2019
> (r346410) @@ -19,7 +19,11 @@ */
>  
>  #include 
> +#ifdef _KERNEL
> +#include 
> +#else
>  #include 
> +#endif
>  
>  /*
>   * Calculate a uniformly distributed random number less than upper_bound
> 
> Modified: head/sys/sys/libkern.h
> ==
> --- head/sys/sys/libkern.hFri Apr 19 19:45:19 2019(r346409)
> +++ head/sys/sys/libkern.hFri Apr 19 20:05:47 2019(r346410)
> @@ -128,6 +128,7 @@ struct malloc_type;
>  uint32_t arc4random(void);
>  void  arc4random_buf(void *, size_t);
>  void  arc4rand(void 

svn commit: r346410 - in head: lib/libc/gen share/man/man9 sys/conf sys/libkern sys/sys

2019-04-19 Thread Conrad Meyer
Author: cem
Date: Fri Apr 19 20:05:47 2019
New Revision: 346410
URL: https://svnweb.freebsd.org/changeset/base/346410

Log:
  libkern: Bring in arc4random_uniform(9) from libc
  
  It is a useful arc4random wrapper in the kernel for much the same reasons as
  in userspace.  Move the source to libkern (because kernel build is
  restricted to sys/, but userspace can include any file it likes) and build
  kernel and libc versions from the same source file.
  
  Copy the documentation from arc4random_uniform(3) to the section 9 page.
  
  While here, add missing arc4random_buf(9) symlink.
  
  Sponsored by: Dell EMC Isilon

Added:
  head/sys/libkern/arc4random_uniform.c
 - copied, changed from r346409, head/lib/libc/gen/arc4random_uniform.c
Deleted:
  head/lib/libc/gen/arc4random_uniform.c
Modified:
  head/lib/libc/gen/Makefile.inc
  head/share/man/man9/Makefile
  head/share/man/man9/random.9
  head/sys/conf/files
  head/sys/sys/libkern.h

Modified: head/lib/libc/gen/Makefile.inc
==
--- head/lib/libc/gen/Makefile.inc  Fri Apr 19 19:45:19 2019
(r346409)
+++ head/lib/libc/gen/Makefile.inc  Fri Apr 19 20:05:47 2019
(r346410)
@@ -3,6 +3,7 @@
 
 # machine-independent gen sources
 .PATH: ${LIBC_SRCTOP}/${LIBC_ARCH}/gen ${LIBC_SRCTOP}/gen
+.PATH: ${SRCTOP}/sys/libkern
 
 CONFS= shells
 

Modified: head/share/man/man9/Makefile
==
--- head/share/man/man9/MakefileFri Apr 19 19:45:19 2019
(r346409)
+++ head/share/man/man9/MakefileFri Apr 19 20:05:47 2019
(r346410)
@@ -1668,6 +1668,8 @@ MLINKS+=psignal.9 gsignal.9 \
psignal.9 tdsignal.9
 MLINKS+=random.9 arc4rand.9 \
random.9 arc4random.9 \
+   random.9 arc4random_buf.9 \
+   random.9 arc4random_uniform.9 \
random.9 is_random_seeded.9 \
random.9 read_random.9 \
random.9 read_random_uio.9 \

Modified: head/share/man/man9/random.9
==
--- head/share/man/man9/random.9Fri Apr 19 19:45:19 2019
(r346409)
+++ head/share/man/man9/random.9Fri Apr 19 20:05:47 2019
(r346410)
@@ -26,7 +26,7 @@
 .\"
 .\" $FreeBSD$
 .\" "
-.Dd April 16, 2019
+.Dd April 19, 2019
 .Dt RANDOM 9
 .Os
 .Sh NAME
@@ -45,6 +45,8 @@
 .Fn arc4random "void"
 .Ft void
 .Fn arc4random_buf "void *ptr" "size_t len"
+.Ft uint32_t
+.Fn arc4random_uniform "uint32_t upper_bound"
 .Ft void
 .Fn arc4rand "void *ptr" "u_int length" "int reseed"
 .Pp
@@ -79,6 +81,15 @@ fills
 with
 .Fa len
 bytes of random data.
+.Pp
+.Fn arc4random_uniform
+will return a single 32-bit value, uniformly distributed but less than
+.Fa upper_bound .
+This is recommended over constructions like
+.Dq Li arc4random() % upper_bound
+as it avoids "modulo bias" when the upper bound is not a power of two.
+In the worst case, this function may consume multiple iterations
+to ensure uniformity.
 .Pp
 The
 .Fn arc4rand

Modified: head/sys/conf/files
==
--- head/sys/conf/files Fri Apr 19 19:45:19 2019(r346409)
+++ head/sys/conf/files Fri Apr 19 20:05:47 2019(r346410)
@@ -3985,6 +3985,7 @@ kgssapi/gsstest.c optional kgssapi_debug
 # the file should be moved to conf/files. from here.
 #
 libkern/arc4random.c   standard
+libkern/arc4random_uniform.c   standard
 crypto/chacha20/chacha.c   standard
 libkern/asprintf.c standard
 libkern/bcd.c  standard

Copied and modified: head/sys/libkern/arc4random_uniform.c (from r346409, 
head/lib/libc/gen/arc4random_uniform.c)
==
--- head/lib/libc/gen/arc4random_uniform.c  Fri Apr 19 19:45:19 2019
(r346409, copy source)
+++ head/sys/libkern/arc4random_uniform.c   Fri Apr 19 20:05:47 2019
(r346410)
@@ -19,7 +19,11 @@
  */
 
 #include 
+#ifdef _KERNEL
+#include 
+#else
 #include 
+#endif
 
 /*
  * Calculate a uniformly distributed random number less than upper_bound

Modified: head/sys/sys/libkern.h
==
--- head/sys/sys/libkern.h  Fri Apr 19 19:45:19 2019(r346409)
+++ head/sys/sys/libkern.h  Fri Apr 19 20:05:47 2019(r346410)
@@ -128,6 +128,7 @@ struct malloc_type;
 uint32_t arc4random(void);
 voidarc4random_buf(void *, size_t);
 voidarc4rand(void *, u_int, int);
+uint32_t arc4random_uniform(uint32_t);
 int timingsafe_bcmp(const void *, const void *, size_t);
 void   *bsearch(const void *, const void *, size_t,
size_t, int (*)(const void *, const void *));
___
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To