From patchwork Wed Jan 15 11:13:28 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Celeste Liu X-Patchwork-Id: 13940314 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id BBEC1C02183 for ; Wed, 15 Jan 2025 11:14:24 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 291E96B008A; Wed, 15 Jan 2025 06:14:24 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 21C9B6B008C; Wed, 15 Jan 2025 06:14:24 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 046106B0092; Wed, 15 Jan 2025 06:14:23 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id D81A56B008A for ; Wed, 15 Jan 2025 06:14:23 -0500 (EST) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 5393812123B for ; Wed, 15 Jan 2025 11:14:23 +0000 (UTC) X-FDA: 83009427606.15.F02D55D Received: from flow-a3-smtp.messagingengine.com (flow-a3-smtp.messagingengine.com [103.168.172.138]) by imf04.hostedemail.com (Postfix) with ESMTP id 30F8340005 for ; Wed, 15 Jan 2025 11:14:21 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=coelacanthus.name header.s=fm3 header.b=oRHyd1GL; dkim=pass header.d=messagingengine.com header.s=fm2 header.b="i LhZEEs"; spf=pass (imf04.hostedemail.com: domain of uwu@coelacanthus.name designates 103.168.172.138 as permitted sender) smtp.mailfrom=uwu@coelacanthus.name; dmarc=pass (policy=quarantine) header.from=coelacanthus.name ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1736939661; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=cefyME3vtsv5sxq1SOu8UxjoNujymAivw3tNwb5ahHc=; b=1AS3xdrYeUe1XAyfE8WASWaTGmAjetoDSAu1tZ2mOy/4Q84KcF7zcAgE54o9JTK4eliRS3 ybdsx68/v3zBo9ePhHFMuQwzNkzDeFyelZOE7n2um4ftCLYUE+QIRQ45eCog6ak1KjksfP 4HqdwJUEus20U/824QagOjC9SW9dxiI= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=coelacanthus.name header.s=fm3 header.b=oRHyd1GL; dkim=pass header.d=messagingengine.com header.s=fm2 header.b="i LhZEEs"; spf=pass (imf04.hostedemail.com: domain of uwu@coelacanthus.name designates 103.168.172.138 as permitted sender) smtp.mailfrom=uwu@coelacanthus.name; dmarc=pass (policy=quarantine) header.from=coelacanthus.name ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1736939661; a=rsa-sha256; cv=none; b=CVARV+Ud6rCPV6wr57f3tD3RH5FE+VlJ2VcLdaAxcTfZBQCSAyoOBB7XsIznxtQE85i/Wo I7kDrRLmEuttWPE/5fTubp/pH6tdfTpMaeJQ1JC02LH73OpynX4bYRyEHV68cg4GnJtNlM SRVFNdeiCBJ7GKkPx8rRqho6SrKaVaM= Received: from phl-compute-02.internal (phl-compute-02.phl.internal [10.202.2.42]) by mailflow.phl.internal (Postfix) with ESMTP id 92B7F200FE6; Wed, 15 Jan 2025 06:14:20 -0500 (EST) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-02.internal (MEProxy); Wed, 15 Jan 2025 06:14:20 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= coelacanthus.name; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1736939660; x=1736946860; bh=cefyME3vts v5sxq1SOu8UxjoNujymAivw3tNwb5ahHc=; b=oRHyd1GLCtmaP88DZ05pDtICaK OXw8OwHKrV8RGJieDIm5D9l6iNnei/l4hT99f4K8RrtFscZE6ICqqnnLU+ZfQ3MU uruFIOmMbeQN0voNVhU+se82GeGFwSzrV8lY+yHw/KdaQCTIrl9uTyqP1r+OwLPu xXcpeWGpLHTZ23FFOUKh/Xy0aAj18F793ZXbThyN0dxM2NOZloQ7P4gxeMXMgCbn siNJlN3Aq0SbrlqJJNZgsa1Qq0E1u/VG0+pnUT2MRdYtHE8rlvxwbewJXdbA1B4R +Tbpbj79cJg8NRFyqaTWdirdQqnDQHlYVHkepAorS9CVeJvPngCgxZSljYLg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm2; t=1736939660; x= 1736946860; bh=cefyME3vtsv5sxq1SOu8UxjoNujymAivw3tNwb5ahHc=; b=i LhZEEsE7v4/MIZ3/8d3eXsH7iCiNgXMU3vV3irR8cGwgPliFyOSWdZKRyITcV5ZX eX8lLYDKBG2uB5SqnUsCdlNrRGrYoWCnFZqy8PJeQ8d3ECqs1sxktl9oSgbF3/N2 kDWKqpFRkzqWl945myxuK6xbmVhNYChPxQpmOo8PCU/VPrGE24ruw0hsPNd6xVkB pTwhSFPAQte67aj4lyF9Fp5RW67iYRNYXMNnXUxnjbC/5boKWoEnA2omvs3D9uf1 Jtc5zrNPWAXSiF/YgiAFRPiwkKZ7b4wzCRQWozO+WOxFv4RTgogUj2aMS7n9+jUp 0UtHD1+TMLJgS4kJXiOfg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefuddrudehlecutefuodetggdotefrodftvfcurf hrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdpuffrtefo kffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsuc dlqddutddtmdenucfjughrpefhfffugggtgffkfhgjvfevofesthejredtredtjeenucfh rhhomhepvegvlhgvshhtvgcunfhiuhcuoehufihusegtohgvlhgrtggrnhhthhhushdrnh grmhgvqeenucggtffrrghtthgvrhhnpeeiteejtdevjeffgfehkeegfeelkeekvdehtdeg leevhfetheejheejiedtjeegteenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmh epmhgrihhlfhhrohhmpehufihusegtohgvlhgrtggrnhhthhhushdrnhgrmhgvpdhnsggp rhgtphhtthhopedvhedpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtoheplhhinhhugi dqkhgvrhhnvghlsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtoheplhguvhes shhtrhgrtggvrdhiohdprhgtphhtthhopegthhgrrhhlihgvsehrihhvohhsihhntgdrtg homhdprhgtphhtthhopegsjhhorhhnsehkvghrnhgvlhdrohhrghdprhgtphhtthhopehs hhhurghhsehkvghrnhgvlhdrohhrghdprhgtphhtthhopehrvgesfieirhiirdhnvghtpd hrtghpthhtohepvggsihgvuggvrhhmseigmhhishhsihhonhdrtghomhdprhgtphhtthho peiihhhouhhquhgrnhesihhstggrshdrrggtrdgtnhdprhgtphhtthhopehlihhnuhigqd hkshgvlhhfthgvshhtsehvghgvrhdrkhgvrhhnvghlrdhorhhg X-ME-Proxy: Feedback-ID: i95c648bc:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 15 Jan 2025 06:14:19 -0500 (EST) From: Celeste Liu Date: Wed, 15 Jan 2025 19:13:28 +0800 Subject: [PATCH v6 2/3] tools: copy include/linux/stddef.h to tools/include MIME-Version: 1.0 Message-Id: <20250115-riscv-new-regset-v6-2-59bfddd33525@coelacanthus.name> References: <20250115-riscv-new-regset-v6-0-59bfddd33525@coelacanthus.name> In-Reply-To: <20250115-riscv-new-regset-v6-0-59bfddd33525@coelacanthus.name> To: Oleg Nesterov , Paul Walmsley , Palmer Dabbelt , Eric Biederman , Kees Cook , Shuah Khan , Albert Ou Cc: Alexandre Ghiti , "Dmitry V. Levin" , Andrea Bolognani , =?utf-8?b?QmrDtnJuIFTDtnBlbA==?= , Thomas Gleixner , Ron Economos , Charlie Jenkins , Andrew Jones , Quan Zhou , Felix Yan , Ruizhe Pan , Guo Ren , Yao Zi , linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-kselftest@vger.kernel.org, Celeste Liu X-Mailer: b4 0.15-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=4577; i=uwu@coelacanthus.name; h=from:subject:message-id; bh=WV0NqvqtTK1mWkN78Oo6GA0cv0m8xWUUF/b/ZrqzqEo=; b=owJ4nJvAy8zAJeafov85RWVtBeNptSSG9PYZFdHJnxQvWgTnrrt4QWqTwV/zbd1fOHm+8piqL H7LlzfPIKCjlIVBjItBVkyRJa+E5SfnpbPdezu2d8HMYWUCGcLAxSkAE6ncz8iw/93V6o+mZ8wn SyYeMDt4u+nxizae6PPGbtsbv/s84zRlZPif1tGg3LzHjPPH7vwT/EXzzTbECkmeEP4343DKkhA j9i9cANkLSSY= X-Developer-Key: i=uwu@coelacanthus.name; a=openpgp; fpr=892EBC7DC392DFF9C9C03F1D15F4180E73787863 X-Rspamd-Queue-Id: 30F8340005 X-Stat-Signature: 1c8xse131gz51tzwcb1biet3wuhx9ub5 X-Rspam-User: X-Rspamd-Server: rspam11 X-HE-Tag: 1736939661-642185 X-HE-Meta: U2FsdGVkX19YMKSK5CE52pJMrTYSrnwr91pEtl3aTgR2P09omjhr/uw4LQmwM7lSsefnRyarfbjuka+7DXy++c4EnDusPTnoQ7X/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7w6Z3vUu84nDO33D7wT2pAhF9ECQLwMoeacUF1AAUDVE7wbMAw0t8bXwKL23OYGPxB+T8pei530HQEPCbvKZt9Ky1QHgbTP2CD5vdjo6h1JwkXqk89vOuvt8DB6kw2HFLLGk52Mj3X+o9wI/LaLV3GJ46R6rNFBWwiaKh4jlicbbZOAFfFn2Zu7gzhdpNaCDHNmL/iYATdYLO7ksKiLsWHnbsA== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Some macro defined in stddef.h are useful and have been used in many code in selftests. Copy them to tools/include so developers needn't create their copy in every files. Remove some definitions like NULL and true/false to be suitable to non-kernel environment. Signed-off-by: Celeste Liu Reviewed-by: Andrew Jones --- tools/include/linux/stddef.h | 85 +++++++++++++++++++++++++++++++++++++++ tools/include/uapi/linux/stddef.h | 6 +-- 2 files changed, 87 insertions(+), 4 deletions(-) diff --git a/tools/include/linux/stddef.h b/tools/include/linux/stddef.h new file mode 100644 index 0000000000000000000000000000000000000000..55f3964d9a3d9f9f9345a75248eec027c56faef9 --- /dev/null +++ b/tools/include/linux/stddef.h @@ -0,0 +1,85 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _LINUX_STDDEF_H +#define _LINUX_STDDEF_H + +#include + +/** + * sizeof_field() - Report the size of a struct field in bytes + * + * @TYPE: The structure containing the field of interest + * @MEMBER: The field to return the size of + */ +#define sizeof_field(TYPE, MEMBER) sizeof((((TYPE *)0)->MEMBER)) + +/** + * offsetofend() - Report the offset of a struct field within the struct + * + * @TYPE: The type of the structure + * @MEMBER: The member within the structure to get the end offset of + */ +#define offsetofend(TYPE, MEMBER) \ + (offsetof(TYPE, MEMBER) + sizeof_field(TYPE, MEMBER)) + +/** + * struct_group() - Wrap a set of declarations in a mirrored struct + * + * @NAME: The identifier name of the mirrored sub-struct + * @MEMBERS: The member declarations for the mirrored structs + * + * Used to create an anonymous union of two structs with identical + * layout and size: one anonymous and one named. The former can be + * used normally without sub-struct naming, and the latter can be + * used to reason about the start, end, and size of the group of + * struct members. + */ +#define struct_group(NAME, MEMBERS...) \ + __struct_group(/* no tag */, NAME, /* no attrs */, MEMBERS) + +/** + * struct_group_attr() - Create a struct_group() with trailing attributes + * + * @NAME: The identifier name of the mirrored sub-struct + * @ATTRS: Any struct attributes to apply + * @MEMBERS: The member declarations for the mirrored structs + * + * Used to create an anonymous union of two structs with identical + * layout and size: one anonymous and one named. The former can be + * used normally without sub-struct naming, and the latter can be + * used to reason about the start, end, and size of the group of + * struct members. Includes structure attributes argument. + */ +#define struct_group_attr(NAME, ATTRS, MEMBERS...) \ + __struct_group(/* no tag */, NAME, ATTRS, MEMBERS) + +/** + * struct_group_tagged() - Create a struct_group with a reusable tag + * + * @TAG: The tag name for the named sub-struct + * @NAME: The identifier name of the mirrored sub-struct + * @MEMBERS: The member declarations for the mirrored structs + * + * Used to create an anonymous union of two structs with identical + * layout and size: one anonymous and one named. The former can be + * used normally without sub-struct naming, and the latter can be + * used to reason about the start, end, and size of the group of + * struct members. Includes struct tag argument for the named copy, + * so the specified layout can be reused later. + */ +#define struct_group_tagged(TAG, NAME, MEMBERS...) \ + __struct_group(TAG, NAME, /* no attrs */, MEMBERS) + +/** + * DECLARE_FLEX_ARRAY() - Declare a flexible array usable in a union + * + * @TYPE: The type of each flexible array element + * @NAME: The name of the flexible array member + * + * In order to have a flexible array member in a union or alone in a + * struct, it needs to be wrapped in an anonymous struct with at least 1 + * named member, but that member can be empty. + */ +#define DECLARE_FLEX_ARRAY(TYPE, NAME) \ + __DECLARE_FLEX_ARRAY(TYPE, NAME) + +#endif diff --git a/tools/include/uapi/linux/stddef.h b/tools/include/uapi/linux/stddef.h index bb6ea517efb51177a7983fadad9b590b12b786e5..f2548fd95f6e1d8cb218d52918bb81a3317d10b1 100644 --- a/tools/include/uapi/linux/stddef.h +++ b/tools/include/uapi/linux/stddef.h @@ -1,8 +1,6 @@ /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ -#ifndef _LINUX_STDDEF_H -#define _LINUX_STDDEF_H - - +#ifndef _UAPI_LINUX_STDDEF_H +#define _UAPI_LINUX_STDDEF_H #ifndef __always_inline #define __always_inline __inline__