GSoC [PATCH] add btf_attr for retrieving map btf information'

SuHsueyu anolasc13 at gmail.com
Tue Aug 16 16:11:01 UTC 2022


From: SuHsueyu <anolasc13 at gmail.com>

Try to add some structs that used in retriving map btf information

---
 src/btf_attr.h | 101 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 101 insertions(+)
 create mode 100644 src/btf_attr.h

diff --git a/src/btf_attr.h b/src/btf_attr.h
new file mode 100644
index 000000000..7b98ed452
--- /dev/null
+++ b/src/btf_attr.h
@@ -0,0 +1,101 @@
+#ifndef STRACE_BTF_ATTR_H
+#define STRACE_BTF_ATTR_H
+
+typedef size_t(*hashmap_hash_fn)(const void* key, void* ctx);
+typedef bool (*hashmap_equal_fn)(const void* key1, const void* key2, void* ctx);
+
+struct hashmap_entry {
+	const void* key;
+	void* value;
+	struct hashmap_entry* next;
+};
+
+struct hashmap {
+	hashmap_hash_fn hash_fn;
+	hashmap_equal_fn equal_fn;
+	void* ctx;
+
+	struct hashmap_entry** buckets;
+	size_t cap;
+	size_t cap_bits;
+	size_t sz;
+};
+
+struct btf_type {
+	__u32 name_off;
+	__u32 info;
+	union {
+		__u32 size;
+		__u32 type;
+	};
+};
+
+enum BTF_KIND {
+	BTF_KIND_UNKN = 0,	/* Unknown	*/
+	BTF_KIND_INT = 1,	/* Integer	*/
+	BTF_KIND_PTR = 2,	/* Pointer	*/
+	BTF_KIND_ARRAY = 3,	/* Array	*/
+	BTF_KIND_STRUCT = 4,	/* Struct	*/
+	BTF_KIND_UNION = 5,	/* Union	*/
+	BTF_KIND_ENUM = 6,	/* Enumeration up to 32-bit values */
+	BTF_KIND_FWD = 7,	/* Forward	*/
+	BTF_KIND_TYPEDEF = 8,	/* Typedef	*/
+	BTF_KIND_VOLATILE = 9,	/* Volatile	*/
+	BTF_KIND_CONST = 10,	/* Const	*/
+	BTF_KIND_RESTRICT = 11,	/* Restrict	*/
+	BTF_KIND_FUNC = 12,	/* Function	*/
+	BTF_KIND_FUNC_PROTO = 13,	/* Function Proto	*/
+	BTF_KIND_VAR = 14,	/* Variable	*/
+	BTF_KIND_DATASEC = 15,	/* Section	*/
+	BTF_KIND_FLOAT = 16,	/* Floating point	*/
+	BTF_KIND_DECL_TAG = 17,	/* Decl Tag */
+	BTF_KIND_TYPE_TAG = 18,	/* Type Tag */
+	BTF_KIND_ENUM64 = 19,	/* Enumeration up to 64-bit values */
+
+	NR_BTF_KINDS,
+	BTF_KIND_MAX = NR_BTF_KINDS - 1,
+};
+
+struct strset {
+	void* strs_data;
+	size_t strs_data_len;
+	size_t strs_data_cap;
+	size_t strs_data_max_len;
+	struct hashmap* strs_hash;
+};
+
+struct btf_header {
+	__u16	magic;
+	__u8	version;
+	__u8	flags;
+	__u32	hdr_len;
+
+	/* All offsets are in bytes relative to the end of this header */
+	__u32	type_off;	/* offset of type section	*/
+	__u32	type_len;	/* length of type section	*/
+	__u32	str_off;	/* offset of string section	*/
+	__u32	str_len;	/* length of string section	*/
+};
+
+struct btf {
+	void* raw_data;
+	void* raw_data_swapped;
+	__u32 raw_size;
+	bool swapped_endian;
+	struct btf_header* hdr;
+	void* types_data;
+	size_t types_data_cap;
+	__u32* type_offs;
+	size_t type_offs_cap;
+	__u32 nr_types;
+	struct btf* base_btf;
+	int start_id;
+	int start_str_off;
+	void* strs_data;
+	struct strset* strs_set;
+	bool strs_deduped;
+	int fd;
+	int ptr_sz;
+};
+
+#endif /* !STRACE_BTF_ATTR_H */
\ No newline at end of file
-- 
2.29.2.windows.3



More information about the Strace-devel mailing list