< prev index next >

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

Print this page




 207   off_t current_pos = -1;
 208   ELF_EHDR ehdr;
 209   ELF_SHDR* shbuf = NULL;
 210   ELF_SHDR* sh = NULL;
 211   char* strtab = NULL;
 212   void* result = NULL;
 213   int cnt;
 214 
 215   current_pos = lseek(lib->fd, (off_t)0L, SEEK_CUR);
 216   lseek(lib->fd, (off_t)0L, SEEK_SET);
 217 
 218   read_elf_header(lib->fd, &ehdr);
 219   shbuf = read_section_header_table(lib->fd, &ehdr);
 220   strtab = read_section_data(lib->fd, &ehdr, &shbuf[ehdr.e_shstrndx]);
 221 
 222   for (cnt = 0, sh = shbuf; cnt < ehdr.e_shnum; cnt++, sh++) {
 223     if (strcmp(".eh_frame", sh->sh_name + strtab) == 0) {
 224       lib->eh_frame.library_base_addr = lib->base;
 225       lib->eh_frame.v_addr = sh->sh_addr;
 226       lib->eh_frame.data = read_section_data(lib->fd, &ehdr, sh);

 227       break;
 228     }
 229   }
 230 
 231   free(strtab);
 232   free(shbuf);
 233   lseek(lib->fd, current_pos, SEEK_SET);
 234   return lib->eh_frame.data != NULL;
 235 }
 236 
 237 lib_info* add_lib_info_fd(struct ps_prochandle* ph, const char* libname, int fd, uintptr_t base) {
 238    lib_info* newlib;
 239 
 240    if ( (newlib = (lib_info*) calloc(1, sizeof(struct lib_info))) == NULL) {
 241       print_debug("can't allocate memory for lib_info\n");
 242       return NULL;
 243    }
 244 
 245    if (strlen(libname) >= sizeof(newlib->name)) {
 246      print_debug("libname %s too long\n", libname);




 207   off_t current_pos = -1;
 208   ELF_EHDR ehdr;
 209   ELF_SHDR* shbuf = NULL;
 210   ELF_SHDR* sh = NULL;
 211   char* strtab = NULL;
 212   void* result = NULL;
 213   int cnt;
 214 
 215   current_pos = lseek(lib->fd, (off_t)0L, SEEK_CUR);
 216   lseek(lib->fd, (off_t)0L, SEEK_SET);
 217 
 218   read_elf_header(lib->fd, &ehdr);
 219   shbuf = read_section_header_table(lib->fd, &ehdr);
 220   strtab = read_section_data(lib->fd, &ehdr, &shbuf[ehdr.e_shstrndx]);
 221 
 222   for (cnt = 0, sh = shbuf; cnt < ehdr.e_shnum; cnt++, sh++) {
 223     if (strcmp(".eh_frame", sh->sh_name + strtab) == 0) {
 224       lib->eh_frame.library_base_addr = lib->base;
 225       lib->eh_frame.v_addr = sh->sh_addr;
 226       lib->eh_frame.data = read_section_data(lib->fd, &ehdr, sh);
 227       lib->eh_frame.size = sh->sh_size;
 228       break;
 229     }
 230   }
 231 
 232   free(strtab);
 233   free(shbuf);
 234   lseek(lib->fd, current_pos, SEEK_SET);
 235   return lib->eh_frame.data != NULL;
 236 }
 237 
 238 lib_info* add_lib_info_fd(struct ps_prochandle* ph, const char* libname, int fd, uintptr_t base) {
 239    lib_info* newlib;
 240 
 241    if ( (newlib = (lib_info*) calloc(1, sizeof(struct lib_info))) == NULL) {
 242       print_debug("can't allocate memory for lib_info\n");
 243       return NULL;
 244    }
 245 
 246    if (strlen(libname) >= sizeof(newlib->name)) {
 247      print_debug("libname %s too long\n", libname);


< prev index next >