From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-ej1-f42.google.com (mail-ej1-f42.google.com [209.85.218.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8C056211278 for ; Wed, 15 Jan 2025 11:35:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.42 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736940929; cv=none; b=ogbRSUUEwUBlXnjuLp3+r8UmrhUIDEnIL/BRThpXzryeDpl5xVeTQ2Vq3lqpOkN3TJwgKfIJKNKPwBrcu8M7NMyF+/bQ3/U3Z9EeWKIgaqPwsmdg3j89ldQj6/3uZsOYvE1kwllpYpsVKSkAs46bMpHHiKpNvPYMR8VfcmFfsKQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736940929; c=relaxed/simple; bh=Kw2NpCJRFMV6OkGDvwN0DkzztFiazcOdmK/rjigTxvw=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=t854OPMBVCRPkn5X7gtHRdjAauq5TY9u1HCc13kLPK0kQtvX+3Y+AtzicvlSmorJqZHksLMTwyPSIaXf7BZh4TCUBbF27al1Jg5WntOllB5rjkM1ciGINLs4J5FgaAzRlGnRVx30t8XeklCOZ8+Kup0kXY0+8lb0l5eoFVFE9lE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ventanamicro.com; spf=pass smtp.mailfrom=ventanamicro.com; dkim=pass (2048-bit key) header.d=ventanamicro.com header.i=@ventanamicro.com header.b=IMgq5/ME; arc=none smtp.client-ip=209.85.218.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ventanamicro.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ventanamicro.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ventanamicro.com header.i=@ventanamicro.com header.b="IMgq5/ME" Received: by mail-ej1-f42.google.com with SMTP id a640c23a62f3a-aaf60d85238so1177125866b.0 for ; Wed, 15 Jan 2025 03:35:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1736940926; x=1737545726; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=lUHWtySzqJ9yO6ZWLDwixXceZtGyWajzSTrgRbyzKjU=; b=IMgq5/MEr7PYzy472urJObXYcLL20tQQEtReofqbPrkHrYbuk6W8OsXZBcLt7+gNgo 17rL4enfQlTSrOzFsV9DV4OF2iuUyoXUm59z0RLi232l++GMT7hjgssI2dk3tELKCJm5 St7Vw/B8A9FlzwsVC31eNGm2RDLnsXVdSrd46gz1UYjeYnDT4GEZ2Pnc47gmuGKDyU0R 7jvsD7+H5z4VVhdgiEpTaIEp9eevoKKGU/Oq54qgsUVWcDuvWNP5xZLK2vYnQ41FGL8H YJRpzs8cfE8mQVj7Ev9BFnv4dmlxv2TKILA6os63VCQ/LxJ4AXH/S1tTs9kYsM4cugaV RQxw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736940926; x=1737545726; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=lUHWtySzqJ9yO6ZWLDwixXceZtGyWajzSTrgRbyzKjU=; b=cMOzQsuZOc4oyA35J9G0ISuh+VxGt148abpJeRCmTHqtMwgrQCgl8vbIVA0y+wTZRl Nrg6p5dfIKGz6CVbjMfMu3Yjy1aumBUWz2k3XPZkX4NXcKG/rU+tAl388beShXsErKsu WIbt1W0aXyAMrliT0pbgPvDGG6xOa2bJz1V8sHHpvXR0eP4W7hHHd/NU+nwt+ajc3djX GdbhwJ18TKkS+olLViiJy6Jo2Q0wNe7pCxUoSXhvoaA5b+OI7tzmNmjS9mUn+dnZvldP 67l8IAHIDT7j2JAq3x3eALXg66DTNoc02uGtUS34zKRBDbHmVo42Ao5lovLOnMkZ3uPy FxWA== X-Forwarded-Encrypted: i=1; AJvYcCU0PDV/T8QWzxqr9zjOb951uCqmptH23ZFOEm+5NOMEP9CVCr05y5nXQO2SliRZUvR1NmslSEGL2DqUips=@vger.kernel.org X-Gm-Message-State: AOJu0YwE7q0EbshSC7ph0hEppxqm6n6msBVZeYjalAHO+/dMBxokXURx OX+SLrCGjTFxgJ1FbMl+yl3S5+JLN6KVJmX+O0pak530OyLgiP5KA7dC1SiONss= X-Gm-Gg: ASbGncuXM0PasIe0lu6ZZuiVNESNeyq32WbsZimbYq7mxrbTmxt4v5otAkQP0ztJ/Yg DREhM84OVDGBHKPBM7Ei0AR2rBR7ELqTUuGDPvtTdwPIoI3gLr2WLMHfgqHmbc1eFq+RDyAwS7k qEFeGrBLa1mxBHHGhHONIsAARg2W47aoiUj8vFHpwGr9GdE5v8w5Ma93zavzefLp2LGC6P/GcLf WDxxGElPf2bzEUBKee4migkruNPMJSU0u6k95B/me6f7dNevuR4jx9V3e7qt4+ke3ARfUJhWJI8 3a3CzefPnFxO0sbHZfG5W0g7fXr0ruKxZYUQZEpwIQ== X-Google-Smtp-Source: AGHT+IEQLKTa0DBxC8EOVUTlbuIfogqAL7gY4MctOjS7wqT4IZEViihjVaBW+6yGKWlOG3PEpzozoQ== X-Received: by 2002:a17:907:9617:b0:ab2:d2e7:abc7 with SMTP id a640c23a62f3a-ab2d2e7b16bmr2022380966b.19.1736940925400; Wed, 15 Jan 2025 03:35:25 -0800 (PST) Received: from localhost (2001-1ae9-1c2-4c00-20f-c6b4-1e57-7965.ip6.tmcz.cz. [2001:1ae9:1c2:4c00:20f:c6b4:1e57:7965]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-ab2c905ed87sm738090866b.28.2025.01.15.03.35.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Jan 2025 03:35:24 -0800 (PST) Date: Wed, 15 Jan 2025 12:35:24 +0100 From: Andrew Jones To: Celeste Liu Cc: Oleg Nesterov , Paul Walmsley , Palmer Dabbelt , Eric Biederman , Kees Cook , Shuah Khan , Albert Ou , Alexandre Ghiti , "Dmitry V. Levin" , Andrea Bolognani , =?utf-8?B?QmrDtnJuIFTDtnBlbA==?= , Thomas Gleixner , Ron Economos , Charlie Jenkins , 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 Subject: Re: [PATCH v6 2/3] tools: copy include/linux/stddef.h to tools/include Message-ID: <20250115-710fcf2a3f874dfd032211c2@orel> References: <20250115-riscv-new-regset-v6-0-59bfddd33525@coelacanthus.name> <20250115-riscv-new-regset-v6-2-59bfddd33525@coelacanthus.name> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20250115-riscv-new-regset-v6-2-59bfddd33525@coelacanthus.name> On Wed, Jan 15, 2025 at 07:13:28PM +0800, Celeste Liu wrote: > 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 > --- > 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__ > > -- > 2.48.0 > Reviewed-by: Andrew Jones