elfcore.c 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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 coredump_params *cprm, loff_t offset)
  11. {
  12. const struct elf_phdr *const gate_phdrs =
  13. (const struct elf_phdr *) (GATE_ADDR + GATE_EHDR->e_phoff);
  14. int i;
  15. Elf64_Off ofs = 0;
  16. for (i = 0; i < GATE_EHDR->e_phnum; ++i) {
  17. struct elf_phdr phdr = gate_phdrs[i];
  18. if (phdr.p_type == PT_LOAD) {
  19. phdr.p_memsz = PAGE_ALIGN(phdr.p_memsz);
  20. phdr.p_filesz = phdr.p_memsz;
  21. if (ofs == 0) {
  22. ofs = phdr.p_offset = offset;
  23. offset += phdr.p_filesz;
  24. } else {
  25. phdr.p_offset = ofs;
  26. }
  27. } else {
  28. phdr.p_offset += ofs;
  29. }
  30. phdr.p_paddr = 0; /* match other core phdrs */
  31. if (!dump_emit(cprm, &phdr, sizeof(phdr)))
  32. return 0;
  33. }
  34. return 1;
  35. }
  36. int elf_core_write_extra_data(struct coredump_params *cprm)
  37. {
  38. const struct elf_phdr *const gate_phdrs =
  39. (const struct elf_phdr *) (GATE_ADDR + GATE_EHDR->e_phoff);
  40. int i;
  41. for (i = 0; i < GATE_EHDR->e_phnum; ++i) {
  42. if (gate_phdrs[i].p_type == PT_LOAD) {
  43. void *addr = (void *)gate_phdrs[i].p_vaddr;
  44. size_t memsz = PAGE_ALIGN(gate_phdrs[i].p_memsz);
  45. if (!dump_emit(cprm, addr, memsz))
  46. return 0;
  47. break;
  48. }
  49. }
  50. return 1;
  51. }
  52. size_t elf_core_extra_data_size(void)
  53. {
  54. const struct elf_phdr *const gate_phdrs =
  55. (const struct elf_phdr *) (GATE_ADDR + GATE_EHDR->e_phoff);
  56. int i;
  57. size_t size = 0;
  58. for (i = 0; i < GATE_EHDR->e_phnum; ++i) {
  59. if (gate_phdrs[i].p_type == PT_LOAD) {
  60. size += PAGE_ALIGN(gate_phdrs[i].p_memsz);
  61. break;
  62. }
  63. }
  64. return size;
  65. }