elfcore.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. Elf32_Half elf_core_extra_phdrs(void)
  7. {
  8. return vsyscall_ehdr ? (((struct elfhdr *)vsyscall_ehdr)->e_phnum) : 0;
  9. }
  10. int elf_core_write_extra_phdrs(struct file *file, loff_t offset, size_t *size,
  11. unsigned long limit)
  12. {
  13. if ( vsyscall_ehdr ) {
  14. const struct elfhdr *const ehdrp =
  15. (struct elfhdr *) vsyscall_ehdr;
  16. const struct elf_phdr *const phdrp =
  17. (const struct elf_phdr *) (vsyscall_ehdr + ehdrp->e_phoff);
  18. int i;
  19. Elf32_Off ofs = 0;
  20. for (i = 0; i < ehdrp->e_phnum; ++i) {
  21. struct elf_phdr phdr = phdrp[i];
  22. if (phdr.p_type == PT_LOAD) {
  23. ofs = phdr.p_offset = offset;
  24. offset += phdr.p_filesz;
  25. } else {
  26. phdr.p_offset += ofs;
  27. }
  28. phdr.p_paddr = 0; /* match other core phdrs */
  29. *size += sizeof(phdr);
  30. if (*size > limit
  31. || !dump_write(file, &phdr, sizeof(phdr)))
  32. return 0;
  33. }
  34. }
  35. return 1;
  36. }
  37. int elf_core_write_extra_data(struct file *file, size_t *size,
  38. unsigned long limit)
  39. {
  40. if ( vsyscall_ehdr ) {
  41. const struct elfhdr *const ehdrp =
  42. (struct elfhdr *) vsyscall_ehdr;
  43. const struct elf_phdr *const phdrp =
  44. (const struct elf_phdr *) (vsyscall_ehdr + ehdrp->e_phoff);
  45. int i;
  46. for (i = 0; i < ehdrp->e_phnum; ++i) {
  47. if (phdrp[i].p_type == PT_LOAD) {
  48. void *addr = (void *) phdrp[i].p_vaddr;
  49. size_t filesz = phdrp[i].p_filesz;
  50. *size += filesz;
  51. if (*size > limit
  52. || !dump_write(file, addr, filesz))
  53. return 0;
  54. }
  55. }
  56. }
  57. return 1;
  58. }
  59. size_t elf_core_extra_data_size(void)
  60. {
  61. if ( vsyscall_ehdr ) {
  62. const struct elfhdr *const ehdrp =
  63. (struct elfhdr *)vsyscall_ehdr;
  64. const struct elf_phdr *const phdrp =
  65. (const struct elf_phdr *) (vsyscall_ehdr + ehdrp->e_phoff);
  66. int i;
  67. for (i = 0; i < ehdrp->e_phnum; ++i)
  68. if (phdrp[i].p_type == PT_LOAD)
  69. return (size_t) phdrp[i].p_filesz;
  70. }
  71. return 0;
  72. }