| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #include "vm/globals.h" | 5 #include "vm/globals.h" |
| 6 #if defined(TARGET_OS_MACOS) | 6 #if defined(TARGET_OS_MACOS) |
| 7 | 7 |
| 8 #include "vm/os.h" | 8 #include "vm/os.h" |
| 9 | 9 |
| 10 #include <errno.h> // NOLINT | 10 #include <errno.h> // NOLINT |
| 11 #include <limits.h> // NOLINT | 11 #include <limits.h> // NOLINT |
| 12 #include <mach/mach.h> // NOLINT | 12 #include <mach/mach.h> // NOLINT |
| 13 #include <mach/clock.h> // NOLINT | 13 #include <mach/clock.h> // NOLINT |
| 14 #include <mach/mach_time.h> // NOLINT | 14 #include <mach/mach_time.h> // NOLINT |
| 15 #include <sys/time.h> // NOLINT | 15 #include <sys/time.h> // NOLINT |
| 16 #include <sys/resource.h> // NOLINT | 16 #include <sys/resource.h> // NOLINT |
| 17 #include <unistd.h> // NOLINT | 17 #include <unistd.h> // NOLINT |
| 18 #if TARGET_OS_IOS | 18 #if TARGET_OS_IOS |
| 19 #include <sys/sysctl.h> // NOLINT | 19 #include <sys/sysctl.h> // NOLINT |
| 20 #include <syslog.h> // NOLINT | 20 #include <syslog.h> // NOLINT |
| 21 #endif | 21 #endif |
| 22 | 22 |
| 23 #include "platform/utils.h" | 23 #include "platform/utils.h" |
| 24 #include "vm/isolate.h" | 24 #include "vm/isolate.h" |
| 25 #include "vm/zone.h" | 25 #include "vm/zone.h" |
| 26 | 26 |
| 27 namespace dart { | 27 namespace dart { |
| 28 | 28 |
| 29 const char* OS::Name() { | 29 const char* OS::Name() { |
| 30 #if TARGET_OS_IOS | 30 #if TARGET_OS_IOS |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 | 146 |
| 147 | 147 |
| 148 int64_t OS::GetCurrentThreadCPUMicros() { | 148 int64_t OS::GetCurrentThreadCPUMicros() { |
| 149 mach_msg_type_number_t count = THREAD_BASIC_INFO_COUNT; | 149 mach_msg_type_number_t count = THREAD_BASIC_INFO_COUNT; |
| 150 thread_basic_info_data_t info_data; | 150 thread_basic_info_data_t info_data; |
| 151 thread_basic_info_t info = &info_data; | 151 thread_basic_info_t info = &info_data; |
| 152 mach_port_t thread_port = mach_thread_self(); | 152 mach_port_t thread_port = mach_thread_self(); |
| 153 if (thread_port == MACH_PORT_NULL) { | 153 if (thread_port == MACH_PORT_NULL) { |
| 154 return -1; | 154 return -1; |
| 155 } | 155 } |
| 156 kern_return_t r = thread_info(thread_port, THREAD_BASIC_INFO, | 156 kern_return_t r = |
| 157 (thread_info_t)info, &count); | 157 thread_info(thread_port, THREAD_BASIC_INFO, (thread_info_t)info, &count); |
| 158 mach_port_deallocate(mach_task_self(), thread_port); | 158 mach_port_deallocate(mach_task_self(), thread_port); |
| 159 ASSERT(r == KERN_SUCCESS); | 159 ASSERT(r == KERN_SUCCESS); |
| 160 int64_t thread_cpu_micros = | 160 int64_t thread_cpu_micros = |
| 161 (info->system_time.seconds + info->user_time.seconds); | 161 (info->system_time.seconds + info->user_time.seconds); |
| 162 thread_cpu_micros *= kMicrosecondsPerSecond; | 162 thread_cpu_micros *= kMicrosecondsPerSecond; |
| 163 thread_cpu_micros += info->user_time.microseconds; | 163 thread_cpu_micros += info->user_time.microseconds; |
| 164 thread_cpu_micros += info->system_time.microseconds; | 164 thread_cpu_micros += info->system_time.microseconds; |
| 165 return thread_cpu_micros; | 165 return thread_cpu_micros; |
| 166 } | 166 } |
| 167 | 167 |
| 168 | 168 |
| 169 intptr_t OS::ActivationFrameAlignment() { | 169 intptr_t OS::ActivationFrameAlignment() { |
| 170 #if TARGET_OS_IOS | 170 #if TARGET_OS_IOS |
| 171 #if TARGET_ARCH_ARM | 171 #if TARGET_ARCH_ARM |
| 172 // Even if we generate code that maintains a stronger alignment, we cannot | 172 // Even if we generate code that maintains a stronger alignment, we cannot |
| 173 // assert the stronger stack alignment because C++ code will not maintain it. | 173 // assert the stronger stack alignment because C++ code will not maintain it. |
| 174 return 8; | 174 return 8; |
| 175 #elif TARGET_ARCH_ARM64 | 175 #elif TARGET_ARCH_ARM64 |
| 176 return 16; | 176 return 16; |
| 177 #elif TARGET_ARCH_IA32 | 177 #elif TARGET_ARCH_IA32 |
| 178 return 16; // iOS simulator | 178 return 16; // iOS simulator |
| 179 #elif TARGET_ARCH_X64 | 179 #elif TARGET_ARCH_X64 |
| 180 return 16; // iOS simulator | 180 return 16; // iOS simulator |
| 181 #elif TARGET_ARCH_DBC | 181 #elif TARGET_ARCH_DBC |
| 182 return 16; | 182 return 16; |
| 183 #else | 183 #else |
| 184 #error Unimplemented | 184 #error Unimplemented |
| 185 #endif | 185 #endif |
| 186 #else // TARGET_OS_IOS | 186 #else // TARGET_OS_IOS |
| 187 // OS X activation frames must be 16 byte-aligned; see "Mac OS X ABI | 187 // OS X activation frames must be 16 byte-aligned; see "Mac OS X ABI |
| 188 // Function Call Guide". | 188 // Function Call Guide". |
| 189 return 16; | 189 return 16; |
| 190 #endif // TARGET_OS_IOS | 190 #endif // TARGET_OS_IOS |
| 191 } | 191 } |
| 192 | 192 |
| 193 | 193 |
| 194 intptr_t OS::PreferredCodeAlignment() { | 194 intptr_t OS::PreferredCodeAlignment() { |
| 195 #if defined(TARGET_ARCH_IA32) || \ | 195 #if defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64) || \ |
| 196 defined(TARGET_ARCH_X64) || \ | 196 defined(TARGET_ARCH_ARM64) || defined(TARGET_ARCH_DBC) |
| 197 defined(TARGET_ARCH_ARM64) || \ | |
| 198 defined(TARGET_ARCH_DBC) | |
| 199 const int kMinimumAlignment = 32; | 197 const int kMinimumAlignment = 32; |
| 200 #elif defined(TARGET_ARCH_ARM) || defined(TARGET_ARCH_MIPS) | 198 #elif defined(TARGET_ARCH_ARM) || defined(TARGET_ARCH_MIPS) |
| 201 const int kMinimumAlignment = 16; | 199 const int kMinimumAlignment = 16; |
| 202 #else | 200 #else |
| 203 #error Unsupported architecture. | 201 #error Unsupported architecture. |
| 204 #endif | 202 #endif |
| 205 intptr_t alignment = kMinimumAlignment; | 203 intptr_t alignment = kMinimumAlignment; |
| 206 // TODO(5411554): Allow overriding default code alignment for | 204 // TODO(5411554): Allow overriding default code alignment for |
| 207 // testing purposes. | 205 // testing purposes. |
| 208 // Flags::DebugIsInt("codealign", &alignment); | 206 // Flags::DebugIsInt("codealign", &alignment); |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 262 } | 260 } |
| 263 } | 261 } |
| 264 | 262 |
| 265 | 263 |
| 266 void OS::DebugBreak() { | 264 void OS::DebugBreak() { |
| 267 __builtin_trap(); | 265 __builtin_trap(); |
| 268 } | 266 } |
| 269 | 267 |
| 270 | 268 |
| 271 char* OS::StrNDup(const char* s, intptr_t n) { | 269 char* OS::StrNDup(const char* s, intptr_t n) { |
| 272 // strndup has only been added to Mac OS X in 10.7. We are supplying | 270 // strndup has only been added to Mac OS X in 10.7. We are supplying |
| 273 // our own copy here if needed. | 271 // our own copy here if needed. |
| 274 #if !defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) || \ | 272 #if !defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) || \ |
| 275 __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ <= 1060 | 273 __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ <= 1060 |
| 276 intptr_t len = strlen(s); | 274 intptr_t len = strlen(s); |
| 277 if ((n < 0) || (len < 0)) { | 275 if ((n < 0) || (len < 0)) { |
| 278 return NULL; | 276 return NULL; |
| 279 } | 277 } |
| 280 if (n < len) { | 278 if (n < len) { |
| 281 len = n; | 279 len = n; |
| 282 } | 280 } |
| 283 char* result = reinterpret_cast<char*>(malloc(len + 1)); | 281 char* result = reinterpret_cast<char*>(malloc(len + 1)); |
| 284 if (result == NULL) { | 282 if (result == NULL) { |
| 285 return NULL; | 283 return NULL; |
| 286 } | 284 } |
| 287 result[len] = '\0'; | 285 result[len] = '\0'; |
| 288 return reinterpret_cast<char*>(memmove(result, s, len)); | 286 return reinterpret_cast<char*>(memmove(result, s, len)); |
| 289 #else // !defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) || ... | 287 #else // !defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) || ... |
| 290 return strndup(s, n); | 288 return strndup(s, n); |
| 291 #endif // !defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) || ... | 289 #endif // !defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) || ... |
| 292 } | 290 } |
| 293 | 291 |
| 294 | 292 |
| 295 intptr_t OS::StrNLen(const char* s, intptr_t n) { | 293 intptr_t OS::StrNLen(const char* s, intptr_t n) { |
| 296 // strnlen has only been added to Mac OS X in 10.7. We are supplying | 294 // strnlen has only been added to Mac OS X in 10.7. We are supplying |
| 297 // our own copy here if needed. | 295 // our own copy here if needed. |
| 298 #if !defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) || \ | 296 #if !defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) || \ |
| 299 __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ <= 1060 | 297 __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ <= 1060 |
| 300 intptr_t len = 0; | 298 intptr_t len = 0; |
| 301 while ((len <= n) && (*s != '\0')) { | 299 while ((len <= n) && (*s != '\0')) { |
| 302 s++; | 300 s++; |
| 303 len++; | 301 len++; |
| 304 } | 302 } |
| 305 return len; | 303 return len; |
| 306 #else // !defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) || ... | 304 #else // !defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) || ... |
| 307 return strnlen(s, n); | 305 return strnlen(s, n); |
| 308 #endif // !defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) || ... | 306 #endif // !defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) || ... |
| 309 } | 307 } |
| 310 | 308 |
| 311 | 309 |
| 312 void OS::Print(const char* format, ...) { | 310 void OS::Print(const char* format, ...) { |
| 313 #if TARGET_OS_IOS | 311 #if TARGET_OS_IOS |
| 314 va_list args; | 312 va_list args; |
| 315 va_start(args, format); | 313 va_start(args, format); |
| 316 vsyslog(LOG_INFO, format, args); | 314 vsyslog(LOG_INFO, format, args); |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 382 | 380 |
| 383 | 381 |
| 384 bool OS::StringToInt64(const char* str, int64_t* value) { | 382 bool OS::StringToInt64(const char* str, int64_t* value) { |
| 385 ASSERT(str != NULL && strlen(str) > 0 && value != NULL); | 383 ASSERT(str != NULL && strlen(str) > 0 && value != NULL); |
| 386 int32_t base = 10; | 384 int32_t base = 10; |
| 387 char* endptr; | 385 char* endptr; |
| 388 int i = 0; | 386 int i = 0; |
| 389 if (str[0] == '-') { | 387 if (str[0] == '-') { |
| 390 i = 1; | 388 i = 1; |
| 391 } | 389 } |
| 392 if ((str[i] == '0') && | 390 if ((str[i] == '0') && (str[i + 1] == 'x' || str[i + 1] == 'X') && |
| 393 (str[i + 1] == 'x' || str[i + 1] == 'X') && | |
| 394 (str[i + 2] != '\0')) { | 391 (str[i + 2] != '\0')) { |
| 395 base = 16; | 392 base = 16; |
| 396 } | 393 } |
| 397 errno = 0; | 394 errno = 0; |
| 398 *value = strtoll(str, &endptr, base); | 395 *value = strtoll(str, &endptr, base); |
| 399 return ((errno == 0) && (endptr != str) && (*endptr == 0)); | 396 return ((errno == 0) && (endptr != str) && (*endptr == 0)); |
| 400 } | 397 } |
| 401 | 398 |
| 402 | 399 |
| 403 void OS::RegisterCodeObservers() { | 400 void OS::RegisterCodeObservers() {} |
| 404 } | |
| 405 | 401 |
| 406 | 402 |
| 407 void OS::PrintErr(const char* format, ...) { | 403 void OS::PrintErr(const char* format, ...) { |
| 408 #if TARGET_OS_IOS | 404 #if TARGET_OS_IOS |
| 409 va_list args; | 405 va_list args; |
| 410 va_start(args, format); | 406 va_start(args, format); |
| 411 vsyslog(LOG_ERR, format, args); | 407 vsyslog(LOG_ERR, format, args); |
| 412 va_end(args); | 408 va_end(args); |
| 413 #else | 409 #else |
| 414 va_list args; | 410 va_list args; |
| 415 va_start(args, format); | 411 va_start(args, format); |
| 416 VFPrint(stderr, format, args); | 412 VFPrint(stderr, format, args); |
| 417 va_end(args); | 413 va_end(args); |
| 418 #endif | 414 #endif |
| 419 } | 415 } |
| 420 | 416 |
| 421 | 417 |
| 422 void OS::InitOnce() { | 418 void OS::InitOnce() { |
| 423 // TODO(5411554): For now we check that initonce is called only once, | 419 // TODO(5411554): For now we check that initonce is called only once, |
| 424 // Once there is more formal mechanism to call InitOnce we can move | 420 // Once there is more formal mechanism to call InitOnce we can move |
| 425 // this check there. | 421 // this check there. |
| 426 static bool init_once_called = false; | 422 static bool init_once_called = false; |
| 427 ASSERT(init_once_called == false); | 423 ASSERT(init_once_called == false); |
| 428 init_once_called = true; | 424 init_once_called = true; |
| 429 } | 425 } |
| 430 | 426 |
| 431 | 427 |
| 432 void OS::Shutdown() { | 428 void OS::Shutdown() {} |
| 433 } | |
| 434 | 429 |
| 435 | 430 |
| 436 void OS::Abort() { | 431 void OS::Abort() { |
| 437 abort(); | 432 abort(); |
| 438 } | 433 } |
| 439 | 434 |
| 440 | 435 |
| 441 void OS::Exit(int code) { | 436 void OS::Exit(int code) { |
| 442 exit(code); | 437 exit(code); |
| 443 } | 438 } |
| 444 | 439 |
| 445 } // namespace dart | 440 } // namespace dart |
| 446 | 441 |
| 447 #endif // defined(TARGET_OS_MACOS) | 442 #endif // defined(TARGET_OS_MACOS) |
| OLD | NEW |