42 #include "prims/jniFastGetField.hpp"
43 #include "prims/jvm_misc.hpp"
44 #include "runtime/arguments.hpp"
45 #include "runtime/atomic.hpp"
46 #include "runtime/extendedPC.hpp"
47 #include "runtime/globals.hpp"
48 #include "runtime/interfaceSupport.hpp"
49 #include "runtime/init.hpp"
50 #include "runtime/java.hpp"
51 #include "runtime/javaCalls.hpp"
52 #include "runtime/mutexLocker.hpp"
53 #include "runtime/objectMonitor.hpp"
54 #include "runtime/orderAccess.inline.hpp"
55 #include "runtime/osThread.hpp"
56 #include "runtime/perfMemory.hpp"
57 #include "runtime/sharedRuntime.hpp"
58 #include "runtime/statSampler.hpp"
59 #include "runtime/stubRoutines.hpp"
60 #include "runtime/thread.inline.hpp"
61 #include "runtime/threadCritical.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>
1625 void * result = NULL;
1626 bool load_attempted = false;
1627
1628 // Check whether the library to load might change execution rights
1629 // of the stack. If they are changed, the protection of the stack
1630 // guard pages will be lost. We need a safepoint to fix this.
1631 //
1632 // See Linux man page execstack(8) for more info.
1633 if (os::uses_stack_guard_pages() && !os::Linux::_stack_is_executable) {
1634 if (!ElfFile::specifies_noexecstack(filename)) {
1635 if (!is_init_completed()) {
1636 os::Linux::_stack_is_executable = true;
1637 // This is OK - No Java threads have been created yet, and hence no
1638 // stack guard pages to fix.
1639 //
1640 // This should happen only when you are building JDK7 using a very
1641 // old version of JDK6 (e.g., with JPRT) and running test_gamma.
1642 //
1643 // Dynamic loader will make all stacks executable after
1644 // this function returns, and will not do that again.
1645 assert(Threads::first() == NULL, "no Java threads should exist yet.");
1646 } else {
1647 warning("You have loaded library %s which might have disabled stack guard. "
1648 "The VM will try to fix the stack guard now.\n"
1649 "It's highly recommended that you fix the library with "
1650 "'execstack -c <libfile>', or link it with '-z noexecstack'.",
1651 filename);
1652
1653 assert(Thread::current()->is_Java_thread(), "must be Java thread");
1654 JavaThread *jt = JavaThread::current();
1655 if (jt->thread_state() != _thread_in_native) {
1656 // This happens when a compiler thread tries to load a hsdis-<arch>.so file
1657 // that requires ExecStack. Cannot enter safe point. Let's give up.
1658 warning("Unable to fix stack guard. Giving up.");
1659 } else {
1660 if (!LoadExecStackDllInVMThread) {
1661 // This is for the case where the DLL has an static
1662 // constructor function that executes JNI code. We cannot
1663 // load such DLLs in the VMThread.
1664 result = os::Linux::dlopen_helper(filename, ebuf, ebuflen);
1665 }
1853 }
1854 return result;
1855 }
1856
1857 void * os::Linux::dll_load_in_vmthread(const char *filename, char *ebuf,
1858 int ebuflen) {
1859 void * result = NULL;
1860 if (LoadExecStackDllInVMThread) {
1861 result = dlopen_helper(filename, ebuf, ebuflen);
1862 }
1863
1864 // Since 7019808, libjvm.so is linked with -noexecstack. If the VM loads a
1865 // library that requires an executable stack, or which does not have this
1866 // stack attribute set, dlopen changes the stack attribute to executable. The
1867 // read protection of the guard pages gets lost.
1868 //
1869 // Need to check _stack_is_executable again as multiple VM_LinuxDllLoad
1870 // may have been queued at the same time.
1871
1872 if (!_stack_is_executable) {
1873 JavaThread *jt = Threads::first();
1874
1875 while (jt) {
1876 if (!jt->stack_guard_zone_unused() && // Stack not yet fully initialized
1877 jt->stack_guards_enabled()) { // No pending stack overflow exceptions
1878 if (!os::guard_memory((char *)jt->stack_end(), jt->stack_guard_zone_size())) {
1879 warning("Attempt to reguard stack yellow zone failed.");
1880 }
1881 }
1882 jt = jt->next();
1883 }
1884 }
1885
1886 return result;
1887 }
1888
1889 void* os::dll_lookup(void* handle, const char* name) {
1890 void* res = dlsym(handle, name);
1891 return res;
1892 }
1893
1894 void* os::get_default_process_handle() {
1895 return (void*)::dlopen(NULL, RTLD_LAZY);
1896 }
1897
1898 static bool _print_ascii_file(const char* filename, outputStream* st) {
1899 int fd = ::open(filename, O_RDONLY);
1900 if (fd == -1) {
1901 return false;
1902 }
|
42 #include "prims/jniFastGetField.hpp"
43 #include "prims/jvm_misc.hpp"
44 #include "runtime/arguments.hpp"
45 #include "runtime/atomic.hpp"
46 #include "runtime/extendedPC.hpp"
47 #include "runtime/globals.hpp"
48 #include "runtime/interfaceSupport.hpp"
49 #include "runtime/init.hpp"
50 #include "runtime/java.hpp"
51 #include "runtime/javaCalls.hpp"
52 #include "runtime/mutexLocker.hpp"
53 #include "runtime/objectMonitor.hpp"
54 #include "runtime/orderAccess.inline.hpp"
55 #include "runtime/osThread.hpp"
56 #include "runtime/perfMemory.hpp"
57 #include "runtime/sharedRuntime.hpp"
58 #include "runtime/statSampler.hpp"
59 #include "runtime/stubRoutines.hpp"
60 #include "runtime/thread.inline.hpp"
61 #include "runtime/threadCritical.hpp"
62 #include "runtime/threadSMR.hpp"
63 #include "runtime/timer.hpp"
64 #include "semaphore_posix.hpp"
65 #include "services/attachListener.hpp"
66 #include "services/memTracker.hpp"
67 #include "services/runtimeService.hpp"
68 #include "utilities/align.hpp"
69 #include "utilities/decoder.hpp"
70 #include "utilities/defaultStream.hpp"
71 #include "utilities/events.hpp"
72 #include "utilities/elfFile.hpp"
73 #include "utilities/growableArray.hpp"
74 #include "utilities/macros.hpp"
75 #include "utilities/vmError.hpp"
76
77 // put OS-includes here
78 # include <sys/types.h>
79 # include <sys/mman.h>
80 # include <sys/stat.h>
81 # include <sys/select.h>
82 # include <pthread.h>
1626 void * result = NULL;
1627 bool load_attempted = false;
1628
1629 // Check whether the library to load might change execution rights
1630 // of the stack. If they are changed, the protection of the stack
1631 // guard pages will be lost. We need a safepoint to fix this.
1632 //
1633 // See Linux man page execstack(8) for more info.
1634 if (os::uses_stack_guard_pages() && !os::Linux::_stack_is_executable) {
1635 if (!ElfFile::specifies_noexecstack(filename)) {
1636 if (!is_init_completed()) {
1637 os::Linux::_stack_is_executable = true;
1638 // This is OK - No Java threads have been created yet, and hence no
1639 // stack guard pages to fix.
1640 //
1641 // This should happen only when you are building JDK7 using a very
1642 // old version of JDK6 (e.g., with JPRT) and running test_gamma.
1643 //
1644 // Dynamic loader will make all stacks executable after
1645 // this function returns, and will not do that again.
1646 #ifdef ASSERT
1647 ThreadsListHandle tlh;
1648 assert(tlh.length() == 0, "no Java threads should exist yet.");
1649 #endif
1650 } else {
1651 warning("You have loaded library %s which might have disabled stack guard. "
1652 "The VM will try to fix the stack guard now.\n"
1653 "It's highly recommended that you fix the library with "
1654 "'execstack -c <libfile>', or link it with '-z noexecstack'.",
1655 filename);
1656
1657 assert(Thread::current()->is_Java_thread(), "must be Java thread");
1658 JavaThread *jt = JavaThread::current();
1659 if (jt->thread_state() != _thread_in_native) {
1660 // This happens when a compiler thread tries to load a hsdis-<arch>.so file
1661 // that requires ExecStack. Cannot enter safe point. Let's give up.
1662 warning("Unable to fix stack guard. Giving up.");
1663 } else {
1664 if (!LoadExecStackDllInVMThread) {
1665 // This is for the case where the DLL has an static
1666 // constructor function that executes JNI code. We cannot
1667 // load such DLLs in the VMThread.
1668 result = os::Linux::dlopen_helper(filename, ebuf, ebuflen);
1669 }
1857 }
1858 return result;
1859 }
1860
1861 void * os::Linux::dll_load_in_vmthread(const char *filename, char *ebuf,
1862 int ebuflen) {
1863 void * result = NULL;
1864 if (LoadExecStackDllInVMThread) {
1865 result = dlopen_helper(filename, ebuf, ebuflen);
1866 }
1867
1868 // Since 7019808, libjvm.so is linked with -noexecstack. If the VM loads a
1869 // library that requires an executable stack, or which does not have this
1870 // stack attribute set, dlopen changes the stack attribute to executable. The
1871 // read protection of the guard pages gets lost.
1872 //
1873 // Need to check _stack_is_executable again as multiple VM_LinuxDllLoad
1874 // may have been queued at the same time.
1875
1876 if (!_stack_is_executable) {
1877 for (JavaThreadIteratorWithHandle jtiwh; JavaThread *jt = jtiwh.next(); ) {
1878 if (!jt->stack_guard_zone_unused() && // Stack not yet fully initialized
1879 jt->stack_guards_enabled()) { // No pending stack overflow exceptions
1880 if (!os::guard_memory((char *)jt->stack_end(), jt->stack_guard_zone_size())) {
1881 warning("Attempt to reguard stack yellow zone failed.");
1882 }
1883 }
1884 }
1885 }
1886
1887 return result;
1888 }
1889
1890 void* os::dll_lookup(void* handle, const char* name) {
1891 void* res = dlsym(handle, name);
1892 return res;
1893 }
1894
1895 void* os::get_default_process_handle() {
1896 return (void*)::dlopen(NULL, RTLD_LAZY);
1897 }
1898
1899 static bool _print_ascii_file(const char* filename, outputStream* st) {
1900 int fd = ::open(filename, O_RDONLY);
1901 if (fd == -1) {
1902 return false;
1903 }
|