< prev index next >

src/os/bsd/vm/os_bsd.cpp

Print this page




 425   // Buffer that fits several sprintfs.
 426   // Note that the space for the colon and the trailing null are provided
 427   // by the nulls included by the sizeof operator.
 428   const size_t bufsize =
 429     MAX2((size_t)MAXPATHLEN,  // for dll_dir & friends.
 430          (size_t)MAXPATHLEN + sizeof(EXTENSIONS_DIR) + system_ext_size); // extensions dir
 431   char *buf = (char *)NEW_C_HEAP_ARRAY(char, bufsize, mtInternal);
 432 
 433   // sysclasspath, java_home, dll_dir
 434   {
 435     char *pslash;
 436     os::jvm_path(buf, bufsize);
 437 
 438     // Found the full path to libjvm.so.
 439     // Now cut the path to <java_home>/jre if we can.
 440     *(strrchr(buf, '/')) = '\0'; // Get rid of /libjvm.so.
 441     pslash = strrchr(buf, '/');
 442     if (pslash != NULL) {
 443       *pslash = '\0';            // Get rid of /{client|server|hotspot}.
 444     }




 445     Arguments::set_dll_dir(buf);
 446 
 447     if (pslash != NULL) {
 448       pslash = strrchr(buf, '/');
 449       if (pslash != NULL) {
 450         *pslash = '\0';          // Get rid of /lib.
 451       }
 452     }
 453     Arguments::set_java_home(buf);
 454     set_boot_path('/', ':');
 455   }
 456 
 457   // Where to look for native libraries.
 458   //
 459   // Note: Due to a legacy implementation, most of the library path
 460   // is set in the launcher. This was to accomodate linking restrictions
 461   // on legacy Bsd implementations (which are no longer supported).
 462   // Eventually, all the library path setting will be done here.
 463   //
 464   // However, to prevent the proliferation of improperly built native


1373     if (dlinfo.dli_fname != NULL) {
1374       jio_snprintf(buf, buflen, "%s", dlinfo.dli_fname);
1375     }
1376     if (dlinfo.dli_fbase != NULL && offset != NULL) {
1377       *offset = addr - (address)dlinfo.dli_fbase;
1378     }
1379     return true;
1380   }
1381 
1382   buf[0] = '\0';
1383   if (offset) *offset = -1;
1384   return false;
1385 }
1386 
1387 // Loads .dll/.so and
1388 // in case of error it checks if .dll/.so was built for the
1389 // same architecture as Hotspot is running on
1390 
1391 #ifdef __APPLE__
1392 void * os::dll_load(const char *filename, char *ebuf, int ebuflen) {



1393   void * result= ::dlopen(filename, RTLD_LAZY);
1394   if (result != NULL) {
1395     // Successful loading
1396     return result;
1397   }
1398 
1399   // Read system error message into ebuf
1400   ::strncpy(ebuf, ::dlerror(), ebuflen-1);
1401   ebuf[ebuflen-1]='\0';
1402 
1403   return NULL;

1404 }
1405 #else
1406 void * os::dll_load(const char *filename, char *ebuf, int ebuflen) {



1407   void * result= ::dlopen(filename, RTLD_LAZY);
1408   if (result != NULL) {
1409     // Successful loading
1410     return result;
1411   }
1412 
1413   Elf32_Ehdr elf_head;
1414 
1415   // Read system error message into ebuf
1416   // It may or may not be overwritten below
1417   ::strncpy(ebuf, ::dlerror(), ebuflen-1);
1418   ebuf[ebuflen-1]='\0';
1419   int diag_msg_max_length=ebuflen-strlen(ebuf);
1420   char* diag_msg_buf=ebuf+strlen(ebuf);
1421 
1422   if (diag_msg_max_length==0) {
1423     // No more space in ebuf for additional diagnostics message
1424     return NULL;
1425   }
1426 


1559   if (lib_arch.elf_class != arch_array[running_arch_index].elf_class) {
1560     ::snprintf(diag_msg_buf, diag_msg_max_length-1," (Possible cause: architecture word width mismatch)");
1561     return NULL;
1562   }
1563 #endif // !S390
1564 
1565   if (lib_arch.compat_class != arch_array[running_arch_index].compat_class) {
1566     if (lib_arch.name!=NULL) {
1567       ::snprintf(diag_msg_buf, diag_msg_max_length-1,
1568                  " (Possible cause: can't load %s-bit .so on a %s-bit platform)",
1569                  lib_arch.name, arch_array[running_arch_index].name);
1570     } else {
1571       ::snprintf(diag_msg_buf, diag_msg_max_length-1,
1572                  " (Possible cause: can't load this .so (machine code=0x%x) on a %s-bit platform)",
1573                  lib_arch.code,
1574                  arch_array[running_arch_index].name);
1575     }
1576   }
1577 
1578   return NULL;

1579 }
1580 #endif // !__APPLE__
1581 
1582 void* os::get_default_process_handle() {
1583 #ifdef __APPLE__
1584   // MacOS X needs to use RTLD_FIRST instead of RTLD_LAZY
1585   // to avoid finding unexpected symbols on second (or later)
1586   // loads of a library.
1587   return (void*)::dlopen(NULL, RTLD_FIRST);
1588 #else
1589   return (void*)::dlopen(NULL, RTLD_LAZY);
1590 #endif
1591 }
1592 
1593 // XXX: Do we need a lock around this as per Linux?
1594 void* os::dll_lookup(void* handle, const char* name) {
1595   return dlsym(handle, name);
1596 }
1597 
1598 int _print_dll_info_cb(const char * name, address base_address, address top_address, void * param) {




 425   // Buffer that fits several sprintfs.
 426   // Note that the space for the colon and the trailing null are provided
 427   // by the nulls included by the sizeof operator.
 428   const size_t bufsize =
 429     MAX2((size_t)MAXPATHLEN,  // for dll_dir & friends.
 430          (size_t)MAXPATHLEN + sizeof(EXTENSIONS_DIR) + system_ext_size); // extensions dir
 431   char *buf = (char *)NEW_C_HEAP_ARRAY(char, bufsize, mtInternal);
 432 
 433   // sysclasspath, java_home, dll_dir
 434   {
 435     char *pslash;
 436     os::jvm_path(buf, bufsize);
 437 
 438     // Found the full path to libjvm.so.
 439     // Now cut the path to <java_home>/jre if we can.
 440     *(strrchr(buf, '/')) = '\0'; // Get rid of /libjvm.so.
 441     pslash = strrchr(buf, '/');
 442     if (pslash != NULL) {
 443       *pslash = '\0';            // Get rid of /{client|server|hotspot}.
 444     }
 445 #ifdef STATIC_BUILD
 446     strcat(buf, "/lib");
 447 #endif
 448 
 449     Arguments::set_dll_dir(buf);
 450 
 451     if (pslash != NULL) {
 452       pslash = strrchr(buf, '/');
 453       if (pslash != NULL) {
 454         *pslash = '\0';          // Get rid of /lib.
 455       }
 456     }
 457     Arguments::set_java_home(buf);
 458     set_boot_path('/', ':');
 459   }
 460 
 461   // Where to look for native libraries.
 462   //
 463   // Note: Due to a legacy implementation, most of the library path
 464   // is set in the launcher. This was to accomodate linking restrictions
 465   // on legacy Bsd implementations (which are no longer supported).
 466   // Eventually, all the library path setting will be done here.
 467   //
 468   // However, to prevent the proliferation of improperly built native


1377     if (dlinfo.dli_fname != NULL) {
1378       jio_snprintf(buf, buflen, "%s", dlinfo.dli_fname);
1379     }
1380     if (dlinfo.dli_fbase != NULL && offset != NULL) {
1381       *offset = addr - (address)dlinfo.dli_fbase;
1382     }
1383     return true;
1384   }
1385 
1386   buf[0] = '\0';
1387   if (offset) *offset = -1;
1388   return false;
1389 }
1390 
1391 // Loads .dll/.so and
1392 // in case of error it checks if .dll/.so was built for the
1393 // same architecture as Hotspot is running on
1394 
1395 #ifdef __APPLE__
1396 void * os::dll_load(const char *filename, char *ebuf, int ebuflen) {
1397 #ifdef STATIC_BUILD
1398   return os::get_default_process_handle();
1399 #else
1400   void * result= ::dlopen(filename, RTLD_LAZY);
1401   if (result != NULL) {
1402     // Successful loading
1403     return result;
1404   }
1405 
1406   // Read system error message into ebuf
1407   ::strncpy(ebuf, ::dlerror(), ebuflen-1);
1408   ebuf[ebuflen-1]='\0';
1409 
1410   return NULL;
1411 #endif // STATIC_BUILD
1412 }
1413 #else
1414 void * os::dll_load(const char *filename, char *ebuf, int ebuflen) {
1415 #ifdef STATIC_BUILD
1416   return os::get_default_process_handle();
1417 #else
1418   void * result= ::dlopen(filename, RTLD_LAZY);
1419   if (result != NULL) {
1420     // Successful loading
1421     return result;
1422   }
1423 
1424   Elf32_Ehdr elf_head;
1425 
1426   // Read system error message into ebuf
1427   // It may or may not be overwritten below
1428   ::strncpy(ebuf, ::dlerror(), ebuflen-1);
1429   ebuf[ebuflen-1]='\0';
1430   int diag_msg_max_length=ebuflen-strlen(ebuf);
1431   char* diag_msg_buf=ebuf+strlen(ebuf);
1432 
1433   if (diag_msg_max_length==0) {
1434     // No more space in ebuf for additional diagnostics message
1435     return NULL;
1436   }
1437 


1570   if (lib_arch.elf_class != arch_array[running_arch_index].elf_class) {
1571     ::snprintf(diag_msg_buf, diag_msg_max_length-1," (Possible cause: architecture word width mismatch)");
1572     return NULL;
1573   }
1574 #endif // !S390
1575 
1576   if (lib_arch.compat_class != arch_array[running_arch_index].compat_class) {
1577     if (lib_arch.name!=NULL) {
1578       ::snprintf(diag_msg_buf, diag_msg_max_length-1,
1579                  " (Possible cause: can't load %s-bit .so on a %s-bit platform)",
1580                  lib_arch.name, arch_array[running_arch_index].name);
1581     } else {
1582       ::snprintf(diag_msg_buf, diag_msg_max_length-1,
1583                  " (Possible cause: can't load this .so (machine code=0x%x) on a %s-bit platform)",
1584                  lib_arch.code,
1585                  arch_array[running_arch_index].name);
1586     }
1587   }
1588 
1589   return NULL;
1590 #endif // STATIC_BUILD
1591 }
1592 #endif // !__APPLE__
1593 
1594 void* os::get_default_process_handle() {
1595 #ifdef __APPLE__
1596   // MacOS X needs to use RTLD_FIRST instead of RTLD_LAZY
1597   // to avoid finding unexpected symbols on second (or later)
1598   // loads of a library.
1599   return (void*)::dlopen(NULL, RTLD_FIRST);
1600 #else
1601   return (void*)::dlopen(NULL, RTLD_LAZY);
1602 #endif
1603 }
1604 
1605 // XXX: Do we need a lock around this as per Linux?
1606 void* os::dll_lookup(void* handle, const char* name) {
1607   return dlsym(handle, name);
1608 }
1609 
1610 int _print_dll_info_cb(const char * name, address base_address, address top_address, void * param) {


< prev index next >