< prev index next >

src/jdk.hotspot.agent/linux/native/libsaproc/ps_core.c

Print this page




 678             break;
 679          }
 680       }
 681 
 682       core_php++;
 683    }
 684 
 685    free(phbuf);
 686    return true;
 687 err:
 688    free(phbuf);
 689    return false;
 690 }
 691 
 692 // read segments of a shared object
 693 static bool read_lib_segments(struct ps_prochandle* ph, int lib_fd, ELF_EHDR* lib_ehdr, uintptr_t lib_base) {
 694   int i = 0;
 695   ELF_PHDR* phbuf;
 696   ELF_PHDR* lib_php = NULL;
 697 




 698   int page_size = sysconf(_SC_PAGE_SIZE);
 699 
 700   if ((phbuf = read_program_header_table(lib_fd, lib_ehdr)) == NULL) {
 701     return false;
 702   }
 703 
 704   // we want to process only PT_LOAD segments that are not writable.
 705   // i.e., text segments. The read/write/exec (data) segments would
 706   // have been already added from core file segments.
 707   for (lib_php = phbuf, i = 0; i < lib_ehdr->e_phnum; i++) {
 708     if ((lib_php->p_type == PT_LOAD) && !(lib_php->p_flags & PF_W) && (lib_php->p_filesz != 0)) {
 709 
 710       uintptr_t target_vaddr = lib_php->p_vaddr + lib_base;
 711       map_info *existing_map = core_lookup(ph, target_vaddr);
 712 
 713       if (existing_map == NULL){
 714         if (add_map_info(ph, lib_fd, lib_php->p_offset,
 715                           target_vaddr, lib_php->p_memsz) == NULL) {
 716           goto err;
 717         }
 718       } else {
 719         // Coredump stores value of p_memsz elf field
 720         // rounded up to page boundary.
 721 
 722         if ((existing_map->memsz != page_size) &&
 723             (existing_map->fd != lib_fd) &&
 724             (ROUNDUP(existing_map->memsz, page_size) != ROUNDUP(lib_php->p_memsz, page_size))) {
 725 
 726           print_debug("address conflict @ 0x%lx (existing map size = %ld, size = %ld, flags = %d)\n",
 727                         target_vaddr, existing_map->memsz, lib_php->p_memsz, lib_php->p_flags);
 728           goto err;
 729         }
 730 
 731         /* replace PT_LOAD segment with library segment */
 732         print_debug("overwrote with new address mapping (memsz %ld -> %ld)\n",
 733                      existing_map->memsz, ROUNDUP(lib_php->p_memsz, page_size));
 734 
 735         existing_map->fd = lib_fd;
 736         existing_map->offset = lib_php->p_offset;
 737         existing_map->memsz = ROUNDUP(lib_php->p_memsz, page_size);
 738       }
 739     }
 740 
 741     lib_php++;
 742   }




 678             break;
 679          }
 680       }
 681 
 682       core_php++;
 683    }
 684 
 685    free(phbuf);
 686    return true;
 687 err:
 688    free(phbuf);
 689    return false;
 690 }
 691 
 692 // read segments of a shared object
 693 static bool read_lib_segments(struct ps_prochandle* ph, int lib_fd, ELF_EHDR* lib_ehdr, uintptr_t lib_base) {
 694   int i = 0;
 695   ELF_PHDR* phbuf;
 696   ELF_PHDR* lib_php = NULL;
 697 
 698 #ifndef LIBC
 699 #error "LIBC not set"
 700 #endif
 701 
 702   int page_size = sysconf(_SC_PAGE_SIZE);
 703 
 704   if ((phbuf = read_program_header_table(lib_fd, lib_ehdr)) == NULL) {
 705     return false;
 706   }
 707 
 708   // we want to process only PT_LOAD segments that are not writable.
 709   // i.e., text segments. The read/write/exec (data) segments would
 710   // have been already added from core file segments.
 711   for (lib_php = phbuf, i = 0; i < lib_ehdr->e_phnum; i++) {
 712     if ((lib_php->p_type == PT_LOAD) && !(lib_php->p_flags & PF_W) && (lib_php->p_filesz != 0)) {
 713 
 714       uintptr_t target_vaddr = lib_php->p_vaddr + lib_base;
 715       map_info *existing_map = core_lookup(ph, target_vaddr);
 716 
 717       if (existing_map == NULL){
 718         if (add_map_info(ph, lib_fd, lib_php->p_offset,
 719                           target_vaddr, lib_php->p_memsz) == NULL) {
 720           goto err;
 721         }
 722       } else {
 723         // Coredump stores value of p_memsz elf field
 724         // rounded up to page boundary.
 725         if ((strcmp(LIBC, "musl")) &&
 726             (existing_map->memsz != page_size) &&
 727             (existing_map->fd != lib_fd) &&
 728             (ROUNDUP(existing_map->memsz, page_size) != ROUNDUP(lib_php->p_memsz, page_size))) {
 729 
 730           print_debug("address conflict @ 0x%lx (existing map size = %ld, size = %ld, flags = %d)\n",
 731                         target_vaddr, existing_map->memsz, lib_php->p_memsz, lib_php->p_flags);
 732           goto err;
 733         }
 734 
 735         /* replace PT_LOAD segment with library segment */
 736         print_debug("overwrote with new address mapping (memsz %ld -> %ld)\n",
 737                      existing_map->memsz, ROUNDUP(lib_php->p_memsz, page_size));
 738 
 739         existing_map->fd = lib_fd;
 740         existing_map->offset = lib_php->p_offset;
 741         existing_map->memsz = ROUNDUP(lib_php->p_memsz, page_size);
 742       }
 743     }
 744 
 745     lib_php++;
 746   }


< prev index next >