Skip to content

Commit 84de2bc

Browse files
committed
remove memsets
Signed-off-by: Mykyta Yatsenko <[email protected]>
1 parent ebcd3e5 commit 84de2bc

File tree

1 file changed

+2
-87
lines changed

1 file changed

+2
-87
lines changed

tools/testing/selftests/bpf/progs/file_reader.c

Lines changed: 2 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -75,102 +75,17 @@ static int task_work_callback(struct bpf_map *map, void *key, void *value)
7575
return 0;
7676
}
7777

78-
/* Finds thread local variable `tls_counter` in this executable's ELF */
7978
static int process_elf(struct task_struct *task, struct vm_area_struct *vma, void *data)
8079
{
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;
8880
struct bpf_dynptr dynptr;
89-
const __u32 slen = 11;
90-
static const char *needle = "tls_counter";
9181

9282
if (!vma->vm_file) {
9383
err = 1;
9484
return 1;
9585
}
9686

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+
17389
bpf_dynptr_file_discard(&dynptr);
174-
*/
17590
return err ? 1 : 0;
17691
}

0 commit comments

Comments
 (0)