Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(169)

Side by Side Diff: third_party/WebKit/Source/platform/wtf/StackUtil.cpp

Issue 2833123002: Replace ASSERT_NOT_REACHED, and RELEASE_ASSERT in platform/wtf (Closed)
Patch Set: wtf Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "platform/wtf/StackUtil.h" 5 #include "platform/wtf/StackUtil.h"
6 6
7 #include "platform/wtf/Assertions.h" 7 #include "platform/wtf/Assertions.h"
8 #include "platform/wtf/Threading.h" 8 #include "platform/wtf/Threading.h"
9 #include "platform/wtf/WTFThreadData.h" 9 #include "platform/wtf/WTFThreadData.h"
10 10
(...skipping 27 matching lines...) Expand all
38 #if OS(FREEBSD) 38 #if OS(FREEBSD)
39 pthread_attr_init(&attr); 39 pthread_attr_init(&attr);
40 error = pthread_attr_get_np(pthread_self(), &attr); 40 error = pthread_attr_get_np(pthread_self(), &attr);
41 #else 41 #else
42 error = pthread_getattr_np(pthread_self(), &attr); 42 error = pthread_getattr_np(pthread_self(), &attr);
43 #endif 43 #endif
44 if (!error) { 44 if (!error) {
45 void* base; 45 void* base;
46 size_t size; 46 size_t size;
47 error = pthread_attr_getstack(&attr, &base, &size); 47 error = pthread_attr_getstack(&attr, &base, &size);
48 RELEASE_ASSERT(!error); 48 CHECK(!error);
49 pthread_attr_destroy(&attr); 49 pthread_attr_destroy(&attr);
50 return size; 50 return size;
51 } 51 }
52 #if OS(FREEBSD) 52 #if OS(FREEBSD)
53 pthread_attr_destroy(&attr); 53 pthread_attr_destroy(&attr);
54 #endif 54 #endif
55 55
56 // Return a 512k stack size, (conservatively) assuming the following: 56 // Return a 512k stack size, (conservatively) assuming the following:
57 // - that size is much lower than the pthreads default (x86 pthreads has a 2M 57 // - that size is much lower than the pthreads default (x86 pthreads has a 2M
58 // default.) 58 // default.)
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 #if OS(FREEBSD) 101 #if OS(FREEBSD)
102 pthread_attr_init(&attr); 102 pthread_attr_init(&attr);
103 error = pthread_attr_get_np(pthread_self(), &attr); 103 error = pthread_attr_get_np(pthread_self(), &attr);
104 #else 104 #else
105 error = pthread_getattr_np(pthread_self(), &attr); 105 error = pthread_getattr_np(pthread_self(), &attr);
106 #endif 106 #endif
107 if (!error) { 107 if (!error) {
108 void* base; 108 void* base;
109 size_t size; 109 size_t size;
110 error = pthread_attr_getstack(&attr, &base, &size); 110 error = pthread_attr_getstack(&attr, &base, &size);
111 RELEASE_ASSERT(!error); 111 CHECK(!error);
112 pthread_attr_destroy(&attr); 112 pthread_attr_destroy(&attr);
113 return reinterpret_cast<uint8_t*>(base) + size; 113 return reinterpret_cast<uint8_t*>(base) + size;
114 } 114 }
115 #if OS(FREEBSD) 115 #if OS(FREEBSD)
116 pthread_attr_destroy(&attr); 116 pthread_attr_destroy(&attr);
117 #endif 117 #endif
118 #if defined(__GLIBC__) 118 #if defined(__GLIBC__)
119 // pthread_getattr_np can fail for the main thread. In this case 119 // pthread_getattr_np can fail for the main thread. In this case
120 // just like NaCl we rely on the __libc_stack_end to give us 120 // just like NaCl we rely on the __libc_stack_end to give us
121 // the start of the stack. 121 // the start of the stack.
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 // tracks the end of the committed range. We're after the end of the reserved 166 // tracks the end of the committed range. We're after the end of the reserved
167 // stack area (most of which will be uncommitted, most times.) 167 // stack area (most of which will be uncommitted, most times.)
168 MEMORY_BASIC_INFORMATION stack_info; 168 MEMORY_BASIC_INFORMATION stack_info;
169 memset(&stack_info, 0, sizeof(MEMORY_BASIC_INFORMATION)); 169 memset(&stack_info, 0, sizeof(MEMORY_BASIC_INFORMATION));
170 size_t result_size = 170 size_t result_size =
171 VirtualQuery(&stack_info, &stack_info, sizeof(MEMORY_BASIC_INFORMATION)); 171 VirtualQuery(&stack_info, &stack_info, sizeof(MEMORY_BASIC_INFORMATION));
172 DCHECK_GE(result_size, sizeof(MEMORY_BASIC_INFORMATION)); 172 DCHECK_GE(result_size, sizeof(MEMORY_BASIC_INFORMATION));
173 uint8_t* stack_end = reinterpret_cast<uint8_t*>(stack_info.AllocationBase); 173 uint8_t* stack_end = reinterpret_cast<uint8_t*>(stack_info.AllocationBase);
174 174
175 uint8_t* stack_start = reinterpret_cast<uint8_t*>(WTF::GetStackStart()); 175 uint8_t* stack_start = reinterpret_cast<uint8_t*>(WTF::GetStackStart());
176 RELEASE_ASSERT(stack_start && stack_start > stack_end); 176 CHECK(stack_start);
177 CHECK_GT(stack_start, stack_end);
177 size_t thread_stack_size = static_cast<size_t>(stack_start - stack_end); 178 size_t thread_stack_size = static_cast<size_t>(stack_start - stack_end);
178 // When the third last page of the reserved stack is accessed as a 179 // When the third last page of the reserved stack is accessed as a
179 // guard page, the second last page will be committed (along with removing 180 // guard page, the second last page will be committed (along with removing
180 // the guard bit on the third last) _and_ a stack overflow exception 181 // the guard bit on the third last) _and_ a stack overflow exception
181 // is raised. 182 // is raised.
182 // 183 //
183 // We have zero interest in running into stack overflow exceptions while 184 // We have zero interest in running into stack overflow exceptions while
184 // marking objects, so simply consider the last three pages + one above 185 // marking objects, so simply consider the last three pages + one above
185 // as off-limits and adjust the reported stack size accordingly. 186 // as off-limits and adjust the reported stack size accordingly.
186 // 187 //
187 // http://blogs.msdn.com/b/satyem/archive/2012/08/13/thread-s-stack-memory-man agement.aspx 188 // http://blogs.msdn.com/b/satyem/archive/2012/08/13/thread-s-stack-memory-man agement.aspx
188 // explains the details. 189 // explains the details.
189 RELEASE_ASSERT(thread_stack_size > 4 * 0x1000); 190 CHECK_GT(thread_stack_size, 4u * 0x1000);
190 thread_stack_size -= 4 * 0x1000; 191 thread_stack_size -= 4 * 0x1000;
191 return thread_stack_size; 192 return thread_stack_size;
192 } 193 }
193 #endif 194 #endif
194 195
195 } // namespace internal 196 } // namespace internal
196 197
197 } // namespace WTF 198 } // namespace WTF
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/platform/wtf/HashTable.h ('k') | third_party/WebKit/Source/platform/wtf/TerminatedArrayBuilder.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698