1.1 --- a/src/os/linux/vm/os_linux.cpp Mon Mar 28 12:48:08 2011 +0200 1.2 +++ b/src/os/linux/vm/os_linux.cpp Wed Mar 30 19:38:07 2011 +0400 1.3 @@ -2648,45 +2648,39 @@ 1.4 // writing thread stacks don't use growable mappings (i.e. those 1.5 // creeated with MAP_GROWSDOWN), and aren't marked "[stack]", so this 1.6 // only applies to the main thread. 1.7 -static bool 1.8 -get_stack_bounds(uintptr_t *bottom, uintptr_t *top) 1.9 -{ 1.10 - FILE *f = fopen("/proc/self/maps", "r"); 1.11 - if (f == NULL) 1.12 + 1.13 +static 1.14 +bool get_stack_bounds(uintptr_t *bottom, uintptr_t *top) { 1.15 + 1.16 + char buf[128]; 1.17 + int fd, sz; 1.18 + 1.19 + if ((fd = ::open("/proc/self/maps", O_RDONLY)) < 0) { 1.20 return false; 1.21 - 1.22 - while (!feof(f)) { 1.23 - size_t dummy; 1.24 - char *str = NULL; 1.25 - ssize_t len = getline(&str, &dummy, f); 1.26 - if (len == -1) { 1.27 - fclose(f); 1.28 - return false; 1.29 - } 1.30 - 1.31 - if (len > 0 && str[len-1] == '\n') { 1.32 - str[len-1] = 0; 1.33 - len--; 1.34 - } 1.35 - 1.36 - static const char *stack_str = "[stack]"; 1.37 - if (len > (ssize_t)strlen(stack_str) 1.38 - && (strcmp(str + len - strlen(stack_str), stack_str) == 0)) { 1.39 - if (sscanf(str, "%" SCNxPTR "-%" SCNxPTR, bottom, top) == 2) { 1.40 - uintptr_t sp = (uintptr_t)__builtin_frame_address(0); 1.41 - if (sp >= *bottom && sp <= *top) { 1.42 - free(str); 1.43 - fclose(f); 1.44 - return true; 1.45 + } 1.46 + 1.47 + const char kw[] = "[stack]"; 1.48 + const int kwlen = sizeof(kw)-1; 1.49 + 1.50 + // Address part of /proc/self/maps couldn't be more than 128 bytes 1.51 + while ((sz = os::get_line_chars(fd, buf, sizeof(buf))) > 0) { 1.52 + if (sz > kwlen && ::memcmp(buf+sz-kwlen, kw, kwlen) == 0) { 1.53 + // Extract addresses 1.54 + if (sscanf(buf, "%" SCNxPTR "-%" SCNxPTR, bottom, top) == 2) { 1.55 + uintptr_t sp = (uintptr_t) __builtin_frame_address(0); 1.56 + if (sp >= *bottom && sp <= *top) { 1.57 + ::close(fd); 1.58 + return true; 1.59 + } 1.60 } 1.61 - } 1.62 - } 1.63 - free(str); 1.64 + } 1.65 } 1.66 - fclose(f); 1.67 + 1.68 + ::close(fd); 1.69 return false; 1.70 } 1.71 1.72 + 1.73 // If the (growable) stack mapping already extends beyond the point 1.74 // where we're going to put our guard pages, truncate the mapping at 1.75 // that point by munmap()ping it. This ensures that when we later