diff options
| author | Rémi Verschelde <rverschelde@gmail.com> | 2020-10-26 15:15:19 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-10-26 15:15:19 +0100 |
| commit | 825ab3b784db07534d2b89f658129b30e3d6807c (patch) | |
| tree | b237872f80f24b0b9de4904901c8d17dd0ff688a /thirdparty/vulkan/loader/vk_loader_platform.h | |
| parent | a3396fabd5700f08d9390f14eab0676d42ee6f14 (diff) | |
| parent | 148ad49c939f2413532ebecf92b60ce8dbc8cb8b (diff) | |
Merge pull request #42817 from akien-mga/vulkan-sdk-1.2.154.0
vulkan: Sync loader, headers and glslang to sdk-1.2.154.0
Diffstat (limited to 'thirdparty/vulkan/loader/vk_loader_platform.h')
| -rw-r--r-- | thirdparty/vulkan/loader/vk_loader_platform.h | 64 |
1 files changed, 43 insertions, 21 deletions
diff --git a/thirdparty/vulkan/loader/vk_loader_platform.h b/thirdparty/vulkan/loader/vk_loader_platform.h index 62e8e3ae09..e227bf07b2 100644 --- a/thirdparty/vulkan/loader/vk_loader_platform.h +++ b/thirdparty/vulkan/loader/vk_loader_platform.h @@ -38,7 +38,6 @@ //#ifndef _GNU_SOURCE //#define _GNU_SOURCE 1 //#endif -// TBD: Are the contents of the following file used? #include <unistd.h> // Note: The following file is for dynamic loading: #include <dlfcn.h> @@ -100,13 +99,43 @@ static inline bool loader_platform_is_path_absolute(const char *path) { static inline char *loader_platform_dirname(char *path) { return dirname(path); } +#if defined(__linux__) + +// find application path + name. Path cannot be longer than 1024, returns NULL if it is greater than that. +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; + if (count == 0) return NULL; + buffer[count] = '\0'; + return buffer; +} +#elif defined(__APPLE__) // defined(__linux__) +#include <libproc.h> +static inline char *loader_platform_executable_path(char *buffer, size_t size) { + pid_t pid = getpid(); + int ret = proc_pidpath(pid, buffer, size); + if (ret <= 0) return NULL; + buffer[ret] = '\0'; + return buffer; +} +#endif // defined (__APPLE__) + +// Compatability with compilers that don't support __has_feature +#ifndef __has_feature +#define __has_feature(x) 0 +#endif + +#if __has_feature(address_sanitizer) || defined(__SANITIZE_ADDRESS__) +#define LOADER_ADDRESS_SANITIZER +#endif + // Dynamic Loading of libraries: typedef void *loader_platform_dl_handle; static inline loader_platform_dl_handle loader_platform_open_library(const char *libPath) { - // When loading the library, we use RTLD_LAZY so that not all symbols have to be - // resolved at this time (which improves performance). Note that if not all symbols - // can be resolved, this could cause crashes later. Use the LD_BIND_NOW environment - // variable to force all symbols to be resolved here. +// When loading the library, we use RTLD_LAZY so that not all symbols have to be +// resolved at this time (which improves performance). Note that if not all symbols +// can be resolved, this could cause crashes later. Use the LD_BIND_NOW environment +// variable to force all symbols to be resolved here. return dlopen(libPath, RTLD_LAZY | RTLD_LOCAL); } static inline const char *loader_platform_open_library_error(const char *libPath) { return dlerror(); } @@ -162,6 +191,7 @@ static inline void loader_platform_thread_cond_broadcast(loader_platform_thread_ #include <io.h> #include <stdbool.h> #include <shlwapi.h> +#include <direct.h> #ifdef __cplusplus #include <iostream> #include <string> @@ -279,6 +309,14 @@ static inline char *loader_platform_dirname(char *path) { return path; } +static inline char *loader_platform_executable_path(char *buffer, size_t size) { + DWORD ret = GetModuleFileName(NULL, buffer, (DWORD)size); + if (ret == 0) return NULL; + if (ret > size) return NULL; + buffer[ret] = '\0'; + return buffer; +} + // Dynamic Loading: typedef HMODULE loader_platform_dl_handle; static loader_platform_dl_handle loader_platform_open_library(const char *lib_path) { @@ -330,25 +368,9 @@ typedef HANDLE loader_platform_thread; // The once init functionality is not used when building a DLL on Windows. This is because there is no way to clean up the // resources allocated by anything allocated by once init. This isn't a problem for static libraries, but it is for dynamic // ones. When building a DLL, we use DllMain() instead to allow properly cleaning up resources. -#if defined(LOADER_DYNAMIC_LIB) #define LOADER_PLATFORM_THREAD_ONCE_DECLARATION(var) #define LOADER_PLATFORM_THREAD_ONCE_DEFINITION(var) #define LOADER_PLATFORM_THREAD_ONCE(ctl, func) -#else -#define LOADER_PLATFORM_THREAD_ONCE_DECLARATION(var) INIT_ONCE var = INIT_ONCE_STATIC_INIT; -#define LOADER_PLATFORM_THREAD_ONCE_DEFINITION(var) INIT_ONCE var; -#define LOADER_PLATFORM_THREAD_ONCE(ctl, func) loader_platform_thread_once_fn(ctl, func) -static BOOL CALLBACK InitFuncWrapper(PINIT_ONCE InitOnce, PVOID Parameter, PVOID *Context) { - void (*func)(void) = (void (*)(void))Parameter; - func(); - return TRUE; -} -static void loader_platform_thread_once_fn(void *ctl, void (*func)(void)) { - assert(func != NULL); - assert(ctl != NULL); - InitOnceExecuteOnce((PINIT_ONCE)ctl, InitFuncWrapper, (void *)func, NULL); -} -#endif // Thread IDs: typedef DWORD loader_platform_thread_id; |