Lines Matching refs:kcore

1438 struct kcore {
1445 static int kcore__open(struct kcore *kcore, const char *filename)
1449 kcore->fd = open(filename, O_RDONLY);
1450 if (kcore->fd == -1)
1453 kcore->elf = elf_begin(kcore->fd, ELF_C_READ, NULL);
1454 if (!kcore->elf)
1457 kcore->elfclass = gelf_getclass(kcore->elf);
1458 if (kcore->elfclass == ELFCLASSNONE)
1461 ehdr = gelf_getehdr(kcore->elf, &kcore->ehdr);
1468 elf_end(kcore->elf);
1470 close(kcore->fd);
1474 static int kcore__init(struct kcore *kcore, char *filename, int elfclass,
1477 kcore->elfclass = elfclass;
1480 kcore->fd = mkstemp(filename);
1482 kcore->fd = open(filename, O_WRONLY | O_CREAT | O_EXCL, 0400);
1483 if (kcore->fd == -1)
1486 kcore->elf = elf_begin(kcore->fd, ELF_C_WRITE, NULL);
1487 if (!kcore->elf)
1490 if (!gelf_newehdr(kcore->elf, elfclass))
1493 memset(&kcore->ehdr, 0, sizeof(GElf_Ehdr));
1498 elf_end(kcore->elf);
1500 close(kcore->fd);
1505 static void kcore__close(struct kcore *kcore)
1507 elf_end(kcore->elf);
1508 close(kcore->fd);
1511 static int kcore__copy_hdr(struct kcore *from, struct kcore *to, size_t count)
1547 static int kcore__add_phdr(struct kcore *kcore, int idx, off_t offset,
1561 if (!gelf_update_phdr(kcore->elf, idx, &phdr))
1567 static off_t kcore__write(struct kcore *kcore)
1569 return elf_update(kcore->elf, ELF_C_WRITE);
1987 * kcore_copy - copy kallsyms, modules and kcore from one directory to another.
1991 * This function copies kallsyms, modules and kcore files from one directory to
1993 * copied from kcore. It is assumed that two segments suffice: one for the
2001 * symbol too. Because it contains only code sections, the resulting kcore is
2004 * the data is copied adjacently whereas the original kcore has gaps. Finally,
2012 struct kcore kcore;
2013 struct kcore extract;
2030 scnprintf(kcore_filename, PATH_MAX, "%s/kcore", from_dir);
2031 scnprintf(extract_filename, PATH_MAX, "%s/kcore", to_dir);
2033 if (kcore__open(&kcore, kcore_filename))
2036 if (kcore_copy__calc_maps(&kci, from_dir, kcore.elf))
2039 if (kcore__init(&extract, extract_filename, kcore.elfclass, false))
2042 if (kcore__copy_hdr(&kcore, &extract, kci.phnum))
2065 if (copy_bytes(kcore.fd, p->offset, extract.fd, offs, p->len))
2079 kcore__close(&kcore);
2095 struct kcore kcore;
2096 struct kcore extract;
2101 if (kcore__open(&kcore, kce->kcore_filename))
2105 if (kcore__init(&extract, kce->extract_filename, kcore.elfclass, true))
2108 if (kcore__copy_hdr(&kcore, &extract, count))
2118 if (copy_bytes(kcore.fd, kce->offs, extract.fd, offset, kce->len))
2128 kcore__close(&kcore);