< prev index next >

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

Print this page


   1 /*
   2  * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *


 735 
 736   if ((phbuf = read_program_header_table(lib_fd, lib_ehdr)) == NULL) {
 737     return false;
 738   }
 739 
 740   // we want to process only PT_LOAD segments that are not writable.
 741   // i.e., text segments. The read/write/exec (data) segments would
 742   // have been already added from core file segments.
 743   for (lib_php = phbuf, i = 0; i < lib_ehdr->e_phnum; i++) {
 744     if ((lib_php->p_type == PT_LOAD) && !(lib_php->p_flags & PF_W) && (lib_php->p_filesz != 0)) {
 745 
 746       uintptr_t target_vaddr = lib_php->p_vaddr + lib_base;
 747       map_info *existing_map = core_lookup(ph, target_vaddr);
 748 
 749       if (existing_map == NULL){
 750         if (add_map_info(ph, lib_fd, lib_php->p_offset,
 751                           target_vaddr, lib_php->p_memsz) == NULL) {
 752           goto err;
 753         }
 754       } else {

 755         // Coredump stores value of p_memsz elf field
 756         // rounded up to page boundary.
 757 
 758         if ((existing_map->memsz != page_size) &&
 759             (existing_map->fd != lib_fd) &&
 760             (ROUNDUP(existing_map->memsz, page_size) != ROUNDUP(lib_php->p_memsz, page_size))) {
 761 
 762           print_debug("address conflict @ 0x%lx (existing map size = %ld, size = %ld, flags = %d)\n",
 763                         target_vaddr, existing_map->memsz, lib_php->p_memsz, lib_php->p_flags);
 764           goto err;
 765         }

 766 
 767         /* replace PT_LOAD segment with library segment */
 768         print_debug("overwrote with new address mapping (memsz %ld -> %ld)\n",
 769                      existing_map->memsz, ROUNDUP(lib_php->p_memsz, page_size));
 770 
 771         existing_map->fd = lib_fd;
 772         existing_map->offset = lib_php->p_offset;
 773         existing_map->memsz = ROUNDUP(lib_php->p_memsz, page_size);
 774       }
 775     }
 776 
 777     lib_php++;
 778   }
 779 
 780   free(phbuf);
 781   return true;
 782 err:
 783   free(phbuf);
 784   return false;
 785 }


   1 /*
   2  * Copyright (c) 2003, 2017, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *


 735 
 736   if ((phbuf = read_program_header_table(lib_fd, lib_ehdr)) == NULL) {
 737     return false;
 738   }
 739 
 740   // we want to process only PT_LOAD segments that are not writable.
 741   // i.e., text segments. The read/write/exec (data) segments would
 742   // have been already added from core file segments.
 743   for (lib_php = phbuf, i = 0; i < lib_ehdr->e_phnum; i++) {
 744     if ((lib_php->p_type == PT_LOAD) && !(lib_php->p_flags & PF_W) && (lib_php->p_filesz != 0)) {
 745 
 746       uintptr_t target_vaddr = lib_php->p_vaddr + lib_base;
 747       map_info *existing_map = core_lookup(ph, target_vaddr);
 748 
 749       if (existing_map == NULL){
 750         if (add_map_info(ph, lib_fd, lib_php->p_offset,
 751                           target_vaddr, lib_php->p_memsz) == NULL) {
 752           goto err;
 753         }
 754       } else {
 755 #ifdef INCLUDE_SA_ATTACH
 756         // Coredump stores value of p_memsz elf field
 757         // rounded up to page boundary.
 758 
 759         if ((existing_map->memsz != page_size) &&
 760             (existing_map->fd != lib_fd) &&
 761             (ROUNDUP(existing_map->memsz, page_size) != ROUNDUP(lib_php->p_memsz, page_size))) {
 762 
 763           print_debug("address conflict @ 0x%lx (existing map size = %ld, size = %ld, flags = %d)\n",
 764                         target_vaddr, existing_map->memsz, lib_php->p_memsz, lib_php->p_flags);
 765           goto err;
 766         }
 767 #endif
 768 
 769         /* replace PT_LOAD segment with library segment */
 770         print_debug("overwrote with new address mapping (memsz %ld -> %ld)\n",
 771                      existing_map->memsz, ROUNDUP(lib_php->p_memsz, page_size));
 772 
 773         existing_map->fd = lib_fd;
 774         existing_map->offset = lib_php->p_offset;
 775         existing_map->memsz = ROUNDUP(lib_php->p_memsz, page_size);
 776       }
 777     }
 778 
 779     lib_php++;
 780   }
 781 
 782   free(phbuf);
 783   return true;
 784 err:
 785   free(phbuf);
 786   return false;
 787 }


< prev index next >