loader: Add OpenBSD support

This commit is contained in:
Brad Smith 2022-08-30 20:14:18 -04:00 committed by Charles Giessen
parent 40faec799c
commit c745281f0f
14 changed files with 28 additions and 28 deletions

View File

@ -32,7 +32,7 @@
#include "log.h"
// Environment variables
#if defined(__linux__) || defined(__APPLE__) || defined(__Fuchsia__) || defined(__QNXNTO__) || defined(__FreeBSD__)
#if defined(__linux__) || defined(__APPLE__) || defined(__Fuchsia__) || defined(__QNXNTO__) || defined(__FreeBSD__) || defined(__OpenBSD__)
bool is_high_integrity() { return geteuid() != getuid() || getegid() != getgid(); }
@ -44,7 +44,7 @@ char *loader_getenv(const char *name, const struct loader_instance *inst) {
}
char *loader_secure_getenv(const char *name, const struct loader_instance *inst) {
#if defined(__APPLE__) || defined(__FreeBSD__)
#if defined(__APPLE__) || defined(__FreeBSD__) || defined(__OpenBSD__)
// Apple does not appear to have a secure getenv implementation.
// The main difference between secure getenv and getenv is that secure getenv
// returns NULL if the process is being run with elevated privileges by a normal user.

View File

@ -35,10 +35,10 @@
char *loader_getenv(const char *name, const struct loader_instance *inst);
void loader_free_getenv(char *val, const struct loader_instance *inst);
#if defined(WIN32) || defined(__linux__) || defined(__APPLE__) || defined(__Fuchsia__) || defined(__QNXNTO__) || defined(__FreeBSD__)
#if defined(WIN32) || defined(__linux__) || defined(__APPLE__) || defined(__Fuchsia__) || defined(__QNXNTO__) || defined(__FreeBSD__) || defined(__OpenBSD__)
bool is_high_integrity();
char *loader_secure_getenv(const char *name, const struct loader_instance *inst);
#endif
#endif

View File

@ -34,7 +34,7 @@
#include <alloca.h>
#endif
#if defined(__linux__) || defined(__APPLE__) || defined(__Fuchsia__) || defined(__QNXNTO__) || defined(__FreeBSD__)
#if defined(__linux__) || defined(__APPLE__) || defined(__Fuchsia__) || defined(__QNXNTO__) || defined(__FreeBSD__) || defined(__OpenBSD__)
#define loader_stack_alloc(size) alloca(size)
#elif defined(_WIN32)
#define loader_stack_alloc(size) _alloca(size)

View File

@ -24,7 +24,7 @@
*/
#pragma once
#if defined(__FreeBSD__)
#if defined(__FreeBSD__) || defined(__OpenBSD__)
#include <sys/types.h>
#include <sys/select.h>
#endif
@ -43,7 +43,7 @@
#include "dlopen_fuchsia.h"
#endif // defined(__Fuchsia__)
#if defined(__linux__) || defined(__APPLE__) || defined(__Fuchsia__) || defined(__QNXNTO__) || defined(__FreeBSD__)
#if defined(__linux__) || defined(__APPLE__) || defined(__Fuchsia__) || defined(__QNXNTO__) || defined(__FreeBSD__) || defined(__OpenBSD__)
#include <unistd.h>
// Note: The following file is for dynamic loading:
#include <dlfcn.h>
@ -98,7 +98,7 @@
#define LAYERS_PATH_ENV "VK_LAYER_PATH"
#define ENABLED_LAYERS_ENV "VK_INSTANCE_LAYERS"
#if defined(__linux__) || defined(__APPLE__) || defined(__Fuchsia__) || defined(__QNXNTO__) || defined(__FreeBSD__)
#if defined(__linux__) || defined(__APPLE__) || defined(__Fuchsia__) || defined(__QNXNTO__) || defined(__FreeBSD__) || defined(__OpenBSD__)
/* Linux-specific common code: */
// VK Library Filenames, Paths, etc.:
@ -219,7 +219,7 @@ static inline void loader_platform_thread_once_fn(pthread_once_t *ctl, void (*fu
#endif
#if defined(__linux__) || defined(__APPLE__) || defined(__Fuchsia__) || defined(__QNXNTO__) || defined(__FreeBSD__)
#if defined(__linux__) || defined(__APPLE__) || defined(__Fuchsia__) || defined(__QNXNTO__) || defined(__FreeBSD__) || defined(__OpenBSD__)
// File IO
static inline bool loader_platform_file_exists(const char *path) {

View File

@ -72,7 +72,7 @@
#define BAD_DUMMY_BINARY_WINDOWS_64 "${CMAKE_CURRENT_SOURCE_DIR}/data/binaries/libdummy_library_elf_64.dll"
#define BAD_DUMMY_BINARY_WINDOWS_32 "${CMAKE_CURRENT_SOURCE_DIR}/data/binaries/libdummy_library_elf_32.dll"
#endif
#if defined(__linux__) || defined(__APPLE__) || defined(__FreeBSD__)
#if defined(__linux__) || defined(__APPLE__) || defined(__FreeBSD__) || defined(__OpenBSD__)
#define DUMMY_BINARY_LINUX_64 "${CMAKE_CURRENT_SOURCE_DIR}/data/binaries/libdummy_library_elf_64.so"
#define DUMMY_BINARY_LINUX_32 "${CMAKE_CURRENT_SOURCE_DIR}/data/binaries/libdummy_library_elf_32.so"
#define BAD_DUMMY_BINARY_LINUX_64 "${CMAKE_CURRENT_SOURCE_DIR}/data/binaries/dummy_library_pe_64.so"

View File

@ -110,7 +110,7 @@ struct D3DKMT_Adapter {
D3DKMT_Adapter& add_path(fs::path src, std::vector<std::wstring>& dest);
};
#elif defined(__linux__) || defined(__APPLE__) || defined(__FreeBSD__)
#elif defined(__linux__) || defined(__APPLE__) || defined(__FreeBSD__) || defined(__OpenBSD__)
struct DirEntry {
DIR* directory;
@ -181,7 +181,7 @@ struct PlatformShim {
size_t created_key_count = 0;
std::vector<HKeyHandle> created_keys;
#elif defined(__linux__) || defined(__APPLE__) || defined(__FreeBSD__)
#elif defined(__linux__) || defined(__APPLE__) || defined(__FreeBSD__) || defined(__OpenBSD__)
bool is_fake_path(fs::path const& path);
fs::path const& get_fake_path(fs::path const& path);

View File

@ -42,7 +42,7 @@ std::vector<std::string> parse_env_var_list(std::string const& var) {
for (size_t i = 0; i < var.size(); i++) {
#if defined(WIN32)
if (var[i] == ';') {
#elif defined(__linux__) || defined(__APPLE__) || defined(__FreeBSD__)
#elif defined(__linux__) || defined(__APPLE__) || defined(__FreeBSD__) || defined(__OpenBSD__)
if (var[i] == ':') {
#endif
if (len != 0) {
@ -145,7 +145,7 @@ void PlatformShim::add_CM_Device_ID(std::wstring const& id, fs::path const& icd_
void PlatformShim::redirect_category(fs::path const& new_path, ManifestCategory search_category) {}
#elif defined(__linux__) || defined(__APPLE__) || defined(__FreeBSD__)
#elif defined(__linux__) || defined(__APPLE__) || defined(__FreeBSD__) || defined(__OpenBSD__)
#include <dirent.h>
#include <unistd.h>

View File

@ -29,7 +29,7 @@
static PlatformShim platform_shim;
extern "C" {
#if defined(__linux__) || defined(__FreeBSD__)
#if defined(__linux__) || defined(__FreeBSD__) || defined(__OpenBSD__)
PlatformShim* get_platform_shim(std::vector<fs::FolderManager>* folders) {
platform_shim = PlatformShim(folders);
return &platform_shim;
@ -42,7 +42,7 @@ FRAMEWORK_EXPORT PlatformShim* get_platform_shim(std::vector<fs::FolderManager>*
#endif
// Necessary for MacOS function shimming
#if defined(__linux__) || defined(__FreeBSD__)
#if defined(__linux__) || defined(__FreeBSD__) || defined(__OpenBSD__)
#define OPENDIR_FUNC_NAME opendir
#define READDIR_FUNC_NAME readdir
#define CLOSEDIR_FUNC_NAME closedir

View File

@ -142,7 +142,7 @@ PlatformShimWrapper::PlatformShimWrapper(std::vector<fs::FolderManager>* folders
PFN_get_platform_shim get_platform_shim_func = shim_library.get_symbol(GET_PLATFORM_SHIM_STR);
assert(get_platform_shim_func != NULL && "Must be able to get \"platform_shim\"");
platform_shim = get_platform_shim_func(folders);
#elif defined(__linux__) || defined(__FreeBSD__)
#elif defined(__linux__) || defined(__FreeBSD__) || defined(__OpenBSD__)
platform_shim = get_platform_shim(folders);
#endif
platform_shim->reset();

View File

@ -77,7 +77,7 @@ std::string get_env_var(std::string const& name, bool report_failure) {
}
return narrow(value);
}
#elif defined(__linux__) || defined(__APPLE__) || defined(__FreeBSD__)
#elif defined(__linux__) || defined(__APPLE__) || defined(__FreeBSD__) || defined(__OpenBSD__)
void set_env_var(std::string const& name, std::string const& value) { setenv(name.c_str(), value.c_str(), 1); }
void remove_env_var(std::string const& name) { unsetenv(name.c_str()); }
@ -224,7 +224,7 @@ std::string make_native(std::string const& in_path) {
else
out += c;
}
#elif defined(__linux__) || defined(__APPLE__) || defined(__FreeBSD__)
#elif defined(__linux__) || defined(__APPLE__) || defined(__FreeBSD__) || defined(__OpenBSD__)
for (size_t i = 0; i < in_path.size(); i++) {
if (i + 1 < in_path.size() && in_path[i] == '\\' && in_path[i + 1] == '\\') {
out += '/';

View File

@ -66,7 +66,7 @@
#include <direct.h>
#include <windows.h>
#include <strsafe.h>
#elif defined(__linux__) || defined(__APPLE__) || defined(__FreeBSD__)
#elif defined(__linux__) || defined(__APPLE__) || defined(__FreeBSD__) || defined(__OpenBSD__)
#include <dirent.h>
#include <sys/types.h>
#include <sys/stat.h>
@ -109,7 +109,7 @@ void set_env_var(std::string const& name, std::string const& value);
void remove_env_var(std::string const& name);
std::string get_env_var(std::string const& name, bool report_failure = true);
#elif defined(__linux__) || defined(__APPLE__) || defined(__FreeBSD__)
#elif defined(__linux__) || defined(__APPLE__) || defined(__FreeBSD__) || defined(__OpenBSD__)
void set_env_var(std::string const& name, std::string const& value);
void remove_env_var(std::string const& name);
std::string get_env_var(std::string const& name, bool report_failure = true);
@ -141,7 +141,7 @@ struct path {
private:
#if defined(WIN32)
static const char path_separator = '\\';
#elif defined(__linux__) || defined(__APPLE__) || defined(__FreeBSD__)
#elif defined(__linux__) || defined(__APPLE__) || defined(__FreeBSD__) || defined(__OpenBSD__)
static const char path_separator = '/';
#endif
@ -282,7 +282,7 @@ inline char* loader_platform_get_proc_address_error(const char* name) {
return errorMsg;
}
#elif defined(__linux__) || defined(__APPLE__) || defined(__FreeBSD__)
#elif defined(__linux__) || defined(__APPLE__) || defined(__FreeBSD__) || defined(__OpenBSD__)
typedef void* loader_platform_dl_handle;
inline loader_platform_dl_handle loader_platform_open_library(const char* libPath) {

View File

@ -151,7 +151,7 @@ TEST(EnvVarICDOverrideSetup, TestOnlyDriverEnvVar) {
remove_env_var("VK_DRIVER_FILES");
}
#if defined(__linux__) || defined(__FreeBSD__)
#if defined(__linux__) || defined(__FreeBSD__) || defined(__OpenBSD__)
// Make sure the loader reports the correct message based on if USE_UNSAFE_FILE_SEARCH is set or not
TEST(EnvVarICDOverrideSetup, NonSecureEnvVarLookup) {
FrameworkEnvironment env{};
@ -255,7 +255,7 @@ TEST(EnvVarICDOverrideSetup, TestBothDriverEnvVars) {
remove_env_var("VK_ADD_DRIVER_FILES");
}
#if defined(__linux__) || defined(__FreeBSD__)
#if defined(__linux__) || defined(__FreeBSD__) || defined(__OpenBSD__)
// Test VK_LAYER_PATH environment variable
TEST(EnvVarICDOverrideSetup, TestOnlyLayerEnvVar) {
FrameworkEnvironment env{};

View File

@ -1027,7 +1027,7 @@ TEST(TryLoadWrongBinaries, WrongICD) {
#if _WIN32 || _WIN64
ASSERT_TRUE(log.find("Failed to open dynamic library"));
#endif
#if defined(__linux__) || defined(__FreeBSD__)
#if defined(__linux__) || defined(__FreeBSD__) || defined(__OpenBSD__)
#if defined(__x86_64__)
ASSERT_TRUE(log.find("wrong ELF class: ELFCLASS32"));
#else

View File

@ -58,13 +58,13 @@ int main(int argc, char** argv) {
remove_env_var("VK_LOADER_DEBUG");
remove_env_var("VK_LOADER_DISABLE_INST_EXT_FILTER");
#if defined(__linux__) || defined(__FreeBSD__)
#if defined(__linux__) || defined(__FreeBSD__) || defined(__OpenBSD__)
set_env_var("XDG_CONFIG_HOME", "/etc");
set_env_var("XDG_CONFIG_DIRS", "/etc");
set_env_var("XDG_DATA_HOME", "/etc");
set_env_var("XDG_DATA_DIRS", "/etc");
#endif
#if defined(__linux__) || defined(__APPLE__) || defined(__FreeBSD__)
#if defined(__linux__) || defined(__APPLE__) || defined(__FreeBSD__) || defined(__OpenBSD__)
set_env_var("HOME", "/home/fake_home");
#endif