structOpsFindInnerType returns the "inner" struct inside a value struct_ops type. Given a value like: struct bpf_struct_ops_bpf_testmod_ops { struct bpf_struct_ops_common common; struct bpf_testmod_ops data; }; this function returns the *btf.Struct for "bpf_testmod_ops" along with the
(vType *btf.Struct)
| 82 | // The inner struct name is derived by trimming the "bpf_struct_ops_" prefix |
| 83 | // from the value's name. |
| 84 | func structOpsFindInnerType(vType *btf.Struct) (*btf.Struct, uint32, error) { |
| 85 | innerName := strings.TrimPrefix(vType.Name, structOpsValuePrefix) |
| 86 | |
| 87 | for _, m := range vType.Members { |
| 88 | if st, ok := btf.As[*btf.Struct](m.Type); ok && st.Name == innerName { |
| 89 | return st, m.Offset.Bytes(), nil |
| 90 | } |
| 91 | } |
| 92 | |
| 93 | return nil, 0, fmt.Errorf("inner struct %q not found in %s", innerName, vType.Name) |
| 94 | } |
| 95 | |
| 96 | // structOpsFindTarget resolves the kernel-side "value struct" for a struct_ops map. |
| 97 | func structOpsFindTarget(userType *btf.Struct, cache *btf.Cache) (vType *btf.Struct, id btf.TypeID, module *btf.Handle, err error) { |
no test coverage detected
searching dependent graphs…