hotspot/src/os/linux/vm/os_linux.cpp

Print this page

        

@@ -52,10 +52,14 @@
 # include <gnu/libc-version.h>
 # include <sys/ipc.h>
 # include <sys/shm.h>
 # include <link.h>
 
+#include <sstream>
+#include <iostream>
+#include <fstream>
+
 #define MAX_PATH    (2 * K)
 
 // for timer info max values which include all bits
 #define ALL_64_BITS CONST64(0xFFFFFFFFFFFFFFFF)
 #define SEC_IN_NANOSECS  1000000000LL

@@ -2490,10 +2494,57 @@
   return ::mmap(addr, size, PROT_NONE,
                 MAP_PRIVATE|MAP_FIXED|MAP_NORESERVE|MAP_ANONYMOUS, -1, 0)
     != MAP_FAILED;
 }
 
+static bool
+get_stack_bounds(uintptr_t *bottom, uintptr_t *top)
+{
+  using namespace std;
+
+  ostringstream oss;
+  oss << "/proc/" << syscall(SYS_gettid) << "/maps";
+  ifstream cin(oss.str().c_str());
+  while (!cin.eof())
+  {
+    string str;
+    getline(cin,str);
+    const string stack_str = "[stack]";
+    if (str.length() > stack_str.length()
+        && (str.compare(str.length() - stack_str.length(),
+                       stack_str.length(), stack_str)
+            == 0))
+      {
+        istringstream iss(str);
+        iss.flags(ios::hex);
+        iss >> *bottom;
+        char c;
+        iss >> c;
+        iss >> *top;
+        uintptr_t sp = (intptr_t)__builtin_frame_address(0);
+        if (sp >= *bottom && sp <= *top)
+          return true;
+      }
+  }
+
+  return false;
+}
+
+bool os::create_stack_guard_pages(char* addr, size_t size) {
+  uintptr_t stack_extent, stack_base;
+  if (get_stack_bounds(&stack_extent, &stack_base)) {
+    if (stack_extent < (uintptr_t)addr)
+      ::munmap((void*)stack_extent, (uintptr_t)addr - stack_extent);
+  }
+
+  return os::commit_memory(addr, size);
+}
+
+bool os::remove_stack_guard_pages(char* addr, size_t size) {
+  return ::munmap(addr, size) == 0;
+}
+
 static address _highest_vm_reserved_address = NULL;
 
 // If 'fixed' is true, anon_mmap() will attempt to reserve anonymous memory
 // at 'requested_addr'. If there are existing memory mappings at the same
 // location, however, they will be overwritten. If 'fixed' is false,