| OLD | NEW |
| 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 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 17 matching lines...) Expand all Loading... |
| 28 // Platform specific code for MacOS goes here. For the POSIX comaptible parts | 28 // Platform specific code for MacOS goes here. For the POSIX comaptible parts |
| 29 // the implementation is in platform-posix.cc. | 29 // the implementation is in platform-posix.cc. |
| 30 | 30 |
| 31 #include <ucontext.h> | 31 #include <ucontext.h> |
| 32 #include <unistd.h> | 32 #include <unistd.h> |
| 33 #include <sys/mman.h> | 33 #include <sys/mman.h> |
| 34 #include <mach/mach_init.h> | 34 #include <mach/mach_init.h> |
| 35 | 35 |
| 36 #include <AvailabilityMacros.h> | 36 #include <AvailabilityMacros.h> |
| 37 | 37 |
| 38 #ifdef MAC_OS_X_VERSION_10_5 | |
| 39 # include <execinfo.h> // backtrace, backtrace_symbols | |
| 40 #endif | |
| 41 | |
| 42 #include <pthread.h> | 38 #include <pthread.h> |
| 43 #include <semaphore.h> | 39 #include <semaphore.h> |
| 44 #include <signal.h> | 40 #include <signal.h> |
| 45 #include <mach/semaphore.h> | 41 #include <mach/semaphore.h> |
| 46 #include <mach/task.h> | 42 #include <mach/task.h> |
| 47 #include <sys/time.h> | 43 #include <sys/time.h> |
| 48 #include <sys/resource.h> | 44 #include <sys/resource.h> |
| 49 #include <sys/types.h> | 45 #include <sys/types.h> |
| 50 #include <stdarg.h> | 46 #include <stdarg.h> |
| 51 #include <stdlib.h> | 47 #include <stdlib.h> |
| 52 | 48 |
| 53 #include <errno.h> | 49 #include <errno.h> |
| 54 | 50 |
| 55 #undef MAP_TYPE | 51 #undef MAP_TYPE |
| 56 | 52 |
| 57 #include "v8.h" | 53 #include "v8.h" |
| 58 | 54 |
| 59 #include "platform.h" | 55 #include "platform.h" |
| 60 | 56 |
| 57 // Manually define these here as weak imports, rather than including execinfo.h. |
| 58 // This lets us launch on 10.4 which does not have these calls. |
| 59 extern "C" { |
| 60 extern int backtrace(void**, int) __attribute__((weak_import)); |
| 61 extern char** backtrace_symbols(void* const*, int) |
| 62 __attribute__((weak_import)); |
| 63 extern void backtrace_symbols_fd(void* const*, int, int) |
| 64 __attribute__((weak_import)); |
| 65 } |
| 66 |
| 67 |
| 61 namespace v8 { | 68 namespace v8 { |
| 62 namespace internal { | 69 namespace internal { |
| 63 | 70 |
| 64 // 0 is never a valid thread id on MacOSX since a ptread_t is | 71 // 0 is never a valid thread id on MacOSX since a ptread_t is |
| 65 // a pointer. | 72 // a pointer. |
| 66 static const pthread_t kNoThread = (pthread_t) 0; | 73 static const pthread_t kNoThread = (pthread_t) 0; |
| 67 | 74 |
| 68 | 75 |
| 69 double ceiling(double x) { | 76 double ceiling(double x) { |
| 70 // Correct Mac OS X Leopard 'ceil' behavior. | 77 // Correct Mac OS X Leopard 'ceil' behavior. |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 207 | 214 |
| 208 | 215 |
| 209 int OS::ActivationFrameAlignment() { | 216 int OS::ActivationFrameAlignment() { |
| 210 // OS X activation frames must be 16 byte-aligned; see "Mac OS X ABI | 217 // OS X activation frames must be 16 byte-aligned; see "Mac OS X ABI |
| 211 // Function Call Guide". | 218 // Function Call Guide". |
| 212 return 16; | 219 return 16; |
| 213 } | 220 } |
| 214 | 221 |
| 215 | 222 |
| 216 int OS::StackWalk(Vector<StackFrame> frames) { | 223 int OS::StackWalk(Vector<StackFrame> frames) { |
| 217 #ifndef MAC_OS_X_VERSION_10_5 | 224 // If weak link to execinfo lib has failed, ie because we are on 10.4, abort. |
| 218 return 0; | 225 if (backtrace == NULL) |
| 219 #else | 226 return 0; |
| 227 |
| 220 int frames_size = frames.length(); | 228 int frames_size = frames.length(); |
| 221 void** addresses = NewArray<void*>(frames_size); | 229 void** addresses = NewArray<void*>(frames_size); |
| 222 int frames_count = backtrace(addresses, frames_size); | 230 int frames_count = backtrace(addresses, frames_size); |
| 223 | 231 |
| 224 char** symbols; | 232 char** symbols; |
| 225 symbols = backtrace_symbols(addresses, frames_count); | 233 symbols = backtrace_symbols(addresses, frames_count); |
| 226 if (symbols == NULL) { | 234 if (symbols == NULL) { |
| 227 DeleteArray(addresses); | 235 DeleteArray(addresses); |
| 228 return kStackWalkError; | 236 return kStackWalkError; |
| 229 } | 237 } |
| 230 | 238 |
| 231 for (int i = 0; i < frames_count; i++) { | 239 for (int i = 0; i < frames_count; i++) { |
| 232 frames[i].address = addresses[i]; | 240 frames[i].address = addresses[i]; |
| 233 // Format a text representation of the frame based on the information | 241 // Format a text representation of the frame based on the information |
| 234 // available. | 242 // available. |
| 235 SNPrintF(MutableCStrVector(frames[i].text, | 243 SNPrintF(MutableCStrVector(frames[i].text, |
| 236 kStackWalkMaxTextLen), | 244 kStackWalkMaxTextLen), |
| 237 "%s", | 245 "%s", |
| 238 symbols[i]); | 246 symbols[i]); |
| 239 // Make sure line termination is in place. | 247 // Make sure line termination is in place. |
| 240 frames[i].text[kStackWalkMaxTextLen - 1] = '\0'; | 248 frames[i].text[kStackWalkMaxTextLen - 1] = '\0'; |
| 241 } | 249 } |
| 242 | 250 |
| 243 DeleteArray(addresses); | 251 DeleteArray(addresses); |
| 244 free(symbols); | 252 free(symbols); |
| 245 | 253 |
| 246 return frames_count; | 254 return frames_count; |
| 247 #endif | |
| 248 } | 255 } |
| 249 | 256 |
| 250 | 257 |
| 251 // Constants used for mmap. | 258 // Constants used for mmap. |
| 252 static const int kMmapFd = -1; | 259 static const int kMmapFd = -1; |
| 253 static const int kMmapFdOffset = 0; | 260 static const int kMmapFdOffset = 0; |
| 254 | 261 |
| 255 | 262 |
| 256 VirtualMemory::VirtualMemory(size_t size) { | 263 VirtualMemory::VirtualMemory(size_t size) { |
| 257 address_ = mmap(NULL, size, PROT_NONE, | 264 address_ = mmap(NULL, size, PROT_NONE, |
| (...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 569 } | 576 } |
| 570 | 577 |
| 571 // This sampler is no longer the active sampler. | 578 // This sampler is no longer the active sampler. |
| 572 active_sampler_ = NULL; | 579 active_sampler_ = NULL; |
| 573 active_ = false; | 580 active_ = false; |
| 574 } | 581 } |
| 575 | 582 |
| 576 #endif // ENABLE_LOGGING_AND_PROFILING | 583 #endif // ENABLE_LOGGING_AND_PROFILING |
| 577 | 584 |
| 578 } } // namespace v8::internal | 585 } } // namespace v8::internal |
| OLD | NEW |