From nobody Sat Feb 17 21:32:51 2024 X-Original-To: dev-commits-src-branches@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4Tchq76VgMz59ktW; Sat, 17 Feb 2024 21:32:51 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Tchq74yfzz4h28; Sat, 17 Feb 2024 21:32:51 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1708205571; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=3B+T2IjkM8S52zwakMbq2JHZVByTwOTke3gjipUW040=; b=NRgYYz5LaqidCqoIm1uhq6pTwn41oENlLwTu50m8L0zyuLwd3kKb8+qzWnSzBydYgReiJo nqlvWsZRGdJNkhk96kWdick956s8RnwDjP+ceBNPexaEXdsQGLtCm7qGo46B3dHnwbwZSD pvkALUqDHklYR55l+X8QauSfIAJgAOUuDYvBVSAJAYrZR/4FtdXlBNTV5bCv4gfCJQVlaj +ZFjfA442sZvziIP9vQRHkdfAwmjS4U3F+T0wmQb0Fng6NMgWDCE8Dy+mTqFhrrDmC2afk 2nXmUYdwVX/a5CeK5Ve/z9MnI5YAe3tu8EseWOrKKJ6wn8TAeg/kkwlUeUPdeA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1708205571; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=3B+T2IjkM8S52zwakMbq2JHZVByTwOTke3gjipUW040=; b=erZ5oD8Svt5DT0uLjaxAi0Cx+jI2X4qpCwhXB8u9FHwhAuPpgRrk6jtb/A5C067OAkMOst J+JDdgaEW5Ro5k26HEy/TFbZ5MSH9UyUGiSxucjk3nU+Mgtlc7Fm0ohxceyzz/uzSeuc19 tNzzz5AJWo96RxBjcnA1ljiAuuxqyAe1YHpc7bK39TWLwZhsir9yQXRVtZZnO0C/45N9wE tyMByBKTWMOtGMtbVh+Q4Qyra47Uh2uiSwYp8ukF9xT+DkNFKVJnCIH6mFsyhWSJ5ki2Dq DzNcjv27shBuUFTFjJuGkJKHNLK/Ax8xd3zgaw886EtjxM8hZfaIXGq3Cj3Sng== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1708205571; a=rsa-sha256; cv=none; b=DT8BgRPLoCf3atUy46YI/9wAvWMc9SBmnulPP9PgILyh/xd5EFl3HJaj6SHSeNCEm5u8DC gamqsGEjLNLjBpR6NAceixQXDgnzxOwTgWH6+TMknoMBhsArfCEED7GCs5UIT2ER58mPUY aB8A+KDS9TgVa8pNugVk4/7z7ouk+1BMoh3OfOMSv6CGzNXH+qCzditauwuccN1BRM7eBC 7ijdVGLWAOsp3lFNxf1JIkApBrdHy2Vd8w5idWp2/FIDg/tiHtyrGCzI2xGTvGeERmLUGs w/68n214hTHlpEjX+ymdR+ywxUx/6+2o1UxPc2sxWWbfzEytB7I/J5k86JH6lQ== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4Tchq7421yzPMD; Sat, 17 Feb 2024 21:32:51 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 41HLWpPV020442; Sat, 17 Feb 2024 21:32:51 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 41HLWp04020439; Sat, 17 Feb 2024 21:32:51 GMT (envelope-from git) Date: Sat, 17 Feb 2024 21:32:51 GMT Message-Id: <202402172132.41HLWp04020439@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Vladimir Kondratyev Subject: git: c3a10c23329b - stable/14 - LinuxKPI: Add static_assert() macro List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-branches@freebsd.org X-BeenThere: dev-commits-src-branches@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: wulf X-Git-Repository: src X-Git-Refname: refs/heads/stable/14 X-Git-Reftype: branch X-Git-Commit: c3a10c23329b35001fbc4ef171aa1739efb27f8d Auto-Submitted: auto-generated The branch stable/14 has been updated by wulf: URL: https://cgit.FreeBSD.org/src/commit/?id=c3a10c23329b35001fbc4ef171aa1739efb27f8d commit c3a10c23329b35001fbc4ef171aa1739efb27f8d Author: Vladimir Kondratyev AuthorDate: 2023-12-24 08:19:58 +0000 Commit: Vladimir Kondratyev CommitDate: 2024-02-17 20:58:36 +0000 LinuxKPI: Add static_assert() macro And move it along BUILD_BUG family in to linux/build_bug.h to match Linux. Sponsored by: Serenity Cyber Security, LLC Reviewed by: manu, bz MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D42800 (cherry picked from commit 31ef29091b0fbadefb4ccfb21e4b30ca7ddca3ed) --- .../linuxkpi/common/include/linux/build_bug.h | 65 ++++++++++++++++++++++ sys/compat/linuxkpi/common/include/linux/kernel.h | 23 +------- 2 files changed, 66 insertions(+), 22 deletions(-) diff --git a/sys/compat/linuxkpi/common/include/linux/build_bug.h b/sys/compat/linuxkpi/common/include/linux/build_bug.h new file mode 100644 index 000000000000..59d1fc228afc --- /dev/null +++ b/sys/compat/linuxkpi/common/include/linux/build_bug.h @@ -0,0 +1,65 @@ +/*- + * Copyright (c) 2017 Mark Johnston + * Copyright (c) 2018 Johannes Lundberg + * Copyright (c) 2021 The FreeBSD Foundation + * Copyright (c) 2021 Vladimir Kondratyev + * Copyright (c) 2023 Serenity Cyber Security, LLC + * + * Portions of this software were developed by Bjoern A. Zeeb + * under sponsorship from the FreeBSD Foundation. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice unmodified, this list of conditions, and the following + * disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _LINUXKPI_LINUX_BUILD_BUG_H_ +#define _LINUXKPI_LINUX_BUILD_BUG_H_ + +#include + +#include + +/* + * BUILD_BUG_ON() can happen inside functions where _Static_assert() does not + * seem to work. Use old-schoold-ish CTASSERT from before commit + * a3085588a88fa58eb5b1eaae471999e1995a29cf but also make sure we do not + * end up with an unused typedef or variable. The compiler should optimise + * it away entirely. + */ +#define _O_CTASSERT(x) _O__CTASSERT(x, __LINE__) +#define _O__CTASSERT(x, y) _O___CTASSERT(x, y) +#define _O___CTASSERT(x, y) while (0) { \ + typedef char __assert_line_ ## y[(x) ? 1 : -1]; \ + __assert_line_ ## y _x; \ + _x[0] = '\0'; \ +} + +#define BUILD_BUG() do { CTASSERT(0); } while (0) +#define BUILD_BUG_ON(x) do { _O_CTASSERT(!(x)) } while (0) +#define BUILD_BUG_ON_MSG(x, msg) BUILD_BUG_ON(x) +#define BUILD_BUG_ON_NOT_POWER_OF_2(x) BUILD_BUG_ON(!powerof2(x)) +#define BUILD_BUG_ON_INVALID(expr) while (0) { (void)(expr); } +#define BUILD_BUG_ON_ZERO(x) ((int)sizeof(struct { int:-((x) != 0); })) + +#define static_assert(x, ...) __static_assert(x, ##__VA_ARGS__, #x) +#define __static_assert(x, msg, ...) _Static_assert(x, msg) + +#endif diff --git a/sys/compat/linuxkpi/common/include/linux/kernel.h b/sys/compat/linuxkpi/common/include/linux/kernel.h index 2ee452cb39ed..fe844777e469 100644 --- a/sys/compat/linuxkpi/common/include/linux/kernel.h +++ b/sys/compat/linuxkpi/common/include/linux/kernel.h @@ -42,6 +42,7 @@ #include #include +#include #include #include #include @@ -91,28 +92,6 @@ #define S64_C(x) x ## LL #define U64_C(x) x ## ULL -/* - * BUILD_BUG_ON() can happen inside functions where _Static_assert() does not - * seem to work. Use old-schoold-ish CTASSERT from before commit - * a3085588a88fa58eb5b1eaae471999e1995a29cf but also make sure we do not - * end up with an unused typedef or variable. The compiler should optimise - * it away entirely. - */ -#define _O_CTASSERT(x) _O__CTASSERT(x, __LINE__) -#define _O__CTASSERT(x, y) _O___CTASSERT(x, y) -#define _O___CTASSERT(x, y) while (0) { \ - typedef char __unused __assert_line_ ## y[(x) ? 1 : -1]; \ - __assert_line_ ## y _x; \ - _x[0] = '\0'; \ -} - -#define BUILD_BUG() do { CTASSERT(0); } while (0) -#define BUILD_BUG_ON(x) do { _O_CTASSERT(!(x)) } while (0) -#define BUILD_BUG_ON_MSG(x, msg) BUILD_BUG_ON(x) -#define BUILD_BUG_ON_NOT_POWER_OF_2(x) BUILD_BUG_ON(!powerof2(x)) -#define BUILD_BUG_ON_INVALID(expr) while (0) { (void)(expr); } -#define BUILD_BUG_ON_ZERO(x) ((int)sizeof(struct { int:-((x) != 0); })) - #define BUG() panic("BUG at %s:%d", __FILE__, __LINE__) #define BUG_ON(cond) do { \ if (cond) { \