dart-sdk/runtime/platform/utils_macos.h
Vyacheslav Egorov 56ad16f4de [vm] Make VM strict about min required Mac OS X version.
Refuse to initialize VM if current Mac OS X version is below
MAC_OS_X_VERSION_MIN_REQUIRED, which was configured in build
time through mac_sdk_min GN argument.

TEST=tested manually by changing return value of MacOSXVersion

Cq-Include-Trybots: luci.dart.try:dart-sdk-mac-arm64-try
Bug: https://github.com/flutter/flutter/issues/121739
Change-Id: I9d913516077dbb196e8d6ebd7fe9f3914de7c748
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/286932
Reviewed-by: Michael Thomsen <mit@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Commit-Queue: Slava Egorov <vegorov@google.com>
2023-03-08 09:08:39 +00:00

75 lines
2.2 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.
#ifndef RUNTIME_PLATFORM_UTILS_MACOS_H_
#define RUNTIME_PLATFORM_UTILS_MACOS_H_
#if !defined(RUNTIME_PLATFORM_UTILS_H_)
#error Do not include utils_macos.h directly; use utils.h instead.
#endif
#include <AvailabilityMacros.h>
#include <libkern/OSByteOrder.h> // NOLINT
namespace dart {
namespace internal {
// Returns the running system's Mac OS X version which matches the encoding
// of MAC_OS_X_VERSION_* defines in AvailabilityMacros.h
int32_t MacOSXVersion();
} // namespace internal
// Run-time OS version checks.
#define DEFINE_IS_OS_FUNCS(VERSION) \
inline bool IsAtLeastOS##VERSION() { \
return (MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_##VERSION) || \
(internal::MacOSXVersion() >= MAC_OS_X_VERSION_##VERSION); \
}
DEFINE_IS_OS_FUNCS(10_14)
// Returns |nullptr| if the current Mac OS X version satisfies minimum required
// Mac OS X version set during compilation (MAC_OS_X_VERSION_MIN_REQUIRED).
//
// Otherwise returns a malloc allocated error string with human readable
// current and expected versions.
char* CheckIsAtLeastMinRequiredMacOSVersion();
inline uint16_t Utils::HostToBigEndian16(uint16_t value) {
return OSSwapHostToBigInt16(value);
}
inline uint32_t Utils::HostToBigEndian32(uint32_t value) {
return OSSwapHostToBigInt32(value);
}
inline uint64_t Utils::HostToBigEndian64(uint64_t value) {
return OSSwapHostToBigInt64(value);
}
inline uint16_t Utils::HostToLittleEndian16(uint16_t value) {
return OSSwapHostToLittleInt16(value);
}
inline uint32_t Utils::HostToLittleEndian32(uint32_t value) {
return OSSwapHostToLittleInt32(value);
}
inline uint64_t Utils::HostToLittleEndian64(uint64_t value) {
return OSSwapHostToLittleInt64(value);
}
inline char* Utils::StrError(int err, char* buffer, size_t bufsize) {
if (strerror_r(err, buffer, bufsize) != 0) {
snprintf(buffer, bufsize, "%s", "strerror_r failed");
}
return buffer;
}
} // namespace dart
#endif // RUNTIME_PLATFORM_UTILS_MACOS_H_