Flutter Engine
The Flutter Engine
os.h
Go to the documentation of this file.
1// Copyright (c) 2011, 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_VM_OS_H_
6#define RUNTIME_VM_OS_H_
7
8#include "vm/globals.h"
9
10// Forward declarations.
11struct tm;
12
13namespace dart {
14
15// Forward declarations.
16class Zone;
17
18// Interface to the underlying OS platform.
19class OS {
20 public:
21 // Returns the name of the given OS. For example "linux".
22 static const char* Name() { return kHostOperatingSystemName; }
23
24 // Returns the current process id.
25 static intptr_t ProcessId();
26
27 // Returns a time-zone name for the given instant.
28 // The name is provided by the underlying platform.
29 // The returned string may be Zone allocated.
30 static const char* GetTimeZoneName(int64_t seconds_since_epoch);
31
32 // Returns the difference in seconds between local time and UTC for the given
33 // instant.
34 // For example 3600 for CET, and 7200 for CEST.
35 static int GetTimeZoneOffsetInSeconds(int64_t seconds_since_epoch);
36
37 // Returns the current time in milliseconds measured
38 // from midnight January 1, 1970 UTC.
39 static int64_t GetCurrentTimeMillis();
40
41 // Returns the current time in microseconds measured
42 // from midnight January 1, 1970 UTC.
43 static int64_t GetCurrentTimeMicros();
44
45 // Returns the current time used by the tracing infrastructure.
46 static int64_t GetCurrentMonotonicMicros();
47
48 // Returns the raw clock value from the monotonic clock.
49 static int64_t GetCurrentMonotonicTicks();
50
51 // Returns the frequency of the monotonic clock.
53
54 // Returns the value of current thread's CPU usage clock in microseconds.
55 // NOTE: This clock will return different values depending on the calling
56 // thread. It is only expected to increase in value as the thread uses
57 // CPU time.
58 // NOTE: This function will return -1 on OSs that are not supported.
59 static int64_t GetCurrentThreadCPUMicros();
60
61 // If the tracing/timeline configuration on takes timestamps as input, returns
62 // the same value as |GetCurrentMonotonicMicros|. Otherwise, returns -1.
64
65 // Returns the activation frame alignment constraint or one if
66 // the platform doesn't care. Guaranteed to be a power of two.
67 static intptr_t ActivationFrameAlignment();
68
69 // Returns number of available processor cores.
71
72 // Sleep the currently executing thread for millis ms.
73 static void Sleep(int64_t millis);
74
75 // Sleep the currently executing thread for micros microseconds.
76 static void SleepMicros(int64_t micros);
77
78 // Debug break.
79 static void DebugBreak();
80
81 // Returns the current program counter.
82 static uintptr_t GetProgramCounter();
83
84 // Print formatted output to stdout/stderr for debugging.
85 // Tracing and debugging prints from the VM should strongly prefer to use
86 // PrintErr to avoid interfering with the application's output, which may
87 // be parsed by another program.
88 static void Print(const char* format, ...) PRINTF_ATTRIBUTE(1, 2);
89 static void PrintErr(const char* format, ...) PRINTF_ATTRIBUTE(1, 2);
90 static void VFPrint(FILE* stream, const char* format, va_list args);
91
92 // Allocate a string and print formatted output into the buffer.
93 // Uses the zone for allocation if one if provided, and otherwise uses
94 // malloc.
95 static char* SCreate(Zone* zone, const char* format, ...)
96 PRINTF_ATTRIBUTE(2, 3);
97 static char* VSCreate(Zone* zone, const char* format, va_list args);
98
99 // Converts a C string which represents a valid dart integer into a 64 bit
100 // value.
101 // Returns false if it is unable to convert the string to a 64 bit value,
102 // the failure could be because of underflow/overflow or invalid characters.
103 // On success the function returns true and 'value' contains the converted
104 // value.
105 static bool StringToInt64(const char* str, int64_t* value);
106
107 // Register code observers relevant to this OS.
109
110 // Initialize the OS class.
111 static void Init();
112
113 // Cleanup the OS class.
114 static void Cleanup();
115
116 // Only implemented on Windows, prevents cleanup code from running.
117 static void PrepareToAbort();
118
119 DART_NORETURN static void Abort();
120
121 DART_NORETURN static void Exit(int code);
122
123 // Retrieves the DSO base for the given instructions image.
124 static const uint8_t* GetAppDSOBase(const uint8_t* snapshot_instructions);
125 static uword GetAppDSOBase(uword snapshot_instructions) {
126 return reinterpret_cast<uword>(
127 GetAppDSOBase(reinterpret_cast<const uint8_t*>(snapshot_instructions)));
128 }
129
130 struct BuildId {
131 intptr_t len;
132 const uint8_t* data;
133 };
134
135 // Retrieves the build ID information for the given instructions image.
136 // If found, returns a BuildId with the length of the build ID and a pointer
137 // to its contents, otherwise returns a BuildId with contents {0, nullptr}.
138 static BuildId GetAppBuildId(const uint8_t* snapshot_instructions);
139 static BuildId GetAppBuildId(uword snapshot_instructions) {
140 return GetAppBuildId(
141 reinterpret_cast<const uint8_t*>(snapshot_instructions));
142 }
143};
144
145} // namespace dart
146
147#endif // RUNTIME_VM_OS_H_
Definition: os.h:19
static DART_NORETURN void Exit(int code)
static int NumberOfAvailableProcessors()
static const char * GetTimeZoneName(int64_t seconds_since_epoch)
static const char * Name()
Definition: os.h:22
static void SleepMicros(int64_t micros)
static int64_t GetCurrentTimeMillis()
static void RegisterCodeObservers()
static int64_t GetCurrentMonotonicMicros()
static void static void PrintErr(const char *format,...) PRINTF_ATTRIBUTE(1
static void Sleep(int64_t millis)
static void Print(const char *format,...) PRINTF_ATTRIBUTE(1
static bool StringToInt64(const char *str, int64_t *value)
static BuildId GetAppBuildId(const uint8_t *snapshot_instructions)
static const uint8_t * GetAppDSOBase(const uint8_t *snapshot_instructions)
Definition: os.cc:13
static void Init()
static int64_t GetCurrentTimeMicros()
static intptr_t ActivationFrameAlignment()
static BuildId GetAppBuildId(uword snapshot_instructions)
Definition: os.h:139
static void static void static void VFPrint(FILE *stream, const char *format, va_list args)
static void Cleanup()
static void DebugBreak()
static DART_NORETURN void Abort()
static char static char * VSCreate(Zone *zone, const char *format, va_list args)
static int64_t GetCurrentThreadCPUMicros()
static uintptr_t GetProgramCounter()
static intptr_t ProcessId()
static void PrepareToAbort()
static int64_t GetCurrentMonotonicFrequency()
static char * SCreate(Zone *zone, const char *format,...) PRINTF_ATTRIBUTE(2
static int64_t GetCurrentMonotonicTicks()
static int64_t GetCurrentMonotonicMicrosForTimeline()
static int GetTimeZoneOffsetInSeconds(int64_t seconds_since_epoch)
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
uint8_t value
uint32_t uint32_t * format
Definition: dart_vm.cc:33
uintptr_t uword
Definition: globals.h:501
#define PRINTF_ATTRIBUTE(string_index, first_to_check)
Definition: globals.h:697
const uint8_t * data
Definition: os.h:132
intptr_t len
Definition: os.h:131