Mercurial > hg > truffle
comparison src/os/linux/vm/os_linux.cpp @ 8858:15c04fe93c18
Merge
author | mgerdin |
---|---|
date | Wed, 03 Apr 2013 09:19:02 +0200 |
parents | 754c24457b20 14509df4cd63 |
children | b9a918201d47 8be1318fbe77 |
comparison
equal
deleted
inserted
replaced
8857:cc5b5976d72c | 8858:15c04fe93c18 |
---|---|
1795 // do not stop the Java threads, they can stack overflow before the stacks | 1795 // do not stop the Java threads, they can stack overflow before the stacks |
1796 // are protected again. | 1796 // are protected again. |
1797 class VM_LinuxDllLoad: public VM_Operation { | 1797 class VM_LinuxDllLoad: public VM_Operation { |
1798 private: | 1798 private: |
1799 const char *_filename; | 1799 const char *_filename; |
1800 char *_ebuf; | |
1801 int _ebuflen; | |
1800 void *_lib; | 1802 void *_lib; |
1801 public: | 1803 public: |
1802 VM_LinuxDllLoad(const char *fn) : | 1804 VM_LinuxDllLoad(const char *fn, char *ebuf, int ebuflen) : |
1803 _filename(fn), _lib(NULL) {} | 1805 _filename(fn), _ebuf(ebuf), _ebuflen(ebuflen), _lib(NULL) {} |
1804 VMOp_Type type() const { return VMOp_LinuxDllLoad; } | 1806 VMOp_Type type() const { return VMOp_LinuxDllLoad; } |
1805 void doit() { | 1807 void doit() { |
1806 _lib = os::Linux::dll_load_inner(_filename); | 1808 _lib = os::Linux::dll_load_in_vmthread(_filename, _ebuf, _ebuflen); |
1807 os::Linux::_stack_is_executable = true; | 1809 os::Linux::_stack_is_executable = true; |
1808 } | 1810 } |
1809 void* loaded_library() { return _lib; } | 1811 void* loaded_library() { return _lib; } |
1810 }; | 1812 }; |
1811 | 1813 |
1849 } else { | 1851 } else { |
1850 if (!LoadExecStackDllInVMThread) { | 1852 if (!LoadExecStackDllInVMThread) { |
1851 // This is for the case where the DLL has an static | 1853 // This is for the case where the DLL has an static |
1852 // constructor function that executes JNI code. We cannot | 1854 // constructor function that executes JNI code. We cannot |
1853 // load such DLLs in the VMThread. | 1855 // load such DLLs in the VMThread. |
1854 result = ::dlopen(filename, RTLD_LAZY); | 1856 result = os::Linux::dlopen_helper(filename, ebuf, ebuflen); |
1855 } | 1857 } |
1856 | 1858 |
1857 ThreadInVMfromNative tiv(jt); | 1859 ThreadInVMfromNative tiv(jt); |
1858 debug_only(VMNativeEntryWrapper vew;) | 1860 debug_only(VMNativeEntryWrapper vew;) |
1859 | 1861 |
1860 VM_LinuxDllLoad op(filename); | 1862 VM_LinuxDllLoad op(filename, ebuf, ebuflen); |
1861 VMThread::execute(&op); | 1863 VMThread::execute(&op); |
1862 if (LoadExecStackDllInVMThread) { | 1864 if (LoadExecStackDllInVMThread) { |
1863 result = op.loaded_library(); | 1865 result = op.loaded_library(); |
1864 } | 1866 } |
1865 load_attempted = true; | 1867 load_attempted = true; |
1867 } | 1869 } |
1868 } | 1870 } |
1869 } | 1871 } |
1870 | 1872 |
1871 if (!load_attempted) { | 1873 if (!load_attempted) { |
1872 result = ::dlopen(filename, RTLD_LAZY); | 1874 result = os::Linux::dlopen_helper(filename, ebuf, ebuflen); |
1873 } | 1875 } |
1874 | 1876 |
1875 if (result != NULL) { | 1877 if (result != NULL) { |
1876 // Successful loading | 1878 // Successful loading |
1877 return result; | 1879 return result; |
1878 } | 1880 } |
1879 | 1881 |
1880 Elf32_Ehdr elf_head; | 1882 Elf32_Ehdr elf_head; |
1881 | |
1882 // Read system error message into ebuf | |
1883 // It may or may not be overwritten below | |
1884 ::strncpy(ebuf, ::dlerror(), ebuflen-1); | |
1885 ebuf[ebuflen-1]='\0'; | |
1886 int diag_msg_max_length=ebuflen-strlen(ebuf); | 1883 int diag_msg_max_length=ebuflen-strlen(ebuf); |
1887 char* diag_msg_buf=ebuf+strlen(ebuf); | 1884 char* diag_msg_buf=ebuf+strlen(ebuf); |
1888 | 1885 |
1889 if (diag_msg_max_length==0) { | 1886 if (diag_msg_max_length==0) { |
1890 // No more space in ebuf for additional diagnostics message | 1887 // No more space in ebuf for additional diagnostics message |
2023 } | 2020 } |
2024 | 2021 |
2025 return NULL; | 2022 return NULL; |
2026 } | 2023 } |
2027 | 2024 |
2028 void * os::Linux::dll_load_inner(const char *filename) { | 2025 void * os::Linux::dlopen_helper(const char *filename, char *ebuf, int ebuflen) { |
2026 void * result = ::dlopen(filename, RTLD_LAZY); | |
2027 if (result == NULL) { | |
2028 ::strncpy(ebuf, ::dlerror(), ebuflen - 1); | |
2029 ebuf[ebuflen-1] = '\0'; | |
2030 } | |
2031 return result; | |
2032 } | |
2033 | |
2034 void * os::Linux::dll_load_in_vmthread(const char *filename, char *ebuf, int ebuflen) { | |
2029 void * result = NULL; | 2035 void * result = NULL; |
2030 if (LoadExecStackDllInVMThread) { | 2036 if (LoadExecStackDllInVMThread) { |
2031 result = ::dlopen(filename, RTLD_LAZY); | 2037 result = dlopen_helper(filename, ebuf, ebuflen); |
2032 } | 2038 } |
2033 | 2039 |
2034 // Since 7019808, libjvm.so is linked with -noexecstack. If the VM loads a | 2040 // Since 7019808, libjvm.so is linked with -noexecstack. If the VM loads a |
2035 // library that requires an executable stack, or which does not have this | 2041 // library that requires an executable stack, or which does not have this |
2036 // stack attribute set, dlopen changes the stack attribute to executable. The | 2042 // stack attribute set, dlopen changes the stack attribute to executable. The |