| 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 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 | 119 |
| 120 double OS::LocalTimeOffset() { | 120 double OS::LocalTimeOffset() { |
| 121 time_t tv = time(NULL); | 121 time_t tv = time(NULL); |
| 122 struct tm* t = localtime(&tv); | 122 struct tm* t = localtime(&tv); |
| 123 // tm_gmtoff includes any daylight savings offset, so subtract it. | 123 // tm_gmtoff includes any daylight savings offset, so subtract it. |
| 124 return static_cast<double>(t->tm_gmtoff * msPerSecond - | 124 return static_cast<double>(t->tm_gmtoff * msPerSecond - |
| 125 (t->tm_isdst > 0 ? 3600 * msPerSecond : 0)); | 125 (t->tm_isdst > 0 ? 3600 * msPerSecond : 0)); |
| 126 } | 126 } |
| 127 | 127 |
| 128 | 128 |
| 129 FILE* OS::FOpen(const char* path, const char* mode) { |
| 130 return fopen(path, mode); |
| 131 } |
| 132 |
| 133 |
| 129 void OS::Print(const char* format, ...) { | 134 void OS::Print(const char* format, ...) { |
| 130 va_list args; | 135 va_list args; |
| 131 va_start(args, format); | 136 va_start(args, format); |
| 132 VPrint(format, args); | 137 VPrint(format, args); |
| 133 va_end(args); | 138 va_end(args); |
| 134 } | 139 } |
| 135 | 140 |
| 136 | 141 |
| 137 void OS::VPrint(const char* format, va_list args) { | 142 void OS::VPrint(const char* format, va_list args) { |
| 138 vprintf(format, args); | 143 vprintf(format, args); |
| 139 } | 144 } |
| 140 | 145 |
| 141 | 146 |
| 142 void OS::PrintError(const char* format, ...) { | 147 void OS::PrintError(const char* format, ...) { |
| 143 va_list args; | 148 va_list args; |
| 144 va_start(args, format); | 149 va_start(args, format); |
| 145 VPrintError(format, args); | 150 VPrintError(format, args); |
| 146 va_end(args); | 151 va_end(args); |
| 147 } | 152 } |
| 148 | 153 |
| 149 | 154 |
| 150 void OS::VPrintError(const char* format, va_list args) { | 155 void OS::VPrintError(const char* format, va_list args) { |
| 151 vfprintf(stderr, format, args); | 156 vfprintf(stderr, format, args); |
| 152 } | 157 } |
| 153 | 158 |
| 154 | 159 |
| 155 int OS::SNPrintF(char* str, size_t size, const char* format, ...) { | 160 int OS::SNPrintF(Vector<char> str, const char* format, ...) { |
| 156 va_list args; | 161 va_list args; |
| 157 va_start(args, format); | 162 va_start(args, format); |
| 158 int result = VSNPrintF(str, size, format, args); | 163 int result = VSNPrintF(str, format, args); |
| 159 va_end(args); | 164 va_end(args); |
| 160 return result; | 165 return result; |
| 161 } | 166 } |
| 162 | 167 |
| 163 | 168 |
| 164 int OS::VSNPrintF(char* str, size_t size, const char* format, va_list args) { | 169 int OS::VSNPrintF(Vector<char> str, |
| 165 int n = vsnprintf(str, size, format, args); // forward to linux. | 170 const char* format, |
| 166 if (n < 0 || static_cast<size_t>(n) >= size) { | 171 va_list args) { |
| 167 str[size - 1] = '\0'; | 172 int n = vsnprintf(str.start(), str.length(), format, args); |
| 173 if (n < 0 || n >= str.length()) { |
| 174 str[str.length() - 1] = '\0'; |
| 168 return -1; | 175 return -1; |
| 169 } else { | 176 } else { |
| 170 return n; | 177 return n; |
| 171 } | 178 } |
| 172 } | 179 } |
| 173 | 180 |
| 174 | 181 |
| 182 void OS::StrNCpy(Vector<char> dest, const char* src, size_t n) { |
| 183 strncpy(dest.start(), src, n); |
| 184 } |
| 185 |
| 186 |
| 187 void OS::WcsCpy(Vector<wchar_t> dest, const wchar_t* src) { |
| 188 wcscpy(dest.start(), src); |
| 189 } |
| 190 |
| 191 |
| 192 char *OS::StrDup(const char* str) { |
| 193 return strdup(str); |
| 194 } |
| 195 |
| 196 |
| 175 double OS::nan_value() { return NAN; } | 197 double OS::nan_value() { return NAN; } |
| 176 | 198 |
| 177 // We keep the lowest and highest addresses mapped as a quick way of | 199 // We keep the lowest and highest addresses mapped as a quick way of |
| 178 // determining that pointers are outside the heap (used mostly in assertions | 200 // determining that pointers are outside the heap (used mostly in assertions |
| 179 // and verification). The estimate is conservative, ie, not all addresses in | 201 // and verification). The estimate is conservative, ie, not all addresses in |
| 180 // 'allocated' space are actually allocated to our heap. The range is | 202 // 'allocated' space are actually allocated to our heap. The range is |
| 181 // [lowest, highest), inclusive on the low and and exclusive on the high end. | 203 // [lowest, highest), inclusive on the low and and exclusive on the high end. |
| 182 static void* lowest_ever_allocated = reinterpret_cast<void*>(-1); | 204 static void* lowest_ever_allocated = reinterpret_cast<void*>(-1); |
| 183 static void* highest_ever_allocated = reinterpret_cast<void*>(0); | 205 static void* highest_ever_allocated = reinterpret_cast<void*>(0); |
| 184 | 206 |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 334 symbols = backtrace_symbols(addresses, frames_count); | 356 symbols = backtrace_symbols(addresses, frames_count); |
| 335 if (symbols == NULL) { | 357 if (symbols == NULL) { |
| 336 DeleteArray(addresses); | 358 DeleteArray(addresses); |
| 337 return kStackWalkError; | 359 return kStackWalkError; |
| 338 } | 360 } |
| 339 | 361 |
| 340 for (int i = 0; i < frames_count; i++) { | 362 for (int i = 0; i < frames_count; i++) { |
| 341 frames[i].address = addresses[i]; | 363 frames[i].address = addresses[i]; |
| 342 // Format a text representation of the frame based on the information | 364 // Format a text representation of the frame based on the information |
| 343 // available. | 365 // available. |
| 344 SNPrintF(frames[i].text, kStackWalkMaxTextLen, "%s", symbols[i]); | 366 SNPrintF(MutableCStrVector(frames[i].text, kStackWalkMaxTextLen), |
| 367 "%s", |
| 368 symbols[i]); |
| 345 // Make sure line termination is in place. | 369 // Make sure line termination is in place. |
| 346 frames[i].text[kStackWalkMaxTextLen - 1] = '\0'; | 370 frames[i].text[kStackWalkMaxTextLen - 1] = '\0'; |
| 347 } | 371 } |
| 348 | 372 |
| 349 DeleteArray(addresses); | 373 DeleteArray(addresses); |
| 350 free(symbols); | 374 free(symbols); |
| 351 | 375 |
| 352 return frames_count; | 376 return frames_count; |
| 353 } | 377 } |
| 354 | 378 |
| (...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 653 } | 677 } |
| 654 | 678 |
| 655 // This sampler is no longer the active sampler. | 679 // This sampler is no longer the active sampler. |
| 656 active_sampler_ = NULL; | 680 active_sampler_ = NULL; |
| 657 active_ = false; | 681 active_ = false; |
| 658 } | 682 } |
| 659 | 683 |
| 660 #endif // ENABLE_LOGGING_AND_PROFILING | 684 #endif // ENABLE_LOGGING_AND_PROFILING |
| 661 | 685 |
| 662 } } // namespace v8::internal | 686 } } // namespace v8::internal |
| OLD | NEW |