|
|
d557d5 |
diff --git a/src/os/linux/vm/os_linux.cpp b/src/os/linux/vm/os_linux.cpp
|
|
|
d557d5 |
--- openjdk/hotspot/src/os/linux/vm/os_linux.cpp
|
|
|
d557d5 |
+++ openjdk/hotspot/src/os/linux/vm/os_linux.cpp
|
|
|
d557d5 |
@@ -2763,39 +2763,47 @@
|
|
|
d557d5 |
// writing thread stacks don't use growable mappings (i.e. those
|
|
|
d557d5 |
// creeated with MAP_GROWSDOWN), and aren't marked "[stack]", so this
|
|
|
d557d5 |
// only applies to the main thread.
|
|
|
d557d5 |
-
|
|
|
d557d5 |
-static
|
|
|
d557d5 |
-bool get_stack_bounds(uintptr_t *bottom, uintptr_t *top) {
|
|
|
d557d5 |
-
|
|
|
d557d5 |
- char buf[128];
|
|
|
d557d5 |
- int fd, sz;
|
|
|
d557d5 |
-
|
|
|
d557d5 |
- if ((fd = ::open("/proc/self/maps", O_RDONLY)) < 0) {
|
|
|
d557d5 |
+static bool
|
|
|
d557d5 |
+get_stack_bounds(uintptr_t *bottom, uintptr_t *top)
|
|
|
d557d5 |
+{
|
|
|
d557d5 |
+ FILE *f = fopen("/proc/self/maps", "r");
|
|
|
d557d5 |
+ if (f == NULL)
|
|
|
d557d5 |
return false;
|
|
|
d557d5 |
- }
|
|
|
d557d5 |
-
|
|
|
d557d5 |
- const char kw[] = "[stack]";
|
|
|
d557d5 |
- const int kwlen = sizeof(kw)-1;
|
|
|
d557d5 |
-
|
|
|
d557d5 |
- // Address part of /proc/self/maps couldn't be more than 128 bytes
|
|
|
d557d5 |
- while ((sz = os::get_line_chars(fd, buf, sizeof(buf))) > 0) {
|
|
|
d557d5 |
- if (sz > kwlen && ::memcmp(buf+sz-kwlen, kw, kwlen) == 0) {
|
|
|
d557d5 |
- // Extract addresses
|
|
|
d557d5 |
- if (sscanf(buf, "%" SCNxPTR "-%" SCNxPTR, bottom, top) == 2) {
|
|
|
d557d5 |
- uintptr_t sp = (uintptr_t) __builtin_frame_address(0);
|
|
|
d557d5 |
- if (sp >= *bottom && sp <= *top) {
|
|
|
d557d5 |
- ::close(fd);
|
|
|
d557d5 |
- return true;
|
|
|
d557d5 |
- }
|
|
|
d557d5 |
+
|
|
|
d557d5 |
+ while (!feof(f)) {
|
|
|
d557d5 |
+ size_t dummy;
|
|
|
d557d5 |
+ char *str = NULL;
|
|
|
d557d5 |
+ ssize_t len = getline(&str, &dummy, f);
|
|
|
d557d5 |
+ if (len == -1) {
|
|
|
d557d5 |
+ fclose(f);
|
|
|
d557d5 |
+ if (str != NULL)
|
|
|
d557d5 |
+ free(str);
|
|
|
d557d5 |
+ return false;
|
|
|
d557d5 |
+ }
|
|
|
d557d5 |
+
|
|
|
d557d5 |
+ if (len > 0 && str[len-1] == '\n') {
|
|
|
d557d5 |
+ str[len-1] = 0;
|
|
|
d557d5 |
+ len--;
|
|
|
d557d5 |
+ }
|
|
|
d557d5 |
+
|
|
|
d557d5 |
+ static const char *stack_str = "[stack]";
|
|
|
d557d5 |
+ if (len > (ssize_t)strlen(stack_str)
|
|
|
d557d5 |
+ && (strcmp(str + len - strlen(stack_str), stack_str) == 0)) {
|
|
|
d557d5 |
+ if (sscanf(str, "%" SCNxPTR "-%" SCNxPTR, bottom, top) == 2) {
|
|
|
d557d5 |
+ uintptr_t sp = (uintptr_t)__builtin_frame_address(0);
|
|
|
d557d5 |
+ if (sp >= *bottom && sp <= *top) {
|
|
|
d557d5 |
+ free(str);
|
|
|
d557d5 |
+ fclose(f);
|
|
|
d557d5 |
+ return true;
|
|
|
d557d5 |
}
|
|
|
d557d5 |
- }
|
|
|
d557d5 |
- }
|
|
|
d557d5 |
-
|
|
|
d557d5 |
- ::close(fd);
|
|
|
d557d5 |
+ }
|
|
|
d557d5 |
+ }
|
|
|
d557d5 |
+ free(str);
|
|
|
d557d5 |
+ }
|
|
|
d557d5 |
+ fclose(f);
|
|
|
d557d5 |
return false;
|
|
|
d557d5 |
}
|
|
|
d557d5 |
|
|
|
d557d5 |
-
|
|
|
d557d5 |
// If the (growable) stack mapping already extends beyond the point
|
|
|
d557d5 |
// where we're going to put our guard pages, truncate the mapping at
|
|
|
d557d5 |
// that point by munmap()ping it. This ensures that when we later
|
|
|
d557d5 |
diff --git a/src/share/vm/runtime/os.cpp b/src/share/vm/runtime/os.cpp
|
|
|
d557d5 |
--- openjdk/hotspot/src/share/vm/runtime/os.cpp
|
|
|
d557d5 |
+++ openjdk/hotspot/src/share/vm/runtime/os.cpp
|
|
|
d557d5 |
@@ -1353,43 +1353,6 @@
|
|
|
d557d5 |
return result;
|
|
|
d557d5 |
}
|
|
|
d557d5 |
|
|
|
d557d5 |
-// Read file line by line, if line is longer than bsize,
|
|
|
d557d5 |
-// skip rest of line.
|
|
|
d557d5 |
-int os::get_line_chars(int fd, char* buf, const size_t bsize){
|
|
|
d557d5 |
- size_t sz, i = 0;
|
|
|
d557d5 |
-
|
|
|
d557d5 |
- // read until EOF, EOL or buf is full
|
|
|
d557d5 |
- while ((sz = (int) read(fd, &buf[i], 1)) == 1 && i < (bsize-2) && buf[i] != '\n') {
|
|
|
d557d5 |
- ++i;
|
|
|
d557d5 |
- }
|
|
|
d557d5 |
-
|
|
|
d557d5 |
- if (buf[i] == '\n') {
|
|
|
d557d5 |
- // EOL reached so ignore EOL character and return
|
|
|
d557d5 |
-
|
|
|
d557d5 |
- buf[i] = 0;
|
|
|
d557d5 |
- return (int) i;
|
|
|
d557d5 |
- }
|
|
|
d557d5 |
-
|
|
|
d557d5 |
- buf[i+1] = 0;
|
|
|
d557d5 |
-
|
|
|
d557d5 |
- if (sz != 1) {
|
|
|
d557d5 |
- // EOF reached. if we read chars before EOF return them and
|
|
|
d557d5 |
- // return EOF on next call otherwise return EOF
|
|
|
d557d5 |
-
|
|
|
d557d5 |
- return (i == 0) ? -1 : (int) i;
|
|
|
d557d5 |
- }
|
|
|
d557d5 |
-
|
|
|
d557d5 |
- // line is longer than size of buf, skip to EOL
|
|
|
d557d5 |
- char ch;
|
|
|
d557d5 |
- while (read(fd, &ch, 1) == 1 && ch != '\n') {
|
|
|
d557d5 |
- // Do nothing
|
|
|
d557d5 |
- }
|
|
|
d557d5 |
-
|
|
|
d557d5 |
- // return initial part of line that fits in buf.
|
|
|
d557d5 |
- // If we reached EOF, it will be returned on next call.
|
|
|
d557d5 |
-
|
|
|
d557d5 |
- return (int) i;
|
|
|
d557d5 |
-}
|
|
|
d557d5 |
|
|
|
d557d5 |
void os::SuspendedThreadTask::run() {
|
|
|
d557d5 |
assert(Threads_lock->owned_by_self() || (_thread == VMThread::vm_thread()), "must have threads lock to call this");
|
|
|
d557d5 |
|
|
|
d557d5 |
diff --git a/src/share/vm/runtime/os.hpp b/src/share/vm/runtime/os.hpp
|
|
|
d557d5 |
--- openjdk/hotspot/src/share/vm/runtime/os.hpp
|
|
|
d557d5 |
+++ openjdk/hotspot/src/share/vm/runtime/os.hpp
|
|
|
d557d5 |
@@ -672,10 +672,6 @@
|
|
|
d557d5 |
// Hook for os specific jvm options that we don't want to abort on seeing
|
|
|
d557d5 |
static bool obsolete_option(const JavaVMOption *option);
|
|
|
d557d5 |
|
|
|
d557d5 |
- // Read file line by line. If line is longer than bsize,
|
|
|
d557d5 |
- // rest of line is skipped. Returns number of bytes read or -1 on EOF
|
|
|
d557d5 |
- static int get_line_chars(int fd, char *buf, const size_t bsize);
|
|
|
d557d5 |
-
|
|
|
d557d5 |
// Extensions
|
|
|
d557d5 |
#include "runtime/os_ext.hpp"
|
|
|
d557d5 |
|
|
|
d557d5 |
|