[fuchsia][time] Use C11 timespec APIs for UTC time
UTC time is being removed from the zircon kernel. Using timespec_get
ensures that the correct userspace UTC clock handle (supplied to the
process through proc_args) is used for UTC time queries.
See https://bugs.fuchsia.dev/p/fuchsia/issues/detail?id=57506
Change-Id: Id22f0c7c7b0dd785ace4b7aa47e3080addf40e61
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/159589
Commit-Queue: Zach Anderson <zra@google.com>
Auto-Submit: Adam Lesinski <adamlesinski@google.com>
Reviewed-by: Zach Anderson <zra@google.com>
diff --git a/runtime/vm/os_fuchsia.cc b/runtime/vm/os_fuchsia.cc
index c30ee49..6ad304e 100644
--- a/runtime/vm/os_fuchsia.cc
+++ b/runtime/vm/os_fuchsia.cc
@@ -12,9 +12,9 @@
#include <stdint.h>
#include <fuchsia/deprecatedtimezone/cpp/fidl.h>
-#include <lib/async/default.h>
-#include <lib/async-loop/loop.h>
#include <lib/async-loop/default.h>
+#include <lib/async-loop/loop.h>
+#include <lib/async/default.h>
#include <lib/inspect/cpp/inspect.h>
#include <lib/sys/cpp/component_context.h>
#include <lib/sys/cpp/service_directory.h>
@@ -22,6 +22,7 @@
#include <zircon/process.h>
#include <zircon/syscalls.h>
#include <zircon/syscalls/object.h>
+#include <zircon/time.h>
#include <zircon/types.h>
#include "platform/assert.h"
@@ -115,6 +116,15 @@
return true;
}
+int64_t GetCurrentTimeNanos() {
+ struct timespec ts;
+ if (timespec_get(&ts, TIME_UTC) == 0) {
+ FATAL("timespec_get failed");
+ return 0;
+ }
+ return zx_time_add_duration(ZX_SEC(ts.tv_sec), ZX_NSEC(ts.tv_nsec));
+}
+
} // namespace
namespace dart {
@@ -177,21 +187,18 @@
int OS::GetLocalTimeZoneAdjustmentInSeconds() {
int32_t local_offset, dst_offset;
- zx_time_t now = 0;
- zx_clock_get(ZX_CLOCK_UTC, &now);
- zx_status_t status = GetLocalAndDstOffsetInSeconds(
- now / ZX_SEC(1), &local_offset, &dst_offset);
+ int64_t now_seconds = GetCurrentTimeNanos() / ZX_SEC(1);
+ zx_status_t status =
+ GetLocalAndDstOffsetInSeconds(now_seconds, &local_offset, &dst_offset);
return status == ZX_OK ? local_offset : 0;
}
int64_t OS::GetCurrentTimeMillis() {
- return GetCurrentTimeMicros() / 1000;
+ return GetCurrentTimeNanos() / ZX_MSEC(1);
}
int64_t OS::GetCurrentTimeMicros() {
- zx_time_t now = 0;
- zx_clock_get(ZX_CLOCK_UTC, &now);
- return now / kNanosecondsPerMicrosecond;
+ return GetCurrentTimeNanos() / ZX_USEC(1);
}
int64_t OS::GetCurrentMonotonicTicks() {