src/hotspot/os/linux/os_linux.cpp
changeset 55556 19d0b382f086
parent 55325 24c59b1579d7
child 55624 cb90a20eb99a
equal deleted inserted replaced
55555:9a5e9537fe1a 55556:19d0b382f086
    82 # include <sys/mman.h>
    82 # include <sys/mman.h>
    83 # include <sys/stat.h>
    83 # include <sys/stat.h>
    84 # include <sys/select.h>
    84 # include <sys/select.h>
    85 # include <pthread.h>
    85 # include <pthread.h>
    86 # include <signal.h>
    86 # include <signal.h>
       
    87 # include <endian.h>
    87 # include <errno.h>
    88 # include <errno.h>
    88 # include <dlfcn.h>
    89 # include <dlfcn.h>
    89 # include <stdio.h>
    90 # include <stdio.h>
    90 # include <unistd.h>
    91 # include <unistd.h>
    91 # include <sys/resource.h>
    92 # include <sys/resource.h>
  1745   if (failed_to_read_elf_head) {
  1746   if (failed_to_read_elf_head) {
  1746     // file i/o error - report dlerror() msg
  1747     // file i/o error - report dlerror() msg
  1747     return NULL;
  1748     return NULL;
  1748   }
  1749   }
  1749 
  1750 
       
  1751   if (elf_head.e_ident[EI_DATA] != LITTLE_ENDIAN_ONLY(ELFDATA2LSB) BIG_ENDIAN_ONLY(ELFDATA2MSB)) {
       
  1752     // handle invalid/out of range endianness values
       
  1753     if (elf_head.e_ident[EI_DATA] == 0 || elf_head.e_ident[EI_DATA] > 2) {
       
  1754       return NULL;
       
  1755     }
       
  1756 
       
  1757 #if defined(VM_LITTLE_ENDIAN)
       
  1758     // VM is LE, shared object BE
       
  1759     elf_head.e_machine = be16toh(elf_head.e_machine);
       
  1760 #else
       
  1761     // VM is BE, shared object LE
       
  1762     elf_head.e_machine = le16toh(elf_head.e_machine);
       
  1763 #endif
       
  1764   }
       
  1765 
  1750   typedef struct {
  1766   typedef struct {
  1751     Elf32_Half    code;         // Actual value as defined in elf.h
  1767     Elf32_Half    code;         // Actual value as defined in elf.h
  1752     Elf32_Half    compat_class; // Compatibility of archs at VM's sense
  1768     Elf32_Half    compat_class; // Compatibility of archs at VM's sense
  1753     unsigned char elf_class;    // 32 or 64 bit
  1769     unsigned char elf_class;    // 32 or 64 bit
  1754     unsigned char endianess;    // MSB or LSB
  1770     unsigned char endianness;   // MSB or LSB
  1755     char*         name;         // String representation
  1771     char*         name;         // String representation
  1756   } arch_t;
  1772   } arch_t;
  1757 
  1773 
  1758 #ifndef EM_486
  1774 #ifndef EM_486
  1759   #define EM_486          6               /* Intel 80486 */
  1775   #define EM_486          6               /* Intel 80486 */
  1776     {EM_SH,          EM_SH,      ELFCLASS32, ELFDATA2LSB, (char*)"SuperH"},
  1792     {EM_SH,          EM_SH,      ELFCLASS32, ELFDATA2LSB, (char*)"SuperH"},
  1777 #else
  1793 #else
  1778     {EM_PPC64,       EM_PPC64,   ELFCLASS64, ELFDATA2MSB, (char*)"Power PC 64"},
  1794     {EM_PPC64,       EM_PPC64,   ELFCLASS64, ELFDATA2MSB, (char*)"Power PC 64"},
  1779     {EM_SH,          EM_SH,      ELFCLASS32, ELFDATA2MSB, (char*)"SuperH BE"},
  1795     {EM_SH,          EM_SH,      ELFCLASS32, ELFDATA2MSB, (char*)"SuperH BE"},
  1780 #endif
  1796 #endif
  1781     {EM_ARM,         EM_ARM,     ELFCLASS32,   ELFDATA2LSB, (char*)"ARM"},
  1797     {EM_ARM,         EM_ARM,     ELFCLASS32, ELFDATA2LSB, (char*)"ARM"},
  1782     {EM_S390,        EM_S390,    ELFCLASSNONE, ELFDATA2MSB, (char*)"IBM System/390"},
  1798     // we only support 64 bit z architecture
       
  1799     {EM_S390,        EM_S390,    ELFCLASS64, ELFDATA2MSB, (char*)"IBM System/390"},
  1783     {EM_ALPHA,       EM_ALPHA,   ELFCLASS64, ELFDATA2LSB, (char*)"Alpha"},
  1800     {EM_ALPHA,       EM_ALPHA,   ELFCLASS64, ELFDATA2LSB, (char*)"Alpha"},
  1784     {EM_MIPS_RS3_LE, EM_MIPS_RS3_LE, ELFCLASS32, ELFDATA2LSB, (char*)"MIPSel"},
  1801     {EM_MIPS_RS3_LE, EM_MIPS_RS3_LE, ELFCLASS32, ELFDATA2LSB, (char*)"MIPSel"},
  1785     {EM_MIPS,        EM_MIPS,    ELFCLASS32, ELFDATA2MSB, (char*)"MIPS"},
  1802     {EM_MIPS,        EM_MIPS,    ELFCLASS32, ELFDATA2MSB, (char*)"MIPS"},
  1786     {EM_PARISC,      EM_PARISC,  ELFCLASS32, ELFDATA2MSB, (char*)"PARISC"},
  1803     {EM_PARISC,      EM_PARISC,  ELFCLASS32, ELFDATA2MSB, (char*)"PARISC"},
  1787     {EM_68K,         EM_68K,     ELFCLASS32, ELFDATA2MSB, (char*)"M68k"},
  1804     {EM_68K,         EM_68K,     ELFCLASS32, ELFDATA2MSB, (char*)"M68k"},
  1823 #else
  1840 #else
  1824     #error Method os::dll_load requires that one of following is defined:\
  1841     #error Method os::dll_load requires that one of following is defined:\
  1825         AARCH64, ALPHA, ARM, AMD64, IA32, IA64, M68K, MIPS, MIPSEL, PARISC, __powerpc__, __powerpc64__, S390, SH, __sparc
  1842         AARCH64, ALPHA, ARM, AMD64, IA32, IA64, M68K, MIPS, MIPSEL, PARISC, __powerpc__, __powerpc64__, S390, SH, __sparc
  1826 #endif
  1843 #endif
  1827 
  1844 
  1828   // Identify compatability class for VM's architecture and library's architecture
  1845   // Identify compatibility class for VM's architecture and library's architecture
  1829   // Obtain string descriptions for architectures
  1846   // Obtain string descriptions for architectures
  1830 
  1847 
  1831   arch_t lib_arch={elf_head.e_machine,0,elf_head.e_ident[EI_CLASS], elf_head.e_ident[EI_DATA], NULL};
  1848   arch_t lib_arch={elf_head.e_machine,0,elf_head.e_ident[EI_CLASS], elf_head.e_ident[EI_DATA], NULL};
  1832   int running_arch_index=-1;
  1849   int running_arch_index=-1;
  1833 
  1850 
  1847     // Even though running architecture detection failed
  1864     // Even though running architecture detection failed
  1848     // we may still continue with reporting dlerror() message
  1865     // we may still continue with reporting dlerror() message
  1849     return NULL;
  1866     return NULL;
  1850   }
  1867   }
  1851 
  1868 
  1852   if (lib_arch.endianess != arch_array[running_arch_index].endianess) {
       
  1853     ::snprintf(diag_msg_buf, diag_msg_max_length-1," (Possible cause: endianness mismatch)");
       
  1854     return NULL;
       
  1855   }
       
  1856 
       
  1857 #ifndef S390
       
  1858   if (lib_arch.elf_class != arch_array[running_arch_index].elf_class) {
       
  1859     ::snprintf(diag_msg_buf, diag_msg_max_length-1," (Possible cause: architecture word width mismatch)");
       
  1860     return NULL;
       
  1861   }
       
  1862 #endif // !S390
       
  1863 
       
  1864   if (lib_arch.compat_class != arch_array[running_arch_index].compat_class) {
  1869   if (lib_arch.compat_class != arch_array[running_arch_index].compat_class) {
  1865     if (lib_arch.name!=NULL) {
  1870     if (lib_arch.name != NULL) {
  1866       ::snprintf(diag_msg_buf, diag_msg_max_length-1,
  1871       ::snprintf(diag_msg_buf, diag_msg_max_length-1,
  1867                  " (Possible cause: can't load %s-bit .so on a %s-bit platform)",
  1872                  " (Possible cause: can't load %s .so on a %s platform)",
  1868                  lib_arch.name, arch_array[running_arch_index].name);
  1873                  lib_arch.name, arch_array[running_arch_index].name);
  1869     } else {
  1874     } else {
  1870       ::snprintf(diag_msg_buf, diag_msg_max_length-1,
  1875       ::snprintf(diag_msg_buf, diag_msg_max_length-1,
  1871                  " (Possible cause: can't load this .so (machine code=0x%x) on a %s-bit platform)",
  1876                  " (Possible cause: can't load this .so (machine code=0x%x) on a %s platform)",
  1872                  lib_arch.code,
  1877                  lib_arch.code, arch_array[running_arch_index].name);
  1873                  arch_array[running_arch_index].name);
  1878     }
  1874     }
  1879     return NULL;
       
  1880   }
       
  1881 
       
  1882   if (lib_arch.endianness != arch_array[running_arch_index].endianness) {
       
  1883     ::snprintf(diag_msg_buf, diag_msg_max_length-1, " (Possible cause: endianness mismatch)");
       
  1884     return NULL;
       
  1885   }
       
  1886 
       
  1887   // ELF file class/capacity : 0 - invalid, 1 - 32bit, 2 - 64bit
       
  1888   if (lib_arch.elf_class > 2 || lib_arch.elf_class < 1) {
       
  1889     ::snprintf(diag_msg_buf, diag_msg_max_length-1, " (Possible cause: invalid ELF file class)");
       
  1890     return NULL;
       
  1891   }
       
  1892 
       
  1893   if (lib_arch.elf_class != arch_array[running_arch_index].elf_class) {
       
  1894     ::snprintf(diag_msg_buf, diag_msg_max_length-1,
       
  1895                " (Possible cause: architecture word width mismatch, can't load %d-bit .so on a %d-bit platform)",
       
  1896                (int) lib_arch.elf_class * 32, arch_array[running_arch_index].elf_class * 32);
       
  1897     return NULL;
  1875   }
  1898   }
  1876 
  1899 
  1877   return NULL;
  1900   return NULL;
  1878 }
  1901 }
  1879 
  1902