| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights
reserved. | 2 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights
reserved. |
| 3 * Copyright (C) 2007 Eric Seidel <eric@webkit.org> | 3 * Copyright (C) 2007 Eric Seidel <eric@webkit.org> |
| 4 * | 4 * |
| 5 * This library is free software; you can redistribute it and/or | 5 * This library is free software; you can redistribute it and/or |
| 6 * modify it under the terms of the GNU Lesser General Public | 6 * modify it under the terms of the GNU Lesser General Public |
| 7 * License as published by the Free Software Foundation; either | 7 * License as published by the Free Software Foundation; either |
| 8 * version 2 of the License, or (at your option) any later version. | 8 * version 2 of the License, or (at your option) any later version. |
| 9 * | 9 * |
| 10 * This library is distributed in the hope that it will be useful, | 10 * This library is distributed in the hope that it will be useful, |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 #include <pthread.h> | 28 #include <pthread.h> |
| 29 | 29 |
| 30 #elif OS(WINDOWS) | 30 #elif OS(WINDOWS) |
| 31 | 31 |
| 32 #include <windows.h> | 32 #include <windows.h> |
| 33 | 33 |
| 34 #elif OS(SOLARIS) | 34 #elif OS(SOLARIS) |
| 35 | 35 |
| 36 #include <thread.h> | 36 #include <thread.h> |
| 37 | 37 |
| 38 #elif OS(QNX) | |
| 39 | |
| 40 #include <errno.h> | |
| 41 #include <fcntl.h> | |
| 42 #include <pthread.h> | |
| 43 #include <stdio.h> | |
| 44 #include <string.h> | |
| 45 #include <sys/procfs.h> | |
| 46 | |
| 47 #elif OS(UNIX) | 38 #elif OS(UNIX) |
| 48 | 39 |
| 49 #include <pthread.h> | 40 #include <pthread.h> |
| 50 #if HAVE(PTHREAD_NP_H) | 41 #if HAVE(PTHREAD_NP_H) |
| 51 #include <pthread_np.h> | 42 #include <pthread_np.h> |
| 52 #endif | 43 #endif |
| 53 | 44 |
| 54 #endif | 45 #endif |
| 55 | 46 |
| 56 namespace WTF { | 47 namespace WTF { |
| 57 | 48 |
| 58 // Bug 26276 - Need a mechanism to determine stack extent | 49 // Bug 26276 - Need a mechanism to determine stack extent |
| 59 // | 50 // |
| 60 // These platforms should now be working correctly: | 51 // These platforms should now be working correctly: |
| 61 // DARWIN, QNX, UNIX | 52 // DARWIN, UNIX |
| 62 // These platforms are not: | 53 // These platforms are not: |
| 63 // WINDOWS, SOLARIS, OPENBSD | 54 // WINDOWS, SOLARIS, OPENBSD |
| 64 // | 55 // |
| 65 // FIXME: remove this! - this code unsafely guesses at stack sizes! | 56 // FIXME: remove this! - this code unsafely guesses at stack sizes! |
| 66 #if OS(WINDOWS) || OS(SOLARIS) || OS(OPENBSD) | 57 #if OS(WINDOWS) || OS(SOLARIS) || OS(OPENBSD) |
| 67 // Based on the current limit used by the JSC parser, guess the stack size. | 58 // Based on the current limit used by the JSC parser, guess the stack size. |
| 68 static const ptrdiff_t estimatedStackSize = 128 * sizeof(void*) * 1024; | 59 static const ptrdiff_t estimatedStackSize = 128 * sizeof(void*) * 1024; |
| 69 // This method assumes the stack is growing downwards. | 60 // This method assumes the stack is growing downwards. |
| 70 static void* estimateStackBound(void* origin) | 61 static void* estimateStackBound(void* origin) |
| 71 { | 62 { |
| 72 return static_cast<char*>(origin) - estimatedStackSize; | 63 return static_cast<char*>(origin) - estimatedStackSize; |
| 73 } | 64 } |
| 74 #endif | 65 #endif |
| 75 | 66 |
| 76 #if OS(DARWIN) | 67 #if OS(DARWIN) |
| 77 | 68 |
| 78 void StackBounds::initialize() | 69 void StackBounds::initialize() |
| 79 { | 70 { |
| 80 pthread_t thread = pthread_self(); | 71 pthread_t thread = pthread_self(); |
| 81 m_origin = pthread_get_stackaddr_np(thread); | 72 m_origin = pthread_get_stackaddr_np(thread); |
| 82 m_bound = static_cast<char*>(m_origin) - pthread_get_stacksize_np(thread); | 73 m_bound = static_cast<char*>(m_origin) - pthread_get_stacksize_np(thread); |
| 83 } | 74 } |
| 84 | 75 |
| 85 #elif OS(QNX) | |
| 86 | |
| 87 void StackBounds::initialize() | |
| 88 { | |
| 89 void* stackBase = 0; | |
| 90 size_t stackSize = 0; | |
| 91 | |
| 92 struct _debug_thread_info threadInfo; | |
| 93 memset(&threadInfo, 0, sizeof(threadInfo)); | |
| 94 threadInfo.tid = pthread_self(); | |
| 95 int fd = open("/proc/self", O_RDONLY); | |
| 96 if (fd == -1) { | |
| 97 LOG_ERROR("Unable to open /proc/self (errno: %d)", errno); | |
| 98 CRASH(); | |
| 99 } | |
| 100 devctl(fd, DCMD_PROC_TIDSTATUS, &threadInfo, sizeof(threadInfo), 0); | |
| 101 close(fd); | |
| 102 stackBase = reinterpret_cast<void*>(threadInfo.stkbase); | |
| 103 stackSize = threadInfo.stksize; | |
| 104 ASSERT(stackBase); | |
| 105 | |
| 106 m_bound = static_cast<char*>(stackBase) + 0x1000; // 4kb guard page | |
| 107 m_origin = static_cast<char*>(stackBase) + stackSize; | |
| 108 } | |
| 109 | |
| 110 #elif OS(SOLARIS) | 76 #elif OS(SOLARIS) |
| 111 | 77 |
| 112 void StackBounds::initialize() | 78 void StackBounds::initialize() |
| 113 { | 79 { |
| 114 stack_t s; | 80 stack_t s; |
| 115 thr_stksegment(&s); | 81 thr_stksegment(&s); |
| 116 m_origin = s.ss_sp; | 82 m_origin = s.ss_sp; |
| 117 m_bound = estimateStackBound(m_origin); | 83 m_bound = estimateStackBound(m_origin); |
| 118 } | 84 } |
| 119 | 85 |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 #endif | 148 #endif |
| 183 // Looks like we should be able to get pTib->StackLimit | 149 // Looks like we should be able to get pTib->StackLimit |
| 184 m_bound = estimateStackBound(m_origin); | 150 m_bound = estimateStackBound(m_origin); |
| 185 } | 151 } |
| 186 | 152 |
| 187 #else | 153 #else |
| 188 #error Need a way to get the stack bounds on this platform | 154 #error Need a way to get the stack bounds on this platform |
| 189 #endif | 155 #endif |
| 190 | 156 |
| 191 } // namespace WTF | 157 } // namespace WTF |
| OLD | NEW |