< 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  *


 991             } else {
 992                print_debug("can't read ELF header for shared object %s\n", lib_name);
 993                close(lib_fd);
 994                // continue with other libraries...
 995             }
 996          }
 997       }
 998 
 999     // read next link_map address
1000     if (ps_pdread(ph, (psaddr_t) link_map_addr + LINK_MAP_NEXT_OFFSET,
1001                    &link_map_addr, sizeof(uintptr_t)) != PS_OK) {
1002       print_debug("can't read next link in link_map\n");
1003       return false;
1004     }
1005   }
1006 
1007   return true;
1008 }
1009 
1010 // the one and only one exposed stuff from this file
1011 struct ps_prochandle* Pgrab_core(const char* exec_file, const char* core_file) {

1012   ELF_EHDR core_ehdr;
1013   ELF_EHDR exec_ehdr;
1014   ELF_EHDR lib_ehdr;
1015 
1016   struct ps_prochandle* ph = (struct ps_prochandle*) calloc(1, sizeof(struct ps_prochandle));
1017   if (ph == NULL) {
1018     print_debug("can't allocate ps_prochandle\n");
1019     return NULL;
1020   }
1021 
1022   if ((ph->core = (struct core_data*) calloc(1, sizeof(struct core_data))) == NULL) {
1023     free(ph);
1024     print_debug("can't allocate ps_prochandle\n");
1025     return NULL;
1026   }
1027 
1028   // initialize ph
1029   ph->ops = &core_ops;
1030   ph->core->core_fd   = -1;
1031   ph->core->exec_fd   = -1;


   1 /*
   2  * Copyright (c) 2003, 2018, 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  *


 991             } else {
 992                print_debug("can't read ELF header for shared object %s\n", lib_name);
 993                close(lib_fd);
 994                // continue with other libraries...
 995             }
 996          }
 997       }
 998 
 999     // read next link_map address
1000     if (ps_pdread(ph, (psaddr_t) link_map_addr + LINK_MAP_NEXT_OFFSET,
1001                    &link_map_addr, sizeof(uintptr_t)) != PS_OK) {
1002       print_debug("can't read next link in link_map\n");
1003       return false;
1004     }
1005   }
1006 
1007   return true;
1008 }
1009 
1010 // the one and only one exposed stuff from this file
1011 JNIEXPORT struct ps_prochandle* JNICALL
1012 Pgrab_core(const char* exec_file, const char* core_file) {
1013   ELF_EHDR core_ehdr;
1014   ELF_EHDR exec_ehdr;
1015   ELF_EHDR lib_ehdr;
1016 
1017   struct ps_prochandle* ph = (struct ps_prochandle*) calloc(1, sizeof(struct ps_prochandle));
1018   if (ph == NULL) {
1019     print_debug("can't allocate ps_prochandle\n");
1020     return NULL;
1021   }
1022 
1023   if ((ph->core = (struct core_data*) calloc(1, sizeof(struct core_data))) == NULL) {
1024     free(ph);
1025     print_debug("can't allocate ps_prochandle\n");
1026     return NULL;
1027   }
1028 
1029   // initialize ph
1030   ph->ops = &core_ops;
1031   ph->core->core_fd   = -1;
1032   ph->core->exec_fd   = -1;


< prev index next >