From: Nikolay Borisov <nborisov@suse.com>
To: bpf@vger.kernel.org
Cc: daniel@iogearbox.net, andrii@kernel.org, ast@kernel.org,
Nikolay Borisov <nborisov@suse.com>
Subject: [RFC PATCH 1/2] libbpf: Add userspace version of for_each_member macro
Date: Mon, 4 Apr 2022 11:38:15 +0300 [thread overview]
Message-ID: <20220404083816.1560501-2-nborisov@suse.com> (raw)
In-Reply-To: <20220404083816.1560501-1-nborisov@suse.com>
There are multiple places in libbpf where iteration of struct/union
members is required. Instead of open-coding it let's introduce a
convenience macro.
Signed-off-by: Nikolay Borisov <nborisov@suse.com>
---
tools/lib/bpf/btf.h | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/tools/lib/bpf/btf.h b/tools/lib/bpf/btf.h
index 061839f04525..74039f8afc63 100644
--- a/tools/lib/bpf/btf.h
+++ b/tools/lib/bpf/btf.h
@@ -578,6 +578,12 @@ static inline struct btf_decl_tag *btf_decl_tag(const struct btf_type *t)
return (struct btf_decl_tag *)(t + 1);
}
+#define for_each_member(i, struct_type, member) \
+ for (i = 0, member = btf_members(struct_type); \
+ i < btf_vlen(struct_type); \
+ i++, member++)
+
+
#ifdef __cplusplus
} /* extern "C" */
#endif
--
2.25.1
next prev parent reply other threads:[~2022-04-04 8:38 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-04-04 8:38 [RFC PATCH 0/2] Add btf__field_exists Nikolay Borisov
2022-04-04 8:38 ` Nikolay Borisov [this message]
2022-04-05 23:31 ` [RFC PATCH 1/2] libbpf: Add userspace version of for_each_member macro Andrii Nakryiko
2022-04-04 8:38 ` [RFC PATCH 2/2] libbpf: Add btf__field_exists Nikolay Borisov
2022-04-05 23:37 ` [RFC PATCH 0/2] " Andrii Nakryiko
2022-04-06 6:41 ` Nikolay Borisov
2022-04-06 17:14 ` Andrii Nakryiko
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220404083816.1560501-2-nborisov@suse.com \
--to=nborisov@suse.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).