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 #ifndef RUNTIME_PLATFORM_GLOBALS_H_ | 5 #ifndef RUNTIME_PLATFORM_GLOBALS_H_ |
6 #define RUNTIME_PLATFORM_GLOBALS_H_ | 6 #define RUNTIME_PLATFORM_GLOBALS_H_ |
7 | 7 |
8 // __STDC_FORMAT_MACROS has to be defined before including <inttypes.h> to | 8 // __STDC_FORMAT_MACROS has to be defined before including <inttypes.h> to |
9 // enable platform independent printf format specifiers. | 9 // enable platform independent printf format specifiers. |
10 #ifndef __STDC_FORMAT_MACROS | 10 #ifndef __STDC_FORMAT_MACROS |
(...skipping 28 matching lines...) Expand all Loading... |
39 | 39 |
40 #if !defined(NOMCX) | 40 #if !defined(NOMCX) |
41 #define NOMCX | 41 #define NOMCX |
42 #endif | 42 #endif |
43 | 43 |
44 #if !defined(UNICODE) | 44 #if !defined(UNICODE) |
45 #define _UNICODE | 45 #define _UNICODE |
46 #define UNICODE | 46 #define UNICODE |
47 #endif | 47 #endif |
48 | 48 |
| 49 #include <Rpc.h> |
| 50 #include <VersionHelpers.h> |
| 51 #include <shellapi.h> |
49 #include <windows.h> | 52 #include <windows.h> |
50 #include <winsock2.h> | 53 #include <winsock2.h> |
51 #include <Rpc.h> | |
52 #include <shellapi.h> | |
53 #include <VersionHelpers.h> | |
54 #endif // defined(_WIN32) | 54 #endif // defined(_WIN32) |
55 | 55 |
56 #if !defined(_WIN32) | 56 #if !defined(_WIN32) |
57 #include <arpa/inet.h> | 57 #include <arpa/inet.h> |
58 #include <inttypes.h> | 58 #include <inttypes.h> |
59 #include <stdint.h> | 59 #include <stdint.h> |
60 #include <unistd.h> | 60 #include <unistd.h> |
61 #endif // !defined(_WIN32) | 61 #endif // !defined(_WIN32) |
62 | 62 |
63 #include <float.h> | 63 #include <float.h> |
64 #include <limits.h> | 64 #include <limits.h> |
65 #include <stdarg.h> | 65 #include <stdarg.h> |
66 #include <stddef.h> | 66 #include <stddef.h> |
67 #include <stdio.h> | 67 #include <stdio.h> |
68 #include <stdlib.h> | 68 #include <stdlib.h> |
69 #include <string.h> | 69 #include <string.h> |
70 #include <sys/types.h> | 70 #include <sys/types.h> |
71 | 71 |
72 #if defined(_WIN32) | 72 #if defined(_WIN32) |
73 #include "platform/c99_support_win.h" | 73 #include "platform/c99_support_win.h" |
| 74 #include "platform/floating_point_win.h" |
74 #include "platform/inttypes_support_win.h" | 75 #include "platform/inttypes_support_win.h" |
75 #include "platform/floating_point_win.h" | |
76 #endif // defined(_WIN32) | 76 #endif // defined(_WIN32) |
77 | 77 |
78 #include "platform/math.h" | 78 #include "platform/math.h" |
79 | 79 |
80 #if !defined(_WIN32) | 80 #if !defined(_WIN32) |
81 #include "platform/floating_point.h" | 81 #include "platform/floating_point.h" |
82 #endif // !defined(_WIN32) | 82 #endif // !defined(_WIN32) |
83 | 83 |
84 // Target OS detection. | 84 // Target OS detection. |
85 // for more information on predefined macros: | 85 // for more information on predefined macros: |
(...skipping 25 matching lines...) Expand all Loading... |
111 // Windows, both 32- and 64-bit, regardless of the check for _WIN32. | 111 // Windows, both 32- and 64-bit, regardless of the check for _WIN32. |
112 #define HOST_OS_WINDOWS 1 | 112 #define HOST_OS_WINDOWS 1 |
113 | 113 |
114 #elif defined(__Fuchsia__) | 114 #elif defined(__Fuchsia__) |
115 #define HOST_OS_FUCHSIA | 115 #define HOST_OS_FUCHSIA |
116 | 116 |
117 #elif !defined(HOST_OS_FUCHSIA) | 117 #elif !defined(HOST_OS_FUCHSIA) |
118 #error Automatic target os detection failed. | 118 #error Automatic target os detection failed. |
119 #endif | 119 #endif |
120 | 120 |
121 | |
122 // Setup product, release or debug build related macros. | 121 // Setup product, release or debug build related macros. |
123 #if defined(PRODUCT) && defined(DEBUG) | 122 #if defined(PRODUCT) && defined(DEBUG) |
124 #error Both PRODUCT and DEBUG defined. | 123 #error Both PRODUCT and DEBUG defined. |
125 #endif // defined(PRODUCT) && defined(DEBUG) | 124 #endif // defined(PRODUCT) && defined(DEBUG) |
126 | 125 |
127 #if defined(PRODUCT) | 126 #if defined(PRODUCT) |
128 #define NOT_IN_PRODUCT(code) | 127 #define NOT_IN_PRODUCT(code) |
129 #else // defined(PRODUCT) | 128 #else // defined(PRODUCT) |
130 #define NOT_IN_PRODUCT(code) code | 129 #define NOT_IN_PRODUCT(code) code |
131 #endif // defined(PRODUCT) | 130 #endif // defined(PRODUCT) |
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
353 #else | 352 #else |
354 #error Unknown architecture. | 353 #error Unknown architecture. |
355 #endif | 354 #endif |
356 | 355 |
357 // Disable background threads by default on armv5te. The relevant | 356 // Disable background threads by default on armv5te. The relevant |
358 // implementations are uniprocessors. | 357 // implementations are uniprocessors. |
359 #if !defined(TARGET_ARCH_ARM_5TE) | 358 #if !defined(TARGET_ARCH_ARM_5TE) |
360 #define ARCH_IS_MULTI_CORE 1 | 359 #define ARCH_IS_MULTI_CORE 1 |
361 #endif | 360 #endif |
362 | 361 |
363 | |
364 #if !defined(TARGET_OS_ANDROID) && !defined(TARGET_OS_FUCHSIA) && \ | 362 #if !defined(TARGET_OS_ANDROID) && !defined(TARGET_OS_FUCHSIA) && \ |
365 !defined(TARGET_OS_MACOS_IOS) && !defined(TARGET_OS_LINUX) && \ | 363 !defined(TARGET_OS_MACOS_IOS) && !defined(TARGET_OS_LINUX) && \ |
366 !defined(TARGET_OS_MACOS) && !defined(TARGET_OS_WINDOWS) | 364 !defined(TARGET_OS_MACOS) && !defined(TARGET_OS_WINDOWS) |
367 // No target OS specified; pick the one matching the host OS. | 365 // No target OS specified; pick the one matching the host OS. |
368 #if defined(HOST_OS_ANDROID) | 366 #if defined(HOST_OS_ANDROID) |
369 #define TARGET_OS_ANDROID 1 | 367 #define TARGET_OS_ANDROID 1 |
370 #elif defined(HOST_OS_FUCHSIA) | 368 #elif defined(HOST_OS_FUCHSIA) |
371 #define TARGET_OS_FUCHSIA 1 | 369 #define TARGET_OS_FUCHSIA 1 |
372 #elif defined(HOST_OS_IOS) | 370 #elif defined(HOST_OS_IOS) |
373 #define TARGET_OS_MACOS 1 | 371 #define TARGET_OS_MACOS 1 |
374 #define TARGET_OS_MACOS_IOS 1 | 372 #define TARGET_OS_MACOS_IOS 1 |
375 #elif defined(HOST_OS_LINUX) | 373 #elif defined(HOST_OS_LINUX) |
376 #define TARGET_OS_LINUX 1 | 374 #define TARGET_OS_LINUX 1 |
377 #elif defined(HOST_OS_MACOS) | 375 #elif defined(HOST_OS_MACOS) |
378 #define TARGET_OS_MACOS 1 | 376 #define TARGET_OS_MACOS 1 |
379 #elif defined(HOST_OS_WINDOWS) | 377 #elif defined(HOST_OS_WINDOWS) |
380 #define TARGET_OS_WINDOWS 1 | 378 #define TARGET_OS_WINDOWS 1 |
381 #else | 379 #else |
382 #error Automatic target OS detection failed. | 380 #error Automatic target OS detection failed. |
383 #endif | 381 #endif |
384 #endif | 382 #endif |
385 | 383 |
386 | |
387 // Short form printf format specifiers | 384 // Short form printf format specifiers |
388 #define Pd PRIdPTR | 385 #define Pd PRIdPTR |
389 #define Pu PRIuPTR | 386 #define Pu PRIuPTR |
390 #define Px PRIxPTR | 387 #define Px PRIxPTR |
391 #define Pd64 PRId64 | 388 #define Pd64 PRId64 |
392 #define Pu64 PRIu64 | 389 #define Pu64 PRIu64 |
393 #define Px64 PRIx64 | 390 #define Px64 PRIx64 |
394 | 391 |
395 // Zero-padded pointer | 392 // Zero-padded pointer |
396 #if defined(ARCH_IS_32_BIT) | 393 #if defined(ARCH_IS_32_BIT) |
397 #define Pp "08" PRIxPTR | 394 #define Pp "08" PRIxPTR |
398 #else | 395 #else |
399 #define Pp "016" PRIxPTR | 396 #define Pp "016" PRIxPTR |
400 #endif | 397 #endif |
401 | 398 |
402 | |
403 // Suffixes for 64-bit integer literals. | 399 // Suffixes for 64-bit integer literals. |
404 #ifdef _MSC_VER | 400 #ifdef _MSC_VER |
405 #define DART_INT64_C(x) x##I64 | 401 #define DART_INT64_C(x) x##I64 |
406 #define DART_UINT64_C(x) x##UI64 | 402 #define DART_UINT64_C(x) x##UI64 |
407 #else | 403 #else |
408 #define DART_INT64_C(x) x##LL | 404 #define DART_INT64_C(x) x##LL |
409 #define DART_UINT64_C(x) x##ULL | 405 #define DART_UINT64_C(x) x##ULL |
410 #endif | 406 #endif |
411 | 407 |
412 // Replace calls to strtoll with _strtoi64 on Windows. | 408 // Replace calls to strtoll with _strtoi64 on Windows. |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
546 \ | 542 \ |
547 private: \ | 543 private: \ |
548 void* operator new(size_t size); | 544 void* operator new(size_t size); |
549 #endif // !defined(DISALLOW_ALLOCATION) | 545 #endif // !defined(DISALLOW_ALLOCATION) |
550 | 546 |
551 // The USE(x) template is used to silence C++ compiler warnings issued | 547 // The USE(x) template is used to silence C++ compiler warnings issued |
552 // for unused variables. | 548 // for unused variables. |
553 template <typename T> | 549 template <typename T> |
554 static inline void USE(T) {} | 550 static inline void USE(T) {} |
555 | 551 |
556 | |
557 // Use implicit_cast as a safe version of static_cast or const_cast | 552 // Use implicit_cast as a safe version of static_cast or const_cast |
558 // for upcasting in the type hierarchy (i.e. casting a pointer to Foo | 553 // for upcasting in the type hierarchy (i.e. casting a pointer to Foo |
559 // to a pointer to SuperclassOfFoo or casting a pointer to Foo to | 554 // to a pointer to SuperclassOfFoo or casting a pointer to Foo to |
560 // a const pointer to Foo). | 555 // a const pointer to Foo). |
561 // When you use implicit_cast, the compiler checks that the cast is safe. | 556 // When you use implicit_cast, the compiler checks that the cast is safe. |
562 // Such explicit implicit_casts are necessary in surprisingly many | 557 // Such explicit implicit_casts are necessary in surprisingly many |
563 // situations where C++ demands an exact type match instead of an | 558 // situations where C++ demands an exact type match instead of an |
564 // argument type convertible to a target type. | 559 // argument type convertible to a target type. |
565 // | 560 // |
566 // The From type can be inferred, so the preferred syntax for using | 561 // The From type can be inferred, so the preferred syntax for using |
567 // implicit_cast is the same as for static_cast etc.: | 562 // implicit_cast is the same as for static_cast etc.: |
568 // | 563 // |
569 // implicit_cast<ToType>(expr) | 564 // implicit_cast<ToType>(expr) |
570 // | 565 // |
571 // implicit_cast would have been part of the C++ standard library, | 566 // implicit_cast would have been part of the C++ standard library, |
572 // but the proposal was submitted too late. It will probably make | 567 // but the proposal was submitted too late. It will probably make |
573 // its way into the language in the future. | 568 // its way into the language in the future. |
574 template <typename To, typename From> | 569 template <typename To, typename From> |
575 inline To implicit_cast(From const& f) { | 570 inline To implicit_cast(From const& f) { |
576 return f; | 571 return f; |
577 } | 572 } |
578 | 573 |
579 | |
580 // Use like this: down_cast<T*>(foo); | 574 // Use like this: down_cast<T*>(foo); |
581 template <typename To, typename From> // use like this: down_cast<T*>(foo); | 575 template <typename To, typename From> // use like this: down_cast<T*>(foo); |
582 inline To down_cast(From* f) { // so we only accept pointers | 576 inline To down_cast(From* f) { // so we only accept pointers |
583 // Ensures that To is a sub-type of From *. This test is here only | 577 // Ensures that To is a sub-type of From *. This test is here only |
584 // for compile-time type checking, and has no overhead in an | 578 // for compile-time type checking, and has no overhead in an |
585 // optimized build at run-time, as it will be optimized away completely. | 579 // optimized build at run-time, as it will be optimized away completely. |
586 if (false) { | 580 if (false) { |
587 implicit_cast<From, To>(0); | 581 implicit_cast<From, To>(0); |
588 } | 582 } |
589 return static_cast<To>(f); | 583 return static_cast<To>(f); |
590 } | 584 } |
591 | 585 |
592 | |
593 // The type-based aliasing rule allows the compiler to assume that | 586 // The type-based aliasing rule allows the compiler to assume that |
594 // pointers of different types (for some definition of different) | 587 // pointers of different types (for some definition of different) |
595 // never alias each other. Thus the following code does not work: | 588 // never alias each other. Thus the following code does not work: |
596 // | 589 // |
597 // float f = foo(); | 590 // float f = foo(); |
598 // int fbits = *(int*)(&f); | 591 // int fbits = *(int*)(&f); |
599 // | 592 // |
600 // The compiler 'knows' that the int pointer can't refer to f since | 593 // The compiler 'knows' that the int pointer can't refer to f since |
601 // the types don't match, so the compiler may cache f in a register, | 594 // the types don't match, so the compiler may cache f in a register, |
602 // leaving random data in fbits. Using C++ style casts makes no | 595 // leaving random data in fbits. Using C++ style casts makes no |
(...skipping 17 matching lines...) Expand all Loading... |
620 // Compile time assertion: sizeof(D) == sizeof(S). A compile error | 613 // Compile time assertion: sizeof(D) == sizeof(S). A compile error |
621 // here means your D and S have different sizes. | 614 // here means your D and S have different sizes. |
622 DART_UNUSED typedef char VerifySizesAreEqual[sizeof(D) == sizeof(S) ? 1 : -1]; | 615 DART_UNUSED typedef char VerifySizesAreEqual[sizeof(D) == sizeof(S) ? 1 : -1]; |
623 | 616 |
624 D destination; | 617 D destination; |
625 // This use of memcpy is safe: source and destination cannot overlap. | 618 // This use of memcpy is safe: source and destination cannot overlap. |
626 memcpy(&destination, &source, sizeof(destination)); | 619 memcpy(&destination, &source, sizeof(destination)); |
627 return destination; | 620 return destination; |
628 } | 621 } |
629 | 622 |
630 | |
631 // Similar to bit_cast, but allows copying from types of unrelated | 623 // Similar to bit_cast, but allows copying from types of unrelated |
632 // sizes. This method was introduced to enable the strict aliasing | 624 // sizes. This method was introduced to enable the strict aliasing |
633 // optimizations of GCC 4.4. Basically, GCC mindlessly relies on | 625 // optimizations of GCC 4.4. Basically, GCC mindlessly relies on |
634 // obscure details in the C++ standard that make reinterpret_cast | 626 // obscure details in the C++ standard that make reinterpret_cast |
635 // virtually useless. | 627 // virtually useless. |
636 template <class D, class S> | 628 template <class D, class S> |
637 inline D bit_copy(const S& source) { | 629 inline D bit_copy(const S& source) { |
638 D destination; | 630 D destination; |
639 // This use of memcpy is safe: source and destination cannot overlap. | 631 // This use of memcpy is safe: source and destination cannot overlap. |
640 memcpy(&destination, reinterpret_cast<const void*>(&source), | 632 memcpy(&destination, reinterpret_cast<const void*>(&source), |
641 sizeof(destination)); | 633 sizeof(destination)); |
642 return destination; | 634 return destination; |
643 } | 635 } |
644 | 636 |
645 | |
646 #if defined(HOST_ARCH_ARM) || defined(HOST_ARCH_ARM64) | 637 #if defined(HOST_ARCH_ARM) || defined(HOST_ARCH_ARM64) |
647 // Similar to bit_copy and bit_cast, but does take the type from the argument. | 638 // Similar to bit_copy and bit_cast, but does take the type from the argument. |
648 template <typename T> | 639 template <typename T> |
649 static inline T ReadUnaligned(const T* ptr) { | 640 static inline T ReadUnaligned(const T* ptr) { |
650 T value; | 641 T value; |
651 memcpy(reinterpret_cast<void*>(&value), reinterpret_cast<const void*>(ptr), | 642 memcpy(reinterpret_cast<void*>(&value), reinterpret_cast<const void*>(ptr), |
652 sizeof(value)); | 643 sizeof(value)); |
653 return value; | 644 return value; |
654 } | 645 } |
655 | 646 |
656 | |
657 // Similar to bit_copy and bit_cast, but does take the type from the argument. | 647 // Similar to bit_copy and bit_cast, but does take the type from the argument. |
658 template <typename T> | 648 template <typename T> |
659 static inline void StoreUnaligned(T* ptr, T value) { | 649 static inline void StoreUnaligned(T* ptr, T value) { |
660 memcpy(reinterpret_cast<void*>(ptr), reinterpret_cast<const void*>(&value), | 650 memcpy(reinterpret_cast<void*>(ptr), reinterpret_cast<const void*>(&value), |
661 sizeof(value)); | 651 sizeof(value)); |
662 } | 652 } |
663 #else // !(HOST_ARCH_ARM || HOST_ARCH_ARM64) | 653 #else // !(HOST_ARCH_ARM || HOST_ARCH_ARM64) |
664 // Similar to bit_copy and bit_cast, but does take the type from the argument. | 654 // Similar to bit_copy and bit_cast, but does take the type from the argument. |
665 template <typename T> | 655 template <typename T> |
666 static inline T ReadUnaligned(const T* ptr) { | 656 static inline T ReadUnaligned(const T* ptr) { |
667 return *ptr; | 657 return *ptr; |
668 } | 658 } |
669 | 659 |
670 | |
671 // Similar to bit_copy and bit_cast, but does take the type from the argument. | 660 // Similar to bit_copy and bit_cast, but does take the type from the argument. |
672 template <typename T> | 661 template <typename T> |
673 static inline void StoreUnaligned(T* ptr, T value) { | 662 static inline void StoreUnaligned(T* ptr, T value) { |
674 *ptr = value; | 663 *ptr = value; |
675 } | 664 } |
676 #endif // !(HOST_ARCH_ARM || HOST_ARCH_ARM64) | 665 #endif // !(HOST_ARCH_ARM || HOST_ARCH_ARM64) |
677 | 666 |
678 | |
679 // On Windows the reentrent version of strtok is called | 667 // On Windows the reentrent version of strtok is called |
680 // strtok_s. Unify on the posix name strtok_r. | 668 // strtok_s. Unify on the posix name strtok_r. |
681 #if defined(HOST_OS_WINDOWS) | 669 #if defined(HOST_OS_WINDOWS) |
682 #define snprintf _snprintf | 670 #define snprintf _snprintf |
683 #define strtok_r strtok_s | 671 #define strtok_r strtok_s |
684 #endif | 672 #endif |
685 | 673 |
686 #if !defined(HOST_OS_WINDOWS) | 674 #if !defined(HOST_OS_WINDOWS) |
687 #if defined(TEMP_FAILURE_RETRY) | 675 #if defined(TEMP_FAILURE_RETRY) |
688 // TEMP_FAILURE_RETRY is defined in unistd.h on some platforms. We should | 676 // TEMP_FAILURE_RETRY is defined in unistd.h on some platforms. We should |
(...skipping 27 matching lines...) Expand all Loading... |
716 // tag in the ICData and check it when recreating the flow graph in | 704 // tag in the ICData and check it when recreating the flow graph in |
717 // optimizing compiler. Enable it for other modes (product, release) if needed | 705 // optimizing compiler. Enable it for other modes (product, release) if needed |
718 // for debugging. | 706 // for debugging. |
719 #if defined(DEBUG) | 707 #if defined(DEBUG) |
720 #define TAG_IC_DATA | 708 #define TAG_IC_DATA |
721 #endif | 709 #endif |
722 | 710 |
723 } // namespace dart | 711 } // namespace dart |
724 | 712 |
725 #endif // RUNTIME_PLATFORM_GLOBALS_H_ | 713 #endif // RUNTIME_PLATFORM_GLOBALS_H_ |
OLD | NEW |