Date: Thu, 6 Feb 2020 08:36:52 -0800 From: Conrad Meyer <cem@freebsd.org> To: Pawel Biernacki <kaktus@freebsd.org> Cc: src-committers <src-committers@freebsd.org>, svn-src-all <svn-src-all@freebsd.org>, svn-src-head <svn-src-head@freebsd.org> Subject: Re: svn commit: r357614 - in head/sys: kern sys Message-ID: <CAG6CVpX4sL40Q=1d%2BCfydCbi20GzS21QJTNcpaoo3=YiSqkcVQ@mail.gmail.com> In-Reply-To: <202002061245.016CjwTi096374@repo.freebsd.org> References: <202002061245.016CjwTi096374@repo.freebsd.org>
next in thread | previous in thread | raw e-mail | index | archive | help
Hi Pawel, I don't think the (notyet) static assertion is quite right. On Thu, Feb 6, 2020 at 4:46 AM Pawel Biernacki <kaktus@freebsd.org> wrote: > > Author: kaktus > Date: Thu Feb 6 12:45:58 2020 > New Revision: 357614 > URL: https://svnweb.freebsd.org/changeset/base/357614 > > Log: > sysctl(9): add CTLFLAG_NEEDGIANT flag > ... > Modified: head/sys/sys/sysctl.h > ============================================================================== > --- head/sys/sys/sysctl.h Thu Feb 6 10:11:41 2020 (r357613) > +++ head/sys/sys/sysctl.h Thu Feb 6 12:45:58 2020 (r357614) > @@ -105,6 +105,13 @@ struct ctlname { > ... > + * One, and only one of CTLFLAG_MPSAFE or CTLFLAG_NEEDGIANT is required > + * for SYSCTL_PROC and SYSCTL_NODE. > ... > @@ -263,6 +270,14 @@ TAILQ_HEAD(sysctl_ctx_list, sysctl_ctx_entry); > #define __DESCR(d) "" > #endif > > +#ifdef notyet > +#define SYSCTL_ENFORCE_FLAGS(x) \ > + _Static_assert(((CTLFLAG_MPSAFE ^ CTLFLAG_NEEDGIANT) & (x)), \ > + "Has to be either CTLFLAG_MPSAFE or CTLFLAG_NEEDGIANT") The current (notyet) assertion checks for one or both flags being set, but you want to disallow both being set. The XOR operator here is meaningless; it is the same as OR for different bit flags. That would be something like: #define _CTLFLAG_MUTUALLY_EXCLUSIVE (CTLFLAG_MPSAFE | CTLFLAG_NEEDGIANT); #define SYSCTL_ENFORCE_FLAGS(x) do { \ _Static_assert(((x) & _CTLFLAG_MUTUALLY_EXCLUSIVE) != 0 && \ ((x) & _CTLFLAG_MUTUALLY_EXCLUSIVE) != _CTLFLAG_MUTUALLY_EXCLUSIVE, \ "Must set exactly one of CTLFLAG_MPSAFE, CTLFLAG_NEEDGIANT"); \ } while (0) Best, Conrad
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CAG6CVpX4sL40Q=1d%2BCfydCbi20GzS21QJTNcpaoo3=YiSqkcVQ>