From nobody Sun Dec 24 08:22:57 2023 X-Original-To: dev-commits-src-all@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 4SyYv610D6z54HJr; Sun, 24 Dec 2023 08:22:58 +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 4SyYv56J7Wz4XJY; Sun, 24 Dec 2023 08:22:57 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1703406178; 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=HyvCZAWm9Pla2d4AwV4sj5Ku24EN3BBilh53R21bm9A=; b=KGWhAbqDPCPnaPJJCVfNUepT4K+f3DaSo+vFKnqVOAzwFLhx/Clx381y9a61anq3nRBPzc GPU/aalD930UhsR1QkIKnC07wAtzmcnN6JI75X9YB8Y0jylnMB6u2zTgFzvazwPqmkS0I1 kstyvUrfJSfCkLL1gzZVjmjej/4H3nmsmqXSJVb8gxiGDe9+T6BMy+wapEMZm6DpEqu44Y w0F9VhM27SHg3jWxZlx7VbbVwgg8LCtw4PWDJA2Kn1Tjua+suxxP6UmH9+zi8r9rZcypxt dgeL021M2qwoIi78eOdxAvEL6H3eQ6imVLPfzoI+UEIBAC7DDo7z2gM0Q09BZw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1703406178; a=rsa-sha256; cv=none; b=Gi7V1x3aL1REZ1PP8XTSOcDL12OaSSpHbVFQ6GazkSc7bn06t2MWsMDhzq3JJFgE+DZKMh 0k8oHQqoYak2xrV6NQAYH4nl+MUKD36TAVoJvpKwHNBHmYprr5JcHTm296amzwMFyCn+Ie jnJPFiz6Goi4U7/z+pUvQ4FxRsphi79RKkJ2zOMsx4iWB2QI7nz9fcb/VCN23aX/gCQ0Sx 2DHKFSKCx4Hd55BIYYaEZraFA1STFWqmCQlcaxJniOEssxpIQWXdxb6VWHHKP43k8w0CJB SXrYX8j266Vn0COxJKbdx6aXFYHobr0ljDcBxF6wU4uOpaU+nIs2NA/ORDZ9ug== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1703406178; 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=HyvCZAWm9Pla2d4AwV4sj5Ku24EN3BBilh53R21bm9A=; b=Tl4JsOASIb3KRWluacXps9MTSulfFXIGJGVuOsZllZSFgQE56mlkjHgIRc3mE4AEw87/52 nRxTQByP4jol3crl9twiJIjeYBrm8rWVUXm4jC8OxtMc/0XGpDB0R4rC7BQwednRVCztqJ lnwQvKCUKTTx+YVf5WzSpBRQVW11TcuwhZGkyd2Lhd0TlpU+QQJzLzYC22noPFZB2U8wsU 9nSc8uCxb9B3newG2dGYyng8RxWf9dQuPqybYI+uuHGT4ggpN+Yz49QODj+PY3nSaJ7xwa IMhaQqqE5TlPNJUa6CirpQ1XqrLVC6hDb5ZUiwNMr6VlIiqZz9MnKG9yt3KIxQ== 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 4SyYv55Nzdz5Tb; Sun, 24 Dec 2023 08:22:57 +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 3BO8MvUM086606; Sun, 24 Dec 2023 08:22:57 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 3BO8Mv0g086603; Sun, 24 Dec 2023 08:22:57 GMT (envelope-from git) Date: Sun, 24 Dec 2023 08:22:57 GMT Message-Id: <202312240822.3BO8Mv0g086603@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Vladimir Kondratyev Subject: git: 31ef29091b0f - main - LinuxKPI: Add static_assert() macro List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@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/main X-Git-Reftype: branch X-Git-Commit: 31ef29091b0fbadefb4ccfb21e4b30ca7ddca3ed Auto-Submitted: auto-generated The branch main has been updated by wulf: URL: https://cgit.FreeBSD.org/src/commit/?id=31ef29091b0fbadefb4ccfb21e4b30ca7ddca3ed commit 31ef29091b0fbadefb4ccfb21e4b30ca7ddca3ed Author: Vladimir Kondratyev AuthorDate: 2023-12-24 08:19:58 +0000 Commit: Vladimir Kondratyev CommitDate: 2023-12-24 08:19:58 +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 --- .../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 73418c849544..097e22e5d8ea 100644 --- a/sys/compat/linuxkpi/common/include/linux/kernel.h +++ b/sys/compat/linuxkpi/common/include/linux/kernel.h @@ -41,6 +41,7 @@ #include #include +#include #include #include #include @@ -90,28 +91,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) { \