< prev index next >

src/hotspot/os/linux/os_linux.cpp

Print this page
rev 47819 : imported patch 10.07.open.rebase_20171110.dcubed


  41 #include "prims/jniFastGetField.hpp"
  42 #include "prims/jvm_misc.hpp"
  43 #include "runtime/arguments.hpp"
  44 #include "runtime/atomic.hpp"
  45 #include "runtime/extendedPC.hpp"
  46 #include "runtime/globals.hpp"
  47 #include "runtime/interfaceSupport.hpp"
  48 #include "runtime/init.hpp"
  49 #include "runtime/java.hpp"
  50 #include "runtime/javaCalls.hpp"
  51 #include "runtime/mutexLocker.hpp"
  52 #include "runtime/objectMonitor.hpp"
  53 #include "runtime/orderAccess.inline.hpp"
  54 #include "runtime/osThread.hpp"
  55 #include "runtime/perfMemory.hpp"
  56 #include "runtime/sharedRuntime.hpp"
  57 #include "runtime/statSampler.hpp"
  58 #include "runtime/stubRoutines.hpp"
  59 #include "runtime/thread.inline.hpp"
  60 #include "runtime/threadCritical.hpp"

  61 #include "runtime/timer.hpp"
  62 #include "semaphore_posix.hpp"
  63 #include "services/attachListener.hpp"
  64 #include "services/memTracker.hpp"
  65 #include "services/runtimeService.hpp"
  66 #include "utilities/align.hpp"
  67 #include "utilities/decoder.hpp"
  68 #include "utilities/defaultStream.hpp"
  69 #include "utilities/events.hpp"
  70 #include "utilities/elfFile.hpp"
  71 #include "utilities/growableArray.hpp"
  72 #include "utilities/macros.hpp"
  73 #include "utilities/vmError.hpp"
  74 
  75 // put OS-includes here
  76 # include <sys/types.h>
  77 # include <sys/mman.h>
  78 # include <sys/stat.h>
  79 # include <sys/select.h>
  80 # include <pthread.h>


1585   void * result = NULL;
1586   bool load_attempted = false;
1587 
1588   // Check whether the library to load might change execution rights
1589   // of the stack. If they are changed, the protection of the stack
1590   // guard pages will be lost. We need a safepoint to fix this.
1591   //
1592   // See Linux man page execstack(8) for more info.
1593   if (os::uses_stack_guard_pages() && !os::Linux::_stack_is_executable) {
1594     if (!ElfFile::specifies_noexecstack(filename)) {
1595       if (!is_init_completed()) {
1596         os::Linux::_stack_is_executable = true;
1597         // This is OK - No Java threads have been created yet, and hence no
1598         // stack guard pages to fix.
1599         //
1600         // This should happen only when you are building JDK7 using a very
1601         // old version of JDK6 (e.g., with JPRT) and running test_gamma.
1602         //
1603         // Dynamic loader will make all stacks executable after
1604         // this function returns, and will not do that again.
1605         assert(Threads::first() == NULL, "no Java threads should exist yet.");



1606       } else {
1607         warning("You have loaded library %s which might have disabled stack guard. "
1608                 "The VM will try to fix the stack guard now.\n"
1609                 "It's highly recommended that you fix the library with "
1610                 "'execstack -c <libfile>', or link it with '-z noexecstack'.",
1611                 filename);
1612 
1613         assert(Thread::current()->is_Java_thread(), "must be Java thread");
1614         JavaThread *jt = JavaThread::current();
1615         if (jt->thread_state() != _thread_in_native) {
1616           // This happens when a compiler thread tries to load a hsdis-<arch>.so file
1617           // that requires ExecStack. Cannot enter safe point. Let's give up.
1618           warning("Unable to fix stack guard. Giving up.");
1619         } else {
1620           if (!LoadExecStackDllInVMThread) {
1621             // This is for the case where the DLL has an static
1622             // constructor function that executes JNI code. We cannot
1623             // load such DLLs in the VMThread.
1624             result = os::Linux::dlopen_helper(filename, ebuf, ebuflen);
1625           }


1813   }
1814   return result;
1815 }
1816 
1817 void * os::Linux::dll_load_in_vmthread(const char *filename, char *ebuf,
1818                                        int ebuflen) {
1819   void * result = NULL;
1820   if (LoadExecStackDllInVMThread) {
1821     result = dlopen_helper(filename, ebuf, ebuflen);
1822   }
1823 
1824   // Since 7019808, libjvm.so is linked with -noexecstack. If the VM loads a
1825   // library that requires an executable stack, or which does not have this
1826   // stack attribute set, dlopen changes the stack attribute to executable. The
1827   // read protection of the guard pages gets lost.
1828   //
1829   // Need to check _stack_is_executable again as multiple VM_LinuxDllLoad
1830   // may have been queued at the same time.
1831 
1832   if (!_stack_is_executable) {
1833     JavaThread *jt = Threads::first();
1834 
1835     while (jt) {
1836       if (!jt->stack_guard_zone_unused() &&     // Stack not yet fully initialized
1837           jt->stack_guards_enabled()) {         // No pending stack overflow exceptions
1838         if (!os::guard_memory((char *)jt->stack_end(), jt->stack_guard_zone_size())) {
1839           warning("Attempt to reguard stack yellow zone failed.");
1840         }
1841       }
1842       jt = jt->next();
1843     }
1844   }
1845 
1846   return result;
1847 }
1848 
1849 void* os::dll_lookup(void* handle, const char* name) {
1850   void* res = dlsym(handle, name);
1851   return res;
1852 }
1853 
1854 void* os::get_default_process_handle() {
1855   return (void*)::dlopen(NULL, RTLD_LAZY);
1856 }
1857 
1858 static bool _print_ascii_file(const char* filename, outputStream* st) {
1859   int fd = ::open(filename, O_RDONLY);
1860   if (fd == -1) {
1861     return false;
1862   }




  41 #include "prims/jniFastGetField.hpp"
  42 #include "prims/jvm_misc.hpp"
  43 #include "runtime/arguments.hpp"
  44 #include "runtime/atomic.hpp"
  45 #include "runtime/extendedPC.hpp"
  46 #include "runtime/globals.hpp"
  47 #include "runtime/interfaceSupport.hpp"
  48 #include "runtime/init.hpp"
  49 #include "runtime/java.hpp"
  50 #include "runtime/javaCalls.hpp"
  51 #include "runtime/mutexLocker.hpp"
  52 #include "runtime/objectMonitor.hpp"
  53 #include "runtime/orderAccess.inline.hpp"
  54 #include "runtime/osThread.hpp"
  55 #include "runtime/perfMemory.hpp"
  56 #include "runtime/sharedRuntime.hpp"
  57 #include "runtime/statSampler.hpp"
  58 #include "runtime/stubRoutines.hpp"
  59 #include "runtime/thread.inline.hpp"
  60 #include "runtime/threadCritical.hpp"
  61 #include "runtime/threadSMR.hpp"
  62 #include "runtime/timer.hpp"
  63 #include "semaphore_posix.hpp"
  64 #include "services/attachListener.hpp"
  65 #include "services/memTracker.hpp"
  66 #include "services/runtimeService.hpp"
  67 #include "utilities/align.hpp"
  68 #include "utilities/decoder.hpp"
  69 #include "utilities/defaultStream.hpp"
  70 #include "utilities/events.hpp"
  71 #include "utilities/elfFile.hpp"
  72 #include "utilities/growableArray.hpp"
  73 #include "utilities/macros.hpp"
  74 #include "utilities/vmError.hpp"
  75 
  76 // put OS-includes here
  77 # include <sys/types.h>
  78 # include <sys/mman.h>
  79 # include <sys/stat.h>
  80 # include <sys/select.h>
  81 # include <pthread.h>


1586   void * result = NULL;
1587   bool load_attempted = false;
1588 
1589   // Check whether the library to load might change execution rights
1590   // of the stack. If they are changed, the protection of the stack
1591   // guard pages will be lost. We need a safepoint to fix this.
1592   //
1593   // See Linux man page execstack(8) for more info.
1594   if (os::uses_stack_guard_pages() && !os::Linux::_stack_is_executable) {
1595     if (!ElfFile::specifies_noexecstack(filename)) {
1596       if (!is_init_completed()) {
1597         os::Linux::_stack_is_executable = true;
1598         // This is OK - No Java threads have been created yet, and hence no
1599         // stack guard pages to fix.
1600         //
1601         // This should happen only when you are building JDK7 using a very
1602         // old version of JDK6 (e.g., with JPRT) and running test_gamma.
1603         //
1604         // Dynamic loader will make all stacks executable after
1605         // this function returns, and will not do that again.
1606 #ifdef ASSERT
1607         ThreadsListHandle tlh;
1608         assert(tlh.length() == 0, "no Java threads should exist yet.");
1609 #endif
1610       } else {
1611         warning("You have loaded library %s which might have disabled stack guard. "
1612                 "The VM will try to fix the stack guard now.\n"
1613                 "It's highly recommended that you fix the library with "
1614                 "'execstack -c <libfile>', or link it with '-z noexecstack'.",
1615                 filename);
1616 
1617         assert(Thread::current()->is_Java_thread(), "must be Java thread");
1618         JavaThread *jt = JavaThread::current();
1619         if (jt->thread_state() != _thread_in_native) {
1620           // This happens when a compiler thread tries to load a hsdis-<arch>.so file
1621           // that requires ExecStack. Cannot enter safe point. Let's give up.
1622           warning("Unable to fix stack guard. Giving up.");
1623         } else {
1624           if (!LoadExecStackDllInVMThread) {
1625             // This is for the case where the DLL has an static
1626             // constructor function that executes JNI code. We cannot
1627             // load such DLLs in the VMThread.
1628             result = os::Linux::dlopen_helper(filename, ebuf, ebuflen);
1629           }


1817   }
1818   return result;
1819 }
1820 
1821 void * os::Linux::dll_load_in_vmthread(const char *filename, char *ebuf,
1822                                        int ebuflen) {
1823   void * result = NULL;
1824   if (LoadExecStackDllInVMThread) {
1825     result = dlopen_helper(filename, ebuf, ebuflen);
1826   }
1827 
1828   // Since 7019808, libjvm.so is linked with -noexecstack. If the VM loads a
1829   // library that requires an executable stack, or which does not have this
1830   // stack attribute set, dlopen changes the stack attribute to executable. The
1831   // read protection of the guard pages gets lost.
1832   //
1833   // Need to check _stack_is_executable again as multiple VM_LinuxDllLoad
1834   // may have been queued at the same time.
1835 
1836   if (!_stack_is_executable) {
1837     for (JavaThreadIteratorWithHandle jtiwh; JavaThread *jt = jtiwh.next(); ) {


1838       if (!jt->stack_guard_zone_unused() &&     // Stack not yet fully initialized
1839           jt->stack_guards_enabled()) {         // No pending stack overflow exceptions
1840         if (!os::guard_memory((char *)jt->stack_end(), jt->stack_guard_zone_size())) {
1841           warning("Attempt to reguard stack yellow zone failed.");
1842         }
1843       }

1844     }
1845   }
1846 
1847   return result;
1848 }
1849 
1850 void* os::dll_lookup(void* handle, const char* name) {
1851   void* res = dlsym(handle, name);
1852   return res;
1853 }
1854 
1855 void* os::get_default_process_handle() {
1856   return (void*)::dlopen(NULL, RTLD_LAZY);
1857 }
1858 
1859 static bool _print_ascii_file(const char* filename, outputStream* st) {
1860   int fd = ::open(filename, O_RDONLY);
1861   if (fd == -1) {
1862     return false;
1863   }


< prev index next >