OLD | NEW |
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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_FUCHSIA) | 6 #if defined(TARGET_OS_FUCHSIA) |
7 | 7 |
8 #include "vm/os.h" | 8 #include "vm/os.h" |
9 | 9 |
10 #include <magenta/syscalls.h> | 10 #include <magenta/syscalls.h> |
11 #include <magenta/types.h> | 11 #include <magenta/types.h> |
12 | 12 |
13 #include "platform/assert.h" | 13 #include "platform/assert.h" |
| 14 #include "vm/zone.h" |
14 | 15 |
15 namespace dart { | 16 namespace dart { |
16 | 17 |
17 const char* OS::Name() { | 18 const char* OS::Name() { |
18 return "fuchsia"; | 19 return "fuchsia"; |
19 } | 20 } |
20 | 21 |
21 | 22 |
22 intptr_t OS::ProcessId() { | 23 intptr_t OS::ProcessId() { |
23 UNIMPLEMENTED(); | 24 UNIMPLEMENTED(); |
(...skipping 23 matching lines...) Expand all Loading... |
47 return GetCurrentTimeMicros() / 1000; | 48 return GetCurrentTimeMicros() / 1000; |
48 } | 49 } |
49 | 50 |
50 | 51 |
51 int64_t OS::GetCurrentTimeMicros() { | 52 int64_t OS::GetCurrentTimeMicros() { |
52 return _magenta_current_time() / 1000; | 53 return _magenta_current_time() / 1000; |
53 } | 54 } |
54 | 55 |
55 | 56 |
56 int64_t OS::GetCurrentMonotonicTicks() { | 57 int64_t OS::GetCurrentMonotonicTicks() { |
57 UNIMPLEMENTED(); | 58 return _magenta_current_time(); |
58 return 0; | |
59 } | 59 } |
60 | 60 |
61 | 61 |
62 int64_t OS::GetCurrentMonotonicFrequency() { | 62 int64_t OS::GetCurrentMonotonicFrequency() { |
63 UNIMPLEMENTED(); | 63 return kNanosecondsPerSecond; |
64 return 0; | |
65 } | 64 } |
66 | 65 |
67 | 66 |
68 int64_t OS::GetCurrentMonotonicMicros() { | 67 int64_t OS::GetCurrentMonotonicMicros() { |
69 UNIMPLEMENTED(); | 68 int64_t ticks = GetCurrentMonotonicTicks(); |
70 return 0; | 69 ASSERT(GetCurrentMonotonicFrequency() == kNanosecondsPerSecond); |
| 70 return ticks / kNanosecondsPerMicrosecond; |
71 } | 71 } |
72 | 72 |
73 | 73 |
74 int64_t OS::GetCurrentThreadCPUMicros() { | 74 int64_t OS::GetCurrentThreadCPUMicros() { |
75 UNIMPLEMENTED(); | 75 UNIMPLEMENTED(); |
76 return 0; | 76 return 0; |
77 } | 77 } |
78 | 78 |
79 | 79 |
80 void* OS::AlignedAllocate(intptr_t size, intptr_t alignment) { | 80 void* OS::AlignedAllocate(intptr_t size, intptr_t alignment) { |
81 UNIMPLEMENTED(); | 81 UNIMPLEMENTED(); |
82 return NULL; | 82 return NULL; |
83 } | 83 } |
84 | 84 |
85 | 85 |
86 void OS::AlignedFree(void* ptr) { | 86 void OS::AlignedFree(void* ptr) { |
87 UNIMPLEMENTED(); | 87 UNIMPLEMENTED(); |
88 } | 88 } |
89 | 89 |
90 | 90 |
91 // TODO(5411554): May need to hoist these architecture dependent code | 91 // TODO(5411554): May need to hoist these architecture dependent code |
92 // into a architecture specific file e.g: os_ia32_linux.cc | 92 // into a architecture specific file e.g: os_ia32_fuchsia.cc |
93 intptr_t OS::ActivationFrameAlignment() { | 93 intptr_t OS::ActivationFrameAlignment() { |
94 UNIMPLEMENTED(); | 94 #if defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64) || \ |
95 return 0; | 95 defined(TARGET_ARCH_ARM64) |
| 96 const int kMinimumAlignment = 16; |
| 97 #elif defined(TARGET_ARCH_ARM) || defined(TARGET_ARCH_DBC) |
| 98 const int kMinimumAlignment = 8; |
| 99 #else |
| 100 #error Unsupported architecture. |
| 101 #endif |
| 102 intptr_t alignment = kMinimumAlignment; |
| 103 // TODO(5411554): Allow overriding default stack alignment for |
| 104 // testing purposes. |
| 105 // Flags::DebugIsInt("stackalign", &alignment); |
| 106 ASSERT(Utils::IsPowerOfTwo(alignment)); |
| 107 ASSERT(alignment >= kMinimumAlignment); |
| 108 return alignment; |
96 } | 109 } |
97 | 110 |
98 | 111 |
99 intptr_t OS::PreferredCodeAlignment() { | 112 intptr_t OS::PreferredCodeAlignment() { |
100 UNIMPLEMENTED(); | 113 #if defined(TARGET_ARCH_IA32) || \ |
101 return 0; | 114 defined(TARGET_ARCH_X64) || \ |
| 115 defined(TARGET_ARCH_ARM64) || \ |
| 116 defined(TARGET_ARCH_DBC) |
| 117 const int kMinimumAlignment = 32; |
| 118 #elif defined(TARGET_ARCH_ARM) || defined(TARGET_ARCH_MIPS) |
| 119 const int kMinimumAlignment = 16; |
| 120 #else |
| 121 #error Unsupported architecture. |
| 122 #endif |
| 123 intptr_t alignment = kMinimumAlignment; |
| 124 // TODO(5411554): Allow overriding default code alignment for |
| 125 // testing purposes. |
| 126 // Flags::DebugIsInt("codealign", &alignment); |
| 127 ASSERT(Utils::IsPowerOfTwo(alignment)); |
| 128 ASSERT(alignment >= kMinimumAlignment); |
| 129 ASSERT(alignment <= OS::kMaxPreferredCodeAlignment); |
| 130 return alignment; |
102 } | 131 } |
103 | 132 |
104 | 133 |
105 bool OS::AllowStackFrameIteratorFromAnotherThread() { | 134 bool OS::AllowStackFrameIteratorFromAnotherThread() { |
106 UNIMPLEMENTED(); | 135 UNIMPLEMENTED(); |
107 return false; | 136 return false; |
108 } | 137 } |
109 | 138 |
110 | 139 |
111 int OS::NumberOfAvailableProcessors() { | 140 int OS::NumberOfAvailableProcessors() { |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
146 } | 175 } |
147 | 176 |
148 | 177 |
149 void OS::VFPrint(FILE* stream, const char* format, va_list args) { | 178 void OS::VFPrint(FILE* stream, const char* format, va_list args) { |
150 vfprintf(stream, format, args); | 179 vfprintf(stream, format, args); |
151 fflush(stream); | 180 fflush(stream); |
152 } | 181 } |
153 | 182 |
154 | 183 |
155 int OS::SNPrint(char* str, size_t size, const char* format, ...) { | 184 int OS::SNPrint(char* str, size_t size, const char* format, ...) { |
156 UNIMPLEMENTED(); | 185 va_list args; |
157 return 0; | 186 va_start(args, format); |
| 187 int retval = VSNPrint(str, size, format, args); |
| 188 va_end(args); |
| 189 return retval; |
158 } | 190 } |
159 | 191 |
160 | 192 |
161 int OS::VSNPrint(char* str, size_t size, const char* format, va_list args) { | 193 int OS::VSNPrint(char* str, size_t size, const char* format, va_list args) { |
162 UNIMPLEMENTED(); | 194 int retval = vsnprintf(str, size, format, args); |
163 return 0; | 195 if (retval < 0) { |
| 196 FATAL1("Fatal error in OS::VSNPrint with format '%s'", format); |
| 197 } |
| 198 return retval; |
164 } | 199 } |
165 | 200 |
166 | 201 |
167 char* OS::SCreate(Zone* zone, const char* format, ...) { | 202 char* OS::SCreate(Zone* zone, const char* format, ...) { |
168 UNIMPLEMENTED(); | 203 va_list args; |
169 return NULL; | 204 va_start(args, format); |
| 205 char* buffer = VSCreate(zone, format, args); |
| 206 va_end(args); |
| 207 return buffer; |
170 } | 208 } |
171 | 209 |
172 | 210 |
173 char* OS::VSCreate(Zone* zone, const char* format, va_list args) { | 211 char* OS::VSCreate(Zone* zone, const char* format, va_list args) { |
174 UNIMPLEMENTED(); | 212 // Measure. |
175 return NULL; | 213 va_list measure_args; |
| 214 va_copy(measure_args, args); |
| 215 intptr_t len = VSNPrint(NULL, 0, format, measure_args); |
| 216 va_end(measure_args); |
| 217 |
| 218 char* buffer; |
| 219 if (zone) { |
| 220 buffer = zone->Alloc<char>(len + 1); |
| 221 } else { |
| 222 buffer = reinterpret_cast<char*>(malloc(len + 1)); |
| 223 } |
| 224 ASSERT(buffer != NULL); |
| 225 |
| 226 // Print. |
| 227 va_list print_args; |
| 228 va_copy(print_args, args); |
| 229 VSNPrint(buffer, len + 1, format, print_args); |
| 230 va_end(print_args); |
| 231 return buffer; |
176 } | 232 } |
177 | 233 |
178 | 234 |
179 bool OS::StringToInt64(const char* str, int64_t* value) { | 235 bool OS::StringToInt64(const char* str, int64_t* value) { |
180 UNIMPLEMENTED(); | 236 UNIMPLEMENTED(); |
181 return false; | 237 return false; |
182 } | 238 } |
183 | 239 |
184 | 240 |
185 void OS::RegisterCodeObservers() { | 241 void OS::RegisterCodeObservers() { |
(...skipping 28 matching lines...) Expand all Loading... |
214 } | 270 } |
215 | 271 |
216 | 272 |
217 void OS::Exit(int code) { | 273 void OS::Exit(int code) { |
218 UNIMPLEMENTED(); | 274 UNIMPLEMENTED(); |
219 } | 275 } |
220 | 276 |
221 } // namespace dart | 277 } // namespace dart |
222 | 278 |
223 #endif // defined(TARGET_OS_FUCHSIA) | 279 #endif // defined(TARGET_OS_FUCHSIA) |
OLD | NEW |