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!
+ }
+}
+