Chromium Code Reviews| 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_LINUX) | 6 #if defined(TARGET_OS_OPENBSD) |
| 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 <malloc.h> // NOLINT | 12 #include <stdlib.h> // NOLINT |
| 13 #include <time.h> // NOLINT | 13 #include <time.h> // NOLINT |
| 14 #include <sys/resource.h> // NOLINT | 14 #include <sys/resource.h> // NOLINT |
| 15 #include <sys/time.h> // NOLINT | 15 #include <sys/time.h> // NOLINT |
| 16 #include <sys/types.h> // NOLINT | 16 #include <sys/types.h> // NOLINT |
| 17 #include <sys/syscall.h> // NOLINT | |
| 18 #include <sys/stat.h> // NOLINT | 17 #include <sys/stat.h> // NOLINT |
| 19 #include <fcntl.h> // NOLINT | 18 #include <fcntl.h> // NOLINT |
| 20 #include <unistd.h> // NOLINT | 19 #include <unistd.h> // NOLINT |
| 21 | 20 |
| 22 #include "platform/utils.h" | 21 #include "platform/utils.h" |
| 23 #include "vm/code_observers.h" | 22 #include "vm/code_observers.h" |
| 24 #include "vm/dart.h" | 23 #include "vm/dart.h" |
| 25 #include "vm/debuginfo.h" | 24 #include "vm/debuginfo.h" |
| 26 #include "vm/isolate.h" | 25 #include "vm/isolate.h" |
| 27 #include "vm/lockers.h" | 26 #include "vm/lockers.h" |
| (...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 252 #elif defined(TARGET_ARCH_ARM64) | 251 #elif defined(TARGET_ARCH_ARM64) |
| 253 return kElfMachARM64; | 252 return kElfMachARM64; |
| 254 #elif defined(TARGET_ARCH_MIPS) | 253 #elif defined(TARGET_ARCH_MIPS) |
| 255 return kElfMachMIPS; | 254 return kElfMachMIPS; |
| 256 #else | 255 #else |
| 257 #error Unknown architecture. | 256 #error Unknown architecture. |
| 258 #endif | 257 #endif |
| 259 } | 258 } |
| 260 | 259 |
| 261 pid_t gettid() { | 260 pid_t gettid() { |
| 262 // libc doesn't wrap the Linux-specific gettid system call. | |
| 263 // Note that this thread id is not the same as the posix thread id. | 261 // Note that this thread id is not the same as the posix thread id. |
| 264 return syscall(SYS_gettid); | 262 return getthrid(); |
| 265 } | 263 } |
| 266 | 264 |
| 267 uint64_t GetKernelTimeNanos() { | 265 uint64_t GetKernelTimeNanos() { |
| 268 if (clock_id_ != kInvalidClockId) { | 266 if (clock_id_ != kInvalidClockId) { |
| 269 struct timespec ts; | 267 struct timespec ts; |
| 270 int r = clock_gettime(clock_id_, &ts); | 268 int r = clock_gettime(clock_id_, &ts); |
| 271 ASSERT(r == 0); | 269 ASSERT(r == 0); |
| 272 uint64_t nanos = static_cast<uint64_t>(ts.tv_sec) * | 270 uint64_t nanos = static_cast<uint64_t>(ts.tv_sec) * |
| 273 static_cast<uint64_t>(kNanosecondsPerSecond); | 271 static_cast<uint64_t>(kNanosecondsPerSecond); |
| 274 nanos += static_cast<uint64_t>(ts.tv_nsec); | 272 nanos += static_cast<uint64_t>(ts.tv_nsec); |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 330 | 328 |
| 331 void* out_file_; | 329 void* out_file_; |
| 332 int clock_fd_; | 330 int clock_fd_; |
| 333 int clock_id_; | 331 int clock_id_; |
| 334 uint64_t code_sequence_; | 332 uint64_t code_sequence_; |
| 335 DISALLOW_COPY_AND_ASSIGN(JitdumpCodeObserver); | 333 DISALLOW_COPY_AND_ASSIGN(JitdumpCodeObserver); |
| 336 }; | 334 }; |
| 337 | 335 |
| 338 | 336 |
| 339 const char* OS::Name() { | 337 const char* OS::Name() { |
| 340 return "linux"; | 338 return "openbsd"; |
| 341 } | 339 } |
| 342 | 340 |
| 343 | 341 |
| 344 intptr_t OS::ProcessId() { | 342 intptr_t OS::ProcessId() { |
| 345 return static_cast<intptr_t>(getpid()); | 343 return static_cast<intptr_t>(getpid()); |
| 346 } | 344 } |
| 347 | 345 |
| 348 | 346 |
| 349 static bool LocalTime(int64_t seconds_since_epoch, tm* tm_result) { | 347 static bool LocalTime(int64_t seconds_since_epoch, tm* tm_result) { |
| 350 time_t seconds = static_cast<time_t>(seconds_since_epoch); | 348 time_t seconds = static_cast<time_t>(seconds_since_epoch); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 388 int64_t OS::GetCurrentTimeMicros() { | 386 int64_t OS::GetCurrentTimeMicros() { |
| 389 // gettimeofday has microsecond resolution. | 387 // gettimeofday has microsecond resolution. |
| 390 struct timeval tv; | 388 struct timeval tv; |
| 391 if (gettimeofday(&tv, NULL) < 0) { | 389 if (gettimeofday(&tv, NULL) < 0) { |
| 392 UNREACHABLE(); | 390 UNREACHABLE(); |
| 393 return 0; | 391 return 0; |
| 394 } | 392 } |
| 395 return (static_cast<int64_t>(tv.tv_sec) * 1000000) + tv.tv_usec; | 393 return (static_cast<int64_t>(tv.tv_sec) * 1000000) + tv.tv_usec; |
| 396 } | 394 } |
| 397 | 395 |
| 398 | |
| 399 int64_t OS::GetCurrentMonotonicMicros() { | 396 int64_t OS::GetCurrentMonotonicMicros() { |
| 400 struct timespec ts; | 397 struct timespec ts; |
| 401 if (clock_gettime(CLOCK_MONOTONIC, &ts) != 0) { | 398 if (clock_gettime(CLOCK_MONOTONIC, &ts) != 0) { |
| 402 UNREACHABLE(); | 399 UNREACHABLE(); |
| 403 return 0; | 400 return 0; |
| 404 } | 401 } |
| 405 // Convert to microseconds. | 402 // Convert to microseconds. |
| 406 int64_t result = ts.tv_sec; | 403 int64_t result = ts.tv_sec; |
| 407 result *= kMicrosecondsPerSecond; | 404 result *= kMicrosecondsPerSecond; |
| 408 result += (ts.tv_nsec / kNanosecondsPerMicrosecond); | 405 result += (ts.tv_nsec / kNanosecondsPerMicrosecond); |
| 409 return result; | 406 return result; |
| 410 } | 407 } |
| 411 | 408 |
| 412 | |
| 413 void* OS::AlignedAllocate(intptr_t size, intptr_t alignment) { | 409 void* OS::AlignedAllocate(intptr_t size, intptr_t alignment) { |
| 414 const int kMinimumAlignment = 16; | 410 const int kMinimumAlignment = 16; |
| 415 ASSERT(Utils::IsPowerOfTwo(alignment)); | 411 ASSERT(Utils::IsPowerOfTwo(alignment)); |
| 416 ASSERT(alignment >= kMinimumAlignment); | 412 ASSERT(alignment >= kMinimumAlignment); |
| 417 void* p = memalign(alignment, size); | 413 void* p = NULL; |
| 418 if (p == NULL) { | 414 if (posix_memalign(&p, alignment, size)) { |
| 419 UNREACHABLE(); | 415 UNREACHABLE(); |
| 420 } | 416 } |
| 421 return p; | 417 return p; |
| 422 } | 418 } |
| 423 | 419 |
| 424 | 420 |
| 425 void OS::AlignedFree(void* ptr) { | 421 void OS::AlignedFree(void* ptr) { |
| 426 free(ptr); | 422 free(ptr); |
| 427 } | 423 } |
| 428 | 424 |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 544 | 540 |
| 545 | 541 |
| 546 int OS::VSNPrint(char* str, size_t size, const char* format, va_list args) { | 542 int OS::VSNPrint(char* str, size_t size, const char* format, va_list args) { |
| 547 int retval = vsnprintf(str, size, format, args); | 543 int retval = vsnprintf(str, size, format, args); |
| 548 if (retval < 0) { | 544 if (retval < 0) { |
| 549 FATAL1("Fatal error in OS::VSNPrint with format '%s'", format); | 545 FATAL1("Fatal error in OS::VSNPrint with format '%s'", format); |
| 550 } | 546 } |
| 551 return retval; | 547 return retval; |
| 552 } | 548 } |
| 553 | 549 |
| 554 | |
|
Ivan Posva
2016/01/11 23:58:40
White space changes.
mulander
2016/01/12 00:22:46
Acknowledged.
| |
| 555 char* OS::SCreate(Zone* zone, const char* format, ...) { | 550 char* OS::SCreate(Zone* zone, const char* format, ...) { |
| 556 va_list args; | 551 va_list args; |
| 557 va_start(args, format); | 552 va_start(args, format); |
| 558 char* buffer = VSCreate(zone, format, args); | 553 char* buffer = VSCreate(zone, format, args); |
| 559 va_end(args); | 554 va_end(args); |
| 560 return buffer; | 555 return buffer; |
| 561 } | 556 } |
| 562 | 557 |
| 563 | |
| 564 char* OS::VSCreate(Zone* zone, const char* format, va_list args) { | 558 char* OS::VSCreate(Zone* zone, const char* format, va_list args) { |
| 565 // Measure. | 559 // Measure. |
| 566 va_list measure_args; | 560 va_list measure_args; |
| 567 va_copy(measure_args, args); | 561 va_copy(measure_args, args); |
| 568 intptr_t len = VSNPrint(NULL, 0, format, measure_args); | 562 intptr_t len = VSNPrint(NULL, 0, format, measure_args); |
| 569 va_end(measure_args); | 563 va_end(measure_args); |
| 570 | 564 |
| 571 char* buffer; | 565 char* buffer; |
| 572 if (zone) { | 566 if (zone) { |
| 573 buffer = zone->Alloc<char>(len + 1); | 567 buffer = zone->Alloc<char>(len + 1); |
| 574 } else { | 568 } else { |
| 575 buffer = reinterpret_cast<char*>(malloc(len + 1)); | 569 buffer = reinterpret_cast<char*>(malloc(len + 1)); |
| 576 } | 570 } |
| 577 ASSERT(buffer != NULL); | 571 ASSERT(buffer != NULL); |
| 578 | 572 |
| 579 // Print. | 573 // Print. |
| 580 va_list print_args; | 574 va_list print_args; |
| 581 va_copy(print_args, args); | 575 va_copy(print_args, args); |
| 582 VSNPrint(buffer, len + 1, format, print_args); | 576 VSNPrint(buffer, len + 1, format, print_args); |
| 583 va_end(print_args); | 577 va_end(print_args); |
| 584 return buffer; | 578 return buffer; |
| 585 } | 579 } |
| 586 | 580 |
| 587 | |
| 588 bool OS::StringToInt64(const char* str, int64_t* value) { | 581 bool OS::StringToInt64(const char* str, int64_t* value) { |
| 589 ASSERT(str != NULL && strlen(str) > 0 && value != NULL); | 582 ASSERT(str != NULL && strlen(str) > 0 && value != NULL); |
| 590 int32_t base = 10; | 583 int32_t base = 10; |
| 591 char* endptr; | 584 char* endptr; |
| 592 int i = 0; | 585 int i = 0; |
| 593 if (str[0] == '-') { | 586 if (str[0] == '-') { |
| 594 i = 1; | 587 i = 1; |
| 595 } | 588 } |
| 596 if ((str[i] == '0') && | 589 if ((str[i] == '0') && |
| 597 (str[i + 1] == 'x' || str[i + 1] == 'X') && | 590 (str[i + 1] == 'x' || str[i + 1] == 'X') && |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 646 abort(); | 639 abort(); |
| 647 } | 640 } |
| 648 | 641 |
| 649 | 642 |
| 650 void OS::Exit(int code) { | 643 void OS::Exit(int code) { |
| 651 exit(code); | 644 exit(code); |
| 652 } | 645 } |
| 653 | 646 |
| 654 } // namespace dart | 647 } // namespace dart |
| 655 | 648 |
| 656 #endif // defined(TARGET_OS_LINUX) | 649 #endif // defined(TARGET_OS_OPENBSD) |
| OLD | NEW |