From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 70DFB4237E; Mon, 9 Jan 2023 12:22:35 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 538F340687; Mon, 9 Jan 2023 12:22:35 +0100 (CET) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mails.dpdk.org (Postfix) with ESMTP id AB23F4067C for ; Mon, 9 Jan 2023 12:22:33 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1673263353; h=from:from: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; bh=KYVI17xl0CxuYPzFBwLvxU/w5seL5y7DWZZo6PU3jl4=; b=AbknX8xVcHQ7eGs82tpFm+cr8SLUyW/SF2r0lmKC84vfND48pSNaPwGQdGr3UbCM/zVcMz BxOpcu9r3DWxqbaPw9qkUu5lWRDAiwhRXdMVuv/TuXNvXQ9Cy/Qv8zzRNWaFRXkHtwLSQC oqjtx0VVvnuyRe8j6rIMQR1/i+Nq5Z4= Received: from mail-pf1-f198.google.com (mail-pf1-f198.google.com [209.85.210.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-156-g7m-vk0oMumEVimYkLOeww-1; Mon, 09 Jan 2023 06:22:31 -0500 X-MC-Unique: g7m-vk0oMumEVimYkLOeww-1 Received: by mail-pf1-f198.google.com with SMTP id u3-20020a056a00124300b0056d4ab0c7cbso3311921pfi.7 for ; Mon, 09 Jan 2023 03:22:31 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=KYVI17xl0CxuYPzFBwLvxU/w5seL5y7DWZZo6PU3jl4=; b=b7L6Wm0INmKX3Txmubn9Os0zHImFVu6fv/MrIg0ZZ/lx/1sJbey9uYhcOTpyskVwyn A1kYsVCBHutQJT7MaFALFcNJXcuk4L3fs1PJhJwyXLJNrFpKdjjhUNBSJ0XzousBxXzl b+faVebJytNcuCBKDDM6k2jdERC/sACXkv7+UN28UYr60L7sNV6/8Aac42RuLEI/rHAD tS5yFaXCxQTvi60MwM5qN3SF9WLdyNp7i9yqPxTSfgj5z7XlyrMA1ligtmr9OFM2n5wk 9iZkd3onujr2nsp32mK3XSqBfBITNqouohAyprMe34JVOEqLN3UR9illHG2x4IZY/KHq GPuw== X-Gm-Message-State: AFqh2kqxlOml1KoiiRAkcrS3h130F3MhDF4Z70CFOcI6T2P4XKnT+kpP BoqRLDQzsy9hCgNSymQXLHQs2NHY2JBakAJUwSD3bC5oU91PKLGEjTT3lUa8txrt5tHaaNOwbIj Qq2sj7BxgHlDy5JBJkPc= X-Received: by 2002:a63:6501:0:b0:479:4c30:9cb4 with SMTP id z1-20020a636501000000b004794c309cb4mr4859754pgb.426.1673263350212; Mon, 09 Jan 2023 03:22:30 -0800 (PST) X-Google-Smtp-Source: AMrXdXujSeRlA6EwYu0ygS7H3Kv9LkuR5i0coWAWOgPWYHn9Riu3KmxKThDnUeh4sVUjdPE5P9T8B6K+CUoXIAjkgrc= X-Received: by 2002:a63:6501:0:b0:479:4c30:9cb4 with SMTP id z1-20020a636501000000b004794c309cb4mr4859748pgb.426.1673263349946; Mon, 09 Jan 2023 03:22:29 -0800 (PST) MIME-Version: 1.0 References: <20221202153432.131023-1-mb@smartsharesystems.com> <20221228151019.101309-1-mb@smartsharesystems.com> In-Reply-To: <20221228151019.101309-1-mb@smartsharesystems.com> From: David Marchand Date: Mon, 9 Jan 2023 12:22:18 +0100 Message-ID: Subject: Re: [PATCH v5 1/4] eal: add nonnull and access function attributes To: =?UTF-8?Q?Morten_Br=C3=B8rup?= Cc: dev@dpdk.org, roretzla@linux.microsoft.com, rmody@marvell.com, timothy.mcdaniel@intel.com, matan@nvidia.com, viacheslavo@nvidia.com, ruifeng.wang@arm.com, zhoumin@loongson.cn, drc@linux.vnet.ibm.com, kda@semihalf.com, bruce.richardson@intel.com, konstantin.v.ananyev@yandex.ru X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org On Wed, Dec 28, 2022 at 4:10 PM Morten Br=C3=B8rup wrote: > > Add "nonnull" function attribute to help the compiler detect a NULL > pointer being passed to a function not accepting NULL pointers as an > argument at build time. > > Add "access" function attribute to tell the compiler how a function > accesses its pointer arguments. > > Add these attributes to the rte_memcpy() function, as the first in > hopefully many to come. > Compilation is broken starting first patch, so patches must be reordered to have the fixes first. > v5: > * No changes. > v4: > * No changes. > v3: > * No changes. > v2: > * Only define "nonnull" for GCC and CLANG. > * Append _param/_params to prepare for possible future attributes > attached directly to the individual parameters, like __rte_unused. > * Use RTE_TOOLCHAIN_GCC instead of RTE_CC_GCC, to fix complaints about > GCC_VERSION being undefined. > * Try to fix Doxygen compliants. Patch history should be put as annotations (i.e. after --- but before patch content). > > Signed-off-by: Morten Br=C3=B8rup > Acked-by: Tyler Retzlaff > Reviewed-by: Ruifeng Wang [snip] > diff --git a/lib/eal/include/rte_common.h b/lib/eal/include/rte_common.h > index 15765b408d..6e4011aa85 100644 > --- a/lib/eal/include/rte_common.h > +++ b/lib/eal/include/rte_common.h > @@ -149,6 +149,35 @@ typedef uint16_t unaligned_uint16_t; > __attribute__((format(printf, format_index, first_arg))) > #endif > > +/** > + * Check pointer arguments at compile-time. > + * > + * @param ... > + * Comma separated list of parameter indexes of pointer arguments. > + */ > +#if defined(RTE_CC_GCC) || defined(RTE_CC_CLANG) > +#define __rte_nonnull_params(...) \ > + __attribute__((nonnull(__VA_ARGS__))) > +#else > +#define __rte_nonnull_params(...) > +#endif > + > +/** > + * Tells compiler about the access mode of a pointer argument. > + * > + * @param access_mode > + * Access mode: read_only, read_write, write_only, or none. > + * @param ... > + * Parameter index of pointer argument. > + * Optionally followeded by comma and parameter index of size argumen= t. > + */ > +#if defined(RTE_TOOLCHAIN_GCC) && (GCC_VERSION >=3D 100400) > +#define __rte_access_param(access_mode, ...) \ > + __attribute__((access(access_mode, __VA_ARGS__))) > +#else > +#define __rte_access_param(access_mode, ...) > +#endif > + This is tightly bound to gcc syntax. With dedicated macros (which I find easier to read too), we can hope to adapt to other compilers if some of them add support for this kind of code cookies. __rte_read_only_params(indexes...) __rte_write_only_params(indexes...) __rte_no_access_params(indexes...) --=20 David Marchand