@@ -75,102 +75,17 @@ static int task_work_callback(struct bpf_map *map, void *key, void *value)
75
75
return 0 ;
76
76
}
77
77
78
- /* Finds thread local variable `tls_counter` in this executable's ELF */
79
78
static int process_elf (struct task_struct * task , struct vm_area_struct * vma , void * data )
80
79
{
81
- /*
82
- Elf64_Ehdr ehdr;
83
- Elf64_Shdr shdrs;
84
- Elf64_Shdr symtab, strtab, tmp;
85
- const Elf64_Sym *symbol;
86
- int count, off, i, e_shnum, e_shoff, e_shentsize, sections = 0;
87
- const char *string;
88
80
struct bpf_dynptr dynptr ;
89
- const __u32 slen = 11;
90
- static const char *needle = "tls_counter";
91
81
92
82
if (!vma -> vm_file ) {
93
83
err = 1 ;
94
84
return 1 ;
95
85
}
96
86
97
- err = bpf_dynptr_from_file(vma->vm_file, 0, &dynptr);
98
- if (err)
99
- goto fail;
100
-
101
- err = bpf_dynptr_read(&ehdr, sizeof(ehdr), &dynptr, 0, 0);
102
- if (err)
103
- goto fail;
104
-
105
- Big endian, do not support
106
- if (ehdr.e_ident[EI_DATA] == ELFDATA2MSB)
107
- goto success;
108
-
109
- if (memcmp(ehdr.e_ident, ELFMAG, SELFMAG) != 0)
110
- goto fail;
111
-
112
- if (ehdr.e_type != ET_EXEC && ehdr.e_type != ET_DYN)
113
- goto fail;
114
-
115
- if (ehdr.e_ident[EI_CLASS] != ELFCLASS64)
116
- goto fail;
117
-
118
- e_shnum = ehdr.e_shnum;
119
- e_shoff = ehdr.e_shoff;
120
- e_shentsize = ehdr.e_shentsize;
121
-
122
- err = bpf_dynptr_read(&shdrs, sizeof(shdrs), &dynptr,
123
- e_shoff + e_shentsize * ehdr.e_shstrndx, 0);
124
- if (err)
125
- goto fail;
126
-
127
- off = shdrs.sh_offset;
128
-
129
- __builtin_memset(&symtab, 0, sizeof(symtab));
130
- __builtin_memset(&strtab, 0, sizeof(strtab));
131
- bpf_for(i, 0, e_shnum)
132
- {
133
- err = bpf_dynptr_read(&tmp, sizeof(Elf64_Shdr), &dynptr, e_shoff + e_shentsize * i,
134
- 0);
135
- if (err)
136
- goto fail;
137
-
138
- string = bpf_dynptr_slice(&dynptr, off + tmp.sh_name, buf, slen);
139
- if (!string)
140
- goto fail;
141
-
142
- if (bpf_strncmp(string, slen, ".symtab") == 0) {
143
- symtab = tmp;
144
- ++sections;
145
- } else if (bpf_strncmp(string, slen, ".strtab") == 0) {
146
- strtab = tmp;
147
- ++sections;
148
- }
149
- if (sections == 2)
150
- break;
151
- }
152
- if (sections != 2)
153
- goto fail;
154
-
155
- count = symtab.sh_size / sizeof(Elf64_Sym);
156
- bpf_for(i, 0, count)
157
- {
158
- symbol = bpf_dynptr_slice(&dynptr, symtab.sh_offset + sizeof(Elf64_Sym) * i, buf,
159
- sizeof(Elf64_Sym));
160
- if (!symbol)
161
- goto fail;
162
- if (symbol->st_name == 0 || ELF64_ST_TYPE(symbol->st_info) != STT_TLS)
163
- continue;
164
- string = bpf_dynptr_slice(&dynptr, strtab.sh_offset + symbol->st_name, buf, slen);
165
- if (!string)
166
- goto fail;
167
- if (bpf_strncmp(string, slen, needle) == 0)
168
- goto success;
169
- }
170
- fail:
171
- err = 1;
172
- success:
87
+ //err = bpf_dynptr_from_file(vma->vm_file, 0, &dynptr);
88
+
173
89
bpf_dynptr_file_discard (& dynptr );
174
- */
175
90
return err ? 1 : 0 ;
176
91
}
0 commit comments