Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(71)

Unified Diff: runtime/vm/os_fuchsia.cc

Issue 2148533002: Fuchsia: Platform specific calls needed to Initialize and Cleanup VM. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Address comments Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/vm/cpuinfo_fuchsia.cc ('k') | runtime/vm/virtual_memory.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/os_fuchsia.cc
diff --git a/runtime/vm/os_fuchsia.cc b/runtime/vm/os_fuchsia.cc
index 10faf1c66a977f41db125a8fd0ff83ec51fc2e32..db9264ee2a3526de093d404118e306413dbd7e66 100644
--- a/runtime/vm/os_fuchsia.cc
+++ b/runtime/vm/os_fuchsia.cc
@@ -11,6 +11,7 @@
#include <magenta/types.h>
#include "platform/assert.h"
+#include "vm/zone.h"
namespace dart {
@@ -54,20 +55,19 @@ int64_t OS::GetCurrentTimeMicros() {
int64_t OS::GetCurrentMonotonicTicks() {
- UNIMPLEMENTED();
- return 0;
+ return _magenta_current_time();
}
int64_t OS::GetCurrentMonotonicFrequency() {
- UNIMPLEMENTED();
- return 0;
+ return kNanosecondsPerSecond;
}
int64_t OS::GetCurrentMonotonicMicros() {
- UNIMPLEMENTED();
- return 0;
+ int64_t ticks = GetCurrentMonotonicTicks();
+ ASSERT(GetCurrentMonotonicFrequency() == kNanosecondsPerSecond);
+ return ticks / kNanosecondsPerMicrosecond;
}
@@ -89,16 +89,45 @@ void OS::AlignedFree(void* ptr) {
// TODO(5411554): May need to hoist these architecture dependent code
-// into a architecture specific file e.g: os_ia32_linux.cc
+// into a architecture specific file e.g: os_ia32_fuchsia.cc
intptr_t OS::ActivationFrameAlignment() {
- UNIMPLEMENTED();
- return 0;
+#if defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64) || \
+ defined(TARGET_ARCH_ARM64)
+ const int kMinimumAlignment = 16;
+#elif defined(TARGET_ARCH_ARM) || defined(TARGET_ARCH_DBC)
+ const int kMinimumAlignment = 8;
+#else
+#error Unsupported architecture.
+#endif
+ intptr_t alignment = kMinimumAlignment;
+ // TODO(5411554): Allow overriding default stack alignment for
+ // testing purposes.
+ // Flags::DebugIsInt("stackalign", &alignment);
+ ASSERT(Utils::IsPowerOfTwo(alignment));
+ ASSERT(alignment >= kMinimumAlignment);
+ return alignment;
}
intptr_t OS::PreferredCodeAlignment() {
- UNIMPLEMENTED();
- return 0;
+#if defined(TARGET_ARCH_IA32) || \
+ defined(TARGET_ARCH_X64) || \
+ defined(TARGET_ARCH_ARM64) || \
+ defined(TARGET_ARCH_DBC)
+ const int kMinimumAlignment = 32;
+#elif defined(TARGET_ARCH_ARM) || defined(TARGET_ARCH_MIPS)
+ const int kMinimumAlignment = 16;
+#else
+#error Unsupported architecture.
+#endif
+ intptr_t alignment = kMinimumAlignment;
+ // TODO(5411554): Allow overriding default code alignment for
+ // testing purposes.
+ // Flags::DebugIsInt("codealign", &alignment);
+ ASSERT(Utils::IsPowerOfTwo(alignment));
+ ASSERT(alignment >= kMinimumAlignment);
+ ASSERT(alignment <= OS::kMaxPreferredCodeAlignment);
+ return alignment;
}
@@ -153,26 +182,53 @@ void OS::VFPrint(FILE* stream, const char* format, va_list args) {
int OS::SNPrint(char* str, size_t size, const char* format, ...) {
- UNIMPLEMENTED();
- return 0;
+ va_list args;
+ va_start(args, format);
+ int retval = VSNPrint(str, size, format, args);
+ va_end(args);
+ return retval;
}
int OS::VSNPrint(char* str, size_t size, const char* format, va_list args) {
- UNIMPLEMENTED();
- return 0;
+ int retval = vsnprintf(str, size, format, args);
+ if (retval < 0) {
+ FATAL1("Fatal error in OS::VSNPrint with format '%s'", format);
+ }
+ return retval;
}
char* OS::SCreate(Zone* zone, const char* format, ...) {
- UNIMPLEMENTED();
- return NULL;
+ va_list args;
+ va_start(args, format);
+ char* buffer = VSCreate(zone, format, args);
+ va_end(args);
+ return buffer;
}
char* OS::VSCreate(Zone* zone, const char* format, va_list args) {
- UNIMPLEMENTED();
- return NULL;
+ // Measure.
+ va_list measure_args;
+ va_copy(measure_args, args);
+ intptr_t len = VSNPrint(NULL, 0, format, measure_args);
+ va_end(measure_args);
+
+ char* buffer;
+ if (zone) {
+ buffer = zone->Alloc<char>(len + 1);
+ } else {
+ buffer = reinterpret_cast<char*>(malloc(len + 1));
+ }
+ ASSERT(buffer != NULL);
+
+ // Print.
+ va_list print_args;
+ va_copy(print_args, args);
+ VSNPrint(buffer, len + 1, format, print_args);
+ va_end(print_args);
+ return buffer;
}
« no previous file with comments | « runtime/vm/cpuinfo_fuchsia.cc ('k') | runtime/vm/virtual_memory.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698