elfcore.c 1.7 KB

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