[vm] Avoid querying boot time on Mac/iOS.

mach_absolute_time uses the same clock as CLOCK_UPTIME_RAW. There are privacy concerns that boot time can be used for device fingerprinting. Dart doesn't not need to know boot time, only some monotonic clock.

TEST=ci
Change-Id: I57acd080bb93ce9cf51b4b90aec09bb7cab7f7af
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/348044
Commit-Queue: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Brian Quinlan <bquinlan@google.com>
This commit is contained in:
Ryan Macnak 2024-01-26 18:21:14 +00:00 committed by Commit Queue
parent c4b9d63cf1
commit 24f838370d
2 changed files with 4 additions and 25 deletions

View file

@ -71,25 +71,15 @@ bool ShellUtils::GetUtf8Argv(int argc, char** argv) {
return false;
}
static mach_timebase_info_data_t timebase_info;
void TimerUtils::InitOnce() {
kern_return_t kr = mach_timebase_info(&timebase_info);
ASSERT(KERN_SUCCESS == kr);
}
void TimerUtils::InitOnce() {}
int64_t TimerUtils::GetCurrentMonotonicMillis() {
return GetCurrentMonotonicMicros() / 1000;
}
int64_t TimerUtils::GetCurrentMonotonicMicros() {
ASSERT(timebase_info.denom != 0);
// timebase_info converts absolute time tick units into nanoseconds. Convert
// to microseconds.
int64_t result = mach_absolute_time() / kNanosecondsPerMicrosecond;
result *= timebase_info.numer;
result /= timebase_info.denom;
return result;
return clock_gettime_nsec_np(CLOCK_MONOTONIC_RAW) /
kNanosecondsPerMicrosecond;
}
void TimerUtils::Sleep(int64_t millis) {

View file

@ -70,19 +70,8 @@ int64_t OS::GetCurrentTimeMicros() {
return (static_cast<int64_t>(tv.tv_sec) * 1000000) + tv.tv_usec;
}
static mach_timebase_info_data_t timebase_info;
int64_t OS::GetCurrentMonotonicTicks() {
if (timebase_info.denom == 0) {
kern_return_t kr = mach_timebase_info(&timebase_info);
ASSERT(KERN_SUCCESS == kr);
}
ASSERT(timebase_info.denom != 0);
// timebase_info converts absolute time tick units into nanoseconds.
int64_t result = mach_absolute_time();
result *= timebase_info.numer;
result /= timebase_info.denom;
return result;
return clock_gettime_nsec_np(CLOCK_MONOTONIC_RAW);
}
int64_t OS::GetCurrentMonotonicFrequency() {