src/hotspot/os/solaris/os_solaris.cpp
changeset 55556 19d0b382f086
parent 55325 24c59b1579d7
child 57651 ddae2da329ed
equal deleted inserted replaced
55555:9a5e9537fe1a 55556:19d0b382f086
  1518   if (get_loaded_modules_info(_print_dll_info_cb, (void *)st)) {
  1518   if (get_loaded_modules_info(_print_dll_info_cb, (void *)st)) {
  1519     st->print_cr("Error: Cannot print dynamic libraries.");
  1519     st->print_cr("Error: Cannot print dynamic libraries.");
  1520   }
  1520   }
  1521 }
  1521 }
  1522 
  1522 
       
  1523 static void change_endianness(Elf32_Half& val) {
       
  1524   unsigned char *ptr = (unsigned char *)&val;
       
  1525   unsigned char swp = ptr[0];
       
  1526   ptr[0] = ptr[1];
       
  1527   ptr[1] = swp;
       
  1528 }
       
  1529 
  1523 // Loads .dll/.so and
  1530 // Loads .dll/.so and
  1524 // in case of error it checks if .dll/.so was built for the
  1531 // in case of error it checks if .dll/.so was built for the
  1525 // same architecture as Hotspot is running on
  1532 // same architecture as Hotspot is running on
  1526 
  1533 
  1527 void * os::dll_load(const char *filename, char *ebuf, int ebuflen) {
  1534 void * os::dll_load(const char *filename, char *ebuf, int ebuflen) {
  1566 
  1573 
  1567   ::close(file_descriptor);
  1574   ::close(file_descriptor);
  1568   if (failed_to_read_elf_head) {
  1575   if (failed_to_read_elf_head) {
  1569     // file i/o error - report dlerror() msg
  1576     // file i/o error - report dlerror() msg
  1570     return NULL;
  1577     return NULL;
       
  1578   }
       
  1579 
       
  1580   if (elf_head.e_ident[EI_DATA] != LITTLE_ENDIAN_ONLY(ELFDATA2LSB) BIG_ENDIAN_ONLY(ELFDATA2MSB)) {
       
  1581     // handle invalid/out of range endianness values
       
  1582     if (elf_head.e_ident[EI_DATA] == 0 || elf_head.e_ident[EI_DATA] > 2) {
       
  1583       return NULL;
       
  1584     }
       
  1585     change_endianness(elf_head.e_machine);
  1571   }
  1586   }
  1572 
  1587 
  1573   typedef struct {
  1588   typedef struct {
  1574     Elf32_Half    code;         // Actual value as defined in elf.h
  1589     Elf32_Half    code;         // Actual value as defined in elf.h
  1575     Elf32_Half    compat_class; // Compatibility of archs at VM's sense
  1590     Elf32_Half    compat_class; // Compatibility of archs at VM's sense
  1586     {EM_SPARC,       EM_SPARC,   ELFCLASS32, ELFDATA2MSB, (char*)"Sparc 32"},
  1601     {EM_SPARC,       EM_SPARC,   ELFCLASS32, ELFDATA2MSB, (char*)"Sparc 32"},
  1587     {EM_SPARC32PLUS, EM_SPARC,   ELFCLASS32, ELFDATA2MSB, (char*)"Sparc 32"},
  1602     {EM_SPARC32PLUS, EM_SPARC,   ELFCLASS32, ELFDATA2MSB, (char*)"Sparc 32"},
  1588     {EM_SPARCV9,     EM_SPARCV9, ELFCLASS64, ELFDATA2MSB, (char*)"Sparc v9 64"},
  1603     {EM_SPARCV9,     EM_SPARCV9, ELFCLASS64, ELFDATA2MSB, (char*)"Sparc v9 64"},
  1589     {EM_PPC,         EM_PPC,     ELFCLASS32, ELFDATA2MSB, (char*)"Power PC 32"},
  1604     {EM_PPC,         EM_PPC,     ELFCLASS32, ELFDATA2MSB, (char*)"Power PC 32"},
  1590     {EM_PPC64,       EM_PPC64,   ELFCLASS64, ELFDATA2MSB, (char*)"Power PC 64"},
  1605     {EM_PPC64,       EM_PPC64,   ELFCLASS64, ELFDATA2MSB, (char*)"Power PC 64"},
  1591     {EM_ARM,         EM_ARM,     ELFCLASS32, ELFDATA2LSB, (char*)"ARM 32"}
  1606     {EM_ARM,         EM_ARM,     ELFCLASS32, ELFDATA2LSB, (char*)"ARM"},
       
  1607     // we only support 64 bit z architecture
       
  1608     {EM_S390,        EM_S390,    ELFCLASS64, ELFDATA2MSB, (char*)"IBM System/390"},
       
  1609     {EM_AARCH64,     EM_AARCH64, ELFCLASS64, ELFDATA2LSB, (char*)"AARCH64"}
  1592   };
  1610   };
  1593 
  1611 
  1594 #if  (defined IA32)
  1612 #if  (defined IA32)
  1595   static  Elf32_Half running_arch_code=EM_386;
  1613   static  Elf32_Half running_arch_code=EM_386;
  1596 #elif   (defined AMD64)
  1614 #elif   (defined AMD64)
  1610 #else
  1628 #else
  1611   #error Method os::dll_load requires that one of following is defined:\
  1629   #error Method os::dll_load requires that one of following is defined:\
  1612        IA32, AMD64, IA64, __sparc, __powerpc__, ARM, ARM
  1630        IA32, AMD64, IA64, __sparc, __powerpc__, ARM, ARM
  1613 #endif
  1631 #endif
  1614 
  1632 
  1615   // Identify compatability class for VM's architecture and library's architecture
  1633   // Identify compatibility class for VM's architecture and library's architecture
  1616   // Obtain string descriptions for architectures
  1634   // Obtain string descriptions for architectures
  1617 
  1635 
  1618   arch_t lib_arch={elf_head.e_machine,0,elf_head.e_ident[EI_CLASS], elf_head.e_ident[EI_DATA], NULL};
  1636   arch_t lib_arch={elf_head.e_machine,0,elf_head.e_ident[EI_CLASS], elf_head.e_ident[EI_DATA], NULL};
  1619   int running_arch_index=-1;
  1637   int running_arch_index=-1;
  1620 
  1638 
  1634     // Even though running architecture detection failed
  1652     // Even though running architecture detection failed
  1635     // we may still continue with reporting dlerror() message
  1653     // we may still continue with reporting dlerror() message
  1636     return NULL;
  1654     return NULL;
  1637   }
  1655   }
  1638 
  1656 
       
  1657   if (lib_arch.compat_class != arch_array[running_arch_index].compat_class) {
       
  1658     if (lib_arch.name != NULL) {
       
  1659       ::snprintf(diag_msg_buf, diag_msg_max_length-1,
       
  1660                  " (Possible cause: can't load %s .so on a %s platform)",
       
  1661                  lib_arch.name, arch_array[running_arch_index].name);
       
  1662     } else {
       
  1663       ::snprintf(diag_msg_buf, diag_msg_max_length-1,
       
  1664                  " (Possible cause: can't load this .so (machine code=0x%x) on a %s platform)",
       
  1665                  lib_arch.code, arch_array[running_arch_index].name);
       
  1666     }
       
  1667     return NULL;
       
  1668   }
       
  1669 
  1639   if (lib_arch.endianess != arch_array[running_arch_index].endianess) {
  1670   if (lib_arch.endianess != arch_array[running_arch_index].endianess) {
  1640     ::snprintf(diag_msg_buf, diag_msg_max_length-1," (Possible cause: endianness mismatch)");
  1671     ::snprintf(diag_msg_buf, diag_msg_max_length-1," (Possible cause: endianness mismatch)");
  1641     return NULL;
  1672     return NULL;
  1642   }
  1673   }
  1643 
  1674 
       
  1675   // ELF file class/capacity : 0 - invalid, 1 - 32bit, 2 - 64bit
       
  1676   if (lib_arch.elf_class > 2 || lib_arch.elf_class < 1) {
       
  1677     ::snprintf(diag_msg_buf, diag_msg_max_length-1, " (Possible cause: invalid ELF file class)");
       
  1678     return NULL;
       
  1679   }
       
  1680 
  1644   if (lib_arch.elf_class != arch_array[running_arch_index].elf_class) {
  1681   if (lib_arch.elf_class != arch_array[running_arch_index].elf_class) {
  1645     ::snprintf(diag_msg_buf, diag_msg_max_length-1," (Possible cause: architecture word width mismatch)");
  1682     ::snprintf(diag_msg_buf, diag_msg_max_length-1,
       
  1683                " (Possible cause: architecture word width mismatch, can't load %d-bit .so on a %d-bit platform)",
       
  1684                (int) lib_arch.elf_class * 32, arch_array[running_arch_index].elf_class * 32);
  1646     return NULL;
  1685     return NULL;
  1647   }
       
  1648 
       
  1649   if (lib_arch.compat_class != arch_array[running_arch_index].compat_class) {
       
  1650     if (lib_arch.name!=NULL) {
       
  1651       ::snprintf(diag_msg_buf, diag_msg_max_length-1,
       
  1652                  " (Possible cause: can't load %s-bit .so on a %s-bit platform)",
       
  1653                  lib_arch.name, arch_array[running_arch_index].name);
       
  1654     } else {
       
  1655       ::snprintf(diag_msg_buf, diag_msg_max_length-1,
       
  1656                  " (Possible cause: can't load this .so (machine code=0x%x) on a %s-bit platform)",
       
  1657                  lib_arch.code,
       
  1658                  arch_array[running_arch_index].name);
       
  1659     }
       
  1660   }
  1686   }
  1661 
  1687 
  1662   return NULL;
  1688   return NULL;
  1663 }
  1689 }
  1664 
  1690