OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
224 OS::Abort(); | 224 OS::Abort(); |
225 } | 225 } |
226 void* addr = mmap(NULL, size, PROT_READ | PROT_EXEC, MAP_PRIVATE, | 226 void* addr = mmap(NULL, size, PROT_READ | PROT_EXEC, MAP_PRIVATE, |
227 fileno(f), 0); | 227 fileno(f), 0); |
228 ASSERT(addr != MAP_FAILED); | 228 ASSERT(addr != MAP_FAILED); |
229 OS::Free(addr, size); | 229 OS::Free(addr, size); |
230 fclose(f); | 230 fclose(f); |
231 } | 231 } |
232 | 232 |
233 | 233 |
234 int OS::StackWalk(Vector<OS::StackFrame> frames) { | |
235 // backtrace is a glibc extension. | |
236 int frames_size = frames.length(); | |
237 ScopedVector<void*> addresses(frames_size); | |
238 | |
239 int frames_count = backtrace(addresses.start(), frames_size); | |
240 | |
241 char** symbols = backtrace_symbols(addresses.start(), frames_count); | |
242 if (symbols == NULL) { | |
243 return kStackWalkError; | |
244 } | |
245 | |
246 for (int i = 0; i < frames_count; i++) { | |
247 frames[i].address = addresses[i]; | |
248 // Format a text representation of the frame based on the information | |
249 // available. | |
250 SNPrintF(MutableCStrVector(frames[i].text, kStackWalkMaxTextLen), | |
251 "%s", | |
252 symbols[i]); | |
253 // Make sure line termination is in place. | |
254 frames[i].text[kStackWalkMaxTextLen - 1] = '\0'; | |
255 } | |
256 | |
257 free(symbols); | |
258 | |
259 return frames_count; | |
260 } | |
261 | |
262 | 234 |
263 // Constants used for mmap. | 235 // Constants used for mmap. |
264 static const int kMmapFd = -1; | 236 static const int kMmapFd = -1; |
265 static const int kMmapFdOffset = 0; | 237 static const int kMmapFdOffset = 0; |
266 | 238 |
267 | 239 |
268 VirtualMemory::VirtualMemory() : address_(NULL), size_(0) { } | 240 VirtualMemory::VirtualMemory() : address_(NULL), size_(0) { } |
269 | 241 |
270 | 242 |
271 VirtualMemory::VirtualMemory(size_t size) | 243 VirtualMemory::VirtualMemory(size_t size) |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
390 return munmap(base, size) == 0; | 362 return munmap(base, size) == 0; |
391 } | 363 } |
392 | 364 |
393 | 365 |
394 bool VirtualMemory::HasLazyCommits() { | 366 bool VirtualMemory::HasLazyCommits() { |
395 // TODO(alph): implement for the platform. | 367 // TODO(alph): implement for the platform. |
396 return false; | 368 return false; |
397 } | 369 } |
398 | 370 |
399 } } // namespace v8::internal | 371 } } // namespace v8::internal |
OLD | NEW |