Re: [PATCH bpf-next v4 3/6] libbpf: Convert st_ops->data to shadow type.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 





On 2/26/24 14:57, Martin KaFai Lau wrote:
On 2/22/24 2:26 PM, thinker.li@xxxxxxxxx wrote:
+/* Convert the data of a struct_ops map to shadow type.
+ *
+ * The function pointers are replaced with the pointers of bpf_program in
+ * st_ops->progs[].
+ */
+static void struct_ops_convert_shadow(struct bpf_map *map,
+                      const struct btf_type *t)
+{
+    struct btf *btf = map->obj->btf;
+    struct bpf_struct_ops *st_ops = map->st_ops;
+    const struct btf_member *m;
+    const struct btf_type *mtype;
+    char *data;
+    int i;
+
+    data = st_ops->data;
+
+    for (i = 0, m = btf_members(t); i < btf_vlen(t); i++, m++) {
+        mtype = skip_mods_and_typedefs(btf, m->type, NULL);
+
+        if (btf_kind(mtype) != BTF_KIND_PTR)
+            continue;
+        if (!resolve_func_ptr(btf, m->type, NULL))
+            continue;
+
+        *((struct bpf_program **)(data + m->offset / 8)) =
+            st_ops->progs[i];

This is to initialize the bpf_program pointer in the st_ops->data.
Can this be done directly at the bpf_object__collect_st_ops_relos()?

No problem!


+    }
+}
+





[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux