| 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 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 | 125 |
| 126 double OS::LocalTimeOffset() { | 126 double OS::LocalTimeOffset() { |
| 127 time_t tv = time(NULL); | 127 time_t tv = time(NULL); |
| 128 struct tm* t = localtime(&tv); | 128 struct tm* t = localtime(&tv); |
| 129 // tm_gmtoff includes any daylight savings offset, so subtract it. | 129 // tm_gmtoff includes any daylight savings offset, so subtract it. |
| 130 return static_cast<double>(t->tm_gmtoff * msPerSecond - | 130 return static_cast<double>(t->tm_gmtoff * msPerSecond - |
| 131 (t->tm_isdst > 0 ? 3600 * msPerSecond : 0)); | 131 (t->tm_isdst > 0 ? 3600 * msPerSecond : 0)); |
| 132 } | 132 } |
| 133 | 133 |
| 134 | 134 |
| 135 FILE* OS::FOpen(const char* path, const char* mode) { |
| 136 return fopen(path, mode); |
| 137 } |
| 138 |
| 139 |
| 135 void OS::Print(const char* format, ...) { | 140 void OS::Print(const char* format, ...) { |
| 136 va_list args; | 141 va_list args; |
| 137 va_start(args, format); | 142 va_start(args, format); |
| 138 VPrint(format, args); | 143 VPrint(format, args); |
| 139 va_end(args); | 144 va_end(args); |
| 140 } | 145 } |
| 141 | 146 |
| 142 | 147 |
| 143 void OS::VPrint(const char* format, va_list args) { | 148 void OS::VPrint(const char* format, va_list args) { |
| 144 vprintf(format, args); | 149 vprintf(format, args); |
| 145 } | 150 } |
| 146 | 151 |
| 147 | 152 |
| 148 void OS::PrintError(const char* format, ...) { | 153 void OS::PrintError(const char* format, ...) { |
| 149 va_list args; | 154 va_list args; |
| 150 va_start(args, format); | 155 va_start(args, format); |
| 151 VPrintError(format, args); | 156 VPrintError(format, args); |
| 152 va_end(args); | 157 va_end(args); |
| 153 } | 158 } |
| 154 | 159 |
| 155 | 160 |
| 156 void OS::VPrintError(const char* format, va_list args) { | 161 void OS::VPrintError(const char* format, va_list args) { |
| 157 vfprintf(stderr, format, args); | 162 vfprintf(stderr, format, args); |
| 158 } | 163 } |
| 159 | 164 |
| 160 | 165 |
| 161 int OS::SNPrintF(char* str, size_t size, const char* format, ...) { | 166 int OS::SNPrintF(Vector<char> str, const char* format, ...) { |
| 162 va_list args; | 167 va_list args; |
| 163 va_start(args, format); | 168 va_start(args, format); |
| 164 int result = VSNPrintF(str, size, format, args); | 169 int result = VSNPrintF(str, format, args); |
| 165 va_end(args); | 170 va_end(args); |
| 166 return result; | 171 return result; |
| 167 } | 172 } |
| 168 | 173 |
| 169 | 174 |
| 170 int OS::VSNPrintF(char* str, size_t size, const char* format, va_list args) { | 175 int OS::VSNPrintF(Vector<char> str, |
| 171 int n = vsnprintf(str, size, format, args); // forward to Mac OS X. | 176 const char* format, |
| 172 if (n < 0 || static_cast<size_t>(n) >= size) { | 177 va_list args) { |
| 173 str[size - 1] = '\0'; | 178 int n = vsnprintf(str.start(), str.length(), format, args); |
| 179 if (n < 0 || n >= str.length()) { |
| 180 str[str.length() - 1] = '\0'; |
| 174 return -1; | 181 return -1; |
| 175 } else { | 182 } else { |
| 176 return n; | 183 return n; |
| 177 } | 184 } |
| 178 } | 185 } |
| 179 | 186 |
| 180 | 187 |
| 188 void OS::StrNCpy(Vector<char> dest, const char* src, size_t n) { |
| 189 strncpy(dest.start(), src, n); |
| 190 } |
| 191 |
| 192 |
| 193 void OS::WcsCpy(Vector<wchar_t> dest, const wchar_t* src) { |
| 194 wcscpy(dest.start(), src); |
| 195 } |
| 196 |
| 197 |
| 198 char *OS::StrDup(const char* str) { |
| 199 return strdup(str); |
| 200 } |
| 201 |
| 202 |
| 181 // We keep the lowest and highest addresses mapped as a quick way of | 203 // We keep the lowest and highest addresses mapped as a quick way of |
| 182 // determining that pointers are outside the heap (used mostly in assertions | 204 // determining that pointers are outside the heap (used mostly in assertions |
| 183 // and verification). The estimate is conservative, ie, not all addresses in | 205 // and verification). The estimate is conservative, ie, not all addresses in |
| 184 // 'allocated' space are actually allocated to our heap. The range is | 206 // 'allocated' space are actually allocated to our heap. The range is |
| 185 // [lowest, highest), inclusive on the low and and exclusive on the high end. | 207 // [lowest, highest), inclusive on the low and and exclusive on the high end. |
| 186 static void* lowest_ever_allocated = reinterpret_cast<void*>(-1); | 208 static void* lowest_ever_allocated = reinterpret_cast<void*>(-1); |
| 187 static void* highest_ever_allocated = reinterpret_cast<void*>(0); | 209 static void* highest_ever_allocated = reinterpret_cast<void*>(0); |
| 188 | 210 |
| 189 | 211 |
| 190 static void UpdateAllocatedSpaceLimits(void* address, int size) { | 212 static void UpdateAllocatedSpaceLimits(void* address, int size) { |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 292 symbols = backtrace_symbols(addresses, frames_count); | 314 symbols = backtrace_symbols(addresses, frames_count); |
| 293 if (symbols == NULL) { | 315 if (symbols == NULL) { |
| 294 DeleteArray(addresses); | 316 DeleteArray(addresses); |
| 295 return kStackWalkError; | 317 return kStackWalkError; |
| 296 } | 318 } |
| 297 | 319 |
| 298 for (int i = 0; i < frames_count; i++) { | 320 for (int i = 0; i < frames_count; i++) { |
| 299 frames[i].address = addresses[i]; | 321 frames[i].address = addresses[i]; |
| 300 // Format a text representation of the frame based on the information | 322 // Format a text representation of the frame based on the information |
| 301 // available. | 323 // available. |
| 302 SNPrintF(frames[i].text, kStackWalkMaxTextLen, "%s", symbols[i]); | 324 SNPrintF(MutableCStrVector(frames[i].text, |
| 325 kStackWalkMaxTextLen), |
| 326 "%s", |
| 327 symbols[i]); |
| 303 // Make sure line termination is in place. | 328 // Make sure line termination is in place. |
| 304 frames[i].text[kStackWalkMaxTextLen - 1] = '\0'; | 329 frames[i].text[kStackWalkMaxTextLen - 1] = '\0'; |
| 305 } | 330 } |
| 306 | 331 |
| 307 DeleteArray(addresses); | 332 DeleteArray(addresses); |
| 308 free(symbols); | 333 free(symbols); |
| 309 | 334 |
| 310 return frames_count; | 335 return frames_count; |
| 311 #endif | 336 #endif |
| 312 } | 337 } |
| (...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 609 } | 634 } |
| 610 | 635 |
| 611 // This sampler is no longer the active sampler. | 636 // This sampler is no longer the active sampler. |
| 612 active_sampler_ = NULL; | 637 active_sampler_ = NULL; |
| 613 active_ = false; | 638 active_ = false; |
| 614 } | 639 } |
| 615 | 640 |
| 616 #endif // ENABLE_LOGGING_AND_PROFILING | 641 #endif // ENABLE_LOGGING_AND_PROFILING |
| 617 | 642 |
| 618 } } // namespace v8::internal | 643 } } // namespace v8::internal |
| OLD | NEW |