Merge

Fri, 08 Mar 2013 17:14:22 -0800

author
dcubed
date
Fri, 08 Mar 2013 17:14:22 -0800
changeset 4713
252ad8d5f22b
parent 4708
8196357e95b5
parent 4711
6b803ba47588
child 4714
35ef86296a5d

Merge

src/os/bsd/vm/os_bsd.cpp file | annotate | diff | comparison | revisions
     1.1 --- a/agent/src/os/linux/ps_core.c	Fri Mar 08 08:22:18 2013 -0800
     1.2 +++ b/agent/src/os/linux/ps_core.c	Fri Mar 08 17:14:22 2013 -0800
     1.3 @@ -132,12 +132,12 @@
     1.4  }
     1.5  
     1.6  // Part of the class sharing workaround
     1.7 -static map_info* add_class_share_map_info(struct ps_prochandle* ph, off_t offset,
     1.8 +static void add_class_share_map_info(struct ps_prochandle* ph, off_t offset,
     1.9                               uintptr_t vaddr, size_t memsz) {
    1.10     map_info* map;
    1.11     if ((map = allocate_init_map(ph->core->classes_jsa_fd,
    1.12                                  offset, vaddr, memsz)) == NULL) {
    1.13 -      return NULL;
    1.14 +      return;
    1.15     }
    1.16  
    1.17     map->next = ph->core->class_share_maps;
     2.1 --- a/src/os/bsd/vm/os_bsd.cpp	Fri Mar 08 08:22:18 2013 -0800
     2.2 +++ b/src/os/bsd/vm/os_bsd.cpp	Fri Mar 08 17:14:22 2013 -0800
     2.3 @@ -57,6 +57,7 @@
     2.4  #include "runtime/threadCritical.hpp"
     2.5  #include "runtime/timer.hpp"
     2.6  #include "services/attachListener.hpp"
     2.7 +#include "services/memTracker.hpp"
     2.8  #include "services/runtimeService.hpp"
     2.9  #include "utilities/decoder.hpp"
    2.10  #include "utilities/defaultStream.hpp"
    2.11 @@ -2275,13 +2276,25 @@
    2.12       return NULL;
    2.13    }
    2.14  
    2.15 +  // The memory is committed
    2.16 +  address pc = CALLER_PC;
    2.17 +  MemTracker::record_virtual_memory_reserve((address)addr, bytes, pc);
    2.18 +  MemTracker::record_virtual_memory_commit((address)addr, bytes, pc);
    2.19 +
    2.20    return addr;
    2.21  }
    2.22  
    2.23  bool os::release_memory_special(char* base, size_t bytes) {
    2.24    // detaching the SHM segment will also delete it, see reserve_memory_special()
    2.25    int rslt = shmdt(base);
    2.26 -  return rslt == 0;
    2.27 +  if (rslt == 0) {
    2.28 +    MemTracker::record_virtual_memory_uncommit((address)base, bytes);
    2.29 +    MemTracker::record_virtual_memory_release((address)base, bytes);
    2.30 +    return true;
    2.31 +  } else {
    2.32 +    return false;
    2.33 +  }
    2.34 +
    2.35  }
    2.36  
    2.37  size_t os::large_page_size() {
     3.1 --- a/src/os/linux/vm/globals_linux.hpp	Fri Mar 08 08:22:18 2013 -0800
     3.2 +++ b/src/os/linux/vm/globals_linux.hpp	Fri Mar 08 17:14:22 2013 -0800
     3.3 @@ -1,5 +1,5 @@
     3.4  /*
     3.5 - * Copyright (c) 2005, 2011, Oracle and/or its affiliates. All rights reserved.
     3.6 + * Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved.
     3.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3.8   *
     3.9   * This code is free software; you can redistribute it and/or modify it
    3.10 @@ -40,6 +40,9 @@
    3.11    product(bool, UseHugeTLBFS, false,                                    \
    3.12            "Use MAP_HUGETLB for large pages")                            \
    3.13                                                                          \
    3.14 +  product(bool, LoadExecStackDllInVMThread, true,                       \
    3.15 +          "Load DLLs with executable-stack attribute in the VM Thread") \
    3.16 +                                                                        \
    3.17    product(bool, UseSHM, false,                                          \
    3.18            "Use SYSV shared memory for large pages")
    3.19  
     4.1 --- a/src/os/linux/vm/os_linux.cpp	Fri Mar 08 08:22:18 2013 -0800
     4.2 +++ b/src/os/linux/vm/os_linux.cpp	Fri Mar 08 17:14:22 2013 -0800
     4.3 @@ -44,6 +44,7 @@
     4.4  #include "runtime/extendedPC.hpp"
     4.5  #include "runtime/globals.hpp"
     4.6  #include "runtime/interfaceSupport.hpp"
     4.7 +#include "runtime/init.hpp"
     4.8  #include "runtime/java.hpp"
     4.9  #include "runtime/javaCalls.hpp"
    4.10  #include "runtime/mutexLocker.hpp"
    4.11 @@ -57,10 +58,12 @@
    4.12  #include "runtime/threadCritical.hpp"
    4.13  #include "runtime/timer.hpp"
    4.14  #include "services/attachListener.hpp"
    4.15 +#include "services/memTracker.hpp"
    4.16  #include "services/runtimeService.hpp"
    4.17  #include "utilities/decoder.hpp"
    4.18  #include "utilities/defaultStream.hpp"
    4.19  #include "utilities/events.hpp"
    4.20 +#include "utilities/elfFile.hpp"
    4.21  #include "utilities/growableArray.hpp"
    4.22  #include "utilities/vmError.hpp"
    4.23  
    4.24 @@ -1796,9 +1799,93 @@
    4.25    // in case of error it checks if .dll/.so was built for the
    4.26    // same architecture as Hotspot is running on
    4.27  
    4.28 +
    4.29 +// Remember the stack's state. The Linux dynamic linker will change
    4.30 +// the stack to 'executable' at most once, so we must safepoint only once.
    4.31 +bool os::Linux::_stack_is_executable = false;
    4.32 +
    4.33 +// VM operation that loads a library.  This is necessary if stack protection
    4.34 +// of the Java stacks can be lost during loading the library.  If we
    4.35 +// do not stop the Java threads, they can stack overflow before the stacks
    4.36 +// are protected again.
    4.37 +class VM_LinuxDllLoad: public VM_Operation {
    4.38 + private:
    4.39 +  const char *_filename;
    4.40 +  void *_lib;
    4.41 + public:
    4.42 +  VM_LinuxDllLoad(const char *fn) :
    4.43 +    _filename(fn), _lib(NULL) {}
    4.44 +  VMOp_Type type() const { return VMOp_LinuxDllLoad; }
    4.45 +  void doit() {
    4.46 +    _lib = os::Linux::dll_load_inner(_filename);
    4.47 +    os::Linux::_stack_is_executable = true;
    4.48 +  }
    4.49 +  void* loaded_library() { return _lib; }
    4.50 +};
    4.51 +
    4.52  void * os::dll_load(const char *filename, char *ebuf, int ebuflen)
    4.53  {
    4.54 -  void * result= ::dlopen(filename, RTLD_LAZY);
    4.55 +  void * result = NULL;
    4.56 +  bool load_attempted = false;
    4.57 +
    4.58 +  // Check whether the library to load might change execution rights
    4.59 +  // of the stack. If they are changed, the protection of the stack
    4.60 +  // guard pages will be lost. We need a safepoint to fix this.
    4.61 +  //
    4.62 +  // See Linux man page execstack(8) for more info.
    4.63 +  if (os::uses_stack_guard_pages() && !os::Linux::_stack_is_executable) {
    4.64 +    ElfFile ef(filename);
    4.65 +    if (!ef.specifies_noexecstack()) {
    4.66 +      if (!is_init_completed()) {
    4.67 +        os::Linux::_stack_is_executable = true;
    4.68 +        // This is OK - No Java threads have been created yet, and hence no
    4.69 +        // stack guard pages to fix.
    4.70 +        //
    4.71 +        // This should happen only when you are building JDK7 using a very
    4.72 +        // old version of JDK6 (e.g., with JPRT) and running test_gamma.
    4.73 +        //
    4.74 +        // Dynamic loader will make all stacks executable after
    4.75 +        // this function returns, and will not do that again.
    4.76 +        assert(Threads::first() == NULL, "no Java threads should exist yet.");
    4.77 +      } else {
    4.78 +        warning("You have loaded library %s which might have disabled stack guard. "
    4.79 +                "The VM will try to fix the stack guard now.\n"
    4.80 +                "It's highly recommended that you fix the library with "
    4.81 +                "'execstack -c <libfile>', or link it with '-z noexecstack'.",
    4.82 +                filename);
    4.83 +
    4.84 +        assert(Thread::current()->is_Java_thread(), "must be Java thread");
    4.85 +        JavaThread *jt = JavaThread::current();
    4.86 +        if (jt->thread_state() != _thread_in_native) {
    4.87 +          // This happens when a compiler thread tries to load a hsdis-<arch>.so file
    4.88 +          // that requires ExecStack. Cannot enter safe point. Let's give up.
    4.89 +          warning("Unable to fix stack guard. Giving up.");
    4.90 +        } else {
    4.91 +          if (!LoadExecStackDllInVMThread) {
    4.92 +            // This is for the case where the DLL has an static
    4.93 +            // constructor function that executes JNI code. We cannot
    4.94 +            // load such DLLs in the VMThread.
    4.95 +            result = ::dlopen(filename, RTLD_LAZY);
    4.96 +          }
    4.97 +
    4.98 +          ThreadInVMfromNative tiv(jt);
    4.99 +          debug_only(VMNativeEntryWrapper vew;)
   4.100 +
   4.101 +          VM_LinuxDllLoad op(filename);
   4.102 +          VMThread::execute(&op);
   4.103 +          if (LoadExecStackDllInVMThread) {
   4.104 +            result = op.loaded_library();
   4.105 +          }
   4.106 +          load_attempted = true;
   4.107 +        }
   4.108 +      }
   4.109 +    }
   4.110 +  }
   4.111 +
   4.112 +  if (!load_attempted) {
   4.113 +    result = ::dlopen(filename, RTLD_LAZY);
   4.114 +  }
   4.115 +
   4.116    if (result != NULL) {
   4.117      // Successful loading
   4.118      return result;
   4.119 @@ -1952,6 +2039,38 @@
   4.120    return NULL;
   4.121  }
   4.122  
   4.123 +void * os::Linux::dll_load_inner(const char *filename) {
   4.124 +  void * result = NULL;
   4.125 +  if (LoadExecStackDllInVMThread) {
   4.126 +    result = ::dlopen(filename, RTLD_LAZY);
   4.127 +  }
   4.128 +
   4.129 +  // Since 7019808, libjvm.so is linked with -noexecstack. If the VM loads a
   4.130 +  // library that requires an executable stack, or which does not have this
   4.131 +  // stack attribute set, dlopen changes the stack attribute to executable. The
   4.132 +  // read protection of the guard pages gets lost.
   4.133 +  //
   4.134 +  // Need to check _stack_is_executable again as multiple VM_LinuxDllLoad
   4.135 +  // may have been queued at the same time.
   4.136 +
   4.137 +  if (!_stack_is_executable) {
   4.138 +    JavaThread *jt = Threads::first();
   4.139 +
   4.140 +    while (jt) {
   4.141 +      if (!jt->stack_guard_zone_unused() &&        // Stack not yet fully initialized
   4.142 +          jt->stack_yellow_zone_enabled()) {       // No pending stack overflow exceptions
   4.143 +        if (!os::guard_memory((char *) jt->stack_red_zone_base() - jt->stack_red_zone_size(),
   4.144 +                              jt->stack_yellow_zone_size() + jt->stack_red_zone_size())) {
   4.145 +          warning("Attempt to reguard stack yellow zone failed.");
   4.146 +        }
   4.147 +      }
   4.148 +      jt = jt->next();
   4.149 +    }
   4.150 +  }
   4.151 +
   4.152 +  return result;
   4.153 +}
   4.154 +
   4.155  /*
   4.156   * glibc-2.0 libdl is not MT safe.  If you are building with any glibc,
   4.157   * chances are you might want to run the generated bits against glibc-2.0
   4.158 @@ -3094,13 +3213,24 @@
   4.159      numa_make_global(addr, bytes);
   4.160    }
   4.161  
   4.162 +  // The memory is committed
   4.163 +  address pc = CALLER_PC;
   4.164 +  MemTracker::record_virtual_memory_reserve((address)addr, bytes, pc);
   4.165 +  MemTracker::record_virtual_memory_commit((address)addr, bytes, pc);
   4.166 +
   4.167    return addr;
   4.168  }
   4.169  
   4.170  bool os::release_memory_special(char* base, size_t bytes) {
   4.171    // detaching the SHM segment will also delete it, see reserve_memory_special()
   4.172    int rslt = shmdt(base);
   4.173 -  return rslt == 0;
   4.174 +  if (rslt == 0) {
   4.175 +    MemTracker::record_virtual_memory_uncommit((address)base, bytes);
   4.176 +    MemTracker::record_virtual_memory_release((address)base, bytes);
   4.177 +    return true;
   4.178 +  } else {
   4.179 +   return false;
   4.180 +  }
   4.181  }
   4.182  
   4.183  size_t os::large_page_size() {
     5.1 --- a/src/os/linux/vm/os_linux.hpp	Fri Mar 08 08:22:18 2013 -0800
     5.2 +++ b/src/os/linux/vm/os_linux.hpp	Fri Mar 08 17:14:22 2013 -0800
     5.3 @@ -94,6 +94,9 @@
     5.4    static void print_libversion_info(outputStream* st);
     5.5  
     5.6   public:
     5.7 +  static bool _stack_is_executable;
     5.8 +  static void *dll_load_inner(const char *name);
     5.9 +
    5.10    static void init_thread_fpu_state();
    5.11    static int  get_fpu_control_word();
    5.12    static void set_fpu_control_word(int fpu_control);
     6.1 --- a/src/os/solaris/vm/os_solaris.cpp	Fri Mar 08 08:22:18 2013 -0800
     6.2 +++ b/src/os/solaris/vm/os_solaris.cpp	Fri Mar 08 17:14:22 2013 -0800
     6.3 @@ -3420,13 +3420,25 @@
     6.4    if ((retAddr != NULL) && UseNUMAInterleaving) {
     6.5      numa_make_global(retAddr, size);
     6.6    }
     6.7 +
     6.8 +  // The memory is committed
     6.9 +  address pc = CALLER_PC;
    6.10 +  MemTracker::record_virtual_memory_reserve((address)retAddr, size, pc);
    6.11 +  MemTracker::record_virtual_memory_commit((address)retAddr, size, pc);
    6.12 +
    6.13    return retAddr;
    6.14  }
    6.15  
    6.16  bool os::release_memory_special(char* base, size_t bytes) {
    6.17    // detaching the SHM segment will also delete it, see reserve_memory_special()
    6.18    int rslt = shmdt(base);
    6.19 -  return rslt == 0;
    6.20 +  if (rslt == 0) {
    6.21 +    MemTracker::record_virtual_memory_uncommit((address)base, bytes);
    6.22 +    MemTracker::record_virtual_memory_release((address)base, bytes);
    6.23 +    return true;
    6.24 +  } else {
    6.25 +   return false;
    6.26 +  }
    6.27  }
    6.28  
    6.29  size_t os::large_page_size() {
     7.1 --- a/src/os/windows/vm/os_windows.cpp	Fri Mar 08 08:22:18 2013 -0800
     7.2 +++ b/src/os/windows/vm/os_windows.cpp	Fri Mar 08 17:14:22 2013 -0800
     7.3 @@ -60,6 +60,7 @@
     7.4  #include "runtime/threadCritical.hpp"
     7.5  #include "runtime/timer.hpp"
     7.6  #include "services/attachListener.hpp"
     7.7 +#include "services/memTracker.hpp"
     7.8  #include "services/runtimeService.hpp"
     7.9  #include "utilities/decoder.hpp"
    7.10  #include "utilities/defaultStream.hpp"
    7.11 @@ -2836,7 +2837,7 @@
    7.12                                  PAGE_READWRITE);
    7.13    // If reservation failed, return NULL
    7.14    if (p_buf == NULL) return NULL;
    7.15 -
    7.16 +  MemTracker::record_virtual_memory_reserve((address)p_buf, size_of_reserve, CALLER_PC);
    7.17    os::release_memory(p_buf, bytes + chunk_size);
    7.18  
    7.19    // we still need to round up to a page boundary (in case we are using large pages)
    7.20 @@ -2898,6 +2899,11 @@
    7.21        if (next_alloc_addr > p_buf) {
    7.22          // Some memory was committed so release it.
    7.23          size_t bytes_to_release = bytes - bytes_remaining;
    7.24 +        // NMT has yet to record any individual blocks, so it
    7.25 +        // need to create a dummy 'reserve' record to match
    7.26 +        // the release.
    7.27 +        MemTracker::record_virtual_memory_reserve((address)p_buf,
    7.28 +          bytes_to_release, CALLER_PC);
    7.29          os::release_memory(p_buf, bytes_to_release);
    7.30        }
    7.31  #ifdef ASSERT
    7.32 @@ -2909,10 +2915,19 @@
    7.33  #endif
    7.34        return NULL;
    7.35      }
    7.36 +
    7.37      bytes_remaining -= bytes_to_rq;
    7.38      next_alloc_addr += bytes_to_rq;
    7.39      count++;
    7.40    }
    7.41 +  // Although the memory is allocated individually, it is returned as one.
    7.42 +  // NMT records it as one block.
    7.43 +  address pc = CALLER_PC;
    7.44 +  MemTracker::record_virtual_memory_reserve((address)p_buf, bytes, pc);
    7.45 +  if ((flags & MEM_COMMIT) != 0) {
    7.46 +    MemTracker::record_virtual_memory_commit((address)p_buf, bytes, pc);
    7.47 +  }
    7.48 +
    7.49    // made it this far, success
    7.50    return p_buf;
    7.51  }
    7.52 @@ -3099,11 +3114,20 @@
    7.53      // normal policy just allocate it all at once
    7.54      DWORD flag = MEM_RESERVE | MEM_COMMIT | MEM_LARGE_PAGES;
    7.55      char * res = (char *)VirtualAlloc(NULL, bytes, flag, prot);
    7.56 +    if (res != NULL) {
    7.57 +      address pc = CALLER_PC;
    7.58 +      MemTracker::record_virtual_memory_reserve((address)res, bytes, pc);
    7.59 +      MemTracker::record_virtual_memory_commit((address)res, bytes, pc);
    7.60 +    }
    7.61 +
    7.62      return res;
    7.63    }
    7.64  }
    7.65  
    7.66  bool os::release_memory_special(char* base, size_t bytes) {
    7.67 +  assert(base != NULL, "Sanity check");
    7.68 +  // Memory allocated via reserve_memory_special() is committed
    7.69 +  MemTracker::record_virtual_memory_uncommit((address)base, bytes);
    7.70    return release_memory(base, bytes);
    7.71  }
    7.72  
     8.1 --- a/src/os_cpu/linux_sparc/vm/os_linux_sparc.cpp	Fri Mar 08 08:22:18 2013 -0800
     8.2 +++ b/src/os_cpu/linux_sparc/vm/os_linux_sparc.cpp	Fri Mar 08 17:14:22 2013 -0800
     8.3 @@ -410,6 +410,11 @@
     8.4        // to handle_unexpected_exception way down below.
     8.5        thread->disable_stack_red_zone();
     8.6        tty->print_raw_cr("An irrecoverable stack overflow has occurred.");
     8.7 +
     8.8 +      // This is a likely cause, but hard to verify. Let's just print
     8.9 +      // it as a hint.
    8.10 +      tty->print_raw_cr("Please check if any of your loaded .so files has "
    8.11 +                        "enabled executable stack (see man page execstack(8))");
    8.12      } else {
    8.13        // Accessing stack address below sp may cause SEGV if current
    8.14        // thread has MAP_GROWSDOWN stack. This should only happen when
     9.1 --- a/src/os_cpu/linux_x86/vm/os_linux_x86.cpp	Fri Mar 08 08:22:18 2013 -0800
     9.2 +++ b/src/os_cpu/linux_x86/vm/os_linux_x86.cpp	Fri Mar 08 17:14:22 2013 -0800
     9.3 @@ -305,6 +305,11 @@
     9.4            // to handle_unexpected_exception way down below.
     9.5            thread->disable_stack_red_zone();
     9.6            tty->print_raw_cr("An irrecoverable stack overflow has occurred.");
     9.7 +
     9.8 +          // This is a likely cause, but hard to verify. Let's just print
     9.9 +          // it as a hint.
    9.10 +          tty->print_raw_cr("Please check if any of your loaded .so files has "
    9.11 +                            "enabled executable stack (see man page execstack(8))");
    9.12          } else {
    9.13            // Accessing stack address below sp may cause SEGV if current
    9.14            // thread has MAP_GROWSDOWN stack. This should only happen when
    10.1 --- a/src/share/vm/runtime/thread.hpp	Fri Mar 08 08:22:18 2013 -0800
    10.2 +++ b/src/share/vm/runtime/thread.hpp	Fri Mar 08 17:14:22 2013 -0800
    10.3 @@ -1,5 +1,5 @@
    10.4  /*
    10.5 - * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
    10.6 + * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
    10.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    10.8   *
    10.9   * This code is free software; you can redistribute it and/or modify it
   10.10 @@ -1289,6 +1289,7 @@
   10.11    void enable_stack_red_zone();
   10.12    void disable_stack_red_zone();
   10.13  
   10.14 +  inline bool stack_guard_zone_unused();
   10.15    inline bool stack_yellow_zone_disabled();
   10.16    inline bool stack_yellow_zone_enabled();
   10.17  
   10.18 @@ -1759,6 +1760,10 @@
   10.19    return (CompilerThread*)this;
   10.20  }
   10.21  
   10.22 +inline bool JavaThread::stack_guard_zone_unused() {
   10.23 +  return _stack_guard_state == stack_guard_unused;
   10.24 +}
   10.25 +
   10.26  inline bool JavaThread::stack_yellow_zone_disabled() {
   10.27    return _stack_guard_state == stack_guard_yellow_disabled;
   10.28  }
    11.1 --- a/src/share/vm/runtime/vm_operations.hpp	Fri Mar 08 08:22:18 2013 -0800
    11.2 +++ b/src/share/vm/runtime/vm_operations.hpp	Fri Mar 08 17:14:22 2013 -0800
    11.3 @@ -94,6 +94,7 @@
    11.4    template(ReportJavaOutOfMemory)                 \
    11.5    template(JFRCheckpoint)                         \
    11.6    template(Exit)                                  \
    11.7 +  template(LinuxDllLoad)                          \
    11.8  
    11.9  class VM_Operation: public CHeapObj<mtInternal> {
   11.10   public:
    12.1 --- a/src/share/vm/utilities/elfFile.cpp	Fri Mar 08 08:22:18 2013 -0800
    12.2 +++ b/src/share/vm/utilities/elfFile.cpp	Fri Mar 08 17:14:22 2013 -0800
    12.3 @@ -197,4 +197,28 @@
    12.4    return NULL;
    12.5  }
    12.6  
    12.7 +#ifdef LINUX
    12.8 +bool ElfFile::specifies_noexecstack() {
    12.9 +  Elf_Phdr phdr;
   12.10 +  if (!m_file)  return true;
   12.11 +
   12.12 +  if (!fseek(m_file, m_elfHdr.e_phoff, SEEK_SET)) {
   12.13 +    for (int index = 0; index < m_elfHdr.e_phnum; index ++) {
   12.14 +      if (fread((void*)&phdr, sizeof(Elf_Phdr), 1, m_file) != 1) {
   12.15 +        m_status = NullDecoder::file_invalid;
   12.16 +        return false;
   12.17 +      }
   12.18 +      if (phdr.p_type == PT_GNU_STACK) {
   12.19 +        if (phdr.p_flags == (PF_R | PF_W))  {
   12.20 +          return true;
   12.21 +        } else {
   12.22 +          return false;
   12.23 +        }
   12.24 +      }
   12.25 +    }
   12.26 +  }
   12.27 +  return false;
   12.28 +}
   12.29 +#endif
   12.30 +
   12.31  #endif // _WINDOWS
    13.1 --- a/src/share/vm/utilities/elfFile.hpp	Fri Mar 08 08:22:18 2013 -0800
    13.2 +++ b/src/share/vm/utilities/elfFile.hpp	Fri Mar 08 17:14:22 2013 -0800
    13.3 @@ -43,6 +43,7 @@
    13.4  
    13.5  typedef Elf64_Ehdr      Elf_Ehdr;
    13.6  typedef Elf64_Shdr      Elf_Shdr;
    13.7 +typedef Elf64_Phdr      Elf_Phdr;
    13.8  typedef Elf64_Sym       Elf_Sym;
    13.9  
   13.10  #if !defined(_ALLBSD_SOURCE) || defined(__APPLE__)
   13.11 @@ -59,6 +60,7 @@
   13.12  
   13.13  typedef Elf32_Ehdr      Elf_Ehdr;
   13.14  typedef Elf32_Shdr      Elf_Shdr;
   13.15 +typedef Elf32_Phdr      Elf_Phdr;
   13.16  typedef Elf32_Sym       Elf_Sym;
   13.17  
   13.18  #if !defined(_ALLBSD_SOURCE) || defined(__APPLE__)
   13.19 @@ -123,6 +125,14 @@
   13.20     ElfFile*  next() const { return m_next; }
   13.21     void set_next(ElfFile* file) { m_next = file; }
   13.22  
   13.23 + public:
   13.24 +  // Returns true if the elf file is marked NOT to require an executable stack,
   13.25 +  // or if the file could not be opened.
   13.26 +  // Returns false if the elf file requires an executable stack, the stack flag
   13.27 +  // is not set at all, or if the file can not be read.
   13.28 +  // On systems other than linux it always returns false.
   13.29 +  bool specifies_noexecstack() NOT_LINUX({ return false; });
   13.30 +
   13.31   protected:
   13.32      ElfFile*         m_next;
   13.33  
    14.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    14.2 +++ b/test/runtime/7107135/Test.java	Fri Mar 08 17:14:22 2013 -0800
    14.3 @@ -0,0 +1,65 @@
    14.4 +/*
    14.5 + * Copyright (c) 2002-2013, Oracle and/or its affiliates. All rights reserved.
    14.6 + * Copyright (c) 2011 SAP AG.  All Rights Reserved.
    14.7 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    14.8 + *
    14.9 + * This code is free software; you can redistribute it and/or modify it
   14.10 + * under the terms of the GNU General Public License version 2 only, as
   14.11 + * published by the Free Software Foundation.
   14.12 + *
   14.13 + * This code is distributed in the hope that it will be useful, but WITHOUT
   14.14 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   14.15 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   14.16 + * version 2 for more details (a copy is included in the LICENSE file that
   14.17 + * accompanied this code).
   14.18 + *
   14.19 + * You should have received a copy of the GNU General Public License version
   14.20 + * 2 along with this work; if not, write to the Free Software Foundation,
   14.21 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   14.22 + *
   14.23 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   14.24 + * or visit www.oracle.com if you need additional information or have any
   14.25 + * questions.
   14.26 + */
   14.27 +
   14.28 +class Test {
   14.29 +
   14.30 +    static boolean loadLib(String libName){
   14.31 +        try {
   14.32 +            System.loadLibrary(libName);
   14.33 +            System.out.println("Loaded library "+ libName + ".");
   14.34 +            return true;
   14.35 +        } catch (SecurityException e) {
   14.36 +            System.out.println("loadLibrary(\"" + libName + "\") throws: " + e + "\n");
   14.37 +        } catch (UnsatisfiedLinkError e) {
   14.38 +            System.out.println("loadLibrary(\"" + libName + "\") throws: " + e + "\n");
   14.39 +        }
   14.40 +        return false;
   14.41 +    }
   14.42 +
   14.43 +    public static int counter = 1;
   14.44 +
   14.45 +    static int Runner() {
   14.46 +        counter = counter * -1;
   14.47 +        int i = counter;
   14.48 +        if(counter < 2) counter += Runner();
   14.49 +        return i;
   14.50 +    }
   14.51 +
   14.52 +    public static int run() {
   14.53 +        try{
   14.54 +            Runner();
   14.55 +        } catch (StackOverflowError e) {
   14.56 +            System.out.println("Caught stack overflow error.");
   14.57 +            return 0;
   14.58 +        } catch (OutOfMemoryError e) {
   14.59 +            return 0;
   14.60 +        }
   14.61 +        return 2;
   14.62 +    }
   14.63 +
   14.64 +    public static void main(String argv[]) {
   14.65 +        loadLib(argv[0]);
   14.66 +        System.exit(run());
   14.67 +    }
   14.68 +}
    15.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    15.2 +++ b/test/runtime/7107135/Test7107135.sh	Fri Mar 08 17:14:22 2013 -0800
    15.3 @@ -0,0 +1,98 @@
    15.4 +#!/bin/sh
    15.5 +
    15.6 +#
    15.7 +#  Copyright (c) 1998, 2013, Oracle and/or its affiliates. All rights reserved.
    15.8 +#  Copyright (c) 2011 SAP AG.  All Rights Reserved.
    15.9 +#  DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   15.10 +#
   15.11 +#  This code is free software; you can redistribute it and/or modify it
   15.12 +#  under the terms of the GNU General Public License version 2 only, as
   15.13 +#  published by the Free Software Foundation.
   15.14 +#
   15.15 +#  This code is distributed in the hope that it will be useful, but WITHOUT
   15.16 +#  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   15.17 +#  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   15.18 +#  version 2 for more details (a copy is included in the LICENSE file that
   15.19 +#  accompanied this code).
   15.20 +#
   15.21 +#  You should have received a copy of the GNU General Public License version
   15.22 +#  2 along with this work; if not, write to the Free Software Foundation,
   15.23 +#  Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   15.24 +#
   15.25 +#  Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   15.26 +#  or visit www.oracle.com if you need additional information or have any
   15.27 +#  questions.
   15.28 +#
   15.29 +
   15.30 +##
   15.31 +## @test Test7107135.sh
   15.32 +## @bug 7107135
   15.33 +## @summary Stack guard pages lost after loading library with executable stack.
   15.34 +## @run shell Test7107135.sh
   15.35 +##
   15.36 +
   15.37 +if [ "${TESTSRC}" = "" ]
   15.38 +then TESTSRC=.
   15.39 +fi
   15.40 +
   15.41 +if [ "${TESTJAVA}" = "" ]
   15.42 +then
   15.43 +  PARENT=`dirname \`which java\``
   15.44 +  TESTJAVA=`dirname ${PARENT}`
   15.45 +  echo "TESTJAVA not set, selecting " ${TESTJAVA}
   15.46 +  echo "If this is incorrect, try setting the variable manually."
   15.47 +fi
   15.48 +
   15.49 +BIT_FLAG=""
   15.50 +
   15.51 +# set platform-dependent variables
   15.52 +OS=`uname -s`
   15.53 +case "$OS" in
   15.54 +  Linux)
   15.55 +    NULL=/dev/null
   15.56 +    PS=":"
   15.57 +    FS="/"
   15.58 +    ;;
   15.59 +  *)
   15.60 +    NULL=NUL
   15.61 +    PS=";"
   15.62 +    FS="\\"
   15.63 +    echo "Test passed; only valid for Linux"
   15.64 +    exit 0;
   15.65 +    ;;
   15.66 +esac
   15.67 +
   15.68 +ARCH=`uname -m`
   15.69 +
   15.70 +THIS_DIR=`pwd`
   15.71 +
   15.72 +cp ${TESTSRC}${FS}*.java ${THIS_DIR}
   15.73 +${TESTJAVA}${FS}bin${FS}javac *.java
   15.74 +
   15.75 +gcc -fPIC -shared -c -o test.o -I${TESTJAVA}${FS}include -I${TESTJAVA}${FS}include${FS}linux ${TESTSRC}${FS}test.c
   15.76 +ld -shared -z   execstack -o libtest-rwx.so test.o
   15.77 +ld -shared -z noexecstack -o libtest-rw.so  test.o
   15.78 +
   15.79 +
   15.80 +LD_LIBRARY_PATH=${THIS_DIR}
   15.81 +echo   LD_LIBRARY_PATH = ${LD_LIBRARY_PATH}
   15.82 +export LD_LIBRARY_PATH
   15.83 +
   15.84 +# This should not fail.
   15.85 +echo Check testprogram. Expected to pass:
   15.86 +echo ${TESTJAVA}${FS}bin${FS}java -cp ${THIS_DIR} Test test-rw
   15.87 +${TESTJAVA}${FS}bin${FS}java -cp ${THIS_DIR} Test test-rw
   15.88 +
   15.89 +echo
   15.90 +echo Test changing of stack protection:
   15.91 +echo ${TESTJAVA}${FS}bin${FS}java -cp ${THIS_DIR} Test test-rw
   15.92 +${TESTJAVA}${FS}bin${FS}java -cp ${THIS_DIR} Test test-rwx
   15.93 +
   15.94 +if [ "$?" == "0" ]
   15.95 +then
   15.96 +  echo
   15.97 +  echo ${TESTJAVA}${FS}bin${FS}java -cp ${THIS_DIR} TestMT test-rwx
   15.98 +  ${TESTJAVA}${FS}bin${FS}java -cp ${THIS_DIR} TestMT test-rwx
   15.99 +fi
  15.100 +
  15.101 +exit $?
    16.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    16.2 +++ b/test/runtime/7107135/TestMT.java	Fri Mar 08 17:14:22 2013 -0800
    16.3 @@ -0,0 +1,85 @@
    16.4 +/*
    16.5 + * Copyright (c) 2002-2013, Oracle and/or its affiliates. All rights reserved.
    16.6 + * Copyright (c) 2011 SAP AG.  All Rights Reserved.
    16.7 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    16.8 + *
    16.9 + * This code is free software; you can redistribute it and/or modify it
   16.10 + * under the terms of the GNU General Public License version 2 only, as
   16.11 + * published by the Free Software Foundation.
   16.12 + *
   16.13 + * This code is distributed in the hope that it will be useful, but WITHOUT
   16.14 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   16.15 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   16.16 + * version 2 for more details (a copy is included in the LICENSE file that
   16.17 + * accompanied this code).
   16.18 + *
   16.19 + * You should have received a copy of the GNU General Public License version
   16.20 + * 2 along with this work; if not, write to the Free Software Foundation,
   16.21 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   16.22 + *
   16.23 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   16.24 + * or visit www.oracle.com if you need additional information or have any
   16.25 + * questions.
   16.26 + */
   16.27 +
   16.28 +class TestMT {
   16.29 +
   16.30 +    static boolean loadLib(String libName) {
   16.31 +        try {
   16.32 +            System.loadLibrary(libName);
   16.33 +            System.out.println("Loaded library "+ libName + ".");
   16.34 +            return true;
   16.35 +        } catch (SecurityException e) {
   16.36 +            System.out.println("loadLibrary(\"" + libName + "\") throws: " + e + "\n");
   16.37 +        } catch (UnsatisfiedLinkError e) {
   16.38 +            System.out.println("loadLibrary(\"" + libName + "\") throws: " + e + "\n");
   16.39 +        }
   16.40 +        return false;
   16.41 +    }
   16.42 +
   16.43 +    public static int counter        = 1;
   16.44 +    static int Runner() {
   16.45 +        counter = counter * -1;
   16.46 +        int i = counter;
   16.47 +        if (counter < 2) counter += Runner();
   16.48 +        return i;
   16.49 +    }
   16.50 +
   16.51 +    public static int run(String msg) {
   16.52 +        try {
   16.53 +            Runner();
   16.54 +        } catch (StackOverflowError e) {
   16.55 +            System.out.println(msg + " caught stack overflow error.");
   16.56 +            return 0;
   16.57 +        } catch (OutOfMemoryError e) {
   16.58 +            return 0;
   16.59 +        }
   16.60 +        return 2;
   16.61 +    }
   16.62 +
   16.63 +    public static void main(String argv[]) {
   16.64 +        try {
   16.65 +            for (int i = 0; i < 20; i++) {
   16.66 +                Thread t = new DoStackOverflow("SpawnedThread " + i);
   16.67 +                t.start();
   16.68 +            }
   16.69 +            run("Main thread");
   16.70 +            loadLib("test-rwx");
   16.71 +            run("Main thread");
   16.72 +        } catch (Exception e) {
   16.73 +            System.out.println(e);
   16.74 +        }
   16.75 +    }
   16.76 +
   16.77 +    static class DoStackOverflow extends Thread {
   16.78 +        public DoStackOverflow(String name) {
   16.79 +            super(name);
   16.80 +        }
   16.81 +        public void run() {
   16.82 +            for (int i = 0; i < 10; ++i) {
   16.83 +                TestMT.run(getName());
   16.84 +                yield();
   16.85 +            }
   16.86 +        }
   16.87 +    }
   16.88 +}
    17.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    17.2 +++ b/test/runtime/7107135/test.c	Fri Mar 08 17:14:22 2013 -0800
    17.3 @@ -0,0 +1,39 @@
    17.4 +/*
    17.5 + * Copyright (c) 2002-2013, Oracle and/or its affiliates. All rights reserved.
    17.6 + * Copyright (c) 2011 SAP AG.  All Rights Reserved.
    17.7 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    17.8 + *
    17.9 + * This code is free software; you can redistribute it and/or modify it
   17.10 + * under the terms of the GNU General Public License version 2 only, as
   17.11 + * published by the Free Software Foundation.
   17.12 + *
   17.13 + * This code is distributed in the hope that it will be useful, but WITHOUT
   17.14 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   17.15 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   17.16 + * version 2 for more details (a copy is included in the LICENSE file that
   17.17 + * accompanied this code).
   17.18 + *
   17.19 + * You should have received a copy of the GNU General Public License version
   17.20 + * 2 along with this work; if not, write to the Free Software Foundation,
   17.21 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   17.22 + *
   17.23 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   17.24 + * or visit www.oracle.com if you need additional information or have any
   17.25 + * questions.
   17.26 + */
   17.27 +
   17.28 +#include <stdlib.h>
   17.29 +#include <string.h>
   17.30 +#include <stdio.h>
   17.31 +#include "jni.h"
   17.32 +#ifdef __cplusplus
   17.33 +extern "C" {
   17.34 +#endif
   17.35 +
   17.36 +JNIEXPORT jint JNICALL Java_Test_someMethod(JNIEnv *env, jobject mainObject) {
   17.37 +  return 3;
   17.38 +}
   17.39 +
   17.40 +#ifdef __cplusplus
   17.41 +}
   17.42 +#endif

mercurial