Flutter Engine
The Flutter Engine
globals.h
Go to the documentation of this 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
3// BSD-style license that can be found in the LICENSE file.
4
5#ifndef RUNTIME_PLATFORM_GLOBALS_H_
6#define RUNTIME_PLATFORM_GLOBALS_H_
7
8#if __cplusplus >= 201703L // C++17
9#define FALL_THROUGH [[fallthrough]] // NOLINT
10#elif defined(__GNUC__) && __GNUC__ >= 7
11#define FALL_THROUGH __attribute__((fallthrough));
12#elif defined(__clang__)
13#define FALL_THROUGH [[clang::fallthrough]] // NOLINT
14#else
15#define FALL_THROUGH ((void)0)
16#endif
17
18#if !defined(NDEBUG) && !defined(DEBUG)
19#if defined(GOOGLE3)
20// google3 builds use NDEBUG to indicate non-debug builds which is different
21// from the way the Dart project expects it: DEBUG indicating a debug build.
22#define DEBUG
23#else
24// Since <cassert> uses NDEBUG to signify that assert() macros should be turned
25// off, we'll define it when DEBUG is _not_ set.
26#define NDEBUG
27#endif // GOOGLE3
28#endif // !NDEBUG && !DEBUG
29
30// __STDC_FORMAT_MACROS has to be defined before including <inttypes.h> to
31// enable platform independent printf format specifiers.
32#ifndef __STDC_FORMAT_MACROS
33#define __STDC_FORMAT_MACROS
34#endif
35
36#if defined(_WIN32)
37// Cut down on the amount of stuff that gets included via windows.h.
38#if !defined(WIN32_LEAN_AND_MEAN)
39#define WIN32_LEAN_AND_MEAN
40#endif
41
42#if !defined(NOMINMAX)
43#define NOMINMAX
44#endif
45
46#if !defined(NOKERNEL)
47#define NOKERNEL
48#endif
49
50#if !defined(NOSERVICE)
51#define NOSERVICE
52#endif
53
54#if !defined(NOSOUND)
55#define NOSOUND
56#endif
57
58#if !defined(NOMCX)
59#define NOMCX
60#endif
61
62#if !defined(UNICODE)
63#define _UNICODE
64#define UNICODE
65#endif
66
67#include <intrin.h>
68#define RPC_USE_NATIVE_WCHAR
69#include <rpc.h>
70#include <shellapi.h>
71#include <versionhelpers.h>
72#include <windows.h>
73#include <winsock2.h>
74#endif // defined(_WIN32)
75
76#if !defined(_WIN32)
77#include <arpa/inet.h>
78#include <unistd.h>
79#endif // !defined(_WIN32)
80
81#include <float.h>
82#include <inttypes.h>
83#include <limits.h>
84#include <math.h>
85#include <stdarg.h>
86#include <stddef.h>
87#include <stdint.h>
88#include <stdio.h>
89#include <stdlib.h>
90#include <string.h>
91#include <sys/types.h>
92
93#include <cassert> // For assert() in constant expressions.
94
95#if defined(_WIN32)
97#endif // defined(_WIN32)
98
99#if !defined(_WIN32)
101#endif // !defined(_WIN32)
102
103// Target OS detection.
104// for more information on predefined macros:
105// - http://msdn.microsoft.com/en-us/library/b0084kay.aspx
106// - with gcc, run: "echo | gcc -E -dM -"
107#if defined(__ANDROID__)
108
109// Check for Android first, to determine its difference from Linux.
110#define DART_HOST_OS_ANDROID 1
111
112#elif defined(__linux__) || defined(__FreeBSD__)
113
114// Generic Linux.
115#define DART_HOST_OS_LINUX 1
116
117#elif defined(__APPLE__)
118
119// Define the flavor of Mac OS we are running on.
120#include <TargetConditionals.h>
121#define DART_HOST_OS_MACOS 1
122#if TARGET_OS_IPHONE
123#define DART_HOST_OS_IOS 1
124#endif
125
126#elif defined(_WIN32)
127
128// Windows, both 32- and 64-bit, regardless of the check for _WIN32.
129#define DART_HOST_OS_WINDOWS 1
130
131#elif defined(__Fuchsia__)
132#define DART_HOST_OS_FUCHSIA
133
134#elif !defined(DART_HOST_OS_FUCHSIA)
135#error Automatic target os detection failed.
136#endif
137
138#if defined(DEBUG)
139#define DEBUG_ONLY(code) code
140#else // defined(DEBUG)
141#define DEBUG_ONLY(code)
142#endif // defined(DEBUG)
143
144namespace dart {
145
147 union {
148 int32_t int_storage[4];
149 int64_t int64_storage[2];
151 double double_storage[2];
152 };
153 simd128_value_t& readFrom(const float* v) {
154 float_storage[0] = v[0];
155 float_storage[1] = v[1];
156 float_storage[2] = v[2];
157 float_storage[3] = v[3];
158 return *this;
159 }
160 simd128_value_t& readFrom(const int32_t* v) {
161 int_storage[0] = v[0];
162 int_storage[1] = v[1];
163 int_storage[2] = v[2];
164 int_storage[3] = v[3];
165 return *this;
166 }
167 simd128_value_t& readFrom(const double* v) {
168 double_storage[0] = v[0];
169 double_storage[1] = v[1];
170 return *this;
171 }
173 *this = *v;
174 return *this;
175 }
176 void writeTo(float* v) {
177 v[0] = float_storage[0];
178 v[1] = float_storage[1];
179 v[2] = float_storage[2];
180 v[3] = float_storage[3];
181 }
182 void writeTo(int32_t* v) {
183 v[0] = int_storage[0];
184 v[1] = int_storage[1];
185 v[2] = int_storage[2];
186 v[3] = int_storage[3];
187 }
188 void writeTo(double* v) {
189 v[0] = double_storage[0];
190 v[1] = double_storage[1];
191 }
192 void writeTo(simd128_value_t* v) { *v = *this; }
193};
194
195// Processor architecture detection. For more info on what's defined, see:
196// http://msdn.microsoft.com/en-us/library/b0084kay.aspx
197// http://www.agner.org/optimize/calling_conventions.pdf
198// or with gcc, run: "echo | gcc -E -dM -"
199#if defined(_M_X64) || defined(__x86_64__)
200#define HOST_ARCH_X64 1
201#define ARCH_IS_64_BIT 1
202#elif defined(_M_IX86) || defined(__i386__)
203#define HOST_ARCH_IA32 1
204#define ARCH_IS_32_BIT 1
205#elif defined(_M_ARM) || defined(__ARMEL__)
206#define HOST_ARCH_ARM 1
207#define ARCH_IS_32_BIT 1
208#elif defined(_M_ARM64) || defined(__aarch64__)
209#define HOST_ARCH_ARM64 1
210#define ARCH_IS_64_BIT 1
211#elif defined(__riscv)
212#if __SIZEOF_POINTER__ == 4
213#define HOST_ARCH_RISCV32 1
214#define ARCH_IS_32_BIT 1
215#elif __SIZEOF_POINTER__ == 8
216#define HOST_ARCH_RISCV64 1
217#define ARCH_IS_64_BIT 1
218#else
219#error Unknown XLEN
220#endif
221#else
222#error Architecture was not detected as supported by Dart.
223#endif
224
225// DART_FORCE_INLINE strongly hints to the compiler that a function should
226// be inlined. Your function is not guaranteed to be inlined but this is
227// stronger than just using "inline".
228// See: http://msdn.microsoft.com/en-us/library/z8y1yy88.aspx for an
229// explanation of some the cases when a function can never be inlined.
230#ifdef _MSC_VER
231#define DART_FORCE_INLINE __forceinline
232#elif __GNUC__
233#define DART_FORCE_INLINE inline __attribute__((always_inline))
234#else
235#error Automatic compiler detection failed.
236#endif
237
238// DART_NOINLINE tells compiler to never inline a particular function.
239#ifdef _MSC_VER
240#define DART_NOINLINE __declspec(noinline)
241#elif __GNUC__
242#define DART_NOINLINE __attribute__((noinline))
243#else
244#error Automatic compiler detection failed.
245#endif
246
247#ifdef _MSC_VER
248#elif __GNUC__
249#define DART_HAS_COMPUTED_GOTO 1
250#else
251#error Automatic compiler detection failed.
252#endif
253
254// LIKELY/UNLIKELY give the compiler branch predictions that may affect block
255// scheduling.
256#ifdef __GNUC__
257#define LIKELY(cond) __builtin_expect((cond), 1)
258#define UNLIKELY(cond) __builtin_expect((cond), 0)
259#else
260#define LIKELY(cond) cond
261#define UNLIKELY(cond) cond
262#endif
263
264// DART_UNUSED indicates to the compiler that a variable or typedef is expected
265// to be unused and disables the related warning.
266#ifdef __GNUC__
267#define DART_UNUSED __attribute__((unused))
268#else
269#define DART_UNUSED
270#endif
271
272// DART_USED indicates to the compiler that a global variable or typedef is used
273// disables e.g. the gcc warning "unused-variable"
274#ifdef __GNUC__
275#define DART_USED __attribute__((used))
276#else
277#define DART_USED
278#endif
279
280// DART_NORETURN indicates to the compiler that a function does not return.
281// It should be used on functions that unconditionally call functions like
282// exit(), which end the program. We use it to avoid compiler warnings in
283// callers of DART_NORETURN functions.
284#ifdef _MSC_VER
285#define DART_NORETURN __declspec(noreturn)
286#elif __GNUC__
287#define DART_NORETURN __attribute__((noreturn))
288#else
289#error Automatic compiler detection failed.
290#endif
291
292#ifdef _MSC_VER
293#define DART_PRETTY_FUNCTION __FUNCSIG__
294#elif __GNUC__
295#define DART_PRETTY_FUNCTION __PRETTY_FUNCTION__
296#else
297#error Automatic compiler detection failed.
298#endif
299
300#if !defined(TARGET_ARCH_ARM) && !defined(TARGET_ARCH_X64) && \
301 !defined(TARGET_ARCH_IA32) && !defined(TARGET_ARCH_ARM64) && \
302 !defined(TARGET_ARCH_RISCV32) && !defined(TARGET_ARCH_RISCV64)
303// No target architecture specified pick the one matching the host architecture.
304#if defined(HOST_ARCH_ARM)
305#define TARGET_ARCH_ARM 1
306#elif defined(HOST_ARCH_X64)
307#define TARGET_ARCH_X64 1
308#elif defined(HOST_ARCH_IA32)
309#define TARGET_ARCH_IA32 1
310#elif defined(HOST_ARCH_ARM64)
311#define TARGET_ARCH_ARM64 1
312#elif defined(HOST_ARCH_RISCV32)
313#define TARGET_ARCH_RISCV32 1
314#elif defined(HOST_ARCH_RISCV64)
315#define TARGET_ARCH_RISCV64 1
316#else
317#error Automatic target architecture detection failed.
318#endif
319#endif
320
321#if defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_ARM) || \
322 defined(TARGET_ARCH_RISCV32)
323#define TARGET_ARCH_IS_32_BIT 1
324#elif defined(TARGET_ARCH_X64) || defined(TARGET_ARCH_ARM64) || \
325 defined(TARGET_ARCH_RISCV64)
326#define TARGET_ARCH_IS_64_BIT 1
327#else
328#error Automatic target architecture detection failed.
329#endif
330
331#if defined(TARGET_ARCH_IS_64_BIT) && !defined(DART_COMPRESSED_POINTERS)
332#define HAS_SMI_63_BITS 1
333#endif
334
335// Verify that host and target architectures match, we cannot
336// have a 64 bit Dart VM generating 32 bit code or vice-versa.
337#if defined(TARGET_ARCH_X64) || defined(TARGET_ARCH_ARM64) || \
338 defined(TARGET_ARCH_RISCV64)
339#if !defined(ARCH_IS_64_BIT) && !defined(FFI_UNIT_TESTS)
340#error Mismatched Host/Target architectures.
341#endif // !defined(ARCH_IS_64_BIT) && !defined(FFI_UNIT_TESTS)
342#elif defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_ARM) || \
343 defined(TARGET_ARCH_RISCV32)
344#if defined(ARCH_IS_64_BIT) && defined(TARGET_ARCH_ARM)
345// This is simarm_x64 or simarm_arm64, which is the only case where host/target
346// architecture mismatch is allowed. Unless, we're running FFI unit tests.
347#define IS_SIMARM_HOST64 1
348#elif !defined(ARCH_IS_32_BIT) && !defined(FFI_UNIT_TESTS)
349#error Mismatched Host/Target architectures.
350#endif // !defined(ARCH_IS_32_BIT) && !defined(FFI_UNIT_TESTS)
351#endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_ARM)
352
353// Determine whether we will be using the simulator.
354#if defined(TARGET_ARCH_IA32)
355#if !defined(HOST_ARCH_IA32)
356#define USING_SIMULATOR 1
357#endif
358#elif defined(TARGET_ARCH_X64)
359#if !defined(HOST_ARCH_X64)
360#define USING_SIMULATOR 1
361#endif
362#elif defined(TARGET_ARCH_ARM)
363#if !defined(HOST_ARCH_ARM)
364#define TARGET_HOST_MISMATCH 1
365#if !defined(IS_SIMARM_HOST64)
366#define USING_SIMULATOR 1
367#endif
368#endif
369#elif defined(TARGET_ARCH_ARM64)
370#if !defined(HOST_ARCH_ARM64)
371#define USING_SIMULATOR 1
372#endif
373#elif defined(TARGET_ARCH_RISCV32)
374#if !defined(HOST_ARCH_RISCV32)
375#define USING_SIMULATOR 1
376#endif
377#elif defined(TARGET_ARCH_RISCV64)
378#if !defined(HOST_ARCH_RISCV64)
379#define USING_SIMULATOR 1
380#endif
381#else
382#error Unknown architecture.
383#endif
384
385#if !defined(DART_TARGET_OS_ANDROID) && !defined(DART_TARGET_OS_FUCHSIA) && \
386 !defined(DART_TARGET_OS_MACOS_IOS) && !defined(DART_TARGET_OS_LINUX) && \
387 !defined(DART_TARGET_OS_MACOS) && !defined(DART_TARGET_OS_WINDOWS)
388// No target OS specified; pick the one matching the host OS.
389#if defined(DART_HOST_OS_ANDROID)
390#define DART_TARGET_OS_ANDROID 1
391#elif defined(DART_HOST_OS_FUCHSIA)
392#define DART_TARGET_OS_FUCHSIA 1
393#elif defined(DART_HOST_OS_IOS)
394#define DART_TARGET_OS_MACOS 1
395#define DART_TARGET_OS_MACOS_IOS 1
396#elif defined(DART_HOST_OS_LINUX)
397#define DART_TARGET_OS_LINUX 1
398#elif defined(DART_HOST_OS_MACOS)
399#define DART_TARGET_OS_MACOS 1
400#elif defined(DART_HOST_OS_WINDOWS)
401#define DART_TARGET_OS_WINDOWS 1
402#else
403#error Automatic target OS detection failed.
404#endif
405#endif
406
407// Short form printf format specifiers
408#define Pd PRIdPTR
409#define Pu PRIuPTR
410#define Px PRIxPTR
411#define PX PRIXPTR
412#define Pd32 PRId32
413#define Pu32 PRIu32
414#define Px32 PRIx32
415#define PX32 PRIX32
416#define Pd64 PRId64
417#define Pu64 PRIu64
418#define Px64 PRIx64
419#define PX64 PRIX64
420
421// Zero-padded pointer
422#if defined(ARCH_IS_32_BIT)
423#define Pp "08" PRIxPTR
424#else
425#define Pp "016" PRIxPTR
426#endif
427
428// Suffixes for 64-bit integer literals.
429#ifdef _MSC_VER
430#define DART_INT64_C(x) x##I64
431#define DART_UINT64_C(x) x##UI64
432#else
433#define DART_INT64_C(x) x##LL
434#define DART_UINT64_C(x) x##ULL
435#endif
436
437// Replace calls to strtoll with _strtoi64 on Windows.
438#ifdef _MSC_VER
439#define strtoll _strtoi64
440#endif
441
442// Byte sizes.
443constexpr intptr_t kInt8SizeLog2 = 0;
444constexpr intptr_t kInt8Size = 1 << kInt8SizeLog2;
445static_assert(kInt8Size == sizeof(int8_t), "Mismatched int8 size constant");
446constexpr intptr_t kInt16SizeLog2 = 1;
447constexpr intptr_t kInt16Size = 1 << kInt16SizeLog2;
448static_assert(kInt16Size == sizeof(int16_t), "Mismatched int16 size constant");
449constexpr intptr_t kInt32SizeLog2 = 2;
450constexpr intptr_t kInt32Size = 1 << kInt32SizeLog2;
451static_assert(kInt32Size == sizeof(int32_t), "Mismatched int32 size constant");
452constexpr intptr_t kInt64SizeLog2 = 3;
453constexpr intptr_t kInt64Size = 1 << kInt64SizeLog2;
454static_assert(kInt64Size == sizeof(int64_t), "Mismatched int64 size constant");
455
456constexpr intptr_t kDoubleSize = sizeof(double);
457constexpr intptr_t kFloatSize = sizeof(float);
458constexpr intptr_t kQuadSize = 4 * kFloatSize;
459constexpr intptr_t kSimd128Size = sizeof(simd128_value_t);
460
461// Bit sizes.
462constexpr intptr_t kBitsPerByteLog2 = 3;
463constexpr intptr_t kBitsPerByte = 1 << kBitsPerByteLog2;
464constexpr intptr_t kBitsPerInt8 = kInt8Size * kBitsPerByte;
465constexpr intptr_t kBitsPerInt16 = kInt16Size * kBitsPerByte;
466constexpr intptr_t kBitsPerInt32 = kInt32Size * kBitsPerByte;
467constexpr intptr_t kBitsPerInt64 = kInt64Size * kBitsPerByte;
468
469// The following macro works on both 32 and 64-bit platforms.
470// Usage: instead of writing 0x1234567890123456ULL
471// write DART_2PART_UINT64_C(0x12345678,90123456);
472#define DART_2PART_UINT64_C(a, b) \
473 (((static_cast<uint64_t>(a) << kBitsPerInt32) + 0x##b##u))
474
475// Integer constants.
476constexpr int8_t kMinInt8 = 0x80;
477constexpr int8_t kMaxInt8 = 0x7F;
478constexpr uint8_t kMaxUint8 = 0xFF;
479constexpr int16_t kMinInt16 = 0x8000;
480constexpr int16_t kMaxInt16 = 0x7FFF;
481constexpr uint16_t kMaxUint16 = 0xFFFF;
482constexpr int32_t kMinInt32 = 0x80000000;
483constexpr int32_t kMaxInt32 = 0x7FFFFFFF;
484constexpr uint32_t kMaxUint32 = 0xFFFFFFFF;
485constexpr int64_t kMinInt64 = DART_INT64_C(0x8000000000000000);
486constexpr int64_t kMaxInt64 = DART_INT64_C(0x7FFFFFFFFFFFFFFF);
487constexpr uint64_t kMaxUint64 = DART_2PART_UINT64_C(0xFFFFFFFF, FFFFFFFF);
488
489constexpr int kMinInt = INT_MIN;
490constexpr int kMaxInt = INT_MAX;
491constexpr int kMaxUint = UINT_MAX;
492
495 DART_INT64_C(0x7FFFFFFFFFFFFC00);
496constexpr int64_t kSignBitDouble = DART_INT64_C(0x8000000000000000);
497
498// Types for native machine words. Guaranteed to be able to hold pointers and
499// integers.
500typedef intptr_t word;
501typedef uintptr_t uword;
502
503// Byte sizes for native machine words.
504#ifdef ARCH_IS_32_BIT
505constexpr intptr_t kWordSizeLog2 = kInt32SizeLog2;
506#else
507constexpr intptr_t kWordSizeLog2 = kInt64SizeLog2;
508#endif
509constexpr intptr_t kWordSize = 1 << kWordSizeLog2;
510static_assert(kWordSize == sizeof(word), "Mismatched word size constant");
511
512// Bit sizes for native machine words.
514constexpr intptr_t kBitsPerWord = 1 << kBitsPerWordLog2;
515
516// Integer constants for native machine words.
517constexpr word kWordMin = static_cast<uword>(1) << (kBitsPerWord - 1);
518constexpr word kWordMax = (static_cast<uword>(1) << (kBitsPerWord - 1)) - 1;
519constexpr uword kUwordMax = static_cast<uword>(-1);
520
521// Size of a class id assigned to concrete, abstract and top-level classes.
522//
523// We use a signed integer type here to make it comparable with intptr_t.
524typedef int32_t classid_t;
525
526// System-wide named constants.
527constexpr intptr_t KBLog2 = 10;
528constexpr intptr_t KB = 1 << KBLog2;
529constexpr intptr_t MBLog2 = KBLog2 + KBLog2;
530constexpr intptr_t MB = 1 << MBLog2;
531constexpr intptr_t GBLog2 = MBLog2 + KBLog2;
532constexpr intptr_t GB = 1 << GBLog2;
533
534constexpr intptr_t KBInWordsLog2 = KBLog2 - kWordSizeLog2;
535constexpr intptr_t KBInWords = 1 << KBInWordsLog2;
536constexpr intptr_t MBInWordsLog2 = KBLog2 + KBInWordsLog2;
537constexpr intptr_t MBInWords = 1 << MBInWordsLog2;
538constexpr intptr_t GBInWordsLog2 = MBLog2 + KBInWordsLog2;
539constexpr intptr_t GBInWords = 1 << GBInWordsLog2;
540
541// Helpers to round memory sizes to human readable values.
542constexpr intptr_t RoundWordsToKB(intptr_t size_in_words) {
543 return (size_in_words + (KBInWords >> 1)) >> KBInWordsLog2;
544}
545constexpr intptr_t RoundWordsToMB(intptr_t size_in_words) {
546 return (size_in_words + (MBInWords >> 1)) >> MBInWordsLog2;
547}
548constexpr intptr_t RoundWordsToGB(intptr_t size_in_words) {
549 return (size_in_words + (GBInWords >> 1)) >> GBInWordsLog2;
550}
551constexpr double WordsToMB(intptr_t size_in_words) {
552 return static_cast<double>(size_in_words) / MBInWords;
553}
554
555constexpr intptr_t kIntptrOne = 1;
556constexpr intptr_t kIntptrMin = (kIntptrOne << (kBitsPerWord - 1));
557constexpr intptr_t kIntptrMax = ~kIntptrMin;
558
559// Time constants.
560constexpr intptr_t kMillisecondsPerSecond = 1000;
561constexpr intptr_t kMicrosecondsPerMillisecond = 1000;
562constexpr intptr_t kMicrosecondsPerSecond =
564constexpr intptr_t kNanosecondsPerMicrosecond = 1000;
565constexpr intptr_t kNanosecondsPerMillisecond =
567constexpr intptr_t kNanosecondsPerSecond =
569
570// Helpers to scale micro second times to human understandable values.
571constexpr double MicrosecondsToSeconds(int64_t micros) {
572 return static_cast<double>(micros) / kMicrosecondsPerSecond;
573}
574constexpr double MicrosecondsToMilliseconds(int64_t micros) {
575 return static_cast<double>(micros) / kMicrosecondsPerMillisecond;
576}
577
578// A macro to disallow the copy constructor and operator= functions.
579// This should be used in the private: declarations for a class.
580#if !defined(DISALLOW_COPY_AND_ASSIGN)
581#define DISALLOW_COPY_AND_ASSIGN(TypeName) \
582 private: \
583 TypeName(const TypeName&) = delete; \
584 void operator=(const TypeName&) = delete
585#endif // !defined(DISALLOW_COPY_AND_ASSIGN)
586
587// A macro to disallow all the implicit constructors, namely the default
588// constructor, copy constructor and operator= functions. This should be
589// used in the private: declarations for a class that wants to prevent
590// anyone from instantiating it. This is especially useful for classes
591// containing only static methods.
592#if !defined(DISALLOW_IMPLICIT_CONSTRUCTORS)
593#define DISALLOW_IMPLICIT_CONSTRUCTORS(TypeName) \
594 private: \
595 TypeName() = delete; \
596 DISALLOW_COPY_AND_ASSIGN(TypeName)
597#endif // !defined(DISALLOW_IMPLICIT_CONSTRUCTORS)
598
599// Macro to disallow allocation in the C++ heap. This should be used
600// in the private section for a class. Don't use UNREACHABLE here to
601// avoid circular dependencies between platform/globals.h and
602// platform/assert.h.
603#if !defined(DISALLOW_ALLOCATION)
604#define DISALLOW_ALLOCATION() \
605 public: \
606 void operator delete(void* pointer) { \
607 fprintf(stderr, "unreachable code\n"); \
608 abort(); \
609 } \
610 \
611 private: \
612 void* operator new(size_t size);
613#endif // !defined(DISALLOW_ALLOCATION)
614
615// The USE(x) template is used to silence C++ compiler warnings issued
616// for unused variables.
617template <typename T>
618static inline void USE(T&&) {}
619
620// The type-based aliasing rule allows the compiler to assume that
621// pointers of different types (for some definition of different)
622// never alias each other. Thus the following code does not work:
623//
624// float f = foo();
625// int fbits = *(int*)(&f);
626//
627// The compiler 'knows' that the int pointer can't refer to f since
628// the types don't match, so the compiler may cache f in a register,
629// leaving random data in fbits. Using C++ style casts makes no
630// difference, however a pointer to char data is assumed to alias any
631// other pointer. This is the 'memcpy exception'.
632//
633// The bit_cast function uses the memcpy exception to move the bits
634// from a variable of one type to a variable of another type. Of
635// course the end result is likely to be implementation dependent.
636// Most compilers (gcc-4.2 and MSVC 2005) will completely optimize
637// bit_cast away.
638//
639// There is an additional use for bit_cast. Recent gccs will warn when
640// they see casts that may result in breakage due to the type-based
641// aliasing rule. If you have checked that there is no breakage you
642// can use bit_cast to cast one pointer type to another. This confuses
643// gcc enough that it can no longer see that you have cast one pointer
644// type to another thus avoiding the warning.
645template <class D, class S>
646DART_FORCE_INLINE D bit_cast(const S& source) {
647 static_assert(sizeof(D) == sizeof(S),
648 "Source and destination must have the same size");
649
650 D destination;
651 // This use of memcpy is safe: source and destination cannot overlap.
652 memcpy(&destination, &source, sizeof(destination));
653 return destination;
654}
655
656// Similar to bit_cast, but allows copying from types of unrelated
657// sizes. This method was introduced to enable the strict aliasing
658// optimizations of GCC 4.4. Basically, GCC mindlessly relies on
659// obscure details in the C++ standard that make reinterpret_cast
660// virtually useless.
661template <class D, class S>
662DART_FORCE_INLINE D bit_copy(const S& source) {
663 D destination;
664 // This use of memcpy is safe: source and destination cannot overlap.
665 memcpy(&destination, reinterpret_cast<const void*>(&source),
666 sizeof(destination));
667 return destination;
668}
669
670// On Windows the reentrant version of strtok is called
671// strtok_s. Unify on the posix name strtok_r.
672#if defined(DART_HOST_OS_WINDOWS)
673#define snprintf _sprintf_p
674#define strtok_r strtok_s
675#endif
676
677#if !defined(DART_HOST_OS_WINDOWS)
678#if defined(TEMP_FAILURE_RETRY)
679// TEMP_FAILURE_RETRY is defined in unistd.h on some platforms. We should
680// not use that version, but instead the one in signal_blocker.h, to ensure
681// we disable signal interrupts.
682#undef TEMP_FAILURE_RETRY
683#endif // defined(TEMP_FAILURE_RETRY)
684#endif // !defined(DART_HOST_OS_WINDOWS)
685
686#if __GNUC__
687// Tell the compiler to do printf format string checking if the
688// compiler supports it; see the 'format' attribute in
689// <http://gcc.gnu.org/onlinedocs/gcc-4.3.0/gcc/Function-Attributes.html>.
690//
691// N.B.: As the GCC manual states, "[s]ince non-static C++ methods
692// have an implicit 'this' argument, the arguments of such methods
693// should be counted from two, not one."
694#define PRINTF_ATTRIBUTE(string_index, first_to_check) \
695 __attribute__((__format__(__printf__, string_index, first_to_check)))
696#else
697#define PRINTF_ATTRIBUTE(string_index, first_to_check)
698#endif
699
700#if defined(_WIN32)
701#define STDIN_FILENO 0
702#define STDOUT_FILENO 1
703#define STDERR_FILENO 2
704#endif
705
706#ifndef PATH_MAX
707// Most platforms use PATH_MAX, but in Windows it's called MAX_PATH.
708#define PATH_MAX MAX_PATH
709#endif
710
711// Undefine math.h definition which clashes with our condition names.
712#undef OVERFLOW
713
714// Include IL printer and disassembler functionality into non-PRODUCT builds,
715// in all AOT compiler builds or when forced.
716#if !defined(PRODUCT) || defined(DART_PRECOMPILER) || \
717 defined(FORCE_INCLUDE_DISASSEMBLER)
718#if defined(DART_PRECOMPILED_RUNTIME) && defined(PRODUCT)
719#error Requested to include IL printer into PRODUCT AOT runtime
720#endif
721#define INCLUDE_IL_PRINTER 1
722#if !defined(FORCE_INCLUDE_DISASSEMBLER)
723#define FORCE_INCLUDE_DISASSEMBLER 1
724#endif
725#endif
726
727// Include HeapSnapshotWriter functionality if not in PRODUCT.
728#if !defined(DART_ENABLE_HEAP_SNAPSHOT_WRITER) && !defined(PRODUCT)
729#define DART_ENABLE_HEAP_SNAPSHOT_WRITER 1
730#endif
731
732#if defined(DART_HOST_OS_ANDROID)
733#define kHostOperatingSystemName "android"
734#elif defined(DART_HOST_OS_FUCHSIA)
735#define kHostOperatingSystemName "fuchsia"
736#elif defined(DART_HOST_OS_IOS)
737#define kHostOperatingSystemName "ios"
738#elif defined(DART_HOST_OS_LINUX)
739#define kHostOperatingSystemName "linux"
740#elif defined(DART_HOST_OS_MACOS)
741#define kHostOperatingSystemName "macos"
742#elif defined(DART_HOST_OS_WINDOWS)
743#define kHostOperatingSystemName "windows"
744#else
745#error Host operating system detection failed.
746#endif
747
748#if defined(HOST_ARCH_ARM)
749#define kHostArchitectureName "arm"
750#elif defined(HOST_ARCH_ARM64)
751#define kHostArchitectureName "arm64"
752#elif defined(HOST_ARCH_IA32)
753#define kHostArchitectureName "ia32"
754#elif defined(HOST_ARCH_RISCV32)
755#define kHostArchitectureName "riscv32"
756#elif defined(HOST_ARCH_RISCV64)
757#define kHostArchitectureName "riscv64"
758#elif defined(HOST_ARCH_X64)
759#define kHostArchitectureName "x64"
760#else
761#error Host architecture detection failed.
762#endif
763
764#if defined(TARGET_ARCH_ARM)
765#define kTargetArchitectureName "arm"
766#elif defined(TARGET_ARCH_ARM64)
767#define kTargetArchitectureName "arm64"
768#elif defined(TARGET_ARCH_IA32)
769#define kTargetArchitectureName "ia32"
770#elif defined(TARGET_ARCH_RISCV32)
771#define kTargetArchitectureName "riscv32"
772#elif defined(TARGET_ARCH_RISCV64)
773#define kTargetArchitectureName "riscv64"
774#elif defined(TARGET_ARCH_X64)
775#define kTargetArchitectureName "x64"
776#else
777#error Target architecture detection failed.
778#endif
779
780// The ordering between DART_TARGET_OS_MACOS_IOS and DART_TARGET_OS_MACOS
781// below is important, since the latter is sometimes defined when the former
782// is, and sometimes not (e.g., ffi tests), so we need to test the former
783// before the latter.
784#if defined(DART_TARGET_OS_ANDROID)
785#define kTargetOperatingSystemName "android"
786#elif defined(DART_TARGET_OS_FUCHSIA)
787#define kTargetOperatingSystemName "fuchsia"
788#elif defined(DART_TARGET_OS_LINUX)
789#define kTargetOperatingSystemName "linux"
790#elif defined(DART_TARGET_OS_MACOS_IOS)
791#define kTargetOperatingSystemName "ios"
792#elif defined(DART_TARGET_OS_MACOS)
793#define kTargetOperatingSystemName "macos"
794#elif defined(DART_TARGET_OS_WINDOWS)
795#define kTargetOperatingSystemName "windows"
796#else
797#error Target operating system detection failed.
798#endif
799
800} // namespace dart
801
802#endif // RUNTIME_PLATFORM_GLOBALS_H_
SkBitmap source
Definition: examples.cpp:28
Definition: dart_vm.cc:33
constexpr int16_t kMaxInt16
Definition: globals.h:480
constexpr int64_t kMaxInt64
Definition: globals.h:486
constexpr intptr_t MB
Definition: globals.h:530
constexpr int64_t kMinInt64
Definition: globals.h:485
constexpr int kMinInt
Definition: globals.h:489
constexpr intptr_t kBitsPerWordLog2
Definition: globals.h:513
constexpr intptr_t kBitsPerByteLog2
Definition: globals.h:462
constexpr uint8_t kMaxUint8
Definition: globals.h:478
constexpr intptr_t kMicrosecondsPerMillisecond
Definition: globals.h:561
constexpr intptr_t MBInWordsLog2
Definition: globals.h:536
constexpr intptr_t GBInWords
Definition: globals.h:539
constexpr double MicrosecondsToSeconds(int64_t micros)
Definition: globals.h:571
DART_FORCE_INLINE D bit_cast(const S &source)
Definition: globals.h:646
constexpr intptr_t kBitsPerWord
Definition: globals.h:514
constexpr intptr_t kNanosecondsPerMillisecond
Definition: globals.h:565
constexpr intptr_t kMicrosecondsPerSecond
Definition: globals.h:562
constexpr intptr_t RoundWordsToGB(intptr_t size_in_words)
Definition: globals.h:548
constexpr intptr_t RoundWordsToMB(intptr_t size_in_words)
Definition: globals.h:545
constexpr int32_t kMinInt32
Definition: globals.h:482
constexpr intptr_t kNanosecondsPerMicrosecond
Definition: globals.h:564
constexpr intptr_t kInt8Size
Definition: globals.h:444
constexpr intptr_t kIntptrMin
Definition: globals.h:556
constexpr int kMaxInt
Definition: globals.h:490
int32_t classid_t
Definition: globals.h:524
constexpr intptr_t MBLog2
Definition: globals.h:529
constexpr intptr_t kInt64Size
Definition: globals.h:453
constexpr int kMaxUint
Definition: globals.h:491
constexpr uint64_t kMaxUint64
Definition: globals.h:487
constexpr intptr_t kInt32SizeLog2
Definition: globals.h:449
constexpr uint32_t kMaxUint32
Definition: globals.h:484
constexpr intptr_t kBitsPerByte
Definition: globals.h:463
constexpr intptr_t kIntptrOne
Definition: globals.h:555
constexpr intptr_t kSimd128Size
Definition: globals.h:459
constexpr intptr_t kWordSizeLog2
Definition: globals.h:507
constexpr uword kUwordMax
Definition: globals.h:519
constexpr intptr_t KB
Definition: globals.h:528
uintptr_t uword
Definition: globals.h:501
constexpr intptr_t kNanosecondsPerSecond
Definition: globals.h:567
constexpr intptr_t kBitsPerInt16
Definition: globals.h:465
constexpr word kWordMin
Definition: globals.h:517
intptr_t word
Definition: globals.h:500
constexpr intptr_t MBInWords
Definition: globals.h:537
constexpr double WordsToMB(intptr_t size_in_words)
Definition: globals.h:551
constexpr intptr_t kMillisecondsPerSecond
Definition: globals.h:560
constexpr intptr_t kInt16SizeLog2
Definition: globals.h:446
constexpr intptr_t GBLog2
Definition: globals.h:531
constexpr intptr_t kInt8SizeLog2
Definition: globals.h:443
static void USE(T &&)
Definition: globals.h:618
constexpr intptr_t kInt32Size
Definition: globals.h:450
constexpr intptr_t KBInWordsLog2
Definition: globals.h:534
constexpr intptr_t GB
Definition: globals.h:532
constexpr intptr_t kBitsPerInt32
Definition: globals.h:466
constexpr int8_t kMaxInt8
Definition: globals.h:477
constexpr intptr_t kQuadSize
Definition: globals.h:458
constexpr intptr_t GBInWordsLog2
Definition: globals.h:538
constexpr int32_t kMaxInt32
Definition: globals.h:483
constexpr intptr_t kInt64SizeLog2
Definition: globals.h:452
constexpr intptr_t kWordSize
Definition: globals.h:509
constexpr intptr_t kFloatSize
Definition: globals.h:457
constexpr int16_t kMinInt16
Definition: globals.h:479
constexpr double MicrosecondsToMilliseconds(int64_t micros)
Definition: globals.h:574
DART_FORCE_INLINE D bit_copy(const S &source)
Definition: globals.h:662
constexpr int64_t kMinInt64RepresentableAsDouble
Definition: globals.h:493
constexpr intptr_t KBInWords
Definition: globals.h:535
constexpr int64_t kMaxInt64RepresentableAsDouble
Definition: globals.h:494
constexpr intptr_t kDoubleSize
Definition: globals.h:456
constexpr intptr_t kInt16Size
Definition: globals.h:447
constexpr intptr_t KBLog2
Definition: globals.h:527
constexpr int8_t kMinInt8
Definition: globals.h:476
constexpr intptr_t kBitsPerInt64
Definition: globals.h:467
constexpr int64_t kSignBitDouble
Definition: globals.h:496
constexpr intptr_t RoundWordsToKB(intptr_t size_in_words)
Definition: globals.h:542
constexpr uint16_t kMaxUint16
Definition: globals.h:481
constexpr intptr_t kIntptrMax
Definition: globals.h:557
constexpr intptr_t kBitsPerInt8
Definition: globals.h:464
constexpr word kWordMax
Definition: globals.h:518
#define DART_2PART_UINT64_C(a, b)
Definition: globals.h:472
#define DART_INT64_C(x)
Definition: globals.h:433
#define T
Definition: precompiler.cc:65
int32_t int_storage[4]
Definition: globals.h:148
void writeTo(simd128_value_t *v)
Definition: globals.h:192
void writeTo(double *v)
Definition: globals.h:188
double double_storage[2]
Definition: globals.h:151
void writeTo(float *v)
Definition: globals.h:176
int64_t int64_storage[2]
Definition: globals.h:149
simd128_value_t & readFrom(const float *v)
Definition: globals.h:153
float float_storage[4]
Definition: globals.h:150
simd128_value_t & readFrom(const int32_t *v)
Definition: globals.h:160
simd128_value_t & readFrom(const double *v)
Definition: globals.h:167
void writeTo(int32_t *v)
Definition: globals.h:182
simd128_value_t & readFrom(const simd128_value_t *v)
Definition: globals.h:172