|
@@ -1028,6 +1028,39 @@ int file__read_maps(int fd, bool exe, mapfn_t mapfn, void *data,
|
|
|
return err;
|
|
|
}
|
|
|
|
|
|
+enum dso_type dso__type_fd(int fd)
|
|
|
+{
|
|
|
+ enum dso_type dso_type = DSO__TYPE_UNKNOWN;
|
|
|
+ GElf_Ehdr ehdr;
|
|
|
+ Elf_Kind ek;
|
|
|
+ Elf *elf;
|
|
|
+
|
|
|
+ elf = elf_begin(fd, PERF_ELF_C_READ_MMAP, NULL);
|
|
|
+ if (elf == NULL)
|
|
|
+ goto out;
|
|
|
+
|
|
|
+ ek = elf_kind(elf);
|
|
|
+ if (ek != ELF_K_ELF)
|
|
|
+ goto out_end;
|
|
|
+
|
|
|
+ if (gelf_getclass(elf) == ELFCLASS64) {
|
|
|
+ dso_type = DSO__TYPE_64BIT;
|
|
|
+ goto out_end;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (gelf_getehdr(elf, &ehdr) == NULL)
|
|
|
+ goto out_end;
|
|
|
+
|
|
|
+ if (ehdr.e_machine == EM_X86_64)
|
|
|
+ dso_type = DSO__TYPE_X32BIT;
|
|
|
+ else
|
|
|
+ dso_type = DSO__TYPE_32BIT;
|
|
|
+out_end:
|
|
|
+ elf_end(elf);
|
|
|
+out:
|
|
|
+ return dso_type;
|
|
|
+}
|
|
|
+
|
|
|
static int copy_bytes(int from, off_t from_offs, int to, off_t to_offs, u64 len)
|
|
|
{
|
|
|
ssize_t r;
|