14f7622ef4
Android is based on Linux, so most of the files were identical sans some subtle discrepancies caused by drift over time. This discrepancies were making code base harder to maintain and in fact were hiding bugs. For example, on Android eventhandler's implementation of timers which relied on passing timeout to `epoll_wait` contained a bug which was not present on Linux which used `timerfd` instead. TEST=ci and manual testing of Flutter app on Android device Fixes https://github.com/dart-lang/sdk/issues/54868 Cq-Include-Trybots: luci.dart.try:vm-aot-android-release-arm64c-try,vm-aot-android-release-arm_x64-try,vm-ffi-android-debug-arm-try,vm-ffi-android-debug-arm64c-try,vm-ffi-android-product-arm-try,vm-ffi-android-product-arm64c-try,vm-ffi-android-release-arm-try,vm-ffi-android-release-arm64c-try Bug: b/311165013 Change-Id: Ia166f69c14177ec34160805a0983eafee8ea65f6 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/350923 Reviewed-by: Martin Kustermann <kustermann@google.com> Commit-Queue: Slava Egorov <vegorov@google.com>
114 lines
3.1 KiB
C++
114 lines
3.1 KiB
C++
// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
|
|
// for details. All rights reserved. Use of this source code is governed by a
|
|
// BSD-style license that can be found in the LICENSE file.
|
|
|
|
#include "platform/globals.h"
|
|
#if defined(DART_HOST_OS_LINUX) || defined(DART_HOST_OS_ANDROID)
|
|
|
|
#include <errno.h> // NOLINT
|
|
#include <netdb.h> // NOLINT
|
|
#include <sys/time.h> // NOLINT
|
|
#include <time.h> // NOLINT
|
|
|
|
#include "bin/utils.h"
|
|
#include "platform/assert.h"
|
|
#include "platform/utils.h"
|
|
|
|
namespace dart {
|
|
namespace bin {
|
|
|
|
OSError::OSError() : sub_system_(kSystem), code_(0), message_(nullptr) {
|
|
Reload();
|
|
}
|
|
|
|
void OSError::Reload() {
|
|
SetCodeAndMessage(kSystem, errno);
|
|
}
|
|
|
|
void OSError::SetCodeAndMessage(SubSystem sub_system, int code) {
|
|
set_sub_system(sub_system);
|
|
set_code(code);
|
|
if (sub_system == kSystem) {
|
|
const int kBufferSize = 1024;
|
|
char error_buf[kBufferSize];
|
|
SetMessage(Utils::StrError(code, error_buf, kBufferSize));
|
|
} else if (sub_system == kGetAddressInfo) {
|
|
SetMessage(gai_strerror(code));
|
|
} else {
|
|
UNREACHABLE();
|
|
}
|
|
}
|
|
|
|
const char* StringUtils::ConsoleStringToUtf8(const char* str,
|
|
intptr_t len,
|
|
intptr_t* result_len) {
|
|
return nullptr;
|
|
}
|
|
|
|
const char* StringUtils::Utf8ToConsoleString(const char* utf8,
|
|
intptr_t len,
|
|
intptr_t* result_len) {
|
|
return nullptr;
|
|
}
|
|
|
|
char* StringUtils::ConsoleStringToUtf8(char* str,
|
|
intptr_t len,
|
|
intptr_t* result_len) {
|
|
return nullptr;
|
|
}
|
|
|
|
char* StringUtils::Utf8ToConsoleString(char* utf8,
|
|
intptr_t len,
|
|
intptr_t* result_len) {
|
|
return nullptr;
|
|
}
|
|
|
|
bool ShellUtils::GetUtf8Argv(int argc, char** argv) {
|
|
return false;
|
|
}
|
|
|
|
void TimerUtils::InitOnce() {}
|
|
|
|
int64_t TimerUtils::GetCurrentMonotonicMillis() {
|
|
return GetCurrentMonotonicMicros() / 1000;
|
|
}
|
|
|
|
int64_t TimerUtils::GetCurrentMonotonicMicros() {
|
|
struct timespec ts;
|
|
if (clock_gettime(CLOCK_MONOTONIC, &ts) != 0) {
|
|
UNREACHABLE();
|
|
return 0;
|
|
}
|
|
// Convert to microseconds.
|
|
int64_t result = ts.tv_sec;
|
|
result *= kMicrosecondsPerSecond;
|
|
result += (ts.tv_nsec / kNanosecondsPerMicrosecond);
|
|
return result;
|
|
}
|
|
|
|
void TimerUtils::Sleep(int64_t millis) {
|
|
struct timespec req; // requested.
|
|
struct timespec rem; // remainder.
|
|
int64_t micros = millis * kMicrosecondsPerMillisecond;
|
|
int64_t seconds = micros / kMicrosecondsPerSecond;
|
|
micros = micros - seconds * kMicrosecondsPerSecond;
|
|
int64_t nanos = micros * kNanosecondsPerMicrosecond;
|
|
req.tv_sec = seconds;
|
|
req.tv_nsec = nanos;
|
|
while (true) {
|
|
int r = nanosleep(&req, &rem);
|
|
if (r == 0) {
|
|
break;
|
|
}
|
|
// We should only ever see an interrupt error.
|
|
ASSERT(errno == EINTR);
|
|
// Copy remainder into requested and repeat.
|
|
req = rem;
|
|
}
|
|
}
|
|
|
|
} // namespace bin
|
|
} // namespace dart
|
|
|
|
#endif // defined(DART_HOST_OS_LINUX) || defined(DART_HOST_OS_ANDROID)
|