elfcore.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #include <linux/elf.h>
  2. #include <linux/coredump.h>
  3. #include <linux/fs.h>
  4. #include <linux/mm.h>
  5. #include <asm/elf.h>
  6. Elf64_Half elf_core_extra_phdrs(void)
  7. {
  8. return GATE_EHDR->e_phnum;
  9. }
  10. int elf_core_write_extra_phdrs(struct file *file, loff_t offset, size_t *size,
  11. unsigned long limit)
  12. {
  13. const struct elf_phdr *const gate_phdrs =
  14. (const struct elf_phdr *) (GATE_ADDR + GATE_EHDR->e_phoff);
  15. int i;
  16. Elf64_Off ofs = 0;
  17. for (i = 0; i < GATE_EHDR->e_phnum; ++i) {
  18. struct elf_phdr phdr = gate_phdrs[i];
  19. if (phdr.p_type == PT_LOAD) {
  20. phdr.p_memsz = PAGE_ALIGN(phdr.p_memsz);
  21. phdr.p_filesz = phdr.p_memsz;
  22. if (ofs == 0) {
  23. ofs = phdr.p_offset = offset;
  24. offset += phdr.p_filesz;
  25. } else {
  26. phdr.p_offset = ofs;
  27. }
  28. } else {
  29. phdr.p_offset += ofs;
  30. }
  31. phdr.p_paddr = 0; /* match other core phdrs */
  32. *size += sizeof(phdr);
  33. if (*size > limit || !dump_write(file, &phdr, sizeof(phdr)))
  34. return 0;
  35. }
  36. return 1;
  37. }
  38. int elf_core_write_extra_data(struct file *file, size_t *size,
  39. unsigned long limit)
  40. {
  41. const struct elf_phdr *const gate_phdrs =
  42. (const struct elf_phdr *) (GATE_ADDR + GATE_EHDR->e_phoff);
  43. int i;
  44. for (i = 0; i < GATE_EHDR->e_phnum; ++i) {
  45. if (gate_phdrs[i].p_type == PT_LOAD) {
  46. void *addr = (void *)gate_phdrs[i].p_vaddr;
  47. size_t memsz = PAGE_ALIGN(gate_phdrs[i].p_memsz);
  48. *size += memsz;
  49. if (*size > limit || !dump_write(file, addr, memsz))
  50. return 0;
  51. break;
  52. }
  53. }
  54. return 1;
  55. }
  56. size_t elf_core_extra_data_size(void)
  57. {
  58. const struct elf_phdr *const gate_phdrs =
  59. (const struct elf_phdr *) (GATE_ADDR + GATE_EHDR->e_phoff);
  60. int i;
  61. size_t size = 0;
  62. for (i = 0; i < GATE_EHDR->e_phnum; ++i) {
  63. if (gate_phdrs[i].p_type == PT_LOAD) {
  64. size += PAGE_ALIGN(gate_phdrs[i].p_memsz);
  65. break;
  66. }
  67. }
  68. return size;
  69. }