loader: add support for GNU/Hurd
authorPino Toscano <toscano.pino@tiscali.it>
Sun, 2 Jul 2023 16:30:58 +0000 (18:30 +0200)
committerCharles Giessen <46324611+charles-lunarg@users.noreply.github.com>
Mon, 3 Jul 2023 20:04:32 +0000 (14:04 -0600)
* add the Hurd to COMMON_UNIX_PLATFORMS, as it is a POSIX OS
* use the Linux paths for getting the executable path (i.e. using
  /proc/self/exe): the Linux procfs provides both "self" and
  "<pid>/exe"
* follow the Linux behaviour in tests w.r.t. the platform shim
  behaviour, the test dummy binaries, and few more other bits

loader/vk_loader_platform.h
tests/framework/framework_config.h.in
tests/framework/shim/shim.h
tests/framework/shim/unix_shim.cpp
tests/framework/test_environment.cpp
tests/framework/test_util.h
tests/loader_envvar_tests.cpp
tests/loader_regression_tests.cpp

index e7a1ad9b3a410765c10c2224497ccf08af3b67d7..1fbdf97cc3dc468c33f733d51e2d77ad23f53468 100644 (file)
@@ -40,7 +40,7 @@
 
 // Set of platforms with a common set of functionality which is queried throughout the program
 #if defined(__linux__) || defined(__APPLE__) || defined(__Fuchsia__) || defined(__QNXNTO__) || defined(__FreeBSD__) || \
-    defined(__OpenBSD__) || defined(__NetBSD__) || defined(__DragonFly__)
+    defined(__OpenBSD__) || defined(__NetBSD__) || defined(__DragonFly__) || defined(__GNU__)
 #define COMMON_UNIX_PLATFORMS 1
 #else
 #define COMMON_UNIX_PLATFORMS 0
@@ -260,7 +260,7 @@ static inline char *loader_platform_dirname(char *path) { return dirname(path);
 
 // loader_platform_executable_path finds application path + name.
 // Path cannot be longer than 1024, returns NULL if it is greater than that.
-#if defined(__linux__)
+#if defined(__linux__) || defined(__GNU__)
 static inline char *loader_platform_executable_path(char *buffer, size_t size) {
     ssize_t count = readlink("/proc/self/exe", buffer, size);
     if (count == -1) return NULL;
index 364d206238b6aff8c5783f58319560c05d2faa91..e07a2abef5201852cc216b71a5cd1b7a78de5f6c 100644 (file)
@@ -77,7 +77,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__) || defined(__OpenBSD__)
+#if defined(__linux__) || defined(__APPLE__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__GNU__)
 #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"
@@ -94,7 +94,7 @@
 #define CURRENT_PLATFORM_DUMMY_BINARY_BAD BAD_DUMMY_BINARY_WINDOWS_32
 #endif
 #endif
-#if defined(__linux__)
+#if defined(__linux__) || defined(__GNU__)
 #if __x86_64__ || __ppc64__
 #define CURRENT_PLATFORM_DUMMY_BINARY_WRONG_TYPE DUMMY_BINARY_LINUX_32
 #define CURRENT_PLATFORM_DUMMY_BINARY_BAD BAD_DUMMY_BINARY_LINUX_64
index d98997648252ce5f4acd51055518b0c44e0c44d2..4a1eed4e3b4edd8472d22e1c652ed462aa5f3b6b 100644 (file)
@@ -227,7 +227,7 @@ extern "C" {
 using PFN_get_platform_shim = PlatformShim* (*)(std::vector<fs::FolderManager>* folders);
 #define GET_PLATFORM_SHIM_STR "get_platform_shim"
 
-#elif defined(__linux__) || defined(__FreeBSD__) || defined(__OpenBSD__)
+#elif defined(__linux__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__GNU__)
 // statically link on linux
 PlatformShim* get_platform_shim(std::vector<fs::FolderManager>* folders);
 #endif
index d2fec892135028ec23df6f7c9a0257a6170dfee5..16bd73ad0006b52ec565e551a9686f21f4633b2c 100644 (file)
@@ -35,7 +35,7 @@
 
 PlatformShim platform_shim;
 extern "C" {
-#if defined(__linux__) || defined(__FreeBSD__) || defined(__OpenBSD__)
+#if defined(__linux__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__GNU__)
 PlatformShim* get_platform_shim(std::vector<fs::FolderManager>* folders) {
     platform_shim = PlatformShim(folders);
     return &platform_shim;
@@ -48,7 +48,7 @@ FRAMEWORK_EXPORT PlatformShim* get_platform_shim(std::vector<fs::FolderManager>*
 #endif
 
 // Necessary for MacOS function shimming
-#if defined(__linux__) || defined(__FreeBSD__) || defined(__OpenBSD__)
+#if defined(__linux__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__GNU__)
 #define OPENDIR_FUNC_NAME opendir
 #define READDIR_FUNC_NAME readdir
 #define CLOSEDIR_FUNC_NAME closedir
index bfd0f536d2d5e61afba708567b8be20e672ab992..ee1451165344cf2a5740760ef0dd8d36b6764a0a 100644 (file)
@@ -334,7 +334,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__) || defined(__OpenBSD__)
+#elif defined(__linux__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__GNU__)
     platform_shim = get_platform_shim(folders);
 #endif
     platform_shim->reset();
index 913eee08cd1921b7fd8bb8dcab61996640bc5f7a..2cebfc68092bbe1d858c14c0cafccac06a21b24d 100644 (file)
@@ -63,7 +63,7 @@
 
 // Set of platforms with a common set of functionality which is queried throughout the program
 #if defined(__linux__) || defined(__APPLE__) || defined(__Fuchsia__) || defined(__QNXNTO__) || defined(__FreeBSD__) || \
-    defined(__OpenBSD__) || defined(__NetBSD__) || defined(__DragonFly__)
+    defined(__OpenBSD__) || defined(__NetBSD__) || defined(__DragonFly__) || defined(__GNU__)
 #define COMMON_UNIX_PLATFORMS 1
 #else
 #define COMMON_UNIX_PLATFORMS 0
@@ -784,7 +784,7 @@ inline bool contains(std::vector<VkLayerProperties> const& vec, const char* name
                        [name](VkLayerProperties const& elem) { return string_eq(name, elem.layerName); });
 }
 
-#if defined(__linux__)
+#if defined(__linux__) || defined(__GNU__)
 
 // find application path + name. Path cannot be longer than 1024, returns NULL if it is greater than that.
 inline std::string test_platform_executable_path() {
index e1ce7275fee3c3c9a3206329a46a0ef666accd4b..729ba46b5fafc96661ec1ffb6a65237bcebce206 100644 (file)
@@ -134,7 +134,7 @@ TEST(EnvVarICDOverrideSetup, TestOnlyDriverEnvVar) {
     env.platform_shim->set_elevated_privilege(false);
 }
 
-#if defined(__linux__) || defined(__FreeBSD__) || defined(__OpenBSD__)
+#if defined(__linux__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__GNU__)
 // Make sure the loader reports the correct message based on if LOADER_USE_UNSAFE_FILE_SEARCH is set or not
 TEST(EnvVarICDOverrideSetup, NonSecureEnvVarLookup) {
     FrameworkEnvironment env{};
@@ -244,7 +244,7 @@ TEST(EnvVarICDOverrideSetup, TestBothDriverEnvVars) {
     ASSERT_EQ(phys_dev_count, 3U);
 }
 
-#if defined(__linux__) || defined(__FreeBSD__) || defined(__OpenBSD__)
+#if defined(__linux__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__GNU__)
 // Test VK_LAYER_PATH environment variable
 TEST(EnvVarICDOverrideSetup, TestOnlyLayerEnvVar) {
     FrameworkEnvironment env{};
index 1ac79391d5f1c2fdfc043a79d6dda5b047d1bb1b..39fa0d4a7333d067a69eb4058ae948d3592e97b0 100644 (file)
@@ -1301,7 +1301,7 @@ TEST(TryLoadWrongBinaries, WrongICD) {
 #if _WIN32 || _WIN64
     ASSERT_TRUE(log.find("Failed to open dynamic library"));
 #endif
-#if defined(__linux__) || defined(__FreeBSD__) || defined(__OpenBSD__)
+#if defined(__linux__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__GNU__)
 #if defined(__x86_64__)
     ASSERT_TRUE(log.find("wrong ELF class: ELFCLASS32"));
 #else
@@ -2699,7 +2699,7 @@ TEST(CreateInstance, InstanceNullExtensionPtr) {
     ASSERT_EQ(env.vulkan_functions.vkCreateInstance(&info, VK_NULL_HANDLE, &inst), VK_ERROR_EXTENSION_NOT_PRESENT);
 }
 
-#if defined(__linux__) || defined(__FreeBSD__) || defined(__OpenBSD__)
+#if defined(__linux__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__GNU__)
 // NOTE: Sort order only affects Linux
 TEST(SortedPhysicalDevices, DevicesSortEnabled10NoAppExt) {
     FrameworkEnvironment env{};
@@ -3529,7 +3529,7 @@ TEST(SortedPhysicalDevices, DeviceGroupsSortedDisabled) {
     }
 }
 
-#endif  // __linux__ || __FreeBSD__ || __OpenBSD__
+#endif  // __linux__ || __FreeBSD__ || __OpenBSD__ || __GNU__
 
 const char* portability_driver_warning =
     "vkCreateInstance: Found drivers that contain devices which support the portability subset, but the "