You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-05 12:10:55 +00:00
openxr: Sync with upstream 1.0.28
This commit is contained in:
43
thirdparty/openxr/src/common/platform_utils.hpp
vendored
43
thirdparty/openxr/src/common/platform_utils.hpp
vendored
@@ -1,4 +1,4 @@
|
||||
// Copyright (c) 2017-2022, The Khronos Group Inc.
|
||||
// Copyright (c) 2017-2023, The Khronos Group Inc.
|
||||
// Copyright (c) 2017-2019 Valve Corporation
|
||||
// Copyright (c) 2017-2019 LunarG, Inc.
|
||||
//
|
||||
@@ -37,6 +37,10 @@
|
||||
#include "common_config.h"
|
||||
#endif // OPENXR_HAVE_COMMON_CONFIG
|
||||
|
||||
// Consumers of this file must ensure this function is implemented. For example, the loader will implement this function so that it
|
||||
// can route messages through the loader's logging system.
|
||||
void LogPlatformUtilsError(const std::string& message);
|
||||
|
||||
// Environment variables
|
||||
#if defined(XR_OS_LINUX) || defined(XR_OS_APPLE)
|
||||
|
||||
@@ -56,9 +60,11 @@ static inline char* ImplGetSecureEnv(const char* name) {
|
||||
#elif defined(HAVE___SECURE_GETENV)
|
||||
return __secure_getenv(name);
|
||||
#else
|
||||
// clang-format off
|
||||
#pragma message( \
|
||||
"Warning: Falling back to non-secure getenv for environmental" \
|
||||
"lookups! Consider updating to a different libc.")
|
||||
// clang-format on
|
||||
|
||||
return ImplGetEnv(name);
|
||||
#endif
|
||||
@@ -79,6 +85,12 @@ static inline std::string PlatformUtilsGetEnv(const char* name) {
|
||||
static inline std::string PlatformUtilsGetSecureEnv(const char* name) {
|
||||
auto str = detail::ImplGetSecureEnv(name);
|
||||
if (str == nullptr) {
|
||||
str = detail::ImplGetEnv(name);
|
||||
if (str != nullptr && !std::string(str).empty()) {
|
||||
LogPlatformUtilsError(std::string("!!! WARNING !!! Environment variable ") + name +
|
||||
" is being ignored due to running with secure execution. The value '" + str +
|
||||
"' will NOT be used.");
|
||||
}
|
||||
return {};
|
||||
}
|
||||
return str;
|
||||
@@ -131,12 +143,6 @@ static inline bool PlatformGetGlobalRuntimeFileName(uint16_t major_version, std:
|
||||
|
||||
#elif defined(XR_OS_WINDOWS)
|
||||
|
||||
#if !defined(NDEBUG)
|
||||
inline void LogError(const std::string& error) { OutputDebugStringA(error.c_str()); }
|
||||
#else
|
||||
#define LogError(x)
|
||||
#endif
|
||||
|
||||
inline std::wstring utf8_to_wide(const std::string& utf8Text) {
|
||||
if (utf8Text.empty()) {
|
||||
return {};
|
||||
@@ -145,7 +151,7 @@ inline std::wstring utf8_to_wide(const std::string& utf8Text) {
|
||||
std::wstring wideText;
|
||||
const int wideLength = ::MultiByteToWideChar(CP_UTF8, 0, utf8Text.data(), (int)utf8Text.size(), nullptr, 0);
|
||||
if (wideLength == 0) {
|
||||
LogError("utf8_to_wide get size error: " + std::to_string(::GetLastError()));
|
||||
LogPlatformUtilsError("utf8_to_wide get size error: " + std::to_string(::GetLastError()));
|
||||
return {};
|
||||
}
|
||||
|
||||
@@ -154,7 +160,7 @@ inline std::wstring utf8_to_wide(const std::string& utf8Text) {
|
||||
wchar_t* wideString = const_cast<wchar_t*>(wideText.data()); // mutable data() only exists in c++17
|
||||
const int length = ::MultiByteToWideChar(CP_UTF8, 0, utf8Text.data(), (int)utf8Text.size(), wideString, wideLength);
|
||||
if (length != wideLength) {
|
||||
LogError("utf8_to_wide convert string error: " + std::to_string(::GetLastError()));
|
||||
LogPlatformUtilsError("utf8_to_wide convert string error: " + std::to_string(::GetLastError()));
|
||||
return {};
|
||||
}
|
||||
|
||||
@@ -169,7 +175,7 @@ inline std::string wide_to_utf8(const std::wstring& wideText) {
|
||||
std::string narrowText;
|
||||
int narrowLength = ::WideCharToMultiByte(CP_UTF8, 0, wideText.data(), (int)wideText.size(), nullptr, 0, nullptr, nullptr);
|
||||
if (narrowLength == 0) {
|
||||
LogError("wide_to_utf8 get size error: " + std::to_string(::GetLastError()));
|
||||
LogPlatformUtilsError("wide_to_utf8 get size error: " + std::to_string(::GetLastError()));
|
||||
return {};
|
||||
}
|
||||
|
||||
@@ -179,7 +185,7 @@ inline std::string wide_to_utf8(const std::wstring& wideText) {
|
||||
const int length =
|
||||
::WideCharToMultiByte(CP_UTF8, 0, wideText.data(), (int)wideText.size(), narrowString, narrowLength, nullptr, nullptr);
|
||||
if (length != narrowLength) {
|
||||
LogError("wide_to_utf8 convert string error: " + std::to_string(::GetLastError()));
|
||||
LogPlatformUtilsError("wide_to_utf8 convert string error: " + std::to_string(::GetLastError()));
|
||||
return {};
|
||||
}
|
||||
|
||||
@@ -245,7 +251,7 @@ static inline std::string PlatformUtilsGetEnv(const char* name) {
|
||||
// call if there was enough capacity. Else it returns the required capacity (including null terminator).
|
||||
const DWORD length = ::GetEnvironmentVariableW(wname.c_str(), wValueData, (DWORD)wValue.size());
|
||||
if ((length == 0) || (length >= wValue.size())) { // If error or the variable increased length between calls...
|
||||
LogError("GetEnvironmentVariable get value error: " + std::to_string(::GetLastError()));
|
||||
LogPlatformUtilsError("GetEnvironmentVariable get value error: " + std::to_string(::GetLastError()));
|
||||
return {};
|
||||
}
|
||||
|
||||
@@ -256,13 +262,20 @@ static inline std::string PlatformUtilsGetEnv(const char* name) {
|
||||
|
||||
// Acts the same as PlatformUtilsGetEnv except returns an empty string if IsHighIntegrityLevel.
|
||||
static inline std::string PlatformUtilsGetSecureEnv(const char* name) {
|
||||
// No secure version for Windows so the below integrity check is needed.
|
||||
const std::string envValue = PlatformUtilsGetEnv(name);
|
||||
|
||||
// Do not allow high integrity processes to act on data that can be controlled by medium integrity processes.
|
||||
if (IsHighIntegrityLevel()) {
|
||||
if (!envValue.empty()) {
|
||||
LogPlatformUtilsError(std::string("!!! WARNING !!! Environment variable ") + name +
|
||||
" is being ignored due to running from an elevated context. The value '" + envValue +
|
||||
"' will NOT be used.");
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
// No secure version for Windows so the above integrity check is needed.
|
||||
return PlatformUtilsGetEnv(name);
|
||||
return envValue;
|
||||
}
|
||||
|
||||
// Sets an environment variable via UTF8 strings.
|
||||
@@ -303,7 +316,7 @@ static inline bool PlatformUtilsSetEnv(const char* /* name */, const char* /* va
|
||||
// Intended to be only used as a fallback on Android, with a more open, "native" technique used in most cases
|
||||
static inline bool PlatformGetGlobalRuntimeFileName(uint16_t major_version, std::string& file_name) {
|
||||
// Prefix for the runtime JSON file name
|
||||
static const char* rt_dir_prefixes[] = {"/oem", "/vendor", "/system"};
|
||||
static const char* rt_dir_prefixes[] = {"/product", "/odm", "/oem", "/vendor", "/system"};
|
||||
static const std::string rt_filename = "/active_runtime.json";
|
||||
static const std::string subdir = "/etc/openxr/";
|
||||
for (const auto prefix : rt_dir_prefixes) {
|
||||
|
||||
Reference in New Issue
Block a user