From owner-svn-src-head@freebsd.org Sat Oct 20 20:49:38 2018 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 4E86AFF54D2; Sat, 20 Oct 2018 20:49:38 +0000 (UTC) (envelope-from cem@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 050CF882AF; Sat, 20 Oct 2018 20:49:38 +0000 (UTC) (envelope-from cem@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id F41C323323; Sat, 20 Oct 2018 20:49:37 +0000 (UTC) (envelope-from cem@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id w9KKnbfk013919; Sat, 20 Oct 2018 20:49:37 GMT (envelope-from cem@FreeBSD.org) Received: (from cem@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w9KKnbW9013918; Sat, 20 Oct 2018 20:49:37 GMT (envelope-from cem@FreeBSD.org) Message-Id: <201810202049.w9KKnbW9013918@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: cem set sender to cem@FreeBSD.org using -f From: Conrad Meyer Date: Sat, 20 Oct 2018 20:49:37 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r339487 - head/sys/sys X-SVN-Group: head X-SVN-Commit-Author: cem X-SVN-Commit-Paths: head/sys/sys X-SVN-Commit-Revision: 339487 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 20 Oct 2018 20:49:38 -0000 Author: cem Date: Sat Oct 20 20:49:37 2018 New Revision: 339487 URL: https://svnweb.freebsd.org/changeset/base/339487 Log: random(4): Translate a comment requirement into a compile-time invariant In various places, random represents the set of sources as a 32-bit word bitmask. It assumes all sources fit within this, i.e., the maximum valid source number is 31. There was a comment specifying this limitation, but we can actually refuse to compile if our assumption is violated instead. We still have a few spare random source slots, but sooner or later someone may need to convert the masks used from raw 32-bit words to bitset(9) APIs. This prevents some kinds of developer foot-shooting when adding new random sources. No functional change. Reviewed by: delphij, markm Approved by: secteam (delphij) Sponsored by: Dell EMC Isilon Differential Revision: https://reviews.freebsd.org/D16982 Modified: head/sys/sys/random.h Modified: head/sys/sys/random.h ============================================================================== --- head/sys/sys/random.h Sat Oct 20 20:45:49 2018 (r339486) +++ head/sys/sys/random.h Sat Oct 20 20:49:37 2018 (r339487) @@ -57,9 +57,6 @@ read_random(void *a __unused, u_int b __unused) * Note: if you add or remove members of random_entropy_source, remember to * also update the strings in the static array random_source_descr[] in * random_harvestq.c. - * - * NOTE: complain loudly to markm@ or on the lists if this enum gets more than 32 - * distinct values (0-31)! ENTROPYSOURCE may be == 32, but not > 32. */ enum random_entropy_source { RANDOM_START = 0, @@ -92,6 +89,8 @@ enum random_entropy_source { RANDOM_PURE_DARN, ENTROPYSOURCE }; +_Static_assert(ENTROPYSOURCE <= 32, + "hardcoded assumption that values fit in a typical word-sized bitset"); #define RANDOM_HARVEST_EVERYTHING_MASK ((1 << (RANDOM_ENVIRONMENTAL_END + 1)) - 1) #define RANDOM_HARVEST_PURE_MASK (((1 << ENTROPYSOURCE) - 1) & (-1UL << RANDOM_PURE_START))