#include "vk_layer_config.h"
#include <cstring>
#include <fstream>
#include <iostream>
#include <string>
#include <charconv>
#include <sys/stat.h>
#include <vulkan/vk_layer.h>
#include "utils/vk_layer_utils.h"
#if defined(_WIN32)
#include <windows.h>
#include <direct.h>
#define GetCurrentDir …
#elif defined(VK_USE_PLATFORM_ANDROID_KHR)
#include <sys/system_properties.h>
#include <unistd.h>
#include "utils/android_ndk_types.h"
#define GetCurrentDir …
#else
#include <unistd.h>
#define GetCurrentDir …
#endif
string;
class ConfigFile { … };
ConfigFile &GetLayerConfig() { … }
#if defined(__ANDROID__)
static void PropCallback(void *cookie, [[maybe_unused]] const char *name, const char *value, [[maybe_unused]] uint32_t serial) {
std::string *property = static_cast<std::string *>(cookie);
*property = value;
}
#endif
std::string GetEnvironment(const char *variable) { … }
void SetEnvironment(const char *variable, const char *value) { … }
const char *getLayerOption(const char *option) { … }
const SettingsFileInfo *GetLayerSettingsFileInfo() { … }
FILE *getLayerLogOutput(const char *option, const char *layer_name) { … }
VkFlags GetLayerOptionFlags(const string &option, vvl::unordered_map<string, VkFlags> const &enum_data, uint32_t option_default) { … }
ConfigFile::ConfigFile() : … { … }
const char *ConfigFile::GetOption(const string &option) { … }
void ConfigFile::SetOption(const string &option, const string &val) { … }
#if defined(WIN32)
static inline bool IsHighIntegrity() {
HANDLE process_token;
if (OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY | TOKEN_QUERY_SOURCE, &process_token)) {
uint8_t mandatory_label_buffer[SECURITY_MAX_SID_SIZE + sizeof(DWORD)];
DWORD buffer_size;
if (GetTokenInformation(process_token, TokenIntegrityLevel, mandatory_label_buffer, sizeof(mandatory_label_buffer),
&buffer_size) != 0) {
const TOKEN_MANDATORY_LABEL *mandatory_label = (const TOKEN_MANDATORY_LABEL *)mandatory_label_buffer;
const DWORD sub_authority_count = *GetSidSubAuthorityCount(mandatory_label->Label.Sid);
const DWORD integrity_level = *GetSidSubAuthority(mandatory_label->Label.Sid, sub_authority_count - 1);
CloseHandle(process_token);
return integrity_level > SECURITY_MANDATORY_MEDIUM_RID;
}
CloseHandle(process_token);
}
return false;
}
#endif
string ConfigFile::FindSettings() { … }
static inline std::string string_trim(const std::string &s) { … }
void ConfigFile::ParseFile(const char *filename) { … }
void PrintMessageFlags(VkFlags vk_flags, char *msg_flags) { … }
void PrintMessageSeverity(VkFlags vk_flags, char *msg_flags) { … }
void PrintMessageType(VkFlags vk_flags, char *msg_flags) { … }
#if __APPLE__
#ifndef VK_USE_PLATFORM_METAL_EXT
#error "VK_USE_PLATFORM_METAL_EXT not defined!"
#endif
#include <TargetConditionals.h>
#if TARGET_OS_IOS
#ifndef VK_USE_PLATFORM_IOS_MVK
#error "VK_USE_PLATFORM_IOS_MVK not defined!"
#endif
#endif
#if TARGET_OS_OSX
#ifndef VK_USE_PLATFORM_MACOS_MVK
#error "VK_USE_PLATFORM_MACOS_MVK not defined!"
#endif
#endif
#endif
#ifdef VK_USE_PLATFORM_ANDROID_KHR
#if __NDK_MAJOR__ < 25
#error "Validation Layers require at least NDK r25 or greater to build"
#endif
void __attribute__((constructor)) CheckAndroidVersion() {
const std::string version = GetEnvironment("ro.build.version.sdk");
if (version.empty()) {
return;
}
constexpr uint32_t target_android_api = 26;
constexpr uint32_t android_api = __ANDROID_API__;
static_assert(android_api >= target_android_api, "Vulkan-ValidationLayers is not supported on Android 25 and below");
uint32_t queried_version{};
if (std::from_chars(version.data(), version.data() + version.size(), queried_version).ec != std::errc()) {
return;
}
if (queried_version < target_android_api) {
LOGCONSOLE("ERROR - Android version is %d and needs to be 26 or above.", queried_version);
}
}
#endif